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 #if !defined(AFX_WHOISSOCKET_H__6D6F3BD7_F9C3_4994_B9B2_58A75CD8208C__INCLUDED_)
00037 #define AFX_WHOISSOCKET_H__6D6F3BD7_F9C3_4994_B9B2_58A75CD8208C__INCLUDED_
00038 
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042 
00043 #pragma warning(disable:4786)
00044 
00045 #include "TCPSocketAsync.h"
00046 
00047 #include <map>
00048 #include <vector>
00049 
00050 KOMODIA_NAMESPACE_START
00051 
00052 class CWhoisSocket : public CTCPSocketAsync
00053 {
00054 public:
00055     
00056     typedef enum _WhoisServer
00057     {
00058         wsNone,
00059         wsArin,
00060         wsApnic,
00061         wsRipe,
00062         wsLast
00063     } WhoisServer;
00064 
00065     
00066     typedef std::vector<std::string> AddressVector;
00067 public:
00068     
00069     const std::string& GetLastTarget()const;
00070 
00071     
00072     const std::string& GetAdditionalWhoisServer()const;
00073 
00074     
00075     static std::string GetAddressForWhois(const std::string& rAddress);
00076 
00077     
00078     static AddressVector AnalyzeAddress(const std::string& rAddress);
00079 
00080     
00081     BOOL IsIPTrace()const;
00082 
00083     
00084     void SetWhoisTimeout(DWORD dwMS);
00085 
00086     
00087     const std::string& GetWhoisData()const;
00088 
00089     
00090     virtual BOOL IsError()const;
00091 
00092     
00093     virtual BOOL IsWhoisDone()const;
00094 
00095     
00096     virtual BOOL Create();
00097 
00098     
00099     BOOL WhoisURL(const std::string& rURL);
00100     BOOL WhoisURL(const std::string& rURL,
00101                   const std::string& rWhoisServer);
00102 
00103     
00104     BOOL WhoisIP(const std::string& rIP);
00105     BOOL WhoisIP(IP aAddress);
00106     BOOL WhoisIP(IP aAddress,
00107                  const std::string& rWhoisServer);
00108 
00109     
00110     CWhoisSocket(BOOL bAsync);
00111     virtual ~CWhoisSocket();
00112 protected:
00113     
00114     virtual void WhoisDone(BOOL bError);
00115 
00116     
00117     virtual BOOL OnSocketTimeout();
00118     virtual BOOL OnSocketConnect(int iErrorCode);
00119     virtual BOOL OnSocketClose(int iErrorCode);
00120     virtual BOOL OnSocketReceive(int iErrorCode);
00121     NO_OnSocketAccept
00122     NO_OnSocketOOB
00123     NO_OnSocketWrite
00124 
00125     
00126     const std::string& GetWhoisServer(const std::string& rURL)const;
00127 private:
00128     
00129     typedef std::map<std::string,std::string> WhoisMAP;
00130 private:
00131     
00132     CWhoisSocket();
00133 
00134     
00135     std::string ExtractAdditionalWhoisServer(const std::string rWhoisQuery)const;
00136 
00137     
00138     static void PopulateMap();
00139 
00140     
00141     void QueryDone(BOOL bError,
00142                    BOOL bReallocate);
00143 
00144     
00145     void ModifyString(std::string& rString)const;
00146 
00147     
00148     void ModifyBuffer(char* pBuffer,
00149                       int iBufferSize)const;
00150 
00151     
00152     BOOL SendURL(const std::string& rURL);
00153 
00154     
00155     BOOL ReceiveWhois();
00156 
00157     
00158     char* m_pData;
00159     
00160     
00161     unsigned long m_ulDataSize;
00162 
00163     
00164     static std::string m_sData[];
00165 
00166     
00167     static std::string m_sEmpty;
00168 
00169     
00170     static std::string m_aIPWhois[wsLast];
00171 
00172     
00173     static std::string m_aWhoisNotFound[wsLast];
00174 
00175     
00176     BOOL m_bAsync;
00177 
00178     
00179     BOOL m_bDone;
00180 
00181     
00182     BOOL m_bError;
00183 
00184     
00185     std::string m_sWhoisData;
00186 
00187     
00188     WhoisServer m_aServer;
00189 
00190     
00191     WhoisServer m_aProgress;
00192 
00193     
00194     std::string m_sDataToSend;
00195 
00196     
00197     DWORD m_dwTimeout;
00198 
00199     
00200     BOOL m_bURL;
00201 
00202     
00203     static WhoisMAP m_aData;
00204 
00205     
00206     static CWhoisSocket m_aSocket;
00207 
00208     
00209     static const std::string m_sWhoisClause;
00210 
00211     
00212     std::string m_sAdditionalWhoisServer;
00213 
00214     
00215     BOOL m_bAdditionalServer;
00216 };
00217 
00218 KOMODIA_NAMESPACE_END
00219 
00220 #endif // !defined(AFX_WHOISSOCKET_H__6D6F3BD7_F9C3_4994_B9B2_58A75CD8208C__INCLUDED_)