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