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