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