1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /** Stores a cached ban entry.
18 * Each ban has one of these hashed in a hash_map to make for faster removal
19 * of already-banned users in the case that they try to reconnect. As no wildcard
20 * matching is done on these IPs, the speed of the system is improved. These cache
21 * entries expire every few hours, which is a reasonable expiry for any reasonable
24 class CoreExport BanCacheHit
27 /** Type of cached ban
30 /** Reason, shown as quit message
33 /** IP to match against, no wildcards here (of course)
36 /** Time that the ban expires at
40 BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason)
43 this->Reason = reason;
45 this->Expiry = ServerInstance->Time() + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
48 // overridden to allow custom time
49 BanCacheHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
52 this->Reason = reason;
54 this->Expiry = ServerInstance->Time() + seconds;
58 /* A container of ban cache items.
59 * must be defined after class BanCacheHit.
61 #if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
62 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
64 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash<std::string> > BanCacheHash;
67 /** A manager for ban cache, which allocates and deallocates and checks cached bans.
69 class CoreExport BanCacheManager
72 BanCacheHash* BanHash;
75 /** Creates and adds a Ban Cache item.
76 * @param ip The IP the item is for.
77 * @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
78 * @param reason The reason for the ban. Left .empty() if it's a negative match.
80 BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
82 // Overridden to allow an optional number of seconds before expiry
83 BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds);
84 BanCacheHit *GetHit(const std::string &ip);
85 bool RemoveHit(BanCacheHit *b);
87 /** Removes all entries of a given type, either positive or negative. Returns the number of hits removed.
88 * @param type The type of bancache entries to remove (e.g. 'G')
89 * @param positive Remove either positive (true) or negative (false) hits.
91 unsigned int RemoveEntries(const std::string &type, bool positive);
95 this->BanHash = new BanCacheHash();