From 80015fe115f37243e7b75a48312edb5a029fa229 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 29 Apr 2005 05:46:17 +0000 Subject: Updated buffering, faster and more sensible (old code sucks) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1256 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 27 +++++++++++---------------- src/users.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index ee6fa803a..cb702245c 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -3863,7 +3863,7 @@ int InspIRCd(void) tvs.tv_sec = 0; tv.tv_sec = 0; tv.tv_usec = 10000L; - char data[10240]; + char data[65535]; timeval tval; fd_set sfd; tval.tv_usec = 10000L; @@ -4065,11 +4065,11 @@ int InspIRCd(void) result = EAGAIN; if ((count2a->second->fd != FD_MAGIC_NUMBER) && (count2a->second->fd != -1) && (FD_ISSET (count2a->second->fd, &sfd))) { - memset(data, 0, 10240); - result = read(count2a->second->fd, data, 10240); - + result = read(count2a->second->fd, data, 65535); if (result) { + if (result > 0) + data[result] = '\0'; // perform a check on the raw buffer as an array (not a string!) to remove // characters 0 and 7 which are illegal in the RFC - replace them with spaces. // hopefully this should stop even more people whining about "Unknown command: *" @@ -4080,9 +4080,11 @@ int InspIRCd(void) } userrec* current = count2a->second; int currfd = current->fd; - char* l = strtok(data,"\n"); + //char* l = strtok(data,"\n"); int floodlines = 0; - while (l) + current->AddBuffer(data); + // while there are complete lines to process... + while (current->BufferIsReady()) { floodlines++; if ((floodlines > current->flood) && (current->flood != 0)) @@ -4094,15 +4096,8 @@ int InspIRCd(void) } char sanitized[NetBufferSize]; memset(sanitized, 0, NetBufferSize); - int ptt = 0; - for (int pt = 0; pt < strlen(l); pt++) - { - if (l[pt] != '\r') - { - sanitized[ptt++] = l[pt]; - } - } - sanitized[ptt] = '\0'; + // use GetBuffer to copy single lines into the sanitized string + strlcpy(sanitized,current->GetBuffer().c_str(),MAXBUF); if (*sanitized) { @@ -4127,7 +4122,7 @@ int InspIRCd(void) goto label; } - l = strtok(NULL,"\n"); + //l = strtok(NULL,"\n"); } goto label; } diff --git a/src/users.cpp b/src/users.cpp index c0332dbe4..40589b234 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -44,6 +44,7 @@ userrec::userrec() flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0; haspassed = false; dns_done = false; + recvq = ""; strcpy(result,""); for (int i = 0; i < MAXCHANS; i++) { @@ -163,3 +164,43 @@ bool userrec::HasPermission(char* command) } +void userrec::AddBuffer(std::string a) +{ + std::string b = ""; + for (int i = 0; i < a.length(); i++) + if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7)) + b = b + a[i]; + std::stringstream stream(recvq); + stream << b; + recvq = stream.str(); +} + +bool userrec::BufferIsReady() +{ + for (int i = 0; i < recvq.length(); i++) + if (recvq[i] == '\n') + return true; + return false; +} + +void userrec::ClearBuffer() +{ + recvq = ""; +} + +std::string userrec::GetBuffer() +{ + log(DEBUG,"GetBuffer\n%s\n",recvq.c_str()); + char* line = (char*)recvq.c_str(); + std::string ret = ""; + while ((*line != '\n') && (strlen(line))) + { + ret = ret + *line; + line++; + } + if ((*line == '\n') || (*line == '\r')) + line++; + recvq = line; + return ret; +} + -- cgit v1.2.3