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