InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
xline.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2004-2007 Craig Edwards <craigedwards@brainbox.cc>
6  * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  *
9  * This file is part of InspIRCd. InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef XLINE_H
24 #define XLINE_H
25 
33 class CoreExport XLine : public classbase
34 {
35  protected:
36 
42  void DefaultApply(User* u, const std::string &line, bool bancache);
43 
44  public:
45 
53  XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
54  : set_time(s_time), duration(d), source(src), reason(re), type(t)
55  {
56  expiry = set_time + duration;
57  }
58 
61  virtual ~XLine()
62  {
63  }
64 
68  virtual void SetCreateTime(time_t created)
69  {
70  set_time = created;
71  expiry = created + duration;
72  }
73 
79  virtual bool Matches(User *u) = 0;
80 
87  virtual bool Matches(const std::string &str) = 0;
88 
93  virtual void Apply(User* u);
94 
98  virtual void Unset() { }
99 
104  virtual void DisplayExpiry() = 0;
105 
113  virtual const char* Displayable() = 0;
114 
117  virtual void OnAdd() { }
118 
121  time_t set_time;
122 
125  long duration;
126 
129  std::string source;
130 
133  std::string reason;
134 
137  time_t expiry;
138 
142  const std::string type;
143 
144  virtual bool IsBurstable();
145 };
146 
149 class CoreExport KLine : public XLine
150 {
151  public:
152 
161  KLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
162  : XLine(s_time, d, src, re, "K"), identmask(ident), hostmask(host)
163  {
164  matchtext = this->identmask;
165  matchtext.append("@").append(this->hostmask);
166  }
167 
171  {
172  }
173 
174  virtual bool Matches(User *u);
175 
176  virtual bool Matches(const std::string &str);
177 
178  virtual void Apply(User* u);
179 
180  virtual void DisplayExpiry();
181 
182  virtual const char* Displayable();
183 
184  virtual bool IsBurstable();
185 
188  std::string identmask;
191  std::string hostmask;
192 
193  std::string matchtext;
194 };
195 
198 class CoreExport GLine : public XLine
199 {
200  public:
209  GLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
210  : XLine(s_time, d, src, re, "G"), identmask(ident), hostmask(host)
211  {
212  matchtext = this->identmask;
213  matchtext.append("@").append(this->hostmask);
214  }
215 
219  {
220  }
221 
222  virtual bool Matches(User *u);
223 
224  virtual bool Matches(const std::string &str);
225 
226  virtual void Apply(User* u);
227 
228  virtual void DisplayExpiry();
229 
230  virtual const char* Displayable();
231 
234  std::string identmask;
237  std::string hostmask;
238 
239  std::string matchtext;
240 };
241 
244 class CoreExport ELine : public XLine
245 {
246  public:
255  ELine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
256  : XLine(s_time, d, src, re, "E"), identmask(ident), hostmask(host)
257  {
258  matchtext = this->identmask;
259  matchtext.append("@").append(this->hostmask);
260  }
261 
262  ~ELine()
263  {
264  }
265 
266  virtual bool Matches(User *u);
267 
268  virtual bool Matches(const std::string &str);
269 
270  virtual void Unset();
271 
272  virtual void DisplayExpiry();
273 
274  virtual void OnAdd();
275 
276  virtual const char* Displayable();
277 
280  std::string identmask;
283  std::string hostmask;
284 
285  std::string matchtext;
286 };
287 
290 class CoreExport ZLine : public XLine
291 {
292  public:
300  ZLine(time_t s_time, long d, std::string src, std::string re, std::string ip)
301  : XLine(s_time, d, src, re, "Z"), ipaddr(ip)
302  {
303  }
304 
308  {
309  }
310 
311  virtual bool Matches(User *u);
312 
313  virtual bool Matches(const std::string &str);
314 
315  virtual void Apply(User* u);
316 
317  virtual void DisplayExpiry();
318 
319  virtual const char* Displayable();
320 
323  std::string ipaddr;
324 };
325 
328 class CoreExport QLine : public XLine
329 {
330  public:
338  QLine(time_t s_time, long d, std::string src, std::string re, std::string nickname)
339  : XLine(s_time, d, src, re, "Q"), nick(nickname)
340  {
341  }
342 
346  {
347  }
348  virtual bool Matches(User *u);
349 
350  virtual bool Matches(const std::string &str);
351 
352  virtual void Apply(User* u);
353 
354  virtual void DisplayExpiry();
355 
356  virtual const char* Displayable();
357 
360  std::string nick;
361 };
362 
370 class CoreExport XLineFactory
371 {
372  protected:
373 
374  std::string type;
375 
376  public:
377 
381  XLineFactory(const std::string &t) : type(t) { }
382 
386  virtual const std::string& GetType() { return type; }
387 
396  virtual XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) = 0;
397 
398  virtual bool AutoApplyToUserList(XLine* x) { return true; }
399 
402  virtual ~XLineFactory() { }
403 };
404 
409 class CoreExport XLineManager
410 {
411  protected:
414  std::vector<XLine *> pending_lines;
415 
418  XLineFactMap line_factory;
419 
425  XLineContainer lookup_lines;
426 
427  public:
428 
431  XLineManager();
432 
435  ~XLineManager();
436 
440  IdentHostPair IdentSplit(const std::string &ident_and_host);
441 
444  void CheckELines();
445 
452  XLineLookup* GetAll(const std::string &type);
453 
456  void DelAll(const std::string &type);
457 
461  std::vector<std::string> GetAllTypes();
462 
468  bool AddLine(XLine* line, User* user);
469 
477  bool DelLine(const char* hostmask, const std::string &type, User* user, bool simulate = false);
478 
489  bool RegisterFactory(XLineFactory* xlf);
490 
495  bool UnregisterFactory(XLineFactory* xlf);
496 
501  XLineFactory* GetFactory(const std::string &type);
502 
508  XLine* MatchesLine(const std::string &type, User* user);
509 
515  XLine* MatchesLine(const std::string &type, const std::string &pattern);
516 
521  void ExpireLine(ContainerIter container, LookupIter item);
522 
527  void ApplyLines();
528 
537  void InvokeStats(const std::string &type, int numeric, User* user, string_list &results);
538 };
539 
540 #endif
virtual void DisplayExpiry()=0
std::vector< XLine * > pending_lines
Definition: xline.h:414
Definition: xline.h:328
Definition: xline.h:244
std::string hostmask
Definition: xline.h:237
XLineFactory(const std::string &t)
Definition: xline.h:381
virtual ~XLine()
Definition: xline.h:61
virtual ~XLineFactory()
Definition: xline.h:402
ZLine(time_t s_time, long d, std::string src, std::string re, std::string ip)
Definition: xline.h:300
Definition: users.h:230
virtual void OnAdd()
Definition: xline.h:117
GLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:209
~GLine()
Definition: xline.h:218
ELine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:255
std::string hostmask
Definition: xline.h:283
Definition: xline.h:290
KLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:161
std::string source
Definition: xline.h:129
std::string nick
Definition: xline.h:360
Definition: base.h:42
std::string hostmask
Definition: xline.h:191
std::string identmask
Definition: xline.h:188
virtual bool Matches(User *u)=0
Definition: xline.cpp:139
virtual void Unset()
Definition: xline.h:98
Definition: xline.h:149
time_t expiry
Definition: xline.h:137
Definition: xline.h:370
long duration
Definition: xline.h:125
QLine(time_t s_time, long d, std::string src, std::string re, std::string nickname)
Definition: xline.h:338
~ZLine()
Definition: xline.h:307
virtual const std::string & GetType()
Definition: xline.h:386
virtual const char * Displayable()=0
std::string reason
Definition: xline.h:133
XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
Definition: xline.h:53
XLineContainer lookup_lines
Definition: xline.h:425
Definition: xline.h:409
std::string identmask
Definition: xline.h:234
virtual void Apply(User *u)
Definition: xline.cpp:523
Definition: xline.h:33
const std::string type
Definition: xline.h:142
~QLine()
Definition: xline.h:345
time_t set_time
Definition: xline.h:121
XLineFactMap line_factory
Definition: xline.h:418
~KLine()
Definition: xline.h:170
std::string ipaddr
Definition: xline.h:323
Definition: xline.h:198
std::string identmask
Definition: xline.h:280
virtual void SetCreateTime(time_t created)
Definition: xline.h:68