diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.cpp | 47 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 10 | ||||
-rw-r--r-- | src/logger.cpp | 13 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 8 | ||||
-rw-r--r-- | src/snomasks.cpp | 22 | ||||
-rw-r--r-- | src/usermanager.cpp | 10 | ||||
-rw-r--r-- | src/users.cpp | 103 |
7 files changed, 58 insertions, 155 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 0cc007464..1c8e9e856 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -595,17 +595,12 @@ void Channel::KickUser(User *src, User *user, const std::string& reason) void Channel::WriteChannel(User* user, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (!user || !text) return; - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteChannel(user, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteChannel(user, textbuffer); } void Channel::WriteChannel(User* user, const std::string &text) @@ -624,17 +619,12 @@ void Channel::WriteChannel(User* user, const std::string &text) void Channel::WriteChannelWithServ(const std::string& ServName, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (!text) return; - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteChannelWithServ(ServName, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteChannelWithServ(ServName, textbuffer); } void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text) @@ -652,34 +642,23 @@ void Channel::WriteChannelWithServ(const std::string& ServName, const std::strin * for the sender (for privmsg etc) */ void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (!text) return; - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteAllExceptSender(user, serversource, status, textbuffer); } void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (!text) return; - int offset = snprintf(textbuffer,MAXBUF,":%s ", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str()); - - va_start(argsPtr, text); - vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr); - va_end(argsPtr); - - this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + textbuffer = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + textbuffer; + this->RawWriteAllExcept(user, serversource, status, except_list, textbuffer); } void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text) diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c097b0033..0673efedf 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -372,13 +372,9 @@ void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::str void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - va_start (argsPtr, format); - vsnprintf(textbuffer, MAXBUF, format, argsPtr); - va_end(argsPtr); - - this->SendWhoisLine(user, dest, numeric, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, format, format) + this->SendWhoisLine(user, dest, numeric, textbuffer); } /** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array diff --git a/src/logger.cpp b/src/logger.cpp index b33f65ac4..2b0b623f6 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -296,18 +296,11 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l) void LogManager::Log(const std::string &type, int loglevel, const char *fmt, ...) { if (Logging) - { return; - } - - va_list a; - static char buf[65536]; - - va_start(a, fmt); - vsnprintf(buf, 65536, fmt, a); - va_end(a); - this->Log(type, loglevel, std::string(buf)); + std::string buf; + VAFORMAT(buf, fmt, fmt); + this->Log(type, loglevel, buf); } void LogManager::Log(const std::string &type, int loglevel, const std::string &msg) diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 92d274679..244180b2f 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -380,12 +380,8 @@ ModResult ModuleSpanningTree::HandleVersion(const std::vector<std::string>& para */ void ModuleSpanningTree::RemoteMessage(User* user, const char* format, ...) { - char text[MAXBUF]; - va_list argsPtr; - - va_start(argsPtr, format); - vsnprintf(text, MAXBUF, format, argsPtr); - va_end(argsPtr); + std::string text; + VAFORMAT(text, format, format); if (IS_LOCAL(user)) user->WriteNotice(text); diff --git a/src/snomasks.cpp b/src/snomasks.cpp index f018a0d1a..820f65e4b 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -52,26 +52,16 @@ void SnomaskManager::WriteGlobalSno(char letter, const std::string& text) void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteToSnoMask(letter, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteToSnoMask(letter, textbuffer); } void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteGlobalSno(letter, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteGlobalSno(letter, textbuffer); } SnomaskManager::SnomaskManager() diff --git a/src/usermanager.cpp b/src/usermanager.cpp index aa0be2f3b..09c9a5bde 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -322,13 +322,9 @@ unsigned int UserManager::LocalUserCount() void UserManager::ServerNoticeAll(const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - va_start (argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - const std::string message = "NOTICE $" + ServerInstance->Config->ServerName + " :" + textbuffer; + std::string message; + VAFORMAT(message, text, text); + message = "NOTICE $" + ServerInstance->Config->ServerName + " :" + message; for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++) { diff --git a/src/users.cpp b/src/users.cpp index f7dafeb86..7e1df61fe 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1016,14 +1016,9 @@ void LocalUser::Write(const std::string& text) */ void LocalUser::Write(const char *text, ...) { - va_list argsPtr; - char textbuffer[MAXBUF]; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->Write(std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->Write(textbuffer); } void User::WriteServ(const std::string& text) @@ -1036,14 +1031,9 @@ void User::WriteServ(const std::string& text) */ void User::WriteServ(const char* text, ...) { - va_list argsPtr; - char textbuffer[MAXBUF]; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteServ(std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteServ(textbuffer); } void User::WriteNotice(const std::string& text) @@ -1053,14 +1043,9 @@ void User::WriteNotice(const std::string& text) void User::WriteNumeric(unsigned int numeric, const char* text, ...) { - va_list argsPtr; - char textbuffer[MAXBUF]; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteNumeric(numeric, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteNumeric(numeric, textbuffer); } void User::WriteNumeric(unsigned int numeric, const std::string &text) @@ -1088,14 +1073,9 @@ void User::WriteFrom(User *user, const std::string &text) void User::WriteFrom(User *user, const char* text, ...) { - va_list argsPtr; - char textbuffer[MAXBUF]; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - this->WriteFrom(user, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + this->WriteFrom(user, textbuffer); } @@ -1103,14 +1083,9 @@ void User::WriteFrom(User *user, const char* text, ...) void User::WriteTo(User *dest, const char *data, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - - va_start(argsPtr, data); - vsnprintf(textbuffer, MAXBUF, data, argsPtr); - va_end(argsPtr); - - this->WriteTo(dest, std::string(textbuffer)); + std::string textbuffer; + VAFORMAT(textbuffer, data, data); + this->WriteTo(dest, textbuffer); } void User::WriteTo(User *dest, const std::string &data) @@ -1120,36 +1095,24 @@ void User::WriteTo(User *dest, const std::string &data) void User::WriteCommon(const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (this->registered != REG_ALL || quitting) return; - int len = snprintf(textbuffer,MAXBUF,":%s ",this->GetFullHost().c_str()); - - va_start(argsPtr, text); - vsnprintf(textbuffer + len, MAXBUF - len, text, argsPtr); - va_end(argsPtr); - - this->WriteCommonRaw(std::string(textbuffer), true); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + textbuffer = ":" + this->GetFullHost() + " " + textbuffer; + this->WriteCommonRaw(textbuffer, true); } void User::WriteCommonExcept(const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - if (this->registered != REG_ALL || quitting) return; - int len = snprintf(textbuffer,MAXBUF,":%s ",this->GetFullHost().c_str()); - - va_start(argsPtr, text); - vsnprintf(textbuffer + len, MAXBUF - len, text, argsPtr); - va_end(argsPtr); - - this->WriteCommonRaw(std::string(textbuffer), false); + std::string textbuffer; + VAFORMAT(textbuffer, text, text); + textbuffer = ":" + this->GetFullHost() + " " + textbuffer; + this->WriteCommonRaw(textbuffer, false); } void User::WriteCommonRaw(const std::string &line, bool include_self) @@ -1248,14 +1211,9 @@ void FakeUser::SendText(const std::string& line) void User::SendText(const char *text, ...) { - va_list argsPtr; - char line[MAXBUF]; - - va_start(argsPtr, text); - vsnprintf(line, MAXBUF, text, argsPtr); - va_end(argsPtr); - - SendText(std::string(line)); + std::string line; + VAFORMAT(line, text, text); + SendText(line); } void User::SendText(const std::string &LinePrefix, std::stringstream &TextStream) @@ -1445,13 +1403,8 @@ bool User::ChangeIdent(const char* newident) void User::SendAll(const char* command, const char* text, ...) { - char textbuffer[MAXBUF]; - va_list argsPtr; - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - + std::string textbuffer; + VAFORMAT(textbuffer, text, text); const std::string message = ":" + this->GetFullHost() + " " + command + " $* :" + textbuffer; for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++) |