]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/bancache.h
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / include / bancache.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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         time_t Expiry;
28
29         BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
30         {
31                 ServerInstance = Instance;
32                 this->Type = type;
33                 this->Reason = reason;
34                 this->IP = ip;
35                 this->Expiry = time(NULL) + 60; // XXX changeme
36         }
37
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)
40         {
41                 ServerInstance = Instance;
42                 this->Type = type;
43                 this->Reason = reason;
44                 this->IP = ip;
45                 this->Expiry = time(NULL) + seconds;
46         }
47 };
48
49 // must be defined after class BanCacheHit.
50 #ifndef WIN32
51 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
52 #else
53 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<string, less<string> > > BanCacheHash;
54 #endif
55
56 class CoreExport BanCacheManager : public classbase
57 {
58  private:
59         BanCacheHash *BanHash;
60         InspIRCd *ServerInstance;
61  public:
62
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.
67          */
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);
71
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.
75          */
76         unsigned int RemoveEntries(const std::string &type, bool positive);
77
78         BanCacheManager(InspIRCd *Instance)
79         {
80                 this->ServerInstance = Instance;
81                 this->BanHash = new BanCacheHash();
82         }
83
84         void RehashCache();
85 };
86
87 #endif