00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__net__DNSCallback_H__
00010 #define __libutilxx__sella__net__DNSCallback_H__
00011
00012 #include "../../common.h"
00013 #include "DNSException.h"
00014 #include "IPAddress.h"
00015 #include "DNS.h"
00016
00017 #include <sys/socket.h>
00018 #include <stdint.h>
00019 #include <udns.h>
00020
00021 #include <string>
00022 #include <memory>
00023 #include <vector>
00024
00025 namespace sella {
00026 namespace net {
00027 class DNSCallback;
00028 }
00029 }
00030
00031 class sella::net::DNSCallback {
00032 friend class DNS;
00033
00034 public:
00035 typedef std::shared_ptr<DNSCallback> shared;
00036 typedef DNSCallback *ptr;
00037 enum Error : int { None = DNS_E_NOERROR, Temporary = DNS_E_TEMPFAIL, Protocol = DNS_E_PROTOCOL, NXDomain = DNS_E_NXDOMAIN, NoData = DNS_E_NODATA, NoMemory = DNS_E_NOMEM, BadQuery = DNS_E_BADQUERY };
00038
00039 public:
00040 DNSCallback() : protocol(0), flags(0) { };
00041 #if 0
00042 DNSCallback(const DNSCallback &other) throw ();
00043 DNSCallback(const DNSCallback &&other) throw ();
00044 virtual ~DNSCallback() throw ();
00045 #endif
00046
00047 virtual void success(const std::string &qname, const std::string &cname, int ttl, const std::vector<IPAddress> &response) const throw () = 0;
00048 virtual void failure(const std::string &qname, Error error) const throw () = 0;
00049
00050 protected:
00051 std::string qname;
00052 int protocol;
00053 int flags;
00054
00055 static const char* getErrorName(Error error) {
00056 switch (error) {
00057 case None:
00058 return "None";
00059 case Temporary:
00060 return "Temporary";
00061 case Protocol:
00062 return "Protocol";
00063 case NXDomain:
00064 return "NXDomain";
00065 case NoData:
00066 return "NoData";
00067 case NoMemory:
00068 return "NoMemory";
00069 case BadQuery:
00070 return "BadQuery";
00071 }
00072
00073 return "Unknown";
00074 }
00075
00076 static const char* getErrorDetail(Error error) {
00077 return ::dns_strerror((int) error);
00078 }
00079 };
00080
00081 #endif
00082
00083
00084
00085