]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Fix memory leaks on reloadmodule and spanningtree unload while connecting servers
[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 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
41
42 /** Contains helper functions and variables for this module,
43  * and keeps them out of the global namespace
44  */
45 class SpanningTreeUtilities : public classbase
46 {
47  public:
48         /** Creator module
49          */
50         ModuleSpanningTree* Creator;
51
52         /** Flatten links and /MAP for non-opers
53          */
54         bool FlatLinks;
55         /** Hide U-Lined servers in /MAP and /LINKS
56          */
57         bool HideULines;
58         /** Announce TS changes to channels on merge
59          */
60         bool AnnounceTSChange;
61
62         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
63          */
64         bool AllowOptCommon;
65
66         /** Make snomasks +CQ quiet during bursts and splits
67          */
68         bool quiet_bursts;
69
70         /* Number of seconds that a server can go without ping
71          * before opers are warned of high latency.
72          */
73         int PingWarnTime;
74         /** This variable represents the root of the server tree
75          */
76         TreeServer *TreeRoot;
77         /** Represents the server whose command we are processing
78          */
79         FakeUser *ServerUser;
80         /** IPs allowed to link to us
81          */
82         std::vector<std::string> ValidIPs;
83         /** Hash of currently connected servers by name
84          */
85         server_hash serverlist;
86         /** Hash of currently known server ids
87          */
88         server_hash sidlist;
89         /** Hash of servers currently bursting but not initialized as connected
90          */
91         std::map<irc::string,TreeSocket*> burstingserverlist;
92         /** List of all outgoing sockets and their timeouts
93          */
94         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
95         /** Holds the data from the <link> tags in the conf
96          */
97         std::vector<reference<Link> > LinkBlocks;
98         /** Holds the data from the <autoconnect> tags in the conf
99          */
100         std::vector<reference<Autoconnect> > AutoconnectBlocks;
101
102         /** True (default) if we are to use challenge-response HMAC
103          * to authenticate passwords.
104          *
105          * NOTE: This defaults to on, but should be turned off if
106          * you are linking to an older version of inspircd.
107          */
108         bool ChallengeResponse;
109
110         /** Ping frequency of server to server links
111          */
112         int PingFreq;
113
114         /** Initialise utility class
115          */
116         SpanningTreeUtilities(ModuleSpanningTree* Creator);
117
118         /** Prepare for class destruction
119          */
120         CullResult cull();
121
122         /** Destroy class and free listeners etc
123          */
124         ~SpanningTreeUtilities();
125
126         void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
127
128         /** Send a message from this server to one other local or remote
129          */
130         bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target);
131
132         /** Send a message from this server to all but one other, local or remote
133          */
134         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit);
135
136         /** Send a message from this server to all but one other, local or remote
137          */
138         bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit);
139
140         /** Send a message from this server to all others
141          */
142         bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params);
143
144         /** Send a message from this server to all others
145          */
146         bool DoOneToMany(const char* prefix, const char* command, parameterlist &params);
147
148         /** 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)
149          */
150         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params);
151
152         /** Read the spanningtree module's tags from the config file
153          */
154         void ReadConfiguration();
155
156         /** Add a server to the server list for GetListOfServersForChannel
157          */
158         void AddThisServer(TreeServer* server, TreeServerList &list);
159
160         /** Compile a list of servers which contain members of channel c
161          */
162         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
163
164         /** Find a server by name
165          */
166         TreeServer* FindServer(const std::string &ServerName);
167
168         /** Find server by SID
169          */
170         TreeServer* FindServerID(const std::string &id);
171
172         /** Find a route to a server by name
173          */
174         TreeServer* BestRouteTo(const std::string &ServerName);
175
176         /** Find a server by glob mask
177          */
178         TreeServer* FindServerMask(const std::string &ServerName);
179
180         /** Returns true if this is a server name we recognise
181          */
182         bool IsServer(const std::string &ServerName);
183
184         /** Find a link tag from a server name
185          */
186         Link* FindLink(const std::string& name);
187
188         /** Refresh the IP cache used for allowing inbound connections
189          */
190         void RefreshIPCache();
191 };
192
193 #endif