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