]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/resolvers.h
InspSocket -> BufferedSocket. Paves the way for a SimpleSocket class which ident...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / resolvers.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __RESOLVERS__H__
15 #define __RESOLVERS__H__
16
17 #include "commands/cmd_whois.h"
18 #include "commands/cmd_stats.h"
19 #include "socket.h"
20 #include "inspircd.h"
21 #include "wildcard.h"
22 #include "xline.h"
23 #include "transport.h"
24
25 #include "m_spanningtree/utils.h"
26 #include "m_spanningtree/link.h"
27
28 /** Handle resolving of server IPs for the cache
29  */
30 class SecurityIPResolver : public Resolver
31 {
32  private:
33         Link MyLink;
34         SpanningTreeUtilities* Utils;
35         Module* mine;
36         std::string host;
37         QueryType query;
38  public:
39         SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached, QueryType qt)
40                 : Resolver(Instance, hostname, qt, cached, me), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
41         {
42         }
43
44         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0)
45         {
46                 Utils->ValidIPs.push_back(result);
47         }
48
49         void OnError(ResolverError e, const std::string &errormessage)
50         {
51                 if (query == DNS_QUERY_AAAA)
52                 {
53                         bool cached;
54                         SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, ServerInstance, host, MyLink, cached, DNS_QUERY_A);
55                         ServerInstance->AddResolver(res, cached);
56                         return;
57                 }
58                 ServerInstance->Log(DEFAULT,"Could not resolve IP associated with Link '%s': %s",MyLink.Name.c_str(),errormessage.c_str());
59         }
60 };
61
62 /** This class is used to resolve server hostnames during /connect and autoconnect.
63  * As of 1.1, the resolver system is seperated out from BufferedSocket, so we must do this
64  * resolver step first ourselves if we need it. This is totally nonblocking, and will
65  * callback to OnLookupComplete or OnError when completed. Once it has completed we
66  * will have an IP address which we can then use to continue our connection.
67  */
68 class ServernameResolver : public Resolver
69 {
70  private:
71         /** A copy of the Link tag info for what we're connecting to.
72          * We take a copy, rather than using a pointer, just in case the
73          * admin takes the tag away and rehashes while the domain is resolving.
74          */
75         Link MyLink;
76         SpanningTreeUtilities* Utils;
77         QueryType query;
78         std::string host;
79         Module* mine;
80  public:
81         ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached, QueryType qt);
82         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0);
83         void OnError(ResolverError e, const std::string &errormessage);
84 };
85
86 #endif