The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

bancache.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *          the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef __BANCACHE_H
00015 #define __BANCACHE_H
00016 
00017 class CoreExport BanCacheHit : public classbase
00018 {
00019  private:
00020         InspIRCd *ServerInstance;
00021  public:
00022         std::string Type;
00023         std::string Reason;
00024         std::string IP;
00025         time_t Expiry;
00026 
00027         BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
00028         {
00029                 ServerInstance = Instance;
00030                 this->Type = type;
00031                 this->Reason = reason;
00032                 this->IP = ip;
00033                 this->Expiry = time(NULL) + 86400; // a day. this might seem long, but entries will be removed as glines/etc expire.
00034         }
00035 
00036         // overridden to allow custom time
00037         BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason, time_t seconds)
00038         {
00039                 ServerInstance = Instance;
00040                 this->Type = type;
00041                 this->Reason = reason;
00042                 this->IP = ip;
00043                 this->Expiry = time(NULL) + seconds;
00044         }
00045 };
00046 
00047 // must be defined after class BanCacheHit.
00048 #ifndef WIN32
00049 typedef nspace::hash_map<std::string, BanCacheHit *, nspace::hash<std::string> > BanCacheHash;
00050 #else
00051 typedef nspace::hash_map<std::string, BanCacheHit*, nspace::hash_compare<std::string, std::less<std::string> > > BanCacheHash;
00052 #endif
00053 
00054 class CoreExport BanCacheManager : public classbase
00055 {
00056  private:
00057         BanCacheHash *BanHash;
00058         InspIRCd *ServerInstance;
00059  public:
00060 
00066         BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason);
00067 
00068         // Overridden to allow an optional number of seconds before expiry
00069         BanCacheHit *AddHit(const std::string &ip, const std::string &type, const std::string &reason, time_t seconds);
00070         BanCacheHit *GetHit(const std::string &ip);
00071         bool RemoveHit(BanCacheHit *b);
00072 
00077         unsigned int RemoveEntries(const std::string &type, bool positive);
00078 
00079         BanCacheManager(InspIRCd *Instance)
00080         {
00081                 this->ServerInstance = Instance;
00082                 this->BanHash = new BanCacheHash();
00083         }
00084 
00085         void RehashCache();
00086 };
00087 
00088 #endif