]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/bancache.cpp
fe23fd0b7e1dc92091ab50f10f6715db387ff3b1
[user/henk/code/inspircd.git] / src / bancache.cpp
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 /* $Core: libIRCDbancache */
15
16 #include "inspircd.h"
17 #include "bancache.h"
18
19 BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &type, const std::string &reason)
20 {
21         BanCacheHit *b;
22
23
24         if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
25                 return NULL;
26
27         b = new BanCacheHit(ServerInstance, ip, type, reason);
28
29         this->BanHash->insert(std::make_pair(ip, b));
30         return b;
31 }
32
33 BanCacheHit *BanCacheManager::GetHit(const std::string &ip)
34 {
35         BanCacheHash::iterator i = this->BanHash->find(ip);
36
37         if (i == this->BanHash->end())
38                 return NULL; // free and safe
39         else
40                 return i->second; // hit.
41 }
42
43 bool BanCacheManager::RemoveHit(BanCacheHit *b)
44 {
45         BanCacheHash::iterator i;
46
47         if (!b)
48                 return false; // I don't think so.
49
50         i = this->BanHash->find(b->IP);
51
52         if (i == this->BanHash->end())
53         {
54                 // err..
55                 ServerInstance->Log(DEBUG, "BanCacheManager::RemoveHit(): I got asked to remove a hit that wasn't in the hash(?)");
56         }
57         else
58         {
59                 this->BanHash->erase(b->IP);
60         }
61
62         delete b;
63         return true;
64 }
65
66