InspIRCd  3.0
xline.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2004-2007 Craig Edwards <[email protected]>
6  * Copyright (C) 2007 Robin Burchell <[email protected]>
7  * Copyright (C) 2007 Dennis Friis <[email protected]>
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 #pragma once
24 
32 class CoreExport XLine : public classbase
33 {
34  protected:
35 
41  void DefaultApply(User* u, const std::string &line, bool bancache);
42 
43  public:
44 
52  XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
53  : set_time(s_time), duration(d), source(src), reason(re), type(t)
54  {
55  expiry = set_time + duration;
56  }
57 
60  virtual ~XLine()
61  {
62  }
63 
67  virtual void SetCreateTime(time_t created)
68  {
69  set_time = created;
70  expiry = created + duration;
71  }
72 
78  virtual bool Matches(User *u) = 0;
79 
86  virtual bool Matches(const std::string &str) = 0;
87 
92  virtual void Apply(User* u);
93 
97  virtual void Unset() { }
98 
103  virtual void DisplayExpiry();
104 
112  virtual const std::string& Displayable() = 0;
113 
116  virtual void OnAdd() { }
117 
120  time_t set_time;
121 
124  long duration;
125 
128  std::string source;
129 
132  std::string reason;
133 
136  time_t expiry;
137 
141  const std::string type;
142 
143  virtual bool IsBurstable();
144 };
145 
148 class CoreExport KLine : public XLine
149 {
150  public:
151 
160  KLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
161  : XLine(s_time, d, src, re, "K"), identmask(ident), hostmask(host)
162  {
163  matchtext = this->identmask;
164  matchtext.append("@").append(this->hostmask);
165  }
166 
170  {
171  }
172 
173  virtual bool Matches(User *u);
174 
175  virtual bool Matches(const std::string &str);
176 
177  virtual void Apply(User* u);
178 
179  virtual const std::string& Displayable();
180 
181  virtual bool IsBurstable();
182 
185  std::string identmask;
188  std::string hostmask;
189 
190  std::string matchtext;
191 };
192 
195 class CoreExport GLine : public XLine
196 {
197  public:
206  GLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
207  : XLine(s_time, d, src, re, "G"), identmask(ident), hostmask(host)
208  {
209  matchtext = this->identmask;
210  matchtext.append("@").append(this->hostmask);
211  }
212 
216  {
217  }
218 
219  virtual bool Matches(User *u);
220 
221  virtual bool Matches(const std::string &str);
222 
223  virtual void Apply(User* u);
224 
225  virtual const std::string& Displayable();
226 
229  std::string identmask;
232  std::string hostmask;
233 
234  std::string matchtext;
235 };
236 
239 class CoreExport ELine : public XLine
240 {
241  public:
250  ELine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
251  : XLine(s_time, d, src, re, "E"), identmask(ident), hostmask(host)
252  {
253  matchtext = this->identmask;
254  matchtext.append("@").append(this->hostmask);
255  }
256 
257  ~ELine()
258  {
259  }
260 
261  virtual bool Matches(User *u);
262 
263  virtual bool Matches(const std::string &str);
264 
265  virtual void Unset();
266 
267  virtual void OnAdd();
268 
269  virtual const std::string& Displayable();
270 
273  std::string identmask;
276  std::string hostmask;
277 
278  std::string matchtext;
279 };
280 
283 class CoreExport ZLine : public XLine
284 {
285  public:
293  ZLine(time_t s_time, long d, std::string src, std::string re, std::string ip)
294  : XLine(s_time, d, src, re, "Z"), ipaddr(ip)
295  {
296  }
297 
301  {
302  }
303 
304  virtual bool Matches(User *u);
305 
306  virtual bool Matches(const std::string &str);
307 
308  virtual void Apply(User* u);
309 
310  virtual const std::string& Displayable();
311 
314  std::string ipaddr;
315 };
316 
319 class CoreExport QLine : public XLine
320 {
321  public:
329  QLine(time_t s_time, long d, std::string src, std::string re, std::string nickname)
330  : XLine(s_time, d, src, re, "Q"), nick(nickname)
331  {
332  }
333 
337  {
338  }
339  virtual bool Matches(User *u);
340 
341  virtual bool Matches(const std::string &str);
342 
343  virtual void Apply(User* u);
344 
345  virtual const std::string& Displayable();
346 
349  std::string nick;
350 };
351 
359 class CoreExport XLineFactory
360 {
361  protected:
362 
363  std::string type;
364 
365  public:
366 
370  XLineFactory(const std::string &t) : type(t) { }
371 
375  virtual const std::string& GetType() { return type; }
376 
385  virtual XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) = 0;
386 
387  virtual bool AutoApplyToUserList(XLine* x) { return true; }
388 
391  virtual ~XLineFactory() { }
392 };
393 
398 class CoreExport XLineManager
399 {
400  protected:
403  std::vector<XLine *> pending_lines;
404 
407  XLineFactMap line_factory;
408 
414  XLineContainer lookup_lines;
415 
416  public:
417 
420  XLineManager();
421 
424  ~XLineManager();
425 
429  IdentHostPair IdentSplit(const std::string &ident_and_host);
430 
433  void CheckELines();
434 
441  XLineLookup* GetAll(const std::string &type);
442 
445  void DelAll(const std::string &type);
446 
450  std::vector<std::string> GetAllTypes();
451 
457  bool AddLine(XLine* line, User* user);
458 
466  bool DelLine(const char* hostmask, const std::string &type, User* user, bool simulate = false);
467 
478  bool RegisterFactory(XLineFactory* xlf);
479 
484  bool UnregisterFactory(XLineFactory* xlf);
485 
490  XLineFactory* GetFactory(const std::string &type);
491 
497  XLine* MatchesLine(const std::string &type, User* user);
498 
504  XLine* MatchesLine(const std::string &type, const std::string &pattern);
505 
510  void ExpireLine(ContainerIter container, LookupIter item);
511 
516  void ApplyLines();
517 
525  void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats);
526 };
std::vector< XLine * > pending_lines
Definition: xline.h:403
Definition: xline.h:319
Definition: xline.h:239
std::string hostmask
Definition: xline.h:232
XLineFactory(const std::string &t)
Definition: xline.h:370
virtual ~XLine()
Definition: xline.h:60
virtual ~XLineFactory()
Definition: xline.h:391
ZLine(time_t s_time, long d, std::string src, std::string re, std::string ip)
Definition: xline.h:293
Definition: users.h:224
virtual void OnAdd()
Definition: xline.h:116
GLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:206
~GLine()
Definition: xline.h:215
ELine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:250
std::string hostmask
Definition: xline.h:276
Definition: xline.h:283
KLine(time_t s_time, long d, std::string src, std::string re, std::string ident, std::string host)
Definition: xline.h:160
std::string source
Definition: xline.h:128
std::string nick
Definition: xline.h:349
Definition: base.h:41
std::string hostmask
Definition: xline.h:188
std::string identmask
Definition: xline.h:185
virtual bool Matches(User *u)=0
Definition: xline.cpp:138
virtual void Unset()
Definition: xline.h:97
Definition: xline.h:148
time_t expiry
Definition: xline.h:136
Definition: xline.h:359
long duration
Definition: xline.h:124
QLine(time_t s_time, long d, std::string src, std::string re, std::string nickname)
Definition: xline.h:329
~ZLine()
Definition: xline.h:300
virtual const std::string & GetType()
Definition: xline.h:375
std::string reason
Definition: xline.h:132
XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
Definition: xline.h:52
XLineContainer lookup_lines
Definition: xline.h:414
Definition: xline.h:398
std::string identmask
Definition: xline.h:229
virtual void Apply(User *u)
Definition: xline.cpp:514
Definition: xline.h:32
const std::string type
Definition: xline.h:141
~QLine()
Definition: xline.h:336
time_t set_time
Definition: xline.h:120
XLineFactMap line_factory
Definition: xline.h:407
virtual const std::string & Displayable()=0
~KLine()
Definition: xline.h:169
std::string ipaddr
Definition: xline.h:314
Definition: xline.h:195
std::string identmask
Definition: xline.h:273
virtual void SetCreateTime(time_t created)
Definition: xline.h:67