]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/resolvers.h
53adaa50f74121d0afbacb5a07acfb37f9e38c86
[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 "configreader.h"
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21 #include "commands/cmd_whois.h"
22 #include "commands/cmd_stats.h"
23 #include "socket.h"
24 #include "inspircd.h"
25 #include "wildcard.h"
26 #include "xline.h"
27 #include "transport.h"
28
29 #include "m_spanningtree/utils.h"
30 #include "m_spanningtree/link.h"
31
32 /** Handle resolving of server IPs for the cache
33  */
34 class SecurityIPResolver : public Resolver
35 {
36  private:
37         Link MyLink;
38         SpanningTreeUtilities* Utils;
39         Module* mine;
40         std::string host;
41         QueryType query;
42  public:
43         SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached, QueryType qt)
44                 : Resolver(Instance, hostname, qt, cached, me), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
45         {
46         }
47
48         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0)
49         {
50                 Utils->ValidIPs.push_back(result);
51         }
52
53         void OnError(ResolverError e, const std::string &errormessage)
54         {
55                 if (query == DNS_QUERY_AAAA)
56                 {
57                         bool cached;
58                         SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, ServerInstance, host, MyLink, cached, DNS_QUERY_A);
59                         ServerInstance->AddResolver(res, cached);
60                         return;
61                 }
62                 ServerInstance->Log(DEFAULT,"Could not resolve IP associated with Link '%s': %s",MyLink.Name.c_str(),errormessage.c_str());
63         }
64 };
65
66 /** This class is used to resolve server hostnames during /connect and autoconnect.
67  * As of 1.1, the resolver system is seperated out from InspSocket, so we must do this
68  * resolver step first ourselves if we need it. This is totally nonblocking, and will
69  * callback to OnLookupComplete or OnError when completed. Once it has completed we
70  * will have an IP address which we can then use to continue our connection.
71  */
72 class ServernameResolver : public Resolver
73 {
74  private:
75         /** A copy of the Link tag info for what we're connecting to.
76          * We take a copy, rather than using a pointer, just in case the
77          * admin takes the tag away and rehashes while the domain is resolving.
78          */
79         Link MyLink;
80         SpanningTreeUtilities* Utils;
81         QueryType query;
82         std::string host;
83         Module* mine;
84  public:
85         ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached, QueryType qt);
86         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum = 0);
87         void OnError(ResolverError e, const std::string &errormessage);
88 };
89
90 #endif