]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/modules/dns.h
Merge pull request #1351 from SaberUK/master+webirc
[user/henk/code/inspircd.git] / include / modules / dns.h
index 4da31b805407fc44fe236a3c48af3d2a92f8e4e7..61abd7144288c5a9c904645f900a87521e3eb9c1 100644 (file)
@@ -33,6 +33,8 @@ namespace DNS
                QUERY_CNAME = 5,
                /* Reverse DNS lookup */
                QUERY_PTR = 12,
+               /* TXT */
+               QUERY_TXT = 16,
                /* IPv6 AAAA lookup */
                QUERY_AAAA = 28
        };
@@ -57,6 +59,7 @@ namespace DNS
                ERROR_UNKNOWN,
                ERROR_UNLOADED,
                ERROR_TIMEDOUT,
+               ERROR_MALFORMED,
                ERROR_NOT_AN_ANSWER,
                ERROR_NONSTANDARD_QUERY,
                ERROR_FORMAT_ERROR,
@@ -72,12 +75,6 @@ namespace DNS
 
        const int PORT = 53;
 
-       /**
-        * The maximum value of a dns request id,
-        * 16 bits wide, 0xFFFF.
-        */
-       const int MAX_REQUEST_ID = 0xFFFF;
-
        class Exception : public ModuleException
        {
         public:
@@ -92,6 +89,7 @@ namespace DNS
                Question() : type(QUERY_NONE) { }
                Question(const std::string& n, QueryType t) : name(n), type(t) { }
                bool operator==(const Question& other) const { return ((name == other.name) && (type == other.type)); }
+               bool operator!=(const Question& other) const { return (!(*this == other)); }
 
                struct hash
                {
@@ -121,6 +119,18 @@ namespace DNS
 
                Query() : error(ERROR_NONE), cached(false) { }
                Query(const Question& q) : question(q), error(ERROR_NONE), cached(false) { }
+
+               const ResourceRecord* FindAnswerOfType(QueryType qtype) const
+               {
+                       for (std::vector<DNS::ResourceRecord>::const_iterator i = answers.begin(); i != answers.end(); ++i)
+                       {
+                               const DNS::ResourceRecord& rr = *i;
+                               if (rr.type == qtype)
+                                       return &rr;
+                       }
+
+                       return NULL;
+               }
        };
 
        class ReplySocket;
@@ -140,11 +150,12 @@ namespace DNS
 
        /** A DNS query.
         */
-       class Request : public Timer, public Question
+       class Request : public Timer
        {
         protected:
                Manager* const manager;
         public:
+               Question question;
                /* Use result cache if available */
                bool use_cache;
                /* Request id */
@@ -154,13 +165,12 @@ namespace DNS
 
                Request(Manager* mgr, Module* mod, const std::string& addr, QueryType qt, bool usecache = true)
                        : Timer((ServerInstance->Config->dns_timeout ? ServerInstance->Config->dns_timeout : 5))
-                       , Question(addr, qt)
                        , manager(mgr)
+                       , question(addr, qt)
                        , use_cache(usecache)
                        , id(0)
                        , creator(mod)
                {
-                       ServerInstance->Timers.AddTimer(this);
                }
 
                virtual ~Request()
@@ -183,7 +193,7 @@ namespace DNS
                 */
                bool Tick(time_t now)
                {
-                       Query rr(*this);
+                       Query rr(this->question);
                        rr.error = ERROR_TIMEDOUT;
                        this->OnError(&rr);
                        delete this;