InspIRCd  3.0
bancache.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2019 Matt Schatz <[email protected]>
5  * Copyright (C) 2013 Sadie Powell <[email protected]>
6  * Copyright (C) 2012-2014 Attila Molnar <[email protected]>
7  * Copyright (C) 2012, 2019 Robby <[email protected]>
8  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
9  * Copyright (C) 2007-2008 Robin Burchell <[email protected]>
10  * Copyright (C) 2007-2008 Craig Edwards <[email protected]>
11  *
12  * This file is part of InspIRCd. InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #pragma once
27 
35 class CoreExport BanCacheHit
36 {
37  public:
40  std::string Type;
43  std::string Reason;
46  time_t Expiry;
47 
48  BanCacheHit(const std::string& type, const std::string& reason, time_t seconds);
49 
50  bool IsPositive() const { return (!Reason.empty()); }
51 };
52 
55 class CoreExport BanCacheManager
56 {
59  typedef TR1NS::unordered_map<std::string, BanCacheHit*, TR1NS::hash<std::string> > BanCacheHash;
60 
61  BanCacheHash BanHash;
62  bool RemoveIfExpired(BanCacheHash::iterator& it);
63 
64  public:
65 
72  BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds = 0);
73  BanCacheHit *GetHit(const std::string &ip);
74 
79  void RemoveEntries(const std::string& type, bool positive);
80 
81  ~BanCacheManager();
82 };
BanCacheHit::Reason
std::string Reason
Definition: bancache.h:43
BanCacheHit::Type
std::string Type
Definition: bancache.h:40
BanCacheHit
Definition: bancache.h:35
BanCacheHit::Expiry
time_t Expiry
Definition: bancache.h:46
BanCacheManager
Definition: bancache.h:55