]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move more stuff into private members of class DNS
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Aug 2006 20:34:23 +0000 (20:34 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Aug 2006 20:34:23 +0000 (20:34 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4654 e03df62e-2008-0410-955e-edbf42e46eb7

include/dns.h
src/dns.cpp

index 5ef3f60e52f49adf2415df2d103e93e997753de3..4b5d5df377c2e040fb9244f46efc4ce2db8840a7 100644 (file)
@@ -57,6 +57,13 @@ enum ResolverError
 
 class DNSRequest;
 class DNSHeader;
+class ResourceRecord;
+
+/* A set of requests keyed by request id */
+typedef std::map<int,DNSRequest*> requestlist;
+
+/* An iterator into a set of requests */
+typedef requestlist::iterator requestlist_iter;
 
 /**
  * The Resolver class is a high-level abstraction for resolving DNS entries.
@@ -144,17 +151,26 @@ class Resolver : public Extensible
 class DNS : public Extensible
 {
  private:
+
+       requestlist requests;
        insp_inaddr myserver;
        static int MasterSocket;
        Resolver* Classes[65536];
+       int MakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload);
+
  public:
+
+       static void FillResourceRecord(ResourceRecord* rr, const unsigned char *input);
+       static void FillHeader(DNSHeader *header, const unsigned char *input, const int length);
+       static void EmptyHeader(unsigned char *output, const DNSHeader *header, const int length);
        static int GetMasterSocket();
+
        int GetIP(const char* name);
        int GetName(const insp_inaddr* ip);
        DNSResult GetResult();
        void MarshallReads(int fd);
        bool AddResolverClass(Resolver* r);
-       DNSRequest* DNSAddQuery(DNSHeader *header, int &id);
+       DNSRequest* AddQuery(DNSHeader *header, int &id);
        DNS();
        ~DNS();
 };
index cf1f02a5963edb708dfe902b8b7e9834cf621340..60318dcc337b0b1d9ca729eae9148c1a3135925b 100644 (file)
@@ -135,15 +135,6 @@ class DNSRequest
        int SendRequests(const DNSHeader *header, const int length, QueryType qt);
 };
 
-/* A set of requests keyed by request id */
-typedef std::map<int,DNSRequest*> requestlist;
-
-/* An iterator into a set of requests */
-typedef requestlist::iterator requestlist_iter;
-
-/* Declare our map */
-requestlist requests;
-
 /*
  * Optimized by brain, these were using integer division and modulus.
  * We can use logic shifts and logic AND to replace these even divisions
@@ -153,7 +144,7 @@ requestlist requests;
 
 
 /* Fill a ResourceRecord class based on raw data input */
-inline void DNSFillResourceRecord(ResourceRecord* rr, const unsigned char *input)
+inline void DNS::FillResourceRecord(ResourceRecord* rr, const unsigned char *input)
 {
        rr->type = (QueryType)((input[0] << 8) + input[1]);
        rr->rr_class = (input[2] << 8) + input[3];
@@ -162,7 +153,7 @@ inline void DNSFillResourceRecord(ResourceRecord* rr, const unsigned char *input
 }
 
 /* Fill a DNSHeader class based on raw data input of a given length */
-inline void DNSFillHeader(DNSHeader *header, const unsigned char *input, const int length)
+inline void DNS::FillHeader(DNSHeader *header, const unsigned char *input, const int length)
 {
        header->id[0] = input[0];
        header->id[1] = input[1];
@@ -176,7 +167,7 @@ inline void DNSFillHeader(DNSHeader *header, const unsigned char *input, const i
 }
 
 /* Empty a DNSHeader class out into raw data, ready for transmission */
-inline void DNSEmptyHeader(unsigned char *output, const DNSHeader *header, const int length)
+inline void DNS::EmptyHeader(unsigned char *output, const DNSHeader *header, const int length)
 {
        output[0] = header->id[0];
        output[1] = header->id[1];
@@ -202,7 +193,7 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
        this->rr_class = 1;
        this->type = qt;
                
-       DNSEmptyHeader(payload,header,length);
+       DNS::EmptyHeader(payload,header,length);
 
        memset(&addr,0,sizeof(addr));
 #ifdef IPV6
@@ -224,7 +215,7 @@ int DNSRequest::SendRequests(const DNSHeader *header, const int length, QueryTyp
 }
 
 /* Add a query with a predefined header, and allocate an ID for it. */
-DNSRequest* DNS::DNSAddQuery(DNSHeader *header, int &id)
+DNSRequest* DNS::AddQuery(DNSHeader *header, int &id)
 {
        id = rand() % 65536;
        DNSRequest* req = new DNSRequest(this->myserver);
@@ -305,7 +296,7 @@ DNS::DNS()
        }
 }
 
-int DNSMakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload)
+int DNS::MakePayload(const char * const name, const unsigned short rr, const unsigned short rr_class, unsigned char * const payload)
 {
        short payloadpos;
        const char * tempchr, * tempchr2;
@@ -351,10 +342,10 @@ int DNS::GetIP(const char *name)
        int length;
        DNSRequest* req;
        
-       if ((length = DNSMakePayload(name,DNS_QRY_A,1,(unsigned char*)&h.payload)) == -1)
+       if ((length = this->MakePayload(name,DNS_QRY_A,1,(unsigned char*)&h.payload)) == -1)
                return -1;
 
-       req = DNSAddQuery(&h, id);
+       req = this->AddQuery(&h, id);
 
        if (req->SendRequests(&h,length,DNS_QRY_A) == -1)
                return -1;
@@ -377,10 +368,10 @@ int DNS::GetName(const insp_inaddr *ip)
 
        sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]);
 
-       if ((length = DNSMakePayload(query,DNS_QRY_PTR,1,(unsigned char*)&h.payload)) == -1)
+       if ((length = this->MakePayload(query,DNS_QRY_PTR,1,(unsigned char*)&h.payload)) == -1)
                return -1;
 
-       req = DNSAddQuery(&h, id);
+       req = this->AddQuery(&h, id);
 
        if (req->SendRequests(&h,length,DNS_QRY_PTR) == -1)
                return -1;
@@ -408,7 +399,7 @@ DNSResult DNS::GetResult()
                return std::make_pair(-1,"");
 
        /* Put the read header info into a header class */
-       DNSFillHeader(&header,buffer,length - 12);
+       DNS::FillHeader(&header,buffer,length - 12);
 
        /* Get the id of this request.
         * Its a 16 bit value stored in two char's,
@@ -536,7 +527,7 @@ DNSInfo DNSRequest::ResultIsReady(DNSHeader &header, int length)
                if (length - i < 10)
                        return std::make_pair((unsigned char*)NULL,"Incorrectly sized DNS reply");
 
-               DNSFillResourceRecord(&rr,&header.payload[i]);
+               DNS::FillResourceRecord(&rr,&header.payload[i]);
                i += 10;
                if (rr.type != this->type)
                {