summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.c90
-rw-r--r--src/botserv.c10
-rw-r--r--src/channels.c12
-rw-r--r--src/core/cs_forbid.c4
-rw-r--r--src/core/db_plain.cpp10
-rw-r--r--src/core/os_staff.c2
-rw-r--r--src/protocol/bahamut.c11
-rw-r--r--src/protocol/inspircd11.c9
-rw-r--r--src/protocol/inspircd12.cpp6
-rw-r--r--src/protocol/ratbox.c6
-rw-r--r--src/protocol/unreal32.c13
-rw-r--r--src/users.c32
12 files changed, 103 insertions, 102 deletions
diff --git a/src/actions.c b/src/actions.c
index 76ddb435b..6ed840653 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -22,22 +22,19 @@
* @param u the User to check
* @return void
*/
-void bad_password(User * u)
+void bad_password(User *u)
{
time_t now = time(NULL);
- if (!u || !Config.BadPassLimit) {
+ if (!u || !Config.BadPassLimit)
return;
- }
- if (Config.BadPassTimeout > 0 && u->invalid_pw_time > 0
- && u->invalid_pw_time < now - Config.BadPassTimeout)
+ if (Config.BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < now - Config.BadPassTimeout)
u->invalid_pw_count = 0;
- u->invalid_pw_count++;
+ ++u->invalid_pw_count;
u->invalid_pw_time = now;
- if (u->invalid_pw_count >= Config.BadPassLimit) {
- kill_user(NULL, u->nick, "Too many invalid passwords");
- }
+ if (u->invalid_pw_count >= Config.BadPassLimit)
+ kill_user("", u->nick, "Too many invalid passwords");
}
/*************************************************************************/
@@ -49,27 +46,21 @@ void bad_password(User * u)
* @param reason for the kill
* @return void
*/
-void kill_user(const char *source, const char *user, const char *reason)
+void kill_user(const std::string &source, const std::string &user, const std::string &reason)
{
char buf[BUFSIZE];
- if (!user || !*user) {
+ if (user.empty())
return;
- }
- if (!source || !*source) {
- source = Config.ServerName;
- }
- if (!reason) {
- reason = "";
- }
- snprintf(buf, sizeof(buf), "%s (%s)", source, reason);
+ std::string real_source = source.empty() ? Config.ServerName : source;
+
+ snprintf(buf, sizeof(buf), "%s (%s)", source.c_str(), reason.c_str());
ircdproto->SendSVSKill(findbot(source), finduser(user), buf);
- if (!ircd->quitonkill && finduser(user)) {
+ if (!ircd->quitonkill && finduser(user))
do_kill(user, buf);
- }
}
/*************************************************************************/
@@ -80,43 +71,46 @@ void kill_user(const char *source, const char *user, const char *reason)
* @param reason for the sqline
* @return void
*/
-void sqline(char *mask, char *reason)
+void sqline(const std::string &mask, const std::string &reason)
{
int i;
Channel *c, *next;
const char *av[3];
struct c_userlist *cu, *cunext;
- if (ircd->chansqline) {
- if (*mask == '#') {
+ if (ircd->chansqline)
+ {
+ if (mask[0] == '#')
+ {
ircdproto->SendSQLine(mask, reason);
- for (i = 0; i < 1024; i++) {
- for (c = chanlist[i]; c; c = next) {
+ for (i = 0; i < 1024; ++i)
+ {
+ for (c = chanlist[i]; c; c = next)
+ {
next = c->next;
- if (!Anope::Match(c->name, mask, false)) {
+ if (!Anope::Match(c->name, mask, false))
continue;
- }
- for (cu = c->users; cu; cu = cunext) {
+ for (cu = c->users; cu; cu = cunext)
+ {
cunext = cu->next;
- if (is_oper(cu->user)) {
+ if (is_oper(cu->user))
continue;
- }
av[0] = c->name;
av[1] = cu->user->nick;
- av[2] = reason;
+ av[2] = reason.c_str();
ircdproto->SendKick(findbot(Config.s_OperServ), c, cu->user, "Q-Lined: %s", av[2]);
do_kick(Config.s_ChanServ, 3, av);
}
}
}
- } else {
- ircdproto->SendSQLine(mask, reason);
}
- } else {
- ircdproto->SendSQLine(mask, reason);
+ else
+ ircdproto->SendSQLine(mask, reason);
}
+ else
+ ircdproto->SendSQLine(mask, reason);
}
/*************************************************************************/
@@ -127,34 +121,32 @@ void sqline(char *mask, char *reason)
* @param nick to remove the ban for
* @return void
*/
-void common_unban(ChannelInfo * ci, char *nick)
+void common_unban(ChannelInfo *ci, const std::string &nick)
{
char *host = NULL;
uint32 ip = 0;
User *u;
Entry *ban, *next;
- if (!ci || !ci->c || !nick) {
+ if (!ci || !ci->c || nick.empty())
return;
- }
- if (!(u = finduser(nick))) {
+ if (!(u = finduser(nick)))
return;
- }
- if (!ci->c->bans || (ci->c->bans->count == 0))
+ if (!ci->c->bans || !ci->c->bans->count)
return;
- if (u->hostip == NULL) {
+ if (u->hostip == NULL)
+ {
host = host_resolve(u->host);
/* we store the just resolved hostname so we don't
* need to do this again */
- if (host) {
+ if (host)
u->hostip = sstrdup(host);
- }
- } else {
- host = sstrdup(u->hostip);
}
+ else
+ host = sstrdup(u->hostip);
/* Convert the host to an IP.. */
if (host)
ip = str_is_ip(host);
@@ -166,8 +158,7 @@ void common_unban(ChannelInfo * ci, char *nick)
for (ban = ci->c->bans->entries; ban; ban = next)
{
next = ban->next;
- if (entry_match(ban, u->nick, u->GetIdent().c_str(), u->host, ip) ||
- entry_match(ban, u->nick, u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip))
+ if (entry_match(ban, u->nick, u->GetIdent().c_str(), u->host, ip) || entry_match(ban, u->nick, u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip))
ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask);
}
}
@@ -177,4 +168,3 @@ void common_unban(ChannelInfo * ci, char *nick)
}
/*************************************************************************/
-
diff --git a/src/botserv.c b/src/botserv.c
index 9dc7e3ed1..bbe3f30c9 100644
--- a/src/botserv.c
+++ b/src/botserv.c
@@ -483,13 +483,15 @@ void insert_bot(BotInfo * bi)
/*************************************************************************/
/*************************************************************************/
-BotInfo *findbot(const char *nick)
+BotInfo *findbot(const std::string &nick)
{
BotInfo *bi;
- if (!nick || !*nick)
+ if (nick.empty())
return NULL;
+ ci::string ci_nick(nick.c_str());
+
/*
* XXX Less than efficient, but we need to do this for good TS6 support currently. This *will* improve. -- w00t
*/
@@ -497,10 +499,10 @@ BotInfo *findbot(const char *nick)
{
for (bi = botlists[i]; bi; bi = bi->next)
{
- if (!stricmp(nick, bi->nick))
+ if (ci_nick == bi->nick)
return bi;
- if (nick == bi->uid)
+ if (ci_nick == bi->uid)
return bi;
}
}
diff --git a/src/channels.c b/src/channels.c
index aa01b99e0..79f956581 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -153,10 +153,10 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, bool En
}
/* We don't track bots */
- if (findbot(param.c_str()))
+ if (findbot(param))
return;
- User *u = finduser(param.c_str());
+ User *u = finduser(param);
if (!u)
{
if (debug)
@@ -285,10 +285,10 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
}
/* We don't track bots */
- if (findbot(param.c_str()))
+ if (findbot(param))
return;
- User *u = finduser(param.c_str());
+ User *u = finduser(param);
if (!u)
{
alog("Channel::RemoveModeInternal() MODE %s +%c for nonexistant user %s", this->name, cm->ModeChar, param.c_str());
@@ -354,7 +354,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
/* Non registered channel, no mlock */
if (!ci || !EnforceMLock || MOD_RESULT == EVENT_STOP)
return;
-
+
/* This channel has this the mode locked on */
if (ci->HasMLock(cm->Name, true))
{
@@ -656,7 +656,7 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av)
{
if (!ac)
return;
-
+
int k = 0, j = 0, add = -1;
for (unsigned int i = 0; i < strlen(av[0]); ++i)
{
diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c
index 9c1690fe2..ae298d8d3 100644
--- a/src/core/cs_forbid.c
+++ b/src/core/cs_forbid.c
@@ -70,7 +70,7 @@ class CommandCSForbid : public Command
struct c_userlist *cu, *nextu;
const char *av[3];
- /* Before banning everyone, it might be prudent to clear +e and +I lists..
+ /* Before banning everyone, it might be prudent to clear +e and +I lists..
* to prevent ppl from rejoining.. ~ Viper */
c->ClearExcepts();
c->ClearInvites();
@@ -95,7 +95,7 @@ class CommandCSForbid : public Command
if (ircd->chansqline)
{
- ircdproto->SendSQLine(ci->name, ((reason) ? reason : "Forbidden"));
+ ircdproto->SendSQLine(ci->name, reason ? reason : "Forbidden");
}
alog("%s: %s set FORBID for channel %s", Config.s_ChanServ, u->nick, ci->name);
diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp
index b551d0b5c..4648378a8 100644
--- a/src/core/db_plain.cpp
+++ b/src/core/db_plain.cpp
@@ -78,7 +78,7 @@ static void ReadDatabase(Module *m = NULL)
}
if (MOD_RESULT == EVENT_STOP)
continue;
-
+
std::string mdbuf;
NickCore *nc;
NickAlias *na;
@@ -98,7 +98,7 @@ static void ReadDatabase(Module *m = NULL)
}
else if (params[0] == "BI")
{
- bi = findbot(params[1].c_str());
+ bi = findbot(params[1]);
Type = MD_BI;
}
else if (params[0] == "CH")
@@ -731,7 +731,7 @@ class DBPlain : public Module
ak->SetFlag(AK_STUCK);
if (Nick)
ak->SetFlag(AK_ISNICK);
-
+
}
else if (key == "MLOCK_ON" || buf == "MLOCK_OFF")
{
@@ -773,7 +773,7 @@ class DBPlain : public Module
else if (key == "BI")
{
if (params[0] == "NAME")
- ci->bi = findbot(params[1].c_str());
+ ci->bi = findbot(params[1]);
else if (params[0] == "FLAGS")
{
for (unsigned j = 1; j < params.size(); ++j)
@@ -1082,7 +1082,7 @@ class DBPlain : public Module
FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, ci));
}
}
-
+
HostCore *hc;
for (hc = hostCoreListHead(); hc; hc = hc->next)
{
diff --git a/src/core/os_staff.c b/src/core/os_staff.c
index 4a06fe098..161022490 100644
--- a/src/core/os_staff.c
+++ b/src/core/os_staff.c
@@ -41,7 +41,7 @@ class CommandOSStaff : public Command
found = 0;
std::string nick = it->first, type = it->second;
- if ((au = finduser(nick.c_str())))
+ if ((au = finduser(nick)))
{
found = 1;
notice_lang(Config.s_OperServ, u, OPER_STAFF_FORMAT, '*', type.c_str(), nick.c_str());
diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c
index aee8b6f22..f00982d6b 100644
--- a/src/protocol/bahamut.c
+++ b/src/protocol/bahamut.c
@@ -167,9 +167,9 @@ class BahamutIRCdProto : public IRCDProto
}
/* SVSMODE -b */
- void SendBanDel(Channel *c, const char *nick)
+ void SendBanDel(Channel *c, const std::string &nick)
{
- SendSVSModeChan(c, "-b", nick);
+ SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str());
}
/* SVSMODE channel modes */
@@ -180,10 +180,11 @@ class BahamutIRCdProto : public IRCDProto
}
/* SQLINE */
- void SendSQLine(const char *mask, const char *reason)
+ void SendSQLine(const std::string &mask, const std::string &reason)
{
- if (!mask || !reason) return;
- send_cmd(NULL, "SQLINE %s :%s", mask, reason);
+ if (mask.empty() || reason.empty())
+ return;
+ send_cmd(NULL, "SQLINE %s :%s", mask.c_str(), reason.c_str());
}
/* UNSGLINE */
diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c
index cdeb58797..eb2718a7a 100644
--- a/src/protocol/inspircd11.c
+++ b/src/protocol/inspircd11.c
@@ -135,7 +135,7 @@ void inspircd_cmd_chghost(const char *nick, const char *vhost)
return;
send_cmd(Config.s_OperServ, "CHGHOST %s %s", nick, vhost);
}
- else
+ else
ircdproto->SendGlobops(findbot(Config.s_OperServ), "CHGHOST not loaded!");
}
@@ -260,10 +260,11 @@ class InspIRCdProto : public IRCDProto
}
/* SQLINE */
- void SendSQLine(const char *mask, const char *reason)
+ void SendSQLine(const std::string &mask, const std::string &reason)
{
- if (!mask || !reason) return;
- send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", mask, Config.s_OperServ, static_cast<long>(time(NULL)), reason);
+ if (mask.empty() || reason.empty())
+ return;
+ send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), reason.c_str());
}
/* SQUIT */
diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp
index 7c67d0524..0af116070 100644
--- a/src/protocol/inspircd12.cpp
+++ b/src/protocol/inspircd12.cpp
@@ -265,9 +265,11 @@ class InspIRCdProto : public IRCDProto
}
/* SQLINE */
- void SendSQLine(const char *mask, const char *reason)
+ void SendSQLine(const std::string &mask, const std::string &reason)
{
- send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", mask, Config.s_OperServ, static_cast<long>(time(NULL)), reason);
+ if (mask.empty() || reason.empty())
+ return;
+ send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), reason.c_str());
}
/* SQUIT */
diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c
index 3b9f982aa..78be63723 100644
--- a/src/protocol/ratbox.c
+++ b/src/protocol/ratbox.c
@@ -173,9 +173,11 @@ class RatboxProto : public IRCDTS6Proto
send_cmd(TS6SID, "OPERWALL :%s", buf);
}
- void SendSQLine(const char *mask, const char *reason)
+ void SendSQLine(const std::string &mask, const std::string &reason)
{
- send_cmd(TS6SID, "RESV * %s :%s", mask, reason);
+ if (mask.empty() || reason.empty())
+ return;
+ send_cmd(TS6SID, "RESV * %s :%s", mask.c_str(), reason.c_str());
}
void SendSGLineDel(SXLine *sx)
diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c
index 085107e5c..7e8d0985b 100644
--- a/src/protocol/unreal32.c
+++ b/src/protocol/unreal32.c
@@ -290,10 +290,11 @@ class UnrealIRCdProto : public IRCDProto
** - Unreal will translate this to TKL for us
**
*/
- void SendSQLine(const char *mask, const char *reason)
+ void SendSQLine(const std::string &mask, const std::string &reason)
{
- if (!mask || !reason) return;
- send_cmd(NULL, "c %s :%s", mask, reason);
+ if (mask.empty() || reason.empty())
+ return;
+ send_cmd(NULL, "c %s :%s", mask.c_str(), reason.c_str());
}
/*
@@ -381,9 +382,9 @@ class UnrealIRCdProto : public IRCDProto
}
/* SVSMODE -b */
- void SendBanDel(Channel *c, const char *nick)
+ void SendBanDel(Channel *c, const std::string &nick)
{
- SendSVSModeChan(c, "-b", nick);
+ SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str());
}
@@ -958,7 +959,7 @@ int anope_event_userhost(const char *source, int ac, const char **av)
std::string host = std::string(std::find(reply.begin(), reply.end(), '@'), reply.end());
host.erase(host.begin());
- User *u = finduser(user.c_str());
+ User *u = finduser(user);
if (u)
{
u->SetCloakedHost(host);
diff --git a/src/users.c b/src/users.c
index 02112c7cf..7e715d547 100644
--- a/src/users.c
+++ b/src/users.c
@@ -441,18 +441,20 @@ void get_user_stats(long *nusers, long *memuse)
/* Find a user by nick. Return NULL if user could not be found. */
-User *finduser(const char *nick)
+User *finduser(const std::string &nick)
{
User *user;
if (debug >= 3)
- alog("debug: finduser(%p)", nick);
+ alog("debug: finduser(%p)", nick.c_str());
- if (isdigit(*nick) && ircd->ts6)
+ if (isdigit(nick[0]) && ircd->ts6)
return find_byuid(nick);
+ ci::string ci_nick(nick.c_str());
+
user = userlist[HASH(nick)];
- while (user && stricmp(user->nick, nick) != 0)
+ while (user && ci_nick != user->nick)
user = user->next;
if (debug >= 3)
alog("debug: finduser(%s) -> 0x%p", nick, static_cast<void *>(user));
@@ -477,7 +479,7 @@ void User::SetModeInternal(UserMode *um, const std::string &Param)
{
if (!um)
return;
-
+
modes[um->Name] = true;
if (!Param.empty())
{
@@ -494,7 +496,7 @@ void User::RemoveModeInternal(UserMode *um)
{
if (!um)
return;
-
+
modes[um->Name] = false;
std::map<UserModeName, std::string>::iterator it = Params.find(um->Name);
if (it != Params.end())
@@ -601,11 +603,11 @@ void User::SetModes(BotInfo *bi, const std::string &modes, ...)
default:
if (add == -1)
continue;
- um = ModeManager::FindUserModeByChar(modebuf[i]);
+ um = ModeManager::FindUserModeByChar(modebuf[i]);
if (!um)
continue;
}
-
+
if (add)
{
if (um->Type == MODE_PARAM && sep.GetToken(sbuf))
@@ -654,7 +656,7 @@ User *nextuser()
return current;
}
-User *find_byuid(const char *uid)
+User *find_byuid(const std::string &uid)
{
User *u, *next;
@@ -1001,7 +1003,7 @@ void do_quit(const char *source, int ac, const char **av)
* av[1] = reason
*/
-void do_kill(const char *nick, const char *msg)
+void do_kill(const std::string &nick, const std::string &msg)
{
User *user;
NickAlias *na;
@@ -1009,18 +1011,18 @@ void do_kill(const char *nick, const char *msg)
user = finduser(nick);
if (!user) {
if (debug) {
- alog("debug: KILL of nonexistent nick: %s", nick);
+ alog("debug: KILL of nonexistent nick: %s", nick.c_str());
}
return;
}
if (debug) {
- alog("debug: %s killed", nick);
+ alog("debug: %s killed", nick.c_str());
}
if ((na = findnick(user->nick)) && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || nick_identified(user))) {
na->last_seen = time(NULL);
if (na->last_quit)
delete [] na->last_quit;
- na->last_quit = *msg ? sstrdup(msg) : NULL;
+ na->last_quit = !msg.empty() ? sstrdup(msg.c_str()) : NULL;
}
if (Config.LimitSessions && !is_ulined(user->server->name)) {
@@ -1198,10 +1200,10 @@ void UserSetInternalModes(User *user, int ac, const char **av)
const char *modes = av[0];
if (!user || !modes)
return;
-
+
if (debug)
alog("debug: Changing user modes for %s to %s", user->nick, merge_args(ac, av));
-
+
for (; *modes; *modes++)
{
UserMode *um;