]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/bancache.h
Remove SpanningTreeProtocolInterface::SendOperNotice - it was translated to a SendSNO...
[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 class CoreExport BanCacheHit : public classbase
18 {
19  private:
20         InspIRCd *ServerInstance;
21  public:
22         std::string Type;
23         std::string Reason;
24         std::string IP;
25         time_t Expiry;
26
27         BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
28         {
29                 ServerInstance = Instance;
30                 this->Type = type;
31                 this->Reason = reason;
32                 this->IP = ip;
33                 this->Expiry = time(NULL) + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
34         }
35
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)
38         {
39                 ServerInstance = Instance;
40                 this->Type = type;
41                 this->Reason = reason;
42                 this->IP = ip;
43                 this->Expiry = time(NULL) + seconds;
44         }
45 };
46
47 // must be defined after class BanCacheHit.
48 #ifndef WIN32
49 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
50 #else
51 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
52 #endif
53
54 class CoreExport BanCacheManager : public classbase
55 {
56  private:
57         BanCacheHash *BanHash;
58         InspIRCd *ServerInstance;
59  public:
60
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.
65          */
66         BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
67
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);
72
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.
76          */
77         unsigned int RemoveEntries(const std::string &type, bool positive);
78
79         BanCacheManager(InspIRCd *Instance)
80         {
81                 this->ServerInstance = Instance;
82                 this->BanHash = new BanCacheHash();
83         }
84
85         void RehashCache();
86 };
87
88 #endif