]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Update Event and Request APIs
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.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 __ST__UTIL__
15 #define __ST__UTIL__
16
17 #include "inspircd.h"
18
19 /* Foward declarations */
20 class TreeServer;
21 class TreeSocket;
22 class Link;
23 class Autoconnect;
24 class ModuleSpanningTree;
25 class SpanningTreeUtilities;
26
27 /* This hash_map holds the hash equivalent of the server
28  * tree, used for rapid linear lookups.
29  */
30 #if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
31         typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
32 #else
33         #ifdef HASHCOMP_DEPRECATED
34                 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
35         #else
36                 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
37         #endif
38 #endif
39
40 /*
41  * Initialises server connections
42  */
43 class ServerSocketListener : public ListenSocketBase
44 {
45         SpanningTreeUtilities *Utils;
46
47  public:
48         ServerSocketListener(SpanningTreeUtilities *u, int port, const std::string& addr, const std::string& hook)
49                 : ListenSocketBase(port, addr), Utils(u), Hook(hook)
50         {
51         }
52
53         std::string Hook;
54
55         virtual void OnAcceptReady(int nfd);
56 };
57
58 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
59
60 /** Contains helper functions and variables for this module,
61  * and keeps them out of the global namespace
62  */
63 class SpanningTreeUtilities : public classbase
64 {
65  public:
66         /** Creator module
67          */
68         ModuleSpanningTree* Creator;
69
70         /** Flatten links and /MAP for non-opers
71          */
72         bool FlatLinks;
73         /** Hide U-Lined servers in /MAP and /LINKS
74          */
75         bool HideULines;
76         /** Announce TS changes to channels on merge
77          */
78         bool AnnounceTSChange;
79
80         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
81          */
82         bool AllowOptCommon;
83
84         /** Make snomasks +CQ quiet during bursts and splits
85          */
86         bool quiet_bursts;
87
88         /** Socket bindings for listening sockets
89          */
90         std::vector<ServerSocketListener *> Bindings;
91         /* Number of seconds that a server can go without ping
92          * before opers are warned of high latency.
93          */
94         int PingWarnTime;
95         /** This variable represents the root of the server tree
96          */
97         TreeServer *TreeRoot;
98         /** Represents the server whose command we are processing
99          */
100         FakeUser *ServerUser;
101         /** IPs allowed to link to us
102          */
103         std::vector<std::string> ValidIPs;
104         /** Hash of currently connected servers by name
105          */
106         server_hash serverlist;
107         /** Hash of currently known server ids
108          */
109         server_hash sidlist;
110         /** Hash of servers currently bursting but not initialized as connected
111          */
112         std::map<irc::string,TreeSocket*> burstingserverlist;
113         /** List of all outgoing sockets and their timeouts
114          */
115         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
116         /** Holds the data from the <link> tags in the conf
117          */
118         std::vector<reference<Link> > LinkBlocks;
119         /** Holds the data from the <autoconnect> tags in the conf
120          */
121         std::vector<reference<Autoconnect> > AutoconnectBlocks;
122
123         /** True (default) if we are to use challenge-response HMAC
124          * to authenticate passwords.
125          *
126          * NOTE: This defaults to on, but should be turned off if
127          * you are linking to an older version of inspircd.
128          */
129         bool ChallengeResponse;
130
131         /** Ping frequency of server to server links
132          */
133         int PingFreq;
134
135         /** Initialise utility class
136          */
137         SpanningTreeUtilities(ModuleSpanningTree* Creator);
138
139         /** Prepare for class destruction
140          */
141         bool cull();
142
143         /** Destroy class and free listeners etc
144          */
145         ~SpanningTreeUtilities();
146
147         void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
148
149         /** Send a message from this server to one other local or remote
150          */
151         bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target);
152
153         /** Send a message from this server to all but one other, local or remote
154          */
155         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit);
156
157         /** Send a message from this server to all but one other, local or remote
158          */
159         bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit);
160
161         /** Send a message from this server to all others
162          */
163         bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params);
164
165         /** Send a message from this server to all others
166          */
167         bool DoOneToMany(const char* prefix, const char* command, parameterlist &params);
168
169         /** Send a message from this server to all others, without doing any processing on the command (e.g. send it as-is with colons and all)
170          */
171         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params);
172
173         /** Read the spanningtree module's tags from the config file
174          */
175         void ReadConfiguration(bool rebind);
176
177         /** Add a server to the server list for GetListOfServersForChannel
178          */
179         void AddThisServer(TreeServer* server, TreeServerList &list);
180
181         /** Compile a list of servers which contain members of channel c
182          */
183         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
184
185         /** Find a server by name
186          */
187         TreeServer* FindServer(const std::string &ServerName);
188
189         /** Find server by SID
190          */
191         TreeServer* FindServerID(const std::string &id);
192
193         /** Find a route to a server by name
194          */
195         TreeServer* BestRouteTo(const std::string &ServerName);
196
197         /** Find a server by glob mask
198          */
199         TreeServer* FindServerMask(const std::string &ServerName);
200
201         /** Returns true if this is a server name we recognise
202          */
203         bool IsServer(const std::string &ServerName);
204
205         /** Find a link tag from a server name
206          */
207         Link* FindLink(const std::string& name);
208
209         /** Refresh the IP cache used for allowing inbound connections
210          */
211         void RefreshIPCache();
212 };
213
214 #endif