+ 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);
+
+ for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
+ {
+ safei = n;
+ safei++;
+
+ 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 && !b->Reason.empty()) || b->Reason.empty())
+ {
+ /* we need to remove this one. */
+ ServerInstance->Logs->Log("BANCACHE", DEBUG, "BanCacheManager::RemoveEntries(): Removing a hit on " + b->IP);
+ delete b;
+ b = NULL;
+ BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
+ removed++;
+ }
+ }
+
+ /* End of safe section */
+ n = safei;
+ }
+
+
+ return removed;
+}
+
+void BanCacheManager::RehashCache()
+{
+ BanCacheHash* NewHash = new BanCacheHash();
+
+ BanCacheHash::iterator safei;
+ for (BanCacheHash::iterator n = BanHash->begin(); n != BanHash->end(); )
+ {
+ safei = n;
+ safei++;
+
+ /* Safe to delete items here through iterator 'n' */
+ BanCacheHit *b = n->second;
+
+ if (ServerInstance->Time() > b->Expiry)
+ {
+ /* we need to remove this one. */
+ delete b;
+ b = NULL;
+ BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
+ }
+ else
+ {
+ /* Actually inserts a std::pair */
+ NewHash->insert(*n);
+ }
+
+ /* End of safe section */
+
+ n = safei;
+ }
+
+ delete BanHash;
+ BanHash = NewHash;
+}