summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-12 12:43:55 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-07-12 12:43:55 +0000
commitd4cb72e31251cf879e65854c82685dddf59072a6 (patch)
treec4bd6f8827179c9564ec61aeb2e4417830a48cd8 /src
parent1905cc30e04e59bd40f5106cc66b575b0e680177 (diff)
Make it work:
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4357 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/dns.cpp50
-rw-r--r--src/dnsqueue.cpp4
-rw-r--r--src/inspsocket.cpp2
-rw-r--r--src/message.cpp8
4 files changed, 48 insertions, 16 deletions
diff --git a/src/dns.cpp b/src/dns.cpp
index 06cff0757..89386664c 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -703,7 +703,7 @@ DNS::~DNS()
{
}
-bool DNS::ReverseLookup(const std::string &ip)
+bool DNS::ReverseLookup(const std::string &ip, bool ins)
{
if (ServerInstance && ServerInstance->stats)
ServerInstance->stats->statsDns++;
@@ -720,13 +720,16 @@ bool DNS::ReverseLookup(const std::string &ip)
}
log(DEBUG,"DNS: ReverseLookup, fd=%d",this->myfd);
#ifndef THREADED_DNS
- if (ServerInstance && ServerInstance->SE)
- ServerInstance->SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+ if (ins)
+ {
+ if (ServerInstance && ServerInstance->SE)
+ ServerInstance->SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+ }
#endif
return true;
}
-bool DNS::ForwardLookup(const std::string &host)
+bool DNS::ForwardLookup(const std::string &host, bool ins)
{
if (ServerInstance && ServerInstance->stats)
ServerInstance->stats->statsDns++;
@@ -737,8 +740,11 @@ bool DNS::ForwardLookup(const std::string &host)
}
log(DEBUG,"DNS: ForwardLookup, fd=%d",this->myfd);
#ifndef THREADED_DNS
- if (ServerInstance && ServerInstance->SE)
- ServerInstance->SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+ if (ins)
+ {
+ if (ServerInstance && ServerInstance->SE)
+ ServerInstance->SE->AddFd(this->myfd,true,X_ESTAB_DNS);
+ }
#endif
return true;
}
@@ -856,7 +862,7 @@ void* dns_task(void* arg)
host = dns1.GetResult();
if (host != "")
{
- if (dns2.ForwardLookup(host))
+ if (dns2.ForwardLookup(host), false)
{
while (!dns2.HasResult())
{
@@ -887,20 +893,37 @@ Resolver::Resolver(const std::string &source, bool forward, const std::string &d
Query.SetNS(Config->DNSServer);
if (forward)
- this->fd = Query.ForwardLookup(input.c_str());
+ {
+ Query.ForwardLookup(input.c_str(), false);
+ this->fd = Query.GetFD();
+ }
else
- this->fd = Query.ReverseLookup(input.c_str());
+ {
+ Query.ReverseLookup(input.c_str(), false);
+ this->Fd = Query.GetFD();
+ }
if (fd < 0)
+ {
+ log(DEBUG,"Resolver::Resolver: RESOLVER_NSDOWN");
this->OnError(RESOLVER_NSDOWN);
+ return;
+ }
if (ServerInstance && ServerInstance->SE)
+ {
+ log(DEBUG,"Resolver::Resolver: this->fd=%d",this->fd);
ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_CLASSDNS);
+ }
else
+ {
+ log(DEBUG,"Resolver::Resolver: RESOLVER_NOTREADY");
this->OnError(RESOLVER_NOTREADY);
+ }
}
Resolver::~Resolver()
{
+ log(DEBUG,"Resolver::~Resolver");
if (ServerInstance && ServerInstance->SE)
ServerInstance->SE->DelFd(this->fd);
}
@@ -912,6 +935,7 @@ int Resolver::GetFd()
bool Resolver::ProcessResult()
{
+ log(DEBUG,"Resolver::ProcessResult");
if (this->fwd)
result = Query.GetResultIP();
else
@@ -919,11 +943,13 @@ bool Resolver::ProcessResult()
if (result != "")
{
+ log(DEBUG,"Resolver::OnLookupComplete(%s)",result.c_str());
this->OnLookupComplete(result);
return true;
}
else
{
+ log(DEBUG,"Resolver::OnError(RESOLVER_NXDOMAIN)");
this->OnError(RESOLVER_NXDOMAIN);
return false;
}
@@ -939,8 +965,10 @@ void Resolver::OnError(ResolverError e)
void dns_deal_with_classes(int fd)
{
+ log(DEBUG,"dns_deal_with_classes(%d)",fd);
if ((fd > -1) && (dns_classes[fd]))
{
+ log(DEBUG,"Valid fd %d",fd);
dns_classes[fd]->ProcessResult();
delete dns_classes[fd];
dns_classes[fd] = NULL;
@@ -949,20 +977,24 @@ void dns_deal_with_classes(int fd)
bool dns_add_class(Resolver* r)
{
+ log(DEBUG,"dns_add_class");
if ((r) && (r->GetFd() > -1))
{
if (!dns_classes[r->GetFd()])
{
+ log(DEBUG,"dns_add_class: added class");
dns_classes[r->GetFd()] = r;
return true;
}
else
{
+ log(DEBUG,"Space occupied!");
return false;
}
}
else
{
+ log(DEBUG,"Bad class");
delete r;
return true;
}
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index 975884796..ce0422fde 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -71,7 +71,7 @@ public:
if (usr)
{
resolver1.SetNS(std::string(Config->DNSServer));
- if (!resolver1.ReverseLookup(std::string(usr->host)))
+ if (!resolver1.ReverseLookup(std::string(usr->host), true))
{
return false;
}
@@ -166,7 +166,7 @@ public:
}
if (hostname != "")
{
- resolver2.ForwardLookup(hostname);
+ resolver2.ForwardLookup(hostname, true);
if (resolver2.GetFD() != -1)
dnslist[resolver2.GetFD()] = this;
}
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index cc0368525..7f4041cb6 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -104,7 +104,7 @@ InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsi
log(DEBUG,"Attempting to resolve %s",this->host);
/* Its not an ip, spawn the resolver */
this->dns.SetNS(std::string(Config->DNSServer));
- this->dns.ForwardLookupWithFD(host,fd);
+ this->dns.ForwardLookupWithFD(host,fd, true);
timeout_end = time(NULL) + maxtime;
timeout = false;
this->state = I_RESOLVING;
diff --git a/src/message.cpp b/src/message.cpp
index 03bd5fd41..7c0b860dc 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -168,15 +168,15 @@ void NonBlocking(int s)
int CleanAndResolve (char *resolvedHost, const char *unresolvedHost, bool forward)
{
- int fd;
+ bool ok;
std::string ipaddr;
DNS d(Config->DNSServer);
if (forward)
- fd = d.ForwardLookup(unresolvedHost);
+ ok = d.ForwardLookup(unresolvedHost, false);
else
- fd = d.ReverseLookup(unresolvedHost);
- if (fd < 0)
+ ok = d.ReverseLookup(unresolvedHost, false);
+ if (!ok)
return 0;
time_t T = time(NULL)+1;
while ((!d.HasResult()) && (time(NULL)<T));