]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Remove unnecessary string copies and dead code
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #ifndef M_SPANNINGTREE_UTILS_H
24 #define M_SPANNINGTREE_UTILS_H
25
26 #include "inspircd.h"
27
28 /* Foward declarations */
29 class TreeServer;
30 class TreeSocket;
31 class Link;
32 class Autoconnect;
33 class ModuleSpanningTree;
34 class SpanningTreeUtilities;
35
36 /* This hash_map holds the hash equivalent of the server
37  * tree, used for rapid linear lookups.
38  */
39 #ifdef HASHMAP_DEPRECATED
40         typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
41 #else
42         typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
43 #endif
44
45 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
46
47 /** Contains helper functions and variables for this module,
48  * and keeps them out of the global namespace
49  */
50 class SpanningTreeUtilities : public classbase
51 {
52  public:
53         /** Creator module
54          */
55         ModuleSpanningTree* Creator;
56
57         /** Flatten links and /MAP for non-opers
58          */
59         bool FlatLinks;
60         /** Hide U-Lined servers in /MAP and /LINKS
61          */
62         bool HideULines;
63         /** Announce TS changes to channels on merge
64          */
65         bool AnnounceTSChange;
66
67         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
68          */
69         bool AllowOptCommon;
70
71         /** Make snomasks +CQ quiet during bursts and splits
72          */
73         bool quiet_bursts;
74
75         /* Number of seconds that a server can go without ping
76          * before opers are warned of high latency.
77          */
78         int PingWarnTime;
79         /** This variable represents the root of the server tree
80          */
81         TreeServer *TreeRoot;
82         /** IPs allowed to link to us
83          */
84         std::vector<std::string> ValidIPs;
85         /** Hash of currently connected servers by name
86          */
87         server_hash serverlist;
88         /** Hash of currently known server ids
89          */
90         server_hash sidlist;
91         /** List of all outgoing sockets and their timeouts
92          */
93         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
94         /** Holds the data from the <link> tags in the conf
95          */
96         std::vector<reference<Link> > LinkBlocks;
97         /** Holds the data from the <autoconnect> tags in the conf
98          */
99         std::vector<reference<Autoconnect> > AutoconnectBlocks;
100
101         /** True (default) if we are to use challenge-response HMAC
102          * to authenticate passwords.
103          *
104          * NOTE: This defaults to on, but should be turned off if
105          * you are linking to an older version of inspircd.
106          */
107         bool ChallengeResponse;
108
109         /** Ping frequency of server to server links
110          */
111         int PingFreq;
112
113         /** Initialise utility class
114          */
115         SpanningTreeUtilities(ModuleSpanningTree* Creator);
116
117         /** Prepare for class destruction
118          */
119         CullResult cull();
120
121         /** Destroy class and free listeners etc
122          */
123         ~SpanningTreeUtilities();
124
125         void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
126
127         /** Send a message from this server to one other local or remote
128          */
129         bool DoOneToOne(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& target);
130
131         /** Send a message from this server to all but one other, local or remote
132          */
133         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlist &params, const std::string& omit);
134
135         /** Send a message from this server to all others
136          */
137         bool DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist &params);
138
139         /** Read the spanningtree module's tags from the config file
140          */
141         void ReadConfiguration();
142
143         /** Add a server to the server list for GetListOfServersForChannel
144          */
145         void AddThisServer(TreeServer* server, TreeServerList &list);
146
147         /** Compile a list of servers which contain members of channel c
148          */
149         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
150
151         /** Find a server by name
152          */
153         TreeServer* FindServer(const std::string &ServerName);
154
155         /** Find server by SID
156          */
157         TreeServer* FindServerID(const std::string &id);
158
159         /** Find a route to a server by name
160          */
161         TreeServer* BestRouteTo(const std::string &ServerName);
162
163         /** Find a server by glob mask
164          */
165         TreeServer* FindServerMask(const std::string &ServerName);
166
167         /** Find a link tag from a server name
168          */
169         Link* FindLink(const std::string& name);
170
171         /** Refresh the IP cache used for allowing inbound connections
172          */
173         void RefreshIPCache();
174 };
175
176 #endif