summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <adam@sigterm.info>2013-05-15 12:33:47 -0700
committerAdam <adam@sigterm.info>2013-05-15 12:33:47 -0700
commite586aaab7c4f7b03514c83451d73b73f55dc6998 (patch)
tree18f4370778cc79d2f21a4308dafbb29a77cfa213 /src
parent23e8bba13c55d33ce89d505780da36c9589e300a (diff)
parentaccccc212cd4f08a3c5532b1ae7a17e76bac8718 (diff)
Merge pull request #531 from SaberUK/master+snprintf-removal
Replace some C-isms with C++-isms.
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp33
-rw-r--r--src/commands/cmd_kick.cpp2
-rw-r--r--src/commands/cmd_oper.cpp24
-rw-r--r--src/commands/cmd_stats.cpp2
-rw-r--r--src/commands/cmd_time.cpp13
-rw-r--r--src/configreader.cpp14
-rw-r--r--src/modmanager_dynamic.cpp7
-rw-r--r--src/modules/extra/m_ldapoper.cpp17
-rw-r--r--src/modules/m_chanhistory.cpp8
-rw-r--r--src/modules/m_chanlog.cpp7
-rw-r--r--src/modules/m_cloaking.cpp5
-rw-r--r--src/modules/m_customtitle.cpp24
-rw-r--r--src/modules/m_dnsbl.cpp6
-rw-r--r--src/modules/m_messageflood.cpp6
-rw-r--r--src/modules/m_namedmodes.cpp5
-rw-r--r--src/modules/m_sqloper.cpp16
-rw-r--r--src/modules/m_sslinfo.cpp14
-rw-r--r--src/server.cpp14
-rw-r--r--src/socketengines/socketengine_poll.cpp2
-rw-r--r--src/usermanager.cpp10
-rw-r--r--src/userprocess.cpp3
-rw-r--r--src/users.cpp47
-rw-r--r--src/wildcard.cpp22
-rw-r--r--src/xline.cpp8
24 files changed, 100 insertions, 209 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 9e9ad670a..39ff8d59c 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -472,10 +472,9 @@ bool Channel::CheckBan(User* user, const std::string& mask)
if (at == std::string::npos)
return false;
- char tomatch[MAXBUF];
- snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
+ const std::string nickIdent = user->nick + "!" + user->ident;
std::string prefix = mask.substr(0, at);
- if (InspIRCd::Match(tomatch, prefix, NULL))
+ if (InspIRCd::Match(nickIdent, prefix, NULL))
{
std::string suffix = mask.substr(at + 1);
if (InspIRCd::Match(user->host, suffix, NULL) ||
@@ -532,9 +531,9 @@ void Channel::PartUser(User *user, std::string &reason)
this->DelUser(user);
}
-void Channel::KickUser(User *src, User *user, const char* reason)
+void Channel::KickUser(User *src, User *user, const std::string& reason)
{
- if (!src || !user || !reason)
+ if (!src || !user)
return;
Membership* memb = GetUser(user);
@@ -585,7 +584,7 @@ void Channel::KickUser(User *src, User *user, const char* reason)
CUList except_list;
FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
- WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
+ WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason.c_str());
user->chans.erase(this);
this->RemoveAllPrefixes(user);
@@ -611,18 +610,15 @@ void Channel::WriteChannel(User* user, const char* text, ...)
void Channel::WriteChannel(User* user, const std::string &text)
{
- char tb[MAXBUF];
-
if (!user)
return;
- snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
- std::string out = tb;
+ const std::string message = ":" + user->GetFullHost() + " " + text;
for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
{
if (IS_LOCAL(i->first))
- i->first->Write(out);
+ i->first->Write(message);
}
}
@@ -643,15 +639,12 @@ void Channel::WriteChannelWithServ(const std::string& ServName, const char* text
void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
{
- char tb[MAXBUF];
-
- snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
- std::string out = tb;
+ const std::string message = ":" + (ServName.empty() ? ServerInstance->Config->ServerName : ServName) + " " + text;
for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
{
if (IS_LOCAL(i->first))
- i->first->Write(out);
+ i->first->Write(message);
}
}
@@ -691,12 +684,8 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList
void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
{
- char tb[MAXBUF];
-
- snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
- std::string out = tb;
-
- this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
+ const std::string message = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + text;
+ this->RawWriteAllExcept(user, serversource, status, except_list, message);
}
void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
diff --git a/src/commands/cmd_kick.cpp b/src/commands/cmd_kick.cpp
index 3c5fb0052..87ee1da6d 100644
--- a/src/commands/cmd_kick.cpp
+++ b/src/commands/cmd_kick.cpp
@@ -77,7 +77,7 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
}
- c->KickUser(user, u, reason.c_str());
+ c->KickUser(user, u, reason);
return CMD_SUCCESS;
}
diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp
index 117813719..15ee9c969 100644
--- a/src/commands/cmd_oper.cpp
+++ b/src/commands/cmd_oper.cpp
@@ -21,8 +21,6 @@
#include "inspircd.h"
-bool OneOfMatches(const char* host, const char* ip, const char* hostlist);
-
/** Handle /OPER. These command handlers can be reloaded by the core,
* and handle basic RFC1459 commands. Commands within modules work
* the same way, however, they can be fully unloaded, where these
@@ -43,30 +41,14 @@ class CommandOper : public SplitCommand
CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
};
-bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
-}
-
CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
{
- char TheHost[MAXBUF];
- char TheIP[MAXBUF];
bool match_login = false;
bool match_pass = false;
bool match_hosts = false;
- snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
- snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString().c_str());
+ const std::string userHost = user->ident + "@" + user->host;
+ const std::string userIP = user->ident + "@" + user->GetIPString();
OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
if (i != ServerInstance->Config->oper_blocks.end())
@@ -75,7 +57,7 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
ConfigTag* tag = ifo->oper_block;
match_login = true;
match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
- match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host"));
+ match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
if (match_pass && match_hosts)
{
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp
index ccf753956..d9f3c1496 100644
--- a/src/commands/cmd_stats.cpp
+++ b/src/commands/cmd_stats.cpp
@@ -283,7 +283,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
double per = (n_eaten/n_elapsed);
-
+
char percent[30];
snprintf(percent, 30, "%03.5f%%", per);
diff --git a/src/commands/cmd_time.cpp b/src/commands/cmd_time.cpp
index db452d381..8c516ac42 100644
--- a/src/commands/cmd_time.cpp
+++ b/src/commands/cmd_time.cpp
@@ -50,16 +50,13 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User
{
if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
return CMD_SUCCESS;
- struct tm* timeinfo;
- time_t local = ServerInstance->Time();
-
- timeinfo = localtime(&local);
- char tms[26];
- snprintf(tms,26,"%s",asctime(timeinfo));
- tms[24] = 0;
+ time_t local = ServerInstance->Time();
+ struct tm* timeinfo = localtime(&local);
+ const std::string& humanTime = asctime(timeinfo);
- user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),tms);
+ user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),
+ ServerInstance->Config->ServerName.c_str(), humanTime.c_str());
return CMD_SUCCESS;
}
diff --git a/src/configreader.cpp b/src/configreader.cpp
index dcf4b7162..cd6122b25 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -335,13 +335,13 @@ struct DeprecatedConfig
{
/** Tag name. */
std::string tag;
-
+
/** Attribute key. */
std::string key;
-
+
/** Attribute value. */
std::string value;
-
+
/** Reason for deprecation. */
std::string reason;
};
@@ -595,14 +595,14 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
ServerInstance->BindPorts(pl);
if (pl.size())
{
- errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n";
+ errstr << "Not all your client ports could be bound." << std::endl
+ << "The following port(s) failed to bind:" << std::endl;
int j = 1;
for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
{
- char buf[MAXBUF];
- snprintf(buf, MAXBUF, "%d. Address: %s Reason: %s\n", j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
- errstr << buf;
+ errstr << j << ".\tAddress: " << (i->first.empty() ? "<all>" : i->first.c_str()) << "\tReason: "
+ << i->second << std::endl;
}
}
}
diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp
index a153accbb..b58697679 100644
--- a/src/modmanager_dynamic.cpp
+++ b/src/modmanager_dynamic.cpp
@@ -37,10 +37,9 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
if (filename.find('/') != std::string::npos)
return false;
- char modfile[MAXBUF];
- snprintf(modfile,MAXBUF,"%s/%s",ServerInstance->Config->ModPath.c_str(),filename.c_str());
+ const std::string moduleFile = ServerInstance->Config->ModPath + "/" + filename;
- if (!ServerConfig::FileExists(modfile))
+ if (!ServerConfig::FileExists(moduleFile.c_str()))
{
LastModuleError = "Module file could not be found: " + filename;
ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
@@ -55,7 +54,7 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
}
Module* newmod = NULL;
- DLLManager* newhandle = new DLLManager(modfile);
+ DLLManager* newhandle = new DLLManager(moduleFile.c_str());
try
{
diff --git a/src/modules/extra/m_ldapoper.cpp b/src/modules/extra/m_ldapoper.cpp
index 856e42dc3..f10773ec9 100644
--- a/src/modules/extra/m_ldapoper.cpp
+++ b/src/modules/extra/m_ldapoper.cpp
@@ -35,21 +35,6 @@
/* $ModDesc: Adds the ability to authenticate opers via LDAP */
/* $LinkerFlags: -lldap */
-// Duplicated code, also found in cmd_oper and m_sqloper
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
-}
-
struct RAIILDAPString
{
char *str;
@@ -97,7 +82,7 @@ class ModuleLDAPAuth : public Module
std::string acceptedhosts = tag->getString("host");
std::string hostname = user->ident + "@" + user->host;
- if (!OneOfMatches(hostname.c_str(), user->GetIPString().c_str(), acceptedhosts))
+ if (!InspIRCd::MatchMask(acceptedhosts, hostname, user->GetIPString()))
return false;
if (!LookupOper(opername, inputpass))
diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp
index 3ee823b4a..6633e9582 100644
--- a/src/modules/m_chanhistory.cpp
+++ b/src/modules/m_chanhistory.cpp
@@ -133,7 +133,7 @@ class ModuleChanHistory : public Module
sendnotice = tag->getBool("notice", true);
}
- void OnUserMessage(User* user,void* dest,int target_type, const std::string &text, char status, const CUList&)
+ void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList&)
{
if (target_type == TYPE_CHANNEL && status == 0)
{
@@ -141,10 +141,8 @@ class ModuleChanHistory : public Module
HistoryList* list = m.ext.get(c);
if (list)
{
- char buf[MAXBUF];
- snprintf(buf, MAXBUF, ":%s PRIVMSG %s :%s",
- user->GetFullHost().c_str(), c->name.c_str(), text.c_str());
- list->lines.push_back(HistoryItem(buf));
+ const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + text;
+ list->lines.push_back(HistoryItem(line));
if (list->lines.size() > list->maxlen)
list->lines.pop_front();
}
diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp
index 4bfce2108..0f53ceedf 100644
--- a/src/modules/m_chanlog.cpp
+++ b/src/modules/m_chanlog.cpp
@@ -73,16 +73,15 @@ class ModuleChanLog : public Module
if (itpair.first == itpair.second)
return MOD_RES_PASSTHRU;
- char buf[MAXBUF];
- snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
+ const std::string snotice = "\2" + desc + "\2: " + msg;
for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
{
Channel *c = ServerInstance->FindChan(it->second);
if (c)
{
- c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
- ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
+ c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), snotice.c_str());
+ ServerInstance->PI->SendChannelPrivmsg(c, 0, snotice);
}
}
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 691b61138..31b361b6f 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -295,9 +295,8 @@ class ModuleCloaking : public Module
/* Check if they have a cloaked host, but are not using it */
if (cloak && *cloak != user->dhost)
{
- char cmask[MAXBUF];
- snprintf(cmask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
- if (InspIRCd::Match(cmask,mask))
+ const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak;
+ if (InspIRCd::Match(cloakMask, mask))
return MOD_RES_DENY;
}
return MOD_RES_PASSTHRU;
diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp
index 1fc49190b..6b100605e 100644
--- a/src/modules/m_customtitle.cpp
+++ b/src/modules/m_customtitle.cpp
@@ -35,27 +35,10 @@ class CommandTitle : public Command
syntax = "<user> <password>";
}
- bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
- {
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
- }
-
CmdResult Handle(const std::vector<std::string> &parameters, User* user)
{
- char TheHost[MAXBUF];
- char TheIP[MAXBUF];
-
- snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
- snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString().c_str());
+ const std::string userHost = user->ident + "@" + user->host;
+ const std::string userIP = user->ident + "@" + user->GetIPString();
ConfigTagList tags = ServerInstance->Config->ConfTags("title");
for (ConfigIter i = tags.first; i != tags.second; ++i)
@@ -67,7 +50,8 @@ class CommandTitle : public Command
std::string title = i->second->getString("title");
std::string vhost = i->second->getString("vhost");
- if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+ if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
+ InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
{
ctitle.set(user, title);
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index 9e0b89fc3..a0ff5b84a 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -361,16 +361,12 @@ class ModuleDNSBL : public Module
ServerInstance->Logs->Log("m_dnsbl", LOG_DEBUG, "User has no connect class in OnSetUserIP");
unsigned char a, b, c, d;
- char reversedipbuf[128];
- std::string reversedip;
-
d = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 24) & 0xFF;
c = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 16) & 0xFF;
b = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 8) & 0xFF;
a = (unsigned char) user->client_sa.in4.sin_addr.s_addr & 0xFF;
- snprintf(reversedipbuf, 128, "%d.%d.%d.%d", d, c, b, a);
- reversedip = std::string(reversedipbuf);
+ const std::string reversedip = ConvToStr(d) + "." + ConvToStr(c) + "." + ConvToStr(b) + "." + ConvToStr(a);
countExt.set(user, DNSBLConfEntries.size());
diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp
index 9ff17924d..a367ecda3 100644
--- a/src/modules/m_messageflood.cpp
+++ b/src/modules/m_messageflood.cpp
@@ -160,10 +160,10 @@ class ModuleMsgFlood : public Module
ServerInstance->SendGlobalMode(parameters, ServerInstance->FakeClient);
}
- char kickmessage[MAXBUF];
- snprintf(kickmessage, MAXBUF, "Channel flood triggered (limit is %u lines in %u secs)", f->lines, f->secs);
+ const std::string kickMessage = "Channel flood triggered (limit is " + ConvToStr(f->lines) +
+ " in " + ConvToStr(f->secs) + " secs)";
- dest->KickUser(ServerInstance->FakeClient, user, kickmessage);
+ dest->KickUser(ServerInstance->FakeClient, user, kickMessage);
return MOD_RES_DENY;
}
diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp
index 4db1f70b9..7d0d3a040 100644
--- a/src/modules/m_namedmodes.cpp
+++ b/src/modules/m_namedmodes.cpp
@@ -35,9 +35,8 @@ static void DisplayList(User* user, Channel* channel)
if (mh->GetNumParams(true))
items << " " << channel->GetModeParameter(letter);
}
- char pfx[MAXBUF];
- snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
- user->SendText(std::string(pfx), items);
+ const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name;
+ user->SendText(line, items);
user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
}
diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp
index b5b020d9d..87ab7d46f 100644
--- a/src/modules/m_sqloper.cpp
+++ b/src/modules/m_sqloper.cpp
@@ -23,20 +23,6 @@
/* $ModDesc: Allows storage of oper credentials in an SQL table */
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
-}
-
class OpMeQuery : public SQLQuery
{
public:
@@ -106,7 +92,7 @@ class OpMeQuery : public SQLQuery
hostname.append("@").append(user->host);
- if (OneOfMatches(hostname.c_str(), user->GetIPString().c_str(), pattern.c_str()))
+ if (InspIRCd::MatchMask(pattern, hostname, user->GetIPString()))
{
/* Opertype and host match, looks like this is it. */
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index 7c8cc12f2..f0f4fc155 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -158,20 +158,6 @@ class ModuleSSLInfo : public Module
}
}
- bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
- {
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
- }
-
ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
{
if ((command == "OPER") && (validated))
diff --git a/src/server.cpp b/src/server.cpp
index 6790b45e7..c2068d75b 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -66,17 +66,11 @@ void RehashHandler::Call(const std::string &reason)
}
}
-std::string InspIRCd::GetVersionString(bool operstring)
+std::string InspIRCd::GetVersionString(bool getFullVersion)
{
- char versiondata[MAXBUF];
- if (operstring)
- {
- std::string sename = SE->GetName();
- snprintf(versiondata,MAXBUF,"%s %s :%s [%s,%s,%s]",VERSION, Config->ServerName.c_str(), SYSTEM,REVISION, sename.c_str(), Config->sid.c_str());
- }
- else
- snprintf(versiondata,MAXBUF,"%s %s :%s",BRANCH,Config->ServerName.c_str(),Config->CustomVersion.c_str());
- return versiondata;
+ if (getFullVersion)
+ return VERSION " " + Config->ServerName + " :" SYSTEM " [" REVISION "," + SE->GetName() + "," + Config->sid + "]";
+ return BRANCH " " + Config->ServerName + " :" + Config->CustomVersion;
}
const char InspIRCd::LogHeader[] =
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index fd3360c36..1080aa132 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -272,7 +272,7 @@ int PollEngine::DispatchEvents()
// whoops, deleted out from under us
continue;
}
-
+
if (events[index].revents & POLLOUT)
{
int mask = eh->GetEventMask();
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index ba1f5f9e6..8ed87a338 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -326,18 +326,17 @@ void UserManager::ServerNoticeAll(const char* text, ...)
return;
char textbuffer[MAXBUF];
- char formatbuffer[MAXBUF];
va_list argsPtr;
va_start (argsPtr, text);
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
+ const std::string message = "NOTICE $" + ServerInstance->Config->ServerName + " :" + textbuffer;
for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
- t->WriteServ(std::string(formatbuffer));
+ t->WriteServ(message);
}
}
@@ -347,18 +346,17 @@ void UserManager::ServerPrivmsgAll(const char* text, ...)
return;
char textbuffer[MAXBUF];
- char formatbuffer[MAXBUF];
va_list argsPtr;
va_start (argsPtr, text);
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
+ const std::string message = "PRIVMSG $" + ServerInstance->Config->ServerName + " :" + textbuffer;
for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
User* t = *i;
- t->WriteServ(std::string(formatbuffer));
+ t->WriteServ(message);
}
}
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index c78f0bb0b..40fd35c59 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -66,8 +66,7 @@ void InspIRCd::DoBackgroundUserStuff()
if (!curr->lastping)
{
time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
- char message[MAXBUF];
- snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
+ const std::string message = "Ping timeout: " + ConvToStr(time) + (time == 1 ? " seconds" : " second");
curr->lastping = 1;
curr->nping = Time() + curr->MyClass->GetPingTime();
this->Users->QuitUser(curr, message);
diff --git a/src/users.cpp b/src/users.cpp
index 7e95dc012..9f4060968 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1081,11 +1081,8 @@ void User::WriteNumeric(unsigned int numeric, const std::string &text)
void User::WriteFrom(User *user, const std::string &text)
{
- char tb[MAXBUF];
-
- snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
-
- this->Write(std::string(tb));
+ const std::string message = ":" + user->GetFullHost() + " " + text;
+ this->Write(message);
}
@@ -1199,18 +1196,13 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
{
- char tb1[MAXBUF];
- char tb2[MAXBUF];
-
if (this->registered != REG_ALL)
return;
already_sent_t uniq_id = ++LocalUser::already_sent_id;
- snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
- snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
- std::string out1 = tb1;
- std::string out2 = tb2;
+ const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
+ const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
UserChanList include_c(chans);
std::map<User*,bool> exceptions;
@@ -1224,7 +1216,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
{
u->already_sent = uniq_id;
if (i->second)
- u->Write(u->IsOper() ? out2 : out1);
+ u->Write(u->IsOper() ? operMessage : normalMessage);
}
}
for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
@@ -1236,7 +1228,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
if (u && !u->quitting && (u->already_sent != uniq_id))
{
u->already_sent = uniq_id;
- u->Write(u->IsOper() ? out2 : out1);
+ u->Write(u->IsOper() ? operMessage : normalMessage);
}
}
}
@@ -1341,8 +1333,6 @@ bool User::ChangeName(const char* gecos)
void User::DoHostCycle(const std::string &quitline)
{
- char buffer[MAXBUF];
-
if (!ServerInstance->Config->CycleHosts)
return;
@@ -1373,18 +1363,17 @@ void User::DoHostCycle(const std::string &quitline)
for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
{
Channel* c = *v;
- snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
- std::string joinline(buffer);
Membership* memb = c->GetUser(this);
- std::string modeline = memb->modes;
- if (modeline.length() > 0)
+ const std::string joinline = ":" + GetFullHost() + " JOIN " + c->name;
+ std::string modeline;
+
+ if (!memb->modes.empty())
{
- for(unsigned int i=0; i < memb->modes.length(); i++)
+ modeline = ":" + (ServerInstance->Config->CycleHostsFromUser ? GetFullHost() : ServerInstance->Config->ServerName)
+ + " MODE " + c->name + " +" + memb->modes;
+
+ for (size_t i = 0; i < memb->modes.length(); i++)
modeline.append(" ").append(nick);
- snprintf(buffer, MAXBUF, ":%s MODE %s +%s",
- ServerInstance->Config->CycleHostsFromUser ? GetFullHost().c_str() : ServerInstance->Config->ServerName.c_str(),
- c->name.c_str(), modeline.c_str());
- modeline = buffer;
}
const UserMembList *ulist = c->GetUsers();
@@ -1402,7 +1391,7 @@ void User::DoHostCycle(const std::string &quitline)
u->already_sent = seen_id;
}
u->Write(joinline);
- if (modeline.length() > 0)
+ if (!memb->modes.empty())
u->Write(modeline);
}
}
@@ -1459,20 +1448,18 @@ bool User::ChangeIdent(const char* newident)
void User::SendAll(const char* command, const char* text, ...)
{
char textbuffer[MAXBUF];
- char formatbuffer[MAXBUF];
va_list argsPtr;
va_start(argsPtr, text);
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
- std::string fmt = formatbuffer;
+ 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++)
{
if ((*i)->registered == REG_ALL)
- (*i)->Write(fmt);
+ (*i)->Write(message);
}
}
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index eb9151293..b64d2d6e8 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -78,7 +78,7 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
* Below here is all wrappers around match_internal
********************************************************************/
-CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
{
if (!map)
map = national_case_insensitive_map;
@@ -86,14 +86,14 @@ CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask,
return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
}
-CoreExport bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
{
if (!map)
map = national_case_insensitive_map;
return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
}
-CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
{
if (irc::sockets::MatchCIDR(str, mask, true))
return true;
@@ -105,7 +105,7 @@ CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &m
return InspIRCd::Match(str, mask, map);
}
-CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
{
if (irc::sockets::MatchCIDR(str, mask, true))
return true;
@@ -117,3 +117,17 @@ CoreExport bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned
return InspIRCd::Match(str, mask, map);
}
+bool InspIRCd::MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr)
+{
+ std::stringstream masklist(masks);
+ std::string mask;
+ while (masklist >> mask)
+ {
+ if (InspIRCd::Match(hostname, mask, ascii_case_insensitive_map) ||
+ InspIRCd::MatchCIDR(ipaddr, mask, ascii_case_insensitive_map))
+ {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/src/xline.cpp b/src/xline.cpp
index fd82ea2df..ff86997bb 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -531,15 +531,15 @@ bool XLine::IsBurstable()
void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
{
- char sreason[MAXBUF];
- snprintf(sreason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason.c_str());
+ const std::string banReason = line + "-Lined: " + reason;
+
if (!ServerInstance->Config->MoronBanner.empty())
u->WriteNotice("*** " + ServerInstance->Config->MoronBanner);
if (ServerInstance->Config->HideBans)
- ServerInstance->Users->QuitUser(u, line + "-Lined", sreason);
+ ServerInstance->Users->QuitUser(u, line + "-Lined", banReason.c_str());
else
- ServerInstance->Users->QuitUser(u, sreason);
+ ServerInstance->Users->QuitUser(u, banReason);
if (bancache)