+ /* Nothing here (yet) either */
+}
+
+/** Get the request id associated with this class */
+int Resolver::GetId()
+{
+ return this->myid;
+}
+
+Module* Resolver::GetCreator()
+{
+ return this->Creator;
+}
+
+/** Process a socket read event */
+void DNS::HandleEvent(EventType, int)
+{
+ /* Fetch the id and result of the next available packet */
+ DNSResult res(0,"",0,"");
+ res.id = 0;
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"Handle DNS event");
+
+ res = this->GetResult();
+
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"Result id %d", res.id);
+
+ /* Is there a usable request id? */
+ if (res.id != -1)
+ {
+ /* Its an error reply */
+ if (res.id & ERROR_MASK)
+ {
+ /* Mask off the error bit */
+ res.id -= ERROR_MASK;
+ /* Marshall the error to the correct class */
+ if (Classes[res.id])
+ {
+ if (ServerInstance && ServerInstance->stats)
+ ServerInstance->stats->statsDnsBad++;
+ Classes[res.id]->OnError(RESOLVER_NXDOMAIN, res.result);
+ delete Classes[res.id];
+ Classes[res.id] = NULL;
+ }
+ return;
+ }
+ else
+ {
+ /* It is a non-error result, marshall the result to the correct class */
+ if (Classes[res.id])
+ {
+ if (ServerInstance && ServerInstance->stats)
+ ServerInstance->stats->statsDnsGood++;
+
+ if (!this->GetCache(res.original.c_str()))
+ this->cache->insert(std::make_pair(res.original.c_str(), CachedQuery(res.result, res.type, res.ttl)));
+
+ Classes[res.id]->OnLookupComplete(res.result, res.ttl, false);
+ delete Classes[res.id];
+ Classes[res.id] = NULL;
+ }
+ }
+
+ if (ServerInstance && ServerInstance->stats)
+ ServerInstance->stats->statsDns++;
+ }
+}
+
+/** Add a derived Resolver to the working set */
+bool DNS::AddResolverClass(Resolver* r)
+{
+ ServerInstance->Logs->Log("RESOLVER",DEBUG,"AddResolverClass 0x%08lx", (unsigned long)r);
+ /* Check the pointers validity and the id's validity */
+ if ((r) && (r->GetId() > -1))
+ {
+ /* Check the slot isnt already occupied -
+ * This should NEVER happen unless we have
+ * a severely broken DNS server somewhere
+ */
+ if (!Classes[r->GetId()])
+ {
+ /* Set up the pointer to the class */
+ Classes[r->GetId()] = r;
+ return true;
+ }
+ }
+
+ /* Pointer or id not valid, or duplicate id.
+ * Free the item and return
+ */
+ delete r;
+ return false;
+}
+
+void DNS::CleanResolvers(Module* module)
+{
+ for (int i = 0; i < MAX_REQUEST_ID; i++)
+ {
+ if (Classes[i])
+ {
+ if (Classes[i]->GetCreator() == module)
+ {
+ Classes[i]->OnError(RESOLVER_FORCEUNLOAD, "Parent module is unloading");
+ delete Classes[i];
+ Classes[i] = NULL;
+ }
+ }