summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-01 22:11:22 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-01 22:11:22 +0000
commitfca2a3c8ea88ecfefd3bfb729bcdcdb674bbe946 (patch)
treebbf962e30e47c0f30b30a471ad6e315c34992efc /src
parent7f4395d336c331dd434bca91b6273c072f26e1bc (diff)
Attempts to fix some random crashes
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@943 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/commands.cpp2
-rw-r--r--src/dnsqueue.cpp63
-rw-r--r--src/inspircd.cpp11
3 files changed, 45 insertions, 31 deletions
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<Lookup> dns_queue;
+typedef std::deque<Lookup> 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<std::string> module_names;
extern std::vector<ircd_module*> factory;
std::vector<int> fd_reap;
-std::vector<userrec*> pending_connects;
+std::vector<std::string> 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<userrec*>::iterator i = pending_connects.begin(); i <= pending_connects.end(); i++)
+ for (std::vector<std::string>::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);
}
}