summaryrefslogtreecommitdiff
path: root/src/bancache.cpp
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-10-01 01:00:10 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-10 19:27:24 +0200
commit05ea9815235187a4821d0154ac8d7e1d982e3617 (patch)
treeb11451fd6f0f1bf027272804b53be253a54e1e6a /src/bancache.cpp
parenta0fdf5fcd51c18e9fa3be245349582e70b69f74f (diff)
BanCache: Simplify BanCacheManager::RemoveEntries()
Diffstat (limited to 'src/bancache.cpp')
-rw-r--r--src/bancache.cpp48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/bancache.cpp b/src/bancache.cpp
index c38a31b4d..244ffd758 100644
--- a/src/bancache.cpp
+++ b/src/bancache.cpp
@@ -53,43 +53,39 @@ BanCacheHit *BanCacheManager::GetHit(const std::string &ip)
}
}
-unsigned int BanCacheManager::RemoveEntries(const std::string &type, bool positive)
+void BanCacheManager::RemoveEntries(const std::string& type, bool positive)
{
- int removed = 0;
-
- BanCacheHash::iterator safei;
-
if (positive)
ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing positive hits for " + type);
else
- ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing negative hits for " + type);
+ ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing all negative hits");
- for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
+ for (BanCacheHash::iterator i = BanHash->begin(); i != BanHash->end(); )
{
- safei = n;
- safei++;
+ BanCacheHit* b = i->second;
+ bool remove = false;
- BanCacheHit *b = n->second;
-
- /* Safe to delete items here through iterator 'n' */
- if (b->Type == type || !positive) // if removing negative hits, ignore type..
+ if (positive)
{
- if ((positive && !b->Reason.empty()) || b->Reason.empty())
- {
- /* we need to remove this one. */
- ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing a hit on " + n->first);
- delete b;
- BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
- removed++;
- }
+ // when removing positive hits, remove only if the type matches
+ remove = b->IsPositive() && (b->Type == type);
+ }
+ else
+ {
+ // when removing negative hits, remove all of them
+ remove = !b->IsPositive();
}
- /* End of safe section */
- n = safei;
+ if (remove)
+ {
+ /* we need to remove this one. */
+ ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing a hit on " + i->first);
+ delete b;
+ i = BanHash->erase(i);
+ }
+ else
+ ++i;
}
-
-
- return removed;
}
void BanCacheManager::RehashCache()