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