diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-29 23:28:19 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-29 23:28:19 +0000 |
commit | 37edb225d7de2592c0a229ce18654d2eb2992f72 (patch) | |
tree | 9957731753fe826ec89418a6d710711c950e6dc0 | |
parent | 5e62a8399f1a7a1e9b0bd02a8df6b1a506d0b203 (diff) |
More removal of formatting where its not neccessary x("%s",str) == bad!
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2704 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/helperfuncs.h | 13 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 190 | ||||
-rw-r--r-- | src/message.cpp | 3 | ||||
-rw-r--r-- | src/modules.cpp | 16 |
4 files changed, 204 insertions, 18 deletions
diff --git a/include/helperfuncs.h b/include/helperfuncs.h index 269cd70b9..2d3b45a74 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -29,6 +29,7 @@ void log(int level,char *text, ...); void readfile(file_cache &F, const char* fname); + void Write(int sock,char *text, ...); void WriteServ(int sock, char* text, ...); void WriteFrom(int sock, userrec *user,char* text, ...); @@ -37,6 +38,18 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...); void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...); void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...); void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...); + +void Write_NoFormat(int sock,const char *text); +void WriteServ_NoFormat(int sock, const char* text); +void WriteFrom_NoFormat(int sock, userrec *user,const char* text); +void WriteTo_NoFormat(userrec *source, userrec *dest,const char *data); +void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* text); +void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text); +void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* text); +void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, const char* text); +void WriteCommon_NoFormat(userrec *u, const char* text); +void WriteCommonExcept_NoFormat(userrec *u, const char* text); + std::string GetServerDescription(char* servername); void WriteCommon(userrec *u, char* text, ...); void WriteCommonExcept(userrec *u, char* text, ...); diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c358b4bf5..c2a323a7c 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -123,7 +123,7 @@ void readfile(file_cache &F, const char* fname) log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size()); } -void Write_NoFormat(int sock,char *text) +void Write_NoFormat(int sock, const char *text) { if ((sock < 0) || (!text)) return; @@ -177,7 +177,7 @@ void Write(int sock,char *text, ...) else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!"); } -void WriteServ_NoFormat(int sock, char* text) +void WriteServ_NoFormat(int sock, const char* text) { if ((sock < 0) || (!text)) return; @@ -232,7 +232,7 @@ void WriteServ(int sock, char* text, ...) else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!"); } -void WriteFrom_NoFormat(int sock, userrec *user,char* text) +void WriteFrom_NoFormat(int sock, userrec *user, const char* text) { if ((sock < 0) || (!text) || (!user)) return; @@ -316,7 +316,7 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...) } } -void WriteTo_NoFormat(userrec *source, userrec *dest,char *data) +void WriteTo_NoFormat(userrec *source, userrec *dest, const char *data) { if ((!dest) || (!data)) return; @@ -357,6 +357,25 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...) } } +void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* text) +{ + if ((!Ptr) || (!user) || (!text)) + { + log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter"); + return; + } + std::vector<char*> *ulist = Ptr->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if (otheruser->fd != FD_MAGIC_NUMBER) + WriteTo_NoFormat(user,otheruser,text); + } +} + + /* write formatted text from a source user to all users on a channel * including the sender (NOT for privmsg, notice etc!) doesnt send to * users on remote servers */ @@ -380,7 +399,7 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...) { char* o = (*ulist)[j]; userrec* otheruser = (userrec*)o; - if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user)) + if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user)) { if (!user) { @@ -394,6 +413,35 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...) } } +void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text) +{ + if ((!Ptr) || (!text)) + { + log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter"); + return; + } + std::vector<char*> *ulist = Ptr->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user)) + { + if (!user) + { + WriteServ_NoFormat(otheruser->fd,text); + } + else + { + WriteTo_NoFormat(user,otheruser,text); + } + } + } +} + + + void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...) { if ((!Ptr) || (!text)) @@ -419,6 +467,26 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...) } } +void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* text) +{ + if ((!Ptr) || (!text)) + { + log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter"); + return; + } + std::vector<char*> *ulist = Ptr->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if (IS_LOCAL(otheruser)) + WriteServ_NoFormat(otheruser->fd,text); + } +} + + + /* write formatted text from a source user to all users on a channel except * for the sender (for privmsg etc) */ @@ -446,6 +514,24 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...) } } +void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, const char* text) +{ + if ((!Ptr) || (!user) || (!text)) + { + log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter"); + return; + } + std::vector<char*> *ulist = Ptr->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if ((IS_LOCAL(otheruser)) && (user != otheruser)) + WriteFrom_NoFormat(otheruser->fd,user,text); + } +} + std::string GetServerDescription(char* servername) { std::string description = ""; @@ -511,10 +597,57 @@ void WriteCommon(userrec *u, char* text, ...) // receives their OWN message for WriteCommon if (!sent_to_at_least_one) { - WriteFrom(u->fd,u,"%s",textbuffer); + WriteFrom_NoFormat(u->fd,u,textbuffer); + } +} + +void WriteCommon_NoFormat(userrec *u, const char* text) +{ + if (!u) + { + log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); + return; + } + + if (u->registered != 7) { + log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); + return; + } + // FIX: Stops a message going to the same person more than once + memset(&already_sent,0,MAX_DESCRIPTORS); + + bool sent_to_at_least_one = false; + + unsigned int y = u->chans.size(); + for (unsigned int i = 0; i < y; i++) + { + if (u->chans[i].channel) + { + std::vector<char*> *ulist = u->chans[i].channel->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if ((otheruser->fd > -1) && (!already_sent[otheruser->fd])) + { + already_sent[otheruser->fd] = 1; + WriteFrom_NoFormat(otheruser->fd,u,text); + sent_to_at_least_one = true; + } + } + } + } + // if the user was not in any channels, no users will receive the text. Make sure the user + // receives their OWN message for WriteCommon + if (!sent_to_at_least_one) + { + WriteFrom_NoFormat(u->fd,u,text); } } + + /* write a formatted string to all users who share at least one common * channel, NOT including the source user e.g. for use in QUIT */ @@ -563,6 +696,47 @@ void WriteCommonExcept(userrec *u, char* text, ...) } } +void WriteCommonExcept_NoFormat(userrec *u, const char* text) +{ + if (!u) + { + log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); + return; + } + + if (u->registered != 7) { + log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); + return; + } + + memset(&already_sent,0,MAX_DESCRIPTORS); + + unsigned int y = u->chans.size(); + for (unsigned int i = 0; i < y; i++) + { + if (u->chans[i].channel) + { + std::vector<char*> *ulist = u->chans[i].channel->GetUsers(); + unsigned int x = ulist->size(); + for (unsigned int j = 0; j < x; j++) + { + char* o = (*ulist)[j]; + userrec* otheruser = (userrec*)o; + if (u != otheruser) + { + if ((otheruser->fd > -1) && (!already_sent[otheruser->fd])) + { + already_sent[otheruser->fd] = 1; + WriteFrom_NoFormat(otheruser->fd,u,text); + } + } + } + } + } +} + + + void WriteOpers(char* text, ...) { if (!text) @@ -926,14 +1100,14 @@ void userlist(userrec *user,chanrec *c) { /* list overflowed into * multiple numerics */ - WriteServ(user->fd,"%s",list); + WriteServ_NoFormat(user->fd,list); snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name); } } /* if whats left in the list isnt empty, send it */ if (list[strlen(list)-1] != ':') { - WriteServ(user->fd,"%s",list); + WriteServ_NoFormat(user->fd,list); } } diff --git a/src/message.cpp b/src/message.cpp index 264871623..41455a2ef 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -146,9 +146,8 @@ void chop(char* str) return; } string temp = str; - FOREACH_MOD(I_OnServerRaw,OnServerRaw(temp,false,NULL)); const char* str2 = temp.c_str(); - snprintf(str,MAXBUF,"%s",str2); + strlcat(str,str2,MAXBUF); if (strlen(str) >= 511) { str[510] = '\r'; diff --git a/src/modules.cpp b/src/modules.cpp index cb9a228a2..87df6bdfc 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -425,17 +425,17 @@ void Server::SendMode(char **parameters, int pcnt, userrec *user) void Server::Send(int Socket, std::string s) { - Write(Socket,"%s",s.c_str()); + Write_NoFormat(Socket,s.c_str()); } void Server::SendServ(int Socket, std::string s) { - WriteServ(Socket,"%s",s.c_str()); + WriteServ_NoFormat(Socket,s.c_str()); } void Server::SendFrom(int Socket, userrec* User, std::string s) { - WriteFrom(Socket,User,"%s",s.c_str()); + WriteFrom_NoFormat(Socket,User,s.c_str()); } void Server::SendTo(userrec* Source, userrec* Dest, std::string s) @@ -448,7 +448,7 @@ void Server::SendTo(userrec* Source, userrec* Dest, std::string s) else { // otherwise it comes from the user specified - WriteTo(Source,Dest,"%s",s.c_str()); + WriteTo_NoFormat(Source,Dest,s.c_str()); } } @@ -461,11 +461,11 @@ void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool Inc { if (IncludeSender) { - WriteChannel(Channel,User,"%s",s.c_str()); + WriteChannel_NoFormat(Channel,User,s.c_str()); } else { - ChanExceptSender(Channel,User,"%s",s.c_str()); + ChanExceptSender_NoFormat(Channel,User,s.c_str()); } } @@ -478,11 +478,11 @@ void Server::SendCommon(userrec* User, std::string text,bool IncludeSender) { if (IncludeSender) { - WriteCommon(User,"%s",text.c_str()); + WriteCommon_NoFormat(User,text.c_str()); } else { - WriteCommonExcept(User,"%s",text.c_str()); + WriteCommonExcept_NoFormat(User,text.c_str()); } } |