X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcull_list.cpp;h=1ce6dfae104fff5a9988298b8c18a73d1287e789;hb=b43fc66c17c2bef6dca66a966676b8128d5774ee;hp=2fb31014bbad1f73dadbe50f18d3003191374b47;hpb=9bc04a302572eb311a147a32ff1d36f1d91f2d7a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/cull_list.cpp b/src/cull_list.cpp index 2fb31014b..1ce6dfae1 100644 --- a/src/cull_list.cpp +++ b/src/cull_list.cpp @@ -2,138 +2,57 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * - * Written by Craig Edwards, Craig McLure, and others. * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include -#include -#include -#include -#include -#include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" -#include "commands.h" -#include "xline.h" -#include "inspstring.h" #include "inspircd.h" -#include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "cull_list.h" +#include -extern InspIRCd* ServerInstance; - -/* - * In current implementation of CullList, this isn't used. It did odd things with a lot of sockets. - */ -bool CullList::IsValid(userrec* user) +void CullList::Apply() { - time_t esignon = 0; - std::map::iterator es = exempt.find(user); - if (es != exempt.end()) - esignon = es->second; - - for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++) + std::set gone; + std::vector queue; + queue.reserve(list.size() + 32); + for(unsigned int i=0; i < list.size(); i++) { - /* - * BUGFIX - * - * Because there is an undetermined period of time between a user existing, - * and this function being called, we have to check for the following condition: - * - * Between CullList::AddItem(u) being called, and CullList::IsValid(u) being called, - * the user with the pointer u has quit, but only to be REPLACED WITH A NEW USER WHO - * BECAUSE OF ALLOCATION RULES, HAS THE SAME MEMORY ADDRESS! To prevent this, we - * cross reference each pointer to the user's signon time, and if the signon times - * do not match, we return false here to indicate this user is NOT valid as it - * seems to differ from the pointer snapshot we got a few seconds earlier. Should - * prevent a few random crashes during netsplits. - */ - if (user == u->second) - return (u->second->signon == esignon); + classbase* c = list[i]; + if (gone.insert(c).second) + { + ServerInstance->Logs->Log("CULLLIST", DEBUG, "Deleting %s @%p", typeid(*c).name(), + (void*)c); + c->cull(); + queue.push_back(c); + } + else + { + ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Object @%p culled twice!", + (void*)c); + } } - return false; -} - -CullItem::CullItem(userrec* u, std::string &r) -{ - this->user = u; - this->reason = r; -} - -CullItem::CullItem(userrec* u, const char* r) -{ - this->user = u; - this->reason = r; -} - -CullItem::~CullItem() -{ -} - -userrec* CullItem::GetUser() -{ - return this->user; -} - -std::string& CullItem::GetReason() -{ - return this->reason; -} - -CullList::CullList() -{ list.clear(); - exempt.clear(); -} - -void CullList::AddItem(userrec* user, std::string &reason) -{ - if (exempt.find(user) == exempt.end()) + for(unsigned int i=0; i < queue.size(); i++) { - CullItem item(user,reason); - list.push_back(item); - exempt[user] = user->signon; + classbase* c = queue[i]; + delete c; } -} - -void CullList::AddItem(userrec* user, const char* reason) -{ - if (exempt.find(user) == exempt.end()) + if (list.size()) { - CullItem item(user,reason); - list.push_back(item); - exempt[user] = user->signon; + ServerInstance->Logs->Log("CULLLIST",DEBUG, "WARNING: Objects added to cull list in a destructor"); + Apply(); } } -int CullList::Apply() +void ActionList::Run() { - int n = list.size(); - while (list.size()) + for(unsigned int i=0; i < list.size(); i++) { - std::vector::iterator a = list.begin(); - - userrec::QuitUser(ServerInstance, a->GetUser(), a->GetReason().c_str()); - list.erase(list.begin()); + list[i]->Call(); } - return n; + list.clear(); }