1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
17 class CoreExport BanCacheHit : public classbase
20 InspIRCd *ServerInstance;
27 BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
29 ServerInstance = Instance;
31 this->Reason = reason;
33 this->Expiry = time(NULL) + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
36 // overridden to allow custom time
37 BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
39 ServerInstance = Instance;
41 this->Reason = reason;
43 this->Expiry = time(NULL) + seconds;
47 // must be defined after class BanCacheHit.
49 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
51 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
54 class CoreExport BanCacheManager : public classbase
57 BanCacheHash *BanHash;
58 InspIRCd *ServerInstance;
61 /** Creates and adds a Ban Cache item.
62 * @param ip The IP the item is for.
63 * @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
64 * @param reason The reason for the ban. Left .empty() if it's a negative match.
66 BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
68 // Overridden to allow an optional number of seconds before expiry
69 BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds);
70 BanCacheHit *GetHit(const std::string &ip);
71 bool RemoveHit(BanCacheHit *b);
73 /** Removes all entries of a given type, either positive or negative. Returns the number of hits removed.
74 * @param type The type of bancache entries to remove (e.g. 'G')
75 * @param positive Remove either positive (true) or negative (false) hits.
77 unsigned int RemoveEntries(const std::string &type, bool positive);
79 BanCacheManager(InspIRCd *Instance)
81 this->ServerInstance = Instance;
82 this->BanHash = new BanCacheHash();