+/** This class is used to resolve server hostnames during /connect and autoconnect.
+ * As of 1.1, the resolver system is seperated out from InspSocket, so we must do this
+ * resolver step first ourselves if we need it. This is totally nonblocking, and will
+ * callback to OnLookupComplete or OnError when completed. Once it has completed we
+ * will have an IP address which we can then use to continue our connection.
+ */
+class ServernameResolver : public Resolver
+{
+ private:
+ /** A copy of the Link tag info for what we're connecting to.
+ * We take a copy, rather than using a pointer, just in case the
+ * admin takes the tag away and rehashes while the domain is resolving.
+ */
+ Link MyLink;
+ public:
+ ServernameResolver(const std::string &hostname, Link x) : Resolver(hostname, DNS_QUERY_FORWARD), MyLink(x)
+ {
+ /* Nothing in here, folks */
+ }
+
+ void OnLookupComplete(const std::string &result)
+ {
+ /* Initiate the connection, now that we have an IP to use.
+ * Passing a hostname directly to InspSocket causes it to
+ * just bail and set its FD to -1.
+ */
+ TreeServer* CheckDupe = FindServer(MyLink.Name.c_str());
+ if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
+ {
+ TreeSocket* newsocket = new TreeSocket(result,MyLink.Port,false,10,MyLink.Name.c_str());
+ if (newsocket->GetFd() > -1)
+ {
+ /* We're all OK */
+ Srv->AddSocket(newsocket);
+ }
+ else
+ {
+ /* Something barfed, show the opers */
+ WriteOpers("*** CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
+ delete newsocket;
+ }
+ }
+ }
+
+ void OnError(ResolverError e, const std::string &errormessage)
+ {
+ /* Ooops! */
+ WriteOpers("*** CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s",MyLink.Name.c_str(),errormessage.c_str());
+ }
+};
+
+class SecurityIPResolver : public Resolver
+{
+ private:
+ Link MyLink;
+ public:
+ SecurityIPResolver(const std::string &hostname, Link x) : Resolver(hostname, DNS_QUERY_FORWARD), MyLink(x)
+ {
+ }
+
+ void OnLookupComplete(const std::string &result)
+ {
+ log(DEBUG,"Security IP cache: Adding IP address '%s' for Link '%s'",result.c_str(),MyLink.Name.c_str());
+ ValidIPs.push_back(result);
+ }
+
+ void OnError(ResolverError e, const std::string &errormessage)
+ {
+ log(DEBUG,"Could not resolve IP associated with Link '%s': %s",MyLink.Name.c_str(),errormessage.c_str());
+ }
+};
+