diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-26 16:36:37 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-07-26 16:36:37 +0000 |
commit | 6344881c9f672d6cfdc8dd4818e79928181af0e1 (patch) | |
tree | cdb8b133264a2008c863c5a558b962e793873e75 | |
parent | e0b2608b68b495fbb4a70d4bbe649a7e3cb70076 (diff) |
Move a ton of stuff into caller* functors
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7578 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd.h | 13 | ||||
-rw-r--r-- | src/inspircd.cpp | 2 | ||||
-rw-r--r-- | src/userprocess.cpp | 48 |
3 files changed, 37 insertions, 26 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 90bd0d70d..e903e273f 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -237,9 +237,11 @@ typedef std::map<irc::string, unsigned int> clonemap; class InspIRCd; +DEFINE_HANDLER1(ProcessUserHandler, void, userrec*); DEFINE_HANDLER1(IsNickHandler, bool, const char*); DEFINE_HANDLER1(IsIdentHandler, bool, const char*); DEFINE_HANDLER1(FindDescriptorHandler, userrec*, int); +DEFINE_HANDLER1(FloodQuitUserHandler, void, userrec*); /* Forward declaration - required */ class XLineManager; @@ -381,9 +383,11 @@ class CoreExport InspIRCd : public classbase /**** Functors ****/ + ProcessUserHandler HandleProcessUser; IsNickHandler HandleIsNick; IsIdentHandler HandleIsIdent; FindDescriptorHandler HandleFindDescriptor; + FloodQuitUserHandler HandleFloodQuitUser; /** InspSocket classes pending deletion after being closed. * We don't delete these immediately as this may cause a segmentation fault. @@ -532,7 +536,7 @@ class CoreExport InspIRCd : public classbase * @return There is no actual return value, however upon exit, the user 'cu' may have been * marked for deletion in the global CullList. */ - void ProcessUser(userrec* cu); + caller1<void, userrec*> ProcessUser; /** Get the total number of currently loaded modules * @return The number of loaded modules @@ -1191,7 +1195,7 @@ class CoreExport InspIRCd : public classbase * fully registered yet, temporarily zline their IP. * @param current user to quit */ - void FloodQuitUser(userrec* current); + caller1<void, userrec*> FloodQuitUser; /** Restart the server. * This function will not return. If an error occurs, @@ -1234,6 +1238,11 @@ class CoreExport InspIRCd : public classbase * be culled. */ void InspSocketCull(); + + char* GetReadBuffer() + { + return this->ReadBuffer; + } }; #endif diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 0f599eda6..ec26325a1 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -382,9 +382,11 @@ void InspIRCd::WritePID(const std::string &filename) InspIRCd::InspIRCd(int argc, char** argv) : ModCount(0), GlobalCulls(this), + HandleProcessUser(this), HandleIsNick(this), HandleIsIdent(this), HandleFindDescriptor(this), + ProcessUser(&HandleProcessUser), IsNick(&HandleIsNick), IsIdent(&HandleIsIdent), FindDescriptor(&HandleFindDescriptor) diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 2c8e45413..818713f89 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -20,39 +20,41 @@ #include "socketengine.h" #include "command_parse.h" -void InspIRCd::FloodQuitUser(userrec* current) +void FloodQuitUserHandler::Call(userrec* current) { - this->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host); - this->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s", + Server->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host); + Server->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s", current->registered == REG_ALL ? current->nick : "", current->registered == REG_ALL ? "!" : "", current->ident, current->host); - current->SetWriteError("Excess flood"); + userrec::QuitUser(Server, current, "Excess flood"); if (current->registered != REG_ALL) { - XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString()); - XLines->apply_lines(APPLY_ZLINES); + Server->XLines->add_zline(120, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString()); + Server->XLines->apply_lines(APPLY_ZLINES); } } -void InspIRCd::ProcessUser(userrec* cu) +void ProcessUserHandler::Call(userrec* cu) { int result = EAGAIN; if (cu->GetFd() == FD_MAGIC_NUMBER) return; - if (this->Config->GetIOHook(cu->GetPort())) + char* ReadBuffer = Server->GetReadBuffer(); + + if (Server->Config->GetIOHook(cu->GetPort())) { int result2 = 0; int MOD_RESULT = 0; try { - MOD_RESULT = this->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2); + MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2); } catch (CoreException& modexcept) { - this->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); + Server->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } if (MOD_RESULT < 0) @@ -75,12 +77,10 @@ void InspIRCd::ProcessUser(userrec* cu) int currfd; int floodlines = 0; - this->stats->statsRecv += result; + Server->stats->statsRecv += result; /* * perform a check on the raw buffer as an array (not a string!) to remove * character 0 which is illegal in the RFC - replace them with spaces. - * XXX - no garauntee there's not \0's in the middle of the data, - * and no reason for it to be terminated either. -- Om */ for (int checker = 0; checker < result; checker++) @@ -104,16 +104,16 @@ void InspIRCd::ProcessUser(userrec* cu) if (current->registered == REG_ALL) { // Make sure they arn't flooding long lines. - if (TIME > current->reset_due) + if (Server->Time() > current->reset_due) { - current->reset_due = TIME + current->threshold; + current->reset_due = Server->Time() + current->threshold; current->lines_in = 0; } current->lines_in++; if (current->flood && current->lines_in > current->flood) - FloodQuitUser(current); + Server->FloodQuitUser(current); else { current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2); @@ -121,7 +121,7 @@ void InspIRCd::ProcessUser(userrec* cu) } } else - FloodQuitUser(current); + Server->FloodQuitUser(current); return; } @@ -129,21 +129,21 @@ void InspIRCd::ProcessUser(userrec* cu) // while there are complete lines to process... while (current->BufferIsReady()) { - if (TIME > current->reset_due) + if (Server->Time() > current->reset_due) { - current->reset_due = TIME + current->threshold; + current->reset_due = Server->Time() + current->threshold; current->lines_in = 0; } if (++current->lines_in > current->flood && current->flood) { - FloodQuitUser(current); + Server->FloodQuitUser(current); return; } if ((++floodlines > current->flood) && (current->flood != 0)) { - FloodQuitUser(current); + Server->FloodQuitUser(current); return; } @@ -154,7 +154,7 @@ void InspIRCd::ProcessUser(userrec* cu) if (single_line.length() > MAXBUF - 2) /* MAXBUF is 514 to allow for neccessary line terminators */ single_line.resize(MAXBUF - 2); /* So to trim to 512 here, we use MAXBUF - 2 */ - this->Parser->ProcessBuffer(single_line, current); + Server->Parser->ProcessBuffer(single_line, current); } return; @@ -162,7 +162,7 @@ void InspIRCd::ProcessUser(userrec* cu) if ((result == -1) && (errno != EAGAIN) && (errno != EINTR)) { - userrec::QuitUser(this, cu, errno ? strerror(errno) : "EOF from client"); + userrec::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client"); return; } } @@ -174,7 +174,7 @@ void InspIRCd::ProcessUser(userrec* cu) } else if (result == 0) { - userrec::QuitUser(this, cu, "Connection closed"); + userrec::QuitUser(Server, cu, "Connection closed"); return; } } |