From fca2a3c8ea88ecfefd3bfb729bcdcdb674bbe946 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 1 Apr 2005 22:11:22 +0000 Subject: Attempts to fix some random crashes git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@943 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/commands.cpp | 2 +- src/dnsqueue.cpp | 63 ++++++++++++++++++++++++++++++++++---------------------- src/inspircd.cpp | 11 +++++----- 3 files changed, 45 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/commands.cpp b/src/commands.cpp index 0af56645d..a52142ae7 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1643,7 +1643,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user) user->registered = (user->registered | 2); // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change // and unless we're lucky we'll get a duff one later on. - lookup_dns(user); + lookup_dns(user->nick); } if (user->registered == 3) { diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 4c328e71c..d74c73ada 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -167,11 +167,11 @@ extern char DNSServer[MAXBUF]; class Lookup { private: DNS* resolver; - userrec* u; + char u[NICKMAX]; public: Lookup() { - u = NULL; + strcpy(u,""); resolver = NULL; } @@ -181,31 +181,37 @@ public: delete resolver; } - Lookup(userrec* user) + Lookup(std::string nick) { - u = user; - log(DEBUG,"New Lookup class with DNSServer set to '%s'",DNSServer); - resolver = new DNS(std::string(DNSServer)); - resolver->ReverseLookup(std::string(user->host)); + userrec* usr = Find(nick); + if (usr) + { + log(DEBUG,"New Lookup class for %s with DNSServer set to '%s'",nick.c_str(),DNSServer); + resolver = new DNS(std::string(DNSServer)); + resolver->ReverseLookup(std::string(usr->host)); + strlcpy(u,nick.c_str(),NICKMAX); + } } bool Done() { + userrec* usr = NULL; if (resolver->HasResult()) { log(DEBUG,"resolver says result available!"); if (resolver->GetFD() != 0) { - log(DEBUG,"Resolver FD is not 0"); + log(DEBUG,"Resolver FD is not 0, getting %s",u); std::string hostname = resolver->GetResult(); - if (u) + usr = Find(u); + if (usr) { - log(DEBUG,"Applying hostname lookup to %s: %s",u->nick,hostname.c_str()); + log(DEBUG,"Applying hostname lookup to %s: %s",usr->nick,hostname.c_str()); if (hostname != "") { - strlcpy(u->host,hostname.c_str(),MAXBUF); - WriteServ(u->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str()); - u->dns_done = true; + strlcpy(usr->host,hostname.c_str(),MAXBUF); + WriteServ(usr->fd,"NOTICE Auth :Resolved your hostname: %s",hostname.c_str()); + usr->dns_done = true; return true; } return false; @@ -213,7 +219,7 @@ public: } else { - u->dns_done = true; + usr->dns_done = true; return true; } } @@ -222,26 +228,32 @@ public: int GetFD() { - if (u) + userrec* usr = Find(u); + if (usr) { - return u->fd; + return usr->fd; } else return 0; } }; -typedef std::vector dns_queue; +typedef std::deque dns_queue; dns_queue dnsq; -bool lookup_dns(userrec* u) +bool lookup_dns(std::string nick) { - // place a new user into the queue... - log(DEBUG,"Queueing DNS lookup for %s",u->nick); - WriteServ(u->fd,"NOTICE Auth :Looking up your hostname..."); - Lookup L(u); - dnsq.push_back(L); - return true; + userrec* u = Find(nick); + if (u) + { + // place a new user into the queue... + log(DEBUG,"Queueing DNS lookup for %s",u->nick); + WriteServ(u->fd,"NOTICE Auth :Looking up your hostname..."); + Lookup L(nick); + dnsq.push_back(L); + return true; + } + return false; } void dns_poll() @@ -253,7 +265,8 @@ void dns_poll() if (dnsq[0].Done() || (!dnsq[0].GetFD())) { log(DEBUG,"****** DNS lookup for fd %d is complete. ******",dnsq[0].GetFD()); - dnsq.erase(dnsq.begin()); + if (dnsq[0].GetFD()) + dnsq.pop_front(); } } } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 5a16c9851..18b220e18 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -98,7 +98,7 @@ std::vector module_names; extern std::vector factory; std::vector fd_reap; -std::vector pending_connects; +std::vector pending_connects; extern int MODCOUNT; @@ -1056,7 +1056,7 @@ void strlower(char *n) /* Find a user record by nickname and return a pointer to it */ -userrec* Find(string nick) +userrec* Find(std::string nick) { user_hash::iterator iter = clientlist.find(nick); @@ -2442,9 +2442,10 @@ void HandlePendingConnects() { if (pending_connects.size()) { - for (std::vector::iterator i = pending_connects.begin(); i <= pending_connects.end(); i++) + for (std::vector::iterator i = pending_connects.begin(); i <= pending_connects.end(); i++) { - userrec* a = *i; + std::string t = *i; + userrec* a = Find(t); if (a) { // this user's dns is done now. @@ -2478,7 +2479,7 @@ void ConnectUser(userrec *user) else { // add them to the pending queue - pending_connects.push_back(user); + pending_connects.push_back(user->nick); } } -- cgit v1.2.3