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