summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-10 17:55:33 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-10 19:27:24 +0200
commit01ea7ce9c34bf85c8d9ec29f58bd82d6536a2162 (patch)
treed50df4bdee70ee387b814b1dcf49561469fbf2ab /src
parent2b1328c3f4b25a9f72cf2c458042ffafc2d5ad6b (diff)
BanCache: Move expiration code into a function, call it from RemoveEntries()
Diffstat (limited to 'src')
-rw-r--r--src/bancache.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/bancache.cpp b/src/bancache.cpp
index 784f5ded6..2d60bd381 100644
--- a/src/bancache.cpp
+++ b/src/bancache.cpp
@@ -39,18 +39,22 @@ BanCacheHit *BanCacheManager::GetHit(const std::string &ip)
if (i == this->BanHash->end())
return NULL; // free and safe
- else
- {
- if (ServerInstance->Time() > i->second->Expiry)
- {
- ServerInstance->Logs->Log("BANCACHE", DEBUG, "Hit on " + ip + " is out of date, removing!");
- delete i->second;
- BanHash->erase(i);
- return NULL; // out of date
- }
- return i->second; // hit.
- }
+ if (RemoveIfExpired(i))
+ return NULL; // expired
+
+ return i->second; // hit.
+}
+
+bool BanCacheManager::RemoveIfExpired(BanCacheHash::iterator& it)
+{
+ if (ServerInstance->Time() < it->second->Expiry)
+ return false;
+
+ ServerInstance->Logs->Log("BANCACHE", DEBUG, "Hit on " + it->first + " is out of date, removing!");
+ delete it->second;
+ it = BanHash->erase(it);
+ return true;
}
void BanCacheManager::RemoveEntries(const std::string& type, bool positive)
@@ -62,6 +66,9 @@ void BanCacheManager::RemoveEntries(const std::string& type, bool positive)
for (BanCacheHash::iterator i = BanHash->begin(); i != BanHash->end(); )
{
+ if (RemoveIfExpired(i))
+ continue; // updates the iterator if expired
+
BanCacheHit* b = i->second;
bool remove = false;