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