00001 #ifndef ZEWHOIS_H
00002 #define ZEWHOIS_H
00003 #include <abuse/abuse.h>
00004 #include <abuse/Url.h>
00005 #include <abuse/UrlRange.h>
00006 #include <abuse/net_error.h>
00007 #include <list>
00008
00009 #define ARINhandle "ARIN"
00010 #define APNIChandle "APNIC"
00011 #define LACNIChandle "LACNIC"
00012 #define JPNIChandle "JPNIC-NET-JP"
00013 #define KRNIChandle "KRNIC-KR"
00014 #define RIPEhandle "RIPE"
00015 #define AFRINIChandle "AFRINIC"
00016 #define RIPEAFRINIChandle "AFRINIC-NET-TRANSFERRED-20050223"
00017 #define BRNIChandle "BR-CGIN-LACNIC"
00018 #define BRNIC1handle "BR-CGIN1-LACNIC"
00019
00020 struct RIRImpl;
00021 class WhoisCache;
00022
00023 class ZeWhois
00024 {
00025 public:
00026 struct RIR
00027 {
00028 public:
00029 const std::string address;
00030 const std::string orgId;
00031 const std::string orgIdTag;
00032 protected:
00033 RIR(const char* addr,const char* org,const char* orgtag):address(addr),
00034 orgId(org),
00035 orgIdTag(orgtag){}
00036 virtual ~RIR(){}
00037 };
00038
00039
00040 struct WhoisEntry
00041 {
00042 UrlRange range;
00043 const RIR* rir;
00044 std::string entry;
00045 WhoisEntry(const UrlRange& r,std::string e,const RIR& ri):range(r),entry(e),rir(&ri){}
00046 WhoisEntry();
00047 WhoisEntry(const WhoisEntry& other):rir(other.rir),range(other.range),entry(other.entry)
00048 {}
00049 bool operator<(const WhoisEntry& other);
00050 };
00051 typedef std::list<WhoisEntry>WhoisList;
00052 static std::string whois(const std::string& forwhat,const Url& url,short int port=43)throw(net_error);
00053 static std::string whois(const Url& forwhat,const Url& url,short int port=43)throw(net_error);
00054 static std::string whoisip(const Url& forwhat,const Url& url,short int port=43)throw(net_error);
00055 static WhoisList whoisip(const Url& forwhat)throw(net_error);
00056 static const RIR& rirFromRirHandle(const std::string& handle)throw(net_error);
00057 static WhoisCache* setCache(WhoisCache* _cache);
00058 static WhoisCache* getCache();
00059 private:
00060 static UrlRange findRange(const std::string& str,const RIRImpl& rir,const Url& url);
00061 static std::string getID(const std::string& response,const RIRImpl& rir)throw(net_error);
00062 static void do_whoisip(const Url& forwhat,const RIR& rir,WhoisList& lst)throw(net_error);
00063 ZeWhois();
00064 static WhoisCache* cache;
00065 };
00066
00067
00068 #endif