]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/bancache.h
Rehash method added which frees unused memory from the hash_map. Has a delete-safe...
[user/henk/code/inspircd.git] / include / bancache.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __BANCACHE_H
15 #define __BANCACHE_H
16
17 #include <string>
18
19 class CoreExport BanCacheHit : public classbase
20 {
21  private:
22         InspIRCd *ServerInstance;
23  public:
24         std::string Type;
25         std::string Reason;
26         std::string IP;
27
28         BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
29         {
30                 ServerInstance = Instance;
31                 this->Type = type;
32                 this->Reason = reason;
33                 this->IP = ip;
34         }
35 };
36
37 // must be defined after class BanCacheHit.
38 #ifndef WIN32
39 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
40 #else
41 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<string, less<string> > > BanCacheHash;
42 #endif
43
44 class CoreExport BanCacheManager : public classbase
45 {
46  private:
47         BanCacheHash *BanHash;
48         InspIRCd *ServerInstance;
49  public:
50
51         /** Creates and adds a Ban Cache item.
52          * @param ip The IP the item is for.
53          * @param type The type of ban cache item. std::string. .empty() means it's a negative match (user is allowed freely).
54          * @param reason The reason for the ban. Left .empty() if it's a negative match.
55          */
56         BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
57         BanCacheHit *GetHit(const std::string &ip);
58         bool RemoveHit(BanCacheHit *b);
59
60         BanCacheManager(InspIRCd *Instance)
61         {
62                 this->ServerInstance = Instance;
63                 this->BanHash = new BanCacheHash();
64         }
65
66         void RehashCache();
67 };
68
69 #endif