* The core uses this to route results to the correct objects.
*/
int myid;
+
+ /**
+ * Cached result, if there is one
+ */
+ CachedQuery *CQ;
+
+ /**
+ * Time left before cache expiry
+ */
+ int time_left;
public:
/**
* Initiate DNS lookup. Your class should not attempt to delete or free these
* When your lookup completes, this method will be called.
* @param result The resulting DNS lookup, either an IP address or a hostname.
*/
- virtual void OnLookupComplete(const std::string &result, unsigned int ttl);
+ virtual void OnLookupComplete(const std::string &result, unsigned int ttl) = 0;
/**
* If an error occurs (such as NXDOMAIN, no domain name found) then this method
* will be called.
* Returns the creator module, or NULL
*/
Module* GetCreator();
+
+ void TriggerCachedResult();
};
/** DNS is a singleton class used by the core to dispatch dns
/** Add a dns Resolver class to this server's active set
* @param r The resolver to add
+ * @param cached The value of 'cached' which you passed to the Resolver constructor before this function.
* @return True if the resolver was added
*/
- bool AddResolver(Resolver* r);
+ bool AddResolver(Resolver* r, bool cached);
/** Add a command to this server's command parser
* @param f A command_t command handler object to add
cache->erase(source.c_str());
}
-void Resolver::OnLookupComplete(const std::string &result, unsigned int ttl)
+void Resolver::TriggerCachedResult()
{
- throw CoreException("Someone didnt define an OnLookupComplete method for their Resolver class!");
+ if (CQ)
+ OnLookupComplete(CQ->data, time_left);
}
/** High level abstraction of dns used by application at large */
cached = false;
- CachedQuery* CQ = ServerInstance->Res->GetCache(source);
+ CQ = ServerInstance->Res->GetCache(source);
if (CQ)
{
- int time_left = CQ->CalcTTLRemaining();
+ time_left = CQ->CalcTTLRemaining();
if (!time_left)
{
ServerInstance->Log(DEBUG,"Cached but EXPIRED result: %s", CQ->data.c_str());
{
cached = true;
ServerInstance->Log(DEBUG,"Cached result: %s", CQ->data.c_str());
- OnLookupComplete(CQ->data, time_left);
return;
}
}
return this->Modes->DelModeWatcher(mw);
}
-bool InspIRCd::AddResolver(Resolver* r)
+bool InspIRCd::AddResolver(Resolver* r, bool cached)
{
- return this->Res->AddResolverClass(r);
+ if (!cached)
+ return this->Res->AddResolverClass(r);
+ else
+ {
+ r->TriggerCachedResult();
+ delete r;
+ return true;
+ }
}
bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
{
bool cached;
resolver = new SQLresolver(this, ServerInstance, host, cached);
- if (!cached)
- ServerInstance->AddResolver(resolver);
- else
- delete resolver;
+ ServerInstance->AddResolver(resolver, cached);
}
catch(...)
{
{
bool cached;
CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, user->password, false, user, user->GetFd(), "PASS", cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
ServerInstance->Log(DEBUG,"MAKE RESOLVER: %s %d %s",newip, user->GetFd(), "IDENT");
bool cached;
CGIResolver* r = new CGIResolver(this, ServerInstance, NotifyOpers, newip, false, user, user->GetFd(), "IDENT", cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
/* now we'd need to fire off lookups for `hostname'. */
bool cached;
DNSBLResolver *r = new DNSBLResolver(this, ServerInstance, hostname, user, user->GetFd(), *i, cached);
- if (!cached)
- ServerInstance->AddResolver(r);
- else
- delete r;
+ ServerInstance->AddResolver(r, cached);
}
}
{
bool cached;
HTTPResolver* r = new HTTPResolver(this, Server, url.domain, cached, (Module*)Mod);
- if (!cached)
- Instance->AddResolver(r);
- else
- delete r;
+ Instance->AddResolver(r, cached);
return true;
}
else
{
bool cached;
SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached);
- if (!cached)
- ServerInstance->AddResolver(sr);
- else
- delete sr;
+ ServerInstance->AddResolver(sr, cached);
}
catch (ModuleException& e)
{
{
bool cached;
ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached);
- if (!cached)
- ServerInstance->AddResolver(snr);
- else
- delete snr;
+ ServerInstance->AddResolver(snr, cached);
}
catch (ModuleException& e)
{
* do it for us as required.*/
try
{
- bool cached1, cached2;
- MyV6Resolver* r = new MyV6Resolver(ServerInstance, Creator, "shake.stacken.kth.se", true, cached1);
- if (!cached1)
- ServerInstance->AddResolver(r);
- else
- {
- ServerInstance->Log(DEBUG,"Result was cached, delete object");
- delete r;
- }
-
- r = new MyV6Resolver(ServerInstance, Creator, "2001:6b0:1:ea:202:a5ff:fecd:13a6", false, cached2);
- if (!cached2)
- ServerInstance->AddResolver(r);
- else
- {
- ServerInstance->Log(DEBUG,"Result was cached, delete object");
- delete r;
- }
+ bool cached;
+ MyV6Resolver* r = new MyV6Resolver(ServerInstance, Creator, "shake.stacken.kth.se", true, cached);
+ ServerInstance->AddResolver(r, cached);
+ r = new MyV6Resolver(ServerInstance, Creator, "2001:6b0:1:ea:202:a5ff:fecd:13a6", false, cached);
+ ServerInstance->AddResolver(r, cached);
}
catch (ModuleException& e)
{
ServerInstance->Log(DEBUG,"Passing instance: %08x",this->ServerInstance);
bool cached;
res_reverse = new UserResolver(this->ServerInstance, this, this->GetIPString(), DNS_QUERY_REVERSE, cached);
- if (!cached)
- this->ServerInstance->AddResolver(res_reverse);
- else
- delete res_reverse;
+ this->ServerInstance->AddResolver(res_reverse, cached);
}
catch (CoreException& e)
{
#else
bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, DNS_QUERY_A, cached);
#endif
- if (!cached)
- this->ServerInstance->AddResolver(bound_user->res_forward);
- else
- delete bound_user->res_forward;
+ this->ServerInstance->AddResolver(bound_user->res_forward, cached);
}
}
catch (CoreException& e)