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, unsigned long d, const std::string& src, const std::string& re, const std::string& t)
53  : set_time(s_time)
54  , duration(d)
55  , source(src)
56  , reason(re)
57  , type(t)
58  , from_config(false)
59  {
60  expiry = set_time + duration;
61  }
62 
65  virtual ~XLine()
66  {
67  }
68 
72  virtual void SetCreateTime(time_t created)
73  {
74  set_time = created;
75  expiry = created + duration;
76  }
77 
83  virtual bool Matches(User *u) = 0;
84 
91  virtual bool Matches(const std::string &str) = 0;
92 
97  virtual void Apply(User* u);
98 
102  virtual void Unset() { }
103 
108  virtual void DisplayExpiry();
109 
117  virtual const std::string& Displayable() = 0;
118 
121  virtual void OnAdd() { }
122 
125  time_t set_time;
126 
129  unsigned long duration;
130 
133  std::string source;
134 
137  std::string reason;
138 
141  time_t expiry;
142 
146  const std::string type;
147 
148  // Whether this XLine was loaded from the server config.
149  bool from_config;
150 
151  virtual bool IsBurstable();
152 };
153 
156 class CoreExport KLine : public XLine
157 {
158  public:
159 
168  KLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
169  : XLine(s_time, d, src, re, "K"), identmask(ident), hostmask(host)
170  {
171  matchtext = this->identmask;
172  matchtext.append("@").append(this->hostmask);
173  }
174 
178  {
179  }
180 
181  bool Matches(User* u) CXX11_OVERRIDE;
182 
183  bool Matches(const std::string& str) CXX11_OVERRIDE;
184 
185  void Apply(User* u) CXX11_OVERRIDE;
186 
187  const std::string& Displayable() CXX11_OVERRIDE;
188 
189  bool IsBurstable() CXX11_OVERRIDE;
190 
193  std::string identmask;
196  std::string hostmask;
197 
198  std::string matchtext;
199 };
200 
203 class CoreExport GLine : public XLine
204 {
205  public:
214  GLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
215  : XLine(s_time, d, src, re, "G"), identmask(ident), hostmask(host)
216  {
217  matchtext = this->identmask;
218  matchtext.append("@").append(this->hostmask);
219  }
220 
224  {
225  }
226 
227  bool Matches(User* u) CXX11_OVERRIDE;
228 
229  bool Matches(const std::string& str) CXX11_OVERRIDE;
230 
231  void Apply(User* u) CXX11_OVERRIDE;
232 
233  const std::string& Displayable() CXX11_OVERRIDE;
234 
237  std::string identmask;
240  std::string hostmask;
241 
242  std::string matchtext;
243 };
244 
247 class CoreExport ELine : public XLine
248 {
249  public:
258  ELine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ident, const std::string& host)
259  : XLine(s_time, d, src, re, "E"), identmask(ident), hostmask(host)
260  {
261  matchtext = this->identmask;
262  matchtext.append("@").append(this->hostmask);
263  }
264 
265  ~ELine()
266  {
267  }
268 
269  bool Matches(User* u) CXX11_OVERRIDE;
270 
271  bool Matches(const std::string& str) CXX11_OVERRIDE;
272 
273  void Unset() CXX11_OVERRIDE;
274 
275  void OnAdd() CXX11_OVERRIDE;
276 
277  const std::string& Displayable() CXX11_OVERRIDE;
278 
281  std::string identmask;
284  std::string hostmask;
285 
286  std::string matchtext;
287 };
288 
291 class CoreExport ZLine : public XLine
292 {
293  public:
301  ZLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& ip)
302  : XLine(s_time, d, src, re, "Z"), ipaddr(ip)
303  {
304  }
305 
309  {
310  }
311 
312  bool Matches(User* u) CXX11_OVERRIDE;
313 
314  bool Matches(const std::string& str) CXX11_OVERRIDE;
315 
316  void Apply(User* u) CXX11_OVERRIDE;
317 
318  const std::string& Displayable() CXX11_OVERRIDE;
319 
322  std::string ipaddr;
323 };
324 
327 class CoreExport QLine : public XLine
328 {
329  public:
337  QLine(time_t s_time, unsigned long d, const std::string& src, const std::string& re, const std::string& nickname)
338  : XLine(s_time, d, src, re, "Q"), nick(nickname)
339  {
340  }
341 
345  {
346  }
347  bool Matches(User* u) CXX11_OVERRIDE;
348 
349  bool Matches(const std::string& str) CXX11_OVERRIDE;
350 
351  void Apply(User* u) CXX11_OVERRIDE;
352 
353  const std::string& Displayable() CXX11_OVERRIDE;
354 
357  std::string nick;
358 };
359 
367 class CoreExport XLineFactory
368 {
369  protected:
370 
371  std::string type;
372 
373  public:
374 
378  XLineFactory(const std::string &t) : type(t) { }
379 
383  virtual const std::string& GetType() { return type; }
384 
393  virtual XLine* Generate(time_t set_time, unsigned long duration, const std::string& source, const std::string& reason, const std::string& xline_specific_mask) = 0;
394 
395  virtual bool AutoApplyToUserList(XLine* x) { return true; }
396 
399  virtual ~XLineFactory() { }
400 };
401 
406 class CoreExport XLineManager
407 {
408  protected:
411  std::vector<XLine *> pending_lines;
412 
415  XLineFactMap line_factory;
416 
422  XLineContainer lookup_lines;
423 
424  public:
425 
428  XLineManager();
429 
432  ~XLineManager();
433 
437  IdentHostPair IdentSplit(const std::string &ident_and_host);
438 
441  void CheckELines();
442 
449  XLineLookup* GetAll(const std::string &type);
450 
453  void DelAll(const std::string &type);
454 
458  std::vector<std::string> GetAllTypes();
459 
465  bool AddLine(XLine* line, User* user);
466 
475  bool DelLine(const char* hostmask, const std::string& type, std::string& reason, User* user, bool simulate = false);
476 
487  bool RegisterFactory(XLineFactory* xlf);
488 
493  bool UnregisterFactory(XLineFactory* xlf);
494 
499  XLineFactory* GetFactory(const std::string &type);
500 
506  XLine* MatchesLine(const std::string &type, User* user);
507 
513  XLine* MatchesLine(const std::string &type, const std::string &pattern);
514 
520  void ExpireLine(ContainerIter container, LookupIter item, bool silent = false);
521 
526  void ApplyLines();
527 
535  void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats);
536 
538  void ExpireRemovedConfigLines(const std::string& type, const insp::flat_set<std::string>& configlines);
539 };
XLine::Apply
virtual void Apply(User *u)
Definition: xline.cpp:545
ZLine::~ZLine
~ZLine()
Definition: xline.h:308
GLine
Definition: xline.h:203
XLineManager::lookup_lines
XLineContainer lookup_lines
Definition: xline.h:422
insp::flat_set
Definition: flat_map.h:204
XLineFactory::XLineFactory
XLineFactory(const std::string &t)
Definition: xline.h:378
ELine::ELine
ELine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:258
ELine
Definition: xline.h:247
XLine::expiry
time_t expiry
Definition: xline.h:141
XLine::~XLine
virtual ~XLine()
Definition: xline.h:65
XLineFactory::~XLineFactory
virtual ~XLineFactory()
Definition: xline.h:399
XLineManager::line_factory
XLineFactMap line_factory
Definition: xline.h:415
XLine::Matches
virtual bool Matches(User *u)=0
Definition: xline.cpp:139
KLine::KLine
KLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:168
QLine::QLine
QLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &nickname)
Definition: xline.h:337
XLine::source
std::string source
Definition: xline.h:133
XLine::set_time
time_t set_time
Definition: xline.h:125
KLine::~KLine
~KLine()
Definition: xline.h:177
XLineFactory::GetType
virtual const std::string & GetType()
Definition: xline.h:383
XLine::XLine
XLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &t)
Definition: xline.h:52
classbase
Definition: base.h:41
KLine
Definition: xline.h:156
XLine::duration
unsigned long duration
Definition: xline.h:129
XLine
Definition: xline.h:32
XLine::type
const std::string type
Definition: xline.h:146
ZLine::ZLine
ZLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ip)
Definition: xline.h:301
XLine::SetCreateTime
virtual void SetCreateTime(time_t created)
Definition: xline.h:72
QLine::~QLine
~QLine()
Definition: xline.h:344
XLineManager::pending_lines
std::vector< XLine * > pending_lines
Definition: xline.h:411
XLine::OnAdd
virtual void OnAdd()
Definition: xline.h:121
XLineFactory
Definition: xline.h:367
XLine::reason
std::string reason
Definition: xline.h:137
QLine
Definition: xline.h:327
User
Definition: users.h:224
GLine::~GLine
~GLine()
Definition: xline.h:223
GLine::GLine
GLine(time_t s_time, unsigned long d, const std::string &src, const std::string &re, const std::string &ident, const std::string &host)
Definition: xline.h:214
XLine::Displayable
virtual const std::string & Displayable()=0
XLineManager
Definition: xline.h:406
XLine::Unset
virtual void Unset()
Definition: xline.h:102
ZLine
Definition: xline.h:291