]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/xline.h
Move lowermap[] into a pre-initialised const array in hashcomp.h,
[user/henk/code/inspircd.git] / include / xline.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __XLINE_H
18 #define __XLINE_H
19
20 // include the common header files
21
22 #include <typeinfo>
23 #include <iostream>
24 #include <string>
25 #include <deque>
26 #include <sstream>
27 #include <vector>
28 #include "users.h"
29 #include "channels.h"
30
31 const int APPLY_GLINES  = 1;
32 const int APPLY_KLINES  = 2;
33 const int APPLY_QLINES  = 4;
34 const int APPLY_ZLINES  = 8;
35 const int APPLY_ALL     = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
36
37 /** XLine is the base class for ban lines such as G lines and K lines.
38  */
39 class XLine : public classbase
40 {
41   public:
42
43         /** The time the line was added.
44          */
45         time_t set_time;
46         
47         /** The duration of the ban, or 0 if permenant
48          */
49         long duration;
50         
51         /** Source of the ban. This can be a servername or an oper nickname
52          */
53         char source[256];
54         
55         /** Reason for the ban
56          */
57         char reason[MAXBUF];
58         
59         /** Number of times the core matches the ban, for statistics
60          */
61         long n_matches;
62         
63 };
64
65 /** KLine class
66  */
67 class KLine : public XLine
68 {
69   public:
70         /** Hostmask (ident@host) to match against
71          * May contain wildcards.
72          */
73         char hostmask[200];
74 };
75
76 /** GLine class
77  */
78 class GLine : public XLine
79 {
80   public:
81         /** Hostmask (ident@host) to match against
82          * May contain wildcards.
83          */
84         char hostmask[200];
85 };
86
87 /** ELine class
88  */
89 class ELine : public XLine
90 {
91   public:
92         /** Hostmask (ident@host) to match against
93          * May contain wildcards.
94          */
95         char hostmask[200];
96 };
97
98 /** ZLine class
99  */
100 class ZLine : public XLine
101 {
102   public:
103         /** IP Address (xx.yy.zz.aa) to match against
104          * May contain wildcards.
105          */
106         char ipaddr[40];
107         /** Set if this is a global Z:line
108          * (e.g. it came from another server)
109          */
110         bool is_global;
111 };
112
113 /** QLine class
114  */
115 class QLine : public XLine
116 {
117   public:
118         /** Nickname to match against.
119          * May contain wildcards.
120          */
121         char nick[64];
122         /** Set if this is a global Z:line
123          * (e.g. it came from another server)
124          */
125         bool is_global;
126 };
127
128 class ServerConfig;
129 class InspIRCd;
130
131 bool InitXLine(ServerConfig* conf, const char* tag);
132 bool DoneXLine(ServerConfig* conf, const char* tag);
133
134 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
135 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
136 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
137 bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
138
139 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
140  */
141 class XLineManager
142 {
143  protected:
144         /** The owner/creator of this class
145          */
146         InspIRCd* ServerInstance;
147
148         /** This functor is used by the std::sort() function to keep glines in order
149          */
150         static bool XLineManager::GSortComparison ( const GLine one, const GLine two );
151
152         /** This functor is used by the std::sort() function to keep elines in order
153          */
154         static bool XLineManager::ESortComparison ( const ELine one, const ELine two );
155
156         /** This functor is used by the std::sort() function to keep zlines in order
157          */
158         static bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two );
159
160         /** This functor is used by the std::sort() function to keep klines in order
161          */
162         static bool XLineManager::KSortComparison ( const KLine one, const KLine two );
163
164         /** This functor is used by the std::sort() function to keep qlines in order
165          */
166         static bool XLineManager::QSortComparison ( const QLine one, const QLine two );
167  public:
168         /* Lists for temporary lines with an expiry time */
169
170         /** Temporary KLines */
171         std::vector<KLine> klines;
172
173         /** Temporary Glines */
174         std::vector<GLine> glines;
175
176         /** Temporary Zlines */
177         std::vector<ZLine> zlines;
178
179         /** Temporary QLines */
180         std::vector<QLine> qlines;
181
182         /** Temporary ELines */
183         std::vector<ELine> elines;
184
185         /* Seperate lists for perm XLines that isnt checked by expiry functions */
186
187         /** Permenant KLines */
188         std::vector<KLine> pklines;
189
190         /** Permenant GLines */
191         std::vector<GLine> pglines;
192
193         /** Permenant ZLines */
194         std::vector<ZLine> pzlines;
195
196         /** Permenant QLines */
197         std::vector<QLine> pqlines;
198
199         /** Permenant ELines */
200         std::vector<ELine> pelines;
201         
202         /** Constructor
203          * @param Instance A pointer to the creator object
204          */
205         XLineManager(InspIRCd* Instance);
206
207         /** Add a new GLine
208          * @param duration The duration of the line
209          * @param source The source of the line
210          * @param reason The reason for the line
211          * @param hostmask The hostmask
212          * @return True if the line was added successfully
213          */
214         bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
215
216         /** Add a new QLine
217          * @param duration The duration of the line
218          * @param source The source of the line
219          * @param reason The reason for the line
220          * @param nickname The nickmask
221          * @return True if the line was added successfully
222          */
223         bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
224
225         /** Add a new ZLine
226          * @param duration The duration of the line
227          * @param source The source of the line
228          * @param reason The reason for the line
229          * @param ipaddr The IP mask
230          * @return True if the line was added successfully
231          */
232         bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
233
234         /** Add a new KLine
235          * @param duration The duration of the line
236          * @param source The source of the line
237          * @param reason The reason for the line
238          * @param hostmask The hostmask
239          * @return True if the line was added successfully
240          */
241         bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
242
243         /** Add a new ELine
244          * @param duration The duration of the line
245          * @param source The source of the line
246          * @param reason The reason for the line
247          * @param hostmask The hostmask
248          * @return True if the line was added successfully
249          */
250         bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
251
252         /** Delete a GLine
253          * @return hostmask The host to remove
254          * @return True if the line was deleted successfully
255          */
256         bool del_gline(const char* hostmask);
257
258         /** Delete a QLine
259          * @return nickname The nick to remove
260          * @return True if the line was deleted successfully
261          */
262         bool del_qline(const char* nickname);
263
264         /** Delete a ZLine
265          * @return ipaddr The IP to remove
266          * @return True if the line was deleted successfully
267          */
268         bool del_zline(const char* ipaddr);
269
270         /** Delete a KLine
271          * @return hostmask The host to remove
272          * @return True if the line was deleted successfully
273          */
274         bool del_kline(const char* hostmask);
275
276         /** Delete a ELine
277          * @return hostmask The host to remove
278          * @return True if the line was deleted successfully
279          */
280         bool del_eline(const char* hostmask);
281
282         /** Check if a nickname matches a QLine
283          * @return nick The nick to check against
284          * @return The reason for the line if there is a match, or NULL if there is no match
285          */
286         char* matches_qline(const char* nick);
287
288         /** Check if a hostname matches a GLine
289          * @return host The host to check against
290          * @return The reason for the line if there is a match, or NULL if there is no match
291          */
292         char* matches_gline(const char* host);
293
294         /** Check if a IP matches a ZLine
295          * @return ipaddr The IP to check against
296          * @return The reason for the line if there is a match, or NULL if there is no match
297          */
298         char* matches_zline(const char* ipaddr);
299
300         /** Check if a hostname matches a KLine
301          * @return host The host to check against
302          * @return The reason for the line if there is a match, or NULL if there is no match
303          */
304         char* matches_kline(const char* host);
305
306         /** Check if a hostname matches a ELine
307          * @return host The host to check against
308          * @return The reason for the line if there is a match, or NULL if there is no match
309          */
310         char* matches_exception(const char* host);
311
312         /** Expire any pending non-permenant lines
313          */
314         void expire_lines();
315
316         /** Apply any new lines
317          * @param What The types of lines to apply, from the set
318          * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
319          */
320         void apply_lines(const int What);
321
322         /** Handle /STATS K
323          * @param user The username making the query
324          * @param results The string_list to receive the results
325          */
326         void stats_k(userrec* user, string_list &results);
327
328         /** Handle /STATS G
329          * @param user The username making the query
330          * @param results The string_list to receive the results
331          */
332         void stats_g(userrec* user, string_list &results);
333
334         /** Handle /STATS Q
335          * @param user The username making the query
336          * @param results The string_list to receive the results
337          */
338         void stats_q(userrec* user, string_list &results);
339
340         /** Handle /STATS Z
341          * @param user The username making the query
342          * @param results The string_list to receive the results
343          */
344         void stats_z(userrec* user, string_list &results);
345
346         /** Handle /STATS E
347          * @param user The username making the query
348          * @param results The string_list to receive the results
349          */
350         void stats_e(userrec* user, string_list &results);
351
352         /** Change creation time of a GLine
353          * @param host The hostname to change
354          * @param create_Time The new creation time
355          */
356         void gline_set_creation_time(const char* host, time_t create_time);
357
358         /** Change creation time of a QLine
359          * @param nick The nickmask to change
360          * @param create_Time The new creation time
361          */
362         void qline_set_creation_time(const char* nick, time_t create_time);
363
364         /** Change creation time of a ZLine
365          * @param ip The ipmask to change
366          * @param create_Time The new creation time
367          */
368         void zline_set_creation_time(const char* ip, time_t create_time);
369
370         /** Change creation time of a ELine
371          * @param host The hostname to change
372          * @param create_Time The new creation time
373          */
374         void eline_set_creation_time(const char* host, time_t create_time);
375         
376         /** Make a ZLine global
377          * @param ipaddr The zline to change
378          * @return True if the zline was updated
379          */
380         bool zline_make_global(const char* ipaddr);
381
382         /** Make a QLine global
383          * @param nickname The qline to change
384          * @return True if the qline was updated
385          */
386         bool qline_make_global(const char* nickname);
387 };
388
389 #endif