bool KviIrcServerDataBase::makeCurrentServer(KviIrcServerDefinition * pDef, QString & szError) { KviIrcServer * pServer = 0; KviPointerHashTableIterator<QString,KviIrcNetwork> it(*m_pRecords); KviIrcNetwork * pNet = 0; KviIrcServer * pServ; if(KviQString::equalCIN(pDef->szServer,"net:",4)) { // net:networkname form QString szNet = pDef->szServer; szNet.remove(0,4); KviIrcNetwork * pNet = m_pRecords->find(szNet); if(pNet) return makeCurrentBestServerInNetwork(szNet,pNet,szError); szError = __tr2qs("The server specification seems to be in the net:<string> but the network couldn't be found in the database"); return false; } if(KviQString::equalCIN(pDef->szServer,"id:",3)) { // id:serverid form QString szId = pDef->szServer; szId.remove(0,3); while((pNet = it.current())) { for(pServ = pNet->serverList()->first(); pServ && (!pServer); pServ = pNet->serverList()->next()) { if(KviQString::equalCI(pServ->id(),szId)) { pServer = pServ; goto search_finished; } } ++it; } szError = __tr2qs("The server specification seems to be in the id:<string> form but the identifier couldn't be found in the database"); return false; } it.toFirst(); while((pNet = it.current())) { for(pServ = pNet->serverList()->first(); pServ && (!pServer); pServ = pNet->serverList()->next()) { if(KviQString::equalCI(pServ->hostName(),pDef->szServer)) { if(pDef->szId.isEmpty() || KviQString::equalCI(pServ->id(),pDef->szId)) { if(pDef->bIPv6 == pServ->isIPv6()) { if(pDef->bSSL == pServ->useSSL()) { if(pDef->bPortIsValid) { // must match the port if(pDef->uPort == pServ->port()) { // port matches if(!pDef->szLinkFilter.isEmpty()) { // must match the link filter if(KviQString::equalCI(pDef->szLinkFilter,pServ->linkFilter())) { // link filter matches pServer = pServ; goto search_finished; } // else link filter doesn't match } else { // no need to match the link filter pServer = pServ; goto search_finished; } } // else port doesn't match } else { // no need to match the port if(!pDef->szLinkFilter.isEmpty()) { // must match the link filter if(KviQString::equalCI(pDef->szLinkFilter,pServ->linkFilter())) { // link filter matches pServer = pServ; goto search_finished; } // else link filter doesn't match } else { // no need to match the link filter pServer = pServ; goto search_finished; } } } } } } } ++it; } search_finished: if(pNet && pServer) { m_szCurrentNetwork = pNet->name(); pNet->setCurrentServer(pServer); return true; } // no such server: is it a valid ip address or hostname ? bool bIsValidIPv4 = KviNetUtils::isValidStringIp(pDef->szServer); #ifdef COMPILE_IPV6_SUPPORT bool bIsValidIPv6 = KviNetUtils::isValidStringIPv6(pDef->szServer); #else bool bIsValidIPv6 = false; #endif if(!(bIsValidIPv4 || bIsValidIPv6)) { // is it a valid hostname ? (must contain at least one dot) if(!pDef->szServer.contains('.')) { // assume it is a network name! KviIrcNetwork * pNet = m_pRecords->find(pDef->szServer); if(pNet) return makeCurrentBestServerInNetwork(pDef->szServer,pNet,szError); // else probably not a network name } } // a valid hostname or ip address, not found in list : add it and make it current pNet = m_pRecords->find(__tr2qs("Standalone Servers")); if(!pNet) { pNet = new KviIrcNetwork(__tr2qs("Standalone Servers")); m_pRecords->replace(pNet->name(),pNet); } KviIrcServer * pSrv = new KviIrcServer(); pSrv->setHostName(pDef->szServer); if(bIsValidIPv4) { pSrv->setIp(pDef->szServer); pSrv->setCacheIp(true); #ifdef COMPILE_IPV6_SUPPORT } else { if(bIsValidIPv6) { pSrv->setIp(pDef->szServer); pSrv->setCacheIp(true); pDef->bIPv6 = true; } } #else }
int KviMircServersIniImport::doImport(const QString& filename) { KviConfigurationFile cfg(filename,KviConfigurationFile::Read,true); int iCount = 0; if(cfg.hasGroup("servers")) { cfg.setGroup("servers"); int i = 0; QString key; QString entry; do { key = QString("n%1").arg(i); entry = cfg.readEntry(key,""); if(!entry.isEmpty()) { QString description; QString serv; QString port; kvi_u32_t uPort = 0; // <description>SERVER:<server:port>GROUP:<network> int idx = entry.indexOf("SERVER:",0,Qt::CaseSensitive); if(idx != -1) { description = entry.left(idx); entry.remove(0,idx + 7); idx = entry.indexOf("GROUP:",0,Qt::CaseSensitive); if(idx != -1) { port = entry.left(idx); entry.remove(0,idx + 6); } idx = port.indexOf(':',0,Qt::CaseSensitive); if(idx != -1) { serv = port.left(idx); port.remove(0,idx + 1); bool bOk; uPort = port.toUInt(&bOk); if(!bOk) uPort = 6667; } else { serv = port; uPort = 6667; } } if(entry.isEmpty()) entry = __tr2qs("Standalone Servers"); if(!serv.isEmpty()) { KviIrcServer s; s.setHostName(serv); s.setDescription(description); s.setPort(uPort); iCount++; emit server(s,entry); } ++i; } } while(!entry.isEmpty()); } else { QString szTmp = QString(__tr2qs("%1 doesn't look like a servers.ini file.\nImport failed.")).arg(filename); QMessageBox::warning(0,__tr2qs("Warning - KVIrc"),szTmp); } return iCount; }