From ae38212c1ce829c783edf971081c90137abb49a0 Mon Sep 17 00:00:00 2001 From: Naram Qashat Date: Sun, 25 Jul 2010 21:58:20 -0400 Subject: Epic commit to replace most of the strings in Anope with a single Anope::string class, plus some other little fixes here and there. If you follow 1.9.x development and are testing things, THIS is one of those things that NEEDS testing. --- src/actions.cpp | 29 +- src/base64.cpp | 334 ++--------- src/bots.cpp | 53 +- src/botserv.cpp | 205 +++---- src/channels.cpp | 414 ++++++-------- src/chanserv.cpp | 212 +++---- src/command.cpp | 14 +- src/commands.cpp | 39 +- src/compat.cpp | 58 -- src/config.cpp | 861 ++++++++++++++--------------- src/configreader.cpp | 30 +- src/encrypt.cpp | 19 +- src/hashcomp.cpp | 93 ++-- src/hostserv.cpp | 36 +- src/init.cpp | 73 ++- src/ircd.cpp | 19 +- src/language.cpp | 8 +- src/log.cpp | 50 +- src/mail.cpp | 50 +- src/main.cpp | 74 ++- src/memory.cpp | 46 -- src/memoserv.cpp | 71 ++- src/messages.cpp | 99 ++-- src/misc.cpp | 497 +++++------------ src/modes.cpp | 96 ++-- src/module.cpp | 20 +- src/modulemanager.cpp | 65 +-- src/modules.cpp | 50 +- src/nickalias.cpp | 35 +- src/nickcore.cpp | 30 +- src/nickserv.cpp | 164 ++---- src/operserv.cpp | 163 +++--- src/opertype.cpp | 16 +- src/process.cpp | 79 ++- src/protocol.cpp | 111 ++-- src/regchannel.cpp | 84 ++- src/send.cpp | 75 +-- src/servers.cpp | 62 +-- src/sessions.cpp | 139 +++-- src/sockets.cpp | 113 ++-- src/threadengines/threadengine_pthread.cpp | 2 +- src/threadengines/threadengine_win32.cpp | 2 +- src/timers.cpp | 4 +- src/tools/db-convert.h | 2 - src/users.cpp | 324 +++++------ src/wildcard.cpp | 12 +- src/win32/windows.cpp | 2 +- 47 files changed, 1950 insertions(+), 3084 deletions(-) delete mode 100644 src/compat.cpp (limited to 'src') diff --git a/src/actions.cpp b/src/actions.cpp index bff5b36fa..17c0a2898 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -48,18 +48,16 @@ bool bad_password(User *u) * @param reason for the kill * @return void */ -void kill_user(const std::string &source, const std::string &user, const std::string &reason) +void kill_user(const Anope::string &source, const Anope::string &user, const Anope::string &reason) { - char buf[BUFSIZE]; - if (user.empty()) return; - std::string real_source = source.empty() ? Config.ServerName : source; + Anope::string real_source = source.empty() ? Config.ServerName : source; - snprintf(buf, sizeof(buf), "%s (%s)", source.c_str(), reason.c_str()); + Anope::string buf = real_source + " (" + reason + ")"; - ircdproto->SendSVSKill(findbot(source), finduser(user), buf); + ircdproto->SendSVSKill(findbot(source), finduser(user), "%s", buf.c_str()); if (!ircd->quitonkill && finduser(user)) do_kill(user, buf); @@ -73,9 +71,9 @@ void kill_user(const std::string &source, const std::string &user, const std::st * @param nick to remove the ban for * @return void */ -void common_unban(ChannelInfo *ci, const std::string &nick) +void common_unban(ChannelInfo *ci, const Anope::string &nick) { - char *host = NULL; + Anope::string host; uint32 ip = 0; User *u; Entry *ban, *next; @@ -89,18 +87,18 @@ void common_unban(ChannelInfo *ci, const std::string &nick) if (!ci->c->bans || !ci->c->bans->count) return; - if (!u->hostip) + if (u->hostip.empty()) { host = host_resolve(u->host); /* we store the just resolved hostname so we don't * need to do this again */ - if (host) - u->hostip = sstrdup(host); + if (!host.empty()) + u->hostip = host; } else - host = sstrdup(u->hostip); + host = u->hostip; /* Convert the host to an IP.. */ - if (host) + if (!host.empty()) ip = str_is_ip(host); if (ircd->svsmode_unban) @@ -109,12 +107,9 @@ void common_unban(ChannelInfo *ci, const std::string &nick) for (ban = ci->c->bans->entries; ban; ban = next) { next = ban->next; - if (entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->host, ip) || entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip)) + if (entry_match(ban, u->nick, u->GetIdent(), u->host, ip) || entry_match(ban, u->nick, u->GetIdent(), u->GetDisplayedHost(), ip)) ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask); } - /* host_resolve() sstrdup us this info so we gotta free it */ - if (host) - delete [] host; } /*************************************************************************/ diff --git a/src/base64.cpp b/src/base64.cpp index 2071ad40a..4f51eb5e8 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -9,31 +9,9 @@ * Based on the original code of Services by Andy Church. */ -/* - This is borrowed from Unreal -*/ - #include "services.h" -static char *int_to_base64(long); -static long base64_to_int(const char *); - -const char *base64enc(long i) -{ - if (i < 0) - return "0"; - return int_to_base64(i); -} - -long base64dec(const char *b64) -{ - if (b64) - return base64_to_int(b64); - else - return 0; -} - -static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const Anope::string Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) @@ -99,223 +77,97 @@ static const char Pad64 = '='; characters followed by one "=" padding character. */ -int b64_encode(const char *src, size_t srclength, char *target, size_t targsize) +void b64_encode(const Anope::string &src, Anope::string &target) { - size_t datalength = 0; + size_t src_pos = 0, src_len = src.length(); unsigned char input[3]; - unsigned char output[4]; - size_t i; - - while (srclength > 2) - { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; + target.clear(); - if (datalength + 4 > targsize) - return -1; - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; + while (src_len - src_pos > 2) + { + input[0] = src[src_pos++]; + input[1] = src[src_pos++]; + input[2] = src[src_pos++]; + + target += Base64[input[0] >> 2]; + target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)]; + target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)]; + target += Base64[input[2] & 0x3f]; } - /* Now we worry about padding. */ - if (srclength) + /* Now we worry about padding */ + if (src_pos != src_len) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; ++i) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return -1; - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; + input[0] = input[1] = input[2] = 0; + for (size_t i = 0; i < src_len - src_pos; ++i) + input[i] = src[src_pos + i]; + + target += Base64[input[0] >> 2]; + target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)]; + if (src_pos == src_len - 1) + target += Pad64; else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; + target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)]; + target += Pad64; } - if (datalength >= targsize) - return -1; - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return datalength; } /* skips all whitespace anywhere. converts characters, four at a time, starting at (or after) src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. */ -int b64_decode(const char *src, char *target, size_t targsize) +void b64_decode(const Anope::string &src, Anope::string &target) { - int tarindex, state, ch; - char *pos; + target.clear(); - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') + unsigned state = 0; + Anope::string::const_iterator ch = src.begin(), end = src.end(); + for (; ch != end; ++ch) { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace(*ch)) /* Skip whitespace anywhere */ continue; - if (ch == Pad64) + if (*ch == Pad64) break; - pos = const_cast(strchr(Base64, ch)); - if (!pos) /* A non-base64 character. */ - return -1; + size_t pos = Base64.find(*ch); + if (pos == Anope::string::npos) /* A non-base64 character */ + return; switch (state) { case 0: - if (target) - { - if (static_cast(tarindex) >= targsize) - return -1; - target[tarindex] = (pos - Base64) << 2; - } + target += pos << 2; state = 1; break; case 1: - if (target) - { - if (static_cast(tarindex) + 1 >= targsize) - return -1; - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4; - } - ++tarindex; + target[target.length() - 1] |= pos >> 4; + target += (pos & 0x0f) << 4; state = 2; break; case 2: - if (target) - { - if (static_cast(tarindex) + 1 >= targsize) - return -1; - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex + 1] = ((pos - Base64) & 0x03) << 6; - } - ++tarindex; + target[target.length() - 1] |= pos >> 2; + target += (pos & 0x03) << 6; state = 3; break; case 3: - if (target) - { - if (static_cast(tarindex) >= targsize) - return -1; - target[tarindex] |= (pos - Base64); - } - ++tarindex; + target[target.length() - 1] |= pos; state = 0; - break; - default: - abort(); } } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) /* We got a pad char. */ - { - ch = *src++; /* Skip it, get next. */ - switch (state) - { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return -1; - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return -1; - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return -1; - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex]) - return -1; - } - } - else - { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state) - return -1; - } - - return tarindex; + if (!target[target.length() - 1]) + target.erase(target.length() - 1); } -const char *encode_ip(unsigned char *ip) +int decode_ip(const Anope::string &buf) { - static char buf[25]; - unsigned char *cp; - struct in_addr ia; /* For IPv4 */ - char *s_ip; /* Signed ip string */ - - if (!ip) - return "*"; + int len = buf.length(); + Anope::string targ; - if (strchr(reinterpret_cast(ip), ':')) - return NULL; - else - { - s_ip = str_signed(ip); - ia.s_addr = inet_addr(s_ip); - cp = reinterpret_cast(ia.s_addr); - b64_encode(reinterpret_cast(&cp), sizeof(struct in_addr), buf, 25); - } - return buf; -} - -int decode_ip(const char *buf) -{ - int len = strlen(buf); - char targ[25]; - struct in_addr ia; - - b64_decode(buf, targ, 25); - ia = *reinterpret_cast(targ); + b64_decode(buf, targ); + const struct in_addr ia = *reinterpret_cast(targ.c_str()); if (len == 24) /* IPv6 */ return 0; else if (len == 8) /* IPv4 */ @@ -323,91 +175,3 @@ int decode_ip(const char *buf) else /* Error?? */ return 0; } - -/* ':' and '#' and '&' and '+' and '@' must never be in this table. */ -/* these tables must NEVER CHANGE! >) */ -char int6_to_base64_map[] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', - 'E', 'F', - 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '{', '}' -}; - -char base64_to_int6_map[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, - -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, 63, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; - -static char *int_to_base64(long val) -{ - /* 32/6 == max 6 bytes for representation, - * +1 for the null, +1 for byte boundaries - */ - static char base64buf[8]; - long i = 7; - - base64buf[i] = '\0'; - - /* Temporary debugging code.. remove before 2038 ;p. - * This might happen in case of 64bit longs (opteron/ia64), - * if the value is then too large it can easily lead to - * a buffer underflow and thus to a crash. -- Syzop - */ - if (val > 2147483647L) - abort(); - - do - { - base64buf[--i] = int6_to_base64_map[val & 63]; - } while (val >>= 6); - - return base64buf + i; -} - -static long base64_to_int(const char *b64) -{ - int v = base64_to_int6_map[static_cast(*b64++)]; - - if (!b64) - return 0; - - while (*b64) - { - v <<= 6; - v += base64_to_int6_map[static_cast(*b64++)]; - } - - return v; -} - -long base64dects(const char *ts) -{ - if (!ts) - return 0; - - char *token = myStrGetToken(ts, '!', 1); - if (!token) - return strtoul(ts, NULL, 10); - - long value = base64dec(token); - delete [] token; - return value; -} diff --git a/src/bots.cpp b/src/bots.cpp index 4114d4317..88b981dcc 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -20,32 +20,31 @@ BotInfo *MemoServ = NULL; BotInfo *NickServ = NULL; BotInfo *OperServ = NULL; -BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal) : User(nnick, ts6_uid_retrieve()) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal) : User(nnick, ts6_uid_retrieve()) { this->ident = nuser; - this->host = sstrdup(nhost.c_str()); - this->realname = sstrdup(nreal.c_str()); + this->host = nhost; + this->realname = nreal; this->server = Me; this->lastmsg = this->created = time(NULL); - ci::string ci_nick(nnick.c_str()); - if (Config.s_ChanServ && ci_nick == Config.s_ChanServ) + if (!Config.s_ChanServ.empty() && nnick.equals_ci(Config.s_ChanServ)) ChanServ = this; - else if (Config.s_BotServ && ci_nick == Config.s_BotServ) + else if (!Config.s_BotServ.empty() && nnick.equals_ci(Config.s_BotServ)) BotServ = this; - else if (Config.s_HostServ && ci_nick == Config.s_HostServ) + else if (!Config.s_HostServ.empty() && nnick.equals_ci(Config.s_HostServ)) HostServ = this; - else if (Config.s_OperServ && ci_nick == Config.s_OperServ) + else if (!Config.s_OperServ.empty() && nnick.equals_ci(Config.s_OperServ)) OperServ = this; - else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ) + else if (!Config.s_MemoServ.empty() && nnick.equals_ci(Config.s_MemoServ)) MemoServ = this; - else if (Config.s_NickServ && ci_nick == Config.s_NickServ) + else if (!Config.s_NickServ.empty() && nnick.equals_ci(Config.s_NickServ)) NickServ = this; - else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer) + else if (!Config.s_GlobalNoticer.empty() && nnick.equals_ci(Config.s_GlobalNoticer)) Global = this; - BotListByNick[this->nick.c_str()] = this; + BotListByNick[this->nick] = this; if (!this->uid.empty()) BotListByUID[this->uid] = this; @@ -53,7 +52,7 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: if (Me && Me->GetUplink() && Me->GetUplink()->IsSynced()) { ircdproto->SendClientIntroduction(this->nick, this->GetIdent(), this->host, this->realname, ircd->pseudoclient_mode, this->uid); - XLine x(this->nick.c_str(), "Reserved for services"); + XLine x(this->nick, "Reserved for services"); ircdproto->SendSQLine(&x); } } @@ -68,21 +67,21 @@ BotInfo::~BotInfo() ci->bi = NULL; } - BotListByNick.erase(this->nick.c_str()); + BotListByNick.erase(this->nick); if (!this->uid.empty()) BotListByUID.erase(this->uid); } -void BotInfo::SetNewNick(const std::string &newnick) +void BotInfo::SetNewNick(const Anope::string &newnick) { - UserListByNick.erase(this->nick.c_str()); - BotListByNick.erase(this->nick.c_str()); + UserListByNick.erase(this->nick); + BotListByNick.erase(this->nick); this->nick = newnick; - UserListByNick[this->nick.c_str()] = this; - BotListByNick[this->nick.c_str()] = this; + UserListByNick[this->nick] = this; + BotListByNick[this->nick] = this; } void BotInfo::RejoinAll() @@ -142,14 +141,14 @@ void BotInfo::Join(Channel *c) { next = ban->next; - if (entry_match(ban, this->nick.c_str(), this->GetIdent().c_str(), this->host, 0)) + if (entry_match(ban, this->nick, this->GetIdent(), this->host, 0)) c->RemoveMode(NULL, CMODE_BAN, ban->mask); } - std::string Limit; + Anope::string Limit; int limit = 0; - if (c->GetParam(CMODE_LIMIT, Limit)) - limit = atoi(Limit.c_str()); + if (c->GetParam(CMODE_LIMIT, Limit) && Limit.is_number_only()) + limit = convertTo(Limit); /* Should we be invited? */ if (c->HasMode(CMODE_INVITE) || (limit && c->users.size() >= limit)) @@ -157,21 +156,21 @@ void BotInfo::Join(Channel *c) } } - ircdproto->SendJoin(this, c->name.c_str(), c->creation_time); + ircdproto->SendJoin(this, c->name, c->creation_time); for (std::list::iterator it = BotModes.begin(), it_end = BotModes.end(); it != it_end; ++it) c->SetMode(this, *it, this->nick, false); c->JoinUser(this); FOREACH_MOD(I_OnBotJoin, OnBotJoin(c->ci, this)); } -void BotInfo::Join(const std::string &chname) +void BotInfo::Join(const Anope::string &chname) { Channel *c = findchan(chname); return this->Join(c ? c : new Channel(chname)); } -void BotInfo::Part(Channel *c, const std::string &reason) +void BotInfo::Part(Channel *c, const Anope::string &reason) { - ircdproto->SendPart(this, c, !reason.empty() ? reason.c_str() : ""); + ircdproto->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); c->DeleteUser(this); } diff --git a/src/botserv.cpp b/src/botserv.cpp index 85f559f24..ae62e7e69 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -42,12 +42,12 @@ void get_botserv_stats(long *nrec, long *memuse) { BotInfo *bi = it->second; - count++; + ++count; mem += sizeof(*bi); - mem += bi->nick.size() + 1; - mem += bi->GetIdent().size() + 1; - mem += strlen(bi->host) + 1; - mem += strlen(bi->realname) + 1; + mem += bi->nick.length() + 1; + mem += bi->GetIdent().length() + 1; + mem += bi->host.length() + 1; + mem += bi->realname.length() + 1; } *nrec = count; @@ -61,7 +61,7 @@ void get_botserv_stats(long *nrec, long *memuse) void bs_init() { - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) moduleAddBotServCmds(); } @@ -69,17 +69,17 @@ void bs_init() /* Main BotServ routine. */ -void botserv(User *u, BotInfo *bi, const std::string &buf) +void botserv(User *u, BotInfo *bi, const Anope::string &buf) { if (!u || !bi || buf.empty()) return; - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string command = buf; + Anope::string command = buf; command.erase(command.begin()); command.erase(command.end()); - ircdproto->SendCTCP(bi, u->nick.c_str(), "%s", command.c_str()); + ircdproto->SendCTCP(bi, u->nick, "%s", command.c_str()); } else mod_run_cmd(bi, u, buf); @@ -91,27 +91,27 @@ void botserv(User *u, BotInfo *bi, const std::string &buf) * bot is on. */ -void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) +void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) { if (!u || !ci || !ci->c || buf.empty()) return; /* Answer to ping if needed */ - if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') + if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') { - std::string ctcp = buf; + Anope::string ctcp = buf; ctcp.erase(ctcp.begin()); ctcp.erase(ctcp.end()); - ircdproto->SendCTCP(ci->bi, u->nick.c_str(), "%s", ctcp.c_str()); + ircdproto->SendCTCP(ci->bi, u->nick, "%s", ctcp.c_str()); } bool was_action = false; - std::string realbuf = buf; + Anope::string realbuf = buf; /* If it's a /me, cut the CTCP part because the ACTION will cause * problems with the caps or badwords kicker */ - if (realbuf.find("\1ACTION ", 0, 8) && realbuf[buf.length() - 1] == '\1') + if (!realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[buf.length() - 1] == '\1') { realbuf.erase(0, 8); realbuf.erase(realbuf.end()); @@ -141,7 +141,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) if (!check_access(u, ci, CA_NOKICK) && Allow) { /* Bolds kicker */ - if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find_first_of(2) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find(2) != Anope::string::npos) { check_ban(ci, u, TTB_BOLDS); bot_kick(ci, u, BOT_REASON_BOLD); @@ -149,7 +149,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Color kicker */ - if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find_first_of(3) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find(3) != Anope::string::npos) { check_ban(ci, u, TTB_COLORS); bot_kick(ci, u, BOT_REASON_COLOR); @@ -157,7 +157,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Reverses kicker */ - if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find_first_of(22) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find(22) != Anope::string::npos) { check_ban(ci, u, TTB_REVERSES); bot_kick(ci, u, BOT_REASON_REVERSE); @@ -165,7 +165,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* Underlines kicker */ - if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find_first_of(31) != std::string::npos) + if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find(31) != Anope::string::npos) { check_ban(ci, u, TTB_UNDERLINES); bot_kick(ci, u, BOT_REASON_UNDERLINE); @@ -204,39 +204,32 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) bool mustkick = false; /* Normalize the buffer */ - const char *nbuf = normalizeBuffer(realbuf.c_str()); + Anope::string nbuf = normalizeBuffer(realbuf); for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { BadWord *bw = ci->GetBadWord(i); - if (bw->type == BW_ANY && ((Config.BSCaseSensitive && strstr(nbuf, bw->word.c_str())) || (!Config.BSCaseSensitive && stristr(nbuf, bw->word.c_str())))) + if (bw->type == BW_ANY && ((Config.BSCaseSensitive && nbuf.find(bw->word) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) mustkick = true; else if (bw->type == BW_SINGLE) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (!stricmp(nbuf, bw->word.c_str())))) + if ((Config.BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config.BSCaseSensitive && bw->word.equals_ci(nbuf))) mustkick = true; - else if ((strchr(nbuf, ' ') == nbuf + len) && ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf)))) + else if (nbuf.find(' ') == len && ((Config.BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config.BSCaseSensitive && bw->word.equals_ci(nbuf)))) mustkick = true; else { - if ((strrchr(nbuf, ' ') == nbuf + strlen(nbuf) - len - 1) && ((Config.BSCaseSensitive && (strstr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)))) + if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((Config.BSCaseSensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!Config.BSCaseSensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) mustkick = true; else { - char *wordbuf = new char[len + 3]; + Anope::string wordbuf = " " + bw->word + " "; - wordbuf[0] = ' '; - wordbuf[len + 1] = ' '; - wordbuf[len + 2] = '\0'; - memcpy(wordbuf + 1, bw->word.c_str(), len); - - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } } @@ -244,40 +237,28 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && !strncmp(nbuf, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf, bw->word.c_str(), len))) + if ((Config.BSCaseSensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!Config.BSCaseSensitive && nbuf.substr(0, len).equals_ci(bw->word))) mustkick = true; else { - char *wordbuf = new char[len + 2]; - - memcpy(wordbuf + 1, bw->word.c_str(), len); - wordbuf[0] = ' '; - wordbuf[len + 1] = '\0'; + Anope::string wordbuf = " " + bw->word; - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } else if (bw->type == BW_END) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && !strncmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len))) + if ((Config.BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!Config.BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) mustkick = true; else { - char *wordbuf = new char[len + 2]; - - memcpy(wordbuf, bw->word.c_str(), len); - wordbuf[len] = ' '; - wordbuf[len + 1] = '\0'; + Anope::string wordbuf = bw->word + " "; - if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) + if ((Config.BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config.BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) mustkick = true; - - delete [] wordbuf; } } @@ -289,15 +270,9 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) else bot_kick(ci, u, BOT_REASON_BADWORD, bw->word.c_str()); - /* free the normalized buffer before return (#850) */ - delete [] nbuf; - return; } } - - /* Free the normalized buffer */ - delete [] nbuf; } /* Flood kicker */ @@ -331,16 +306,15 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) if (!ud) return; - if (ud->lastline && stricmp(ud->lastline, buf.c_str())) + if (!ud->lastline.empty() && !ud->lastline.equals_ci(buf)) { - delete [] ud->lastline; - ud->lastline = sstrdup(buf.c_str()); + ud->lastline = buf; ud->times = 0; } else { - if (!ud->lastline) - ud->lastline = sstrdup(buf.c_str()); + if (ud->lastline.empty()) + ud->lastline = buf; ++ud->times; } @@ -354,41 +328,35 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) } /* return if the user is on the ignore list */ - if (get_ignore(u->nick.c_str()) != NULL) + if (get_ignore(u->nick)) return; /* Fantaisist commands */ - if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == *Config.BSFantasyCharacter && !was_action) + if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == Config.BSFantasyCharacter[0] && !was_action) { spacesepstream sep(buf); - std::string token; + Anope::string token; - if (sep.GetToken(token) && token[0] == *Config.BSFantasyCharacter) + if (sep.GetToken(token) && token[0] == Config.BSFantasyCharacter[0]) { /* Strip off the fantasy character */ token.erase(token.begin()); if (check_access(u, ci, CA_FANTASIA)) { - Command *command = FindCommand(ChanServ, token.c_str()); + Command *command = FindCommand(ChanServ, token); /* Command exists and can not be called by fantasy */ if (command && !command->HasFlag(CFLAG_DISABLE_FANTASY)) { - std::string bbuf = std::string(token); + Anope::string bbuf = token; /* Some commands don't need the channel name added.. eg !help */ if (!command->HasFlag(CFLAG_STRIP_CHANNEL)) - { - bbuf += " "; - bbuf += ci->name; - } + bbuf += " " + ci->name; if (!sep.StreamEnd()) - { - bbuf += " "; - bbuf += sep.GetRemaining(); - } + bbuf += " " + sep.GetRemaining(); chanserv(u, bbuf); } @@ -405,21 +373,11 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) /*************************************************************************/ -BotInfo *findbot(const char *nick) -{ - return findbot(ci::string(nick)); -} - -BotInfo *findbot(const std::string &nick) -{ - return findbot(ci::string(nick.c_str())); -} - -BotInfo *findbot(const ci::string &nick) +BotInfo *findbot(const Anope::string &nick) { if (isdigit(nick[0]) && ircd->ts6) { - botinfo_uid_map::const_iterator it = BotListByUID.find(nick.c_str()); + botinfo_uid_map::const_iterator it = BotListByUID.find(nick); if (it != BotListByUID.end()) return it->second; @@ -440,14 +398,13 @@ BotInfo *findbot(const ci::string &nick) static BanData *get_ban_data(Channel *c, User *u) { - char mask[BUFSIZE]; BanData *bd, *next; time_t now = time(NULL); if (!c || !u) return NULL; - snprintf(mask, sizeof(mask), "%s@%s", u->GetIdent().c_str(), u->GetDisplayedHost().c_str()); + Anope::string mask = u->GetIdent() + "@" + u->GetDisplayedHost(); for (bd = c->bd; bd; bd = next) { @@ -459,13 +416,11 @@ static BanData *get_ban_data(Channel *c, User *u) bd->prev->next = bd->next; else c->bd = bd->next; - if (bd->mask) - delete [] bd->mask; next = bd->next; delete bd; continue; } - if (!stricmp(bd->mask, mask)) + if (bd->mask.equals_ci(mask)) { bd->last_use = now; return bd; @@ -475,7 +430,7 @@ static BanData *get_ban_data(Channel *c, User *u) /* If we fall here it is that we haven't found the record */ bd = new BanData; - bd->mask = sstrdup(mask); + bd->mask = mask; bd->last_use = now; for (int x = 0; x < TTB_SIZE; ++x) bd->ttb[x] = 0; @@ -511,11 +466,9 @@ static UserData *get_user_data(Channel *c, User *u) /* Checks whether data is obsolete */ if (now - uc->ud.last_use > Config.BSKeepData) { - if (uc->ud.lastline) - delete [] uc->ud.lastline; /* We should not free and realloc, but reset to 0 instead. */ - memset(&uc->ud, 0, sizeof(UserData)); + uc->ud.Clear(); uc->ud.last_use = now; } @@ -550,11 +503,11 @@ static void check_ban(ChannelInfo *ci, User *u, int ttbtype) /* Should not use == here because bd->ttb[ttbtype] could possibly be > ci->ttb[ttbtype] * if the TTB was changed after it was not set (0) before and the user had already been * kicked a few times. Bug #1056 - Adam */ - char mask[BUFSIZE]; + Anope::string mask; bd->ttb[ttbtype] = 0; - get_idealban(ci, u, mask, sizeof(mask)); + get_idealban(ci, u, mask); if (ci->c) ci->c->SetMode(NULL, CMODE_BAN, mask); @@ -589,9 +542,9 @@ static void bot_kick(ChannelInfo *ci, User *u, int message, ...) /* Makes a simple ban and kicks the target */ -void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, const char *reason) +void bot_raw_ban(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) { - char mask[BUFSIZE]; + Anope::string mask; User *u = finduser(nick); if (!u) @@ -599,35 +552,35 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, const char *reaso if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u) == 1) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(BOT_EXCEPT)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(BOT_EXCEPT)); return; } - get_idealban(ci, u, mask, sizeof(mask)); + get_idealban(ci, u, mask); ci->c->SetMode(NULL, CMODE_BAN, mask); /* Check if we need to do a signkick or not -GD */ if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) - ci->c->Kick(ci->bi, u, "%s (%s)", reason ? reason : ci->bi->nick.c_str(), requester->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); else - ci->c->Kick(ci->bi, u, "%s", reason ? reason : ci->bi->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); } /*************************************************************************/ /* Makes a kick with a "dynamic" reason ;) */ -void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, const char *reason) +void bot_raw_kick(User *requester, ChannelInfo *ci, const Anope::string &nick, const Anope::string &reason) { User *u = finduser(nick); @@ -636,24 +589,24 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, const char *reas if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) - ci->c->Kick(ci->bi, u, "%s (%s)", reason ? reason : ci->bi->nick.c_str(), requester->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str()); else - ci->c->Kick(ci->bi, u, "%s", reason ? reason : ci->bi->nick.c_str()); + ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); } /*************************************************************************/ /* Makes a mode operation on a channel for a nick */ -void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick) +void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, const Anope::string &nick) { char buf[BUFSIZE] = ""; User *u; @@ -665,16 +618,16 @@ void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); - if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && *mode == '-' && requester != u) + if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && mode[0] == '-' && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", getstring(ACCESS_DENIED)); return; } - if (*mode == '-' && ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) + if (mode[0] == '-' && ci->HasFlag(CI_PEACE) && !requester->nick.equals_ci(nick) && get_access(u, ci) >= get_access(requester, ci)) return; - ci->c->SetModes(NULL, "%s %s", mode, nick); + ci->c->SetModes(NULL, "%s %s", mode.c_str(), nick.c_str()); } /*************************************************************************/ @@ -683,15 +636,11 @@ void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick * @param A string to be parsed for control and color codes * @return A string stripped of control and color codes */ -char *normalizeBuffer(const char *buf) +Anope::string normalizeBuffer(const Anope::string &buf) { - char *newbuf; - int i, len, j = 0; + Anope::string newbuf; - len = strlen(buf); - newbuf = new char[len + 1]; - - for (i = 0; i < len; ++i) + for (unsigned i = 0, end = buf.length(); i < end; ++i) { switch (buf[i]) { @@ -748,13 +697,9 @@ char *normalizeBuffer(const char *buf) break; /* A valid char gets copied into the new buffer */ default: - newbuf[j] = buf[i]; - ++j; + newbuf += buf[i]; } } - /* Terminate the string */ - newbuf[j] = 0; - return newbuf; } diff --git a/src/channels.cpp b/src/channels.cpp index e58655f58..862dfe152 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -19,17 +19,16 @@ channel_map ChannelList; * @param name The channel name * @param ts The time the channel was created */ -Channel::Channel(const std::string &name, time_t ts) +Channel::Channel(const Anope::string &name, time_t ts) { if (name.empty()) throw CoreException("A channel without a name ?"); this->name = name; - ChannelList[this->name.c_str()] = this; + ChannelList[this->name] = this; this->creation_time = ts; - this->topic = NULL; this->bans = this->excepts = this->invites = NULL; this->bd = NULL; this->server_modetime = this->chanserv_modetime = 0; @@ -54,8 +53,6 @@ Channel::~Channel() for (bd = this->bd; bd; bd = next) { - if (bd->mask) - delete [] bd->mask; next = bd->next; delete bd; } @@ -63,9 +60,6 @@ Channel::~Channel() if (this->ci) this->ci->c = NULL; - if (this->topic) - delete [] this->topic; - if (this->bans && this->bans->count) while (this->bans->entries) entry_delete(this->bans, this->bans->entries); @@ -78,7 +72,7 @@ Channel::~Channel() while (this->invites->entries) entry_delete(this->invites, this->invites->entries); - ChannelList.erase(this->name.c_str()); + ChannelList.erase(this->name); } void Channel::Sync() @@ -90,7 +84,7 @@ void Channel::Sync() } if (Me && Me->IsSynced() && !this->topic_sync) - restore_topic(name.c_str()); + restore_topic(name); } void Channel::JoinUser(User *user) @@ -106,7 +100,7 @@ void Channel::JoinUser(User *user) uc->Status = Status; this->users.push_back(uc); - if (!get_ignore(user->nick.c_str())) + if (!get_ignore(user->nick)) { if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) { @@ -117,8 +111,8 @@ void Channel::JoinUser(User *user) } /* Added channelname to entrymsg - 30.03.2004, Certus */ /* Also, don't send the entrymsg when bursting -GD */ - if (this->ci && this->ci->entry_message && user->server->IsSynced()) - user->SendMessage(whosends(this->ci)->nick, "[%s] %s", this->name.c_str(), this->ci->entry_message); + if (this->ci && !this->ci->entry_message.empty() && user->server->IsSynced()) + user->SendMessage(whosends(this->ci)->nick, "[%s] %s", this->name.c_str(), this->ci->entry_message.c_str()); } /** @@ -129,16 +123,15 @@ void Channel::JoinUser(User *user) * But don't join the bot if the channel is persistant - Adam * But join persistant channels when syncing with our uplink- DP **/ - if (Config.s_BotServ && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST)) && this->users.size() == Config.BSMinUsers) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST)) && this->users.size() == Config.BSMinUsers) this->ci->bi->Join(this); /* Only display the greet if the main uplink we're connected * to has synced, or we'll get greet-floods when the net * recovers from a netsplit. -GD */ - if (Config.s_BotServ && this->ci && this->ci->bi && this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && user->Account()->greet && - check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && !user->Account()->greet.empty() && check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) { - ircdproto->SendPrivmsg(this->ci->bi, this->name.c_str(), "[%s] %s", user->Account()->display, user->Account()->greet); + ircdproto->SendPrivmsg(this->ci->bi, this->name, "[%s] %s", user->Account()->display.c_str(), user->Account()->greet.c_str()); this->ci->bi->lastmsg = time(NULL); } } @@ -150,7 +143,7 @@ void Channel::DeleteUser(User *user) { if (this->ci) update_cs_lastseen(user, this->ci); - + Alog(LOG_DEBUG) << user->nick << " leaves " << this->name; CUserList::iterator cit, cit_end = this->users.end(); @@ -190,7 +183,7 @@ void Channel::DeleteUser(User *user) if (this->ci && this->ci->HasFlag(CI_INHABIT)) return; - if (Config.s_BotServ && this->ci && this->ci->bi && this->FindUser(this->ci->bi)) + if (!Config.s_BotServ.empty() && this->ci && this->ci->bi && this->FindUser(this->ci->bi)) this->ci->bi->Part(this->ci->c); else if (this->users.empty()) delete this; @@ -257,7 +250,7 @@ bool Channel::HasMode(ChannelModeName Name) * @param param The param * @param EnforeMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::SetModeInternal(ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -275,7 +268,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } BotInfo *bi = NULL; - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) bi = findbot(param); User *u = bi ? bi : finduser(param); @@ -306,7 +299,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } ChannelModeList *cml = dynamic_cast(cm); - cml->AddMask(this, param.c_str()); + cml->AddMask(this, param); return; } @@ -321,7 +314,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En } /* They could be resetting the mode to change its params */ - std::map::iterator it = Params.find(cm->Name); + std::map::iterator it = Params.find(cm->Name); if (it != Params.end()) Params.erase(it); @@ -354,7 +347,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* Remove the mode */ if (cm->Type == MODE_PARAM) { - std::string cparam; + Anope::string cparam; GetParam(cm->Name, cparam); RemoveMode(NULL, cm, cparam); } @@ -365,14 +358,14 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En else if (cm->Type == MODE_PARAM && ci->HasMLock(cm->Name, true)) { ChannelModeParam *cmp = dynamic_cast(cm); - std::string cparam, ciparam; + Anope::string cparam, ciparam; /* Get the param currently set on this channel */ GetParam(cmp->Name, cparam); /* Get the param set in mlock */ ci->GetParam(cmp->Name, ciparam); /* We have the wrong param set */ - if (cparam.empty() || ciparam.empty() || cparam != ciparam) + if (cparam.empty() || ciparam.empty() || !cparam.equals_cs(ciparam)) /* Reset the mode with the correct param */ SetMode(NULL, cm, ciparam); } @@ -383,7 +376,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En * @param param The param * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -401,7 +394,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool } BotInfo *bi = NULL; - if (Config.s_BotServ) + if (!Config.s_BotServ.empty()) bi = findbot(param); User *u = bi ? bi : finduser(param); @@ -437,7 +430,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool } ChannelModeList *cml = dynamic_cast(cm); - cml->DelMask(this, param.c_str()); + cml->DelMask(this, param); return; } @@ -445,7 +438,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool if (cm->Type == MODE_PARAM) { - std::map::iterator it = Params.find(cm->Name); + std::map::iterator it = Params.find(cm->Name); if (it != Params.end()) Params.erase(it); } @@ -457,7 +450,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool if (ci) { ci->UnsetFlag(CI_PERSIST); - if (Config.s_BotServ && ci->bi && this->FindUser(ci->bi)) + if (!Config.s_BotServ.empty() && ci->bi && this->FindUser(ci->bi)) this->ci->bi->Part(this); } } @@ -486,7 +479,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool /* This is a param mode */ else if (cm->Type == MODE_PARAM) { - std::string cparam; + Anope::string cparam; /* Get the param stored in mlock for this mode */ if (ci->GetParam(cm->Name, cparam)) SetMode(NULL, cm, cparam); @@ -500,7 +493,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -509,8 +502,8 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bo return; else if (cm->Type == MODE_PARAM && HasMode(cm->Name)) { - std::string cparam; - if (GetParam(cm->Name, cparam) && cparam == param) + Anope::string cparam; + if (GetParam(cm->Name, cparam) && cparam.equals_cs(param)) return; } else if (cm->Type == MODE_STATUS) @@ -535,7 +528,7 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bo * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -547,7 +540,7 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const std::string ¶ * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::SetMode(BotInfo *bi, char Mode, const std::string ¶m, bool EnforceMLock) +void Channel::SetMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) { SetMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); } @@ -558,7 +551,7 @@ void Channel::SetMode(BotInfo *bi, char Mode, const std::string ¶m, bool Enf * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool EnforceMLock) { if (!cm) return; @@ -597,7 +590,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool EnforceMLock) { RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock); } @@ -609,7 +602,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const std::string &p * @param param Optional param arg for the mode * @param EnforceMLock true if mlocks should be enforced, false to override mlock */ -void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string ¶m, bool EnforceMLock) +void Channel::RemoveMode(BotInfo *bi, char Mode, const Anope::string ¶m, bool EnforceMLock) { RemoveMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock); } @@ -619,9 +612,9 @@ void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string ¶m, bool * @param Target a string to put the param into * @return true on success */ -const bool Channel::GetParam(ChannelModeName Name, std::string &Target) +const bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) { - std::map::iterator it = Params.find(Name); + std::map::iterator it = Params.find(Name); Target.clear(); @@ -639,7 +632,7 @@ const bool Channel::GetParam(ChannelModeName Name, std::string &Target) */ const bool Channel::HasParam(ChannelModeName Name) { - std::map::iterator it = Params.find(Name); + std::map::iterator it = Params.find(Name); if (it != Params.end()) return true; @@ -666,7 +659,7 @@ void Channel::ClearModes(BotInfo *bi) this->RemoveMode(NULL, cm); else if (cm->Type == MODE_PARAM) { - std::string param; + Anope::string param; this->GetParam(cm->Name, param); this->RemoveMode(NULL, cm, param); } @@ -742,7 +735,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; - std::string modebuf, sbuf; + Anope::string modebuf, sbuf; int add = -1; va_start(args, cmodes); vsnprintf(buf, BUFSIZE - 1, cmodes, args); @@ -750,7 +743,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.size(); i < end; ++i) + for (unsigned i = 0, end = modebuf.length(); i < end; ++i) { ChannelMode *cm; @@ -859,10 +852,10 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av) * @param nick The nick being kicked * @param reason The reason for the kick */ -void Channel::KickInternal(const std::string &source, const std::string &nick, const std::string &reason) +void Channel::KickInternal(const Anope::string &source, const Anope::string &nick, const Anope::string &reason) { BotInfo *bi = NULL; - if (Config.s_BotServ && this->ci) + if (!Config.s_BotServ.empty() && this->ci) bi = findbot(nick); User *user = bi ? bi : finduser(nick); if (!user) @@ -873,7 +866,7 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c Alog(LOG_DEBUG) << "Channel::KickInternal kicking " << user->nick << " from " << this->name; - std::string chname = this->name; + Anope::string chname = this->name; if (user->FindChannel(this)) { @@ -882,7 +875,7 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c } else Alog(LOG_DEBUG) << "Channel::KickInternal got kick for user " << user->nick << " who isn't on channel " << this->name << " ?"; - + /* Bots get rejoined */ if (bi) bi->Join(chname); @@ -923,12 +916,9 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) * eventual parameters won't be added to the string. */ -char *chan_get_modes(Channel * chan, int complete, int plus) +Anope::string chan_get_modes(Channel *chan, int complete, int plus) { - static char res[BUFSIZE]; - char params[BUFSIZE]; - char *end = res, *value, *pend = params, *pend2 = params; - std::string param; + Anope::string res, params, param; if (chan->HasModes()) { @@ -941,7 +931,7 @@ char *chan_get_modes(Channel * chan, int complete, int plus) if (chan->HasMode(cm->Name)) { - *end++ = cm->ModeChar; + res += cm->ModeChar; if (complete) { @@ -954,42 +944,22 @@ char *chan_get_modes(Channel * chan, int complete, int plus) chan->GetParam(cmp->Name, param); if (!param.empty()) - { - value = const_cast(param.c_str()); - - *pend++ = ' '; - - while (*value) - *pend++ = *value++; - } + params += " " + param; } } } } } - while (*pend2) - *end++ = *pend2++; + res += params; } - *end = 0; - return res; } /*************************************************************************/ -Channel *findchan(const char *chan) -{ - return findchan(ci::string(chan)); -} - -Channel *findchan(const std::string &chan) -{ - return findchan(ci::string(chan.c_str())); -} - -Channel *findchan(const ci::string &chan) +Channel *findchan(const Anope::string &chan) { channel_map::const_iterator it = ChannelList.find(chan); @@ -1006,7 +976,7 @@ void get_channel_stats(long *nrec, long *memuse) { long count = 0, mem = 0; BanData *bd; - std::string buf; + Anope::string buf; for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) { @@ -1014,8 +984,8 @@ void get_channel_stats(long *nrec, long *memuse) ++count; mem += sizeof(*chan); - if (chan->topic) - mem += strlen(chan->topic) + 1; + if (!chan->topic.empty()) + mem += chan->topic.length() + 1; if (chan->GetParam(CMODE_KEY, buf)) mem += buf.length() + 1; if (chan->GetParam(CMODE_FLOOD, buf)) @@ -1031,13 +1001,13 @@ void get_channel_stats(long *nrec, long *memuse) { mem += sizeof(*it); mem += sizeof((*it)->ud); - if ((*it)->ud.lastline) - mem += strlen((*it)->ud.lastline) + 1; + if (!(*it)->ud.lastline.empty()) + mem += (*it)->ud.lastline.length() + 1; } for (bd = chan->bd; bd; bd = bd->next) { - if (bd->mask) - mem += strlen(bd->mask) + 1; + if (!bd->mask.empty()) + mem += bd->mask.length() + 1; mem += sizeof(*bd); } } @@ -1050,7 +1020,7 @@ void get_channel_stats(long *nrec, long *memuse) /* Is the given nick on the given channel? This function supports links. */ -User *nc_on_chan(Channel *c, NickCore *nc) +User *nc_on_chan(Channel *c, const NickCore *nc) { if (!c || !nc) return NULL; @@ -1073,7 +1043,7 @@ User *nc_on_chan(Channel *c, NickCore *nc) * av[0] = channels to join */ -void do_join(const char *source, int ac, const char **av) +void do_join(const Anope::string &source, int ac, const char **av) { User *user; Channel *chan; @@ -1087,7 +1057,7 @@ void do_join(const char *source, int ac, const char **av) } commasepstream sep(av[0]); - ci::string buf; + Anope::string buf; while (sep.GetToken(buf)) { if (buf[0] == '0') @@ -1096,7 +1066,7 @@ void do_join(const char *source, int ac, const char **av) { ChannelContainer *cc = *it++; - std::string channame = cc->chan->name; + Anope::string channame = cc->chan->name; FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, cc->chan)); cc->chan->DeleteUser(user); FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(channame), channame, "")); @@ -1114,7 +1084,7 @@ void do_join(const char *source, int ac, const char **av) /* Join came with a TS */ if (ac == 2) { - time_t ts = atol(av[1]); + time_t ts = Anope::string(av[1]).is_number_only() ? convertTo(av[1]) : 0; /* Their time is older, we lose */ if (chan->creation_time > ts) @@ -1161,7 +1131,7 @@ void do_join(const char *source, int ac, const char **av) * @param ac number of args * @param av The channel, nick(s) being kicked, and reason */ -void do_kick(const std::string &source, int ac, const char **av) +void do_kick(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); if (!c) @@ -1170,7 +1140,7 @@ void do_kick(const std::string &source, int ac, const char **av) return; } - std::string buf; + Anope::string buf; commasepstream sep(av[1]); while (sep.GetToken(buf)) c->KickInternal(source, buf, av[2]); @@ -1183,7 +1153,7 @@ void do_kick(const std::string &source, int ac, const char **av) * av[1] = reason (optional) */ -void do_part(const char *source, int ac, const char **av) +void do_part(const Anope::string &source, int ac, const char **av) { User *user = finduser(source); if (!user) @@ -1193,7 +1163,7 @@ void do_part(const char *source, int ac, const char **av) } commasepstream sep(av[0]); - ci::string buf; + Anope::string buf; while (sep.GetToken(buf)) { Channel *c = findchan(buf); @@ -1204,7 +1174,7 @@ void do_part(const char *source, int ac, const char **av) if (user->FindChannel(c)) { FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, c)); - std::string ChannelName = c->name; + Anope::string ChannelName = c->name; c->DeleteUser(user); FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, findchan(ChannelName), ChannelName, av[1] ? av[1] : "")); } @@ -1221,7 +1191,7 @@ void do_part(const char *source, int ac, const char **av) * @param ac Number of args in array.. * @param av Array of args */ -void do_cmode(const char *source, int ac, const char **av) +void do_cmode(const Anope::string &source, int ac, const char **av) { Channel *c; ChannelInfo *ci; @@ -1248,8 +1218,8 @@ void do_cmode(const char *source, int ac, const char **av) /* :42XAAAAAO TMODE 1106409026 #ircops +b *!*@*.aol.com */ if (ircd->ts6 && isdigit(av[0][0])) { - --ac; - ++av; + --ac; + ++av; } c = findchan(av[0]); @@ -1264,7 +1234,7 @@ void do_cmode(const char *source, int ac, const char **av) return; } - if (strchr(source, '.') && !av[1][strcspn(av[1], "bovahq")]) + if (source.find('.') != Anope::string::npos && Anope::string(av[1]).find_first_of("bovahq") == Anope::string::npos) { if (time(NULL) != c->server_modetime) { @@ -1283,23 +1253,11 @@ void do_cmode(const char *source, int ac, const char **av) /* Handle a TOPIC command. */ -void do_topic(const char *source, int ac, const char **av) +void do_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); ChannelInfo *ci; - int ts; - time_t topic_time; - char *topicsetter; - - if (ircd->sjb64) - { - ts = base64dects(av[2]); - Alog(LOG_DEBUG) << "encoded TOPIC TS " << av[2] << " converted to " << ts; - } - else - ts = strtoul(av[2], NULL, 10); - - topic_time = ts; + time_t topic_time = Anope::string(av[2]).is_number_only() ? convertTo(av[2]) : 0; if (!c) { @@ -1315,35 +1273,25 @@ void do_topic(const char *source, int ac, const char **av) /* For Unreal, cut off the ! and any futher part of the topic setter. * This way, nick!ident@host setters will only show the nick. -GD */ - topicsetter = myStrGetToken(av[1], '!', 0); + Anope::string topicsetter = myStrGetToken(av[1], '!', 0); /* If the current topic we have matches the last known topic for this * channel exactly, there's no need to update anything and we can as * well just return silently without updating anything. -GD */ - if (ac > 3 && *av[3] && ci && ci->last_topic && !strcmp(av[3], ci->last_topic) && !strcmp(topicsetter, ci->last_topic_setter.c_str())) - { - delete [] topicsetter; + if (ac > 3 && *av[3] && ci && !ci->last_topic.empty() && ci->last_topic.equals_cs(av[3]) && ci->last_topic_setter.equals_cs(topicsetter)) return; - } if (check_topiclock(c, topic_time)) - { - delete [] topicsetter; return; - } - if (c->topic) - { - delete [] c->topic; - c->topic = NULL; - } + if (!c->topic.empty()) + c->topic.clear(); if (ac > 3 && *av[3]) - c->topic = sstrdup(av[3]); + c->topic = av[3]; c->topic_setter = topicsetter; c->topic_time = topic_time; - delete [] topicsetter; record_topic(av[0]); @@ -1377,12 +1325,12 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes) if (!c || !(ci = c->ci)) return; - if (ci->HasFlag(CI_FORBIDDEN) || *(c->name.c_str()) == '+') + if (ci->HasFlag(CI_FORBIDDEN) || c->name[0] == '+') return; Alog(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << c->name << " (" << (give_modes ? "" : "not ") << "giving modes)"; - if (give_modes && !get_ignore(user->nick.c_str()) && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP))) + if (give_modes && !get_ignore(user->nick) && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP))) { if (owner && check_access(user, ci, CA_AUTOOWNER)) c->SetMode(NULL, CMODE_OWNER, user->nick); @@ -1420,7 +1368,7 @@ void chan_set_