]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dnsqueue.cpp
Fixes to way allocations are handled
[user/henk/code/inspircd.git] / src / dnsqueue.cpp
index 71ab99019d19b9f5d61ecdb82aba06daa17b926d..1e1aa33c85a75d5c9412cb23a6c02b7723ac10e5 100644 (file)
@@ -127,6 +127,8 @@ struct StrHashComp
                char a[MAXBUF],b[MAXBUF];
                strlcpy(a,s1.c_str(),MAXBUF);
                strlcpy(b,s2.c_str(),MAXBUF);
+                strlower(a);
+                strlower(b);
                return (strcasecmp(a,b) == 0);
        }
 
@@ -162,30 +164,27 @@ extern command_table cmdlist;
 extern ClassVector Classes;
 
 extern char DNSServer[MAXBUF];
+long max_fd_alloc = 0;
+
+extern time_t TIME;
 
 class Lookup {
 private:
-       DNS* resolver;
+       DNS resolver;
        char u[NICKMAX];
 public:
        Lookup()
        {
                strcpy(u,"");
-               resolver = NULL;
        }
 
        void Reset()
        {
                strcpy(u,"");
-               if (resolver)
-                       delete resolver;
-               resolver = NULL;
        }
 
        ~Lookup()
        {
-               if (resolver)
-                       delete resolver;
        }
 
        bool DoLookup(std::string nick)
@@ -194,8 +193,8 @@ public:
                if (usr)
                {
                        log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer);
-                       resolver = new DNS(std::string(DNSServer));
-                       if (!resolver->ReverseLookup(std::string(usr->host)))
+                       resolver.SetNS(DNSServer);
+                       if (!resolver.ReverseLookup(usr->host))
                                return false;
                        strlcpy(u,nick.c_str(),NICKMAX);
                        return true;
@@ -206,11 +205,11 @@ public:
        bool Done()
        {
                userrec* usr = NULL;
-               if (resolver->HasResult())
+               if (resolver.HasResult())
                {
-                       if (resolver->GetFD() != 0)
+                       if (resolver.GetFD() != 0)
                        {
-                               std::string hostname = resolver->GetResult();
+                               std::string hostname = resolver.GetResult();
                                usr = Find(u);
                                if (usr)
                                {
@@ -222,6 +221,7 @@ public:
                                        if ((hostname != "") && (usr->registered != 7))
                                        {
                                                strlcpy(usr->host,hostname.c_str(),MAXBUF);
+                                               strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
                                                WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str());
                                                usr->dns_done = true;
                                                return true;
@@ -244,9 +244,11 @@ public:
        int GetFD()
        {
                userrec* usr = Find(u);
-               if (usr)
-                       return usr->fd;
-               else return 0;
+               if (!usr)
+                       return 0;
+               if (usr->dns_done)
+                       return 0;
+               return usr->fd;
        }
 };
 
@@ -271,6 +273,10 @@ bool lookup_dns(std::string nick)
                                        return true;
                                }
                        }
+                       // calculate the maximum value, this saves cpu time later
+                       for (int p = 0; p < MAXBUF; p++)
+                               if (dnsq[p].GetFD())
+                                       max_fd_alloc = p;
                }
                else
                {
@@ -283,7 +289,7 @@ bool lookup_dns(std::string nick)
 void dns_poll()
 {
        // do we have items in the queue?
-       for (int j = 0; j < MAXBUF; j++)
+       for (int j = 0; j <= max_fd_alloc; j++)
        {
                // are any ready, or stale?
                if (dnsq[j].GetFD())
@@ -294,5 +300,11 @@ void dns_poll()
                        }
                }
        }
+       // looks like someones freed an item, recalculate end of list.
+       if ((!dnsq[max_fd_alloc].GetFD()) && (max_fd_alloc != 0))
+               for (int p = 0; p < MAXBUF; p++)
+                       if (dnsq[p].GetFD())
+                               max_fd_alloc = p;
+
 }