]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/resolvers.h
Allow multiple autoconnects in a single <autoconnect> tag, fix infinite failover
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / resolvers.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 "socket.h"
18 #include "inspircd.h"
19 #include "xline.h"
20 #include "../transport.h"
21
22 #include "utils.h"
23 #include "link.h"
24
25 /** Handle resolving of server IPs for the cache
26  */
27 class SecurityIPResolver : public Resolver
28 {
29  private:
30         reference<Link> MyLink;
31         SpanningTreeUtilities* Utils;
32         Module* mine;
33         std::string host;
34         QueryType query;
35  public:
36         SecurityIPResolver(Module* me, SpanningTreeUtilities* U, const std::string &hostname, Link* x, bool &cached, QueryType qt)
37                 : Resolver(hostname, qt, cached, me), MyLink(x), Utils(U), mine(me), host(hostname), query(qt)
38         {
39         }
40
41         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
42         {
43                 Utils->ValidIPs.push_back(result);
44         }
45
46         void OnError(ResolverError e, const std::string &errormessage)
47         {
48                 if (query == DNS_QUERY_AAAA)
49                 {
50                         bool cached;
51                         SecurityIPResolver* res = new SecurityIPResolver(mine, Utils, host, MyLink, cached, DNS_QUERY_A);
52                         ServerInstance->AddResolver(res, cached);
53                         return;
54                 }
55                 ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Could not resolve IP associated with Link '%s': %s",
56                         MyLink->Name.c_str(),errormessage.c_str());
57         }
58 };
59
60 /** This class is used to resolve server hostnames during /connect and autoconnect.
61  * As of 1.1, the resolver system is seperated out from BufferedSocket, so we must do this
62  * resolver step first ourselves if we need it. This is totally nonblocking, and will
63  * callback to OnLookupComplete or OnError when completed. Once it has completed we
64  * will have an IP address which we can then use to continue our connection.
65  */
66 class ServernameResolver : public Resolver
67 {
68  private:
69         SpanningTreeUtilities* Utils;
70         QueryType query;
71         std::string host;
72         Module* mine;
73         reference<Link> MyLink;
74         reference<Autoconnect> myautoconnect;
75  public:
76         ServernameResolver(Module* me, SpanningTreeUtilities* Util, const std::string &hostname, Link* x, bool &cached, QueryType qt, Autoconnect* myac);
77         void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached);
78         void OnError(ResolverError e, const std::string &errormessage);
79 };
80
81 #endif