1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 class CoreExport BanCacheHit : public classbase
22 InspIRCd *ServerInstance;
29 BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
31 ServerInstance = Instance;
33 this->Reason = reason;
35 this->Expiry = time(NULL) + 60; // XXX changeme
38 // overridden to allow custom time
39 BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
41 ServerInstance = Instance;
43 this->Reason = reason;
45 this->Expiry = time(NULL) + seconds;
49 // must be defined after class BanCacheHit.
51 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
53 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<string, less<string> > > BanCacheHash;
56 class CoreExport BanCacheManager : public classbase
59 BanCacheHash *BanHash;
60 InspIRCd *ServerInstance;
63 /** Creates and adds a Ban Cache item.
64 * @param ip The IP the item is for.
65 * @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
66 * @param reason The reason for the ban. Left .empty() if it's a negative match.
68 BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
69 BanCacheHit *GetHit(const std::string &ip);
70 bool RemoveHit(BanCacheHit *b);
72 /** Removes all entries of a given type, either positive or negative. Returns the number of hits removed.
73 * @param type The type of bancache entries to remove (e.g. 'G')
74 * @param positive Remove either positive (true) or negative (false) hits.
76 unsigned int RemoveEntries(const std::string &type, bool positive);
78 BanCacheManager(InspIRCd *Instance)
80 this->ServerInstance = Instance;
81 this->BanHash = new BanCacheHash();