]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dnsqueue.cpp
Decide that it wasn't quite appropriate :(
[user/henk/code/inspircd.git] / src / dnsqueue.cpp
index 78be4d8f18f0ada51384ebb5587470220eb483a2..8be3ea99b0b742a3312866e5b5c80aca0f6cf6f3 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -19,7 +19,6 @@ using namespace std;
 #include "inspircd_config.h"
 #include "inspircd.h"
 #include "inspircd_io.h"
-#include "inspircd_util.h"
 #include <unistd.h>
 #include <sys/errno.h>
 #include <sys/ioctl.h>
@@ -43,7 +42,6 @@ using namespace std;
 #include <time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/poll.h>
 #include <sys/time.h>
 #include <netinet/in.h>
 #include <string.h>
@@ -52,14 +50,14 @@ using namespace std;
 #include "hashcomp.h"
 #include "socketengine.h"
 
-extern SocketEngine* SE;
-typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
-extern user_hash clientlist;
-extern char DNSServer[MAXBUF];
+extern ServerConfig* Config;
+extern InspIRCd* ServerInstance;
+
+address_cache addrcache;
 
 class Lookup;
 
-Lookup* dnslist[65535];
+Lookup* dnslist[MAX_DESCRIPTORS];
 
 //enum LookupState { reverse, forward };
 
@@ -72,12 +70,14 @@ private:
 public:
        Lookup()
        {
-               strcpy(u,"");
+               *u = 0;
+               hostname = "";
        }
 
        void Reset()
        {
-               strcpy(u,"");
+               *u = 0;
+               hostname = "";
        }
 
        ~Lookup()
@@ -90,12 +90,12 @@ public:
                userrec* usr = Find(nick);
                if (usr)
                {
-                       resolver1.SetNS(std::string(DNSServer));
+                       resolver1.SetNS(std::string(Config->DNSServer));
                        if (!resolver1.ReverseLookup(std::string(usr->host)))
                        {
                                return false;
                        }
-                       strlcpy(u,nick.c_str(),NICKMAX);
+                       strlcpy(u,nick.c_str(),NICKMAX-1);
 
                        /* ASSOCIATE WITH DNS LOOKUP LIST */
                        if (resolver1.GetFD() != -1)
@@ -129,10 +129,17 @@ public:
                                                }
                                                if ((hostname != "") && (usr->registered != 7))
                                                {
-                                                       if (std::string(usr->ip) == ip)
+                                                       if (std::string((char*)inet_ntoa(usr->ip4)) == ip)
                                                        {
                                                                strlcpy(usr->host,hostname.c_str(),MAXBUF);
                                                                strlcpy(usr->dhost,hostname.c_str(),MAXBUF);
+                                                               /*address_cache::iterator address = addrcache.find(usr->ip4);
+                                                               if (address == addrcache.end())
+                                                               {
+                                                                       log(DEBUG,"Caching hostname %s -> %s",(char*)inet_ntoa(usr->ip4),hostname.c_str());
+                                                                       addrcache[usr->ip4] = new std::string(hostname);
+                                                               }*/
+                                                               WriteServ(usr->fd,"NOTICE Auth :*** Found your hostname");
                                                        }
                                                        usr->dns_done = true;
                                                        return true;
@@ -172,6 +179,7 @@ public:
                                        {
                                                if ((usr->registered > 3) || (hostname == ""))
                                                {
+                                                       WriteServ(usr->fd,"NOTICE Auth :*** Could not resolve your hostname -- Using your IP address instead");
                                                        usr->dns_done = true;
                                                        return true;
                                                }
@@ -205,6 +213,17 @@ bool lookup_dns(std::string nick)
        userrec* u = Find(nick);
        if (u)
        {
+               /* Check the cache */
+               /*address_cache::iterator address = addrcache.find(u->ip4);
+               if (address != addrcache.end())
+               {
+                       WriteServ(u->fd,"NOTICE Auth :*** Found your hostname (cached)");
+                       log(DEBUG,"Found cached host");
+                       strlcpy(u->host,address->second->c_str(),MAXBUF);
+                       strlcpy(u->dhost,address->second->c_str(),MAXBUF);
+                       u->dns_done = true;
+                       return true;
+               }*/
                /* If the user exists, create a new
                 * lookup object, and associate it
                 * with the user. The lookup object
@@ -229,7 +248,7 @@ bool lookup_dns(std::string nick)
 void dns_poll(int fdcheck)
 {
        /* Check the given file descriptor is in valid range */
-       if ((fdcheck < 0) || (fdcheck > 65535))
+       if ((fdcheck < 0) || (fdcheck > MAX_DESCRIPTORS))
                return;
 
        /* Try and find the file descriptor in our list of
@@ -268,6 +287,7 @@ void dns_poll(int fdcheck)
         * just to be safe so we dont get any more events
         * about it.
         */
-       SE->DelFd(fdcheck);
+       if (ServerInstance && ServerInstance->SE)
+               ServerInstance->SE->DelFd(fdcheck);
 }