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