mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
Tried to implement sprintf that returns std::string of any size, realized it would scale like unreal scales to ircnet (e.g. it wouldnt!) so took it back out.
Moved chop() functionality into userrec::AddWriteBuf and make it nicer (no strlen) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4433 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
69f280701b
commit
983f18f834
@ -29,8 +29,6 @@
|
||||
#include "channels.h"
|
||||
|
||||
int common_channels(userrec *u, userrec *u2);
|
||||
void chop(char* str);
|
||||
void tidystring(char* str);
|
||||
void Blocking(int s);
|
||||
void NonBlocking(int s);
|
||||
int CleanAndResolve (char *resolvedHost, const char *unresolvedHost, bool forward);
|
||||
|
@ -161,7 +161,6 @@ void Write_NoFormat(int sock, const char *text)
|
||||
if (fd_ref_table[sock])
|
||||
{
|
||||
bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
|
||||
chop(tb);
|
||||
|
||||
if (Config->GetIOHook(fd_ref_table[sock]->port))
|
||||
{
|
||||
@ -210,7 +209,6 @@ void Write(int sock, char *text, ...)
|
||||
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
||||
va_end(argsPtr);
|
||||
bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
|
||||
chop(tb);
|
||||
|
||||
if (Config->GetIOHook(fd_ref_table[sock]->port))
|
||||
{
|
||||
@ -247,7 +245,6 @@ void WriteServ_NoFormat(int sock, const char* text)
|
||||
if (fd_ref_table[sock])
|
||||
{
|
||||
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
|
||||
chop(tb);
|
||||
|
||||
if (Config->GetIOHook(fd_ref_table[sock]->port))
|
||||
{
|
||||
@ -312,7 +309,6 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
|
||||
if (fd_ref_table[sock])
|
||||
{
|
||||
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
|
||||
chop(tb);
|
||||
|
||||
if (Config->GetIOHook(fd_ref_table[sock]->port))
|
||||
{
|
||||
@ -360,7 +356,6 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
|
||||
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
|
||||
va_end(argsPtr);
|
||||
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
|
||||
chop(tb);
|
||||
|
||||
if (Config->GetIOHook(fd_ref_table[sock]->port))
|
||||
{
|
||||
@ -403,7 +398,6 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
|
||||
va_start(argsPtr, data);
|
||||
vsnprintf(textbuffer, MAXBUF, data, argsPtr);
|
||||
va_end(argsPtr);
|
||||
chop(textbuffer);
|
||||
|
||||
// if no source given send it from the server.
|
||||
if (!source)
|
||||
|
@ -76,80 +76,6 @@ int common_channels(userrec *u, userrec *u2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tidystring(char* str)
|
||||
{
|
||||
// strips out double spaces before a : parameter
|
||||
|
||||
char temp[MAXBUF];
|
||||
bool go_again = true;
|
||||
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
// pointer voodoo++ --w00t
|
||||
while ((*str) && (*str == ' '))
|
||||
str++;
|
||||
|
||||
while (go_again)
|
||||
{
|
||||
bool noparse = false;
|
||||
int t = 0, a = 0;
|
||||
go_again = false;
|
||||
const int lenofstr = strlen(str);
|
||||
|
||||
/*
|
||||
* by caching strlen() of str, we theoretically avoid 3 expensive calls each time this loop
|
||||
* rolls around.. should speed things up a nanosecond or two. ;)
|
||||
*/
|
||||
|
||||
while (a < lenofstr)
|
||||
{
|
||||
if ((a < lenofstr - 1) && (noparse == false))
|
||||
{
|
||||
if ((str[a] == ' ') && (str[a+1] == ' '))
|
||||
{
|
||||
log(DEBUG,"Tidied extra space out of string: %s",str);
|
||||
go_again = true;
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
if (a < lenofstr - 1)
|
||||
{
|
||||
if ((str[a] == ' ') && (str[a+1] == ':'))
|
||||
{
|
||||
noparse = true;
|
||||
}
|
||||
}
|
||||
|
||||
temp[t++] = str[a++];
|
||||
}
|
||||
|
||||
temp[t] = '\0';
|
||||
strlcpy(str,temp,MAXBUF);
|
||||
}
|
||||
}
|
||||
|
||||
/* chop a string down to 512 characters and preserve linefeed (irc max
|
||||
* line length) */
|
||||
|
||||
void chop(char* str)
|
||||
{
|
||||
if (!str)
|
||||
{
|
||||
log(DEBUG,"ERROR! Null string passed to chop()!");
|
||||
return;
|
||||
}
|
||||
if (strlen(str) >= 511)
|
||||
{
|
||||
str[510] = '\r';
|
||||
str[511] = '\n';
|
||||
str[512] = '\0';
|
||||
log(DEBUG,"Excess line chopped.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Blocking(int s)
|
||||
{
|
||||
int flags = fcntl(s, F_GETFL, 0);
|
||||
|
@ -472,7 +472,17 @@ void userrec::AddWriteBuf(const std::string &data)
|
||||
return;
|
||||
}
|
||||
|
||||
sendq.append(data);
|
||||
if (data.length() > 512)
|
||||
{
|
||||
std::string newdata(data);
|
||||
newdata.resize(510);
|
||||
newdata.append("\r\n");
|
||||
sendq.append(newdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendq.append(data);
|
||||
}
|
||||
}
|
||||
|
||||
// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
|
||||
|
Loading…
x
Reference in New Issue
Block a user