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