]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/xline.h
Whoops, must be const
[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_PERM_ONLY       = 16;
30 const int APPLY_ALL             = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
31
32 /** XLine is the base class for ban lines such as G lines and K lines.
33  */
34 class CoreExport XLine : public classbase
35 {
36   public:
37
38         /** Create an XLine.
39          * @param s_time The set time
40          * @param d The duration of the xline
41          * @param src The sender of the xline
42          * @param re The reason of the xline
43          */
44         XLine(time_t s_time, long d, const char* src, const char* re)
45                 : set_time(s_time), duration(d)
46         {
47                 source = strdup(src);
48                 reason = strdup(re);
49                 expiry = set_time + duration;
50         }
51
52         /** Destructor
53          */
54         virtual ~XLine()
55         {
56                 free(reason);
57                 free(source);
58         }
59         /** The time the line was added.
60          */
61         time_t set_time;
62         
63         /** The duration of the ban, or 0 if permenant
64          */
65         long duration;
66         
67         /** Source of the ban. This can be a servername or an oper nickname
68          */
69         char* source;
70         
71         /** Reason for the ban
72          */
73         char* reason;
74
75         /** Expiry time
76          */
77         time_t expiry;
78 };
79
80 /** KLine class
81  */
82 class CoreExport KLine : public XLine
83 {
84   public:
85         /** Create a K-Line.
86          * @param s_time The set time
87          * @param d The duration of the xline
88          * @param src The sender of the xline
89          * @param re The reason of the xline
90          * @param ident Ident to match
91          * @param host Host to match
92          */
93         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)
94         {
95                 identmask = strdup(ident);
96                 hostmask = strdup(host);
97         }
98
99         /** Destructor
100          */
101         ~KLine()
102         {
103                 free(identmask);
104                 free(hostmask);
105         }
106
107         /** Ident mask
108          */
109         char* identmask;
110         /** Host mask
111          */
112         char* hostmask;
113 };
114
115 /** GLine class
116  */
117 class CoreExport GLine : public XLine
118 {
119   public:
120         /** Create a G-Line.
121          * @param s_time The set time
122          * @param d The duration of the xline
123          * @param src The sender of the xline
124          * @param re The reason of the xline
125          * @param ident Ident to match
126          * @param host Host to match
127          */
128         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)
129         {
130                 identmask = strdup(ident);
131                 hostmask = strdup(host);
132         }
133
134         /** Destructor
135          */
136         ~GLine()
137         {
138                 free(identmask);
139                 free(hostmask);
140         }
141
142         /** Ident mask
143          */
144         char* identmask;
145         /** Host mask
146          */
147         char* hostmask;
148 };
149
150 /** ELine class
151  */
152 class CoreExport ELine : public XLine
153 {
154   public:
155         /** Create an E-Line.
156          * @param s_time The set time
157          * @param d The duration of the xline
158          * @param src The sender of the xline
159          * @param re The reason of the xline
160          * @param ident Ident to match
161          * @param host Host to match
162          */
163         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)
164         {
165                 identmask = strdup(ident);
166                 hostmask = strdup(host);
167         }
168
169         ~ELine()
170         {
171                 free(identmask);
172                 free(hostmask);
173         }
174
175         /** Ident mask
176          */
177         char* identmask;
178         /** Host mask
179          */
180         char* hostmask;
181 };
182
183 /** ZLine class
184  */
185 class CoreExport ZLine : public XLine
186 {
187   public:
188         /** Create a Z-Line.
189          * @param s_time The set time
190          * @param d The duration of the xline
191          * @param src The sender of the xline
192          * @param re The reason of the xline
193          * @param ip IP to match
194          */
195         ZLine(time_t s_time, long d, const char* src, const char* re, const char* ip) : XLine(s_time, d, src, re)
196         {
197                 ipaddr = strdup(ip);
198         }
199
200         /** Destructor
201          */
202         ~ZLine()
203         {
204                 free(ipaddr);
205         }
206
207         /** IP mask
208          */
209         char* ipaddr;
210 };
211
212 /** QLine class
213  */
214 class CoreExport QLine : public XLine
215 {
216   public:
217         /** Create a G-Line.
218          * @param s_time The set time
219          * @param d The duration of the xline
220          * @param src The sender of the xline
221          * @param re The reason of the xline
222          * @param nickname Nickname to match
223          */
224         QLine(time_t s_time, long d, const char* src, const char* re, const char* nickname) : XLine(s_time, d, src, re)
225         {
226                 nick = strdup(nickname);
227         }
228
229         /** Destructor
230          */
231         ~QLine()
232         {
233                 free(nick);
234         }
235
236         /** Nickname mask
237          */
238         char* nick;
239 };
240
241 /* Required forward declarations
242  */
243 class ServerConfig;
244 class InspIRCd;
245
246 /** Initialize x line
247  */
248 bool InitXLine(ServerConfig* conf, const char* tag);
249
250 /** Done adding zlines from the config
251  */
252 bool DoneZLine(ServerConfig* conf, const char* tag);
253 /** Done adding qlines from the config
254  */
255 bool DoneQLine(ServerConfig* conf, const char* tag);
256 /** Done adding klines from the config
257  */
258 bool DoneKLine(ServerConfig* conf, const char* tag);
259 /** Done adding elines from the config
260  */
261 bool DoneELine(ServerConfig* conf, const char* tag);
262
263 /** Add a config-defined zline
264  */
265 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
266 /** Add a config-defined qline
267  */
268 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
269 /** Add a config-defined kline
270  */
271 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
272 /** Add a config-defined eline
273  */
274 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
275
276 /** Contains an ident and host split into two strings
277  */
278 typedef std::pair<std::string, std::string> IdentHostPair;
279
280 /** XLineManager is a class used to manage glines, klines, elines, zlines and qlines.
281  */
282 class CoreExport XLineManager
283 {
284  protected:
285         /** The owner/creator of this class
286          */
287         InspIRCd* ServerInstance;
288
289         /** This functor is used by the std::sort() function to keep glines in order
290          */
291         static bool GSortComparison ( const GLine* one, const GLine* two );
292
293         /** This functor is used by the std::sort() function to keep elines in order
294          */
295         static bool ESortComparison ( const ELine* one, const ELine* two );
296
297         /** This functor is used by the std::sort() function to keep zlines in order
298          */
299         static bool ZSortComparison ( const ZLine* one, const ZLine* two );
300
301         /** This functor is used by the std::sort() function to keep klines in order
302          */
303         static bool KSortComparison ( const KLine* one, const KLine* two );
304
305         /** This functor is used by the std::sort() function to keep qlines in order
306          */
307         static bool QSortComparison ( const QLine* one, const QLine* two );
308  public:
309         /* Lists for temporary lines with an expiry time */
310
311         /** Temporary KLines */
312         std::vector<KLine*> klines;
313
314         /** Temporary Glines */
315         std::vector<GLine*> glines;
316
317         /** Temporary Zlines */
318         std::vector<ZLine*> zlines;
319
320         /** Temporary QLines */
321         std::vector<QLine*> qlines;
322
323         /** Temporary ELines */
324         std::vector<ELine*> elines;
325
326         /* Seperate lists for perm XLines that isnt checked by expiry functions */
327
328         /** Permenant KLines */
329         std::vector<KLine*> pklines;
330
331         /** Permenant GLines */
332         std::vector<GLine*> pglines;
333
334         /** Permenant ZLines */
335         std::vector<ZLine*> pzlines;
336
337         /** Permenant QLines */
338         std::vector<QLine*> pqlines;
339
340         /** Permenant ELines */
341         std::vector<ELine*> pelines;
342         
343         /** Constructor
344          * @param Instance A pointer to the creator object
345          */
346         XLineManager(InspIRCd* Instance);
347
348         /** Split an ident and host into two seperate strings.
349          * This allows for faster matching.
350          */
351         IdentHostPair IdentSplit(const std::string &ident_and_host);
352
353         /** Add a new GLine
354          * @param duration The duration of the line
355          * @param source The source of the line
356          * @param reason The reason for the line
357          * @param hostmask The hostmask
358          * @return True if the line was added successfully
359          */
360         bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
361
362         /** Add a new QLine
363          * @param duration The duration of the line
364          * @param source The source of the line
365          * @param reason The reason for the line
366          * @param nickname The nickmask
367          * @return True if the line was added successfully
368          */
369         bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
370
371         /** Add a new ZLine
372          * @param duration The duration of the line
373          * @param source The source of the line
374          * @param reason The reason for the line
375          * @param ipaddr The IP mask
376          * @return True if the line was added successfully
377          */
378         bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
379
380         /** Add a new KLine
381          * @param duration The duration of the line
382          * @param source The source of the line
383          * @param reason The reason for the line
384          * @param hostmask The hostmask
385          * @return True if the line was added successfully
386          */
387         bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
388
389         /** Add a new ELine
390          * @param duration The duration of the line
391          * @param source The source of the line
392          * @param reason The reason for the line
393          * @param hostmask The hostmask
394          * @return True if the line was added successfully
395          */
396         bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
397
398         /** Delete a GLine
399          * @param hostmask The host to remove
400          * @param simulate If this is true, don't actually remove the line, just return
401          * @return True if the line was deleted successfully
402          */
403         bool del_gline(const char* hostmask, bool simulate = false);
404
405         /** Delete a QLine
406          * @param nickname The nick to remove
407          * @param simulate If this is true, don't actually remove the line, just return
408          * @return True if the line was deleted successfully
409          */
410         bool del_qline(const char* nickname, bool simulate = false);
411
412         /** Delete a ZLine
413          * @param ipaddr The IP to remove
414          * @param simulate If this is true, don't actually remove the line, just return
415          * @return True if the line was deleted successfully
416          */
417         bool del_zline(const char* ipaddr, bool simulate = false);
418
419         /** Delete a KLine
420          * @param hostmask The host to remove
421          * @param simulate If this is true, don't actually remove the line, just return
422          * @return True if the line was deleted successfully
423          */
424         bool del_kline(const char* hostmask, bool simulate = false);
425
426         /** Delete a ELine
427          * @param hostmask The host to remove
428          * @param simulate If this is true, don't actually remove the line, just return
429          * @return True if the line was deleted successfully
430          */
431         bool del_eline(const char* hostmask, bool simulate = false);
432
433         /** Check if a nickname matches a QLine
434          * @return nick The nick to check against
435          * @return The reason for the line if there is a match, or NULL if there is no match
436          */
437         QLine* matches_qline(const char* nick, bool permonly = false);
438
439         /** Check if a hostname matches a GLine
440          * @param user The user to check against
441          * @return The reason for the line if there is a match, or NULL if there is no match
442          */
443         GLine* matches_gline(User* user, bool permonly = false);
444
445         /** Check if a IP matches a ZLine
446          * @param ipaddr The IP to check against
447          * @return The reason for the line if there is a match, or NULL if there is no match
448          */
449         ZLine* matches_zline(const char* ipaddr, bool permonly = false);
450
451         /** Check if a hostname matches a KLine
452          * @param user The user to check against
453          * @return The reason for the line if there is a match, or NULL if there is no match
454          */
455         KLine* matches_kline(User* user, bool permonly = false);
456
457         /** Check if a hostname matches a ELine
458          * @param user The user to check against
459          * @return The reason for the line if there is a match, or NULL if there is no match
460          */
461         ELine* matches_exception(User* user, bool permonly = false);
462
463         /** Expire any pending non-permenant lines
464          */
465         void expire_lines();
466
467         /** Apply any new lines
468          * @param What The types of lines to apply, from the set
469          * APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES | APPLY_ALL
470          * | APPLY_LOCAL_ONLY
471          */
472         void apply_lines(const int What);
473
474         /** Handle /STATS K
475          * @param user The username making the query
476          * @param results The string_list to receive the results
477          */
478         void stats_k(User* user, string_list &results);
479
480         /** Handle /STATS G
481          * @param user The username making the query
482          * @param results The string_list to receive the results
483          */
484         void stats_g(User* user, string_list &results);
485
486         /** Handle /STATS Q
487          * @param user The username making the query
488          * @param results The string_list to receive the results
489          */
490         void stats_q(User* user, string_list &results);
491
492         /** Handle /STATS Z
493          * @param user The username making the query
494          * @param results The string_list to receive the results
495          */
496         void stats_z(User* user, string_list &results);
497
498         /** Handle /STATS E
499          * @param user The username making the query
500          * @param results The string_list to receive the results
501          */
502         void stats_e(User* user, string_list &results);
503
504         /** Change creation time of a GLine
505          * @param host The hostname to change
506          * @param create_Time The new creation time
507          */
508         void gline_set_creation_time(const char* host, time_t create_time);
509
510         /** Change creation time of a QLine
511          * @param nick The nickmask to change
512          * @param create_Time The new creation time
513          */
514         void qline_set_creation_time(const char* nick, time_t create_time);
515
516         /** Change creation time of a ZLine
517          * @param ip The ipmask to change
518          * @param create_Time The new creation time
519          */
520         void zline_set_creation_time(const char* ip, time_t create_time);
521
522         /** Change creation time of a ELine
523          * @param host The hostname to change
524          * @param create_Time The new creation time
525          */
526         void eline_set_creation_time(const char* host, time_t create_time);
527 };
528
529 #endif
530