summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp34
-rw-r--r--src/commands/cmd_who.cpp28
-rw-r--r--src/filelogger.cpp10
-rw-r--r--src/inspstring.cpp122
-rw-r--r--src/users.cpp11
5 files changed, 31 insertions, 174 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 39ff8d59c..0cc007464 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -733,43 +733,37 @@ int Channel::CountInvisible()
return count;
}
-char* Channel::ChanModes(bool showkey)
+const char* Channel::ChanModes(bool showkey)
{
- static char scratch[MAXBUF];
- static char sparam[MAXBUF];
- char* offset = scratch;
- std::string extparam;
+ static std::string scratch;
+ std::string sparam;
- *scratch = '\0';
- *sparam = '\0';
+ scratch.clear();
/* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
for(int n = 0; n < 64; n++)
{
if(this->modes[n])
{
- *offset++ = n + 65;
- extparam.clear();
+ scratch.push_back(n + 65);
if (n == 'k' - 65 && !showkey)
{
- extparam = "<key>";
+ sparam += " <key>";
}
else
{
- extparam = this->GetModeParameter(n + 65);
- }
- if (!extparam.empty())
- {
- charlcat(sparam,' ',MAXBUF);
- strlcat(sparam,extparam.c_str(),MAXBUF);
+ const std::string param = this->GetModeParameter(n + 65);
+ if (!param.empty())
+ {
+ sparam += ' ';
+ sparam += param;
+ }
}
}
}
- /* Null terminate scratch */
- *offset = '\0';
- strlcat(scratch,sparam,MAXBUF);
- return scratch;
+ scratch += sparam;
+ return scratch.c_str();
}
/* compile a userlist of a channel into a string, each nick seperated by
diff --git a/src/commands/cmd_who.cpp b/src/commands/cmd_who.cpp
index 5a5c27dcf..c865cf67b 100644
--- a/src/commands/cmd_who.cpp
+++ b/src/commands/cmd_who.cpp
@@ -249,33 +249,17 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
opt_far = false;
opt_time = false;
- Channel *ch = NULL;
std::vector<std::string> whoresults;
std::string initial = "352 " + user->nick + " ";
- char matchtext[MAXBUF];
- bool usingwildcards = false;
-
/* Change '0' into '*' so the wildcard matcher can grok it */
- if (parameters[0] == "0")
- strlcpy(matchtext, "*", MAXBUF);
- else
- strlcpy(matchtext, parameters[0].c_str(), MAXBUF);
+ std::string matchtext = ((parameters[0] == "0") ? "*" : parameters[0]);
- for (const char* check = matchtext; *check; check++)
- {
- if (*check == '*' || *check == '?')
- {
- usingwildcards = true;
- break;
- }
- }
+ // WHO flags count as a wildcard
+ bool usingwildcards = ((parameters.size() > 1) || (matchtext.find_first_of("*?") != std::string::npos));
if (parameters.size() > 1)
{
- /* Fix for bug #444, WHO flags count as a wildcard */
- usingwildcards = true;
-
for (std::string::const_iterator iter = parameters[1].begin(); iter != parameters[1].end(); ++iter)
{
switch (*iter)
@@ -325,7 +309,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
/* who on a channel? */
- ch = ServerInstance->FindChan(matchtext);
+ Channel* ch = ServerInstance->FindChan(matchtext);
if (ch)
{
@@ -364,7 +348,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
{
User* oper = *i;
- if (whomatch(user, oper, matchtext))
+ if (whomatch(user, oper, matchtext.c_str()))
{
if (!user->SharesChannelWith(oper))
{
@@ -380,7 +364,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
{
for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++)
{
- if (whomatch(user, i->second, matchtext))
+ if (whomatch(user, i->second, matchtext.c_str()))
{
if (!user->SharesChannelWith(i->second))
{
diff --git a/src/filelogger.cpp b/src/filelogger.cpp
index 0575256d0..245cbbaab 100644
--- a/src/filelogger.cpp
+++ b/src/filelogger.cpp
@@ -40,7 +40,7 @@ FileLogStream::~FileLogStream()
void FileLogStream::OnLog(int loglevel, const std::string &type, const std::string &text)
{
- static char TIMESTR[26];
+ static std::string TIMESTR;
static time_t LAST = 0;
if (loglevel < this->loglvl)
@@ -53,11 +53,13 @@ void FileLogStream::OnLog(int loglevel, const std::string &type, const std::stri
time_t local = ServerInstance->Time();
struct tm *timeinfo = localtime(&local);
- strlcpy(TIMESTR,asctime(timeinfo),26);
- TIMESTR[24] = ':';
+ TIMESTR.assign(asctime(timeinfo), 24);
+ TIMESTR += ": ";
LAST = ServerInstance->Time();
}
- std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
+ std::string out = TIMESTR;
+ out += text;
+ out += '\n';
this->f->WriteLogLine(out);
}
diff --git a/src/inspstring.cpp b/src/inspstring.cpp
index 534b7ce00..72d6c64c8 100644
--- a/src/inspstring.cpp
+++ b/src/inspstring.cpp
@@ -21,128 +21,6 @@
#include "inspircd.h"
-/*
- * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef HAS_STRLCPY
-CoreExport size_t strlcat(char *dst, const char *src, size_t siz)
-{
- char *d = dst;
- const char *s = src;
- size_t n = siz, dlen;
-
- while (n-- != 0 && *d != '\0')
- d++;
-
- dlen = d - dst;
- n = siz - dlen;
-
- if (n == 0)
- return(dlen + strlen(s));
-
- while (*s != '\0')
- {
- if (n != 1)
- {
- *d++ = *s;
- n--;
- }
-
- s++;
- }
-
- *d = '\0';
- return(dlen + (s - src)); /* count does not include NUL */
-}
-
-CoreExport size_t strlcpy(char *dst, const char *src, size_t siz)
-{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0)
- {
- do
- {
- if ((*d++ = *s++) == 0)
- break;
- } while (--n != 0);
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0)
- {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++);
- }
-
- return(s - src - 1); /* count does not include NUL */
-}
-#endif
-
-CoreExport int charlcat(char* x,char y,int z)
-{
- char* x__n = x;
- int v = 0;
-
- while(*x__n++)
- v++;
-
- if (v < z - 1)
- {
- *--x__n = y;
- *++x__n = 0;
- }
-
- return v;
-}
-
-CoreExport bool charremove(char* mp, char remove)
-{
- char* mptr = mp;
- bool shift_down = false;
-
- while (*mptr)
- {
- if (*mptr == remove)
- shift_down = true;
-
- if (shift_down)
- *mptr = *(mptr+1);
-
- mptr++;
- }
-
- return shift_down;
-}
-
static const char hextable[] = "0123456789abcdef";
std::string BinToHex(const std::string& data)
diff --git a/src/users.cpp b/src/users.cpp
index 3fd558daf..460f97a18 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -153,15 +153,15 @@ void User::SetMode(unsigned char m, bool value)
const char* User::FormatModes(bool showparameters)
{
- static char data[MAXBUF];
+ static std::string data;
std::string params;
- int offset = 0;
+ data.clear();
for (unsigned char n = 0; n < 64; n++)
{
if (modes[n])
{
- data[offset++] = n + 65;
+ data.push_back(n + 65);
ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
if (showparameters && mh && mh->GetNumParams(true))
{
@@ -171,9 +171,8 @@ const char* User::FormatModes(bool showparameters)
}
}
}
- data[offset] = 0;
- strlcat(data, params.c_str(), MAXBUF);
- return data;
+ data += params;
+ return data.c_str();
}
User::User(const std::string &uid, const std::string& sid, int type)