00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #include "stdafx.h"
00037 #include "WhoisSocket.h"
00038 
00039 #include "ErrorHandlerMacros.h"
00040 
00041 #ifdef _MEMORY_DEBUG 
00042     #define new    DEBUG_NEW  
00043     #define malloc DEBUG_MALLOC  
00044     static char THIS_FILE[] = __FILE__;  
00045 #endif
00046 
00047 KOMODIA_NAMESPACE_START
00048 
00049 #define CWhoisSocket_Class "CWhoisSocket"
00050 #define FINISH_CHAR "FINISH"
00051 
00052 std::string CWhoisSocket::m_sEmpty="";
00053 
00054 std::string CWhoisSocket::m_sData[]={"COM","whois.crsnic.net",
00055                                      "NET","whois.crsnic.net",
00056                                      "ORG","whois.crsnic.net",
00057                                      "EDU","whois.crsnic.net",
00058                                      "UK","whois.nic.uk",
00059                                      "NU","whois.nic.nu",
00060                                      "CC","whois.nic.cc",
00061                                      "AU","whois.aunic.net",
00062                                      "MIL","whois.nic.mil",
00063                                      "IL","whois.isoc.org.il",
00064                                      "AC","whois.nic.ac",
00065                                      "AG","whois.nic.ag",
00066                                      "AS","whois.nic.as",
00067                                      "AT","whois.nic.at",
00068                                      "BE","whois.dns.be",
00069                                      "BG","whois.digsys.bg",
00070                                      "BR","whois.nic.br",
00071                                      "BV","whois.norid.no",
00072                                      "SJ","whois.norid.no",
00073                                      "CC","whois.nic.cc",
00074                                      "CH","whois.nic.ch",
00075                                      "CD","whois.nic.cd",
00076                                      "CK","whois.ck-nic.org.ck",
00077                                      "CL","whois.nic.cl",
00078                                      "CX","whois.nic.cx",
00079                                      "DE","whois.denic.de",
00080                                      "CZ","whois.nic.cz",
00081                                      "EE","whois.eenet.ee",
00082                                      "FJ","whois.usp.ac.fj",
00083                                      "FR","whois.nic.fr",
00084                                      "GS","whois.adamsnames.tc",
00085                                      "HU","nic.hu",
00086                                      "IN","whois.ncst.ernet.in",
00087                                      "IE","whois.domainregistry.ie",
00088                                      "IR","whois.nic.ir",
00089                                      "IS","whois.isnet.is",
00090                                      "IT","whois.nic.it",
00091                                      "JP","whois.nic.ad.jp",
00092                                      "KR","whois.krnic.net",
00093                                      "LI","whois.nic.li",
00094                                      "LU","whois.dns.lu",
00095                                      "TC","whois.adamsnames.tc",
00096                                      "MX","whois.nic.mx",
00097                                      "NL","whois.domain-registry.nl",
00098                                      "NO","whois.norid.no",
00099                                      "NU","whois.nic.nu",
00100                                      "PL","whois.nask.pl",
00101                                      "PW","whois.nic.pw",
00102                                      "RE","whois.nic.fr",
00103                                      "RU","whois.ripn.net",
00104                                      "RO","whois.rnc.ro",
00105                                      "SE","whois.nic-se.se",
00106                                      "SG","whois.nic.net.sg",
00107                                      "SH","whois.nic.sh",
00108                                      "SI","whois.arnes.si",
00109                                      "SZ","whois.adamsnames.tc",
00110                                      "TC","whois.adamsnames.tc",
00111                                      "TH","whois.thnic.net",
00112                                      "TJ","whois.nic.tj",
00113                                      "TO","whois.tonic.to",
00114                                      "TR","whois.metu.edu.tr",
00115                                      "TW","whois.twnic.net",
00116                                      "UA","whois.net.ua",
00117                                      "VG","whois.adamsnames.tc",
00118                                      "WF","whois.nic.fr",
00119                                      "YT","whois.nic.fr",
00120                                      FINISH_CHAR};
00121 
00122 std::string CWhoisSocket::m_aIPWhois[wsLast]={"",
00123                                               "whois.arin.net",
00124                                               "whois.apnic.net",
00125                                               "whois.ripe.net"};
00126 
00127 std::string CWhoisSocket::m_aWhoisNotFound[wsLast]={"",
00128                                                     "These addresses have been further assigned",
00129                                                     "No entries found",
00130                                                     "This address space is assigned at various other places in"};
00131 CWhoisSocket::WhoisMAP CWhoisSocket::m_aData;
00132 
00133 CWhoisSocket CWhoisSocket::m_aSocket;
00134 
00135 const std::string CWhoisSocket::m_sWhoisClause="Whois Server: ";
00136 
00137 CWhoisSocket::CWhoisSocket() : CTCPSocketAsync(FALSE)
00138 {
00139     try
00140     {
00141         
00142         SetName(CWhoisSocket_Class);
00143 
00144         
00145         PopulateMap();
00146     }
00147     ERROR_HANDLER("CWhoisSocket")
00148 }
00149 
00150 CWhoisSocket::CWhoisSocket(BOOL bAsync) : CTCPSocketAsync(FALSE),
00151                                           m_bAsync(bAsync),
00152                                           m_bDone(TRUE),
00153                                           m_bError(FALSE),
00154                                           m_aServer(wsNone),
00155                                           m_dwTimeout(5000)
00156 {
00157     try
00158     {
00159         
00160         SetName(CWhoisSocket_Class);
00161     }
00162     ERROR_HANDLER("CWhoisSocket")
00163 }
00164 
00165 CWhoisSocket::~CWhoisSocket()
00166 {
00167 }
00168 
00169 void CWhoisSocket::QueryDone(BOOL bError,
00170                              BOOL bReallocate)
00171 {
00172     try
00173     {
00174         
00175         m_bError=bError;
00176 
00177         
00178         if (bReallocate)
00179         {
00180             
00181             if (!Close())
00182                 ReportError("QueryDone","Failed to close socket!");
00183 
00184             
00185             if (!Create())
00186                 ReportError("QueryDone","Failed to create socket!");
00187         }
00188 
00189         
00190         if (m_bURL)
00191         {
00192             m_bDone=TRUE;
00193 
00194             
00195             if (bError)
00196                 m_sWhoisData="";
00197             
00198             else if (m_bAdditionalServer)
00199                 m_sAdditionalWhoisServer=ExtractAdditionalWhoisServer(m_sWhoisData);
00200             else
00201                 m_sAdditionalWhoisServer="";
00202 
00203             
00204             WhoisDone(bError);
00205         }
00206         else if (m_aProgress!=wsNone)
00207         {
00208             
00209             
00210             if (!bError &&
00211                 m_sWhoisData.find(m_aWhoisNotFound[m_aProgress])==std::string::npos)
00212             {
00213                 
00214                 m_aServer=m_aProgress;
00215 
00216                 
00217                 m_bDone=TRUE;
00218 
00219                 
00220                 WhoisDone(FALSE);
00221             }
00222             else
00223             {
00224                 
00225                 m_aProgress=(WhoisServer)((int)m_aProgress-1);
00226 
00227                 
00228                 if (m_aProgress==wsNone)
00229                 {
00230                     
00231                     m_bDone=TRUE;
00232                     m_bError=TRUE;
00233         
00234                     
00235                     WhoisDone(TRUE);
00236                 }
00237                 else if (!WhoisURL(m_sDataToSend,m_aIPWhois[m_aProgress]))
00238                 {
00239                     
00240                     ReportError("QueryDone","Failed to connect!");
00241 
00242                     
00243                     
00244                     m_aProgress=(WhoisServer)((int)m_aProgress-1);
00245         
00246                     
00247                     QueryDone(TRUE,
00248                               TRUE);
00249                 }
00250             }
00251         }
00252         else
00253             
00254             WhoisDone(TRUE);
00255     }
00256     ERROR_HANDLER("QueryDone")
00257 }
00258 
00259 void CWhoisSocket::WhoisDone(BOOL bError)
00260 {
00261 }
00262 
00263 BOOL CWhoisSocket::OnSocketTimeout()
00264 {
00265     try
00266     {
00267         
00268         KillTimer();
00269 
00270         
00271         QueryDone(TRUE,
00272                   TRUE);
00273 
00274         
00275         return FALSE;
00276     }
00277     ERROR_HANDLER_RETURN("OnSocketTimeout",FALSE)
00278 }
00279 
00280 BOOL CWhoisSocket::OnSocketConnect(int iErrorCode)
00281 {
00282     try
00283     {
00284         
00285         if (iErrorCode)
00286         {
00287             
00288             ReportError("OnSocketConnect",iErrorCode);
00289 
00290             
00291             QueryDone(TRUE,
00292                       TRUE);
00293 
00294             
00295             return FALSE;
00296         }
00297 
00298         
00299         if (!SendURL(m_sDataToSend))
00300         {
00301             
00302             ReportError("OnSocketConnect","Failed to send data!");
00303 
00304             
00305             QueryDone(TRUE,
00306                       TRUE);
00307 
00308             
00309             return FALSE;
00310         }
00311 
00312         
00313         SetTimeout(m_dwTimeout);
00314 
00315         
00316         return TRUE;
00317     }
00318     ERROR_HANDLER_RETURN("OnSocketConnect",FALSE)
00319 }
00320 
00321 BOOL CWhoisSocket::OnSocketClose(int iErrorCode)
00322 {
00323     try
00324     {
00325         
00326         KillTimer();
00327 
00328         
00329         if (!Close())
00330             ReportError("OnSocketClose","Failed to close socket!");
00331 
00332         
00333         if (!Create())
00334         {
00335             
00336             ReportError("OnSocketClose","Failed to create socket!");
00337 
00338             
00339             return FALSE;
00340         }
00341 
00342         
00343         QueryDone(FALSE,
00344                   FALSE);
00345 
00346         
00347         return TRUE;
00348     }
00349     ERROR_HANDLER_RETURN("OnSocketClose",FALSE)
00350 }
00351 
00352 BOOL CWhoisSocket::OnSocketReceive(int iErrorCode)
00353 {
00354     try
00355     {
00356         
00357         KillTimer();
00358 
00359         
00360         if (iErrorCode)
00361         {
00362             
00363             ReportError("OnSocketReceive",iErrorCode);
00364 
00365             
00366             QueryDone(TRUE,
00367                       TRUE);
00368 
00369             
00370             return FALSE;
00371         }
00372 
00373         
00374         char aData[4000];
00375 
00376         
00377         int iSize;
00378         iSize=Receive(aData,sizeof(aData)/2-1);
00379 
00380         
00381         if (iSize==GetErrorCode())
00382         {
00383             
00384             QueryDone(TRUE,
00385                       TRUE);
00386 
00387             
00388             return FALSE;
00389         }
00390 
00391         
00392         for (int iCounter=0;
00393              iCounter<iSize;
00394              iCounter++)
00395             if (!aData[iCounter])
00396                 aData[iCounter]=10;
00397 
00398         
00399         aData[iSize]=0;
00400 
00401         
00402         ModifyBuffer(aData,iSize+1);
00403 
00404         
00405         m_sWhoisData+=aData;
00406 
00407         
00408         SetTimeout(m_dwTimeout);
00409         
00410         
00411         return TRUE;
00412     }
00413     ERROR_HANDLER_RETURN("OnSocketReceive",FALSE)
00414 }
00415 
00416 const std::string& CWhoisSocket::GetWhoisServer(const std::string& rURL)const
00417 {
00418     try
00419     {
00420         
00421         std::string::size_type aPos;
00422         aPos=rURL.find_last_of('.');
00423 
00424         
00425         if (aPos==std::string::npos)
00426             return m_sEmpty;
00427 
00428         
00429         if (rURL.length()-aPos>4)
00430             return m_sEmpty;
00431 
00432         
00433         std::string::size_type aCopied;
00434         char aExtension[10];
00435         aCopied=rURL.copy(aExtension,rURL.length()-aPos-1,aPos+1);
00436         aExtension[aCopied]=0;
00437 
00438         
00439         strupr(aExtension);
00440 
00441         
00442         std::string sExtension;
00443         sExtension=aExtension;
00444 
00445         
00446         WhoisMAP::const_iterator aIterator;
00447         aIterator=m_aData.find(sExtension);
00448 
00449         
00450         if (aIterator!=m_aData.end())
00451             return aIterator->second;
00452         else
00453             
00454             return m_sEmpty;
00455     }
00456     ERROR_HANDLER_RETURN("GetWhoisServer",m_sEmpty)
00457 }
00458 
00459 BOOL CWhoisSocket::Create()
00460 {
00461     try
00462     {
00463         
00464         if (CTCPSocketAsync::Create())
00465         {
00466             if (!m_bAsync)
00467             {
00468                 if (!ReBlock())
00469                 {
00470                     
00471                     ReportError("CreateRegular","Failed to reblock!");
00472 
00473                     
00474                     return FALSE;
00475                 }
00476 
00477                 
00478                 if (!SetReceiveTimeout(m_dwTimeout))
00479                 {
00480                     
00481                     ReportError("CreateRegular","Failed to set timeout!");
00482 
00483                     
00484                     return FALSE;
00485                 }
00486             }
00487 
00488             
00489             return TRUE;
00490         }
00491         else
00492             return FALSE;
00493     }
00494     ERROR_HANDLER_RETURN("Create",FALSE)
00495 }
00496 
00497 BOOL CWhoisSocket::WhoisURL(const std::string& rURL)
00498 {
00499     try
00500     {
00501         
00502         std::string sHost;
00503         sHost=GetWhoisServer(rURL);
00504 
00505         
00506         m_bURL=TRUE;
00507 
00508         
00509         if (!sHost.length())
00510         {
00511             
00512             ReportError("WhoisURL","Failed to find host to connect to!");
00513 
00514             
00515             return FALSE;
00516         }
00517         else
00518             return WhoisURL(rURL,sHost);
00519     }
00520     ERROR_HANDLER_RETURN("WhoisURL",FALSE)
00521 }
00522 
00523 BOOL CWhoisSocket::WhoisURL(const std::string& rURL,
00524                             const std::string& rWhoisServer)
00525 {
00526     try
00527     {
00528         
00529         IP aAddress;
00530         aAddress=ResolveDNS(rWhoisServer.c_str());
00531 
00532         
00533         if (!aAddress)
00534         {
00535             
00536             ReportError("WhoisURL","Failed to resolve whois server!");
00537 
00538             
00539             return FALSE;
00540         }
00541 
00542         
00543         m_bDone=FALSE;
00544         m_bError=FALSE;
00545         m_sWhoisData="";
00546         m_sDataToSend=rURL;
00547         m_sAdditionalWhoisServer="";
00548         m_bAdditionalServer=rWhoisServer=="whois.crsnic.net";
00549 
00550         
00551         if (!Connect(aAddress,43))
00552         {
00553             
00554             ReportError("WhoisURL","Failed to connect!");
00555 
00556             
00557             m_bDone=TRUE;
00558 
00559             
00560             m_bError=TRUE;
00561 
00562             
00563             return FALSE;
00564         }
00565 
00566         
00567         if (!m_bAsync)
00568             if (!SendURL(rURL))
00569             {
00570                 
00571                 ReportError("WhoisURL","Failed to send data!");
00572 
00573                 
00574                 m_bDone=TRUE;
00575 
00576                 
00577                 m_bError=TRUE;
00578 
00579                 
00580                 return FALSE;
00581             }
00582             else
00583                 return ReceiveWhois();
00584         else
00585             return TRUE;
00586     }
00587     ERROR_HANDLER_RETURN("WhoisURL",FALSE)
00588 }
00589 
00590 BOOL CWhoisSocket::IsWhoisDone()const
00591 {
00592     return m_bDone;
00593 }
00594 
00595 BOOL CWhoisSocket::IsError()const
00596 {
00597     return m_bError;
00598 }
00599 
00600 BOOL CWhoisSocket::ReceiveWhois()
00601 {
00602     try
00603     {
00604         
00605         char aData[4000];
00606 
00607         
00608         while (1)
00609         {
00610             
00611             int iSize;
00612             iSize=Receive(aData,sizeof(aData)/2-1);
00613 
00614             
00615             if (!iSize)
00616             {
00617                 
00618                 if (!Close())
00619                     ReportError("ReceiveWhois","Failed to close socket!");
00620 
00621                 
00622                 if (!Create())
00623                 {
00624                     
00625                     ReportError("ReceiveWhois","Failed to create socket!");
00626 
00627                     
00628                     return FALSE;
00629                 }
00630 
00631                 
00632                 if (m_bAdditionalServer)
00633                     m_sAdditionalWhoisServer=ExtractAdditionalWhoisServer(m_sWhoisData);
00634 
00635                 
00636                 return TRUE;
00637             }
00638 
00639             
00640             if (iSize==GetErrorCode())
00641                 return FALSE;
00642 
00643             
00644             for (int iCounter=0;
00645                  iCounter<iSize;
00646                  iCounter++)
00647                 if (!aData[iCounter])
00648                     aData[iCounter]=10;
00649 
00650             
00651             aData[iSize]=0;
00652 
00653             
00654             ModifyBuffer(aData,iSize+1);
00655 
00656             
00657             m_sWhoisData+=aData;
00658         }
00659         
00660         
00661         return TRUE;
00662     }
00663     ERROR_HANDLER_RETURN("ReceiveWhois",FALSE)
00664 }
00665 
00666 BOOL CWhoisSocket::SendURL(const std::string& rURL)
00667 {
00668     try
00669     {
00670         
00671         char* pBuffer;
00672         pBuffer=new char[rURL.length()+10];
00673 
00674         
00675         rURL.copy(pBuffer,rURL.length(),0);
00676         
00677         
00678         pBuffer[rURL.length()]=10;
00679 
00680         
00681         int iSendSize;
00682         iSendSize=Send(pBuffer,rURL.length()+1);
00683 
00684         
00685         delete [] pBuffer;
00686 
00687         
00688         return iSendSize!=GetErrorCode();
00689     }
00690     ERROR_HANDLER_RETURN("SendURL",FALSE)
00691 }
00692 
00693 void CWhoisSocket::ModifyString(std::string& rString)const
00694 {
00695     try
00696     {
00697         
00698         std::string::iterator aIterator;
00699         aIterator=rString.begin();
00700 
00701         
00702         std::string sReplace;
00703         char aChar;
00704         aChar=13;
00705 
00706         
00707         while (aIterator<rString.end())
00708         {
00709             
00710             if (*aIterator==10)
00711             {
00712                 
00713                 std::string::iterator aBackupIterator;
00714                 aBackupIterator=aIterator;
00715 
00716                 
00717                 ++aIterator;
00718 
00719                 
00720                 rString.insert(aBackupIterator,aChar);
00721             }
00722             else
00723                 ++aIterator;
00724         }
00725     }
00726     ERROR_HANDLER("ModifyString")
00727 }
00728 
00729 const std::string& CWhoisSocket::GetWhoisData()const
00730 {
00731     return m_sWhoisData;
00732 }
00733 
00734 BOOL CWhoisSocket::WhoisIP(const std::string& rIP)
00735 {
00736     try
00737     {
00738         
00739         return WhoisIP(StringToLong(rIP));
00740     }
00741     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00742 }
00743 
00744 BOOL CWhoisSocket::WhoisIP(IP aAddress)
00745 {
00746     try
00747     {
00748         
00749         m_aServer=wsNone;
00750 
00751         
00752         if (!m_bAsync)
00753         {
00754             
00755             for (int iCounter=wsRipe;
00756                  iCounter>wsNone;
00757                  --iCounter)
00758             {
00759                 
00760                 if (!WhoisIP(aAddress,m_aIPWhois[iCounter]))
00761                 {
00762                     
00763                     ReportError("WhoisIP","Failed getting data from server!");
00764 
00765                     
00766                     return FALSE;
00767                 }
00768 
00769                 
00770                 if (m_sWhoisData.find(m_aWhoisNotFound[iCounter])==std::string::npos)
00771                 {
00772                     
00773                     m_aServer=(WhoisServer)iCounter;
00774 
00775                     
00776                     return TRUE;
00777                 }
00778             }
00779 
00780             
00781             return FALSE;
00782         }
00783         else
00784         {
00785             
00786             m_aProgress=wsRipe;
00787 
00788             
00789             return WhoisIP(aAddress,m_aIPWhois[m_aProgress]);
00790         }
00791     }
00792     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00793 }
00794 
00795 BOOL CWhoisSocket::WhoisIP(IP aAddress,
00796                            const std::string& rWhoisServer)
00797 {
00798     try
00799     {
00800         
00801         m_bURL=FALSE;
00802 
00803         
00804         return WhoisURL(LongToStdString(aAddress),rWhoisServer);
00805     }
00806     ERROR_HANDLER_RETURN("WhoisIP",FALSE)
00807 }
00808 
00809 void CWhoisSocket::SetWhoisTimeout(DWORD dwMS)
00810 {
00811     try
00812     {
00813         
00814         m_dwTimeout=dwMS;
00815 
00816         
00817         SetReceiveTimeout(dwMS);
00818     }
00819     ERROR_HANDLER("SetWhoisTimeout")
00820 }
00821 
00822 BOOL CWhoisSocket::IsIPTrace()const
00823 {
00824     return !m_bURL;
00825 }
00826 
00827 void CWhoisSocket::ModifyBuffer(char* pBuffer,
00828                                 int iBufferSize)const
00829 {
00830     try
00831     {
00832         
00833         char* pNewBuffer;
00834         pNewBuffer=new char[iBufferSize*2];
00835 
00836         
00837         int iBufferPos;
00838         iBufferPos=0;
00839 
00840         
00841         for (int iCounter=0;iCounter<iBufferSize;++iCounter)
00842         {
00843             
00844             pNewBuffer[iBufferPos++]=pBuffer[iCounter];
00845 
00846             
00847             if (pBuffer[iCounter]==10)
00848                 pNewBuffer[iBufferPos++]=13;
00849         }
00850 
00851         
00852         memcpy(pBuffer,pNewBuffer,iBufferPos);
00853 
00854         
00855         delete [] pNewBuffer;
00856     }
00857     ERROR_HANDLER("ModifyBuffer")
00858 }
00859 
00860 void CWhoisSocket::PopulateMap()
00861 {
00862     try
00863     {
00864         
00865         int iPos;
00866         iPos=0;
00867 
00868         while (m_sData[iPos]!=FINISH_CHAR)
00869         {
00870             
00871             m_aData.insert(WhoisMAP::value_type(m_sData[iPos],m_sData[iPos+1]));
00872 
00873             
00874             iPos+=2;
00875         }
00876     }
00877     ERROR_HANDLER_STATIC(CWhoisSocket_Class,"PopulateMap")
00878 }
00879 
00880 CWhoisSocket::AddressVector CWhoisSocket::AnalyzeAddress(const std::string& rAddress)
00881 {
00882     
00883     AddressVector aVector;
00884 
00885     
00886     if (!rAddress.length())
00887     {
00888         
00889         ReportStaticError(CWhoisSocket_Class,"AnalyzeAddress","Recieved empty string!");
00890 
00891         
00892         return aVector;
00893     }
00894 
00895     try
00896     {
00897         
00898         std::string sTmp;
00899         sTmp=rAddress;
00900 
00901         
00902         std::string::size_type aPos;
00903         aPos=sTmp.find_last_of('.');
00904 
00905         
00906         while (aPos!=std::string::npos)
00907         {
00908             
00909             int iCopySize;
00910             iCopySize=sTmp.length()-aPos-1;
00911 
00912             
00913             char* pExtension;
00914             pExtension=new char[iCopySize+1];
00915 
00916             
00917             std::string::size_type aCopied;
00918             aCopied=sTmp.copy(pExtension,iCopySize,aPos+1);
00919             pExtension[aCopied]=0;
00920 
00921             
00922             strupr(pExtension);
00923 
00924             
00925             std::string sData;
00926             sData=pExtension;
00927 
00928             
00929             aVector.push_back(sData);
00930 
00931             
00932             delete [] pExtension;
00933 
00934             
00935             sTmp=sTmp.substr(0,aPos);
00936 
00937             
00938             aPos=sTmp.find_last_of('.');
00939         }
00940 
00941         
00942         aVector.push_back(sTmp);
00943 
00944         
00945         return aVector;
00946     }
00947     ERROR_HANDLER_STATIC_RETURN(CWhoisSocket_Class,"AnalyzeAddress",aVector)
00948 }
00949 
00950 std::string CWhoisSocket::GetAddressForWhois(const std::string& rAddress)
00951 {
00952     try
00953     {
00954         
00955         AddressVector aVector;
00956         aVector=AnalyzeAddress(rAddress);
00957 
00958         
00959         if (aVector.begin()==aVector.end())
00960             return "";
00961 
00962         
00963         AddressVector::const_iterator aIterator;
00964         aIterator=aVector.begin();
00965 
00966         
00967         std::string sAddress;
00968         std::string sAddAddress;
00969 
00970         
00971         sAddress+=*aIterator;
00972 
00973         
00974         ++aIterator;
00975         if (aIterator==aVector.end())
00976             return "";
00977 
00978         
00979         sAddAddress=*aIterator;
00980         sAddAddress+='.';
00981         sAddAddress+=sAddress;
00982 
00983         
00984         if (!(*aIterator=="COM" ||
00985               *aIterator=="NET" ||
00986               *aIterator=="ORG" ||
00987               *aIterator=="MIL" ||
00988               *aIterator=="EDU" ||
00989               *aIterator=="CO") ||
00990               sAddress.length()==3)
00991             
00992             return sAddAddress;
00993 
00994         
00995         ++aIterator;
00996         if (aIterator==aVector.end())
00997             return "";
00998 
00999         
01000         sAddress=*aIterator;
01001         sAddress+='.';
01002         sAddress+=sAddAddress;
01003 
01004         
01005         return sAddress;
01006     }
01007     ERROR_HANDLER_STATIC_RETURN(CWhoisSocket_Class,"GetAddressForWhois","")
01008 }
01009 
01010 const std::string& CWhoisSocket::GetAdditionalWhoisServer()const
01011 {
01012     return m_sAdditionalWhoisServer;
01013 }
01014 
01015 std::string CWhoisSocket::ExtractAdditionalWhoisServer(const std::string rWhoisQuery)const
01016 {
01017     try
01018     {
01019         if (!rWhoisQuery.length())
01020             return "";
01021 
01022         
01023         std::string::size_type aPos;
01024         aPos=rWhoisQuery.find(m_sWhoisClause);
01025 
01026         
01027         if (aPos==std::string::npos)
01028             return "";
01029 
01030         
01031         char aChar;
01032         aChar=10;
01033 
01034         
01035         std::string::size_type aLastPos;
01036         aLastPos=rWhoisQuery.find_first_of(aChar,aPos);
01037 
01038         
01039         if (aLastPos==std::string::npos)
01040             return "";
01041 
01042         
01043         aPos+=m_sWhoisClause.length();
01044 
01045         
01046         return rWhoisQuery.substr(aPos,aLastPos-aPos);
01047     }
01048     ERROR_HANDLER_RETURN("ExtractAdditionalWhoisServer","")
01049 }
01050 
01051 const std::string& CWhoisSocket::GetLastTarget()const
01052 {
01053     return m_sDataToSend;
01054 }
01055 
01056 KOMODIA_NAMESPACE_END