summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/actions.cpp29
-rw-r--r--src/base64.cpp334
-rw-r--r--src/bots.cpp53
-rw-r--r--src/botserv.cpp205
-rw-r--r--src/channels.cpp414
-rw-r--r--src/chanserv.cpp212
-rw-r--r--src/command.cpp14
-rw-r--r--src/commands.cpp39
-rw-r--r--src/compat.cpp58
-rw-r--r--src/config.cpp861
-rw-r--r--src/configreader.cpp30
-rw-r--r--src/encrypt.cpp19
-rw-r--r--src/hashcomp.cpp93
-rw-r--r--src/hostserv.cpp36
-rw-r--r--src/init.cpp73
-rw-r--r--src/ircd.cpp19
-rw-r--r--src/language.cpp8
-rw-r--r--src/log.cpp50
-rw-r--r--src/mail.cpp50
-rw-r--r--src/main.cpp74
-rw-r--r--src/memory.cpp46
-rw-r--r--src/memoserv.cpp71
-rw-r--r--src/messages.cpp99
-rw-r--r--src/misc.cpp497
-rw-r--r--src/modes.cpp96
-rw-r--r--src/module.cpp20
-rw-r--r--src/modulemanager.cpp65
-rw-r--r--src/modules.cpp50
-rw-r--r--src/nickalias.cpp35
-rw-r--r--src/nickcore.cpp30
-rw-r--r--src/nickserv.cpp164
-rw-r--r--src/operserv.cpp163
-rw-r--r--src/opertype.cpp16
-rw-r--r--src/process.cpp79
-rw-r--r--src/protocol.cpp111
-rw-r--r--src/regchannel.cpp84
-rw-r--r--src/send.cpp75
-rw-r--r--src/servers.cpp62
-rw-r--r--src/sessions.cpp139
-rw-r--r--src/sockets.cpp113
-rw-r--r--src/threadengines/threadengine_pthread.cpp2
-rw-r--r--src/threadengines/threadengine_win32.cpp2
-rw-r--r--src/timers.cpp4
-rw-r--r--src/tools/db-convert.h2
-rw-r--r--src/users.cpp324
-rw-r--r--src/wildcard.cpp12
-rw-r--r--src/win32/windows.cpp2
47 files changed, 1950 insertions, 3084 deletions
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<char *>(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<size_t>(tarindex) >= targsize)
- return -1;
- target[tarindex] = (pos - Base64) << 2;
- }
+ target += pos << 2;
state = 1;
break;
case 1:
- if (target)
- {
- if (static_cast<size_t>(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<size_t>(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<size_t>(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<char *>(ip), ':'))
- return NULL;
- else
- {
- s_ip = str_signed(ip);
- ia.s_addr = inet_addr(s_ip);
- cp = reinterpret_cast<unsigned char *>(ia.s_addr);
- b64_encode(reinterpret_cast<const char *>(&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<struct in_addr *>(targ);
+ b64_decode(buf, targ);
+ const struct in_addr ia = *reinterpret_cast<const struct in_addr *>(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<const unsigned char>(*b64++)];
-
- if (!b64)
- return 0;
-
- while (*b64)
- {
- v <<= 6;
- v += base64_to_int6_map[static_cast<const unsigned char>(*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<int>(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<ChannelModeStatus *>::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<long>(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 &param, bool EnforceMLock)
+void Channel::SetModeInternal(ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -275,7 +268,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, 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 &param, bool En
}
ChannelModeList *cml = dynamic_cast<ChannelModeList *>(cm);
- cml->AddMask(this, param.c_str());
+ cml->AddMask(this, param);
return;
}
@@ -321,7 +314,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, bool En
}
/* They could be resetting the mode to change its params */
- std::map<ChannelModeName, std::string>::iterator it = Params.find(cm->Name);
+ std::map<ChannelModeName, Anope::string>::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 &param, 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 &param, bool En
else if (cm->Type == MODE_PARAM && ci->HasMLock(cm->Name, true))
{
ChannelModeParam *cmp = dynamic_cast<ChannelModeParam *>(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 &param, 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 &param, bool EnforceMLock)
+void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -401,7 +394,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, 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 &param, bool
}
ChannelModeList *cml = dynamic_cast<ChannelModeList *>(cm);
- cml->DelMask(this, param.c_str());
+ cml->DelMask(this, param);
return;
}
@@ -445,7 +438,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
if (cm->Type == MODE_PARAM)
{
- std::map<ChannelModeName, std::string>::iterator it = Params.find(cm->Name);
+ std::map<ChannelModeName, Anope::string>::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 &param, 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 &param, 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 &param, 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 &param, bool EnforceMLock)
+void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -509,8 +502,8 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string &param, 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 &param, 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 &param, bool EnforceMLock)
+void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool EnforceMLock)
{
SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock);
}
@@ -547,7 +540,7 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const std::string &para
* @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 &param, bool EnforceMLock)
+void Channel::SetMode(BotInfo *bi, char Mode, const Anope::string &param, bool EnforceMLock)
{
SetMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock);
}
@@ -558,7 +551,7 @@ void Channel::SetMode(BotInfo *bi, char Mode, const std::string &param, 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 &param, bool EnforceMLock)
+void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -597,7 +590,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const std::string &param,
* @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 &param, bool EnforceMLock)
+void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, 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 &param, bool EnforceMLock)
+void Channel::RemoveMode(BotInfo *bi, char Mode, const Anope::string &param, bool EnforceMLock)
{
RemoveMode(bi, ModeManager::FindChannelModeByChar(Mode), param, EnforceMLock);
}
@@ -619,9 +612,9 @@ void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string &param, 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<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::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<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::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<char *>(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<time_t>(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<time_t>(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_correct_modes(User *user, Channel *c, int give_modes)
* @param bi The bot to send the modes from
* @param modes The modes
*/
-void MassChannelModes(BotInfo *bi, const std::string &modes)
+void MassChannelModes(BotInfo *bi, const Anope::string &modes)
{
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
{
@@ -1428,7 +1376,7 @@ void MassChannelModes(BotInfo *bi, const std::string &modes)
if (c->bouncy_modes)
return;
- c->SetModes(bi, false, modes.c_str());
+ c->SetModes(bi, false, "%s", modes.c_str());
}
}
@@ -1441,7 +1389,7 @@ void restore_unsynced_topics()
Channel *c = it->second;
if (!c->topic_sync)
- restore_topic(c->name.c_str());
+ restore_topic(c->name);
}
}
@@ -1453,60 +1401,52 @@ void restore_unsynced_topics()
* @param mask Host/IP/CIDR mask to convert to an entry
* @return Entry struct for the given mask, NULL if creation failed
*/
-Entry *entry_create(char *mask)
+Entry *entry_create(const Anope::string &mask)
{
Entry *entry;
- char *nick = NULL, *user, *host, *cidrhost;
+ Anope::string cidrhost;
uint32 ip, cidr;
entry = new Entry;
entry->SetFlag(ENTRYTYPE_NONE);
entry->prev = NULL;
entry->next = NULL;
- entry->nick = NULL;
- entry->user = NULL;
- entry->host = NULL;
- entry->mask = sstrdup(mask);
+ entry->mask = mask;
+
+ Anope::string newmask = mask, host, nick, user;
- host = strchr(mask, '@');
- if (host)
+ size_t at = newmask.find('@');
+ if (at != Anope::string::npos)
{
- *host++ = '\0';
+ host = newmask.substr(at + 1);
+ newmask = newmask.substr(0, at);
/* If the user is purely a wildcard, ignore it */
- if (str_is_pure_wildcard(mask))
- user = NULL;
- else
+ if (!str_is_pure_wildcard(newmask))
{
/* There might be a nick too */
- user = strchr(mask, '!');
- if (user)
+ //user = strchr(mask, '!');
+ size_t ex = newmask.find('!');
+ if (ex != Anope::string::npos)
{
- *user++ = '\0';
+ user = newmask.substr(ex + 1);
+ newmask = newmask.substr(0, ex);
/* If the nick is purely a wildcard, ignore it */
- if (str_is_pure_wildcard(mask))
- nick = NULL;
- else
- nick = mask;
+ if (!str_is_pure_wildcard(newmask))
+ nick = newmask;
}
else
- {
- nick = NULL;
- user = mask;
- }
+ user = newmask;
}
}
else
- {
/* It is possibly an extended ban/invite mask, but we do
* not support these at this point.. ~ Viper */
/* If there's no user in the mask, assume a pure wildcard */
- user = NULL;
- host = mask;
- }
+ host = newmask;
- if (nick)
+ if (!nick.empty())
{
- entry->nick = sstrdup(nick);
+ entry->nick = nick;
/* Check if we have a wildcard user */
if (str_is_wildcard(nick))
entry->SetFlag(ENTRYTYPE_NICK_WILD);
@@ -1514,9 +1454,9 @@ Entry *entry_create(char *mask)
entry->SetFlag(ENTRYTYPE_NICK);
}
- if (user)
+ if (!user.empty())
{
- entry->user = sstrdup(user);
+ entry->user = user;
/* Check if we have a wildcard user */
if (str_is_wildcard(user))
entry->SetFlag(ENTRYTYPE_USER_WILD);
@@ -1525,16 +1465,16 @@ Entry *entry_create(char *mask)
}
/* Only check the host if it's not a pure wildcard */
- if (*host && !str_is_pure_wildcard(host))
+ if (!host.empty() && !str_is_pure_wildcard(host))
{
- if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, &cidrhost))
+ if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, cidrhost))
{
entry->cidr_ip = ip;
entry->cidr_mask = cidr;
entry->SetFlag(ENTRYTYPE_CIDR4);
host = cidrhost;
}
- else if (ircd->cidrchanbei && strchr(host, '/'))
+ else if (ircd->cidrchanbei && host.find('/') != Anope::string::npos)
{
/* Most IRCd's don't enforce sane bans therefore it is not
* so unlikely we will encounter this.
@@ -1549,14 +1489,13 @@ Entry *entry_create(char *mask)
}
else
{
- entry->host = sstrdup(host);
+ entry->host = host;
if (str_is_wildcard(host))
entry->SetFlag(ENTRYTYPE_HOST_WILD);
else
entry->SetFlag(ENTRYTYPE_HOST);
}
}
- delete [] mask;
return entry;
}
@@ -1567,13 +1506,11 @@ Entry *entry_create(char *mask)
* @param mask The mask to parse and add to the list
* @return Pointer to newly added entry. NULL if it fails.
*/
-Entry *entry_add(EList *list, const char *mask)
+Entry *entry_add(EList *list, const Anope::string &mask)
{
Entry *e;
- char *hostmask;
- hostmask = sstrdup(mask);
- e = entry_create(hostmask);
+ e = entry_create(mask);
if (!e)
return NULL;
@@ -1607,13 +1544,6 @@ void entry_delete(EList *list, Entry *e)
if (list->entries == e)
list->entries = e->next;
- if (e->nick)
- delete [] e->nick;
- if (e->user)
- delete [] e->user;
- if (e->host)
- delete [] e->host;
- delete [] e->mask;
delete e;
--list->count;
@@ -1643,20 +1573,19 @@ EList *list_create()
* @param ip IP to match against, set to 0 to not match this
* @return 1 for a match, 0 for no match
*/
-int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const ci::string &host, uint32 ip)
+int entry_match(Entry *e, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip)
{
/* If we don't get an entry, or it s an invalid one, no match ~ Viper */
if (!e || !e->FlagCount())
return 0;
- ci::string ci_nick(nick.c_str()), ci_user(user.c_str()), ci_host(host.c_str());
if (ircd->cidrchanbei && e->HasFlag(ENTRYTYPE_CIDR4) && (!ip || (ip && (ip & e->cidr_mask) != e->cidr_ip)))
return 0;
- if (e->HasFlag(ENTRYTYPE_NICK) && (nick.empty() || nick != e->nick))
+ if (e->HasFlag(ENTRYTYPE_NICK) && (nick.empty() || e->nick.equals_ci(nick)))
return 0;
- if (e->HasFlag(ENTRYTYPE_USER) && (user.empty() || user != e->user))
+ if (e->HasFlag(ENTRYTYPE_USER) && (user.empty() || e->user.equals_ci(user)))
return 0;
- if (e->HasFlag(ENTRYTYPE_HOST) && (host.empty() || host != e->host))
+ if (e->HasFlag(ENTRYTYPE_HOST) && (host.empty() || e->host.equals_ci(host)))
return 0;
if (e->HasFlag(ENTRYTYPE_NICK_WILD) && !Anope::Match(nick, e->nick))
return 0;
@@ -1675,40 +1604,30 @@ int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const
* @param ip IP to match against, set to 0 to not match this
* @return 1 for a match, 0 for no match
*/
-int entry_match_mask(Entry *e, const char *mask, uint32 ip)
+int entry_match_mask(Entry *e, const Anope::string &mask, uint32 ip)
{
- char *hostmask, *nick, *user, *host;
int res;
- hostmask = sstrdup(mask);
+ Anope::string hostmask = mask, host, user, nick;
- host = strchr(hostmask, '@');
- if (host)
+ size_t at = hostmask.find('@');
+ if (at != Anope::string::npos)
{
- *host++ = '\0';
- user = strchr(hostmask, '!');
- if (user)
+ host = hostmask.substr(at + 1);
+ hostmask = hostmask.substr(0, at);
+ size_t ex = hostmask.find('!');
+ if (ex != Anope::string::npos)
{
- *user++ = '\0';
- nick = hostmask;
+ user = hostmask.substr(ex + 1);
+ nick = hostmask.substr(0, ex);
}
else
- {
- nick = NULL;
user = hostmask;
- }
}
else
- {
- nick = NULL;
- user = NULL;
host = hostmask;
- }
- res = entry_match(e, nick ? nick : "", user ? user : "", host ? host : "", ip);
-
- /* Free the destroyed mask. */
- delete [] hostmask;
+ res = entry_match(e, nick, user, host, ip);
return res;
}
@@ -1722,7 +1641,7 @@ int entry_match_mask(Entry *e, const char *mask, uint32 ip)
* @param ip The ip to match
* @return Returns the first matching entry, if none, NULL is returned.
*/
-Entry *elist_match(EList *list, const char *nick, const char *user, const char *host, uint32 ip)
+Entry *elist_match(EList *list, const Anope::string &nick, const Anope::string &user, const Anope::string &host, uint32 ip)
{
Entry *e;
@@ -1730,7 +1649,7 @@ Entry *elist_match(EList *list, const char *nick, const char *user, const char *
return NULL;
for (e = list->entries; e; e = e->next)
- if (entry_match(e, nick ? nick : "", user ? user : "", host ? host : "", ip))
+ if (entry_match(e, nick, user, host, ip))
return e;
/* We matched none */
@@ -1744,44 +1663,34 @@ Entry *elist_match(EList *list, const char *nick, const char *user, const char *
* @param ip The ip to match
* @return Returns the first matching entry, if none, NULL is returned.
*/
-Entry *elist_match_mask(EList *list, const char *mask, uint32 ip)
+Entry *elist_match_mask(EList *list, const Anope::string &mask, uint32 ip)
{
- char *hostmask, *nick, *user, *host;
Entry *res;
- if (!list || !list->entries || !mask)
+ if (!list || !list->entries || mask.empty())
return NULL;
- hostmask = sstrdup(mask);
+ Anope::string hostmask = mask, host, user, nick;
- host = strchr(hostmask, '@');
- if (host)
+ size_t at = hostmask.find('@');
+ if (at != Anope::string::npos)
{
- *host++ = '\0';
- user = strchr(hostmask, '!');
- if (user)
+ host = hostmask.substr(at + 1);
+ hostmask = hostmask.substr(0, at);
+ size_t ex = hostmask.find('!');
+ if (ex != Anope::string::npos)
{
- *user++ = '\0';
- nick = hostmask;
+ user = hostmask.substr(ex + 1);
+ nick = hostmask.substr(0, ex);
}
else
- {
- nick = NULL;
user = hostmask;
- }
}
else
- {
- nick = NULL;
- user = NULL;
host = hostmask;
- }
res = elist_match(list, nick, user, host, ip);
- /* Free the destroyed mask. */
- delete [] hostmask;
-
return res;
}
@@ -1794,36 +1703,33 @@ Entry *elist_match_mask(EList *list, const char *mask, uint32 ip)
Entry *elist_match_user(EList *list, User *u)
{
Entry *res;
- char *host;
+ Anope::string host;
uint32 ip = 0;
if (!list || !list->entries || !u)
return NULL;
- if (u->hostip == NULL)
+ 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);
/* Match what we ve got against the lists.. */
- res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->host, ip);
+ res = elist_match(list, u->nick, u->GetIdent(), u->host, ip);
if (!res)
- res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip);
- if (!res && !u->GetCloakedHost().empty() && u->GetCloakedHost() != u->GetDisplayedHost())
- res = elist_match(list, u->nick.c_str(), u->GetIdent().c_str(), u->GetCloakedHost().c_str(), ip);
-
- if (host)
- delete [] host;
+ res = elist_match(list, u->nick, u->GetIdent(), u->GetDisplayedHost(), ip);
+ if (!res && !u->GetCloakedHost().empty() && !u->GetCloakedHost().equals_cs(u->GetDisplayedHost()))
+ res = elist_match(list, u->nick, u->GetIdent(), u->GetCloakedHost(), ip);
return res;
}
@@ -1834,15 +1740,15 @@ Entry *elist_match_user(EList *list, User *u)
* @param mask The *!*@* mask to match
* @return Returns the first matching entry, if none, NULL is returned.
*/
-Entry *elist_find_mask(EList *list, const char *mask)
+Entry *elist_find_mask(EList *list, const Anope::string &mask)
{
Entry *e;
- if (!list || !list->entries || !mask)
+ if (!list || !list->entries || mask.empty())
return NULL;
for (e = list->entries; e; e = e->next)
- if (!stricmp(e->mask, mask))
+ if (e->mask.equals_ci(mask))
return e;
return NULL;
@@ -1867,14 +1773,14 @@ long get_memuse(EList *list)
{
for (e = list->entries; e; e = e->next)
{
- if (e->nick)
- mem += strlen(e->nick) + 1;
- if (e->user)
- mem += strlen(e->user) + 1;
- if (e->host)
- mem += strlen(e->host) + 1;
- if (e->mask)
- mem += strlen(e->mask) + 1;
+ if (!e->nick.empty())
+ mem += e->nick.length() + 1;
+ if (!e->user.empty())
+ mem += e->user.length() + 1;
+ if (!e->host.empty())
+ mem += e->host.length() + 1;
+ if (!e->mask.empty())
+ mem += e->mask.length() + 1;
}
}
diff --git a/src/chanserv.cpp b/src/chanserv.cpp
index 27cb159ce..bcfe239cd 100644
--- a/src/chanserv.cpp
+++ b/src/chanserv.cpp
@@ -66,16 +66,16 @@ LevelInfo levelinfo[] = {
{ CA_AUTOHALFOP, "AUTOHALFOP", CHAN_LEVEL_AUTOHALFOP },
{ CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP },
{ CA_AUTOPROTECT, "AUTOPROTECT", CHAN_LEVEL_AUTOPROTECT },
- { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE },
+ { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE },
{ CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN },
{ CA_SIGNKICK, "SIGNKICK", CHAN_LEVEL_SIGNKICK },
{ CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST },
{ CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE },
- { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK },
+ { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK },
{ CA_SET, "SET", CHAN_LEVEL_SET },
{ CA_BAN, "BAN", CHAN_LEVEL_BAN },
- { CA_BANME, "BANME", CHAN_LEVEL_BANME },
- { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR },
+ { CA_BANME, "BANME", CHAN_LEVEL_BANME },
+ { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR },
{ CA_GETKEY, "GETKEY", CHAN_LEVEL_GETKEY },
{ CA_HALFOP, "HALFOP", CHAN_LEVEL_HALFOP },
{ CA_HALFOPME, "HALFOPME", CHAN_LEVEL_HALFOPME },
@@ -86,20 +86,20 @@ LevelInfo levelinfo[] = {
{ CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP },
{ CA_OPDEOPME, "OPDEOPME", CHAN_LEVEL_OPDEOPME },
{ CA_PROTECT, "PROTECT", CHAN_LEVEL_PROTECT },
- { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME },
- { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC },
- { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN },
- { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE },
+ { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME },
+ { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC },
+ { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN },
+ { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE },
{ CA_VOICEME, "VOICEME", CHAN_LEVEL_VOICEME },
{ CA_MEMO, "MEMO", CHAN_LEVEL_MEMO },
{ CA_ASSIGN, "ASSIGN", CHAN_LEVEL_ASSIGN },
{ CA_BADWORDS, "BADWORDS", CHAN_LEVEL_BADWORDS },
{ CA_FANTASIA, "FANTASIA", CHAN_LEVEL_FANTASIA },
- { CA_GREET, "GREET", CHAN_LEVEL_GREET },
+ { CA_GREET, "GREET", CHAN_LEVEL_GREET },
{ CA_NOKICK, "NOKICK", CHAN_LEVEL_NOKICK },
{ CA_SAY, "SAY", CHAN_LEVEL_SAY },
- { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER },
- { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER },
+ { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER },
+ { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER },
{ CA_OWNERME, "OWNERME", CHAN_LEVEL_OWNERME },
{ CA_FOUNDER, "FOUNDER", CHAN_LEVEL_FOUNDER },
{ -1 }
@@ -117,43 +117,38 @@ void moduleAddChanServCmds()
/* Returns modes for mlock in a nice way. */
-char *get_mlock_modes(ChannelInfo *ci, int complete)
+Anope::string get_mlock_modes(ChannelInfo *ci, int complete)
{
- static char res[BUFSIZE];
- char *end, *value;
ChannelMode *cm;
ChannelModeParam *cmp;
std::map<char, ChannelMode *>::iterator it, it_end;
- std::string param;
-
- memset(&res, '\0', sizeof(res));
- end = res;
+ Anope::string res, param;
if (ci->GetMLockCount(true) || ci->GetMLockCount(false))
{
if (ci->GetMLockCount(true))
{
- *end++ = '+';
+ res += '+';
for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
{
cm = it->second;
if (ci->HasMLock(cm->Name, true))
- *end++ = it->first;
+ res += it->first;
}
}
if (ci->GetMLockCount(false))
{
- *end++ = '-';
+ res += '-';
for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it)
{
cm = it->second;
if (ci->HasMLock(cm->Name, false))
- *end++ = it->first;
+ res += it->first;
}
}
@@ -170,13 +165,7 @@ char *get_mlock_modes(ChannelInfo *ci, int complete)
ci->GetParam(cmp->Name, param);
if (!param.empty())
- {
- value = const_cast<char *>(param.c_str());
-
- *end++ = ' ';
- while (*value)
- *end++ = *value++;
- }
+ res += " " + param;
}
}
}
@@ -192,7 +181,7 @@ char *get_mlock_modes(ChannelInfo *ci, int complete)
void get_chanserv_stats(long *nrec, long *memuse)
{
long count = 0, mem = 0;
- std::string param;
+ Anope::string param;
for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
{
@@ -200,8 +189,8 @@ void get_chanserv_stats(long *nrec, long *memuse)
++count;
mem += sizeof(*ci);
- if (ci->desc)
- mem += strlen(ci->desc) + 1;
+ if (!ci->desc.empty())
+ mem += ci->desc.length() + 1;
mem += ci->GetAccessCount() * sizeof(ChanAccess);
mem += ci->GetAkickCount() * sizeof(AutoKick);
@@ -214,21 +203,21 @@ void get_chanserv_stats(long *nrec, long *memuse)
if (ci->GetParam(CMODE_REDIRECT, param))
mem += param.length() + 1;
- if (ci->last_topic)
- mem += strlen(ci->last_topic) + 1;
- if (ci->entry_message)
- mem += strlen(ci->entry_message) + 1;
- if (ci->forbidby)
- mem += strlen(ci->forbidby) + 1;
- if (ci->forbidreason)
- mem += strlen(ci->forbidreason) + 1;
+ if (!ci->last_topic.empty())
+ mem += ci->last_topic.length() + 1;
+ if (!ci->entry_message.empty())
+ mem += ci->entry_message.length() + 1;
+ if (!ci->forbidby.empty())
+ mem += ci->forbidby.length() + 1;
+ if (!ci->forbidreason.empty())
+ mem += ci->forbidreason.length() + 1;
if (ci->levels)
mem += sizeof(*ci->levels) * CA_SIZE;
unsigned memos = ci->memos.memos.size();
mem += memos * sizeof(Memo);
for (unsigned j = 0; j < memos; ++j)
- if (ci->memos.memos[j]->text)
- mem += strlen(ci->memos.memos[j]->text) + 1;
+ if (!ci->memos.memos[j]->text.empty())
+ mem += ci->memos.memos[j]->text.length() + 1;
if (ci->ttb)
mem += sizeof(*ci->ttb) * TTB_SIZE;
mem += ci->GetBadWordCount() * sizeof(BadWord);
@@ -251,17 +240,17 @@ void cs_init()
/* Main ChanServ routine. */
-void chanserv(User *u, const std::string &buf)
+void chanserv(User *u, const Anope::string &buf)
{
if (!u || 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(ChanServ, u->nick.c_str(), "%s", command.c_str());
+ ircdproto->SendCTCP(ChanServ, u->nick, "%s", command.c_str());
}
else
mod_run_cmd(ChanServ, u, buf);
@@ -279,7 +268,7 @@ void check_modes(Channel *c)
ChannelInfo *ci;
ChannelMode *cm;
std::map<char, ChannelMode *>::iterator it, it_end;
- std::string param, ciparam;
+ Anope::string param, ciparam;
if (!c)
{
@@ -326,8 +315,8 @@ void check_modes(Channel *c)
/* Add the eventual parameter and modify the Channel structure */
if (cm->Type == MODE_PARAM)
{
- if (ci->GetParam(cm->Name, param))
- c->SetMode(NULL, cm, param);
+ if (ci->GetParam(cm->Name, ciparam))
+ c->SetMode(NULL, cm, ciparam);
}
else
c->SetMode(NULL, cm);
@@ -339,7 +328,7 @@ void check_modes(Channel *c)
ci->GetParam(cm->Name, ciparam);
/* If the channel doesnt have the mode, or it does and it isn't set correctly */
- if (!c->HasMode(cm->Name) || (!param.empty() && !ciparam.empty() && param != ciparam))
+ if (!c->HasMode(cm->Name) || (!param.empty() && !ciparam.empty() && !param.equals_cs(ciparam)))
c->SetMode(NULL, cm, ciparam);
}
}
@@ -386,7 +375,7 @@ int check_valid_admin(User *user, Channel *chan, int servermode)
if (servermode && !check_access(user, chan->ci, CA_AUTOPROTECT))
{
- notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ);
+ notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ.c_str());
chan->RemoveMode(NULL, CMODE_PROTECT, user->nick);
return 0;
}
@@ -422,7 +411,7 @@ int check_valid_op(User *user, Channel *chan, int servermode)
if (servermode && !check_access(user, chan->ci, CA_AUTOOP))
{
- notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ);
+ notice_lang(Config.s_ChanServ, user, CHAN_IS_REGISTERED, Config.s_ChanServ.c_str());
if (owner)
chan->RemoveMode(NULL, CMODE_OWNER, user->nick);
@@ -456,7 +445,7 @@ int check_valid_op(User *user, Channel *chan, int servermode)
/* Record the current channel topic in the ChannelInfo structure. */
-void record_topic(const char *chan)
+void record_topic(const Anope::string &chan)
{
Channel *c;
ChannelInfo *ci;
@@ -468,14 +457,7 @@ void record_topic(const char *chan)
if (!c || !(ci = c->ci))
return;
- if (ci->last_topic)
- delete [] ci->last_topic;
-
- if (c->topic)
- ci->last_topic = sstrdup(c->topic);
- else
- ci->last_topic = NULL;
-
+ ci->last_topic = c->topic;
ci->last_topic_setter = c->topic_setter;
ci->last_topic_time = c->topic_time;
}
@@ -484,7 +466,7 @@ void record_topic(const char *chan)
/* Restore the topic in a channel when it's created, if we should. */
-void restore_topic(const char *chan)
+void restore_topic(const Anope::string &chan)
{
Channel *c = findchan(chan);
ChannelInfo *ci;
@@ -493,27 +475,25 @@ void restore_topic(const char *chan)
return;
/* We can be sure that the topic will be in sync when we return -GD */
c->topic_sync = 1;
- if (!(ci->HasFlag(CI_KEEPTOPIC)))
+ if (!ci->HasFlag(CI_KEEPTOPIC))
{
/* We need to reset the topic here, since it's currently empty and
* should be updated with a TOPIC from the IRCd soon. -GD
*/
- ci->last_topic = NULL;
+ ci->last_topic.clear();
ci->last_topic_setter = whosends(ci)->nick;
ci->last_topic_time = time(NULL);
return;
}
- if (c->topic)
- delete [] c->topic;
- if (ci->last_topic)
+ if (!ci->last_topic.empty())
{
- c->topic = sstrdup(ci->last_topic);
+ c->topic = ci->last_topic;
c->topic_setter = ci->last_topic_setter;
c->topic_time = ci->last_topic_time;
}
else
{
- c->topic = NULL;
+ c->topic.clear();
c->topic_setter = whosends(ci)->nick;
}
if (ircd->join2set && whosends(ci) == ChanServ)
@@ -521,7 +501,7 @@ void restore_topic(const char *chan)
ChanServ->Join(chan);
c->SetMode(NULL, CMODE_OP, Config.s_ChanServ);
}
- ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : "");
+ ircdproto->SendTopic(whosends(ci), c, c->topic_setter, c->topic);
if (ircd->join2set && whosends(ci) == ChanServ)
ChanServ->Part(c);
}
@@ -544,16 +524,14 @@ int check_topiclock(Channel *c, time_t topic_time)
if (!(ci = c->ci) || !ci->HasFlag(CI_TOPICLOCK))
return 0;
- if (c->topic)
- delete [] c->topic;
- if (ci->last_topic)
+ if (!ci->last_topic.empty())
{
- c->topic = sstrdup(ci->last_topic);
+ c->topic = ci->last_topic;
c->topic_setter = ci->last_topic_setter;
}
else
{
- c->topic = NULL;
+ c->topic.clear();
/* Bot assigned & Symbiosis ON?, the bot will set the topic - doc */
/* Altough whosends() also checks for Config.BSMinUsers -GD */
c->topic_setter = whosends(ci)->nick;
@@ -571,7 +549,7 @@ int check_topiclock(Channel *c, time_t topic_time)
else
{
/* If no last topic, we can't use last topic time! - doc */
- if (ci->last_topic)
+ if (!ci->last_topic.empty())
c->topic_time = ci->last_topic_time;
else
c->topic_time = time(NULL) + 1;
@@ -583,7 +561,7 @@ int check_topiclock(Channel *c, time_t topic_time)
c->SetMode(NULL, CMODE_OP, Config.s_ChanServ);
}
- ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : "");
+ ircdproto->SendTopic(whosends(ci), c, c->topic_setter, c->topic);
if (ircd->join2set && whosends(ci) == ChanServ)
ChanServ->Part(c);
@@ -613,11 +591,10 @@ void expire_chans()
if (MOD_RESULT == EVENT_STOP)
continue;
- char *chname = sstrdup(ci->name.c_str());
+ Anope::string chname = ci->name;
Alog() << "Expiring channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << " )";
delete ci;
FOREACH_MOD(I_OnChanExpire, OnChanExpire(chname));
- delete [] chname;
}
}
}
@@ -651,7 +628,7 @@ void cs_remove_nick(const NickCore *nc)
Alog() << Config.s_ChanServ << ": Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to successor " << nc2->display;
ci->founder = nc2;
ci->successor = NULL;
- nc2->channelcount++;
+ ++nc2->channelcount;
}
}
else
@@ -692,17 +669,7 @@ void cs_remove_nick(const NickCore *nc)
/*************************************************************************/
-ChannelInfo *cs_findchan(const char *chan)
-{
- return cs_findchan(ci::string(chan));
-}
-
-ChannelInfo *cs_findchan(const std::string &chan)
-{
- return cs_findchan(ci::string(chan.c_str()));
-}
-
-ChannelInfo *cs_findchan(const ci::string &chan)
+ChannelInfo *cs_findchan(const Anope::string &chan)
{
registered_channel_map::const_iterator it = RegisteredChannelList.find(chan);
@@ -744,7 +711,7 @@ int check_access(User *user, ChannelInfo *ci, int what)
return what == CA_AUTODEOP || what == CA_NOJOIN ? 0 : 1;
/* Hacks to make flags work */
- if (what == CA_AUTODEOP && (ci->HasFlag(CI_SECUREOPS)) && !level)
+ if (what == CA_AUTODEOP && ci->HasFlag(CI_SECUREOPS) && !level)
return 1;
if (what == CA_AUTODEOP || what == CA_NOJOIN)
@@ -829,7 +796,7 @@ int get_access(User *user, ChannelInfo *ci)
NickAlias *na = findnick(user->nick);
if (na)
access = ci->GetAccess(na->nc);
- if (access && user->IsRecognized() && !(ci->HasFlag(CI_SECURE)))
+ if (access && user->IsRecognized() && !ci->HasFlag(CI_SECURE))
return access->level;
}
@@ -855,34 +822,33 @@ void update_cs_lastseen(User *user, ChannelInfo *ci)
/* Returns the best ban possible for an user depending of the bantype
value. */
-int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen)
+int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret)
{
- char *mask;
+ Anope::string mask;
- if (!ci || !u || !ret || retlen == 0)
+ if (!ci || !u)
return 0;
- std::string vident = u->GetIdent();
+ Anope::string vident = u->GetIdent();
switch (ci->bantype)
{
case 0:
- snprintf(ret, retlen, "*!%s@%s", vident.c_str(), u->GetDisplayedHost().c_str());
+ ret = "*!" + vident + "@" + u->GetDisplayedHost();
return 1;
case 1:
if (vident[0] == '~')
- snprintf(ret, retlen, "*!*%s@%s", vident.c_str(), u->GetDisplayedHost().c_str());
+ ret = "*!*" + vident + "@" + u->GetDisplayedHost();
else
- snprintf(ret, retlen, "*!%s@%s", vident.c_str(), u->GetDisplayedHost().c_str());
+ ret = "*!" + vident + "@" + u->GetDisplayedHost();
return 1;
case 2:
- snprintf(ret, retlen, "*!*@%s", u->GetDisplayedHost().c_str());
+ ret = "*!*@" + u->GetDisplayedHost();
return 1;
case 3:
mask = create_mask(u);
- snprintf(ret, retlen, "*!%s", mask);
- delete [] mask;
+ ret = "*!" + mask;
return 1;
default:
@@ -892,17 +858,15 @@ int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen)
/*************************************************************************/
-int get_access_level(ChannelInfo *ci, NickAlias *na)
+int get_access_level(ChannelInfo *ci, NickCore *nc)
{
- ChanAccess *access;
-
- if (!ci || !na)
+ if (!ci || !nc)
return 0;
- if (na->nc == ci->founder)
+ if (nc == ci->founder)
return ACCESS_FOUNDER;
- access = ci->GetAccess(na->nc);
+ ChanAccess *access = ci->GetAccess(nc);
if (!access)
return 0;
@@ -910,23 +874,15 @@ int get_access_level(ChannelInfo *ci, NickAlias *na)
return access->level;
}
-int get_access_level(ChannelInfo *ci, NickCore *nc)
+int get_access_level(ChannelInfo *ci, NickAlias *na)
{
- if (!ci || !nc)
+ if (!na)
return 0;
- if (nc == ci->founder)
- return ACCESS_FOUNDER;
-
- ChanAccess *access = ci->GetAccess(nc);
-
- if (!access)
- return 0;
- else
- return access->level;
+ return get_access_level(ci, na->nc);
}
-const char *get_xop_level(int level)
+Anope::string get_xop_level(int level)
{
ChannelMode *halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP);
@@ -954,7 +910,7 @@ const char *get_xop_level(int level)
/* Is the mask stuck? */
-AutoKick *is_stuck(ChannelInfo * ci, const char *mask)
+AutoKick *is_stuck(ChannelInfo *ci, const Anope::string &mask)
{
if (!ci)
return NULL;
@@ -966,11 +922,11 @@ AutoKick *is_stuck(ChannelInfo * ci, const char *mask)
if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK))
continue;
- if (Anope::Match(akick->mask, mask, false))
+ if (Anope::Match(akick->mask, mask))
return akick;
if (ircd->reversekickcheck)
- if (Anope::Match(mask, akick->mask, false))
+ if (Anope::Match(mask, akick->mask))
return akick;
}
@@ -992,21 +948,21 @@ void stick_mask(ChannelInfo *ci, AutoKick *akick)
{
/* If akick is already covered by a wider ban.
Example: c->bans[i] = *!*@*.org and akick->u.mask = *!*@*.epona.org */
- if (entry_match_mask(ban, akick->mask.c_str(), 0))
+ if (entry_match_mask(ban, akick->mask, 0))
return;
if (ircd->reversekickcheck)
{
/* If akick is wider than a ban already in place.
Example: c->bans[i] = *!*@irc.epona.org and akick->u.mask = *!*@*.epona.org */
- if (Anope::Match(ban->mask, akick->mask.c_str(), false))
+ if (Anope::Match(ban->mask, akick->mask))
return;
}
}
}
/* Falling there means set the ban */
- ci->c->SetMode(NULL, CMODE_BAN, akick->mask.c_str());
+ ci->c->SetMode(NULL, CMODE_BAN, akick->mask);
}
/* Ban the stuck mask in a safe manner. */
@@ -1023,7 +979,7 @@ void stick_all(ChannelInfo *ci)
if (akick->HasFlag(AK_ISNICK) || !akick->HasFlag(AK_STUCK))
continue;
- ci->c->SetMode(NULL, CMODE_BAN, akick->mask.c_str());
+ ci->c->SetMode(NULL, CMODE_BAN, akick->mask);
}
}
diff --git a/src/command.cpp b/src/command.cpp
index 5c4bc4ee4..de9842d78 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -8,7 +8,7 @@
#include "services.h"
#include "modules.h"
-Command::Command(const ci::string &sname, size_t min_params, size_t max_params, const ci::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission)
+Command::Command(const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission)
{
this->module = NULL;
this->service = NULL;
@@ -18,20 +18,18 @@ Command::~Command()
{
}
-CommandReturn Command::Execute(User *u, const std::vector<ci::string> &)
+CommandReturn Command::Execute(User *u, const std::vector<Anope::string> &)
{
return MOD_CONT;
}
void Command::OnServHelp(User *u) { }
-bool Command::OnHelp(User *u, const ci::string &subcommand) { return false; }
+bool Command::OnHelp(User *u, const Anope::string &subcommand) { return false; }
-void Command::OnSyntaxError(User *u, const ci::string &subcommand)
-{
-}
+void Command::OnSyntaxError(User *u, const Anope::string &subcommand) { }
-void Command::SetPermission(const ci::string &reststr)
+void Command::SetPermission(const Anope::string &reststr)
{
this->permission = reststr;
}
@@ -41,7 +39,7 @@ bool Command::AddSubcommand(Command *c)
return false;
}
-bool Command::DelSubcommand(const ci::string &cname)
+bool Command::DelSubcommand(const Anope::string &cname)
{
return false;
}
diff --git a/src/commands.cpp b/src/commands.cpp
index ebe189fd4..2647ea952 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -14,12 +14,12 @@
#include "language.h"
#include "hashcomp.h"
-Command *FindCommand(BotInfo *bi, const ci::string &name)
+Command *FindCommand(BotInfo *bi, const Anope::string &name)
{
if (!bi || bi->Commands.empty() || name.empty())
return NULL;
- std::map<ci::string, Command *>::iterator it = bi->Commands.find(name);
+ CommandMap::iterator it = bi->Commands.find(name);
if (it != bi->Commands.end())
return it->second;
@@ -27,16 +27,16 @@ Command *FindCommand(BotInfo *bi, const ci::string &name)
return NULL;
}
-void mod_run_cmd(BotInfo *bi, User *u, const std::string &message)
+void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message)
{
- spacesepstream sep(ci::string(message.c_str()));
- ci::string cmd;
+ spacesepstream sep(message);
+ Anope::string cmd;
if (sep.GetToken(cmd))
- mod_run_cmd(bi, u, FindCommand(bi, cmd), cmd, sep.GetRemaining().c_str());
+ mod_run_cmd(bi, u, FindCommand(bi, cmd), cmd, sep.GetRemaining());
}
-void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, const ci::string &message)
+void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message)
{
if (!bi || !u)
return;
@@ -57,22 +57,19 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co
// Command requires registered users only
if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified())
{
- notice_lang(bi->nick, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ);
+ notice_lang(bi->nick, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str());
Alog() << "Access denied for unregistered user " << u->nick << " with service " << bi->nick << " and command " << command;
return;
}
- std::vector<ci::string> params;
- ci::string curparam, endparam;
+ std::vector<Anope::string> params;
+ Anope::string curparam, endparam;
spacesepstream sep(message);
while (sep.GetToken(curparam))
{
// - 1 because params[0] corresponds with a maxparam of 1.
- if (params.size() >= (c->MaxParams - 1))
- {
- endparam += curparam;
- endparam += " ";
- }
+ if (params.size() >= c->MaxParams - 1)
+ endparam += curparam + " ";
else
params.push_back(curparam);
}
@@ -80,7 +77,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co
if (!endparam.empty())
{
// Remove trailing space
- endparam.erase(endparam.size() - 1, endparam.size());
+ endparam.erase(endparam.length() - 1);
// Add it
params.push_back(endparam);
@@ -98,7 +95,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co
if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ))
{
- if (ircdproto->IsChannelValid(params[0].c_str()))
+ if (ircdproto->IsChannelValid(params[0]))
{
ChannelInfo *ci = cs_findchan(params[0]);
if (ci)
@@ -142,7 +139,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co
if (ret == MOD_CONT)
{
- FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name.c_str(), params));
+ FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name, params));
}
}
@@ -154,18 +151,18 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const ci::string &command, co
* @param cmd Command
* @return void
*/
-void mod_help_cmd(BotInfo *bi, User *u, const ci::string &cmd)
+void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd)
{
if (!bi || !u || cmd.empty())
return;
spacesepstream tokens(cmd);
- ci::string token;
+ Anope::string token;
tokens.GetToken(token);
Command *c = FindCommand(bi, token);
- ci::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining().c_str();
+ Anope::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining();
if (!c || (Config.HidePrivilegedCommands && !c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) || !c->OnHelp(u, subcommand))
notice_lang(bi->nick, u, NO_HELP_AVAILABLE, cmd.c_str());
diff --git a/src/compat.cpp b/src/compat.cpp
deleted file mode 100644
index 2fdb57b86..000000000
--- a/src/compat.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Compatibility routines.
- *
- * (C) 2003-2010 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "services.h"
-
-/*************************************************************************/
-
-#if !HAVE_STRICMP && !HAVE_STRCASECMP
-
-/* stricmp, strnicmp: Case-insensitive versions of strcmp() and
- * strncmp().
- */
-
-int stricmp(const char *s1, const char *s2)
-{
- register int c;
-
- while ((c = tolower(*s1)) == tolower(*s2))
- {
- if (!c)
- return 0;
- ++s1;
- ++s2;
- }
- if (c < tolower(*s2))
- return -1;
- return 1;
-}
-
-int strnicmp(const char *s1, const char *s2, size_t len)
-{
- register int c;
-
- if (!len)
- return 0;
- while ((c = tolower(*s1)) == tolower(*s2) && len > 0)
- {
- if (!c || !--len)
- return 0;
- ++s1;
- ++s2;
- }
- if (c < tolower(*s2))
- return -1;
- return 1;
-}
-
-#endif
-
-/*************************************************************************/
diff --git a/src/config.cpp b/src/config.cpp
index 61f9d586f..c9dcf426a 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -15,29 +15,28 @@
/*************************************************************************/
-ci::string services_conf = "services.conf"; // Services configuration file name
+Anope::string services_conf = "services.conf"; // Services configuration file name
ServerConfig Config;
-static ci::string Modules;
-static ci::string EncModules;
-static ci::string DBModules;
-static ci::string SocketEngineModule;
-static ci::string HostCoreModules;
-static ci::string MemoCoreModules;
-static ci::string BotCoreModules;
-static ci::string OperCoreModules;
-static ci::string NickCoreModules;
-static ci::string ChanCoreModules;
-static ci::string DefCon1;
-static ci::string DefCon2;
-static ci::string DefCon3;
-static ci::string DefCon4;
-static char *UlineServers;
-static ci::string OSNotifications;
-static ci::string BSDefaults;
-static ci::string CSDefaults;
-static char *temp_nsuserhost;
-static ci::string NSDefaults;
+static Anope::string Modules;
+static Anope::string EncModules;
+static Anope::string DBModules;
+static Anope::string HostCoreModules;
+static Anope::string MemoCoreModules;
+static Anope::string BotCoreModules;
+static Anope::string OperCoreModules;
+static Anope::string NickCoreModules;
+static Anope::string ChanCoreModules;
+static Anope::string DefCon1;
+static Anope::string DefCon2;
+static Anope::string DefCon3;
+static Anope::string DefCon4;
+static Anope::string UlineServers;
+static Anope::string OSNotifications;
+static Anope::string BSDefaults;
+static Anope::string CSDefaults;
+static Anope::string temp_nsuserhost;
+static Anope::string NSDefaults;
/*************************************************************************/
@@ -51,48 +50,43 @@ void ServerConfig::ClearStack()
include_stack.clear();
}
-bool ServerConfig::CheckOnce(const char *tag)
+bool ServerConfig::CheckOnce(const Anope::string &tag)
{
int count = ConfValueEnum(config_data, tag);
if (count > 1)
- throw ConfigException(std::string("You have more than one <") + tag + "> tag, this is not permitted.");
+ throw ConfigException("You have more than one <" + tag + "> tag, this is not permitted.");
if (count < 1)
- throw ConfigException(std::string("You have not defined a <") + tag + "> tag, this is required.");
+ throw ConfigException("You have not defined a <" + tag + "> tag, this is required.");
return true;
}
-bool NoValidation(ServerConfig *, const char *, const char *, ValueItem &)
+bool NoValidation(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &)
{
return true;
}
-bool DoneConfItem(ServerConfig *, const char *)
+void ServerConfig::ValidateNoSpaces(const Anope::string &p, const Anope::string &tag, const Anope::string &val)
{
- return true;
-}
-
-void ServerConfig::ValidateNoSpaces(const char *p, const ci::string &tag, const ci::string &val)
-{
- for (const char *ptr = p; *ptr; ++ptr)
+ for (Anope::string::const_iterator ptr = p.begin(), end = p.end(); ptr != end; ++ptr)
if (*ptr == ' ')
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> cannot contain spaces");
+ throw ConfigException("The value of <" + tag + ":" + val + "> cannot contain spaces");
}
/* NOTE: Before anyone asks why we're not using inet_pton for this, it is because inet_pton and friends do not return so much detail,
* even in strerror(errno). They just return 'yes' or 'no' to an address without such detail as to whats WRONG with the address.
* Because ircd users arent as technical as they used to be (;)) we are going to give more of a useful error message.
*/
-void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::string &val, bool wild)
+void ServerConfig::ValidateIP(const Anope::string &p, const Anope::string &tag, const Anope::string &val, bool wild)
{
int num_dots = 0, num_seps = 0;
bool not_numbers = false, not_hex = false;
- if (*p)
+ if (!p.empty())
{
- if (*p == '.')
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not an IP address");
+ if (p[0] == '.')
+ throw ConfigException("The value of <" + tag + ":" + val + "> is not an IP address");
- for (const char *ptr = p; *ptr; ++ptr)
+ for (Anope::string::const_iterator ptr = p.begin(), end = p.end(); ptr != end; ++ptr)
{
if (wild && (*ptr == '*' || *ptr == '?' || *ptr == '/'))
continue;
@@ -106,7 +100,7 @@ void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::st
switch (*ptr)
{
case ' ':
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not an IP address");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is not an IP address");
case '.':
++num_dots;
break;
@@ -115,41 +109,41 @@ void ServerConfig::ValidateIP(const char *p, const ci::string &tag, const ci::st
}
}
if (num_dots > 3)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is an IPv4 address with too many fields!");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is an IPv4 address with too many fields!");
if (num_seps > 8)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is an IPv6 address with too many fields!");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is an IPv6 address with too many fields!");
if (!num_seps && num_dots < 3 && !wild)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> looks to be a malformed IPv4 address");
+ throw ConfigException("The value of <" + tag + ":" + val + "> looks to be a malformed IPv4 address");
if (!num_seps && num_dots == 3 && not_numbers)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> contains non-numeric characters in an IPv4 address");
+ throw ConfigException("The value of <" + tag + ":" + val + "> contains non-numeric characters in an IPv4 address");
if (num_seps && not_hex)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> contains non-hexdecimal characters in an IPv6 address");
+ throw ConfigException("The value of <" + tag + ":" + val + "> contains non-hexdecimal characters in an IPv6 address");
if (num_seps && num_dots != 3 && num_dots && !wild)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is a malformed IPv6 4in6 address");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is a malformed IPv6 4in6 address");
}
}
-void ServerConfig::ValidateHostname(const char *p, const ci::string &tag, const ci::string &val)
+void ServerConfig::ValidateHostname(const Anope::string &p, const Anope::string &tag, const Anope::string &val)
{
- if (!strcasecmp(p, "localhost"))
+ if (p.equals_ci("localhost"))
return;
int num_dots = 0, num_seps = 0;
- if (*p)
+ if (!p.empty())
{
- if (*p == '.')
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname");
- for (const char *ptr = p; *ptr; ++ptr)
+ if (p[0] == '.')
+ throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname");
+ for (unsigned i = 0, end = p.length(); i < end; ++i)
{
- switch (*ptr)
+ switch (p[i])
{
case ' ':
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname");
case '.':
++num_dots;
break;
@@ -159,72 +153,70 @@ void ServerConfig::ValidateHostname(const char *p, const ci::string &tag, const
}
}
if (!num_dots && !num_seps)
- throw ConfigException(ci::string("The value of <") + tag + ":" + val + "> is not a valid hostname");
+ throw ConfigException("The value of <" + tag + ":" + val + "> is not a valid hostname");
}
}
-bool ValidateNotEmpty(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateNotEmpty(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
if (data.GetValue().empty())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty!");
return true;
}
-bool ValidateNotZero(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateNotZero(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!data.GetInteger())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero!");
+ if (!data.GetInteger() && !dotime(data.GetValue()))
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero!");
return true;
}
-bool ValidateEmailReg(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateEmailReg(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
if (Config.NSEmailReg)
{
- if (ci::string(value) == "preregexpire")
+ if (value.equals_ci("preregexpire"))
{
if (!data.GetInteger())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when e-mail registration are enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when e-mail registration are enabled!");
}
else
{
if (!data.GetBool())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be set to yes when e-mail registrations are enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be set to yes when e-mail registrations are enabled!");
}
}
return true;
}
-bool ValidatePort(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidatePort(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
int port = data.GetInteger();
if (!port)
return true;
if (port < 1 || port > 65535)
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> is not a value port, it must be between 1 and 65535!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> is not a value port, it must be between 1 and 65535!");
return true;
}
-bool ValidateLanguage(ServerConfig *, const char *, const char *, ValueItem &data)
+bool ValidateLanguage(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data)
{
int language = data.GetInteger();
- char maxlang[3];
- snprintf(maxlang, 3, "%d", USED_LANGS);
if (language < 1 || language > USED_LANGS)
- throw ConfigException(std::string("The value for <nickserv:defaultlanguage> must be between 1 and ") + maxlang + "!");
+ throw ConfigException("The value for <nickserv:defaultlanguage> must be between 1 and " + stringify(USED_LANGS) + "!");
data.Set(--language);
return true;
}
-bool ValidateGuestPrefix(ServerConfig *conf, const char *tag, const char *value, ValueItem &data)
+bool ValidateGuestPrefix(ServerConfig *conf, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
ValidateNotEmpty(conf, tag, value, data);
- if (data.GetValue().size() > 21)
+ if (data.GetValue().length() > 21)
throw ConfigException("The value for <nickserv:guestnickprefix> cannot exceed 21 characters in length!");
return true;
}
-bool ValidateBantype(ServerConfig *, const char *, const char *, ValueItem &data)
+bool ValidateBantype(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data)
{
int bantype = data.GetInteger();
if (bantype < 0 || bantype > 3)
@@ -232,53 +224,53 @@ bool ValidateBantype(ServerConfig *, const char *, const char *, ValueItem &data
return true;
}
-bool ValidateBotServ(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateBotServ(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (Config.s_BotServ)
+ if (!Config.s_BotServ.empty())
{
- if (ci::string(value) == "description")
+ if (value.equals_ci("description"))
{
if (data.GetValue().empty())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when BotServ is enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when BotServ is enabled!");
}
- else if (ci::string(value) == "minusers" || ci::string(value) == "badwordsmax" || ci::string(value) == "keepdata")
+ else if (value.equals_ci("minusers") || value.equals_ci("badwordsmax") || value.equals_ci("keepdata"))
{
- if (!data.GetInteger())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when BotServ is enabled!");
+ if (!data.GetInteger() && !dotime(data.GetValue()))
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when BotServ is enabled!");
}
}
return true;
}
-bool ValidateHostServ(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateHostServ(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (Config.s_HostServ)
+ if (!Config.s_HostServ.empty())
{
- if (ci::string(value) == "description")
+ if (value.equals_ci("description"))
{
if (data.GetValue().empty())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when HostServ is enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when HostServ is enabled!");
}
}
return true;
}
-bool ValidateLimitSessions(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateLimitSessions(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
if (Config.LimitSessions)
{
- if (ci::string(value) == "maxsessionlimit" || ci::string(value) == "exceptionexpiry")
+ if (value.equals_ci("maxsessionlimit") || value.equals_ci("exceptionexpiry"))
{
- if (!data.GetInteger())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when session limiting is enabled!");
+ if (!data.GetInteger() && !dotime(data.GetValue()))
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when session limiting is enabled!");
}
}
return true;
}
-bool ValidateDefCon(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateDefCon(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (ci::string(value) == "defaultlevel")
+ if (value.equals_ci("defaultlevel"))
{
int level = data.GetInteger();
if (!level)
@@ -288,26 +280,26 @@ bool ValidateDefCon(ServerConfig *, const char *tag, const char *value, ValueIte
}
else if (Config.DefConLevel)
{
- if ((ci::string(value).substr(0, 5) == "level" && isdigit(value[5])) || ci::string(value) == "chanmodes" || ci::string(value) == "akillreason")
+ if ((value.substr(0, 5).equals_ci("level") && isdigit(value[5])) || value.equals_ci("chanmodes") || value.equals_ci("akillreason"))
{
if (data.GetValue().empty())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when DefCon is enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when DefCon is enabled!");
}
- else if (ci::string(value) == "message" && Config.GlobalOnDefconMore)
+ else if (value.equals_ci("message") && Config.GlobalOnDefconMore)
{
if (data.GetValue().empty())
throw ConfigException("The value for <defcon:message> cannot be empty when globalondefconmore is enabled!");
}
- else if (ci::string(value) == "sessionlimit" || ci::string(value) == "akillexpire")
+ else if (value.equals_ci("sessionlimit") || value.equals_ci("akillexpire"))
{
- if (!data.GetInteger())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> must be non-zero when DefCon is enabled!");
+ if (!data.GetInteger() && !dotime(data.GetValue()))
+ throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when DefCon is enabled!");
}
}
return true;
}
-bool ValidateNickLen(ServerConfig *, const char *, const char *, ValueItem &data)
+bool ValidateNickLen(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data)
{
int nicklen = data.GetInteger();
if (!nicklen)
@@ -324,20 +316,20 @@ bool ValidateNickLen(ServerConfig *, const char *, const char *, ValueItem &data
return true;
}
-bool ValidateMail(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateMail(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
if (Config.UseMail)
{
- if (ci::string(value) == "sendmailpath" || ci::string(value) == "sendfrom")
+ if (value.equals_ci("sendmailpath") || value.equals_ci("sendfrom"))
{
if (data.GetValue().empty())
- throw ConfigException(std::string("The value for <") + tag + ":" + value + "> cannot be empty when e-mail is enabled!");
+ throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when e-mail is enabled!");
}
}
return true;
}
-bool ValidateGlobalOnCycle(ServerConfig *, const char *tag, const char *value, ValueItem &data)
+bool ValidateGlobalOnCycle(ServerConfig *, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
if (Config.GlobalOnCycle)
{
@@ -350,7 +342,7 @@ bool ValidateGlobalOnCycle(ServerConfig *, const char *tag, const char *value, V
return true;
}
-void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail)
+void ServerConfig::ReportConfigError(const Anope::string &errormessage, bool bail)
{
Alog() << "There were errors in your configuration file: " << errormessage;
if (bail)
@@ -360,7 +352,7 @@ void ServerConfig::ReportConfigError(const std::string &errormessage, bool bail)
}
}
-bool InitUplinks(ServerConfig *, const char *, bool bail)
+bool InitUplinks(ServerConfig *, const Anope::string &, bool bail)
{
// If bail is false, we were reloading, don't clear anything
if (!bail)
@@ -375,13 +367,13 @@ bool InitUplinks(ServerConfig *, const char *, bool bail)
return true;
}
-bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool bail)
+bool DoUplink(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool bail)
{
// If bail is false, we were reloading, don't even try to add another uplink
if (!bail)
return true;
// Validation variables
- const char *host = values[0].GetString(), *password = values[3].GetString();
+ Anope::string host = values[0].GetValue(), password = values[3].GetValue();
int port = values[2].GetInteger();
bool ipv6 = values[1].GetBool();
ValueItem vi_host(host), vi_port(port), vi_password(password);
@@ -399,7 +391,7 @@ bool DoUplink(ServerConfig *conf, const char *, const char **, ValueList &values
return true;
}
-bool DoneUplinks(ServerConfig *, const char *, bool bail)
+bool DoneUplinks(ServerConfig *, const Anope::string &, bool bail)
{
// If bail is false, we were reloading, ignore this check
if (!bail)
@@ -409,7 +401,7 @@ bool DoneUplinks(ServerConfig *, const char *, bool bail)
return true;
}
-static bool InitOperTypes(ServerConfig *, const char *, bool)
+static bool InitOperTypes(ServerConfig *, const Anope::string &, bool)
{
for (std::list<OperType *>::iterator it = Config.MyOperTypes.begin(), it_end = Config.MyOperTypes.end(); it != it_end; ++it)
delete *it;
@@ -418,12 +410,12 @@ static bool InitOperTypes(ServerConfig *, const char *, bool)
return true;
}
-static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool)
+static bool DoOperType(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool)
{
- const char *name = values[0].GetString();
- const char *inherits = values[1].GetString();
- const char *commands = values[2].GetString();
- const char *privs = values[3].GetString();
+ Anope::string name = values[0].GetValue();
+ Anope::string inherits = values[1].GetValue();
+ Anope::string commands = values[2].GetValue();
+ Anope::string privs = values[3].GetValue();
ValueItem vi(name);
if (!ValidateNotEmpty(conf, "opertype", "name", vi))
@@ -431,7 +423,7 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis
OperType *ot = new OperType(name);
- ci::string tok;
+ Anope::string tok;
spacesepstream cmdstr(commands);
while (cmdstr.GetToken(tok))
ot->AddCommand(tok);
@@ -444,11 +436,11 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis
while (inheritstr.GetToken(tok))
{
/* Strip leading ' ' after , */
- if (tok.size() > 1 && tok[0] == ' ')
+ if (tok.length() > 1 && tok[0] == ' ')
tok.erase(tok.begin());
for (std::list<OperType *>::iterator it = Config.MyOperTypes.begin(), it_end = Config.MyOperTypes.end(); it != it_end; ++it)
{
- if ((*it)->GetName() == tok)
+ if ((*it)->GetName().equals_ci(tok))
{
Alog() << "Inheriting commands and privs from " << (*it)->GetName() << " to " << ot->GetName();
ot->Inherits(*it);
@@ -461,14 +453,14 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis
return true;
}
-static bool DoneOperTypes(ServerConfig *, const char *, bool)
+static bool DoneOperTypes(ServerConfig *, const Anope::string &, bool)
{
return true;
}
/*************************************************************************/
-static bool InitOpers(ServerConfig *, const char *, bool)
+static bool InitOpers(ServerConfig *, const Anope::string &, bool)
{
for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
it->second->ot = NULL;
@@ -478,10 +470,10 @@ static bool InitOpers(ServerConfig *, const char *, bool)
return true;
}
-static bool DoOper(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool)
+static bool DoOper(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool)
{
- const char *name = values[0].GetString();
- const char *type = values[1].GetString();
+ Anope::string name = values[0].GetValue();
+ Anope::string type = values[1].GetValue();
ValueItem vi(name);
if (!ValidateNotEmpty(conf, "oper", "name", vi))
@@ -495,12 +487,11 @@ static bool DoOper(ServerConfig *conf, const char *, const char **, ValueList &v
return true;
}
-static bool DoneOpers(ServerConfig *, const char *, bool)
+static bool DoneOpers(ServerConfig *, const Anope::string &, bool)
{
- // XXX: this is duplicated in config.c
- for (std::list<std::pair<ci::string, ci::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it)
+ for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it)
{
- ci::string nick = it->first, type = it->second;
+ Anope::string nick = it->first, type = it->second;
NickAlias *na = findnick(nick);
if (!na)
@@ -514,7 +505,7 @@ static bool DoneOpers(ServerConfig *, const char *, bool)
for (std::list<OperType *>::iterator tit = Config.MyOperTypes.begin(), tit_end = Config.MyOperTypes.end(); tit != tit_end; ++tit)
{
OperType *ot = *tit;
- if (ot->GetName() == type)
+ if (ot->GetName().equals_ci(type))
{
Alog() << "Tied oper " << na->nc->display << " to type " << type;
na->nc->ot = ot;
@@ -526,16 +517,16 @@ static bool DoneOpers(ServerConfig *, const char *, bool)
/*************************************************************************/
-bool InitModules(ServerConfig *, const char *, bool)
+bool InitModules(ServerConfig *, const Anope::string &, bool)
{
Modules.clear();
return true;
}
-bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool)
+bool DoModule(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *, bool)
{
// First we validate that there was a name in the module block
- const char *module = values[0].GetString();
+ Anope::string module = values[0].GetValue();
ValueItem vi(module);
if (!ValidateNotEmpty(conf, "module", "name", vi))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information.");
@@ -543,11 +534,11 @@ bool DoModule(ServerConfig *conf, const char *, const char **, ValueList &values
if (!Modules.empty())
Modules += " ";
// Add the module name to the string
- Modules += values[0].GetString();
+ Modules += values[0].GetValue();
return true;
}
-bool DoneModules(ServerConfig *, const char *, bool)
+bool DoneModules(ServerConfig *, const Anope::string &, bool)
{
return true;
}
@@ -556,7 +547,7 @@ int ServerConfig::Read(bool bail)
{
errstr.clear();
// These tags MUST occur and must ONLY occur once in the config file
- static const char *Once[] = {"serverinfo", "networkinfo", "options", "nickserv", "chanserv", "memoserv", "operserv", NULL};
+ static const Anope::string Once[] = {"serverinfo", "networkinfo", "options", "nickserv", "chanserv", "memoserv", "operserv", ""};
// These tags can occur ONCE or not at all
InitialConfig Values[] = {
/* The following comments are from CyberBotX to w00t as examples to use:
@@ -612,25 +603,25 @@ int ServerConfig::Read(bool bail)
*
* We may need to add some other validation functions to handle certain things, we can handle that later.
* Any questions about these, w00t, feel free to ask. */
- {"serverinfo", "name", "", new ValueContainerChar(&Config.ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "description", "", new ValueContainerChar(&Config.ServerDesc), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "localhost", "", new ValueContainerChar(&Config.LocalHost), DT_HOSTNAME | DT_NORELOAD, NoValidation},
- {"serverinfo", "type", "", new ValueContainerChar(&Config.IRCDModule), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "id", "", new ValueContainerChar(&Config.Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
- {"serverinfo", "ident", "", new ValueContainerChar(&Config.ServiceUser), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "hostname", "", new ValueContainerChar(&Config.ServiceHost), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "pid", "services.pid", new ValueContainerChar(&Config.PIDFilename), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"serverinfo", "motd", "services.motd", new ValueContainerChar(&Config.MOTDFilename), DT_CHARPTR, ValidateNotEmpty},
- {"networkinfo", "logchannel", "", new ValueContainerChar(&Config.LogChannel), DT_CHARPTR, NoValidation},
+ {"serverinfo", "name", "", new ValueContainerString(&Config.ServerName), DT_HOSTNAME | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "description", "", new ValueContainerString(&Config.ServerDesc), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "localhost", "", new ValueContainerString(&Config.LocalHost), DT_HOSTNAME | DT_NORELOAD, NoValidation},
+ {"serverinfo", "type", "", new ValueContainerString(&Config.IRCDModule), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "id", "", new ValueContainerString(&Config.Numeric), DT_NOSPACES | DT_NORELOAD, NoValidation},
+ {"serverinfo", "ident", "", new ValueContainerString(&Config.ServiceUser), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "hostname", "", new ValueContainerString(&Config.ServiceHost), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "pid", "services.pid", new ValueContainerString(&Config.PIDFilename), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"serverinfo", "motd", "services.motd", new ValueContainerString(&Config.MOTDFilename), DT_STRING, ValidateNotEmpty},
+ {"networkinfo", "logchannel", "", new ValueContainerString(&Config.LogChannel), DT_STRING, NoValidation},
{"networkinfo", "logbot", "no", new ValueContainerBool(&Config.LogBot), DT_BOOLEAN, NoValidation},
- {"networkinfo", "networkname", "", new ValueContainerChar(&Config.NetworkName), DT_CHARPTR, ValidateNotEmpty},
+ {"networkinfo", "networkname", "", new ValueContainerString(&Config.NetworkName), DT_STRING, ValidateNotEmpty},
{"networkinfo", "nicklen", "0", new ValueContainerUInt(&Config.NickLen), DT_UINTEGER | DT_NORELOAD, ValidateNickLen},
{"networkinfo", "userlen", "10", new ValueContainerUInt(&Config.UserLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
{"networkinfo", "hostlen", "64", new ValueContainerUInt(&Config.HostLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
- {"options", "encryption", "", new ValueContainerCIString(&EncModules), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty},
+ {"options", "encryption", "", new ValueContainerString(&EncModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
{"options", "passlen", "32", new ValueContainerUInt(&Config.PassLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
- {"options", "database", "", new ValueContainerCIString(&DBModules), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty},
- {"options", "socketengine", "", new ValueContainerCIString(&Config.SocketEngine), DT_CISTRING | DT_NORELOAD, ValidateNotEmpty},
+ {"options", "database", "", new ValueContainerString(&DBModules), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"options", "socketengine", "", new ValueContainerString(&Config.SocketEngine), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
{"options", "userkey1", "0", new ValueContainerLUInt(&Config.UserKey1), DT_LUINTEGER, NoValidation},
{"options", "userkey2", "0", new ValueContainerLUInt(&Config.UserKey2), DT_LUINTEGER, NoValidation},
{"options", "userkey3", "0", new ValueContainerLUInt(&Config.UserKey3), DT_LUINTEGER, NoValidation},
@@ -652,25 +643,25 @@ int ServerConfig::Read(bool bail)
{"options", "logusers", "no", new ValueContainerBool(&Config.LogUsers), DT_BOOLEAN, NoValidation},
{"options", "hidestatso", "no", new ValueContainerBool(&Config.HideStatsO), DT_BOOLEAN, NoValidation},
{"options", "globaloncycle", "no", new ValueContainerBool(&Config.GlobalOnCycle), DT_BOOLEAN, NoValidation},
- {"options", "globaloncycledown", "", new ValueContainerChar(&Config.GlobalOnCycleMessage), DT_CHARPTR, ValidateGlobalOnCycle},
- {"options", "globaloncycleup", "", new ValueContainerChar(&Config.GlobalOnCycleUP), DT_CHARPTR, ValidateGlobalOnCycle},
+ {"options", "globaloncycledown", "", new ValueContainerString(&Config.GlobalOnCycleMessage), DT_STRING, ValidateGlobalOnCycle},
+ {"options", "globaloncycleup", "", new ValueContainerString(&Config.GlobalOnCycleUP), DT_STRING, ValidateGlobalOnCycle},
{"options", "anonymousglobal", "no", new ValueContainerBool(&Config.AnonymousGlobal), DT_BOOLEAN, NoValidation},
{"options", "nickregdelay", "0", new ValueContainerUInt(&Config.NickRegDelay), DT_UINTEGER, NoValidation},
{"options", "restrictopernicks", "no", new ValueContainerBool(&Config.RestrictOperNicks), DT_BOOLEAN, NoValidation},
{"options", "newscount", "3", new ValueContainerUInt(&Config.NewsCount), DT_UINTEGER, NoValidation},
- {"options", "ulineservers", "", new ValueContainerChar(&UlineServers), DT_CHARPTR, NoValidation},
+ {"options", "ulineservers", "", new ValueContainerString(&UlineServers), DT_STRING, NoValidation},
{"options", "enablelogchannel", "no", new ValueContainerBool(&LogChan), DT_BOOLEAN, NoValidation},
- {"options", "mlock", "+nrt", new ValueContainerCIString(&Config.MLock), DT_CISTRING, NoValidation},
- {"options", "botmodes", "", new ValueContainerCIString(&Config.BotModes), DT_CISTRING, NoValidation},
+ {"options", "mlock", "+nrt", new ValueContainerString(&Config.MLock), DT_STRING, NoValidation},
+ {"options", "botmodes", "", new ValueContainerString(&Config.BotModes), DT_STRING, NoValidation},
{"options", "maxretries", "10", new ValueContainerUInt(&Config.MaxRetries), DT_UINTEGER, NoValidation},
{"options", "retrywait", "60", new ValueContainerInt(&Config.RetryWait), DT_INTEGER, ValidateNotZero},
{"options", "hideprivilegedcommands", "no", new ValueContainerBool(&Config.HidePrivilegedCommands), DT_BOOLEAN, ValidateEmailReg},
- {"nickserv", "nick", "NickServ", new ValueContainerChar(&Config.s_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"nickserv", "description", "Nickname Registration Service", new ValueContainerChar(&Config.desc_NickServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
+ {"nickserv", "nick", "NickServ", new ValueContainerString(&Config.s_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"nickserv", "description", "Nickname Registration Service", new ValueContainerString(&Config.desc_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
{"nickserv", "emailregistration", "no", new ValueContainerBool(&Config.NSEmailReg), DT_BOOLEAN, NoValidation},
- {"nickserv", "modules", "", new ValueContainerCIString(&NickCoreModules), DT_CISTRING, NoValidation},
+ {"nickserv", "modules", "", new ValueContainerString(&NickCoreModules), DT_STRING, NoValidation},
{"nickserv", "forceemail", "no", new ValueContainerBool(&Config.NSForceEmail), DT_BOOLEAN, ValidateEmailReg},
- {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerCIString(&NSDefaults), DT_CISTRING, NoValidation},
+ {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerString(&NSDefaults), DT_STRING, NoValidation},
{"nickserv", "defaultlanguage", "0", new ValueContainerUInt(&Config.NSDefLanguage), DT_UINTEGER, ValidateLanguage},
{"nickserv", "regdelay", "0", new ValueContainerTime(&Config.NSRegDelay), DT_TIME, NoValidation},
{"nickserv", "resenddelay", "0", new ValueContainerTime(&Config.NSResendDelay), DT_TIME, NoValidation},
@@ -678,63 +669,63 @@ int ServerConfig::Read(bool bail)
{"nickserv", "preregexpire", "0", new ValueContainerTime(&Config.NSRExpire), DT_TIME, ValidateEmailReg},
{"nickserv", "maxaliases", "0", new ValueContainerInt(&Config.NSMaxAliases), DT_INTEGER, NoValidation},
{"nickserv", "accessmax", "0", new ValueContainerUInt(&Config.NSAccessMax), DT_UINTEGER, ValidateNotZero},
- {"nickserv", "enforceruser", "", new ValueContainerChar(&temp_nsuserhost), DT_CHARPTR, ValidateNotEmpty},
+ {"nickserv", "enforceruser", "", new ValueContainerString(&temp_nsuserhost), DT_STRING, ValidateNotEmpty},
{"nickserv", "releasetimeout", "0", new ValueContainerTime(&Config.NSReleaseTimeout), DT_TIME, ValidateNotZero},
{"nickserv", "allowkillimmed", "no", new ValueContainerBool(&Config.NSAllowKillImmed), DT_BOOLEAN | DT_NORELOAD, NoValidation},
{"nickserv", "nogroupchange", "no", new ValueContainerBool(&Config.NSNoGroupChange), DT_BOOLEAN, NoValidation},
{"nickserv", "listopersonly", "no", new ValueContainerBool(&Config.NSListOpersOnly), DT_BOOLEAN, NoValidation},
{"nickserv", "listmax", "0", new ValueContainerUInt(&Config.NSListMax), DT_UINTEGER, ValidateNotZero},
- {"nickserv", "guestnickprefix", "", new ValueContainerChar(&Config.NSGuestNickPrefix), DT_CHARPTR, ValidateGuestPrefix},
+ {"nickserv", "guestnickprefix", "", new ValueContainerString(&Config.NSGuestNickPrefix), DT_STRING, ValidateGuestPrefix},
{"nickserv", "secureadmins", "no", new ValueContainerBool(&Config.NSSecureAdmins), DT_BOOLEAN, NoValidation},
{"nickserv", "strictprivileges", "no", new ValueContainerBool(&Config.NSStrictPrivileges), DT_BOOLEAN, NoValidation},
{"nickserv", "modeonid", "no", new ValueContainerBool(&Config.NSModeOnID), DT_BOOLEAN, NoValidation},
{"nickserv", "addaccessonreg", "no", new ValueContainerBool(&Config.NSAddAccessOnReg), DT_BOOLEAN, NoValidation},
{"mail", "usemail", "no", new ValueContainerBool(&Config.UseMail), DT_BOOLEAN, ValidateEmailReg},
- {"mail", "sendmailpath", "", new ValueContainerChar(&Config.SendMailPath), DT_CHARPTR, ValidateMail},
- {"mail", "sendfrom", "", new ValueContainerChar(&Config.SendFrom), DT_CHARPTR, ValidateMail},
+ {"mail", "sendmailpath", "", new ValueContainerString(&Config.SendMailPath), DT_STRING, ValidateMail},
+ {"mail", "sendfrom", "", new ValueContainerString(&Config.SendFrom), DT_STRING, ValidateMail},
{"mail", "restrict", "no", new ValueContainerBool(&Config.RestrictMail), DT_BOOLEAN, NoValidation},
{"mail", "delay", "0", new ValueContainerTime(&Config.MailDelay), DT_TIME, NoValidation},
{"mail", "dontquoteaddresses", "no", new ValueContainerBool(&Config.DontQuoteAddresses), DT_BOOLEAN, NoValidation},
- {"chanserv", "nick", "ChanServ", new ValueContainerChar(&Config.s_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"chanserv", "description", "Channel Registration Service", new ValueContainerChar(&Config.desc_ChanServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"chanserv", "modules", "", new ValueContainerCIString(&ChanCoreModules), DT_CISTRING, NoValidation},
- {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerCIString(&CSDefaults), DT_CISTRING, NoValidation},
+ {"chanserv", "nick", "ChanServ", new ValueContainerString(&Config.s_ChanServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"chanserv", "description", "Channel Registration Service", new ValueContainerString(&Config.desc_ChanServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"chanserv", "modules", "", new ValueContainerString(&ChanCoreModules), DT_STRING, NoValidation},
+ {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerString(&CSDefaults), DT_STRING, NoValidation},
{"chanserv", "maxregistered", "0", new ValueContainerUInt(&Config.CSMaxReg), DT_UINTEGER, NoValidation},
{"chanserv", "expire", "14d", new ValueContainerTime(&Config.CSExpire), DT_TIME, NoValidation},
{"chanserv", "defbantype", "2", new ValueContainerInt(&Config.CSDefBantype), DT_INTEGER, ValidateBantype},
{"chanserv", "accessmax", "0", new ValueContainerUInt(&Config.CSAccessMax), DT_UINTEGER, ValidateNotZero},
{"chanserv", "autokickmax", "0", new ValueContainerUInt(&Config.CSAutokickMax), DT_UINTEGER, ValidateNotZero},
- {"chanserv", "autokickreason", "User has been banned from the channel", new ValueContainerChar(&Config.CSAutokickReason), DT_CHARPTR, ValidateNotEmpty},
+ {"chanserv", "autokickreason", "User has been banned from the channel", new ValueContainerString(&Config.CSAutokickReason), DT_STRING, ValidateNotEmpty},
{"chanserv", "inhabit", "0", new ValueContainerTime(&Config.CSInhabit), DT_TIME, ValidateNotZero},
{"chanserv", "listopersonly", "no", new ValueContainerBool(&Config.CSListOpersOnly), DT_BOOLEAN, NoValidation},
{"chanserv", "listmax", "0", new ValueContainerUInt(&Config.CSListMax), DT_UINTEGER, ValidateNotZero},
{"chanserv", "opersonly", "no", new ValueContainerBool(&Config.CSOpersOnly), DT_BOOLEAN, NoValidation},
- {"memoserv", "nick", "MemoServ", new ValueContainerChar(&Config.s_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"memoserv", "description", "Memo Service", new ValueContainerChar(&Config.desc_MemoServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"memoserv", "modules", "", new ValueContainerCIString(&MemoCoreModules), DT_CISTRING, NoValidation},
+ {"memoserv", "nick", "MemoServ", new ValueContainerString(&Config.s_MemoServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"memoserv", "description", "Memo Service", new ValueContainerString(&Config.desc_MemoServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"memoserv", "modules", "", new ValueContainerString(&MemoCoreModules), DT_STRING, NoValidation},
{"memoserv", "maxmemos", "0", new ValueContainerUInt(&Config.MSMaxMemos), DT_UINTEGER, NoValidation},
{"memoserv", "senddelay", "0", new ValueContainerTime(&Config.MSSendDelay), DT_TIME, NoValidation},
{"memoserv", "notifyall", "no", new ValueContainerBool(&Config.MSNotifyAll), DT_BOOLEAN, NoValidation},
{"memoserv", "memoreceipt", "0", new ValueContainerUInt(&Config.MSMemoReceipt), DT_UINTEGER, NoValidation},
- {"botserv", "nick", "", new ValueContainerChar(&Config.s_BotServ), DT_CHARPTR | DT_NORELOAD, NoValidation},
- {"botserv", "description", "Bot Service", new ValueContainerChar(&Config.desc_BotServ), DT_CHARPTR | DT_NORELOAD, ValidateBotServ},
- {"botserv", "modules", "", new ValueContainerCIString(&BotCoreModules), DT_CISTRING, NoValidation},
- {"botserv", "defaults", "", new ValueContainerCIString(&BSDefaults), DT_CISTRING, NoValidation},
+ {"botserv", "nick", "", new ValueContainerString(&Config.s_BotServ), DT_STRING | DT_NORELOAD, NoValidation},
+ {"botserv", "description", "Bot Service", new ValueContainerString(&Config.desc_BotServ), DT_STRING | DT_NORELOAD, ValidateBotServ},
+ {"botserv", "modules", "", new ValueContainerString(&BotCoreModules), DT_STRING, NoValidation},
+ {"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation},
{"botserv", "minusers", "0", new ValueContainerUInt(&Config.BSMinUsers), DT_UINTEGER, ValidateBotServ},
{"botserv", "badwordsmax", "0", new ValueContainerUInt(&Config.BSBadWordsMax), DT_UINTEGER, ValidateBotServ},
{"botserv", "keepdata", "0", new ValueContainerTime(&Config.BSKeepData), DT_TIME, ValidateBotServ},
{"botserv", "smartjoin", "no", new ValueContainerBool(&Config.BSSmartJoin), DT_BOOLEAN, NoValidation},
{"botserv", "gentlebadwordreason", "no", new ValueContainerBool(&Config.BSGentleBWReason), DT_BOOLEAN, NoValidation},
{"botserv", "casesensitive", "no", new ValueContainerBool(&Config.BSCaseSensitive), DT_BOOLEAN, NoValidation},
- {"botserv", "fantasycharacter", "!", new ValueContainerChar(&Config.BSFantasyCharacter), DT_CHARPTR, NoValidation},
- {"hostserv", "nick", "", new ValueContainerChar(&Config.s_HostServ), DT_CHARPTR | DT_NORELOAD, NoValidation},
- {"hostserv", "description", "vHost Service", new ValueContainerChar(&Config.desc_HostServ), DT_CHARPTR | DT_NORELOAD, ValidateHostServ},
- {"hostserv", "modules", "", new ValueContainerCIString(&HostCoreModules), DT_CISTRING, NoValidation},
- {"operserv", "nick", "OperServ", new ValueContainerChar(&Config.s_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"operserv", "description", "Operator Service", new ValueContainerChar(&Config.desc_OperServ), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"operserv", "globalnick", "Global", new ValueContainerChar(&Config.s_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"operserv", "globaldescription", "Global Noticer", new ValueContainerChar(&Config.desc_GlobalNoticer), DT_CHARPTR | DT_NORELOAD, ValidateNotEmpty},
- {"operserv", "modules", "", new ValueContainerCIString(&OperCoreModules), DT_CISTRING, NoValidation},
+ {"botserv", "fantasycharacter", "!", new ValueContainerString(&Config.BSFantasyCharacter), DT_STRING, NoValidation},
+ {"hostserv", "nick", "", new ValueContainerString(&Config.s_HostServ), DT_STRING | DT_NORELOAD, NoValidation},
+ {"hostserv", "description", "vHost Service", new ValueContainerString(&Config.desc_HostServ), DT_STRING | DT_NORELOAD, ValidateHostServ},
+ {"hostserv", "modules", "", new ValueContainerString(&HostCoreModules), DT_STRING, NoValidation},
+ {"operserv", "nick", "OperServ", new ValueContainerString(&Config.s_OperServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"operserv", "description", "Operator Service", new ValueContainerString(&Config.desc_OperServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"operserv", "globalnick", "Global", new ValueContainerString(&Config.s_GlobalNoticer), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"operserv", "globaldescription", "Global Noticer", new ValueContainerString(&Config.desc_GlobalNoticer), DT_STRING | DT_NORELOAD, ValidateNotEmpty},
+ {"operserv", "modules", "", new ValueContainerString(&OperCoreModules), DT_STRING, NoValidation},
{"operserv", "superadmin", "no", new ValueContainerBool(&Config.SuperAdmin), DT_BOOLEAN, NoValidation},
{"operserv", "logmaxusers", "no", new ValueContainerBool(&Config.LogMaxUsers), DT_BOOLEAN, NoValidation},
{"operserv", "autokillexpiry", "0", new ValueContainerTime(&Config.AutokillExpiry), DT_TIME, ValidateNotZero},
@@ -745,60 +736,60 @@ int ServerConfig::Read(bool bail)
{"operserv", "akillonadd", "no", new ValueContainerBool(&Config.AkillOnAdd), DT_BOOLEAN, NoValidation},
{"operserv", "killonsnline", "no", new ValueContainerBool(&Config.KillonSNline), DT_BOOLEAN, NoValidation},
{"operserv", "killonsqline", "no", new ValueContainerBool(&Config.KillonSQline), DT_BOOLEAN, NoValidation},
- {"operserv", "notifications", "", new ValueContainerCIString(&OSNotifications), DT_CISTRING, NoValidation},
+ {"operserv", "notifications", "", new ValueContainerString(&OSNotifications), DT_STRING, NoValidation},
{"operserv", "limitsessions", "no", new ValueContainerBool(&Config.LimitSessions), DT_BOOLEAN, NoValidation},
{"operserv", "defaultsessionlimit", "0", new ValueContainerUInt(&Config.DefSessionLimit), DT_UINTEGER, NoValidation},
{"operserv", "maxsessionlimit", "0", new ValueContainerUInt(&Config.MaxSessionLimit), DT_UINTEGER, ValidateLimitSessions},
{"operserv", "exceptionexpiry", "0", new ValueContainerTime(&Config.ExceptionExpiry), DT_TIME, ValidateLimitSessions},
- {"operserv", "sessionlimitexceeded", "", new ValueContainerChar(&Config.SessionLimitExceeded), DT_CHARPTR, NoValidation},
- {"operserv", "sessionlimitdetailsloc", "", new ValueContainerChar(&Config.SessionLimitDetailsLoc), DT_CHARPTR, NoValidation},
+ {"operserv", "sessionlimitexceeded", "", new ValueContainerString(&Config.SessionLimitExceeded), DT_STRING, NoValidation},
+ {"operserv", "sessionlimitdetailsloc", "", new ValueContainerString(&Config.SessionLimitDetailsLoc), DT_STRING, NoValidation},
{"operserv", "maxsessionkill", "0", new ValueContainerInt(&Config.MaxSessionKill), DT_INTEGER, NoValidation},
{"operserv", "sessionautokillexpiry", "0", new ValueContainerTime(&Config.SessionAutoKillExpiry), DT_TIME, NoValidation},
{"operserv", "addakiller", "no", new ValueContainerBool(&Config.AddAkiller), DT_BOOLEAN, NoValidation},
{"operserv", "opersonly", "no", new ValueContainerBool(&Config.OSOpersOnly), DT_BOOLEAN, NoValidation},
{"defcon", "defaultlevel", "0", new ValueContainerInt(&DefConLevel), DT_INTEGER, ValidateDefCon},
- {"defcon", "level4", "", new ValueContainerCIString(&DefCon4), DT_CISTRING, ValidateDefCon},
- {"defcon", "level3", "", new ValueContainerCIString(&DefCon3), DT_CISTRING, ValidateDefCon},
- {"defcon", "level2", "", new ValueContainerCIString(&DefCon2), DT_CISTRING, ValidateDefCon},
- {"defcon", "level1", "", new ValueContainerCIString(&DefCon1), DT_CISTRING, ValidateDefCon},
+ {"defcon", "level4", "", new ValueContainerString(&DefCon4), DT_STRING, ValidateDefCon},
+ {"defcon", "level3", "", new ValueContainerString(&DefCon3), DT_STRING, ValidateDefCon},
+ {"defcon", "level2", "", new ValueContainerString(&DefCon2), DT_STRING, ValidateDefCon},
+ {"defcon", "level1", "", new ValueContainerString(&DefCon1), DT_STRING, ValidateDefCon},
{"defcon", "sessionlimit", "0", new ValueContainerInt(&Config.DefConSessionLimit), DT_INTEGER, ValidateDefCon},
{"defcon", "akillexpire", "0", new ValueContainerTime(&Config.DefConAKILL), DT_TIME, ValidateDefCon},
- {"defcon", "chanmodes", "", new ValueContainerChar(&Config.DefConChanModes), DT_CHARPTR, ValidateDefCon},
+ {"defcon", "chanmodes", "", new ValueContainerString(&Config.DefConChanModes), DT_STRING, ValidateDefCon},
{"defcon", "timeout", "0", new ValueContainerTime(&Config.DefConTimeOut), DT_TIME, NoValidation},
{"defcon", "globalondefcon", "no", new ValueContainerBool(&Config.GlobalOnDefcon), DT_BOOLEAN, NoValidation},
{"defcon", "globalondefconmore", "no", new ValueContainerBool(&Config.GlobalOnDefconMore), DT_BOOLEAN, NoValidation},
- {"defcon", "message", "", new ValueContainerChar(&Config.DefconMessage), DT_CHARPTR, ValidateDefCon},
- {"defcon", "offmessage", "", new ValueContainerChar(&Config.DefConOffMessage), DT_CHARPTR, NoValidation},
- {"defcon", "akillreason", "", new ValueContainerChar(&Config.DefConAkillReason), DT_CHARPTR, ValidateDefCon},
- {NULL, NULL, NULL, NULL, DT_NOTHING, NoValidation}
+ {"defcon", "message", "", new ValueContainerString(&Config.DefconMessage), DT_STRING, ValidateDefCon},
+ {"defcon", "offmessage", "", new ValueContainerString(&Config.DefConOffMessage), DT_STRING, NoValidation},
+ {"defcon", "akillreason", "", new ValueContainerString(&Config.DefConAkillReason), DT_STRING, ValidateDefCon},
+ {"", "", "", NULL, DT_NOTHING, NoValidation}
};
/* These tags can occur multiple times, and therefore they have special code to read them
* which is different to the code for reading the singular tags listed above. */
MultiConfig MultiValues[] = {
{"uplink",
- {"host", "ipv6", "port", "password", NULL},
- {"", "no", "0", "", NULL},
+ {"host", "ipv6", "port", "password", ""},
+ {"", "no", "0", "", ""},
{DT_HOSTNAME | DT_NORELOAD, DT_BOOLEAN | DT_NORELOAD, DT_UINTEGER | DT_NORELOAD, DT_NOSPACES | DT_NORELOAD},
InitUplinks, DoUplink, DoneUplinks},
{"module",
- {"name", NULL},
- {"", NULL},
+ {"name", ""},
+ {"", ""},
{DT_CHARPTR},
InitModules, DoModule, DoneModules},
{"opertype",
- {"name", "inherits", "commands", "privs", NULL},
- {"", "", "", "", NULL},
+ {"name", "inherits", "commands", "privs", ""},
+ {"", "", "", "", ""},
{DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
InitOperTypes, DoOperType, DoneOperTypes},
{"oper",
- {"name", "type", NULL},
- {"", "", NULL},
+ {"name", "type", ""},
+ {"", "", ""},
{DT_CHARPTR, DT_CHARPTR},
InitOpers, DoOper, DoneOpers},
- {NULL,
- {NULL},
- {NULL},
+ {"",
+ {""},
+ {""},
{0},
NULL, NULL, NULL}
};
@@ -821,9 +812,9 @@ int ServerConfig::Read(bool bail)
try
{
// Read the values of all the tags which occur once or not at all, and call their callbacks.
- for (int Index = 0; Values[Index].tag; ++Index)
+ for (int Index = 0; !Values[Index].tag.empty(); ++Index)
{
- char item[BUFSIZE];
+ Anope::string item;
int dt = Values[Index].datatype;
bool allow_newlines = dt & DT_ALLOW_NEWLINE, allow_wild = dt & DT_ALLOW_WILD, noreload = dt & DT_NORELOAD;
dt &= ~DT_ALLOW_NEWLINE;
@@ -837,7 +828,7 @@ int ServerConfig::Read(bool bail)
continue;
}
- ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, BUFSIZE, allow_newlines);
+ ConfValue(config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, allow_newlines);
ValueItem vi(item);
if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
@@ -847,23 +838,23 @@ int ServerConfig::Read(bool bail)
{
case DT_NOSPACES:
{
- ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val);
- ValidateNoSpaces(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
+ ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val);
+ ValidateNoSpaces(vi.GetValue(), Values[Index].tag, Values[Index].value);
+ vcs->Set(vi.GetValue());
}
break;
case DT_HOSTNAME:
{
- ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val);
- ValidateHostname(vi.GetString(), Values[Index].tag, Values[Index].value);
- vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
+ ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val);
+ ValidateHostname(vi.GetValue(), Values[Index].tag, Values[Index].value);
+ vcs->Set(vi.GetValue());
}
break;
case DT_IPADDRESS:
{
- ValueContainerChar *vcc = dynamic_cast<ValueContainerChar *>(Values[Index].val);
- ValidateIP(vi.GetString(), Values[Index].tag, Values[Index].value, allow_wild);
- vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
+ ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val);
+ ValidateIP(vi.GetValue(), Values[Index].tag, Values[Index].value, allow_wild);
+ vcs->Set(vi.GetValue());
}
break;
case DT_CHARPTR:
@@ -873,10 +864,10 @@ int ServerConfig::Read(bool bail)
vcc->Set(vi.GetString(), strlen(vi.GetString()) + 1);
}
break;
- case DT_STRING:
+ case DT_CSSTRING:
{
- ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val);
- vcs->Set(vi.GetValue());
+ ValueContainerCSString *vcs = dynamic_cast<ValueContainerCSString *>(Values[Index].val);
+ vcs->Set(vi.GetCSValue());
}
break;
case DT_CISTRING:
@@ -885,6 +876,12 @@ int ServerConfig::Read(bool bail)
vcs->Set(vi.GetCIValue());
}
break;
+ case DT_STRING:
+ {
+ ValueContainerString *vcs = dynamic_cast<ValueContainerString *>(Values[Index].val);
+ vcs->Set(vi.GetValue());
+ }
+ break;
case DT_INTEGER:
{
int val = vi.GetInteger();
@@ -908,7 +905,7 @@ int ServerConfig::Read(bool bail)
break;
case DT_TIME:
{
- time_t time = dotime(vi.GetString());
+ time_t time = dotime(vi.GetValue());
ValueContainerTime *vci = dynamic_cast<ValueContainerTime *>(Values[Index].val);
vci->Set(&time, sizeof(time_t));
}
@@ -931,7 +928,7 @@ int ServerConfig::Read(bool bail)
/* Read the multiple-tag items (class tags, connect tags, etc)
* and call the callbacks associated with them. We have three
* callbacks for these, a 'start', 'item' and 'end' callback. */
- for (int Index = 0; MultiValues[Index].tag; ++Index)
+ for (int Index = 0; !MultiValues[Index].tag.empty(); ++Index)
{
MultiValues[Index].init_function(this, MultiValues[Index].tag, bail);
int number_of_tags = ConfValueEnum(config_data, MultiValues[Index].tag);
@@ -939,7 +936,7 @@ int ServerConfig::Read(bool bail)
{
ValueList vl;
vl.clear();
- for (int valuenum = 0; MultiValues[Index].items[valuenum]; ++valuenum)
+ for (int valuenum = 0; !MultiValues[Index].items[valuenum].empty(); ++valuenum)
{
int dt = MultiValues[Index].datatype[valuenum];
bool allow_newlines = dt & DT_ALLOW_NEWLINE, allow_wild = dt & DT_ALLOW_WILD, noreload = dt & DT_NORELOAD;
@@ -953,47 +950,47 @@ int ServerConfig::Read(bool bail)
{
case DT_NOSPACES:
{
- char item[BUFSIZE];
- if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
vl.push_back(ValueItem(item));
else
vl.push_back(ValueItem(""));
- ValidateNoSpaces(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
+ ValidateNoSpaces(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
}
break;
case DT_HOSTNAME:
{
- char item[BUFSIZE];
- if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
vl.push_back(ValueItem(item));
else
vl.push_back(ValueItem(""));
- ValidateHostname(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
+ ValidateHostname(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum]);
}
break;
case DT_IPADDRESS:
{
- char item[BUFSIZE];
- if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
vl.push_back(ValueItem(item));
else
vl.push_back(ValueItem(""));
- ValidateIP(vl[vl.size() - 1].GetString(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
+ ValidateIP(vl[vl.size() - 1].GetValue(), MultiValues[Index].tag, MultiValues[Index].items[valuenum], allow_wild);
}
break;
case DT_CHARPTR:
{
- char item[BUFSIZE];
- if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, BUFSIZE, allow_newlines))
- vl.push_back(ValueItem(item));
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
+ vl.push_back(ValueItem(item.c_str()));
else
vl.push_back(ValueItem(""));
}
break;
- case DT_STRING:
+ case DT_CSSTRING:
{
- ci::string item;
- if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
vl.push_back(ValueItem(item));
else
vl.push_back(ValueItem(""));
@@ -1001,8 +998,17 @@ int ServerConfig::Read(bool bail)
break;
case DT_CISTRING:
{
- ci::string item;
- if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
+ vl.push_back(ValueItem(item));
+ else
+ vl.push_back(ValueItem(""));
+ }
+ break;
+ case DT_STRING:
+ {
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
vl.push_back(ValueItem(item));
else
vl.push_back(ValueItem(""));
@@ -1021,13 +1027,13 @@ int ServerConfig::Read(bool bail)
break;
case DT_TIME:
{
- ci::string item;
- if (ConfValue(config_data, ci::string(MultiValues[Index].tag), ci::string(MultiValues[Index].items[valuenum]), ci::string(MultiValues[Index].items_default[valuenum]), tagnum, item, allow_newlines))
+ Anope::string item;
+ if (ConfValue(config_data, MultiValues[Index].tag, MultiValues[Index].items[valuenum], MultiValues[Index].items_default[valuenum], tagnum, item, allow_newlines))
{
#ifdef _WIN32
- long time = static_cast<long>(dotime(item.c_str()));
+ long time = static_cast<long>(dotime(item));
#else
- time_t time = dotime(item.c_str());
+ time_t time = dotime(item);
#endif
vl.push_back(ValueItem(time));
}
@@ -1042,7 +1048,7 @@ int ServerConfig::Read(bool bail)
}
}
}
- MultiValues[Index].validation_function(this, MultiValues[Index].tag, static_cast<const char **>(MultiValues[Index].items), vl, MultiValues[Index].datatype, bail);
+ MultiValues[Index].validation_function(this, MultiValues[Index].tag, MultiValues[Index].items, vl, MultiValues[Index].datatype, bail);
}
MultiValues[Index].finish_function(this, MultiValues[Index].tag, bail);
}
@@ -1052,7 +1058,7 @@ int ServerConfig::Read(bool bail)
ReportConfigError(ce.GetReason(), bail);
if (!CheckedAllValues)
{
- for (int Index = 0; Values[Index].tag; ++Index)
+ for (int Index = 0; !Values[Index].tag.empty(); ++Index)
{
if (Values[Index].val)
delete Values[Index].val;
@@ -1061,18 +1067,18 @@ int ServerConfig::Read(bool bail)
return 0;
}
Alog(LOG_DEBUG) << "End config";
- for (int Index = 0; Once[Index]; ++Index)
+ for (int Index = 0; !Once[Index].empty(); ++Index)
if (!CheckOnce(Once[Index]))
return 0;
Alog() << "Done reading configuration file.";
return 1;
}
-bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::ostringstream &errorstream)
+bool ServerConfig::LoadConf(ConfigDataHash &target, const Anope::string &filename, std::ostringstream &errorstream)
{
- std::string line;
- ci::string section, wordbuffer, itemname;
- std::ifstream conf(filename);
+ Anope::string line;
+ Anope::string section, wordbuffer, itemname;
+ std::ifstream conf(filename.c_str());
int linenumber = 0;
bool in_word = false, in_quote = false, in_ml_comment = false;
KeyValList sectiondata;
@@ -1083,10 +1089,10 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o
}
Alog(LOG_DEBUG) << "Start to read conf " << filename;
// Start reading characters...
- while (getline(conf, line))
+ while (getline(conf, line.str()))
{
++linenumber;
- unsigned c = 0, len = line.size();
+ unsigned c = 0, len = line.length();
for (; c < len; ++c)
{
char ch = line[c];
@@ -1190,7 +1196,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o
wordbuffer.clear();
itemname.clear();
}
- target.insert(std::pair<ci::string, KeyValList>(section, sectiondata));
+ target.insert(std::pair<Anope::string, KeyValList>(section, sectiondata));
section.clear();
sectiondata.clear();
}
@@ -1256,35 +1262,12 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char *filename, std::o
return true;
}
-bool ServerConfig::LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream)
-{
- return LoadConf(target, filename.c_str(), errorstream);
-}
-
-bool ServerConfig::LoadConf(ConfigDataHash &target, const ci::string &filename, std::ostringstream &errorstream)
-{
- return LoadConf(target, filename.c_str(), errorstream);
-}
-
-bool ServerConfig::ConfValue(ConfigDataHash &target, const char *tag, const char *var, int index, char *result, int length, bool allow_linefeeds)
-{
- return ConfValue(target, tag, var, "", index, result, length, allow_linefeeds);
-}
-
-bool ServerConfig::ConfValue(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index, char *result, int length, bool allow_linefeeds)
-{
- ci::string value;
- bool r = ConfValue(target, ci::string(tag), ci::string(var), ci::string(default_value), index, value, allow_linefeeds);
- strlcpy(result, value.c_str(), length);
- return r;
-}
-
-bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index, ci::string &result, bool allow_linefeeds)
+bool ServerConfig::ConfValue(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index, Anope::string &result, bool allow_linefeeds)
{
return ConfValue(target, tag, var, "", index, result, allow_linefeeds);
}
-bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index, ci::string &result, bool allow_linefeeds)
+bool ServerConfig::ConfValue(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index, Anope::string &result, bool allow_linefeeds)
{
ConfigDataHash::size_type pos = index;
if (pos < target.count(tag))
@@ -1297,15 +1280,12 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, cons
KeyValList::iterator j = iter->second.begin(), jend = iter->second.end();
for (; j != jend; ++j)
{
- if (j->first == var)
+ if (j->first.equals_ci(var))
{
- if (!allow_linefeeds && j->second.find('\n') != std::string::npos)
+ if (!allow_linefeeds && j->second.find('\n') != Anope::string::npos)
{
Alog(LOG_DEBUG) << "Value of <" << tag << ":" << var << "> contains a linefeed, and linefeeds in this value are not permitted -- stripped to spaces.";
- ci::string::iterator n = j->second.begin(), nend = j->second.end();
- for (; n != nend; ++n)
- if (*n == '\n')
- *n = ' ';
+ j->second.replace_all_cs("\n", " ");
}
else
{
@@ -1331,34 +1311,24 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const ci::string &tag, cons
return false;
}
-bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char *tag, const char *var, int index, int &result)
-{
- return ConfValueInteger(target, ci::string(tag), ci::string(var), "", index, result);
-}
-
-bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index, int &result)
-{
- return ConfValueInteger(target, ci::string(tag), ci::string(var), ci::string(default_value), index, result);
-}
-
-bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index, int &result)
+bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index, int &result)
{
return ConfValueInteger(target, tag, var, "", index, result);
}
-bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index, int &result)
+bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index, int &result)
{
- ci::string value;
+ Anope::string value;
std::istringstream stream;
bool r = ConfValue(target, tag, var, default_value, index, value);
- stream.str(value.c_str());
+ stream.str(value.str());
if (!(stream >> result))
return false;
else
{
if (!value.empty())
{
- if (value.substr(0, 2) == "0x")
+ if (value.substr(0, 2).equals_ci("0x"))
{
char *endptr;
@@ -1392,51 +1362,26 @@ bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const ci::string &ta
return r;
}
-bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char *tag, const char *var, int index)
-{
- return ConfValueBool(target, ci::string(tag), ci::string(var), "", index);
-}
-
-bool ServerConfig::ConfValueBool(ConfigDataHash &target, const char *tag, const char *var, const char *default_value, int index)
-{
- return ConfValueBool(target, ci::string(tag), ci::string(var), ci::string(default_value), index);
-}
-
-bool ServerConfig::ConfValueBool(ConfigDataHash &target, const ci::string &tag, const ci::string &var, int index)
+bool ServerConfig::ConfValueBool(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, int index)
{
return ConfValueBool(target, tag, var, "", index);
}
-bool ServerConfig::ConfValueBool(ConfigDataHash &target, const ci::string &tag, const ci::string &var, const ci::string &default_value, int index)
+bool ServerConfig::ConfValueBool(ConfigDataHash &target, const Anope::string &tag, const Anope::string &var, const Anope::string &default_value, int index)
{
- ci::string result;
+ Anope::string result;
if (!ConfValue(target, tag, var, default_value, index, result))
return false;
- return result == "yes" || result == "true" || result == "1";
-}
-
-int ServerConfig::ConfValueEnum(ConfigDataHash &target, const char *tag)
-{
- return target.count(tag);
-}
-
-int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag)
-{
- return target.count(tag.c_str());
+ return result.equals_ci("yes") || result.equals_ci("true") || result.equals_ci("1");
}
-int ServerConfig::ConfValueEnum(ConfigDataHash &target, const ci::string &tag)
+int ServerConfig::ConfValueEnum(ConfigDataHash &target, const Anope::string &tag)
{
return target.count(tag);
}
-int ServerConfig::ConfVarEnum(ConfigDataHash &target, const char *tag, int index)
-{
- return ConfVarEnum(target, ci::string(tag), index);
-}
-
-int ServerConfig::ConfVarEnum(ConfigDataHash &target, const ci::string &tag, int index)
+int ServerConfig::ConfVarEnum(ConfigDataHash &target, const Anope::string &tag, int index)
{
ConfigDataHash::size_type pos = index;
@@ -1478,7 +1423,9 @@ ValueItem::ValueItem(const char *value) : v(value) { }
ValueItem::ValueItem(const std::string &value) : v(value) { }
-ValueItem::ValueItem(const ci::string &value) : v(value.c_str()) { }
+ValueItem::ValueItem(const ci::string &value) : v(value) { }
+
+ValueItem::ValueItem(const Anope::string &value) : v(value) { }
void ValueItem::Set(const char *value)
{
@@ -1492,7 +1439,12 @@ void ValueItem::Set(const std::string &value)
void ValueItem::Set(const ci::string &value)
{
- v = value.c_str();
+ v = value;
+}
+
+void ValueItem::Set(const Anope::string &value)
+{
+ v = value;
}
void ValueItem::Set(int value)
@@ -1504,9 +1456,9 @@ void ValueItem::Set(int value)
int ValueItem::GetInteger()
{
- if (v.empty())
+ if (v.empty() || !v.is_number_only())
return 0;
- return atoi(v.c_str());
+ return convertTo<int>(v);
}
const char *ValueItem::GetString() const
@@ -1548,26 +1500,6 @@ void error(int linenum, const char *message, ...)
/*************************************************************************/
-#define CHECK(v) \
-do \
-{ \
- if (!v) \
- {\
- error(0, #v " missing"); \
- retval = 0; \
- } \
-} while (0)
-
-#define CHEK2(v, n) \
-do \
-{ \
- if (!v) \
- { \
- error(0, #n " missing"); \
- retval = 0; \
- } \
-} while (0)
-
/* Read the entire configuration file. If an error occurs while reading
* the file or a required directive is not found, print and log an
* appropriate error message and return 0; otherwise, return 1.
@@ -1579,24 +1511,24 @@ do \
int read_config(int reload)
{
int retval = 1;
- char *s;
int defconCount = 0;
retval = Config.Read(reload ? false : true);
- if (!retval) return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX
+ if (!retval)
+ return 0; // Temporary until most of the below is modified to use the new parser -- CyberBotX
- if (temp_nsuserhost)
+ if (!temp_nsuserhost.empty())
{
- if (!(s = strchr(temp_nsuserhost, '@')))
+ size_t at = temp_nsuserhost.find('@');
+ if (at == Anope::string::npos)
{
Config.NSEnforcerUser = temp_nsuserhost;
Config.NSEnforcerHost = Config.ServiceHost;
}
else
{
- *s++ = 0;
- Config.NSEnforcerUser = temp_nsuserhost;
- Config.NSEnforcerHost = s;
+ Config.NSEnforcerUser = temp_nsuserhost.substr(0, at);
+ Config.NSEnforcerHost = temp_nsuserhost.substr(at + 1);
}
}
@@ -1606,38 +1538,38 @@ int read_config(int reload)
Config.NSDefFlags.SetFlag(NI_MEMO_SIGNON);
Config.NSDefFlags.SetFlag(NI_MEMO_RECEIVE);
}
- else if (NSDefaults != "none")
+ else if (!NSDefaults.equals_ci("none"))
{
spacesepstream options(NSDefaults);
- ci::string option;
+ Anope::string option;
while (options.GetToken(option))
{
- if (option == "kill")
+ if (option.equals_ci("kill"))
Config.NSDefFlags.SetFlag(NI_KILLPROTECT);
- else if (option == "killquick")
+ else if (option.equals_ci("killquick"))
Config.NSDefFlags.SetFlag(NI_KILL_QUICK);
- else if (option == "secure")
+ else if (option.equals_ci("secure"))
Config.NSDefFlags.SetFlag(NI_SECURE);
- else if (option == "private")
+ else if (option.equals_ci("private"))
Config.NSDefFlags.SetFlag(NI_PRIVATE);
- else if (option == "msg")
+ else if (option.equals_ci("msg"))
{
if (!Config.UsePrivmsg)
Alog() << "msg in <nickserv:defaults> can only be used when UsePrivmsg is set";
else
Config.NSDefFlags.SetFlag(NI_MSG);
}
- else if (option == "hideemail")
+ else if (option.equals_ci("hideemail"))
Config.NSDefFlags.SetFlag(NI_HIDE_EMAIL);
- else if (option == "hideusermask")
+ else if (option.equals_ci("hideusermask"))
Config.NSDefFlags.SetFlag(NI_HIDE_MASK);
- else if (option == "hidequit")
+ else if (option.equals_ci("hidequit"))
Config.NSDefFlags.SetFlag(NI_HIDE_QUIT);
- else if (option == "memosignon")
+ else if (option.equals_ci("memosignon"))
Config.NSDefFlags.SetFlag(NI_MEMO_SIGNON);
- else if (option == "memoreceive")
+ else if (option.equals_ci("memoreceive"))
Config.NSDefFlags.SetFlag(NI_MEMO_RECEIVE);
- else if (option == "autoop")
+ else if (option.equals_ci("autoop"))
Config.NSDefFlags.SetFlag(NI_AUTOOP);
}
}
@@ -1661,37 +1593,37 @@ int read_config(int reload)
Config.CSDefFlags.SetFlag(CI_SECUREFOUNDER);
Config.CSDefFlags.SetFlag(CI_SIGNKICK);
}
- else if (CSDefaults != "none")
+ else if (!CSDefaults.equals_ci("none"))
{
spacesepstream options(CSDefaults);
- ci::string option;
+ Anope::string option;
while (options.GetToken(option))
{
- if (option == "keeptopic")
+ if (option.equals_ci("keeptopic"))
Config.CSDefFlags.SetFlag(CI_KEEPTOPIC);
- else if (option == "topiclock")
+ else if (option.equals_ci("topiclock"))
Config.CSDefFlags.SetFlag(CI_TOPICLOCK);
- else if (option == "private")
+ else if (option.equals_ci("private"))
Config.CSDefFlags.SetFlag(CI_PRIVATE);
- else if (option == "restricted")
+ else if (option.equals_ci("restricted"))
Config.CSDefFlags.SetFlag(CI_RESTRICTED);
- else if (option == "secure")
+ else if (option.equals_ci("secure"))
Config.CSDefFlags.SetFlag(CI_SECURE);
- else if (option == "secureops")
+ else if (option.equals_ci("secureops"))
Config.CSDefFlags.SetFlag(CI_SECUREOPS);
- else if (option == "securefounder")
+ else if (option.equals_ci("securefounder"))
Config.CSDefFlags.SetFlag(CI_SECUREFOUNDER);
- else if (option == "signkick")
+ else if (option.equals_ci("signkick"))
Config.CSDefFlags.SetFlag(CI_SIGNKICK);
- else if (option == "signkicklevel")
+ else if (option.equals_ci("signkicklevel"))
Config.CSDefFlags.SetFlag(CI_SIGNKICK_LEVEL);
- else if (option == "opnotice")
+ else if (option.equals_ci("opnotice"))
Config.CSDefFlags.SetFlag(CI_OPNOTICE);
- else if (option == "xop")
+ else if (option.equals_ci("xop"))
Config.CSDefFlags.SetFlag(CI_XOP);
- else if (option == "peace")
+ else if (option.equals_ci("peace"))
Config.CSDefFlags.SetFlag(CI_PEACE);
- else if (option == "persist")
+ else if (option.equals_ci("persist"))
Config.CSDefFlags.SetFlag(CI_PERSIST);
}
}
@@ -1699,18 +1631,18 @@ int read_config(int reload)
if (!BSDefaults.empty())
{
spacesepstream options(BSDefaults);
- ci::string option;
+ Anope::string option;
while (options.GetToken(option))
{
- if (option == "dontkickops")
+ if (option.equals_ci("dontkickops"))
Config.BSDefFlags.SetFlag(BS_DONTKICKOPS);
- else if (option == "dontkickvoices")
+ else if (option.equals_ci("dontkickvoices"))
Config.BSDefFlags.SetFlag(BS_DONTKICKVOICES);
- else if (option == "greet")
+ else if (option.equals_ci("greet"))
Config.BSDefFlags.SetFlag(BS_GREET);
- else if (option == "fantasy")
+ else if (option.equals_ci("fantasy"))
Config.BSDefFlags.SetFlag(BS_FANTASY);
- else if (option == "symbiosis")
+ else if (option.equals_ci("symbiosis"))
Config.BSDefFlags.SetFlag(BS_SYMBIOSIS);
}
}
@@ -1721,82 +1653,75 @@ int read_config(int reload)
if (!OSNotifications.empty())
{
spacesepstream notifications(OSNotifications);
- ci::string notice;
+ Anope::string notice;
while (notifications.GetToken(notice))
{
- if (notice == "oper")
+ if (notice.equals_ci("oper"))
Config.WallOper = true;
- else if (notice == "bados")
+ else if (notice.equals_ci("bados"))
Config.WallBadOS = true;
- else if (notice == "osglobal")
+ else if (notice.equals_ci("osglobal"))
Config.WallOSGlobal = true;
- else if (notice == "osmode")
+ else if (notice.equals_ci("osmode"))
Config.WallOSMode = true;
- else if (notice == "osclearmodes")
+ else if (notice.equals_ci("osclearmodes"))
Config.WallOSClearmodes = true;
- else if (notice == "oskick")
+ else if (notice.equals_ci("oskick"))
Config.WallOSKick = true;
- else if (notice == "osakill")
+ else if (notice.equals_ci("osakill"))
Config.WallOSAkill = true;
- else if (notice == "ossnline")
+ else if (notice.equals_ci("ossnline"))
Config.WallOSSNLine = true;
- else if (notice == "ossqline")
+ else if (notice.equals_ci("ossqline"))
Config.WallOSSQLine = true;
- else if (notice == "osszline")
+ else if (notice.equals_ci("osszline"))
Config.WallOSSZLine = true;
- else if (notice == "osnoop")
+ else if (notice.equals_ci("osnoop"))
Config.WallOSNoOp = true;
- else if (notice == "osjupe")
+ else if (notice.equals_ci("osjupe"))
Config.WallOSJupe = true;
- else if (notice == "akillexpire")
+ else if (notice.equals_ci("akillexpire"))
Config.WallAkillExpire = true;
- else if (notice == "snlineexpire")
+ else if (notice.equals_ci("snlineexpire"))
Config.WallSNLineExpire = true;
- else if (notice == "sqlineexpire")
+ else if (notice.equals_ci("sqlineexpire"))
Config.WallSQLineExpire = true;
- else if (notice == "szlineexpire")
+ else if (notice.equals_ci("szlineexpire"))
Config.WallSZLineExpire = true;
- else if (notice == "exceptionexpire")
+ else if (notice.equals_ci("exceptionexpire"))
Config.WallExceptionExpire = true;
- else if (notice == "getpass")
+ else if (notice.equals_ci("getpass"))
Config.WallGetpass = true;
- else if (notice == "setpass")
+ else if (notice.equals_ci("setpass"))
Config.WallSetpass = true;
- else if (notice == "forbid")
+ else if (notice.equals_ci("forbid"))
Config.WallForbid = true;
- else if (notice == "drop")
+ else if (notice.equals_ci("drop"))
Config.WallDrop = true;
}
}
/* Ulines */
-
- if (UlineServers)
+ if (!UlineServers.empty())
{
- Config.NumUlines = 0;
+ Config.Ulines.clear();
- s = strtok(UlineServers, " ");
- do
- {
- if (s)
- {
- ++Config.NumUlines;
- Config.Ulines = static_cast<char **>(realloc(Config.Ulines, sizeof(char *) * Config.NumUlines));
- Config.Ulines[Config.NumUlines - 1] = sstrdup(s);
- }
- } while ((s = strtok(NULL, " ")));
+ spacesepstream ulines(UlineServers);
+ Anope::string uline;
+ while (ulines.GetToken(uline))
+ Config.Ulines.push_back(uline);
}
/* Modules Autoload building... :P */
- Config.ModulesAutoLoad = BuildStringList(!Modules.empty() ? Modules : "");
- Config.EncModuleList = BuildStringList(!EncModules.empty() ? EncModules : "");
- Config.DBModuleList = BuildStringList(!DBModules.empty() ? DBModules : "");
- Config.HostServCoreModules = BuildStringList(!HostCoreModules.empty() ? HostCoreModules : "");
- Config.MemoServCoreModules = BuildStringList(!MemoCoreModules.empty() ? MemoCoreModules : "");
- Config.BotServCoreModules = BuildStringList(!BotCoreModules.empty() ? BotCoreModules : "");
- Config.OperServCoreModules = BuildStringList(!OperCoreModules.empty() ? OperCoreModules : "");
- Config.ChanServCoreModules = BuildStringList(!ChanCoreModules.empty() ? ChanCoreModules : "");
- Config.NickServCoreModules = BuildStringList(!NickCoreModules.empty() ? NickCoreModules : "");
+ Config.ModulesAutoLoad = BuildStringList(Modules);
+ Config.EncModuleList = BuildStringList(EncModules);
+ Config.DBModuleList = BuildStringList(DBModules);
+ Config.HostServCoreModules = BuildStringList(HostCoreModules);
+ Config.MemoServCoreModules = BuildStringList(MemoCoreModules);
+ Config.BotServCoreModules = BuildStringList(BotCoreModules);
+ Config.OperServCoreModules = BuildStringList(OperCoreModules);
+ Config.ChanServCoreModules = BuildStringList(ChanCoreModules);
+ Config.NickServCoreModules = BuildStringList(NickCoreModules);
if (Config.LimitSessions)
{
@@ -1804,12 +1729,12 @@ int read_config(int reload)
Config.SessionAutoKillExpiry = 1800; /* 30 minutes */
}
- if (Config.s_BotServ)
+ if (!Config.s_BotServ.empty())
{
- if (!Config.BSFantasyCharacter || !*Config.BSFantasyCharacter)
- Config.BSFantasyCharacter = sstrdup("!");
- if (*Config.BSFantasyCharacter && strlen(Config.BSFantasyCharacter) > 1)
- printf("*** Config.BSFantasyCharacter is more than 1 character long. Only the first\n*** character ('%c') will be used. The others will be ignored.\n", *Config.BSFantasyCharacter);
+ if (Config.BSFantasyCharacter.empty())
+ Config.BSFantasyCharacter = "!";
+ if (Config.BSFantasyCharacter.length() > 1)
+ printf("*** Config.BSFantasyCharacter is more than 1 character long. Only the first\n*** character ('%c') will be used. The others will be ignored.\n", Config.BSFantasyCharacter[0]);
}
/* Check the user keys */
@@ -1827,7 +1752,7 @@ int read_config(int reload)
for (unsigned int level = 1; level < 5; ++level)
{
DefCon[level] = 0;
- ci::string *levelDefinition = NULL;
+ Anope::string *levelDefinition = NULL;
switch (level)
{
case 1:
@@ -1843,28 +1768,28 @@ int read_config(int reload)
levelDefinition = &DefCon4;
}
spacesepstream operations(*levelDefinition);
- ci::string operation;
+ Anope::string operation;
while (operations.GetToken(operation))
{
- if (operation == "nonewchannels")
+ if (operation.equals_ci("nonewchannels"))
AddDefCon(level, DEFCON_NO_NEW_CHANNELS);
- else if (operation == "nonewnicks")
+ else if (operation.equals_ci("nonewnicks"))
AddDefCon(level, DEFCON_NO_NEW_NICKS);
- else if (operation == "nomlockchanges")
+ else if (operation.equals_ci("nomlockchanges"))
AddDefCon(level, DEFCON_NO_MLOCK_CHANGE);
- else if (operation == "forcechanmodes")
+ else if (operation.equals_ci("forcechanmodes"))
AddDefCon(level, DEFCON_FORCE_CHAN_MODES);
- else if (operation == "reducedsessions")
+ else if (operation.equals_ci("reducedsessions"))
AddDefCon(level, DEFCON_REDUCE_SESSION);
- else if (operation == "nonewclients")
+ else if (operation.equals_ci("nonewclients"))
AddDefCon(level, DEFCON_NO_NEW_CLIENTS);
- else if (operation == "operonly")
+ else if (operation.equals_ci("operonly"))
AddDefCon(level, DEFCON_OPER_ONLY);
- else if (operation == "silentoperonly")
+ else if (operation.equals_ci("silentoperonly"))
AddDefCon(level, DEFCON_SILENT_OPER_ONLY);
- else if (operation == "akillnewclients")
+ else if (operation.equals_ci("akillnewclients"))
AddDefCon(level, DEFCON_AKILL_NEW_CLIENTS);
- else if (operation == "nonewmemos")
+ else if (operation.equals_ci("nonewmemos"))
AddDefCon(level, DEFCON_NO_NEW_MEMOS);
}
}
@@ -1873,21 +1798,41 @@ int read_config(int reload)
for (defconCount = 1; defconCount <= 5; ++defconCount)
{
if (CheckDefCon(defconCount, DEFCON_REDUCE_SESSION))
- CHECK(Config.DefConSessionLimit);
+ {
+ if (!Config.DefConSessionLimit)
+ {
+ error(0, "Config.DefConSessionLimit missing");
+ retval = 0;
+ }
+ }
if (CheckDefCon(defconCount, DEFCON_AKILL_NEW_CLIENTS))
{
- CHECK(Config.DefConAKILL);
- CHECK(Config.DefConAkillReason);
+ if (!Config.DefConAKILL)
+ {
+ error(0, "Config.DefConAKILL missing");
+ retval = 0;
+ }
+ if (Config.DefConAkillReason.empty())
+ {
+ error(0, "Config.DefConAkillReason missing");
+ retval = 0;
+ }
}
if (CheckDefCon(defconCount, DEFCON_FORCE_CHAN_MODES))
- CHECK(Config.DefConChanModes);
+ {
+ if (Config.DefConChanModes.empty())
+ {
+ error(0, "Config.DefConChanModes missing");
+ retval = 0;
+ }
+ }
}
}
SetDefaultMLock();
/* Disable the log channel if its defined in the conf, but not enabled */
- if (!Config.LogChannel && LogChan)
+ if (Config.LogChannel.empty() && LogChan)
LogChan = false;
if (!retval)
diff --git a/src/configreader.cpp b/src/configreader.cpp
index fc9a7cb28..9e17b34be 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -25,42 +25,42 @@ ConfigReader::~ConfigReader()
delete this->data;
}
-ConfigReader::ConfigReader(const std::string &filename) : data(new ConfigDataHash), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(true), error(CONF_NO_ERROR)
+ConfigReader::ConfigReader(const Anope::string &filename) : data(new ConfigDataHash), errorlog(new std::ostringstream(std::stringstream::in | std::stringstream::out)), privatehash(true), error(CONF_NO_ERROR)
{
Config.ClearStack();
}
-std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds)
+Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index, bool allow_linefeeds)
{
/* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */
- ci::string result;
+ Anope::string result;
- if (!Config.ConfValue(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index, result, allow_linefeeds))
+ if (!Config.ConfValue(*this->data, tag, name, default_value, index, result, allow_linefeeds))
this->error = CONF_VALUE_NOT_FOUND;
- return result.c_str();
+ return result;
}
-std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds)
+Anope::string ConfigReader::ReadValue(const Anope::string &tag, const Anope::string &name, int index, bool allow_linefeeds)
{
return ReadValue(tag, name, "", index, allow_linefeeds);
}
-bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index)
+bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index)
{
- return Config.ConfValueBool(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index);
+ return Config.ConfValueBool(*this->data, tag, name, default_value, index);
}
-bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index)
+bool ConfigReader::ReadFlag(const Anope::string &tag, const Anope::string &name, int index)
{
return ReadFlag(tag, name, "", index);
}
-int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool need_positive)
+int ConfigReader::ReadInteger(const Anope::string &tag, const Anope::string &name, const Anope::string &default_value, int index, bool need_positive)
{
int result;
- if (!Config.ConfValueInteger(*this->data, ci::string(tag.c_str()), ci::string(name.c_str()), ci::string(default_value.c_str()), index, result))
+ if (!Config.ConfValueInteger(*this->data, tag, name, default_value, index, result))
{
this->error = CONF_VALUE_NOT_FOUND;
return 0;
@@ -75,7 +75,7 @@ int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, c
return result;
}
-int ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool need_positive)
+int ConfigReader::ReadInteger(const Anope::string &tag, const Anope::string &name, int index, bool need_positive)
{
return ReadInteger(tag, name, "", index, need_positive);
}
@@ -92,14 +92,14 @@ void ConfigReader::DumpErrors(bool bail)
Config.ReportConfigError(this->errorlog->str(), bail);
}
-int ConfigReader::Enumerate(const std::string &tag)
+int ConfigReader::Enumerate(const Anope::string &tag)
{
return Config.ConfValueEnum(*this->data, tag);
}
-int ConfigReader::EnumerateValues(const std::string &tag, int index)
+int ConfigReader::EnumerateValues(const Anope::string &tag, int index)
{
- return Config.ConfVarEnum(*this->data, ci::string(tag.c_str()), index);
+ return Config.ConfVarEnum(*this->data, tag, index);
}
bool ConfigReader::Verify()
diff --git a/src/encrypt.cpp b/src/encrypt.cpp
index f70d8fa8c..0121c0c4a 100644
--- a/src/encrypt.cpp
+++ b/src/encrypt.cpp
@@ -18,7 +18,7 @@
* Encrypt string `src' of length `len', placing the result in buffer
* `dest' of size `size'. Returns 0 on success, -1 on error.
**/
-int enc_encrypt(const std::string &src, std::string &dest)
+int enc_encrypt(const Anope::string &src, Anope::string &dest)
{
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, dest));
@@ -33,15 +33,15 @@ int enc_encrypt(const std::string &src, std::string &dest)
* allow decryption, and -1 if another failure occurred (e.g. destination
* buffer too small).
**/
-int enc_decrypt(const std::string &src, std::string &dest)
+int enc_decrypt(const Anope::string &src, Anope::string &dest)
{
- size_t pos = src.find(":");
- if (pos == std::string::npos)
+ size_t pos = src.find(':');
+ if (pos == Anope::string::npos)
{
Alog() << "Error: enc_decrypt() called with invalid password string (" << src << ")";
return -1;
}
- std::string hashm(src.begin(), src.begin() + pos);
+ Anope::string hashm(src.begin(), src.begin() + pos);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnDecrypt, OnDecrypt(hashm, src, dest));
@@ -57,16 +57,15 @@ int enc_decrypt(const std::string &src, std::string &dest)
* 0 if the password does not match
* 0 if an error occurred while checking
**/
-int enc_check_password(std::string &plaintext, std::string &password)
+int enc_check_password(Anope::string &plaintext, Anope::string &password)
{
- std::string hashm;
- size_t pos = password.find(":");
- if (pos == std::string::npos)
+ size_t pos = password.find(':');
+ if (pos == Anope::string::npos)
{
Alog() << "Error: enc_check_password() called with invalid password string (" << password << ")";
return 0;
}
- hashm.assign(password.begin(), password.begin() + pos);
+ Anope::string hashm(password.begin(), password.begin() + pos);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnCheckPassword, OnCheckPassword(hashm, plaintext, password));
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index 3698ef565..72bcf0936 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -8,7 +8,7 @@
* for use in Anope.
*/
-#include "hashcomp.h"
+#include "anope.h"
/******************************************************
*
@@ -103,33 +103,23 @@ const char *ci::ci_char_traits::find(const char *s1, int n, char c)
return n >= 0 ? s1 : NULL;
}
-sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
+sepstream::sepstream(const Anope::string &source, char seperator) : tokens(source), sep(seperator)
{
last_starting_position = n = tokens.begin();
}
-sepstream::sepstream(const ci::string &source, char seperator) : tokens(source.c_str()), sep(seperator)
+bool sepstream::GetToken(Anope::string &token)
{
- last_starting_position = n = tokens.begin();
-}
-
-sepstream::sepstream(const char *source, char seperator) : tokens(source), sep(seperator)
-{
- last_starting_position = n = tokens.begin();
-}
-
-bool sepstream::GetToken(std::string &token)
-{
- std::string::iterator lsp = last_starting_position;
+ Anope::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
if (*n == sep || n + 1 == tokens.end())
{
last_starting_position = n + 1;
- token = std::string(lsp, n + 1 == tokens.end() ? n + 1 : n);
+ token = Anope::string(lsp, n + 1 == tokens.end() ? n + 1 : n);
- while (token.length() && token.find_last_of(sep) == token.length() - 1)
+ while (token.length() && token.rfind(sep) == token.length() - 1)
token.erase(token.end() - 1);
++n;
@@ -140,21 +130,13 @@ bool sepstream::GetToken(std::string &token)
++n;
}
- token = "";
+ token.clear();
return false;
}
-bool sepstream::GetToken(ci::string &token)
+const Anope::string sepstream::GetRemaining()
{
- std::string tmp_token;
- bool result = GetToken(tmp_token);
- token = tmp_token.c_str();
- return result;
-}
-
-const std::string sepstream::GetRemaining()
-{
- return std::string(n, tokens.end());
+ return Anope::string(n, tokens.end());
}
bool sepstream::StreamEnd()
@@ -162,7 +144,6 @@ bool sepstream::StreamEnd()
return n == tokens.end();
}
-#if defined(_WIN32) && _MSV_VER < 1600
/** Compare two std::string's values for hashing in hash_map
* @param s1 The first string
* @param s2 The second string
@@ -171,11 +152,16 @@ bool sepstream::StreamEnd()
*/
bool hash_compare_std_string::operator()(const std::string &s1, const std::string &s2) const
{
- if (s1.length() != s2.length())
- return true;
- return (std::char_traits<char>::compare(s1.c_str(), s2.c_str(), s1.length()) < 0);
+ register int i = std::char_traits<char>::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length());
+ if (!i)
+ return s1.length() < s2.length();
+ return i < 0;
+}
+
+bool hash_compare_std_string::operator()(const Anope::string &s1, const Anope::string &s2) const
+{
+ return operator()(s1.str(), s2.str());
}
-#endif
/** Return a hash value for a string
* @param s The string
@@ -191,7 +177,11 @@ size_t hash_compare_std_string::operator()(const std::string &s) const
return t;
}
-#if defined(_WIN32) && _MSV_VER < 1600
+size_t hash_compare_std_string::operator()(const Anope::string &s) const
+{
+ return operator()(s.str());
+}
+
/** Compare two ci::string's values for hashing in hash_map
* @param s1 The first string
* @param s2 The second string
@@ -200,11 +190,16 @@ size_t hash_compare_std_string::operator()(const std::string &s) const
*/
bool hash_compare_ci_string::operator()(const ci::string &s1, const ci::string &s2) const
{
- if (s1.length() != s2.length())
- return true;
- return (ci::ci_char_traits::compare(s1.c_str(), s2.c_str(), s1.length()) < 0);
+ register int i = ci::ci_char_traits::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length());
+ if (!i)
+ return s1.length() < s2.length();
+ return i < 0;
+}
+
+bool hash_compare_ci_string::operator()(const Anope::string &s1, const Anope::string &s2) const
+{
+ return operator()(s1.ci_str(), s2.ci_str());
}
-#endif
/** Return a hash value for a string using case insensitivity
* @param s The string
@@ -220,7 +215,11 @@ size_t hash_compare_ci_string::operator()(const ci::string &s) const
return t;
}
-#if defined(_WIN32) && _MSV_VER < 1600
+size_t hash_compare_ci_string::operator()(const Anope::string &s) const
+{
+ return operator()(s.ci_str());
+}
+
/** Compare two irc::string's values for hashing in hash_map
* @param s1 The first string
* @param s2 The second string
@@ -229,11 +228,16 @@ size_t hash_compare_ci_string::operator()(const ci::string &s) const
*/
bool hash_compare_irc_string::operator()(const irc::string &s1, const irc::string &s2) const
{
- if (s1.length() != s2.length())
- return true;
- return (irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), s1.length()) < 0);
+ register int i = irc::irc_char_traits::compare(s1.c_str(), s2.c_str(), s1.length() < s2.length() ? s1.length() : s2.length());
+ if (!i)
+ return s1.length() < s2.length();
+ return i < 0;
+}
+
+bool hash_compare_irc_string::operator()(const Anope::string &s1, const Anope::string &s2) const
+{
+ return operator()(s1.irc_str(), s2.irc_str());
}
-#endif
/** Return a hash value for a string using RFC1459 case sensitivity rules
* @param s The string
@@ -248,3 +252,8 @@ size_t hash_compare_irc_string::operator()(const irc::string &s) const
return t;
}
+
+size_t hash_compare_irc_string::operator()(const Anope::string &s) const
+{
+ return operator()(s.irc_str());
+}
diff --git a/src/hostserv.cpp b/src/hostserv.cpp
index f59ac8c6e..b4ccabacb 100644
--- a/src/hostserv.cpp
+++ b/src/hostserv.cpp
@@ -13,8 +13,6 @@
#include "modules.h"
#include "language.h"
-E int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time);
-
E void moduleAddHostServCmds();
/*************************************************************************/
@@ -43,11 +41,11 @@ void get_hostserv_stats(long *nrec, long *memuse)
continue;
if (!na->hostinfo.GetIdent().empty())
- mem += na->hostinfo.GetIdent().size();
+ mem += na->hostinfo.GetIdent().length();
if (!na->hostinfo.GetHost().empty())
- mem += na->hostinfo.GetHost().size();
+ mem += na->hostinfo.GetHost().length();
if (!na->hostinfo.GetCreator().empty())
- mem += na->hostinfo.GetCreator().size();
+ mem += na->hostinfo.GetCreator().length();
++count;
}
@@ -63,7 +61,7 @@ void get_hostserv_stats(long *nrec, long *memuse)
*/
void hostserv_init()
{
- if (Config.s_HostServ)
+ if (!Config.s_HostServ.empty())
moduleAddHostServCmds();
}
@@ -75,20 +73,20 @@ void hostserv_init()
* @param buf Buffer holding the message
* @return void
*/
-void hostserv(User *u, const std::string &buf)
+void hostserv(User *u, const Anope::string &buf)
{
if (!u || 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(HostServ, u->nick.c_str(), "%s", command.c_str());
+ ircdproto->SendCTCP(HostServ, u->nick, "%s", command.c_str());
}
else if (!ircd->vhost)
- notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ);
+ notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ.c_str());
else
mod_run_cmd(HostServ, u, buf);
}
@@ -99,7 +97,7 @@ void hostserv(User *u, const std::string &buf)
* @param creator Who created the vhost
* @param time When the vhost was craated
*/
-void HostInfo::SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t created)
+void HostInfo::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created)
{
Ident = ident;
Host = host;
@@ -128,7 +126,7 @@ bool HostInfo::HasVhost() const
/** Retrieve the vhost ident
* @return the ident
*/
-const std::string &HostInfo::GetIdent() const
+const Anope::string &HostInfo::GetIdent() const
{
return Ident;
}
@@ -136,7 +134,7 @@ const std::string &HostInfo::GetIdent() const
/** Retrieve the vhost host
* @return the host
*/
-const std::string &HostInfo::GetHost() const
+const Anope::string &HostInfo::GetHost() const
{
return Host;
}
@@ -144,7 +142,7 @@ const std::string &HostInfo::GetHost() const
/** Retrieve the vhost creator
* @return the creator
*/
-const std::string &HostInfo::GetCreator() const
+const Anope::string &HostInfo::GetCreator() const
{
return Creator;
}
@@ -186,15 +184,11 @@ void do_on_id(User *u)
if (!na || !na->hostinfo.HasVhost())
return;
- if (!u->vhost || u->vhost != na->hostinfo.GetHost() || (!na->hostinfo.GetIdent().empty() && u->GetVIdent() != na->hostinfo.GetIdent()))
+ if (u->vhost.empty() || !u->vhost.equals_cs(na->hostinfo.GetHost()) || (!na->hostinfo.GetIdent().empty() && !u->GetVIdent().equals_cs(na->hostinfo.GetIdent())))
{
ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost());
if (ircd->vhost)
- {
- if (u->vhost)
- delete [] u->vhost;
- u->vhost = sstrdup(na->hostinfo.GetHost().c_str());
- }
+ u->vhost = na->hostinfo.GetHost();
if (ircd->vident && !na->hostinfo.GetIdent().empty())
u->SetVIdent(na->hostinfo.GetIdent());
u->UpdateHost();
diff --git a/src/init.cpp b/src/init.cpp
index 6ea0cab35..7388f7e79 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -19,7 +19,7 @@ extern void moduleAddIRCDMsgs();
/*************************************************************************/
-void introduce_user(const std::string &user)
+void introduce_user(const Anope::string &user)
{
/* Watch out for infinite loops... */
#define LTSIZE 20
@@ -36,11 +36,10 @@ void introduce_user(const std::string &user)
{
BotInfo *bi = it->second;
- ci::string ci_bi_nick(bi->nick.c_str());
- if (user.empty() || ci_bi_nick == user)
+ if (user.empty() || bi->nick.equals_ci(user))
{
ircdproto->SendClientIntroduction(bi->nick, bi->GetIdent(), bi->host, bi->realname, ircd->pseudoclient_mode, bi->GetUID());
- XLine x(bi->nick.c_str(), "Reserved for services");
+ XLine x(bi->nick, "Reserved for services");
ircdproto->SendSQLine(&x);
}
}
@@ -58,7 +57,7 @@ static int set_group()
struct group *gr;
setgrent();
- while ((gr = getgrent()) != NULL)
+ while ((gr = getgrent()))
{
if (!strcmp(gr->gr_name, RUNGROUP))
break;
@@ -82,7 +81,7 @@ static int set_group()
/*************************************************************************/
/* Vector of pairs of command line arguments and their params */
-static std::vector<std::pair<std::string, std::string> > CommandLineArguments;
+static std::vector<std::pair<Anope::string, Anope::string> > CommandLineArguments;
/** Called on startup to organize our starting arguments in a better way
* and check for errors
@@ -93,12 +92,12 @@ static void ParseCommandLineArguments(int ac, char **av)
{
for (int i = 1; i < ac; ++i)
{
- std::string option = av[i];
- std::string param = "";
+ Anope::string option = av[i];
+ Anope::string param;
while (!option.empty() && option[0] == '-')
option.erase(option.begin());
size_t t = option.find('=');
- if (t != std::string::npos)
+ if (t != Anope::string::npos)
{
param = option.substr(t + 1);
option.erase(t);
@@ -116,9 +115,9 @@ static void ParseCommandLineArguments(int ac, char **av)
* @param shortname A shorter name, eg --debug and -d
* @return true if name/shortname was found, false if not
*/
-bool GetCommandLineArgument(const std::string &name, char shortname)
+bool GetCommandLineArgument(const Anope::string &name, char shortname)
{
- std::string Unused;
+ Anope::string Unused;
return GetCommandLineArgument(name, shortname, Unused);
}
@@ -128,13 +127,13 @@ bool GetCommandLineArgument(const std::string &name, char shortname)
* @param param A string to put the param, if any, of the argument
* @return true if name/shortname was found, false if not
*/
-bool GetCommandLineArgument(const std::string &name, char shortname, std::string &param)
+bool GetCommandLineArgument(const Anope::string &name, char shortname, Anope::string &param)
{
param.clear();
- for (std::vector<std::pair<std::string, std::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it)
+ for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it)
{
- if (it->first == name || it->first[0] == shortname)
+ if (it->first.equals_ci(name) || it->first[0] == shortname)
{
param = it->second;
return true;
@@ -150,7 +149,7 @@ bool GetCommandLineArgument(const std::string &name, char shortname, std::string
static void remove_pidfile()
{
- remove(Config.PIDFilename);
+ remove(Config.PIDFilename.c_str());
}
/*************************************************************************/
@@ -161,7 +160,7 @@ static void write_pidfile()
{
FILE *pidfile;
- pidfile = fopen(Config.PIDFilename, "w");
+ pidfile = fopen(Config.PIDFilename.c_str(), "w");
if (pidfile)
{
#ifdef _WIN32
@@ -173,7 +172,7 @@ static void write_pidfile()
atexit(remove_pidfile);
}
else
- log_perror("Warning: cannot write to PID file %s", Config.PIDFilename);
+ log_perror("Warning: cannot write to PID file %s", Config.PIDFilename.c_str());
}
/*************************************************************************/
@@ -246,12 +245,12 @@ int init_primary(int ac, char **av)
if (GetCommandLineArgument("protocoldebug"))
protocoldebug = 1;
- std::string Arg;
+ Anope::string Arg;
if (GetCommandLineArgument("debug", 'd', Arg))
{
- if (!Arg.empty())
- {
- int level = atoi(Arg.c_str());
+ if (!Arg.empty())
+ {
+ int level = Arg.is_number_only() ? convertTo<int>(Arg) : -1;
if (level > 0)
debug = level;
else
@@ -259,9 +258,9 @@ int init_primary(int ac, char **av)
Alog(LOG_TERMINAL) << "Invalid option given to --debug";
return -1;
}
- }
- else
- ++debug;
+ }
+ else
+ ++debug;
}
if (GetCommandLineArgument("config", 'c', Arg))
@@ -271,7 +270,7 @@ int init_primary(int ac, char **av)
Alog(LOG_TERMINAL) << "The --config option requires a file name";
return -1;
}
- services_conf = Arg.c_str();
+ services_conf = Arg;
}
if (GetCommandLineArgument("dir", 0, Arg))
@@ -318,9 +317,9 @@ int init_primary(int ac, char **av)
/* Add IRCD Protocol Module; exit if there are errors */
if (protocol_module_init())
return -1;
-
+
/* Create me */
- Me = new Server(NULL, Config.ServerName, 0, Config.ServerDesc, (Config.Numeric ? Config.Numeric : ""));
+ Me = new Server(NULL, Config.ServerName, 0, Config.ServerDesc, Config.Numeric);
/* First thing, add our core bots internally. Before modules are loaded and before the database is read
* This is used for modules adding commands and for the BotInfo* poiners in the command classes.
@@ -334,19 +333,19 @@ int init_primary(int ac, char **av)
* Note that it is important this is after loading the protocol module. The ircd struct must exist for
* the ts6_ functions
*/
- if (Config.s_OperServ)
+ if (!Config.s_OperServ.empty())
new BotInfo(Config.s_OperServ, Config.ServiceUser, Config.ServiceHost, Config.desc_OperServ);
- if (Config.s_NickServ)
+ if (!Config.s_NickServ.empty())
new BotInfo(Config.s_NickServ, Config.ServiceUser, Config.ServiceHost, Config.desc_NickServ);
- if (Config.s_ChanServ)
+ if (!Config.s_ChanServ.empty())
new BotInfo(Config.s_ChanServ, Config.ServiceUser, Config.ServiceHost, Config.desc_ChanServ);
- if (Config.s_HostServ)
+ if (!Config.s_HostServ.empty())
new BotInfo(Config.s_HostServ, Config.ServiceUser, Config.ServiceHost, Config.desc_HostServ);
- if (Config.s_MemoServ)
+ if (!Config.s_MemoServ.empty())
new BotInfo(Config.s_MemoServ, Config.ServiceUser, Config.ServiceHost, Config.desc_MemoServ);
- if (Config.s_BotServ)
+ if (!Config.s_BotServ.empty())
new BotInfo(Config.s_BotServ, Config.ServiceUser, Config.ServiceHost, Config.desc_BotServ);
- if (Config.s_GlobalNoticer)
+ if (!Config.s_GlobalNoticer.empty())
new BotInfo(Config.s_GlobalNoticer, Config.ServiceUser, Config.ServiceHost, Config.desc_GlobalNoticer);
/* Add Encryption Modules */
@@ -399,11 +398,7 @@ int init_secondary(int ac, char **av)
#else
if (!SupportedWindowsVersion())
{
- char *winver = GetWindowsVersion();
-
- Alog() << winver << " is not a supported version of Windows";
-
- delete [] winver;
+ Alog() << GetWindowsVersion() << " is not a supported version of Windows";
return -1;
}
diff --git a/src/ircd.cpp b/src/ircd.cpp
index c06237a1b..e6ac76079 100644
--- a/src/ircd.cpp
+++ b/src/ircd.cpp
@@ -18,7 +18,7 @@ IRCDProto *ircdproto;
* Globals we want from the protocol file
**/
IRCDVar *ircd;
-char *version_protocol;
+Anope::string version_protocol;
int UseTSMODE;
void pmodule_ircd_proto(IRCDProto *proto)
@@ -26,19 +26,6 @@ void pmodule_ircd_proto(IRCDProto *proto)
ircdproto = proto;
}
-void anope_SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...)
-{
- va_list args;
- char buf[BUFSIZE] = "";
- if (fmt)
- {
- va_start(args, fmt);
- vsnprintf(buf, BUFSIZE - 1, fmt, args);
- va_end(args);
- }
- ircdproto->SendNumeric(source, numeric, dest, buf);
-}
-
/**
* Set routines for modules to set the prefered function for dealing with things.
**/
@@ -47,9 +34,9 @@ void pmodule_ircd_var(IRCDVar *ircdvar)
ircd = ircdvar;
}
-void pmodule_ircd_version(const char *version)
+void pmodule_ircd_version(const Anope::string &version)
{
- version_protocol = sstrdup(version);
+ version_protocol = version;
}
void pmodule_ircd_useTSMode(int use)
diff --git a/src/language.cpp b/src/language.cpp
index 473df39e8..558363f17 100644
--- a/src/language.cpp
+++ b/src/language.cpp
@@ -172,7 +172,7 @@ void lang_sanitize()
strnrepl(tmp, sizeof(tmp), "%R", "/");
else
strnrepl(tmp, sizeof(tmp), "%R", "/msg ");
- newstr = sstrdup(tmp);
+ newstr = strdup(tmp);
delete [] langtexts[i][j];
langtexts[i][j] = newstr;
}
@@ -303,7 +303,7 @@ int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
/* Send a syntax-error message to the user. */
-void syntax_error(char *service, User *u, const char *command, int msgnum)
+void syntax_error(const Anope::string &service, User *u, const Anope::string &command, int msgnum)
{
const char *str;
@@ -312,7 +312,7 @@ void syntax_error(char *service, User *u, const char *command, int msgnum)
str = getstring(u, msgnum);
notice_lang(service, u, SYNTAX_ERROR, str);
- notice_lang(service, u, MORE_INFO, service, command);
+ notice_lang(service, u, MORE_INFO, service.c_str(), command.c_str());
}
const char *getstring(NickAlias *na, int index)
@@ -327,7 +327,7 @@ const char *getstring(NickAlias *na, int index)
return langtexts[langidx][index];
}
-const char *getstring(NickCore *nc, int index)
+const char *getstring(const NickCore *nc, int index)
{
// Default to config
int langidx = Config.NSDefLanguage;
diff --git a/src/log.cpp b/src/log.cpp
index 3ce47c526..9f5e05ebc 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -17,7 +17,7 @@ static int curday = 0;
/*************************************************************************/
-static int get_logname(char *name, int count, struct tm *tm)
+static int get_logname(Anope::string &name, struct tm *tm)
{
char timestamp[32];
time_t t;
@@ -30,7 +30,7 @@ static int get_logname(char *name, int count, struct tm *tm)
/* fix bug 577 */
strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm);
- snprintf(name, count, "logs/%s.%s", timestamp, log_filename.c_str());
+ name = Anope::string("logs/") + timestamp + "." + log_filename;
curday = tm->tm_yday;
return 1;
@@ -43,7 +43,7 @@ static void remove_log()
time_t t;
struct tm tm;
- char name[PATH_MAX];
+ Anope::string name;
if (!Config.KeepLogs)
return;
@@ -53,8 +53,8 @@ static void remove_log()
tm = *localtime(&t);
/* removed if from here cause get_logchan is always 1 */
- get_logname(name, sizeof(name), &tm);
- DeleteFile(name);
+ get_logname(name, &tm);
+ DeleteFile(name.c_str());
}
/*************************************************************************/
@@ -82,18 +82,18 @@ static void checkday()
int open_log()
{
- char name[PATH_MAX];
+ Anope::string name;
if (logfile)
return 0;
/* if removed again.. get_logname is always 1 */
- get_logname(name, sizeof(name), NULL);
- logfile = fopen(name, "a");
+ get_logname(name, NULL);
+ logfile = fopen(name.c_str(), "a");
if (logfile)
setbuf(logfile, NULL);
- return logfile != NULL ? 0 : -1;
+ return logfile ? 0 : -1;
}
/*************************************************************************/
@@ -111,11 +111,11 @@ void close_log()
/*************************************************************************/
/* added cause this is used over and over in the code */
-char *log_gettimestamp()
+Anope::string log_gettimestamp()
{
time_t t;
struct tm tm;
- static char tbuf[256];
+ char tbuf[256];
time(&t);
tm = *localtime(&t);
@@ -145,7 +145,6 @@ char *log_gettimestamp()
void log_perror(const char *fmt, ...)
{
va_list args;
- char *buf;
int errno_save = errno;
char str[BUFSIZE];
@@ -158,12 +157,12 @@ void log_perror(const char *fmt, ...)
vsnprintf(str, sizeof(str), fmt, args);
va_end(args);
- buf = log_gettimestamp();
+ Anope::string buf = log_gettimestamp();
if (logfile)
- fprintf(logfile, "%s %s : %s\n", buf, str, strerror(errno_save));
+ fprintf(logfile, "%s %s : %s\n", buf.c_str(), str, strerror(errno_save));
if (nofork)
- fprintf(stderr, "%s %s : %s\n", buf, str, strerror(errno_save));
+ fprintf(stderr, "%s %s : %s\n", buf.c_str(), str, strerror(errno_save));
errno = errno_save;
}
@@ -176,7 +175,6 @@ void log_perror(const char *fmt, ...)
void fatal(const char *fmt, ...)
{
va_list args;
- char *buf;
char buf2[4096];
checkday();
@@ -188,12 +186,12 @@ void fatal(const char *fmt, ...)
vsnprintf(buf2, sizeof(buf2), fmt, args);
va_end(args);
- buf = log_gettimestamp();
+ Anope::string buf = log_gettimestamp();
if (logfile)
- fprintf(logfile, "%s FATAL: %s\n", buf, buf2);
+ fprintf(logfile, "%s FATAL: %s\n", buf.c_str(), buf2);
if (nofork)
- fprintf(stderr, "%s FATAL: %s\n", buf, buf2);
+ fprintf(stderr, "%s FATAL: %s\n", buf.c_str(), buf2);
if (UplinkSock)
ircdproto->SendGlobops(NULL, "FATAL ERROR! %s", buf2);
@@ -210,7 +208,6 @@ void fatal(const char *fmt, ...)
void fatal_perror(const char *fmt, ...)
{
va_list args;
- char *buf;
char buf2[4096];
int errno_save = errno;
@@ -223,12 +220,12 @@ void fatal_perror(const char *fmt, ...)
vsnprintf(buf2, sizeof(buf2), fmt, args);
va_end(args);
- buf = log_gettimestamp();
+ Anope::string buf = log_gettimestamp();
if (logfile)
- fprintf(logfile, "%s FATAL: %s: %s\n", buf, buf2, strerror(errno_save));
+ fprintf(logfile, "%s FATAL: %s: %s\n", buf.c_str(), buf2, strerror(errno_save));
if (nofork)
- fprintf(stderr, "%s FATAL: %s: %s\n", buf, buf2, strerror(errno_save));
+ fprintf(stderr, "%s FATAL: %s: %s\n", buf.c_str(), buf2, strerror(errno_save));
if (UplinkSock)
ircdproto->SendGlobops(NULL, "FATAL ERROR! %s: %s", buf2, strerror(errno_save));
@@ -249,20 +246,19 @@ Alog::~Alog()
if (Level >= LOG_DEBUG && (Level - LOG_DEBUG + 1) > debug)
return;
- char *tbuf;
int errno_save = errno;
checkday();
- tbuf = log_gettimestamp();
+ Anope::string tbuf = log_gettimestamp();
if (logfile)
- fprintf(logfile, "%s %s\n", tbuf, buf.str().c_str());
+ fprintf(logfile, "%s %s\n", tbuf.c_str(), buf.str().c_str());
if (nofork)
std::cout << tbuf << " " << buf.str() << std::endl;
else if (Level == LOG_TERMINAL) // XXX dont use this yet unless you know we're at terminal and not daemonized
std::cout << buf.str() << std::endl;
- if (Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel))
+ if (!Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel))
ircdproto->SendPrivmsg(Global, Config.LogChannel, "%s", buf.str().c_str());
errno = errno_save;
}
diff --git a/src/mail.cpp b/src/mail.cpp
index c7c8ebda7..b5e2149f9 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -11,12 +11,12 @@ MailThread::~MailThread()
void MailThread::Run()
{
- FILE *pipe = popen(Config.SendMailPath, "w");
+ FILE *pipe = popen(Config.SendMailPath.c_str(), "w");
if (!pipe)
return;
- fprintf(pipe, "From: %s\n", Config.SendFrom);
+ fprintf(pipe, "From: %s\n", Config.SendFrom.c_str());
if (Config.DontQuoteAddresses)
fprintf(pipe, "To: %s <%s>\n", MailTo.c_str(), Addr.c_str());
else
@@ -30,7 +30,7 @@ void MailThread::Run()
Success = true;
}
-bool Mail(User *u, NickRequest *nr, const std::string &service, const std::string &subject, const std::string &message)
+bool Mail(User *u, NickRequest *nr, const Anope::string &service, const Anope::string &subject, const Anope::string &message)
{
if (!u || !nr || subject.empty() || service.empty() || message.empty())
return false;
@@ -38,11 +38,11 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin
time_t t = time(NULL);
if (!Config.UseMail)
- notice_lang(service.c_str(), u, MAIL_DISABLED);
+ notice_lang(service, u, MAIL_DISABLED);
else if (t - u->lastmail < Config.MailDelay)
- notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail);
- else if (!nr->email)
- notice_lang(service.c_str(), u, MAIL_INVALID, nr->nick);
+ notice_lang(service, u, MAIL_DELAYED, t - u->lastmail);
+ else if (nr->email.empty())
+ notice_lang(service, u, MAIL_INVALID, nr->nick.c_str());
else
{
u->lastmail = nr->lastmail = t;
@@ -53,7 +53,7 @@ bool Mail(User *u, NickRequest *nr, const std::string &service, const std::strin
return false;
}
-bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &subject, const std::string &message)
+bool Mail(User *u, NickCore *nc, const Anope::string &service, const Anope::string &subject, const Anope::string &message)
{
if (!u || !nc || subject.empty() || service.empty() || message.empty())
return false;
@@ -61,11 +61,11 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &
time_t t = time(NULL);
if (!Config.UseMail)
- notice_lang(service.c_str(), u, MAIL_DISABLED);
+ notice_lang(service, u, MAIL_DISABLED);
else if (t - u->lastmail < Config.MailDelay)
- notice_lang(service.c_str(), u, MAIL_DELAYED, t - u->lastmail);
- else if (!nc->email)
- notice_lang(service.c_str(), u, MAIL_INVALID, nc->display);
+ notice_lang(service, u, MAIL_DELAYED, t - u->lastmail);
+ else if (nc->email.empty())
+ notice_lang(service, u, MAIL_INVALID, nc->display.c_str());
else
{
u->lastmail = nc->lastmail = t;
@@ -76,9 +76,9 @@ bool Mail(User *u, NickCore *nc, const std::string &service, const std::string &
return false;
}
-bool Mail(NickCore *nc, const std::string &subject, const std::string &message)
+bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message)
{
- if (!Config.UseMail || !nc || !nc->email || subject.empty() || message.empty())
+ if (!Config.UseMail || !nc || nc->email.empty() || subject.empty() || message.empty())
return false;
nc->lastmail = time(NULL);
@@ -96,28 +96,28 @@ bool Mail(NickCore *nc, const std::string &subject, const std::string &message)
* @param email Email to Validate
* @return bool
*/
-bool MailValidate(const std::string &email)
+bool MailValidate(const Anope::string &email)
{
bool has_period = false;
- char copy[BUFSIZE];
static char specials[] = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', ' '};
if (email.empty())
return false;
- strlcpy(copy, email.c_str(), sizeof(copy));
+ Anope::string copy = email;
- char *domain = strchr(copy, '@');
- if (!domain)
+ size_t at = copy.find('@');
+ if (at == Anope::string::npos)
return false;
- *domain++ = '\0';
+ Anope::string domain = copy.substr(at + 1);
+ copy = copy.substr(0, at);
- /* Don't accept NULL copy or domain. */
- if (!*copy || !*domain)
+ /* Don't accept empty copy or domain. */
+ if (copy.empty() || domain.empty())
return false;
/* Check for forbidden characters in the name */
- for (unsigned int i = 0; i < strlen(copy); ++i)
+ for (unsigned i = 0, end = copy.length(); i < end; ++i)
{
if (copy[i] <= 31 || copy[i] >= 127)
return false;
@@ -127,7 +127,7 @@ bool MailValidate(const std::string &email)
}
/* Check for forbidden characters in the domain */
- for (unsigned int i = 0; i < strlen(domain); ++i)
+ for (unsigned i = 0, end = domain.length(); i < end; ++i)
{
if (domain[i] <= 31 || domain[i] >= 127)
return false;
@@ -136,7 +136,7 @@ bool MailValidate(const std::string &email)
return false;
if (domain[i] == '.')
{
- if (!i || i == strlen(domain) - 1)
+ if (!i || i == end - 1)
return false;
has_period = true;
}
diff --git a/src/main.cpp b/src/main.cpp
index dccfcc15f..5e29db9f8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,15 +34,13 @@
# include <sys/resource.h>
#endif
-const char * const Anope::compiled = __TIME__ " " __DATE__;
-
/******** Global variables! ********/
/* Command-line options: (note that configuration variables are in config.c) */
-std::string services_dir; /* -dir dirname */
-std::string services_bin; /* Binary as specified by the user */
-std::string orig_cwd; /* Original current working directory */
-std::string log_filename = "services.log"; /* -log filename */
+Anope::string services_dir; /* -dir dirname */
+Anope::string services_bin; /* Binary as specified by the user */
+Anope::string orig_cwd; /* Original current working directory */
+Anope::string log_filename = "services.log"; /* -log filename */
int debug = 0; /* -debug */
int readonly = 0; /* -readonly */
bool LogChan = false; /* -logchan */
@@ -52,7 +50,7 @@ int nothird = 0; /* -nothrid */
int noexpire = 0; /* -noexpire */
int protocoldebug = 0; /* -protocoldebug */
-std::string binary_dir; /* Used to store base path for Anope */
+Anope::string binary_dir; /* Used to store base path for Anope */
#ifdef _WIN32
# include <process.h>
# define execve _execve
@@ -65,7 +63,7 @@ int quitting = 0;
int shutting_down = 0;
/* Contains a message as to why services is terminating */
-const char *quitmsg = NULL;
+Anope::string quitmsg;
/* Should we update the databases now? */
int save_data = 0;
@@ -112,7 +110,7 @@ Socket *UplinkSock = NULL;
class UplinkSocket : public ClientSocket
{
public:
- UplinkSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6)
+ UplinkSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6)
{
UplinkSock = this;
}
@@ -124,7 +122,7 @@ class UplinkSocket : public ClientSocket
UplinkSock = NULL;
}
- bool Read(const std::string &buf)
+ bool Read(const Anope::string &buf)
{
process(buf);
return true;
@@ -178,7 +176,7 @@ void do_restart_services()
FOREACH_MOD(I_OnPreRestart, OnPreRestart());
- if (!quitmsg)
+ if (quitmsg.empty())
quitmsg = "Restarting";
/* Send a quit for all of our bots */
for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
@@ -186,9 +184,9 @@ void do_restart_services()
/* Don't use quitmsg here, it may contain information you don't want people to see */
ircdproto->SendQuit(it->second, "Restarting");
/* Erase bots from the user list so they don't get nuked later on */
- UserListByNick.erase(it->second->nick.c_str());
+ UserListByNick.erase(it->second->nick);
if (!it->second->GetUID().empty())
- UserListByUID.erase(it->second->GetUID().c_str());
+ UserListByUID.erase(it->second->GetUID());
}
ircdproto->SendSquit(Config.ServerName, quitmsg);
delete UplinkSock;
@@ -218,7 +216,7 @@ static void services_shutdown()
{
FOREACH_MOD(I_OnPreShutdown, OnPreShutdown());
- if (!quitmsg)
+ if (quitmsg.empty())
quitmsg = "Terminating, reason unknown";
Alog() << quitmsg;
if (started && UplinkSock)
@@ -229,7 +227,7 @@ static void services_shutdown()
/* Don't use quitmsg here, it may contain information you don't want people to see */
ircdproto->SendQuit(it->second, "Shutting down");
/* Erase bots from the user list so they don't get nuked later on */
- UserListByNick.erase(it->second->nick.c_str());
+ UserListByNick.erase(it->second->nick);
if (!it->second->GetUID().empty())
UserListByUID.erase(it->second->GetUID());
}
@@ -258,7 +256,7 @@ void sighandler(int signum)
* always set when we need it. It seems some signals slip through to the
* QUIT code without having a valid quitmsg. -GD
*/
- if (!quitmsg)
+ if (quitmsg.empty())
quitmsg = "Services terminating via a signal.";
if (started)
@@ -324,7 +322,7 @@ void sighandler(int signum)
else
{
if (isatty(2))
- fprintf(stderr, "%s\n", quitmsg);
+ fprintf(stderr, "%s\n", quitmsg.c_str());
else
Alog() << quitmsg;
@@ -336,7 +334,7 @@ void sighandler(int signum)
/** The following comes from InspIRCd to get the full path of the Anope executable
*/
-std::string GetFullProgDir(char *argv0)
+Anope::string GetFullProgDir(const Anope::string &argv0)
{
char buffer[PATH_MAX];
#ifdef _WIN32
@@ -346,31 +344,31 @@ std::string GetFullProgDir(char *argv0)
*/
if (GetModuleFileName(NULL, buffer, PATH_MAX))
{
- std::string fullpath = buffer;
- std::string::size_type n = fullpath.rfind("\\" SERVICES_BIN);
- services_bin = fullpath.substr(n + 1, fullpath.size());
- return std::string(fullpath, 0, n);
+ Anope::string fullpath = buffer;
+ Anope::string::size_type n = fullpath.rfind("\\" SERVICES_BIN);
+ services_bin = fullpath.substr(n + 1, fullpath.length());
+ return fullpath.substr(0, n);
}
#else
// Get the current working directory
if (getcwd(buffer, PATH_MAX))
{
- std::string remainder = argv0;
+ Anope::string remainder = argv0;
/* Does argv[0] start with /? If so, it's a full path, use it */
if (remainder[0] == '/')
{
- std::string::size_type n = remainder.rfind("/" SERVICES_BIN);
- services_bin = remainder.substr(n + 1, remainder.size());
- return std::string(remainder, 0, n);
+ Anope::string::size_type n = remainder.rfind("/" SERVICES_BIN);
+ services_bin = remainder.substr(n + 1, remainder.length());
+ return remainder.substr(0, n);
}
services_bin = remainder;
- if (services_bin.substr(0, 2) == "./")
+ if (services_bin.substr(0, 2).equals_cs("./"))
services_bin = services_bin.substr(2);
- std::string fullpath = std::string(buffer) + "/" + remainder;
- std::string::size_type n = fullpath.rfind("/" SERVICES_BIN);
- return std::string(fullpath, 0, n);
+ Anope::string fullpath = Anope::string(buffer) + "/" + remainder;
+ Anope::string::size_type n = fullpath.rfind("/" SERVICES_BIN);
+ return fullpath.substr(0, n);
}
#endif
return "/";
@@ -397,7 +395,7 @@ static bool Connect()
try
{
- new UplinkSocket(uplink_server->host, uplink_server->port, Config.LocalHost ? Config.LocalHost : "", uplink_server->ipv6);
+ new UplinkSocket(uplink_server->host, uplink_server->port, Config.LocalHost, uplink_server->ipv6);
}
catch (const SocketException &ex)
{
@@ -444,13 +442,13 @@ int main(int ac, char **av, char **envp)
#endif
binary_dir = GetFullProgDir(av[0]);
- if (binary_dir[binary_dir.size() - 1] == '.')
- binary_dir = binary_dir.substr(0, binary_dir.size() - 2);
+ if (binary_dir[binary_dir.length() - 1] == '.')
+ binary_dir = binary_dir.substr(0, binary_dir.length() - 2);
#ifdef _WIN32
- std::string::size_type n = binary_dir.rfind("\\");
+ Anope::string::size_type n = binary_dir.rfind('\\');
services_dir = binary_dir.substr(0, n) + "\\data";
#else
- std::string::size_type n = binary_dir.rfind("/");
+ Anope::string::size_type n = binary_dir.rfind('/');
services_dir = binary_dir.substr(0, n) + "/data";
#endif
@@ -580,12 +578,12 @@ int main(int ac, char **av, char **envp)
return 0;
}
-inline std::string Anope::Version()
+inline Anope::string Anope::Version()
{
return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA + " (" + stringify(VERSION_BUILD) + ")";
}
-inline std::string Anope::Build()
+inline Anope::string Anope::Build()
{
- return std::string("build #") + stringify(BUILD) + ", compiled " + compiled;
+ return "build #" + stringify(BUILD) + ", compiled " + Anope::compiled;
}
diff --git a/src/memory.cpp b/src/memory.cpp
index 1fb1d2b21..12e0a1d08 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -21,25 +21,6 @@
/*************************************************************************/
/**
- * malloc, replacement so we can trap for "out of memory"
- * @param size to allocate
- * @return void
- */
-void *smalloc(long size)
-{
- void *buf;
-
- if (!size)
- size = 1;
- buf = malloc(size);
- if (!buf)
- abort();
- return buf;
-}
-
-/*************************************************************************/
-
-/**
* calloc, replacement so we can trap for "out of memory"
* @param elsize to allocate
* @param els size of members
@@ -78,33 +59,6 @@ void *srealloc(void *oldptr, long newsize)
}
/*************************************************************************/
-
-/**
- * strdup, replacement so we can trap for "out of memory"
- * @param oldptr Old Pointer
- * @param newsize Size of new pointer
- * @return void
- */
-char *sstrdup(const char *src)
-{
- char *ret = NULL;
- if (src)
- {
- ret = new char[strlen(src) + 1];
- if (!ret)
- abort();
- strcpy(ret, src);
- }
- else
- {
- Alog() << "sstrdup() called with NULL-arg";
- abort();
- }
-
- return ret;
-}
-
-/*************************************************************************/
/*************************************************************************/
/* In the future: malloc() replacements that tell us if we're leaking and
diff --git a/src/memoserv.cpp b/src/memoserv.cpp
index 5ceca0c7a..cc7ee5db4 100644
--- a/src/memoserv.cpp
+++ b/src/memoserv.cpp
@@ -50,17 +50,17 @@ void ms_init()
* @param buf Buffer containing the privmsg
* @return void
*/
-void memoserv(User *u, const std::string &buf)
+void memoserv(User *u, const Anope::string &buf)
{
if (!u || 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(MemoServ, u->nick.c_str(), "%s", command.c_str());
+ ircdproto->SendCTCP(MemoServ, u->nick, "%s", command.c_str());
}
else
mod_run_cmd(MemoServ, u, buf);
@@ -70,14 +70,14 @@ void memoserv(User *u, const std::string &buf)
/**
* check_memos: See if the given user has any unread memos, and send a
- * NOTICE to that user if so (and if the appropriate flag is
- * set).
+ * NOTICE to that user if so (and if the appropriate flag is
+ * set).
* @param u User Struct
* @return void
*/
void check_memos(User *u)
{
- NickCore *nc;
+ const NickCore *nc;
unsigned i, newcnt = 0;
if (!u)
@@ -86,7 +86,7 @@ void check_memos(User *u)
return;
}
- if (!(nc = u->Account()) || !u->IsRecognized() || !(nc->HasFlag(NI_MEMO_SIGNON)))
+ if (!(nc = u->Account()) || !u->IsRecognized() || !nc->HasFlag(NI_MEMO_SIGNON))
return;
for (i = 0; i < nc->memos.memos.size(); ++i)
@@ -98,7 +98,7 @@ void check_memos(User *u)
{
notice_lang(Config.s_MemoServ, u, newcnt == 1 ? MEMO_HAVE_NEW_MEMO : MEMO_HAVE_NEW_MEMOS, newcnt);
if (newcnt == 1 && (nc->memos.memos[i - 1]->HasFlag(MF_UNREAD)))
- notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_LAST, Config.s_MemoServ);
+ notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_LAST, Config.s_MemoServ.c_str());
else if (newcnt == 1)
{
for (i = 0; i < nc->memos.memos.size(); ++i)
@@ -106,10 +106,10 @@ void check_memos(User *u)
if (nc->memos.memos[i]->HasFlag(MF_UNREAD))
break;
}
- notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_NUM, Config.s_MemoServ, nc->memos.memos[i]->number);
+ notice_lang(Config.s_MemoServ, u, MEMO_TYPE_READ_NUM, Config.s_MemoServ.c_str(), nc->memos.memos[i]->number);
}
else
- notice_lang(Config.s_MemoServ, u, MEMO_TYPE_LIST_NEW, Config.s_MemoServ);
+ notice_lang(Config.s_MemoServ, u, MEMO_TYPE_LIST_NEW, Config.s_MemoServ.c_str());
}
if (nc->memos.memomax > 0 && nc->memos.memos.size() >= nc->memos.memomax)
{
@@ -132,9 +132,9 @@ void check_memos(User *u)
* @return `ischan' 1 if the name was a channel name, else 0.
* @return `isforbid' 1 if the name is forbidden, else 0.
*/
-MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid)
+MemoInfo *getmemoinfo(const Anope::string &name, int *ischan, int *isforbid)
{
- if (*name == '#')
+ if (name[0] == '#')
{
ChannelInfo *ci;
if (ischan)
@@ -200,19 +200,19 @@ MemoInfo *getmemoinfo(const char *name, int *ischan, int *isforbid)
* 3 - reply to user and request read receipt
* @return void
*/
-void memo_send(User *u, const char *name, const char *text, int z)
+void memo_send(User *u, const Anope::string &name, const Anope::string &text, int z)
{
int ischan;
int isforbid;
Memo *m;
MemoInfo *mi;
time_t now = time(NULL);
- char *source = u->Account()->display;
+ Anope::string source = u->Account()->display;
int is_servoper = u->Account() && u->Account()->IsServicesOper();
if (readonly)
notice_lang(Config.s_MemoServ, u, MEMO_SEND_DISABLED);
- else if (!text)
+ else if (text.empty())
{
if (!z)
syntax_error(Config.s_MemoServ, u, "SEND", MEMO_SEND_SYNTAX);
@@ -223,16 +223,16 @@ void memo_send(User *u, const char *name, const char *text, int z)
else if (!u->IsIdentified() && !u->IsRecognized())
{
if (!z || z == 3)
- notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ);
+ notice_lang(Config.s_MemoServ, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ.c_str());
}
else if (!(mi = getmemoinfo(name, &ischan, &isforbid)))
{
if (!z || z == 3)
{
if (isforbid)
- notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name);
+ notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name.c_str());
else
- notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name);
+ notice_lang(Config.s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str());
}
}
else if (z != 2 && Config.MSSendDelay > 0 && u && u->lastmemosend + Config.MSSendDelay > now)
@@ -247,12 +247,12 @@ void memo_send(User *u, const char *name, const char *text, int z)
else if (!mi->memomax && !is_servoper)
{
if (!z || z == 3)
- notice_lang(Config.s_MemoServ, u, MEMO_X_GETS_NO_MEMOS, name);
+ notice_lang(Config.s_MemoServ, u, MEMO_X_GETS_NO_MEMOS, name.c_str());
}
else if (mi->memomax > 0 && mi->memos.size() >= mi->memomax && !is_servoper)
{
if (!z || z == 3)
- notice_lang(Config.s_MemoServ, u, MEMO_X_HAS_TOO_MANY_MEMOS, name);
+ notice_lang(Config.s_MemoServ, u, MEMO_X_HAS_TOO_MANY_MEMOS, name.c_str());
}
else
{
@@ -272,7 +272,7 @@ void memo_send(User *u, const char *name, const char *text, int z)
else
m->number = 1;
m->time = time(NULL);
- m->text = sstrdup(text);
+ m->text = text;
m->SetFlag(MF_UNREAD);
/* Set notify sent flag - DrStein */
if (z == 2)
@@ -281,10 +281,10 @@ void memo_send(User *u, const char *name, const char *text, int z)
if (z == 3)
m->SetFlag(MF_RECEIPT);
if (!z || z == 3)
- notice_lang(Config.s_MemoServ, u, MEMO_SENT, name);
+ notice_lang(Config.s_MemoServ, u, MEMO_SENT, name.c_str());
if (!ischan)
{
- NickCore *nc = (findnick(name))->nc;
+ NickCore *nc = findnick(name)->nc;
FOREACH_MOD(I_OnMemoSend, OnMemoSend(u, nc, m));
@@ -297,13 +297,13 @@ void memo_send(User *u, const char *name, const char *text, int z)
NickAlias *na = *it;
User *user = finduser(na->nick);
if (user && user->IsIdentified())
- notice_lang(Config.s_MemoServ, user, MEMO_NEW_MEMO_ARRIVED, source, Config.s_MemoServ, m->number);
+ notice_lang(Config.s_MemoServ, user, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config.s_MemoServ.c_str(), m->number);
}
}
else
{
if ((u = finduser(name)) && u->IsIdentified() && nc->HasFlag(NI_MEMO_RECEIVE))
- notice_lang(Config.s_MemoServ, u, MEMO_NEW_MEMO_ARRIVED, source, Config.s_MemoServ, m->number);
+ notice_lang(Config.s_MemoServ, u, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config.s_MemoServ.c_str(), m->number);
} /* if (flags & MEMO_RECEIVE) */
}
/* if (MSNotifyAll) */
@@ -325,8 +325,8 @@ void memo_send(User *u, const char *name, const char *text, int z)
if (check_access(cu->user, c->ci, CA_MEMO))
{
- if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE) && !get_ignore(cu->user->nick.c_str()))
- notice_lang(Config.s_MemoServ, cu->user, MEMO_NEW_X_MEMO_ARRIVED, c->ci->name.c_str(), Config.s_MemoServ, c->ci->name.c_str(), m->number);
+ if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE) && !get_ignore(cu->user->nick))
+ notice_lang(Config.s_MemoServ, cu->user, MEMO_NEW_X_MEMO_ARRIVED, c->ci->name.c_str(), Config.s_MemoServ.c_str(), c->ci->name.c_str(), m->number);
}
}
} /* MSNotifyAll */
@@ -354,9 +354,8 @@ int delmemo(MemoInfo *mi, int num)
}
if (i < mi->memos.size())
{
- delete [] mi->memos[i]->text; /* Deallocate memo text memory */
delete mi->memos[i]; /* Deallocate the memo itself */
- mi->memos.erase(mi->memos.begin() + i); /* Remove the memo pointer from the vector */
+ mi->memos.erase(mi->memos.begin() + i); /* Remove the memo pointer from the vector */
return 1;
}
else
@@ -369,7 +368,7 @@ static bool SendMemoMail(NickCore *nc, Memo *m)
{
char message[BUFSIZE];
- snprintf(message, sizeof(message), getstring(NICK_MAIL_TEXT), nc->display, m->sender.c_str(), m->number, m->text);
+ snprintf(message, sizeof(message), getstring(NICK_MAIL_TEXT), nc->display.c_str(), m->sender.c_str(), m->number, m->text.c_str());
return Mail(nc, getstring(MEMO_MAIL_SUBJECT), message);
}
@@ -378,7 +377,7 @@ static bool SendMemoMail(NickCore *nc, Memo *m)
/* Send receipt notification to sender. */
-void rsend_notify(User *u, Memo *m, const char *chan)
+void rsend_notify(User *u, Memo *m, const Anope::string &chan)
{
NickAlias *na;
NickCore *nc;
@@ -402,10 +401,10 @@ void rsend_notify(User *u, Memo *m, const char *chan)
/* Text of the memo varies if the recepient was a
nick or channel */
- if (chan)
+ if (!chan.empty())
{
fmt = getstring(na, MEMO_RSEND_CHAN_MEMO_TEXT);
- snprintf(text, sizeof(text), fmt, chan);
+ snprintf(text, sizeof(text), fmt, chan.c_str());
}
else
{
@@ -414,11 +413,11 @@ void rsend_notify(User *u, Memo *m, const char *chan)
}
/* Send notification */
- memo_send(u, m->sender.c_str(), text, 2);
+ memo_send(u, m->sender, text, 2);
/* Notify recepient of the memo that a notification has
been sent to the sender */
- notice_lang(Config.s_MemoServ, u, MEMO_RSEND_USER_NOTIFICATION, nc->display);
+ notice_lang(Config.s_MemoServ, u, MEMO_RSEND_USER_NOTIFICATION, nc->display.c_str());
}
/* Remove receipt flag from the original memo */
diff --git a/src/messages.cpp b/src/messages.cpp
index 857229f65..49188ce93 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -15,7 +15,7 @@
/*************************************************************************/
-int m_nickcoll(const char *user)
+int m_nickcoll(const Anope::string &user)
{
introduce_user(user);
return MOD_CONT;
@@ -23,25 +23,25 @@ int m_nickcoll(const char *user)
/*************************************************************************/
-int m_away(const char *source, const char *msg)
+int m_away(const Anope::string &source, const Anope::string &msg)
{
User *u;
u = finduser(source);
- if (u && !msg) /* un-away */
+ if (u && msg.empty()) /* un-away */
check_memos(u);
return MOD_CONT;
}
/*************************************************************************/
-int m_kill(const std::string &nick, const char *msg)
+int m_kill(const Anope::string &nick, const Anope::string &msg)
{
BotInfo *bi;
/* Recover if someone kills us. */
- if (Config.s_BotServ && (bi = findbot(nick)))
+ if (!Config.s_BotServ.empty() && (bi = findbot(nick)))
{
introduce_user(nick);
bi->RejoinAll();
@@ -54,36 +54,36 @@ int m_kill(const std::string &nick, const char *msg)
/*************************************************************************/
-int m_time(const char *source, int ac, const char **av)
+int m_time(const Anope::string &source, int ac, const char **av)
{
time_t t;
struct tm *tm;
char buf[64];
- if (!source)
+ if (source.empty())
return MOD_CONT;
time(&t);
tm = localtime(&t);
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
- ircdproto->SendNumeric(Config.ServerName, 391, source, "%s :%s", Config.ServerName, buf);
+ ircdproto->SendNumeric(Config.ServerName, 391, source, "%s :%s", Config.ServerName.c_str(), buf);
return MOD_CONT;
}
/*************************************************************************/
-int m_motd(const char *source)
+int m_motd(const Anope::string &source)
{
FILE *f;
char buf[BUFSIZE];
- if (!source)
+ if (source.empty())
return MOD_CONT;
- f = fopen(Config.MOTDFilename, "r");
+ f = fopen(Config.MOTDFilename.c_str(), "r");
if (f)
{
- ircdproto->SendNumeric(Config.ServerName, 375, source, ":- %s Message of the Day", Config.ServerName);
+ ircdproto->SendNumeric(Config.ServerName, 375, source, ":- %s Message of the Day", Config.ServerName.c_str());
while (fgets(buf, sizeof(buf), f))
{
buf[strlen(buf) - 1] = 0;
@@ -99,9 +99,8 @@ int m_motd(const char *source)
/*************************************************************************/
-int m_privmsg(const std::string &source, const std::string &receiver, const std::string &message)
+int m_privmsg(const Anope::string &source, const Anope::string &receiver, const Anope::string &message)
{
- char *target;
time_t starttime, stoptime; /* When processing started and finished */
if (source.empty() || receiver.empty() || message.empty())
@@ -115,12 +114,12 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std:
BotInfo *bi = findbot(receiver);
if (bi)
- ircdproto->SendMessage(bi, source.c_str(), "%s", getstring(USER_RECORD_NOT_FOUND));
+ ircdproto->SendMessage(bi, source, "%s", getstring(USER_RECORD_NOT_FOUND));
return MOD_CONT;
}
- if (receiver[0] == '#' && Config.s_BotServ)
+ if (receiver[0] == '#' && !Config.s_BotServ.empty())
{
ChannelInfo *ci = cs_findchan(receiver);
if (ci)
@@ -135,30 +134,29 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std:
/* Check if we should ignore. Operators always get through. */
if (allow_ignore && !is_oper(u))
{
- if (get_ignore(source.c_str()))
+ if (get_ignore(source))
{
- target = myStrGetToken(message.c_str(), ' ', 0);
+ Anope::string target = myStrGetToken(message, ' ', 0);
Alog() << "Ignored message from " << source << " to " << receiver << " using command " << target;
- delete [] target;
return MOD_CONT;
}
}
/* If a server is specified (nick@server format), make sure it matches
* us, and strip it off. */
- std::string botname = receiver;
+ Anope::string botname = receiver;
size_t s = receiver.find('@');
- if (s != std::string::npos)
+ if (s != Anope::string::npos)
{
- ci::string servername(receiver.begin() + s + 1, receiver.end());
- botname = botname.erase(s);
- if (servername != Config.ServerName)
+ Anope::string servername(receiver.begin() + s + 1, receiver.end());
+ botname = botname.substr(0, s);
+ if (!servername.equals_ci(Config.ServerName))
return MOD_CONT;
}
else if (Config.UseStrictPrivMsg)
{
Alog(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source;
- notice_lang(receiver, u, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config.ServerName, receiver.c_str());
+ notice_lang(receiver, u, INVALID_TARGET, receiver.c_str(), receiver.c_str(), Config.ServerName.c_str(), receiver.c_str());
return MOD_CONT;
}
@@ -169,32 +167,31 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std:
if (bi)
{
- ci::string ci_bi_nick(bi->nick.c_str());
- if (ci_bi_nick == Config.s_OperServ)
+ if (bi->nick.equals_ci(Config.s_OperServ))
{
if (!is_oper(u) && Config.OSOpersOnly)
{
notice_lang(Config.s_OperServ, u, ACCESS_DENIED);
if (Config.WallBadOS)
- ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config.s_OperServ, u->nick.c_str(), u->GetIdent().c_str(), u->host);
+ ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config.s_OperServ.c_str(), u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str());
}
else
operserv(u, message);
}
- else if (ci_bi_nick == Config.s_NickServ)
+ else if (bi->nick.equals_ci(Config.s_NickServ))
nickserv(u, message);
- else if (ci_bi_nick == Config.s_ChanServ)
+ else if (bi->nick.equals_ci(Config.s_ChanServ))
{
if (!is_oper(u) && Config.CSOpersOnly)
notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
else
chanserv(u, message);
}
- else if (ci_bi_nick == Config.s_MemoServ)
+ else if (bi->nick.equals_ci(Config.s_MemoServ))
memoserv(u, message);
- else if (Config.s_HostServ && ci_bi_nick == Config.s_HostServ)
+ else if (!Config.s_HostServ.empty() && bi->nick.equals_ci(Config.s_HostServ))
hostserv(u, message);
- else if (Config.s_BotServ)
+ else if (!Config.s_BotServ.empty() && bi->nick.equals_ci(Config.s_BotServ))
botserv(u, bi, message);
}
@@ -202,8 +199,8 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std:
if (allow_ignore)
{
stoptime = time(NULL);
- if (stoptime > starttime && source.find('.') == std::string::npos)
- add_ignore(source.c_str(), stoptime - starttime);
+ if (stoptime > starttime && source.find('.') == Anope::string::npos)
+ add_ignore(source, stoptime - starttime);
}
}
@@ -212,7 +209,7 @@ int m_privmsg(const std::string &source, const std::string &receiver, const std:
/*************************************************************************/
-int m_stats(const char *source, int ac, const char **av)
+int m_stats(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -227,7 +224,7 @@ int m_stats(const char *source, int ac, const char **av)
if (u && is_oper(u))
{
ircdproto->SendNumeric(Config.ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- ircdproto->SendNumeric(Config.ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host, UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, time(NULL) - start_time);
+ ircdproto->SendNumeric(Config.ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, time(NULL) - start_time);
}
ircdproto->SendNumeric(Config.ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*');
@@ -240,11 +237,11 @@ int m_stats(const char *source, int ac, const char **av)
ircdproto->SendNumeric(Config.ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*');
else
{
- std::list<std::pair<ci::string, ci::string> >::iterator it, it_end;
+ std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end;
for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it)
{
- ci::string nick = it->first, type = it->second;
+ Anope::string nick = it->first, type = it->second;
NickCore *nc = findcore(nick);
if (nc)
@@ -273,28 +270,28 @@ int m_stats(const char *source, int ac, const char **av)
/*************************************************************************/
-int m_version(const char *source, int ac, const char **av)
+int m_version(const Anope::string &source, int ac, const char **av)
{
- if (source)
- ircdproto->SendNumeric(Config.ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
+ if (!source.empty())
+ ircdproto->SendNumeric(Config.ServerName, 351, source, "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
return MOD_CONT;
}
/*************************************************************************/
-int m_whois(const char *source, const char *who)
+int m_whois(const Anope::string &source, const Anope::string &who)
{
- if (source && who)
+ if (!source.empty() && !who.empty())
{
NickAlias *na;
BotInfo *bi = findbot(who);
if (bi)
{
- ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname);
+ ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str());
ircdproto->SendNumeric(Config.ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str());
- ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config.ServerName, Config.ServerDesc);
+ ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config.ServerName.c_str(), Config.ServerDesc.c_str());
ircdproto->SendNumeric(Config.ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), time(NULL) - bi->lastmsg, start_time);
- ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who);
+ ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str());
}
else if (!ircd->svshold && (na = findnick(who)) && na->HasFlag(NS_HELD))
{
@@ -302,12 +299,12 @@ int m_whois(const char *source, const char *who)
* We can't just say it doesn't exist here, even tho it does for
* other servers :) -GD
*/
- ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :Services Enforcer", na->nick, Config.NSEnforcerUser, Config.NSEnforcerHost);
- ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", na->nick, Config.ServerName, Config.ServerDesc);
- ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who);
+ ircdproto->SendNumeric(Config.ServerName, 311, source, "%s %s %s * :Services Enforcer", na->nick.c_str(), Config.NSEnforcerUser.c_str(), Config.NSEnforcerHost.c_str());
+ ircdproto->SendNumeric(Config.ServerName, 312, source, "%s %s :%s", na->nick.c_str(), Config.ServerName.c_str(), Config.ServerDesc.c_str());
+ ircdproto->SendNumeric(Config.ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str());
}
else
- ircdproto->SendNumeric(Config.ServerName, 401, source, "%s :No such service.", who);
+ ircdproto->SendNumeric(Config.ServerName, 401, source, "%s :No such service.", who.c_str());
}
return MOD_CONT;
}
diff --git a/src/misc.cpp b/src/misc.cpp
index eb8b28f83..0e838695d 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -30,7 +30,7 @@ struct arc4_stream
* @param filename The file
* @return true if the file exists, false if it doens't
*/
-bool IsFile(const std::string &filename)
+bool IsFile(const Anope::string &filename)
{
struct stat fileinfo;
if (!stat(filename.c_str(), &fileinfo))
@@ -72,29 +72,8 @@ int tolower(char c)
/*************************************************************************/
/**
- * Simple function to convert binary data to hex.
- * Taken from hybrid-ircd ( http://ircd-hybrid.com/ )
- */
-void binary_to_hex(unsigned char *bin, char *hex, int length)
-{
- static const char trans[] = "0123456789ABCDEF";
- int i;
-
- for (i = 0; i < length; ++i)
- {
- hex[i << 1] = trans[bin[i] >> 4];
- hex[(i << 1) + 1] = trans[bin[i] & 0xf];
- }
-
- hex[i << 1] = '\0';
-}
-
-
-/*************************************************************************/
-
-/**
* strscpy: Copy at most len-1 characters from a string to a buffer, and
- * add a null terminator after the last character copied.
+ * add a null terminator after the last character copied.
* @param d Buffer to copy into
* @param s Data to copy int
* @param len Length of data
@@ -114,38 +93,6 @@ char *strscpy(char *d, const char *s, size_t len)
/*************************************************************************/
/**
- * stristr: Search case-insensitively for string s2 within string s1,
- * returning the first occurrence of s2 or NULL if s2 was not
- * found.
- * @param s1 String 1
- * @param s2 String 2
- * @return first occurrence of s2
- */
-const char *stristr(const char *s1, const char *s2)
-{
- register const char *s = s1, *d = s2;
-
- while (*s1)
- {
- if (tolower(*s1) == tolower(*d))
- {
- ++s1;
- ++d;
- if (!*d)
- return s;
- }
- else
- {
- s = ++s1;
- d = s2;
- }
- }
- return NULL;
-}
-
-/*************************************************************************/
-
-/**
* strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop
* replacing if a replacement would cause the string to exceed
* `size' bytes (including the null terminator). Return the
@@ -223,11 +170,11 @@ const char *merge_args(int argc, char **argv)
/*************************************************************************/
-NumberList::NumberList(const std::string &list, bool descending) : desc(descending), is_valid(true)
+NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending)
{
- char *error;
+ Anope::string error;
commasepstream sep(list);
- std::string token;
+ Anope::string token;
sep.GetToken(token);
if (token.empty())
@@ -236,10 +183,10 @@ NumberList::NumberList(const std::string &list, bool descending) : desc(descendi
{
size_t t = token.find('-');
- if (t == std::string::npos)
+ if (t == Anope::string::npos)
{
- unsigned num = strtol(token.c_str(), &error, 10);
- if (!*error)
+ unsigned num = convertTo<unsigned>(token, error, false);
+ if (error.empty())
numbers.insert(num);
else
{
@@ -252,10 +199,10 @@ NumberList::NumberList(const std::string &list, bool descending) : desc(descendi
}
else
{
- char *error2;
- unsigned num1 = strtol(token.substr(0, t).c_str(), &error, 10);
- unsigned num2 = strtol(token.substr(t + 1).c_str(), &error2, 10);
- if (!*error && !*error2)
+ Anope::string error2;
+ unsigned num1 = convertTo<unsigned>(token.substr(0, t), error, false);
+ unsigned num2 = convertTo<unsigned>(token.substr(t + 1), error2, false);
+ if (error.empty() && error2.empty())
{
for (unsigned i = num1; i <= num2; ++i)
numbers.insert(i);
@@ -299,7 +246,7 @@ void NumberList::HandleNumber(unsigned)
{
}
-bool NumberList::InvalidRange(const std::string &)
+bool NumberList::InvalidRange(const Anope::string &)
{
return true;
}
@@ -315,17 +262,18 @@ bool NumberList::InvalidRange(const std::string &)
* @param s String to convert
* @return time_t
*/
-time_t dotime(const char *s)
+time_t dotime(const Anope::string &s)
{
int amount;
- if (!s || !*s)
+ if (s.empty())
return -1;
- amount = strtol(s, const_cast<char **>(&s), 10);
- if (*s)
+ Anope::string end;
+ amount = convertTo<int>(s, end, false);
+ if (!end.empty())
{
- switch (*s)
+ switch (end[0])
{
case 's':
return amount;
@@ -353,17 +301,16 @@ time_t dotime(const char *s)
* Expresses in a string the period of time represented by a given amount
* of seconds (with days/hours/minutes).
* @param na Nick Alias
- * @param buf buffer to store result into
- * @param bufsize Size of the buffer
* @param seconds time in seconds
* @return buffer
*/
-const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds)
+Anope::string duration(const NickCore *nc, time_t seconds)
{
int days = 0, hours = 0, minutes = 0;
int need_comma = 0;
- char buf2[64], *end;
+ char buf[64];
+ Anope::string buffer;
const char *comma = getstring(nc, COMMA_SPACE);
/* We first calculate everything */
@@ -374,31 +321,32 @@ const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds)
minutes = seconds / 60;
if (!days && !hours && !minutes)
- snprintf(buf, bufsize, getstring(nc, seconds <= 1 ? DURATION_SECOND : DURATION_SECONDS), seconds);
+ {
+ snprintf(buf, sizeof(buf), getstring(nc, seconds <= 1 ? DURATION_SECOND : DURATION_SECONDS), seconds);
+ buffer = buf;
+ }
else
{
- end = buf;
if (days)
{
- snprintf(buf2, sizeof(buf2), getstring(nc, days == 1 ? DURATION_DAY : DURATION_DAYS), days);
- end += snprintf(end, bufsize - (end - buf), "%s", buf2);
+ snprintf(buf, sizeof(buf), getstring(nc, days == 1 ? DURATION_DAY : DURATION_DAYS), days);
+ buffer = buf;
need_comma = 1;
}
if (hours)
{
- snprintf(buf2, sizeof(buf2), getstring(nc, hours == 1 ? DURATION_HOUR : DURATION_HOURS), hours);
- end += snprintf(end, bufsize - (end - buf), "%s%s", need_comma ? comma : "", buf2);
+ snprintf(buf, sizeof(buf), getstring(nc, hours == 1 ? DURATION_HOUR : DURATION_HOURS), hours);
+ buffer += Anope::string(need_comma ? comma : "") + buf;
need_comma = 1;
}
if (minutes)
{
- snprintf(buf2, sizeof(buf2), getstring(nc, minutes == 1 ? DURATION_MINUTE : DURATION_MINUTES), minutes);
- end += snprintf(end, bufsize - (end - buf), "%s%s", need_comma ? comma : "", buf2);
- need_comma = 1;
+ snprintf(buf, sizeof(buf), getstring(nc, minutes == 1 ? DURATION_MINUTE : DURATION_MINUTES), minutes);
+ buffer += Anope::string(need_comma ? comma : "") + buf;
}
}
- return buf;
+ return buffer;
}
/*************************************************************************/
@@ -406,19 +354,19 @@ const char *duration(NickCore *nc, char *buf, int bufsize, time_t seconds)
/**
* Generates a human readable string of type "expires in ..."
* @param na Nick Alias
- * @param buf buffer to store result into
- * @param bufsize Size of the buffer
* @param seconds time in seconds
* @return buffer
*/
-const char *expire_left(NickCore *nc, char *buf, int len, time_t expires)
+Anope::string expire_left(const NickCore *nc, time_t expires)
{
time_t now = time(NULL);
+ char buf[256];
+
if (!expires)
- strlcpy(buf, getstring(nc, NO_EXPIRE), len);
+ strlcpy(buf, getstring(nc, NO_EXPIRE), sizeof(buf));
else if (expires <= now)
- strlcpy(buf, getstring(nc, EXPIRES_SOON), len);
+ strlcpy(buf, getstring(nc, EXPIRES_SOON), sizeof(buf));
else
{
time_t diff = expires - now + 59;
@@ -426,21 +374,21 @@ const char *expire_left(NickCore *nc, char *buf, int len, time_t expires)
if (diff >= 86400)
{
int days = diff / 86400;
- snprintf(buf, len, getstring(nc, days == 1 ? EXPIRES_1D : EXPIRES_D), days);
+ snprintf(buf, sizeof(buf), getstring(nc, days == 1 ? EXPIRES_1D : EXPIRES_D), days);
}
else
{
if (diff <= 3600)
{
int minutes = diff / 60;
- snprintf(buf, len, getstring(nc, minutes == 1 ? EXPIRES_1M : EXPIRES_M), minutes);
+ snprintf(buf, sizeof(buf), getstring(nc, minutes == 1 ? EXPIRES_1M : EXPIRES_M), minutes);
}
else
{
int hours = diff / 3600, minutes;
diff -= hours * 3600;
minutes = diff / 60;
- snprintf(buf, len, getstring(nc, hours == 1 && minutes == 1 ? EXPIRES_1H1M : (hours == 1 && minutes != 1 ? EXPIRES_1HM : (hours != 1 && minutes == 1 ? EXPIRES_H1M : EXPIRES_HM))), hours, minutes);
+ snprintf(buf, sizeof(buf), getstring(nc, hours == 1 && minutes == 1 ? EXPIRES_1H1M : (hours == 1 && minutes != 1 ? EXPIRES_1HM : (hours != 1 && minutes == 1 ? EXPIRES_H1M : EXPIRES_HM))), hours, minutes);
}
}
}
@@ -448,19 +396,18 @@ const char *expire_left(NickCore *nc, char *buf, int len, time_t expires)
return buf;
}
-
/*************************************************************************/
/**
* Validate the host
* shortname = ( letter / digit ) *( letter / digit / "-" ) *( letter / digit )
* hostname = shortname *( "." shortname )
- * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit
+ * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit
* @param host = string to check
* @param type = format, 1 = ip4addr, 2 = hostname
* @return 1 if a host is valid, 0 if it isnt.
*/
-int doValidHost(const char *host, int type)
+int doValidHost(const Anope::string &host, int type)
{
int idx = 0;
int len = 0;
@@ -468,10 +415,10 @@ int doValidHost(const char *host, int type)
int dots = 1;
if (type != 1 && type != 2)
return 0;
- if (!host)
+ if (host.empty())
return 0;
- len = strlen(host);
+ len = host.length();
if (len > Config.HostLen)
return 0;
@@ -539,7 +486,7 @@ int doValidHost(const char *host, int type)
* @param type = format, 1 = ip4addr, 2 = hostname
* @return 1 if a host is valid, 0 if it isnt.
*/
-int isValidHost(const char *host, int type)
+int isValidHost(const Anope::string &host, int type)
{
int status = 0;
if (type == 3)
@@ -576,54 +523,18 @@ int isvalidchar(const char c)
* @param token_number the token number
* @return token
*/
-char *myStrGetToken(const char *str, const char dilim, int token_number)
+Anope::string myStrGetToken(const Anope::string &str, char delim, int token_number)
{
- int len, idx, counter = 0, start_pos = 0;
- char *substring = NULL;
- if (!str)
- return NULL;
- len = strlen(str);
- for (idx = 0; idx <= len; ++idx)
- {
- if (str[idx] == dilim || idx == len)
- {
- if (counter == token_number)
- substring = myStrSubString(str, start_pos, idx);
- else
- start_pos = idx + 1;
- ++counter;
- }
- }
- return substring;
-}
+ if (str.empty())
+ return "";
-/*************************************************************************/
-
-/**
- * Get the token only
- * @param str String to search in
- * @param dilim Character to search for
- * @param token_number the token number
- * @return token
- */
-char *myStrGetOnlyToken(const char *str, const char dilim, int token_number)
-{
- int len, idx, counter = 0, start_pos = 0;
- char *substring = NULL;
- if (!str)
- return NULL;
- len = strlen(str);
- for (idx = 0; idx <= len; ++idx)
+ Anope::string substring;
+ for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx)
{
- if (str[idx] == dilim)
+ if (str[idx] == delim || idx == len)
{
if (counter == token_number)
- {
- if (str[idx] == '\r')
- substring = myStrSubString(str, start_pos, idx - 1);
- else
- substring = myStrSubString(str, start_pos, idx);
- }
+ substring = str.substr(start_pos, idx - start_pos - 1);
else
start_pos = idx + 1;
++counter;
@@ -641,20 +552,18 @@ char *myStrGetOnlyToken(const char *str, const char dilim, int token_number)
* @param token_number the token number
* @return token
*/
-char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number)
+Anope::string myStrGetTokenRemainder(const Anope::string &str, const char dilim, int token_number)
{
- int len, idx, counter = 0, start_pos = 0;
- char *substring = NULL;
- if (!str)
- return NULL;
- len = strlen(str);
+ if (str.empty())
+ return "";
- for (idx = 0; idx <= len; ++idx)
+ Anope::string substring;
+ for (size_t idx = 0, len = str.length(), start_pos = 0, counter = 0; idx <= len; ++idx)
{
if (str[idx] == dilim || idx == len)
{
if (counter == token_number)
- substring = myStrSubString(str, start_pos, len);
+ substring = str.substr(start_pos);
else
start_pos = idx + 1;
++counter;
@@ -666,32 +575,6 @@ char *myStrGetTokenRemainder(const char *str, const char dilim, int token_number
/*************************************************************************/
/**
- * Get the string between point A and point B
- * @param str String to search in
- * @param start Point A
- * @param end Point B
- * @return the string in between
- */
-char *myStrSubString(const char *src, int start, int end)
-{
- char *substring = NULL;
- int len, idx;
- if (!src)
- return NULL;
- len = strlen(src);
- if (start >= 0 && end <= len && end > start)
- {
- substring = new char[(end - start) + 1];
- for (idx = 0; idx <= end - start; ++idx)
- substring[idx] = src[start + idx];
- substring[end - start] = '\0';
- }
- return substring;
-}
-
-/*************************************************************************/
-
-/**
* Clean up the buffer for extra spaces
* @param str to clean up
* @return void
@@ -733,17 +616,17 @@ void doCleanBuffer(char *str)
* @param killer whom is doing the killing
* @return void
*/
-void EnforceQlinedNick(const std::string &nick, const char *killer)
+void EnforceQlinedNick(const Anope::string &nick, const Anope::string &killer)
{
if (findbot(nick))
return;
-
+
User *u2 = finduser(nick);
if (u2)
{
Alog() << "Killed Q-lined nick: " << u2->GetMask();
- kill_user(killer, u2->nick.c_str(), "This nick is reserved for Services. Please use a non Q-Lined nick.");
+ kill_user(killer, u2->nick, "This nick is reserved for Services. Please use a non Q-Lined nick.");
}
}
@@ -755,49 +638,45 @@ void EnforceQlinedNick(const std::string &nick, const char *killer)
* @param int Check if botserv bots
* @return int
*/
-int nickIsServices(const char *tempnick, int bot)
+int nickIsServices(const Anope::string &tempnick, int bot)
{
int found = 0;
- char *s, *nick;
- if (!tempnick)
+ if (tempnick.empty())
return found;
- nick = sstrdup(tempnick);
+ Anope::string nick = tempnick;
- s = strchr(nick, '@');
- if (s)
+ size_t at = nick.find('@');
+ if (at != Anope::string::npos)
{
- *s++ = 0;
- if (stricmp(s, Config.ServerName))
- {
- delete [] nick;
+ Anope::string servername = nick.substr(at + 1);
+ if (!servername.equals_ci(Config.ServerName))
return found;
- }
+ nick = nick.substr(0, at);
}
- if (Config.s_NickServ && !stricmp(nick, Config.s_NickServ))
+ if (!Config.s_NickServ.empty() && nick.equals_ci(Config.s_NickServ))
++found;
- else if (Config.s_ChanServ && !stricmp(nick, Config.s_ChanServ))
+ else if (!Config.s_ChanServ.empty() && nick.equals_ci(Config.s_ChanServ))
++found;
- else if (Config.s_HostServ && !stricmp(nick, Config.s_HostServ))
+ else if (!Config.s_HostServ.empty() && nick.equals_ci(Config.s_HostServ))
++found;
- else if (Config.s_MemoServ && !stricmp(nick, Config.s_MemoServ))
+ else if (!Config.s_MemoServ.empty() && nick.equals_ci(Config.s_MemoServ))
++found;
- else if (Config.s_BotServ && !stricmp(nick, Config.s_BotServ))
+ else if (!Config.s_BotServ.empty() && nick.equals_ci(Config.s_BotServ))
++found;
- else if (Config.s_OperServ && !stricmp(nick, Config.s_OperServ))
+ else if (!Config.s_OperServ.empty() && nick.equals_ci(Config.s_OperServ))
++found;
- else if (Config.s_GlobalNoticer && !stricmp(nick, Config.s_GlobalNoticer))
+ else if (!Config.s_GlobalNoticer.empty() && nick.equals_ci(Config.s_GlobalNoticer))
++found;
- else if (Config.s_BotServ && bot)
+ else if (!Config.s_BotServ.empty() && bot)
{
for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
- ci::string ci_bi_nick(bi->nick.c_str());
- if (ci_bi_nick == nick)
+ if (nick.equals_ci(bi->nick))
{
++found;
break;
@@ -805,9 +684,6 @@ int nickIsServices(const char *tempnick, int bot)
}
}
- /* Somehow, something tells me we should free this :) -GD */
- delete [] nick;
-
return found;
}
@@ -967,20 +843,14 @@ uint32 getrandom32()
* @param dilim Dilimiter
* @return number of tokens
*/
-int myNumToken(const char *str, const char dilim)
+int myNumToken(const Anope::string &str, char dilim)
{
- int len, idx, counter = 0, start_pos = 0;
- if (!str)
+ if (str.empty())
return 0;
- len = strlen(str);
- for (idx = 0; idx <= len; ++idx)
- {
+ int counter = 0;
+ for (size_t idx = 0, len = str.length(); idx <= len; ++idx)
if (str[idx] == dilim || idx == len)
- {
- start_pos = idx + 1;
++counter;
- }
- }
return counter;
}
@@ -991,24 +861,22 @@ int myNumToken(const char *str, const char dilim)
* @param host to convert
* @return ip address
*/
-char *host_resolve(char *host)
+Anope::string host_resolve(const Anope::string &host)
{
struct hostent *hentp = NULL;
uint32 ip = INADDR_NONE;
char ipbuf[16];
- char *ipreturn;
+ Anope::string ipreturn;
struct in_addr addr;
- ipreturn = NULL;
-
- hentp = gethostbyname(host);
+ hentp = gethostbyname(host.c_str());
if (hentp)
{
memcpy(&ip, hentp->h_addr, sizeof(hentp->h_length));
addr.s_addr = ip;
ntoa(addr, ipbuf, sizeof(ipbuf));
- ipreturn = sstrdup(ipbuf);
+ ipreturn = ipbuf;
Alog(LOG_DEBUG) << "resolved " << host << " to " << ipbuf;
}
return ipreturn;
@@ -1020,11 +888,11 @@ char *host_resolve(char *host)
* @param src The source string
* @return a list of strings
*/
-std::list<std::string> BuildStringList(const std::string &src)
+std::list<Anope::string> BuildStringList(const Anope::string &src)
{
spacesepstream tokens(src);
- std::string token;
- std::list<std::string> Ret;
+ Anope::string token;
+ std::list<Anope::string> Ret;
while (tokens.GetToken(token))
Ret.push_back(token);
@@ -1032,23 +900,11 @@ std::list<std::string> BuildStringList(const std::string &src)
return Ret;
}
-std::list<ci::string> BuildStringList(const ci::string &src)
+std::vector<Anope::string> BuildStringVector(const Anope::string &src)
{
spacesepstream tokens(src);
- ci::string token;
- std::list<ci::string> Ret;
-
- while (tokens.GetToken(token))
- Ret.push_back(token);
-
- return Ret;
-}
-
-std::vector<std::string> BuildStringVector(const std::string &src)
-{
- spacesepstream tokens(src);
- std::string token;
- std::vector<std::string> Ret;
+ Anope::string token;
+ std::vector<Anope::string> Ret;
while (tokens.GetToken(token))
Ret.push_back(token);
@@ -1073,25 +929,13 @@ char *str_signed(unsigned char *str)
while (*str)
{
*nstr = static_cast<char>(*str);
- str++;
- nstr++;
+ ++str;
+ ++nstr;
}
return nstr;
}
-/**
- * Strip the mode prefix from the given string.
- * Useful for using the modes stored in things like ircd->ownerset etc..
- **/
-
-char *stripModePrefix(const char *str)
-{
- if (str && (*str == '+' || *str == '-'))
- return sstrdup(str + 1);
- return NULL;
-}
-
/* Equivalent to inet_ntoa */
void ntoa(struct in_addr addr, char *ipaddr, int len)
@@ -1194,36 +1038,32 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
#endif
#ifdef _WIN32
-char *GetWindowsVersion()
+Anope::string GetWindowsVersion()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
- char buf[BUFSIZE];
- char *extra;
- char *cputype;
+ Anope::string buf, extra, cputype;
SYSTEM_INFO si;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
ZeroMemory(&si, sizeof(SYSTEM_INFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi)))
+ if (!(bOsVersionInfoEx = GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi))))
{
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if (!GetVersionEx((OSVERSIONINFO *)&osvi))
- return sstrdup("");
+ if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi)))
+ return "";
}
GetSystemInfo(&si);
/* Determine CPU type 32 or 64 */
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- cputype = sstrdup(" 64-bit");
+ cputype = " 64-bit";
else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
- cputype = sstrdup(" 32-bit");
+ cputype = " 32-bit";
else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- cputype = sstrdup(" Itanium 64-bit");
- else
- cputype = sstrdup(" ");
+ cputype = " Itanium 64-bit";
switch (osvi.dwPlatformId)
{
@@ -1233,96 +1073,78 @@ char *GetWindowsVersion()
if (osvi.dwMajorVersion == 6 && !osvi.dwMinorVersion)
{
if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- extra = sstrdup("Enterprise Edition");
+ extra = " Enterprise Edition";
else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- extra = sstrdup("Datacenter Edition");
+ extra = " Datacenter Edition";
else if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
- extra = sstrdup("Home Premium/Basic");
- else
- extra = sstrdup(" ");
+ extra = " Home Premium/Basic";
if (osvi.wProductType & VER_NT_WORKSTATION)
- snprintf(buf, sizeof(buf), "Microsoft Windows Vista %s%s", cputype, extra);
+ buf = "Microsoft Windows Vista" + cputype + extra;
else
- snprintf(buf, sizeof(buf), "Microsoft Windows Server 2008 %s%s", cputype, extra);
- delete [] extra;
+ buf = "Microsoft Windows Server 2008" + cputype + extra;
}
/* Windows 2003 or Windows XP Pro 64 */
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
{
if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- extra = sstrdup("Datacenter Edition");
+ extra = " Datacenter Edition";
else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- extra = sstrdup("Enterprise Edition");
+ extra = " Enterprise Edition";
#ifdef VER_SUITE_COMPUTE_SERVER
else if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
- extra = sstrdup("Compute Cluster Edition");
+ extra = " Compute Cluster Edition";
#endif
else if (osvi.wSuiteMask == VER_SUITE_BLADE)
- extra = sstrdup("Web Edition");
+ extra = " Web Edition";
else
- extra = sstrdup("Standard Edition");
+ extra = " Standard Edition";
if (osvi.wProductType & VER_NT_WORKSTATION && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- snprintf(buf, sizeof(buf), "Windows XP Professional x64 Edition %s", extra);
+ buf = "Microsoft Windows XP Professional x64 Edition" + extra;
else
- snprintf(buf, sizeof(buf), "Microsoft Windows Server 2003 Family %s%s", cputype, extra);
- delete [] extra;
+ buf = "Microsoft Windows Server 2003 Family" + cputype + extra;
}
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
{
if (osvi.wSuiteMask & VER_SUITE_EMBEDDEDNT)
- extra = sstrdup("Embedded");
+ extra = " Embedded";
else if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
- extra = sstrdup("Home Edition");
- else
- extra = sstrdup(" ");
- snprintf(buf, sizeof(buf), "Microsoft Windows XP %s", extra);
- delete [] extra;
+ extra = " Home Edition";
+ buf = "Microsoft Windows XP" + extra;
}
if (osvi.dwMajorVersion == 5 && !osvi.dwMinorVersion)
{
if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- extra = sstrdup("Datacenter Server");
+ extra = " Datacenter Server";
else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- extra = sstrdup("Advanced Server");
+ extra = " Advanced Server";
else
- extra = sstrdup("Server");
- snprintf(buf, sizeof(buf), "Microsoft Windows 2000 %s", extra);
- delete [] extra;
+ extra = " Server";
+ buf = "Microsoft Windows 2000" + extra;
}
if (osvi.dwMajorVersion <= 4)
{
if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- extra = sstrdup("Server 4.0, Enterprise Edition");
- else
- extra = sstrdup("Server 4.0");
- snprintf(buf, sizeof(buf), "Microsoft Windows NT %s", extra);
- delete [] extra;
+ extra = " Enterprise Edition";
+ buf = "Microsoft Windows NT Server 4.0" + extra;
}
break;
case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4 && !osvi.dwMinorVersion)
{
if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B')
- extra = sstrdup("OSR2");
- else
- extra = sstrdup(" ");
- snprintf(buf, sizeof(buf), "Microsoft Windows 95 %s", extra);
- delete [] extra;
+ extra = " OSR2";
+ buf = "Microsoft Windows 95" + extra;
}
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
{
if (osvi.szCSDVersion[1] == 'A')
- extra = sstrdup("SE");
- else
- extra = sstrdup(" ");
- snprintf(buf, sizeof(buf), "Microsoft Windows 98 %s", extra);
- delete [] extra;
+ extra = "SE";
+ buf = "Microsoft Windows 98" + extra;
}
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
- snprintf(buf, sizeof(buf), "Microsoft Windows Millennium Edition");
+ buf = "Microsoft Windows Millenium Edition";
}
- delete [] cputype;
- return sstrdup(buf);
+ return buf;
}
int SupportedWindowsVersion()
@@ -1333,10 +1155,10 @@ int SupportedWindowsVersion()
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi)))
+ if (!(bOsVersionInfoEx = GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi))))
{
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if (!GetVersionEx((OSVERSIONINFO *)&osvi))
+ if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&osvi)))
return 0;
}
@@ -1396,14 +1218,11 @@ uint16 netmask_to_cidr(uint32 mask)
* @param str String to check
* @return 1 for wildcard, 0 for anything else
*/
-int str_is_wildcard(const char *str)
+int str_is_wildcard(const Anope::string &str)
{
- while (*str)
- {
- if (*str == '*' || *str == '?')
+ for (Anope::string::const_iterator c = str.begin(), c_end = str.end(); c != c_end; ++c)
+ if (*c == '*' || *c == '?')
return 1;
- ++str;
- }
return 0;
}
@@ -1413,14 +1232,11 @@ int str_is_wildcard(const char *str)
* @param str String to check
* @return 1 for pure wildcard, 0 for anything else
*/
-int str_is_pure_wildcard(const char *str)
+int str_is_pure_wildcard(const Anope::string &str)
{
- while (*str)
- {
- if (*str != '*')
+ for (Anope::string::const_iterator c = str.begin(), c_end = str.end(); c != c_end; ++c)
+ if (*c != '*')
return 0;
- ++str;
- }
return 1;
}
@@ -1432,21 +1248,19 @@ int str_is_pure_wildcard(const char *str)
* @param str String to check
* @return The IP, if one found. 0 if none.
*/
-uint32 str_is_ip(char *str)
+uint32 str_is_ip(const Anope::string &str)
{
int i;
int octets[4] = { -1, -1, -1, -1 };
- char *s = str;
+ Anope::string s = str;
uint32 ip;
for (i = 0; i < 4; ++i)
{
- octets[i] = strtol(s, &s, 10);
+ octets[i] = convertTo<int>(s, s, false);
/* Bail out if the octet is invalid or wrongly terminated */
- if (octets[i] < 0 || octets[i] > 255 || (i < 3 && *s != '.'))
+ if (octets[i] < 0 || octets[i] > 255 || (i < 3 && s[0] != '.'))
return 0;
- if (i < 3)
- ++s;
}
/* Fill the IP - the dirty way */
@@ -1469,22 +1283,19 @@ uint32 str_is_ip(char *str)
* @param host Displayed host
* @return 1 for IP/CIDR, 0 for anything else
*/
-int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host)
+int str_is_cidr(const Anope::string &str, uint32 *ip, uint32 *mask, Anope::string &host)
{
int i;
int octets[4] = { -1, -1, -1, -1 };
- char *s = str;
- char buf[512];
+ Anope::string s = str;
uint16 cidr;
for (i = 0; i < 4; ++i)
{
- octets[i] = strtol(s, &s, 10);
+ octets[i] = convertTo<int>(s, s, false);
/* Bail out if the octet is invalid or wrongly terminated */
- if (octets[i] < 0 || octets[i] > 255 || (i < 3 && *s != '.'))
+ if (octets[i] < 0 || octets[i] > 255 || (i < 3 && s[0] != '.'))
return 0;
- if (i < 3)
- ++s;
}
/* Fill the IP - the dirty way */
@@ -1493,13 +1304,12 @@ int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host)
*ip += octets[1] * 65536;
*ip += octets[0] * 16777216;
- if (*s == '/')
+ if (s[0] == '/')
{
- ++s;
/* There's a CIDR mask here! */
- cidr = strtol(s, &s, 10);
+ cidr = convertTo<uint16>(s.substr(1), s, false);
/* Bail out if the CIDR is invalid or the string isn't done yet */
- if (cidr > 32 || *s)
+ if (cidr > 32 || s[0])
return 0;
}
else
@@ -1516,12 +1326,9 @@ int str_is_cidr(char *str, uint32 *ip, uint32 *mask, char **host)
octets[2] = (*ip & 0x0000FF00) / 256;
octets[3] = (*ip & 0x000000FF);
- if (cidr == 32)
- snprintf(buf, 512, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]);
- else
- snprintf(buf, 512, "%d.%d.%d.%d/%d", octets[0], octets[1], octets[2], octets[3], cidr);
-
- *host = sstrdup(buf);
+ host = stringify(octets[0]) + "." + stringify(octets[1]) + "." + stringify(octets[2]) + "." + stringify(octets[3]);
+ if (cidr != 32)
+ host += "/" + stringify(cidr);
return 1;
}
diff --git a/src/modes.cpp b/src/modes.cpp
index 38ac2ad00..3642b977e 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -32,7 +32,7 @@ Flags<ChannelModeName, CMODE_END> DefMLockOn;
/* Default mlocked modes off */
Flags<ChannelModeName, CMODE_END> DefMLockOff;
/* Map for default mlocked mode parameters */
-std::map<ChannelModeName, std::string> DefMLockParams;
+std::map<ChannelModeName, Anope::string> DefMLockParams;
/* Modes to set on bots when they join the channel */
std::list<ChannelModeStatus *> BotModes;
@@ -45,11 +45,11 @@ void SetDefaultMLock()
DefMLockParams.clear();
Flags<ChannelModeName, CMODE_END> *ptr = NULL;
- std::string modes, param;
+ Anope::string modes, param;
spacesepstream sep(Config.MLock);
sep.GetToken(modes);
- for (unsigned i = 0, end_mode = modes.size(); i < end_mode; ++i)
+ for (unsigned i = 0, end_mode = modes.length(); i < end_mode; ++i)
{
if (modes[i] == '+')
ptr = &DefMLockOn;
@@ -82,7 +82,7 @@ void SetDefaultMLock()
/* Set Bot Modes */
BotModes.clear();
- for (unsigned i = 0, end_mode = Config.BotModes.size(); i < end_mode; ++i)
+ for (unsigned i = 0, end_mode = Config.BotModes.length(); i < end_mode; ++i)
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(Config.BotModes[i]);
@@ -97,7 +97,7 @@ void SetDefaultMLock()
* @param modeChar The mode char
* @param modeType The mode type
*/
-Mode::Mode(ModeClass mClass, const std::string &mNameAsString, char modeChar, ModeType modeType) : Class(mClass), NameAsString(mNameAsString), ModeChar(modeChar), Type(modeType)
+Mode::Mode(ModeClass mClass, const Anope::string &mNameAsString, char modeChar, ModeType modeType) : Class(mClass), NameAsString(mNameAsString), ModeChar(modeChar), Type(modeType)
{
}
@@ -112,7 +112,7 @@ Mode::~Mode()
* @param mNameAsString The mode name as a string
* @param modeChar The mode char
*/
-UserMode::UserMode(UserModeName mName, const std::string &mNameAsString, char modeChar) : Mode(MC_USER, mNameAsString, modeChar, MODE_REGULAR), Name(mName)
+UserMode::UserMode(UserModeName mName, const Anope::string &mNameAsString, char modeChar) : Mode(MC_USER, mNameAsString, modeChar, MODE_REGULAR), Name(mName)
{
}
@@ -127,7 +127,7 @@ UserMode::~UserMode()
* @param mNameAsString The mode name as a string
* @param modeChar The mode char
*/
-UserModeParam::UserModeParam(UserModeName mName, const std::string &mNameAsString, char modeChar) : UserMode(mName, mNameAsString, modeChar)
+UserModeParam::UserModeParam(UserModeName mName, const Anope::string &mNameAsString, char modeChar) : UserMode(mName, mNameAsString, modeChar)
{
this->Type = MODE_PARAM;
}
@@ -137,7 +137,7 @@ UserModeParam::UserModeParam(UserModeName mName, const std::string &mNameAsStrin
* @param mNameAsString The mode name as a string
* @param modeChar The mode char
*/
-ChannelMode::ChannelMode(ChannelModeName mName, const std::string &mNameAsString, char modeChar) : Mode(MC_CHANNEL, mNameAsString, modeChar, MODE_REGULAR), Name(mName)
+ChannelMode::ChannelMode(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar) : Mode(MC_CHANNEL, mNameAsString, modeChar, MODE_REGULAR), Name(mName)
{
}
@@ -152,7 +152,7 @@ ChannelMode::~ChannelMode()
* @param mNameAsString The mode name as a string
* @param modeChar The mode char
*/
-ChannelModeList::ChannelModeList(ChannelModeName mName, const std::string &mNameAsString, char modeChar) : ChannelMode(mName, mNameAsString, modeChar)
+ChannelModeList::ChannelModeList(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar) : ChannelMode(mName, mNameAsString, modeChar)
{
this->Type = MODE_LIST;
}
@@ -169,7 +169,7 @@ ChannelModeList::~ChannelModeList()
* @param modeChar The mode char
* @param MinusArg true if the mode sends no arg when unsetting
*/
-ChannelModeParam::ChannelModeParam(ChannelModeName mName, const std::string &mNameAsString, char modeChar, bool MinusArg) : ChannelMode(mName, mNameAsString, modeChar), MinusNoArg(MinusArg)
+ChannelModeParam::ChannelModeParam(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, bool MinusArg) : ChannelMode(mName, mNameAsString, modeChar), MinusNoArg(MinusArg)
{
this->Type = MODE_PARAM;
}
@@ -186,7 +186,7 @@ ChannelModeParam::~ChannelModeParam()
* @param modeChar The mode char
* @param mSymbol The symbol for the mode, eg @ % +
*/
-ChannelModeStatus::ChannelModeStatus(ChannelModeName mName, const std::string &mNameAsString, char modeChar, char mSymbol) : ChannelMode(mName, mNameAsString, modeChar), Symbol(mSymbol)
+ChannelModeStatus::ChannelModeStatus(ChannelModeName mName, const Anope::string &mNameAsString, char modeChar, char mSymbol) : ChannelMode(mName, mNameAsString, modeChar), Symbol(mSymbol)
{
this->Type = MODE_STATUS;
}
@@ -201,9 +201,9 @@ ChannelModeStatus::~ChannelModeStatus()
* @param value The key
* @return true or false
*/
-bool ChannelModeKey::IsValid(const std::string &value)
+bool ChannelModeKey::IsValid(const Anope::string &value)
{
- if (!value.empty() && value.find(':') != std::string::npos && value.find(',') != std::string::npos)
+ if (!value.empty() && value.find(':') != Anope::string::npos && value.find(',') != Anope::string::npos)
return true;
return false;
@@ -246,12 +246,12 @@ bool ChannelModeRegistered::CanSet(User *u)
* @param chan The channel
* @param mask The ban
*/
-void ChannelModeBan::AddMask(Channel *chan, const char *mask)
+void ChannelModeBan::AddMask(Channel *chan, const Anope::string &mask)
{
Entry *ban;
/* check for NULL values otherwise we will segfault */
- if (!chan || !mask)
+ if (!chan || mask.empty())
{
Alog(LOG_DEBUG) << "add_ban called with NULL values";
return;
@@ -268,13 +268,13 @@ void ChannelModeBan::AddMask(Channel *chan, const char *mask)
/* Check whether it matches a botserv bot after adding internally
* and parsing it through cidr support. ~ Viper */
- if (Config.s_BotServ && Config.BSSmartJoin && chan->ci && chan->ci->bi && chan->FindUser(chan->ci->bi))
+ if (!Config.s_BotServ.empty() && Config.BSSmartJoin && chan->ci && chan->ci->bi && chan->FindUser(chan->ci->bi))
{
BotInfo *bi = chan->ci->bi;
- if (entry_match(ban, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, 0))
+ if (entry_match(ban, bi->nick, bi->GetIdent(), bi->host, 0))
{
- ircdproto->SendMode(bi, chan, "-b %s", mask);
+ ircdproto->SendMode(bi, chan, "-b %s", mask.c_str());
entry_delete(chan->bans, ban);
return;
}
@@ -287,13 +287,13 @@ void ChannelModeBan::AddMask(Channel *chan, const char *mask)
* @param chan The channel
* @param mask The ban
*/
-void ChannelModeBan::DelMask(Channel *chan, const char *mask)
+void ChannelModeBan::DelMask(Channel *chan, const Anope::string &mask)
{
AutoKick *akick;
Entry *ban;
/* Sanity check as it seems some IRCD will just send -b without a mask */
- if (!mask || !chan->bans || !chan->bans->count)
+ if (mask.empty() || !chan->bans || !chan->bans->count)
return;
ban = elist_find_mask(chan->bans, mask);
@@ -313,11 +313,11 @@ void ChannelModeBan::DelMask(Channel *chan, const char *mask)
* @param chan The channel
* @param mask The except
*/
-void ChannelModeExcept::AddMask(Channel *chan, const char *mask)
+void ChannelModeExcept::AddMask(Channel *chan, const Anope::string &mask)
{
Entry *exception;
- if (!chan || !mask)
+ if (!chan || mask.empty())
{
Alog(LOG_DEBUG) << "add_exception called with NULL values";
return;
@@ -339,12 +339,12 @@ void ChannelModeExcept::AddMask(Channel *chan, const char *mask)
* @param chan The channel
* @param mask The except
*/
-void ChannelModeExcept::DelMask(Channel *chan, const char *mask)
+void ChannelModeExcept::DelMask(Channel *chan, const Anope::string &mask)
{
Entry *exception;
/* Sanity check as it seems some IRCD will just send -e without a mask */
- if (!mask || !chan->excepts || !chan->excepts->count)
+ if (mask.empty() || !chan->excepts || !chan->excepts->count)
return;
exception = elist_find_mask(chan->excepts, mask);
@@ -360,11 +360,11 @@ void ChannelModeExcept::DelMask(Channel *chan, const char *mask)
* @param chan The channel
* @param mask The invex
*/
-void ChannelModeInvex::AddMask(Channel *chan, const char *mask)
+void ChannelModeInvex::AddMask(Channel *chan, const Anope::string &mask)
{
Entry *invite;
- if (!chan || !mask)
+ if (!chan || mask.empty())
{
Alog(LOG_DEBUG) << "add_invite called with NULL values";
return;
@@ -387,12 +387,12 @@ void ChannelModeInvex::AddMask(Channel *chan, const char *mask)
* @param chan The channel
* @param mask The index
*/
-void ChannelModeInvex::DelMask(Channel *chan, const char *mask)
+void ChannelModeInvex::DelMask(Channel *chan, const Anope::string &mask)
{
Entry *invite;
/* Sanity check as it seems some IRCD will just send -I without a mask */
- if (!mask || !chan->invites || !chan->invites->count)
+ if (mask.empty() || !chan->invites || !chan->invites->count)
return;
invite = elist_find_mask(chan->invites, mask);
@@ -404,12 +404,12 @@ void ChannelModeInvex::DelMask(Channel *chan, const char *mask)
}
}
-void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param)
+void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param)
{
ChannelMode *cm = NULL;
UserMode *um = NULL;
- std::list<std::pair<void *, std::string> > *list, *otherlist;
- std::list<std::pair<void *, std::string > >::iterator it, it_end;
+ std::list<std::pair<void *, Anope::string> > *list, *otherlist;
+ std::list<std::pair<void *, Anope::string > >::iterator it, it_end;
bool IsParam = false;
if (Type == ST_CHANNEL)
@@ -441,7 +441,7 @@ void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param)
/* The param must match too (can have multiple status or list modes), but
* if it is a param mode it can match no matter what the param is
*/
- if (it->first == Mode && (it->second == Param || IsParam))
+ if (it->first == Mode && (Param.equals_cs(it->second) || IsParam))
{
list->erase(it);
/* It can only be on this list once */
@@ -454,7 +454,7 @@ void StackerInfo::AddMode(void *Mode, bool Set, const std::string &Param)
/* The param must match too (can have multiple status or list modes), but
* if it is a param mode it can match no matter what the param is
*/
- if (it->first == Mode && (it->second == Param || IsParam))
+ if (it->first == Mode && (Param.equals_cs(it->second) || IsParam))
{
otherlist->erase(it);
return;
@@ -491,11 +491,11 @@ StackerInfo *ModeManager::GetInfo(void *Item)
* @param info The stacker info for a channel or user
* @return a list of strings
*/
-std::list<std::string> ModeManager::BuildModeStrings(StackerInfo *info)
+std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info)
{
- std::list<std::string> ret;
- std::list<std::pair<void *, std::string> >::iterator it, it_end;
- std::string buf, parambuf;
+ std::list<Anope::string> ret;
+ std::list<std::pair<void *, Anope::string> >::iterator it, it_end;
+ Anope::string buf, parambuf;
ChannelMode *cm = NULL;
UserMode *um = NULL;
unsigned NModes = 0;
@@ -571,7 +571,7 @@ std::list<std::string> ModeManager::BuildModeStrings(StackerInfo *info)
* @param Set Adding or removing?
* @param Param A param, if there is one
*/
-void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param)
+void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, u, um, Set, Param, ST_USER);
}
@@ -583,7 +583,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Se
* @param Set Adding or removing?
* @param Param A param, if there is one
*/
-void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param)
+void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL);
}
@@ -596,7 +596,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, b
* @param Param A param, if there is one
* @param Type The type this is, user or channel
*/
-void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const std::string &Param, StackerType Type)
+void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const Anope::string &Param, StackerType Type)
{
StackerInfo *s = GetInfo(Object);
s->Type = Type;
@@ -747,7 +747,7 @@ char ModeManager::GetStatusChar(char Value)
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, c, cm, Set, Param);
}
@@ -759,7 +759,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set,
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const Anope::string &Param)
{
StackerAdd(bi, c, FindChannelModeByName(Name), Set, Param);
}
@@ -771,7 +771,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const Anope::string &Param)
{
StackerAdd(bi, c, FindChannelModeByChar(Mode), Set, Param);
}
@@ -783,7 +783,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set,
* @param Set true for setting, false for removing
* @param param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, u, um, Set, Param);
}
@@ -795,7 +795,7 @@ void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const Anope::string &Param)
{
StackerAdd(bi, u, FindUserModeByName(Name), Set, Param);
}
@@ -807,7 +807,7 @@ void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set,
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const std::string &Param)
+void ModeManager::StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const Anope::string &Param)
{
StackerAdd(bi, u, FindUserModeByChar(Mode), Set, Param);
}
@@ -823,7 +823,7 @@ void ModeManager::ProcessModes()
StackerInfo *s = it->second;
User *u = NULL;
Channel *c = NULL;
- std::list<std::string> ModeStrings = BuildModeStrings(s);
+ std::list<Anope::string> ModeStrings = BuildModeStrings(s);
if (s->Type == ST_USER)
u = static_cast<User *>(it->first);
@@ -832,7 +832,7 @@ void ModeManager::ProcessModes()
else
throw CoreException("ModeManager::ProcessModes got invalid Stacker Info type");
- for (std::list<std::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit)
+ for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit)
{
if (c)
ircdproto->SendMode(s->bi, c, lit->c_str());
diff --git a/src/module.cpp b/src/module.cpp
index d2382eb02..99233d7a3 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -9,7 +9,7 @@
#include "modules.h"
#include "language.h"
-Module::Module(const std::string &mname, const std::string &creator)
+Module::Module(const Anope::string &mname, const Anope::string &creator)
{
this->name = mname; /* Our name */
this->type = THIRD;
@@ -45,7 +45,7 @@ Module::~Module()
**/
if (HostServ)
{
- for (std::map<ci::string, Command *>::iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = HostServ->Commands.begin(), it_end = HostServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -57,7 +57,7 @@ Module::~Module()
if (BotServ)
{
- for (std::map<ci::string, Command *>::iterator it = BotServ->Commands.begin(), it_end = BotServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = BotServ->Commands.begin(), it_end = BotServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -69,7 +69,7 @@ Module::~Module()
if (MemoServ)
{
- for (std::map<ci::string, Command *>::iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = MemoServ->Commands.begin(), it_end = MemoServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -81,7 +81,7 @@ Module::~Module()
if (NickServ)
{
- for (std::map<ci::string, Command *>::iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = NickServ->Commands.begin(), it_end = NickServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -93,7 +93,7 @@ Module::~Module()
if (ChanServ)
{
- for (std::map<ci::string, Command *>::iterator it = ChanServ->Commands.begin(), it_end = ChanServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = ChanServ->Commands.begin(), it_end = ChanServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -105,7 +105,7 @@ Module::~Module()
if (OperServ)
{
- for (std::map<ci::string, Command *>::iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; )
+ for (CommandMap::iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; )
{
Command *c = it->second;
++it;
@@ -117,9 +117,7 @@ Module::~Module()
std::list<Module *>::iterator it = std::find(Modules.begin(), Modules.end(), this);
if (it != Modules.end())
- {
Modules.erase(it);
- }
}
void Module::SetType(MODType ntype)
@@ -137,12 +135,12 @@ bool Module::GetPermanent()
return this->permanent;
}
-void Module::SetVersion(const std::string &nversion)
+void Module::SetVersion(const Anope::string &nversion)
{
this->version = nversion;
}
-void Module::SetAuthor(const std::string &nauthor)
+void Module::SetAuthor(const Anope::string &nauthor)
{
this->author = nauthor;
}
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 884bba5a8..4e26289ec 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -25,6 +25,12 @@ void ModuleManager::LoadModuleList(std::list<ci::string> &ModuleList)
ModuleManager::LoadModule(*it, NULL);
}
+void ModuleManager::LoadModuleList(std::list<Anope::string> &ModuleList)
+{
+ for (std::list<Anope::string>::iterator it = ModuleList.begin(), it_end = ModuleList.end(); it != it_end; ++it)
+ ModuleManager::LoadModule(*it, NULL);
+}
+
/**
* Copy the module from the modules folder to the runtime folder.
* This will prevent module updates while the modules is loaded from
@@ -34,39 +40,37 @@ void ModuleManager::LoadModuleList(std::list<ci::string> &ModuleList)
* @param output the destination to copy the module to
* @return MOD_ERR_OK on success
*/
-static int moduleCopyFile(const char *name, const char *output)
+static int moduleCopyFile(const Anope::string &name, Anope::string &output)
{
int ch;
FILE *source, *target;
#ifndef _WIN32
int srcfp;
#endif
- char input[4096];
+ Anope::string input = services_dir + "/modules/" + name + MODULE_EXT;
- strlcpy(input, services_dir.c_str(), sizeof(input));
- strlcat(input, "/modules/", sizeof(input)); /* Get full path with module extension */
- strlcat(input, name, sizeof(input));
- strlcat(input, MODULE_EXT, sizeof(input));
-
- if (!(source = fopen(input, "rb")))
+ if (!(source = fopen(input.c_str(), "rb")))
return MOD_ERR_NOEXIST;
+ char *tmp_output = strdup(output.c_str());
#ifndef _WIN32
- if ((srcfp = mkstemp(const_cast<char *>(output))) == -1)
+ if ((srcfp = mkstemp(const_cast<char *>(tmp_output))) == -1)
#else
- if (!mktemp(const_cast<char *>(output)))
+ if (!mktemp(const_cast<char *>(tmp_output)))
#endif
{
fclose(source);
return MOD_ERR_FILE_IO;
}
+ output = tmp_output;
+ delete [] tmp_output;
Alog(LOG_DEBUG) << "Runtime module location: " << output;
#ifndef _WIN32
if (!(target = fdopen(srcfp, "w")))
#else
- if (!(target = fopen(output, "wb")))
+ if (!(target = fopen(output.c_str(), "wb")))
#endif
{
fclose(source);
@@ -116,35 +120,25 @@ template <class TYPE> TYPE function_cast(ano_module_t symbol)
return cast.function;
}
-int ModuleManager::LoadModule(const std::string &modname, User *u)
+int ModuleManager::LoadModule(const Anope::string &modname, User *u)
{
const char *err;
- Module *(*func)(const std::string &, const std::string &);
+ Module *(*func)(const Anope::string &, const Anope::string &);
int ret = 0;
if (modname.empty())
return MOD_ERR_PARAMS;
- if (FindModule(modname) != NULL)
+ if (FindModule(modname))
return MOD_ERR_EXISTS;
Alog(LOG_DEBUG) << "trying to load [" << modname << "]";
/* Generate the filename for the temporary copy of the module */
- std::string pbuf;
- pbuf = services_dir + "/modules/";
-#ifndef _WIN32
- pbuf += "runtime/";
-#else
- pbuf += "runtime\\";
-#endif
- pbuf += modname;
- pbuf += MODULE_EXT;
- pbuf += ".";
- pbuf += "XXXXXX";
+ Anope::string pbuf = services_dir + "/modules/runtime/" + modname + MODULE_EXT + ".XXXXXX";
/* Don't skip return value checking! -GD */
- if ((ret = moduleCopyFile(modname.c_str(), pbuf.c_str())) != MOD_ERR_OK)
+ if ((ret = moduleCopyFile(modname, pbuf)) != MOD_ERR_OK)
{
/* XXX: This used to assign filename here, but I don't think that was correct..
* even if it was, it makes life very fucking difficult, so.
@@ -162,7 +156,7 @@ int ModuleManager::LoadModule(const std::string &modname, User *u)
}
ano_modclearerr();
- func = function_cast<Module *(*)(const std::string &, const std::string &)>(dlsym(handle, "AnopeInit"));
+ func = function_cast<Module *(*)(const Anope::string &, const Anope::string &)>(dlsym(handle, "AnopeInit"));
if (!func && (err = dlerror()))
{
Alog() << "No init function found, not an Anope module";
@@ -174,11 +168,9 @@ int ModuleManager::LoadModule(const std::string &modname, User *u)
throw CoreException("Couldn't find constructor, yet moderror wasn't set?");
/* Create module. */
- std::string nick;
+ Anope::string nick;
if (u)
nick = u->nick;
- else
- nick = "";
Module *m;
@@ -238,16 +230,6 @@ int ModuleManager::LoadModule(const std::string &modname, User *u)
return MOD_ERR_OK;
}
-int ModuleManager::LoadModule(const char *modname, User *u)
-{
- return LoadModule(std::string(modname), u);
-}
-
-int ModuleManager::LoadModule(const ci::string &modname, User *u)
-{
- return LoadModule(std::string(modname.c_str()), u);
-}
-
int ModuleManager::UnloadModule(Module *m, User *u)
{
if (!m || !m->handle)
@@ -286,7 +268,7 @@ void ModuleManager::DeleteModule(Module *m)
DetachAll(m);
ano_module_t handle = m->handle;
- std::string filename = m->filename;
+ Anope::string filename = m->filename;
ano_modclearerr();
destroy_func = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
@@ -479,4 +461,3 @@ void ModuleManager::UnloadAll(bool unload_proto)
DeleteModule(m);
}
}
-
diff --git a/src/modules.cpp b/src/modules.cpp
index fda941e50..b6115137d 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -13,14 +13,12 @@
#include "language.h"
#include "version.h"
-std::multimap<std::string, Message *> MessageMap;
+message_map MessageMap;
std::list<Module *> Modules;
-char *mod_current_buffer = NULL;
-
-char *ModuleGetErrStr(int status)
+Anope::string ModuleGetErrStr(int status)
{
- const char *module_err_str[] = {
+ Anope::string module_err_str[] = {
"Module, Okay - No Error", /* MOD_ERR_OK */
"Module Error, Allocating memory", /* MOD_ERR_MEMORY */
"Module Error, Not enough parameters", /* MOD_ERR_PARAMS */
@@ -36,7 +34,7 @@ char *ModuleGetErrStr(int status)
"Module Error, No Service found for request", /* MOD_ERR_NOSERVICE */
"Module Error, No module name for request" /* MOD_ERR_NO_MOD_NAME */
};
- return const_cast<char *>(module_err_str[status]);
+ return module_err_str[status];
}
/************************************************/
@@ -60,7 +58,7 @@ int protocol_module_init()
*/
if (ircd->ts6)
{
- if (!Config.Numeric)
+ if (Config.Numeric.empty())
{
Alog() << "This IRCd protocol requires a server id to be set in Anope's configuration.";
ret = -1;
@@ -83,7 +81,7 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av)
this->lang[langNumber].argc = ac;
this->lang[langNumber].argv = new char *[ac];
for (i = 0; i < ac; ++i)
- this->lang[langNumber].argv[i] = sstrdup(av[i]);
+ this->lang[langNumber].argv[i] = strdup(av[i]);
}
/**
@@ -91,35 +89,25 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av)
* @param name the name of the module to find
* @return a pointer to the module found, or NULL
*/
-Module *FindModule(const std::string &name)
+Module *FindModule(const Anope::string &name)
{
for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
{
Module *m = *it;
- if (m->name == name)
+ if (m->name.equals_ci(name))
return m;
}
return NULL;
}
-Module *FindModule(const char *name)
-{
- return FindModule(std::string(name));
-}
-
-Module *FindModule(const ci::string &name)
-{
- return FindModule(std::string(name.c_str()));
-}
-
/** Add a message to Anope
* @param name The message name as sent by the IRCd
* @param func A callback function that will be called when this message is received
* @return The new message object
*/
-Message *Anope::AddMessage(const std::string &name, int (*func)(const char *source, int ac, const char **av))
+Message *Anope::AddMessage(const Anope::string &name, int (*func)(const Anope::string &source, int ac, const char **av))
{
Message *m = new Message;
@@ -139,12 +127,12 @@ Message *Anope::AddMessage(const std::string &name, int (*func)(const char *sour
*/
bool Anope::DelMessage(Message *m)
{
- std::multimap<std::string, Message *>::iterator it = MessageMap.find(m->name);
+ message_map::iterator it = MessageMap.find(m->name);
if (it == MessageMap.end())
return false;
- std::multimap<std::string, Message *>::iterator upper = MessageMap.upper_bound(m->name);
+ message_map::iterator upper = MessageMap.upper_bound(m->name);
for (; it != upper; ++it)
{
@@ -158,20 +146,21 @@ bool Anope::DelMessage(Message *m)
return false;
}
+
/** Find message in the message table
* @param name The name of the message were looking for
* @return NULL if we cant find it, or a pointer to the Message if we can
**/
-std::vector<Message *> Anope::FindMessage(const std::string &name)
+std::vector<Message *> Anope::FindMessage(const Anope::string &name)
{
std::vector<Message *> messages;
- std::multimap<std::string, Message *>::iterator it = MessageMap.find(name);
+ message_map::iterator it = MessageMap.find(name);
if (it == MessageMap.end())
return messages;
- std::multimap<std::string, Message *>::iterator upper = MessageMap.upper_bound(name);
+ message_map::iterator upper = MessageMap.upper_bound(name);
for (; it != upper; ++it)
messages.push_back(it->second);
@@ -179,7 +168,6 @@ std::vector<Message *> Anope::FindMessage(const std::string &name)
return messages;
}
-
/*******************************************************************************
* Command Functions
*******************************************************************************/
@@ -192,7 +180,7 @@ int Module::AddCommand(BotInfo *bi, Command *c)
c->module = this;
c->service = bi;
- std::pair<std::map<ci::string, Command *>::iterator, bool> it = bi->Commands.insert(std::make_pair(c->name, c));
+ std::pair<CommandMap::iterator, bool> it = bi->Commands.insert(std::make_pair(c->name, c));
if (it.second != true)
{
@@ -266,7 +254,7 @@ bool moduleMinVersion(int major, int minor, int patch, int build)
return ret;
}
-void Module::NoticeLang(const char *source, User *u, int number, ...)
+void Module::NoticeLang(const Anope::string &source, User *u, int number, ...)
{
va_list va;
char buffer[4096], outbuf[4096];
@@ -287,7 +275,7 @@ void Module::NoticeLang(const char *source, User *u, int number, ...)
{
fmt = this->lang[mlang].argv[number];
- buf = sstrdup(fmt);
+ buf = strdup(fmt);
va_start(va, number);
vsnprintf(buffer, 4095, buf, va);
va_end(va);
@@ -366,7 +354,7 @@ void ModuleRunTimeDirCleanUp()
{
if (!dp->d_ino)
continue;
- if (!stricmp(dp->d_name, ".") || !stricmp(dp->d_name, ".."))
+ if (Anope::string(dp->d_name).equals_cs(".") || Anope::string(dp->d_name).equals_cs(".."))
continue;
snprintf(filebuf, BUFSIZE, "%s/%s", dirbuf, dp->d_name);
DeleteFile(filebuf);
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index 8ffbac891..c18f93005 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -1,15 +1,14 @@
#include "services.h"
#include "modules.h"
-NickRequest::NickRequest(const std::string &nickname)
+NickRequest::NickRequest(const Anope::string &nickname)
{
if (nickname.empty())
throw CoreException("Empty nick passed to NickRequest constructor");
- email = NULL;
requested = lastmail = 0;
- this->nick = sstrdup(nickname.c_str());
+ this->nick = nickname;
NickRequestList[this->nick] = this;
}
@@ -19,45 +18,39 @@ NickRequest::~NickRequest()
FOREACH_MOD(I_OnDelNickRequest, OnDelNickRequest(this));
NickRequestList.erase(this->nick);
-
- if (this->nick)
- delete [] this->nick;
- if (this->email)
- delete [] this->email;
}
/** Default constructor
* @param nick The nick
* @param nickcore The nickcofe for this nick
*/
-NickAlias::NickAlias(const std::string &nickname, NickCore *nickcore)
+NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore)
{
if (nickname.empty())
throw CoreException("Empty nick passed to NickAlias constructor");
else if (!nickcore)
throw CoreException("Empty nickcore passed to NickAlias constructor");
- nick = last_quit = last_realname = last_usermask = NULL;
time_registered = last_seen = 0;
- this->nick = sstrdup(nickname.c_str());
+ this->nick = nickname;
this->nc = nickcore;
nc->aliases.push_back(this);
NickAliasList[this->nick] = this;
- for (std::list<std::pair<ci::string, ci::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it)
+ for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it)
{
if (nc->ot)
break;
- if (stricmp(it->first.c_str(), this->nick))
+ if (!this->nick.equals_ci(it->first))
continue;
for (std::list<OperType *>::iterator tit = Config.MyOperTypes.begin(), tit_end = Config.MyOperTypes.end(); tit != tit_end; ++tit)
{
OperType *ot = *tit;
- if (ot->GetName() == it->second)
+ if (ot->GetName().equals_ci(it->second))
{
Alog() << "Tied oper " << nc->display << " to type " << ot->GetName();
nc->ot = ot;
@@ -99,21 +92,13 @@ NickAlias::~NickAlias()
else
{
/* Display updating stuff */
- if (!stricmp(this->nick, this->nc->display))
+ if (this->nick.equals_ci(this->nc->display))
change_core_display(this->nc);
}
}
/* Remove us from the aliases list */
NickAliasList.erase(this->nick);
-
- delete [] this->nick;
- if (this->last_usermask)
- delete [] this->last_usermask;
- if (this->last_realname)
- delete [] this->last_realname;
- if (this->last_quit)
- delete [] this->last_quit;
}
/** Release a nick from being held. This can be called from the core (ns_release)
@@ -127,7 +112,7 @@ void NickAlias::Release()
if (ircd->svshold)
ircdproto->SendSVSHoldDel(this->nick);
else
- ircdproto->SendQuit(this->nick, NULL);
+ ircdproto->SendQuit(this->nick, "");
this->UnsetFlag(NS_HELD);
}
@@ -148,7 +133,7 @@ void NickAlias::OnCancel(User *)
ircdproto->SendSVSHold(this->nick);
else
{
- std::string uid = (ircd->ts6 ? ts6_uid_retrieve() : "");
+ Anope::string uid = ircd->ts6 ? ts6_uid_retrieve() : "";
ircdproto->SendClientIntroduction(this->nick, Config.NSEnforcerUser, Config.NSEnforcerHost, "Services Enforcer", "+", uid);
new NickServRelease(this->nick, uid, Config.NSReleaseTimeout);
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 6c9392aef..565a23a26 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -4,17 +4,16 @@
/** Default constructor
* @param display The display nick
*/
-NickCore::NickCore(const std::string &coredisplay)
+NickCore::NickCore(const Anope::string &coredisplay)
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
- display = email = greet = NULL;
ot = NULL;
language = channelcount = 0;
lastmail = 0;
- this->display = sstrdup(coredisplay.c_str());
+ this->display = coredisplay;
/* Set default nick core flags */
for (size_t t = NI_BEGIN + 1; t != NI_END; ++t)
@@ -55,32 +54,19 @@ NickCore::~NickCore()
/* Clear access before deleting display name, we want to be able to use the display name in the clear access event */
this->ClearAccess();
- /* Now we can safely free it. */
- delete [] this->display;
-
- if (this->email)
- delete [] this->email;
- if (this->greet)
- delete [] this->greet;
if (!this->memos.memos.empty())
{
for (unsigned i = 0, end = this->memos.memos.size(); i < end; ++i)
- {
- if (this->memos.memos[i]->text)
- delete [] this->memos.memos[i]->text;
delete this->memos.memos[i];
- }
this->memos.memos.clear();
}
}
-bool NickCore::HasCommand(const ci::string &cmdstr) const
+bool NickCore::HasCommand(const Anope::string &cmdstr) const
{
if (!this->ot)
- {
// No opertype.
return false;
- }
return this->ot->HasCommand(cmdstr);
}
@@ -93,7 +79,7 @@ bool NickCore::IsServicesOper() const
return false;
}
-bool NickCore::HasPriv(const ci::string &privstr) const
+bool NickCore::HasPriv(const Anope::string &privstr) const
{
if (!this->ot)
// No opertype.
@@ -102,20 +88,20 @@ bool NickCore::HasPriv(const ci::string &privstr) const
return this->ot->HasPriv(privstr);
}
-void NickCore::AddAccess(const std::string &entry)
+void NickCore::AddAccess(const Anope::string &entry)
{
access.push_back(entry);
FOREACH_MOD(I_OnNickAddAccess, OnNickAddAccess(this, entry));
}
-std::string NickCore::GetAccess(unsigned entry)
+Anope::string NickCore::GetAccess(unsigned entry)
{
if (access.empty() || entry >= access.size())
return "";
return access[entry];
}
-bool NickCore::FindAccess(const std::string &entry)
+bool NickCore::FindAccess(const Anope::string &entry)
{
for (unsigned i = 0, end = access.size(); i < end; ++i)
if (access[i] == entry)
@@ -124,7 +110,7 @@ bool NickCore::FindAccess(const std::string &entry)
return false;
}
-void NickCore::EraseAccess(const std::string &entry)
+void NickCore::EraseAccess(const Anope::string &entry)
{
for (unsigned i = 0, end = access.size(); i < end; ++i)
if (access[i] == entry)
diff --git a/src/nickserv.cpp b/src/nickserv.cpp
index 70cc3d654..0397c8b32 100644
--- a/src/nickserv.cpp
+++ b/src/nickserv.cpp
@@ -17,13 +17,16 @@ nickalias_map NickAliasList;
nickcore_map NickCoreList;
nickrequest_map NickRequestList;
-static std::map<std::string, NickServCollide *> NickServCollides;
-static std::map<std::string, NickServRelease *> NickServReleases;
+typedef std::map<Anope::string, NickServCollide *, hash_compare_std_string> nickservcollides_map;
+typedef std::map<Anope::string, NickServRelease *, hash_compare_std_string> nickservreleases_map;
-NickServCollide::NickServCollide(const std::string &_nick, time_t delay) : Timer(delay), nick(_nick)
+static nickservcollides_map NickServCollides;
+static nickservreleases_map NickServReleases;
+
+NickServCollide::NickServCollide(const Anope::string &_nick, time_t delay) : Timer(delay), nick(_nick)
{
/* Erase the current collide and use the new one */
- std::map<std::string, NickServCollide *>::iterator nit = NickServCollides.find(nick);
+ nickservcollides_map::iterator nit = NickServCollides.find(nick);
if (nit != NickServCollides.end())
delete nit->second;
@@ -46,10 +49,10 @@ void NickServCollide::Tick(time_t ctime)
u->Collide(na);
}
-NickServRelease::NickServRelease(const std::string &_nick, const std::string &_uid, time_t delay) : Timer(delay), nick(_nick), uid(_uid)
+NickServRelease::NickServRelease(const Anope::string &_nick, const Anope::string &_uid, time_t delay) : Timer(delay), nick(_nick), uid(_uid)
{
/* Erase the current release timer and use the new one */
- std::map<std::string, NickServRelease *>::iterator nit = NickServReleases.find(nick);
+ nickservreleases_map::iterator nit = NickServReleases.find(nick);
if (nit != NickServReleases.end())
delete nit->second;
@@ -90,14 +93,14 @@ void get_aliases_stats(long *nrec, long *memuse)
++count;
mem += sizeof(*na);
- if (na->nick)
- mem += strlen(na->nick) + 1;
- if (na->last_usermask)
- mem += strlen(na->last_usermask) + 1;
- if (na->last_realname)
- mem += strlen(na->last_realname) + 1;
- if (na->last_quit)
- mem += strlen(na->last_quit) + 1;
+ if (!na->nick.empty())
+ mem += na->nick.length() + 1;
+ if (!na->last_usermask.empty())
+ mem += na->last_usermask.length() + 1;
+ if (!na->last_realname.empty())
+ mem += na->last_realname.length() + 1;
+ if (!na->last_quit.empty())
+ mem += na->last_quit.length() + 1;
}
*nrec = count;
*memuse = mem;
@@ -119,25 +122,22 @@ void get_core_stats(long *nrec, long *memuse)
++count;
mem += sizeof(*nc);
- if (nc->display)
- mem += strlen(nc->display) + 1;
+ if (!nc->display.empty())
+ mem += nc->display.length() + 1;
if (!nc->pass.empty())
- mem += (nc->pass.capacity() + (2 * sizeof(size_t)) + (2 * sizeof(void *)));
- if (nc->email)
- mem += strlen(nc->email) + 1;
- if (nc->greet)
- mem += strlen(nc->greet) + 1;
+ mem += nc->pass.length() + 1;
+ if (!nc->greet.empty())
+ mem += nc->greet.length() + 1;
+
+ mem += sizeof(Anope::string) * nc->access.size();
- mem += sizeof(std::string) * nc->access.size();
for (j = 0, end = nc->access.size(); j < end; ++j)
mem += nc->GetAccess(j).length() + 1;
mem += nc->memos.memos.size() * sizeof(Memo);
for (j = 0, end = nc->memos.memos.size(); j < end; ++j)
- {
- if (nc->memos.memos[j]->text)
- mem += strlen(nc->memos.memos[j]->text) + 1;
- }
+ if (!nc->memos.memos[j]->text.empty())
+ mem += nc->memos.memos[j]->text.length() + 1;
mem += sizeof(NickAlias *) * nc->aliases.size();
}
@@ -159,17 +159,17 @@ void ns_init()
/* Main NickServ routine. */
-void nickserv(User *u, const std::string &buf)
+void nickserv(User *u, const Anope::string &buf)
{
if (!u || 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(NickServ, u->nick.c_str(), "%s", command.c_str());
+ ircdproto->SendCTCP(NickServ, u->nick, "%s", command.c_str());
}
else
mod_run_cmd(NickServ, u, buf);
@@ -216,13 +216,9 @@ int validate_user(User *u)
if (!na->nc->HasFlag(NI_SECURE) && u->IsRecognized())
{
na->last_seen = time(NULL);
- if (na->last_usermask)
- delete [] na->last_usermask;
- std::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
- na->last_usermask = sstrdup(last_usermask.c_str());
- if (na->last_realname)
- delete [] na->last_realname;
- na->last_realname = sstrdup(u->realname);
+ Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
+ na->last_usermask = last_usermask;
+ na->last_realname = u->realname;
check_memos(u);
@@ -232,9 +228,9 @@ int validate_user(User *u)
if (u->IsRecognized() || !na->nc->HasFlag(NI_KILL_IMMED))
{
if (na->nc->HasFlag(NI_SECURE))
- notice_lang(Config.s_NickServ, u, NICK_IS_SECURE, Config.s_NickServ);
+ notice_lang(Config.s_NickServ, u, NICK_IS_SECURE, Config.s_NickServ.c_str());
else
- notice_lang(Config.s_NickServ, u, NICK_IS_REGISTERED, Config.s_NickServ);
+ notice_lang(Config.s_NickServ, u, NICK_IS_REGISTERED, Config.s_NickServ.c_str());
}
if (na->nc->HasFlag(NI_KILLPROTECT) && !u->IsRecognized())
@@ -288,7 +284,7 @@ void expire_nicks()
FOREACH_RESULT(I_OnPreNickExpire, OnPreNickExpire(na));
if (MOD_RESULT == EVENT_STOP)
continue;
- Alog() << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email ? na->nc->email : "none") << ")";
+ Alog() << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
FOREACH_MOD(I_OnNickExpire, OnNickExpire(na));
delete na;
}
@@ -313,17 +309,7 @@ void expire_requests()
/*************************************************************************/
-NickRequest *findrequestnick(const char *nick)
-{
- return findrequestnick(ci::string(nick));
-}
-
-NickRequest *findrequestnick(const std::string &nick)
-{
- return findrequestnick(ci::string(nick.c_str()));
-}
-
-NickRequest *findrequestnick(const ci::string &nick)
+NickRequest *findrequestnick(const Anope::string &nick)
{
nickrequest_map::const_iterator it = NickRequestList.find(nick);
@@ -332,17 +318,7 @@ NickRequest *findrequestnick(const ci::string &nick)
return NULL;
}
-NickAlias *findnick(const char *nick)
-{
- return findnick(ci::string(nick));
-}
-
-NickAlias *findnick(const std::string &nick)
-{
- return findnick(ci::string(nick.c_str()));
-}
-
-NickAlias *findnick(const ci::string &nick)
+NickAlias *findnick(const Anope::string &nick)
{
nickalias_map::const_iterator it = NickAliasList.find(nick);
@@ -353,17 +329,7 @@ NickAlias *findnick(const ci::string &nick)
/*************************************************************************/
-NickCore *findcore(const char *nick)
-{
- return findcore(ci::string(nick));
-}
-
-NickCore *findcore(const std::string &nick)
-{
- return findcore(ci::string(nick.c_str()));
-}
-
-NickCore *findcore(const ci::string &nick)
+NickCore *findcore(const Anope::string &nick)
{
nickcore_map::const_iterator it = NickCoreList.find(nick);
@@ -383,54 +349,23 @@ NickCore *findcore(const ci::string &nick)
*/
bool is_on_access(User *u, NickCore *nc)
{
- unsigned i, end;
- char *buf;
- char *buf2 = NULL;
- char *buf3 = NULL;
- std::string tmp_buf;
-
if (!u || !nc || nc->access.empty())
return false;
- tmp_buf = u->GetIdent() + "@" + u->host;
- buf = sstrdup(tmp_buf.c_str());
+ Anope::string buf = u->GetIdent() + "@" + u->host, buf2, buf3;
if (ircd->vhost)
{
- if (u->vhost)
- {
- tmp_buf = u->GetIdent() + "@" + u->vhost;
- buf2 = sstrdup(tmp_buf.c_str());
- }
+ if (!u->vhost.empty())
+ buf2 = u->GetIdent() + "@" + u->vhost;
if (!u->GetCloakedHost().empty())
- {
- tmp_buf = u->GetIdent() + "@" + u->GetCloakedHost();
- buf3 = sstrdup(tmp_buf.c_str());
- }
+ buf3 = u->GetIdent() + "@" + u->GetCloakedHost();
}
- for (i = 0, end = nc->access.size(); i < end; ++i)
+ for (unsigned i = 0, end = nc->access.size(); i < end; ++i)
{
- std::string access = nc->GetAccess(i);
- if (Anope::Match(buf, access, false) || (buf2 && Anope::Match(buf2, access, false)) || (buf3 && Anope::Match(buf3, access, false)))
- {
- delete [] buf;
- if (ircd->vhost)
- {
- if (u->vhost)
- delete [] buf2;
- if (!u->GetCloakedHost().empty())
- delete [] buf3;
- }
+ Anope::string access = nc->GetAccess(i);
+ if (Anope::Match(buf, access) || (!buf2.empty() && Anope::Match(buf2, access)) || (!buf3.empty() && Anope::Match(buf3, access)))
return true;
- }
- }
- delete [] buf;
- if (ircd->vhost)
- {
- if (buf2)
- delete [] buf2;
- if (buf3)
- delete [] buf3;
}
return false;
}
@@ -441,7 +376,7 @@ bool is_on_access(User *u, NickCore *nc)
* it to the first alias in the list.
*/
-void change_core_display(NickCore *nc, const char *newdisplay)
+void change_core_display(NickCore *nc, const Anope::string &newdisplay)
{
/* Log ... */
FOREACH_MOD(I_OnChangeCoreDisplay, OnChangeCoreDisplay(nc, newdisplay));
@@ -450,8 +385,7 @@ void change_core_display(NickCore *nc, const char *newdisplay)
/* Remove the core from the list */
NickCoreList.erase(nc->display);
- delete [] nc->display;
- nc->display = sstrdup(newdisplay);
+ nc->display = newdisplay;
NickCoreList[nc->display] = nc;
}
@@ -462,7 +396,7 @@ void change_core_display(NickCore *nc)
if (nc->aliases.empty())
return;
na = nc->aliases.front();
- change_core_display(nc,na->nick);
+ change_core_display(nc, na->nick);
}
/*************************************************************************/
diff --git a/src/operserv.cpp b/src/operserv.cpp
index b97f66072..e91ad113b 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -22,7 +22,7 @@ Flags<ChannelModeName, CMODE_END> DefConModesOn;
/* Defcon modes mlocked off */
Flags<ChannelModeName, CMODE_END> DefConModesOff;
/* Map of Modesa and Params for DefCon */
-std::map<ChannelModeName, std::string> DefConModesOnParams;
+std::map<ChannelModeName, Anope::string> DefConModesOnParams;
XLineManager *SGLine, *SZLine, *SQLine, *SNLine;
@@ -37,32 +37,32 @@ void os_init()
XLineManager::RegisterXLineManager(SNLine = new SNLineManager());
}
-void operserv(User *u, const std::string &buf)
+void operserv(User *u, const Anope::string &buf)
{
if (!u || buf.empty())
return;
Alog() << Config.s_OperServ << ": " << u->nick << ": " << buf;
- if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ if (buf.substr(0, 6).equals_cs("\1PING ") && buf[buf.length() - 1] == '\1')
{
- std::string command = buf;
+ Anope::string command = buf;
command.erase(command.begin());
command.erase(command.end());
- ircdproto->SendCTCP(OperServ, u->nick.c_str(), "%s", command.c_str());
+ ircdproto->SendCTCP(OperServ, u->nick, "%s", command.c_str());
}
else
mod_run_cmd(OperServ, u, buf);
}
-bool SetDefConParam(ChannelModeName Name, std::string &buf)
+bool SetDefConParam(ChannelModeName Name, const Anope::string &buf)
{
return DefConModesOnParams.insert(std::make_pair(Name, buf)).second;
}
-bool GetDefConParam(ChannelModeName Name, std::string &buf)
+bool GetDefConParam(ChannelModeName Name, Anope::string &buf)
{
- std::map<ChannelModeName, std::string>::iterator it = DefConModesOnParams.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name);
buf.clear();
@@ -77,7 +77,7 @@ bool GetDefConParam(ChannelModeName Name, std::string &buf)
void UnsetDefConParam(ChannelModeName Name)
{
- std::map<ChannelModeName, std::string>::iterator it = DefConModesOnParams.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = DefConModesOnParams.find(Name);
if (it != DefConModesOnParams.end())
DefConModesOnParams.erase(it);
@@ -122,7 +122,7 @@ void DelDefCon(int level, DefconLevel Level)
DefCon[level][Level] = false;
}
-void server_global(Server *s, const std::string &message)
+void server_global(Server *s, const Anope::string &message)
{
/* Do not send the notice to ourselves our juped servers */
if (s != Me && !s->HasFlag(SERVER_JUPED))
@@ -135,7 +135,7 @@ void server_global(Server *s, const std::string &message)
}
}
-void oper_global(char *nick, const char *fmt, ...)
+void oper_global(const Anope::string &nick, const char *fmt, ...)
{
va_list args;
char msg[2048]; /* largest valid message is 512, this should cover any global */
@@ -144,14 +144,13 @@ void oper_global(char *nick, const char *fmt, ...)
vsnprintf(msg, sizeof(msg), fmt, args);
va_end(args);
- if (nick && !Config.AnonymousGlobal)
+ if (!nick.empty() && !Config.AnonymousGlobal)
{
- std::string rmsg = std::string("[") + nick + std::string("] ") + msg;
- server_global(Me->GetUplink(), rmsg.c_str());
+ Anope::string rmsg = "[" + nick + "] " + msg;
+ server_global(Me->GetUplink(), rmsg);
}
else
server_global(Me->GetUplink(), msg);
-
}
/**************************************************************************/
@@ -159,42 +158,45 @@ void oper_global(char *nick, const char *fmt, ...)
/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;
-XLine::XLine(const ci::string &mask, const std::string &reason) : Mask(mask), Reason(reason)
+XLine::XLine(const Anope::string &mask, const Anope::string &reason) : Mask(mask), Reason(reason)
{
Expires = Created = 0;
}
-XLine::XLine(const ci::string &mask, const ci::string &by, const time_t expires, const std::string &reason) : Mask(mask), By(by), Created(time(NULL)), Expires(expires), Reason(reason)
+XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason) : Mask(mask), By(by), Created(time(NULL)), Expires(expires), Reason(reason)
{
}
-ci::string XLine::GetNick() const
+Anope::string XLine::GetNick() const
{
size_t nick_t = Mask.find('!');
- if (nick_t == ci::string::npos)
+ if (nick_t == Anope::string::npos)
return "";
- return Mask.substr(0, nick_t - 1);
+ return Mask.substr(0, nick_t);
}
-ci::string XLine::GetUser() const
+Anope::string XLine::GetUser() const
{
size_t user_t = Mask.find('!'), host_t = Mask.find('@');
- if (user_t == ci::string::npos)
- return Mask.substr(0, host_t);
- else if (host_t != ci::string::npos)
- return Mask.substr((user_t != ci::string::npos ? user_t + 1 : 0), host_t);
+ if (host_t != Anope::string::npos)
+ {
+ if (user_t != Anope::string::npos)
+ return Mask.substr(user_t + 1, host_t - user_t - 1);
+ else
+ return Mask.substr(0, host_t);
+ }
else
return "";
}
-ci::string XLine::GetHost() const
+Anope::string XLine::GetHost() const
{
size_t host_t = Mask.find('@');
- if (host_t == ci::string::npos)
+ if (host_t == Anope::string::npos)
return Mask;
else
return Mask.substr(host_t + 1);
@@ -243,7 +245,7 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm)
std::pair<XLineManager *, XLine *> XLineManager::CheckAll(User *u)
{
std::pair<XLineManager *, XLine *> ret;
-
+
ret.first = NULL;
ret.second = NULL;
@@ -275,7 +277,7 @@ const size_t XLineManager::GetCount() const
/** Get the XLine vector
* @return The vecotr
*/
-const std::vector<XLine *>& XLineManager::GetList() const
+const std::vector<XLine *> &XLineManager::GetList() const
{
return XLines;
}
@@ -336,7 +338,7 @@ void XLineManager::Clear()
* @param reaosn The reason
* @return A pointer to the XLine
*/
-XLine *XLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason)
+XLine *XLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
return NULL;
}
@@ -357,10 +359,10 @@ void XLineManager::Del(XLine *x)
* 3 - Mask is already covered by another mask
* In each case the XLine it matches/is covered by is returned in XLine*
*/
-std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expires)
+std::pair<int, XLine *> XLineManager::CanAdd(const Anope::string &mask, time_t expires)
{
std::pair<int, XLine *> ret;
-
+
ret.first = 0;
ret.second = NULL;
@@ -369,7 +371,7 @@ std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expi
XLine *x = GetEntry(i);
ret.second = x;
- if (x->Mask == mask)
+ if (x->Mask.equals_ci(mask))
{
if (!x->Expires || x->Expires >= expires)
{
@@ -403,13 +405,13 @@ std::pair<int, XLine *> XLineManager::CanAdd(const ci::string &mask, time_t expi
* @param mask The mask
* @return The XLine the user matches, or NULL
*/
-XLine *XLineManager::HasEntry(const ci::string &mask) const
+XLine *XLineManager::HasEntry(const Anope::string &mask) const
{
for (unsigned i = 0, end = XLines.size(); i < end; ++i)
{
XLine *x = XLines[i];
- if (x->Mask == mask)
+ if (x->Mask.equals_ci(mask))
return x;
}
@@ -437,13 +439,13 @@ XLine *XLineManager::Check(User *u)
continue;
}
- if (!x->GetNick().empty() && !Anope::Match(u->nick.c_str(), x->GetNick()))
+ if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
continue;
- if (!x->GetUser().empty() && !Anope::Match(u->GetIdent().c_str(), x->GetUser()))
+ if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
continue;
- if (x->GetHost().empty() || (u->hostip && Anope::Match(u->hostip, x->GetHost())) || Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost.c_str(), x->GetHost())) || (u->vhost && Anope::Match(u->vhost, x->GetHost())))
+ if (x->GetHost().empty() || (!u->hostip.empty() && Anope::Match(u->hostip, x->GetHost())) || Anope::Match(u->host, x->GetHost()) || (!u->chost.empty() && Anope::Match(u->chost, x->GetHost())) || (!u->vhost.empty() && Anope::Match(u->vhost, x->GetHost())))
{
OnMatch(u, x);
return x;
@@ -468,26 +470,26 @@ void XLineManager::OnExpire(XLine *x)
{
}
-XLine *SGLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason)
+XLine *SGLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
- if (mask.find('!') != ci::string::npos)
+ if (mask.find('!') != Anope::string::npos)
{
if (bi && u)
- notice_lang(bi->nick.c_str(), u, OPER_AKILL_NO_NICK);
+ notice_lang(bi->nick, u, OPER_AKILL_NO_NICK);
return NULL;
}
- if (mask.find('@') == ci::string::npos)
+ if (mask.find('@') == Anope::string::npos)
{
if (bi && u)
- notice_lang(bi->nick.c_str(), u, BAD_USERHOST_MASK);
+ notice_lang(bi->nick, u, BAD_USERHOST_MASK);
return NULL;
}
- if (strspn(mask.c_str(), "~@.*?") == mask.length())
+ if (mask.find_first_not_of("~@.*?") == Anope::string::npos)
{
if (bi && u)
- notice_lang(bi->nick.c_str(), u, USERHOST_MASK_TOO_WIDE, mask.c_str());
+ notice_lang(bi->nick, u, USERHOST_MASK_TOO_WIDE, mask.c_str());
return NULL;
}
@@ -497,21 +499,21 @@ XLine *SGLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (bi && u)
{
if (canAdd.first == 1)
- notice_lang(bi->nick.c_str(), u, OPER_AKILL_EXISTS, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_AKILL_EXISTS, canAdd.second->Mask.c_str());
else if (canAdd.first == 2)
- notice_lang(bi->nick.c_str(), u, OPER_AKILL_CHANGED, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_AKILL_CHANGED, canAdd.second->Mask.c_str());
else if (canAdd.first == 3)
- notice_lang(bi->nick.c_str(), u, OPER_AKILL_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_AKILL_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
}
return canAdd.second;
}
- std::string realreason = reason;
+ Anope::string realreason = reason;
if (u && Config.AddAkiller)
realreason = "[" + u->nick + "]" + reason;
- XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, realreason);
+ XLine *x = new XLine(mask, u ? u->nick : "", expires, realreason);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnAddAkill, OnAddAkill(u, x));
@@ -545,12 +547,12 @@ void SGLineManager::OnExpire(XLine *x)
ircdproto->SendGlobops(OperServ, "AKILL on %s has expired", x->Mask.c_str());
}
-XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason)
+XLine *SNLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
- if (!mask.empty() && strspn(mask.c_str(), "*?") == mask.length())
+ if (!mask.empty() && mask.find_first_not_of("*?") == Anope::string::npos)
{
if (bi && u)
- notice_lang(bi->nick.c_str(), u, USERHOST_MASK_TOO_WIDE, mask.c_str());
+ notice_lang(bi->nick, u, USERHOST_MASK_TOO_WIDE, mask.c_str());
return NULL;
}
@@ -560,17 +562,17 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (bi && u)
{
if (canAdd.first == 1)
- notice_lang(bi->nick.c_str(), u, OPER_SNLINE_EXISTS, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SNLINE_EXISTS, canAdd.second->Mask.c_str());
else if (canAdd.first == 2)
- notice_lang(bi->nick.c_str(), u, OPER_SNLINE_CHANGED, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SNLINE_CHANGED, canAdd.second->Mask.c_str());
else if (canAdd.first == 3)
- notice_lang(bi->nick.c_str(), u, OPER_SNLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SNLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
}
return canAdd.second;
}
- XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason);
+ XLine *x = new XLine(mask, u ? u->nick : "", expires, reason);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SNLINE));
@@ -584,7 +586,7 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (Config.KillonSNline && !ircd->sglineenforce)
{
- std::string rreason = "G-Lined: " + reason;
+ Anope::string rreason = "G-Lined: " + reason;
for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; )
{
@@ -592,7 +594,7 @@ XLine *SNLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
++it;
if (!is_oper(user) && Anope::Match(user->realname, x->Mask))
- kill_user(Config.ServerName, user->nick, rreason.c_str());
+ kill_user(Config.ServerName, user->nick, rreason);
}
}
@@ -608,8 +610,8 @@ void SNLineManager::OnMatch(User *u, XLine *x)
{
ircdproto->SendSGLine(x);
- std::string reason = "G-Lined: " + x->Reason;
- kill_user(Config.s_OperServ, u->nick, reason.c_str());
+ Anope::string reason = "G-Lined: " + x->Reason;
+ kill_user(Config.s_OperServ, u->nick, reason);
}
void SNLineManager::OnExpire(XLine *x)
@@ -618,9 +620,9 @@ void SNLineManager::OnExpire(XLine *x)
ircdproto->SendGlobops(OperServ, "SNLINE on \2%s\2 has expired", x->Mask.c_str());
}
-XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason)
+XLine *SQLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
- if (strspn(mask.c_str(), "*") == mask.length())
+ if (mask.find_first_not_of("*") == Anope::string::npos)
{
if (bi && u)
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask.c_str());
@@ -640,17 +642,17 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (bi && u)
{
if (canAdd.first == 1)
- notice_lang(bi->nick.c_str(), u, OPER_SQLINE_EXISTS, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SQLINE_EXISTS, canAdd.second->Mask.c_str());
else if (canAdd.first == 2)
- notice_lang(bi->nick.c_str(), u, OPER_SQLINE_CHANGED, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SQLINE_CHANGED, canAdd.second->Mask.c_str());
else if (canAdd.first == 3)
- notice_lang(bi->nick.c_str(), u, OPER_SQLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SQLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
}
return canAdd.second;
}
- XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason);
+ XLine *x = new XLine(mask, u ? u->nick : "", expires, reason);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SQLINE));
@@ -664,7 +666,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (Config.KillonSQline)
{
- std::string rreason = "Q-Lined: " + reason;
+ Anope::string rreason = "Q-Lined: " + reason;
if (mask[0] == '#')
{
@@ -672,7 +674,7 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
{
Channel *c = cit->second;
- if (!Anope::Match(c->name.c_str(), mask))
+ if (!Anope::Match(c->name, mask))
continue;
for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
{
@@ -692,8 +694,8 @@ XLine *SQLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
User *user = it->second;
++it;
- if (!is_oper(user) && Anope::Match(user->nick.c_str(), x->Mask))
- kill_user(Config.ServerName, user->nick, rreason.c_str());
+ if (!is_oper(user) && Anope::Match(user->nick, x->Mask))
+ kill_user(Config.ServerName, user->nick, rreason);
}
}
}
@@ -712,8 +714,7 @@ void SQLineManager::OnMatch(User *u, XLine *x)
{
ircdproto->SendSQLine(x);
- char reason[300];
- snprintf(reason, sizeof(reason), "Q-Lined: %s", x->Reason.c_str());
+ Anope::string reason = "Q-Lined: " + x->Reason;
kill_user(Config.s_OperServ, u->nick, reason);
}
@@ -731,7 +732,7 @@ bool SQLineManager::Check(Channel *c)
{
XLine *x = *it;
- if (Anope::Match(c->name.c_str(), x->Mask))
+ if (Anope::Match(c->name, x->Mask))
return true;
}
}
@@ -739,15 +740,15 @@ bool SQLineManager::Check(Channel *c)
return false;
}
-XLine *SZLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t expires, const std::string &reason)
+XLine *SZLineManager::Add(BotInfo *bi, User *u, const Anope::string &mask, time_t expires, const Anope::string &reason)
{
- if (mask.find('!') != ci::string::npos || mask.find('@') != ci::string::npos)
+ if (mask.find('!') != Anope::string::npos || mask.find('@') != Anope::string::npos)
{
notice_lang(Config.s_OperServ, u, OPER_SZLINE_ONLY_IPS);
return NULL;
}
- if (strspn(mask.c_str(), "*?") == mask.length())
+ if (mask.find_first_not_of("*?") == Anope::string::npos)
{
notice_lang(Config.s_OperServ, u, USERHOST_MASK_TOO_WIDE, mask.c_str());
return NULL;
@@ -759,17 +760,17 @@ XLine *SZLineManager::Add(BotInfo *bi, User *u, const ci::string &mask, time_t e
if (bi && u)
{
if (canAdd.first == 1)
- notice_lang(bi->nick.c_str(), u, OPER_SZLINE_EXISTS, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SZLINE_EXISTS, canAdd.second->Mask.c_str());
else if (canAdd.first == 2)
- notice_lang(bi->nick.c_str(), u, OPER_SZLINE_CHANGED, canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SZLINE_CHANGED, canAdd.second->Mask.c_str());
else if (canAdd.first == 3)
- notice_lang(bi->nick.c_str(), u, OPER_SZLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
+ notice_lang(bi->nick, u, OPER_SZLINE_ALREADY_COVERED, mask.c_str(), canAdd.second->Mask.c_str());
}
return canAdd.second;
}
- XLine *x = new XLine(mask, u ? u->nick.c_str() : "", expires, reason);
+ XLine *x = new XLine(mask, u ? u->nick : "", expires, reason);
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, X_SZLINE));
diff --git a/src/opertype.cpp b/src/opertype.cpp
index 968163003..a4ea94dd3 100644
--- a/src/opertype.cpp
+++ b/src/opertype.cpp
@@ -7,13 +7,13 @@
#include "services.h"
-OperType::OperType(const ci::string &nname) : name(nname)
+OperType::OperType(const Anope::string &nname) : name(nname)
{
}
-bool OperType::HasCommand(const ci::string &cmdstr) const
+bool OperType::HasCommand(const Anope::string &cmdstr) const
{
- for (std::list<ci::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it)
+ for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it)
{
if (Anope::Match(cmdstr, *it))
return true;
@@ -29,9 +29,9 @@ bool OperType::HasCommand(const ci::string &cmdstr) const
return false;
}
-bool OperType::HasPriv(const ci::string &privstr) const
+bool OperType::HasPriv(const Anope::string &privstr) const
{
- for (std::list<ci::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it)
+ for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it)
{
if (Anope::Match(privstr, *it))
return true;
@@ -47,17 +47,17 @@ bool OperType::HasPriv(const ci::string &privstr) const
return false;
}
-void OperType::AddCommand(const ci::string &cmdstr)
+void OperType::AddCommand(const Anope::string &cmdstr)
{
this->commands.push_back(cmdstr);
}
-void OperType::AddPriv(const ci::string &privstr)
+void OperType::AddPriv(const Anope::string &privstr)
{
this->privs.push_back(privstr);
}
-const ci::string &OperType::GetName() const
+const Anope::string &OperType::GetName() const
{
return this->name;
}
diff --git a/src/process.cpp b/src/process.cpp
index 07f1ff451..6ea72dcb6 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -27,48 +27,40 @@ IgnoreData *ignore;
* @param nick Nick or (nick!)user@host to add to the ignorelist.
* @param delta Seconds untill new entry is set to expire. 0 for permanent.
*/
-void add_ignore(const char *nick, time_t delta)
+void add_ignore(const Anope::string &nick, time_t delta)
{
IgnoreData *ign;
- char tmp[BUFSIZE];
- char *mask, *user, *host;
+ Anope::string tmp, mask;
+ size_t user, host;
User *u;
time_t now;
- if (!nick)
+ if (nick.empty())
return;
now = time(NULL);
/* If it s an existing user, we ignore the hostmask. */
if ((u = finduser(nick)))
- {
- snprintf(tmp, sizeof(tmp), "*!*@%s", u->host);
- mask = sstrdup(tmp);
- }
+ mask = "*!*@" + u->host;
/* Determine whether we get a nick or a mask. */
- else if ((host = const_cast<char *>(strchr(nick, '@'))))
+ else if ((host = nick.find('@')) != Anope::string::npos)
{
/* Check whether we have a nick too.. */
- if ((user = const_cast<char *>(strchr(nick, '!'))))
+ if ((user = nick.find('!')) != Anope::string::npos)
{
/* this should never happen */
if (user > host)
return;
- mask = sstrdup(nick);
+ mask = nick;
}
else
- {
/* We have user@host. Add nick wildcard. */
- snprintf(tmp, sizeof(tmp), "*!%s", nick);
- mask = sstrdup(tmp);
- }
+ mask = "*!" + nick;
}
/* We only got a nick.. */
- else {
- snprintf(tmp, sizeof(tmp), "%s!*@*", nick);
- mask = sstrdup(tmp);
- }
+ else
+ mask = nick + "!*@*";
/* Check if we already got an identical entry. */
for (ign = ignore; ign; ign = ign->next)
- if (!stricmp(ign->mask, mask))
+ if (mask.equals_ci(ign->mask))
break;
/* Found one.. */
if (ign)
@@ -102,14 +94,14 @@ void add_ignore(const char *nick, time_t delta)
* @param nick Nick or (nick!)user@host to look for on the ignorelist.
* @return Pointer to the ignore record, NULL if none was found.
*/
-IgnoreData *get_ignore(const char *nick)
+IgnoreData *get_ignore(const Anope::string &nick)
{
IgnoreData *ign;
- char tmp[BUFSIZE];
- char *user, *host;
+ Anope::string tmp;
+ size_t user, host;
time_t now;
User *u;
- if (!nick)
+ if (nick.empty())
return NULL;
/* User has disabled the IGNORE system */
if (!allow_ignore)
@@ -129,24 +121,24 @@ IgnoreData *get_ignore(const char *nick)
else
{
/* We didn't get a user.. generate a valid mask. */
- if ((host = const_cast<char *>(strchr(nick, '@'))))
+ if ((host = nick.find('@')) != Anope::string::npos)
{
- if ((user = const_cast<char *>(strchr(nick, '!'))))
+ if ((user = nick.find('!')) != Anope::string::npos)
{
/* this should never happen */
if (user > host)
return NULL;
- snprintf(tmp, sizeof(tmp), "%s", nick);
+ tmp = nick;
}
else
/* We have user@host. Add nick wildcard. */
- snprintf(tmp, sizeof(tmp), "*!%s", nick);
+ tmp = "*!" + nick;
}
/* We only got a nick.. */
else
- snprintf(tmp, sizeof(tmp), "%s!*@*", nick);
+ tmp = nick + "!*@*";
for (ign = ignore; ign; ign = ign->next)
- if (Anope::Match(tmp, ign->mask, false))
+ if (Anope::Match(tmp, ign->mask))
break;
}
/* Check whether the entry has timed out */
@@ -159,7 +151,6 @@ IgnoreData *get_ignore(const char *nick)
ignore = ign->next;
if (ign->next)
ign->next->prev = ign->prev;
- delete [] ign->mask;
delete ign;
ign = NULL;
}
@@ -175,37 +166,37 @@ IgnoreData *get_ignore(const char *nick)
* @param nick Nick or (nick!)user@host to delete from the ignorelist.
* @return Returns 1 on success, 0 if no entry is found.
*/
-int delete_ignore(const char *nick)
+int delete_ignore(const Anope::string &nick)
{
IgnoreData *ign;
- char tmp[BUFSIZE];
- char *user, *host;
+ Anope::string tmp;
+ size_t user, host;
User *u;
- if (!nick)
+ if (nick.empty())
return 0;
/* If it s an existing user, we ignore the hostmask. */
if ((u = finduser(nick)))
- snprintf(tmp, sizeof(tmp), "*!*@%s", u->host);
+ tmp = "*!*@" + u->host;
/* Determine whether we get a nick or a mask. */
- else if ((host = const_cast<char *>(strchr(nick, '@'))))
+ else if ((host = nick.find('@')) != Anope::string::npos)
{
/* Check whether we have a nick too.. */
- if ((user = const_cast<char *>(strchr(nick, '!'))))
+ if ((user = nick.find('!')) != Anope::string::npos)
{
/* this should never happen */
if (user > host)
return 0;
- snprintf(tmp, sizeof(tmp), "%s", nick);
+ tmp = nick;
}
else
/* We have user@host. Add nick wildcard. */
- snprintf(tmp, sizeof(tmp), "*!%s", nick);
+ tmp = "*!" + nick;
}
/* We only got a nick.. */
else
- snprintf(tmp, sizeof(tmp), "%s!*@*", nick);
+ tmp = nick + "!*@*";
for (ign = ignore; ign; ign = ign->next)
- if (!stricmp(ign->mask, tmp))
+ if (tmp.equals_ci(ign->mask))
break;
/* No matching ignore found. */
if (!ign)
@@ -218,7 +209,6 @@ int delete_ignore(const char *nick)
ignore = ign->next;
if (ign->next)
ign->next->prev = ign->prev;
- delete [] ign->mask;
delete ign;
ign = NULL;
return 1;
@@ -240,7 +230,6 @@ int clear_ignores()
{
next = ign->next;
Alog(LOG_DEBUG) << "Deleting ignore entry " << ign->mask;
- delete [] ign->mask;
delete ign;
++i;
}
@@ -299,7 +288,7 @@ int split_buf(char *buf, const char ***argv, int colon_special)
/* process: Main processing routine. Takes the string in inbuf (global
* variable) and does something appropriate with it. */
-void process(const std::string &buffer)
+void process(const Anope::string &buffer)
{
int retVal = 0;
char source[64] = "";
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 13ff84a24..7bb21407b 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -1,6 +1,6 @@
#include "services.h"
-void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *buf)
+void IRCDProto::SendMessageInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
if (Config.NSDefFlags.HasFlag(NI_MSG))
SendPrivmsgInternal(bi, dest, buf);
@@ -8,50 +8,49 @@ void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *b
SendNoticeInternal(bi, dest, buf);
}
-void IRCDProto::SendNoticeInternal(BotInfo *bi, const char *dest, const char *msg)
+void IRCDProto::SendNoticeInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &msg)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest, msg);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest.c_str(), msg.c_str());
}
-void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const char *dest, const char *buf)
+void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest, buf);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest.c_str(), buf.c_str());
}
-void IRCDProto::SendQuitInternal(BotInfo *bi, const char *buf)
+void IRCDProto::SendQuitInternal(BotInfo *bi, const Anope::string &buf)
{
- if (buf)
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf);
+ if (!buf.empty())
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf.c_str());
else
send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT");
}
-void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const char *buf)
+void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf)
{
- if (buf)
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf);
+ if (!buf.empty())
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf.c_str());
else
send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s", chan->name.c_str());
}
-void IRCDProto::SendGlobopsInternal(BotInfo *source, const char *buf)
+void IRCDProto::SendGlobopsInternal(BotInfo *source, const Anope::string &buf)
{
if (source)
- send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf);
+ send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf.c_str());
else
- send_cmd(Config.ServerName, "GLOBOPS :%s", buf);
+ send_cmd(Config.ServerName, "GLOBOPS :%s", buf.c_str());
}
-void IRCDProto::SendCTCPInternal(BotInfo *bi, const char *dest, const char *buf)
+void IRCDProto::SendCTCPInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
- char *s = normalizeBuffer(buf);
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest, s);
- delete [] s;
+ Anope::string s = normalizeBuffer(buf);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest.c_str(), s.c_str());
}
-void IRCDProto::SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf)
+void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf)
{
- send_cmd(source, "%03d %s %s", numeric, dest, buf);
+ send_cmd(source, "%03d %s %s", numeric, dest.c_str(), buf.c_str());
}
void IRCDProto::SendSVSKill(BotInfo *source, User *user, const char *fmt, ...)
@@ -110,7 +109,7 @@ void IRCDProto::SendNoticeChanops(BotInfo *bi, Channel *dest, const char *fmt, .
SendNoticeChanopsInternal(bi, dest, buf);
}
-void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...)
+void IRCDProto::SendMessage(BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -120,7 +119,7 @@ void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...)
SendMessageInternal(bi, dest, buf);
}
-void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...)
+void IRCDProto::SendNotice(BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -130,18 +129,18 @@ void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...)
SendNoticeInternal(bi, dest, buf);
}
-void IRCDProto::SendAction(BotInfo *bi, const char *dest, const char *fmt, ...)
+void IRCDProto::SendAction(BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
- char buf[BUFSIZE] = "", actionbuf[BUFSIZE] = "";
+ char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
va_end(args);
- snprintf(actionbuf, BUFSIZE - 1, "%cACTION %s%c", 1, buf, 1);
+ Anope::string actionbuf = Anope::string("\1ACTION ") + buf + '\1';
SendPrivmsgInternal(bi, dest, actionbuf);
}
-void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...)
+void IRCDProto::SendPrivmsg(BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -151,17 +150,17 @@ void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...)
SendPrivmsgInternal(bi, dest, buf);
}
-void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const char *msg)
+void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const Anope::string &msg)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str());
}
-void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const char *msg)
+void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const Anope::string &msg)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str());
}
-void IRCDProto::SendQuit(const char *nick, const char *)
+void IRCDProto::SendQuit(const Anope::string &nick, const Anope::string &)
{
send_cmd(nick, "QUIT");
}
@@ -176,12 +175,12 @@ void IRCDProto::SendQuit(BotInfo *bi, const char *fmt, ...)
SendQuitInternal(bi, buf);
}
-void IRCDProto::SendPing(const char *servname, const char *who)
+void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who)
{
- if (!servname)
- send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who);
+ if (servname.empty())
+ send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who.c_str());
else
- send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname, who);
+ send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname.c_str(), who.c_str());
}
/**
@@ -190,17 +189,17 @@ void IRCDProto::SendPing(const char *servname, const char *who)
* @param servname Daemon or client that is responding to the PING.
* @param who Origin of the PING and destination of the PONG message.
**/
-void IRCDProto::SendPong(const char *servname, const char *who)
+void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who)
{
- if (!servname)
- send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who);
- else
- send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname, who);
+ if (servname.empty())
+ send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who.c_str());
+ else
+ send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname.c_str(), who.c_str());
}
-void IRCDProto::SendInvite(BotInfo *bi, const char *chan, const char *nick)
+void IRCDProto::SendInvite(BotInfo *bi, const Anope::string &chan, const Anope::string &nick)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick, chan);
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick.c_str(), chan.c_str());
}
void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...)
@@ -214,7 +213,8 @@ void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...)
va_end(args);
SendPartInternal(bi, chan, buf);
}
- else SendPartInternal(bi, chan, NULL);
+ else
+ SendPartInternal(bi, chan, "");
}
void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...)
@@ -227,21 +227,22 @@ void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...)
SendGlobopsInternal(source, buf);
}
-void IRCDProto::SendSquit(const char *servname, const char *message)
+void IRCDProto::SendSquit(const Anope::string &servname, const Anope::string &message)
{
- send_cmd(NULL, "SQUIT %s :%s", servname, message);
+ send_cmd("", "SQUIT %s :%s", servname.c_str(), message.c_str());
}
-void IRCDProto::SendChangeBotNick(BotInfo *bi, const char *newnick)
+void IRCDProto::SendChangeBotNick(BotInfo *bi, const Anope::string &newnick)
{
- send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick, static_cast<long>(time(NULL)));
+ send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(time(NULL)));
}
-void IRCDProto::SendForceNickChange(User *u, const char *newnick, time_t when)
+
+void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when)
{
- send_cmd(NULL, "SVSNICK %s %s :%ld", u->nick.c_str(), newnick, static_cast<long>(when));
+ send_cmd("", "SVSNICK %s %s :%ld", u->nick.c_str(), newnick.c_str(), static_cast<long>(when));
}
-void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...)
+void IRCDProto::SendCTCP(BotInfo *bi, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -251,7 +252,7 @@ void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...)
SendCTCPInternal(bi, dest, buf);
}
-void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...)
+void IRCDProto::SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -261,10 +262,10 @@ void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, c
SendNumericInternal(source, numeric, dest, buf);
}
-int IRCDProto::IsChannelValid(const char *chan)
+bool IRCDProto::IsChannelValid(const Anope::string &chan)
{
- if (*chan != '#')
- return 0;
+ if (chan[0] != '#')
+ return false;
- return 1;
+ return true;
}
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 4670bc109..d596b6bb6 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -16,16 +16,14 @@
/** Default constructor
* @param chname The channel name
*/
-ChannelInfo::ChannelInfo(const std::string &chname)
+ChannelInfo::ChannelInfo(const Anope::string &chname)
{
if (chname.empty())
throw CoreException("Empty channel passed to ChannelInfo constructor");
founder = successor = NULL;
- desc = last_topic = forbidby = forbidreason = NULL;
last_topic_time = 0;
levels = NULL;
- entry_message = NULL;
c = NULL;
capsmin = capspercent = 0;
floodlines = floodsecs = 0;
@@ -59,7 +57,7 @@ ChannelInfo::ChannelInfo(const std::string &chname)
reset_levels(this);
- RegisteredChannelList[this->name.c_str()] = this;
+ RegisteredChannelList[this->name] = this;
}
/** Default destructor, cleans up the channel complete and removes it from the internal list
@@ -79,19 +77,8 @@ ChannelInfo::~ChannelInfo()
this->c->ci = NULL;
}
- RegisteredChannelList.erase(this->name.c_str());
+ RegisteredChannelList.erase(this->name);
- if (this->desc)
- delete [] this->desc;
- if (this->entry_message)
- delete [] this->entry_message;
-
- if (this->last_topic)
- delete [] this->last_topic;
- if (this->forbidby)
- delete [] this->forbidby;
- if (this->forbidreason)
- delete [] this->forbidreason;
this->ClearAccess();
this->ClearAkick();
this->ClearBadWords();
@@ -101,11 +88,7 @@ ChannelInfo::~ChannelInfo()
if (!this->memos.memos.empty())
{
for (i = 0, end = this->memos.memos.size(); i < end; ++i)
- {
- if (this->memos.memos[i]->text)
- delete [] this->memos.memos[i]->text;
delete this->memos.memos[i];
- }
this->memos.memos.clear();
}
@@ -126,7 +109,7 @@ ChannelInfo::~ChannelInfo()
* Creates a new access list entry and inserts it into the access list.
*/
-void ChannelInfo::AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen)
+void ChannelInfo::AddAccess(NickCore *nc, int16 level, const Anope::string &creator, int32 last_seen)
{
ChanAccess *new_access = new ChanAccess();
new_access->nc = nc;
@@ -164,7 +147,7 @@ ChanAccess *ChannelInfo::GetAccess(unsigned index)
* Retrieves an entry from the access list that matches the given NickCore, optionally also matching a certain level.
*/
-ChanAccess *ChannelInfo::GetAccess(NickCore *nc, int16 level)
+ChanAccess *ChannelInfo::GetAccess(const NickCore *nc, int16 level)
{
if (access.empty())
return NULL;
@@ -184,7 +167,6 @@ const unsigned ChannelInfo::GetAccessCount() const
return access.empty() ? 0 : access.size();
}
-
/** Erase an entry from the channel access list
*
* @param index The index in the access list vector
@@ -217,7 +199,7 @@ void ChannelInfo::ClearAccess()
* @param lu The time the akick was last used, defaults to never
* @return The AutoKick structure
*/
-AutoKick *ChannelInfo::AddAkick(const std::string &user, NickCore *akicknc, const std::string &reason, time_t t, time_t lu)
+AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu)
{
if (!akicknc)
return NULL;
@@ -243,7 +225,7 @@ AutoKick *ChannelInfo::AddAkick(const std::string &user, NickCore *akicknc, cons
* @param lu The time the akick was last used, defaults to never
* @return The AutoKick structure
*/
-AutoKick *ChannelInfo::AddAkick(const std::string &user, const std::string &mask, const std::string &reason, time_t t, time_t lu)
+AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu)
{
AutoKick *autokick = new AutoKick();
autokick->mask = mask;
@@ -302,7 +284,7 @@ void ChannelInfo::ClearAkick()
* @param type The type (SINGLE START END)
* @return The badword
*/
-BadWord *ChannelInfo::AddBadWord(const std::string &word, BadWordType type)
+BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
{
BadWord *bw = new BadWord;
bw->word = word;
@@ -360,11 +342,11 @@ void ChannelInfo::ClearBadWords()
*/
void ChannelInfo::LoadMLock()
{
- std::vector<std::string> modenames;
+ std::vector<Anope::string> modenames;
if (this->GetExtRegular("db_mlock_modes_on", modenames))
{
- for (std::vector<std::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
+ for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
{
for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit)
{
@@ -372,7 +354,7 @@ void ChannelInfo::LoadMLock()
{
ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit);
- if (cm->NameAsString == *it)
+ if (cm->NameAsString.equals_ci(*it))
this->SetMLock(cm->Name, true);
}
}
@@ -383,7 +365,7 @@ void ChannelInfo::LoadMLock()
if (this->GetExtRegular("db_mlock_modes_off", modenames))
{
- for (std::vector<std::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
+ for (std::vector<Anope::string>::iterator it = modenames.begin(), it_end = modenames.end(); it != it_end; ++it)
{
for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit)
{
@@ -391,7 +373,7 @@ void ChannelInfo::LoadMLock()
{
ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit);
- if (cm->NameAsString == *it)
+ if (cm->NameAsString.equals_ci(*it))
this->SetMLock(cm->Name, false);
}
}
@@ -400,11 +382,11 @@ void ChannelInfo::LoadMLock()
this->Shrink("db_mlock_modes_off");
}
- std::vector<std::pair<std::string, std::string> > params;
+ std::vector<std::pair<Anope::string, Anope::string> > params;
if (this->GetExtRegular("db_mlp", params))
{
- for (std::vector<std::pair<std::string, std::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it)
+ for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = params.begin(), it_end = params.end(); it != it_end; ++it)
{
for (std::list<Mode *>::iterator mit = ModeManager::Modes.begin(), mit_end = ModeManager::Modes.end(); mit != mit_end; ++mit)
{
@@ -412,7 +394,7 @@ void ChannelInfo::LoadMLock()
{
ChannelMode *cm = dynamic_cast<ChannelMode *>(*mit);
- if (cm->NameAsString == it->first)
+ if (cm->NameAsString.equals_ci(it->first))
this->SetMLock(cm->Name, true, it->second);
}
}
@@ -441,7 +423,7 @@ const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status)
* @param param The param to use for this mode, if required
* @return true on success, false on failure (module blocking)
*/
-bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string param)
+bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const Anope::string &param)
{
if (!status && !param.empty())
throw CoreException("Was told to mlock a mode negatively with a param?");
@@ -455,7 +437,7 @@ bool ChannelInfo::SetMLock(ChannelModeName Name, bool status, const std::string
mlock_on.UnsetFlag(Name);
mlock_off.UnsetFlag(Name);
- std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name);
if (it != Params.end())
Params.erase(it);
@@ -484,7 +466,7 @@ bool ChannelInfo::RemoveMLock(ChannelModeName Name)
mlock_on.UnsetFlag(Name);
mlock_off.UnsetFlag(Name);
- std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name);
if (it != Params.end())
Params.erase(it);
@@ -516,9 +498,9 @@ const size_t ChannelInfo::GetMLockCount(bool status) const
* @param Target a string to put the param into
* @return true on success
*/
-const bool ChannelInfo::GetParam(ChannelModeName Name, std::string &Target)
+const bool ChannelInfo::GetParam(ChannelModeName Name, Anope::string &Target)
{
- std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name);
Target.clear();
@@ -536,7 +518,7 @@ const bool ChannelInfo::GetParam(ChannelModeName Name, std::string &Target)
*/
const bool ChannelInfo::HasParam(ChannelModeName Name)
{
- std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
+ std::map<ChannelModeName, Anope::string>::iterator it = Params.find(Name);
if (it != Params.end())
return true;
@@ -559,9 +541,9 @@ bool ChannelInfo::CheckKick(User *user)
{
AutoKick *autokick;
bool set_modes = false, do_kick = false;
- NickCore *nc;
- char mask[BUFSIZE];
- const char *reason;
+ const NickCore *nc;
+ Anope::string mask;
+ Anope::string reason;
if (!user || !this->c)
return false;
@@ -582,8 +564,8 @@ bool ChannelInfo::CheckKick(User *user)
if (!is_oper(user) && (this->HasFlag(CI_SUSPENDED) || this->HasFlag(CI_FORBIDDEN)))
{
- get_idealban(this, user, mask, sizeof(mask));
- reason = this->forbidreason ? this->forbidreason : getstring(user, CHAN_MAY_NOT_BE_USED);
+ get_idealban(this, user, mask);
+ reason = !this->forbidreason.empty() ? this->forbidreason : getstring(user, CHAN_MAY_NOT_BE_USED);
set_modes = true;
do_kick = true;
}
@@ -602,15 +584,15 @@ bool ChannelInfo::CheckKick(User *user)
{
autokick = this->GetAkick(j);
- if ((autokick->HasFlag(AK_ISNICK) && autokick->nc == nc) || (!autokick->HasFlag(AK_ISNICK) && match_usermask(autokick->mask.c_str(), user)))
+ if ((autokick->HasFlag(AK_ISNICK) && autokick->nc == nc) || (!autokick->HasFlag(AK_ISNICK) && match_usermask(autokick->mask, user)))
{
Alog(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask);
autokick->last_used = time(NULL);
if (autokick->HasFlag(AK_ISNICK))
- get_idealban(this, user, mask, sizeof(mask));
+ get_idealban(this, user, mask);
else
- strlcpy(mask, autokick->mask.c_str(), sizeof(mask));
- reason = !autokick->reason.empty() ? autokick->reason.c_str() : Config.CSAutokickReason;
+ mask = autokick->mask;
+ reason = !autokick->reason.empty() ? autokick->reason : Config.CSAutokickReason;
do_kick = true;
break;
}
@@ -619,7 +601,7 @@ bool ChannelInfo::CheckKick(User *user)
if (!do_kick && check_access(user, this, CA_NOJOIN))
{
- get_idealban(this, user, mask, sizeof(mask));
+ get_idealban(this, user, mask);
reason = getstring(user, CHAN_NOT_ALLOWED_TO_JOIN);
do_kick = true;
}
@@ -653,7 +635,7 @@ bool ChannelInfo::CheckKick(User *user)
}
this->c->SetMode(NULL, CMODE_BAN, mask);
- this->c->Kick(NULL, user, "%s", reason);
+ this->c->Kick(NULL, user, "%s", reason.c_str());
return true;
}
diff --git a/src/send.cpp b/src/send.cpp
index 430c7f919..f04e937c2 100644
--- a/src/send.cpp
+++ b/src/send.cpp
@@ -21,42 +21,7 @@
* @param ... any number of parameters
* @return void
*/
-void send_cmd(const char *source, const char *fmt, ...)
-{
- va_list args;
- static char buf[BUFSIZE];
-
- va_start(args, fmt);
-
- vsnprintf(buf, BUFSIZE - 1, fmt, args);
-
- if (!UplinkSock)
- {
- if (source)
- Alog(LOG_DEBUG) << "Attemtped to send \"" << source << " " << buf << "\" with UplinkSock NULL";
- else
- Alog(LOG_DEBUG) << "Attemtped to send \"" << buf << "\" with UplinkSock NULL";
- return;
- }
-
- if (source)
- {
- UplinkSock->Write(":%s %s", source, buf);
- Alog(LOG_DEBUG) << "Sent: :" << source << " " << buf;
- }
- else
- {
- UplinkSock->Write("%s", buf);
- Alog(LOG_DEBUG) << "Sent: "<< buf;
- }
-
- va_end(args);
-}
-
-/*
- * Copypasta version that accepts std::string source.
- */
-void send_cmd(const std::string &source, const char *fmt, ...)
+void send_cmd(const Anope::string &source, const char *fmt, ...)
{
va_list args;
static char buf[BUFSIZE];
@@ -70,7 +35,7 @@ void send_cmd(const std::string &source, const char *fmt, ...)
if (!source.empty())
Alog(LOG_DEBUG) << "Attemtped to send \"" << source << " " << buf << "\" with UplinkSock NULL";
else
- Alog(LOG_DEBUG) << "Attemtped to send " << buf << "\" with UplinkSock NULL";
+ Alog(LOG_DEBUG) << "Attemtped to send \"" << buf << "\" with UplinkSock NULL";
return;
}
@@ -82,7 +47,7 @@ void send_cmd(const std::string &source, const char *fmt, ...)
else
{
UplinkSock->Write("%s", buf);
- Alog(LOG_DEBUG) << "Sent: " << buf;
+ Alog(LOG_DEBUG) << "Sent: "<< buf;
}
va_end(args);
@@ -98,7 +63,7 @@ void send_cmd(const std::string &source, const char *fmt, ...)
* @param ... any number of parameters
* @return void
*/
-void notice_server(char *source, Server * s, const char *fmt, ...)
+void notice_server(const Anope::string &source, Server *s, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -119,32 +84,6 @@ void notice_server(char *source, Server * s, const char *fmt, ...)
/*************************************************************************/
/**
- * Send a NULL-terminated array of text as NOTICEs.
- * @param source Orgin of the Message
- * @param dest Destination of the Notice
- * @param text Array of text to send
- * @return void
- */
-void notice_list(char *source, char *dest, char **text)
-{
- User *u = finduser(dest);
- while (*text)
- {
- /* Have to kludge around an ircII bug here: if a notice includes
- * no text, it is ignored, so we replace blank lines by lines
- * with a single space.
- */
- if (**text)
- u->SendMessage(source, "%s", *text);
- else
- u->SendMessage(source, " ");
- ++text;
- }
-}
-
-/*************************************************************************/
-
-/**
* Send a message in the user's selected language to the user using NOTICE.
* @param source Orgin of the Message
* @param u User Struct
@@ -152,7 +91,7 @@ void notice_list(char *source, char *dest, char **text)
* @param ... any number of parameters
* @return void
*/
-void notice_lang(const std::string &source, User * dest, int message, ...)
+void notice_lang(const Anope::string &source, User *dest, int message, ...)
{
va_list args;
char buf[4096]; /* because messages can be really big */
@@ -193,7 +132,7 @@ void notice_lang(const std::string &source, User * dest, int message, ...)
* @param ... any number of parameters
* @return void
*/
-void notice_help(const char *source, User * dest, int message, ...)
+void notice_help(const Anope::string &source, User * dest, int message, ...)
{
va_list args;
char buf[4096], buf2[4096], outbuf[BUFSIZE];
@@ -220,7 +159,7 @@ void notice_help(const char *source, User * dest, int message, ...)
if (*s)
*s++ = 0;
strscpy(outbuf, t, sizeof(outbuf));
- strnrepl(outbuf, sizeof(outbuf), "\1\1", source);
+ strnrepl(outbuf, sizeof(outbuf), "\1\1", source.c_str());
dest->SendMessage(source, "%s", *outbuf ? outbuf : " ");
}
diff --git a/src/servers.cpp b/src/servers.cpp
index 69562e9c2..251e594ea 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -12,7 +12,7 @@
#include "services.h"
#include "modules.h"
-char *TS6SID = NULL;
+Anope::string TS6SID;
/* Anope */
Server *Me = NULL;
@@ -56,7 +56,7 @@ Flags<CapabType, CAPAB_END> Capab;
* @param description Server rdescription
* @param sid Server sid/numeric
*/
-Server::Server(Server *uplink, const std::string &name, unsigned int hops, const std::string &description, const std::string &sid) : Name(name), Hops(hops), Description(description), SID(sid), UplinkServer(uplink)
+Server::Server(Server *uplink, const Anope::string &name, unsigned int hops, const Anope::string &description, const Anope::string &sid) : Name(name), Hops(hops), Description(description), SID(sid), UplinkServer(uplink)
{
Links = NULL;
@@ -103,9 +103,7 @@ Server::~Server()
if (na && !na->HasFlag(NS_FORBIDDEN) && (!na->nc->HasFlag(NI_SUSPENDED)) && (u->IsRecognized() || u->IsIdentified()))
{
na->last_seen = t;
- if (na->last_quit)
- delete [] na->last_quit;
- na->last_quit = (!QReason.empty() ? sstrdup(QReason.c_str()) : NULL);
+ na->last_quit = QReason;
}
delete u;
@@ -116,15 +114,11 @@ Server::~Server()
}
if (UplinkServer)
- {
UplinkServer->DelLink(this);
- }
if (Links)
- {
for (std::list<Server *>::iterator it = Links->begin(), it_end = Links->end(); it != it_end; ++it)
delete *it;
- }
delete Links;
}
@@ -132,7 +126,7 @@ Server::~Server()
/** Delete this server with a reason
* @param reason The reason
*/
-void Server::Delete(const std::string &reason)
+void Server::Delete(const Anope::string &reason)
{
QReason = reason;
delete this;
@@ -141,7 +135,7 @@ void Server::Delete(const std::string &reason)
/** Get the name for this server
* @return The name
*/
-const std::string &Server::GetName() const
+const Anope::string &Server::GetName() const
{
return Name;
}
@@ -157,7 +151,7 @@ unsigned int Server::GetHops() const
/** Set the server description
* @param desc The new description
*/
-void Server::SetDescription(const std::string &desc)
+void Server::SetDescription(const Anope::string &desc)
{
Description = desc;
}
@@ -165,7 +159,7 @@ void Server::SetDescription(const std::string &desc)
/** Get the server description
* @return The server description
*/
-const std::string &Server::GetDescription() const
+const Anope::string &Server::GetDescription() const
{
return Description;
}
@@ -173,7 +167,7 @@ const std::string &Server::GetDescription() const
/** Get the server numeric/SID
* @return The numeric/SID
*/
-const std::string &Server::GetSID() const
+const Anope::string &Server::GetSID() const
{
return SID;
}
@@ -204,7 +198,7 @@ void Server::AddLink(Server *s)
*/
if (this == Me && !UplinkServer)
UplinkServer = s;
-
+
if (!Links)
Links = new std::list<Server *>();
@@ -286,8 +280,8 @@ bool Server::IsSynced() const
*/
bool Server::IsULined() const
{
- for (int j = 0; j < Config.NumUlines; ++j)
- if (!stricmp(Config.Ulines[j], GetName().c_str()))
+ for (std::list<Anope::string>::const_iterator it = Config.Ulines.begin(), it_end = Config.Ulines.end(); it != it_end; ++it)
+ if (it->equals_ci(GetName()))
return true;
return false;
}
@@ -297,13 +291,13 @@ bool Server::IsULined() const
* @param s The server list to search for this server on, defaults to our Uplink
* @return The server
*/
-Server *Server::Find(const std::string &name, Server *s)
+Server *Server::Find(const Anope::string &name, Server *s)
{
Alog(LOG_DEBUG) << "Server::Find called for " << name;
if (!s)
s = Me;
- if (s->GetName() == name || s->GetSID() == name)
+ if (s->GetName().equals_cs(name) || s->GetSID().equals_cs(name))
return s;
if (s->GetLinks())
@@ -312,7 +306,7 @@ Server *Server::Find(const std::string &name, Server *s)
{
Server *serv = *it;
- if (serv->GetName() == name || serv->GetSID() == name)
+ if (serv->GetName().equals_cs(name) || serv->GetSID().equals_cs(name))
return serv;
Alog(LOG_DEBUG) << "Server::Find checking " << serv->GetName() << " server tree for " << name;
Server *server = Server::Find(name, serv);
@@ -335,7 +329,7 @@ Server *Server::Find(const std::string &name, Server *s)
* @param numeric Server Numberic/SUID
* @return void
*/
-void do_server(const std::string &source, const std::string &servername, unsigned int hops, const std::string &descript, const std::string &numeric)
+void do_server(const Anope::string &source, const Anope::string &servername, unsigned int hops, const Anope::string &descript, const Anope::string &numeric)
{
if (source.empty())
Alog(LOG_DEBUG) << "Server " << servername << " introduced";
@@ -358,8 +352,8 @@ void do_server(const std::string &source, const std::string &servername, unsigne
Server *newserver = new Server(s, servername, hops, descript, numeric);
/* Announce services being online. */
- if (Config.GlobalOnCycle && Config.GlobalOnCycleUP)
- notice_server(Config.s_GlobalNoticer, newserver, "%s", Config.GlobalOnCycleUP);
+ if (Config.GlobalOnCycle && !Config.GlobalOnCycleUP.empty())
+ notice_server(Config.s_GlobalNoticer, newserver, "%s", Config.GlobalOnCycleUP.c_str());
/* Let modules know about the connection */
FOREACH_MOD(I_OnNewServer, OnNewServer(newserver));
@@ -374,9 +368,8 @@ void do_server(const std::string &source, const std::string &servername, unsigne
* @param av Agruments as part of the SQUIT
* @return void
*/
-void do_squit(const char *source, int ac, const char **av)
+void do_squit(const Anope::string &source, int ac, const char **av)
{
- char buf[BUFSIZE];
Server *s = Server::Find(av[0]);
if (!s)
@@ -387,22 +380,23 @@ void do_squit(const char *source, int ac, const char **av)
FOREACH_MOD(I_OnServerQuit, OnServerQuit(s));
+ Anope::string buf;
/* If this is a juped server, send a nice global to inform the online
* opers that we received it.
*/
if (s->HasFlag(SERVER_JUPED))
{
- snprintf(buf, BUFSIZE, "Received SQUIT for juped server %s", s->GetName().c_str());
- ircdproto->SendGlobops(OperServ, buf);
+ buf = "Received SQUIT for juped server " + s->GetName();
+ ircdproto->SendGlobops(OperServ, "%s", buf.c_str());
}
- snprintf(buf, sizeof(buf), "%s %s", s->GetName().c_str(), s->GetUplink()->GetName().c_str());
+ buf = s->GetName() + " " + s->GetUplink()->GetName();
if (s->GetUplink() == Me->GetUplink() && Capab.HasFlag(CAPAB_UNCONNECT))
{
Alog(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName();
/* need to fix */
- ircdproto->SendSquit(s->GetName().c_str(), buf);
+ ircdproto->SendSquit(s->GetName(), buf);
}
s->Delete(buf);
@@ -420,11 +414,11 @@ void CapabParse(int ac, const char **av)
{
for (unsigned j = 0; !Capab_Info[j].Token.empty(); ++j)
{
- if (av[i] == Capab_Info[j].Token)
+ if (Capab_Info[j].Token.equals_ci(av[i]))
{
Capab.SetFlag(Capab_Info[j].Flag);
- if (Capab_Info[j].Token == "NICKIP" && !ircd->nickip)
+ if (Capab_Info[j].Token.equals_ci("NICKIP") && !ircd->nickip)
ircd->nickip = 1;
break;
}
@@ -452,7 +446,7 @@ static char ts6_new_uid[10];
static void ts6_uid_increment(unsigned int slot)
{
- if (slot != strlen(TS6SID))
+ if (slot != TS6SID.length())
{
if (ts6_new_uid[slot] == 'Z')
ts6_new_uid[slot] = '0';
@@ -487,7 +481,7 @@ const char *ts6_uid_retrieve()
if (!ts6_uid_initted)
{
- snprintf(ts6_new_uid, 10, "%sAAAAAA", TS6SID);
+ snprintf(ts6_new_uid, 10, "%sAAAAAA", TS6SID.c_str());
ts6_uid_initted = true;
}
@@ -554,7 +548,7 @@ const char *ts6_sid_retrieve()
if (!ts6_sid_initted)
{
// Initialize ts6_new_sid with the services server SID
- snprintf(ts6_new_sid, 4, "%s", TS6SID);
+ snprintf(ts6_new_sid, 4, "%s", TS6SID.c_str());
ts6_sid_initted = true;
}
diff --git a/src/sessions.cpp b/src/sessions.cpp
index 9c8ec7163..9a1bc7a76 100644
--- a/src/sessions.cpp
+++ b/src/sessions.cpp
@@ -51,8 +51,7 @@
session_map SessionList;
-Exception *exceptions = NULL;
-int16 nexceptions = 0;
+std::vector<Exception *> exceptions;
/*************************************************************************/
/****************************** Statistics *******************************/
@@ -66,7 +65,7 @@ void get_session_stats(long *nrec, long *memuse)
{
Session *session = it->second;
- mem += strlen(session->host) + 1;
+ mem += session->host.length() + 1;
}
*memuse = mem;
@@ -76,15 +75,19 @@ void get_session_stats(long *nrec, long *memuse)
void get_exception_stats(long *nrec, long *memuse)
{
long mem;
- int i;
- mem = sizeof(Exception) * nexceptions;
- for (i = 0; i < nexceptions; ++i)
+ mem = sizeof(Exception) * exceptions.size();
+ for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it)
{
- mem += strlen(exceptions[i].mask) + 1;
- mem += strlen(exceptions[i].reason) + 1;
+ Exception *e = *it;
+ if (!e->mask.empty())
+ mem += e->mask.length() + 1;
+ if (!e->reason.empty())
+ mem += e->reason.length() + 1;
+ if (!e->who.empty())
+ mem += e->who.length() + 1;
}
- *nrec = nexceptions;
+ *nrec = exceptions.size();
*memuse = mem;
}
@@ -92,7 +95,7 @@ void get_exception_stats(long *nrec, long *memuse)
/********************* Internal Session Functions ************************/
/*************************************************************************/
-Session *findsession(const std::string &host)
+Session *findsession(const Anope::string &host)
{
session_map::const_iterator it = SessionList.find(host);
@@ -106,7 +109,7 @@ Session *findsession(const std::string &host)
* Returns 1 if the host was added or 0 if the user was killed.
*/
-int add_session(const char *nick, const char *host, char *hostip)
+int add_session(const Anope::string &nick, const Anope::string &host, const Anope::string &hostip)
{
Session *session;
Exception *exception;
@@ -120,12 +123,12 @@ int add_session(const char *nick, const char *host, char *hostip)
sessionlimit = exception ? exception->limit : Config.DefSessionLimit;
- if (sessionlimit != 0 && session->count >= sessionlimit)
+ if (sessionlimit && session->count >= sessionlimit)
{
- if (Config.SessionLimitExceeded)
- ircdproto->SendMessage(OperServ, nick, Config.SessionLimitExceeded, host);
- if (Config.SessionLimitDetailsLoc)
- ircdproto->SendMessage(OperServ, nick, "%s", Config.SessionLimitDetailsLoc);
+ if (!Config.SessionLimitExceeded.empty())
+ ircdproto->SendMessage(OperServ, nick, Config.SessionLimitExceeded.c_str(), host.c_str());
+ if (!Config.SessionLimitDetailsLoc.empty())
+ ircdproto->SendMessage(OperServ, nick, "%s", Config.SessionLimitDetailsLoc.c_str());
/* Previously on IRCds that send a QUIT (InspIRCD) when a user is killed, the session for a host was
* decremented in do_quit, which caused problems and fixed here
@@ -140,12 +143,11 @@ int add_session(const char *nick, const char *host, char *hostip)
++session->hits;
if (Config.MaxSessionKill && session->hits >= Config.MaxSessionKill)
{
- char akillmask[BUFSIZE];
- snprintf(akillmask, sizeof(akillmask), "*@%s", host);
- XLine *x = new XLine(ci::string("*@") + host, Config.s_OperServ, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded");
+ Anope::string akillmask = "*@" + host;
+ XLine *x = new XLine(akillmask, Config.s_OperServ, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded");
if (x)
x->By = Config.s_OperServ;
- ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask);
+ ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask.c_str());
}
return 0;
}
@@ -157,7 +159,7 @@ int add_session(const char *nick, const char *host, char *hostip)
}
session = new Session;
- session->host = sstrdup(host);
+ session->host = host;
session->count = 1;
session->hits = 0;
@@ -166,7 +168,7 @@ int add_session(const char *nick, const char *host, char *hostip)
return 1;
}
-void del_session(const char *host)
+void del_session(const Anope::string &host)
{
if (!Config.LimitSessions)
{
@@ -174,7 +176,7 @@ void del_session(const char *host)
return;
}
- if (!host || !*host)
+ if (host.empty())
{
Alog(LOG_DEBUG) << "del_session called with NULL values";
return;
@@ -188,7 +190,7 @@ void del_session(const char *host)
{
if (debug)
{
- ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", host);
+ ircdproto->SendGlobops(OperServ, "WARNING: Tried to delete non-existant session: \2%s", host.c_str());
Alog(LOG_DEBUG) << "session: Tried to delete non-existant session: " << host;
}
return;
@@ -204,7 +206,6 @@ void del_session(const char *host)
Alog(LOG_DEBUG_2) << "del_session(): free session structure";
- delete [] session->host;
delete session;
Alog(LOG_DEBUG_2) << "del_session() done";
@@ -216,46 +217,45 @@ void del_session(const char *host)
void expire_exceptions()
{
- int i;
time_t now = time(NULL);
- for (i = 0; i < nexceptions; ++i)
+ for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; )
{
- if (!exceptions[i].expires || exceptions[i].expires > now)
+ Exception *e = *it;
+ std::vector<Exception *>::iterator curr_it = it++;
+
+ if (!e->expires || e->expires > now)
continue;
if (Config.WallExceptionExpire)
- ircdproto->SendGlobops(OperServ, "Session limit exception for %s has expired.", exceptions[i].mask);
- delete [] exceptions[i].mask;
- delete [] exceptions[i].reason;
- delete [] exceptions[i].who;
- --nexceptions;
- memmove(exceptions + i, exceptions + i + 1, sizeof(Exception) * (nexceptions - i));
- exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions));
- --i;
+ ircdproto->SendGlobops(OperServ, "Session limit exception for %s has expired.", e->mask.c_str());
+ delete e;
+ exceptions.erase(curr_it);
}
}
/* Find the first exception this host matches and return it. */
-Exception *find_host_exception(const char *host)
+Exception *find_host_exception(const Anope::string &host)
{
- int i;
-
- for (i = 0; i < nexceptions; ++i)
- if ((Anope::Match(host, exceptions[i].mask, false)))
- return &exceptions[i];
+ for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it)
+ {
+ Exception *e = *it;
+ if (Anope::Match(host, e->mask))
+ return e;
+ }
return NULL;
}
/* Same as find_host_exception() except
* this tries to find the exception by IP also. */
-Exception *find_hostip_exception(const char *host, const char *hostip)
+Exception *find_hostip_exception(const Anope::string &host, const Anope::string &hostip)
{
- int i;
-
- for (i = 0; i < nexceptions; ++i)
- if (Anope::Match(host, exceptions[i].mask, false) || ((ircd->nickip && hostip) && Anope::Match(hostip, exceptions[i].mask, false)))
- return &exceptions[i];
+ for (std::vector<Exception *>::const_iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it)
+ {
+ Exception *e = *it;
+ if (Anope::Match(host, e->mask) || (ircd->nickip && !hostip.empty() && Anope::Match(hostip, e->mask)))
+ return e;
+ }
return NULL;
}
@@ -264,52 +264,47 @@ Exception *find_hostip_exception(const char *host, const char *hostip)
/************************ Exception Manipulation *************************/
/*************************************************************************/
-int exception_add(User *u, const char *mask, const int limit, const char *reason, const char *who, const time_t expires)
+int exception_add(User *u, const Anope::string &mask, int limit, const Anope::string &reason, const Anope::string &who, time_t expires)
{
- int i;
-
/* Check if an exception already exists for this mask */
- for (i = 0; i < nexceptions; ++i)
+ for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ++it)
{
- if (!stricmp(mask, exceptions[i].mask))
+ Exception *e = *it;
+ if (e->mask.equals_ci(mask))
{
- if (exceptions[i].limit != limit)
+ if (e->limit != limit)
{
- exceptions[i].limit = limit;
+ e->limit = limit;
if (u)
- notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_CHANGED, mask, exceptions[i].limit);
+ notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_CHANGED, mask.c_str(), e->limit);
return -2;
}
else
{
if (u)
- notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_EXISTS, mask);
+ notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_EXISTS, mask.c_str());
return -1;
}
}
}
- nexceptions++;
- exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions));
-
- exceptions[nexceptions - 1].mask = sstrdup(mask);
- exceptions[nexceptions - 1].limit = limit;
- exceptions[nexceptions - 1].reason = sstrdup(reason);
- exceptions[nexceptions - 1].time = time(NULL);
- exceptions[nexceptions - 1].who = sstrdup(who);
- exceptions[nexceptions - 1].expires = expires;
- exceptions[nexceptions - 1].num = nexceptions - 1;
+ Exception *exception = new Exception();
+ exception->mask = mask;
+ exception->limit = limit;
+ exception->reason = reason;
+ exception->time = time(NULL);
+ exception->who = who;
+ exception->expires = expires;
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnExceptionAdd, OnExceptionAdd(u, &exceptions[nexceptions - 1]));
+ FOREACH_RESULT(I_OnExceptionAdd, OnExceptionAdd(u, exception));
if (MOD_RESULT == EVENT_STOP)
{
- delete [] exceptions[nexceptions - 1].mask;
- delete [] exceptions[nexceptions - 1].reason;
- --nexceptions;
- exceptions = static_cast<Exception *>(srealloc(exceptions, sizeof(Exception) * nexceptions));
+ delete exception;
return -3;
}
+ exceptions.push_back(exception);
+
return 1;
}
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 418b1b334..d72b2847d 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -24,9 +24,9 @@ Socket::Socket(int nsock, bool nIPv6)
Type = SOCKTYPE_CLIENT;
IPv6 = nIPv6;
if (nsock == 0)
- sock = socket(IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
+ Sock = socket(IPv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
else
- sock = nsock;
+ Sock = nsock;
SocketEngine->AddSocket(this);
}
@@ -35,7 +35,7 @@ Socket::Socket(int nsock, bool nIPv6)
Socket::~Socket()
{
SocketEngine->DelSocket(this);
- CloseSocket(sock);
+ CloseSocket(Sock);
}
/** Really recieve something from the buffer
@@ -52,7 +52,7 @@ const int Socket::RecvInternal(char *buf, size_t sz) const
* @param buf What to write
* @return Number of bytes written
*/
-const int Socket::SendInternal(const std::string &buf) const
+const int Socket::SendInternal(const Anope::string &buf) const
{
return send(GetSock(), buf.c_str(), buf.length(), 0);
}
@@ -62,7 +62,7 @@ const int Socket::SendInternal(const std::string &buf) const
*/
int Socket::GetSock() const
{
- return sock;
+ return Sock;
}
/** Mark a socket as blockig
@@ -122,8 +122,7 @@ size_t Socket::WriteBufferLen() const
*/
bool Socket::ProcessRead()
{
- char tbuffer[NET_BUFSIZE];
- memset(&tbuffer, '\0', sizeof(tbuffer));
+ char tbuffer[NET_BUFSIZE] = "";
RecvLen = RecvInternal(tbuffer, sizeof(tbuffer) - 1);
if (RecvLen <= 0)
@@ -132,7 +131,7 @@ bool Socket::ProcessRead()
std::string sbuffer = extrabuf;
sbuffer.append(tbuffer);
extrabuf.clear();
- size_t lastnewline = sbuffer.find_last_of('\n');
+ size_t lastnewline = sbuffer.rfind('\n');
if (lastnewline == std::string::npos)
{
extrabuf = sbuffer;
@@ -147,10 +146,12 @@ bool Socket::ProcessRead()
sepstream stream(sbuffer, '\n');
- std::string tbuf;
+ Anope::string tbuf;
while (stream.GetToken(tbuf))
{
- TrimBuf(tbuf);
+ std::string tmp_tbuf = tbuf.str();
+ TrimBuf(tmp_tbuf);
+ tbuf = tmp_tbuf;
if (!tbuf.empty())
if (!Read(tbuf))
@@ -190,7 +191,7 @@ void Socket::ProcessError()
* @param buf The line
* @return true to continue reading, false to drop the socket
*/
-bool Socket::Read(const std::string &buf)
+bool Socket::Read(const Anope::string &buf)
{
return false;
}
@@ -202,8 +203,7 @@ void Socket::Write(const char *message, ...)
{
va_list vi;
char tbuffer[BUFSIZE];
- std::string sbuf;
-
+
if (!message)
return;
@@ -211,16 +211,16 @@ void Socket::Write(const char *message, ...)
vsnprintf(tbuffer, sizeof(tbuffer), message, vi);
va_end(vi);
- sbuf = tbuffer;
+ Anope::string sbuf = tbuffer;
Write(sbuf);
}
/** Write to the socket
* @param message The message
*/
-void Socket::Write(const std::string &message)
+void Socket::Write(const Anope::string &message)
{
- WriteBuffer.append(message + "\r\n");
+ WriteBuffer.append(message.str() + "\r\n");
SocketEngine->MarkWriteable(this);
}
@@ -230,11 +230,11 @@ void Socket::Write(const std::string &message)
* @param nsock The socket
* @param nIPv6 IPv6
*/
-ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost, bool nIPv6) : Socket(0, nIPv6), TargetHost(nTargetHost), Port(nPort), BindHost(nBindHost)
+ClientSocket::ClientSocket(const Anope::string &nTargetHost, int nPort, const Anope::string &nBindHost, bool nIPv6) : Socket(0, nIPv6), TargetHost(nTargetHost), Port(nPort), BindHost(nBindHost)
{
- if (!IPv6 && (TargetHost.find(':') != std::string::npos || BindHost.find(':') != std::string::npos))
+ if (!IPv6 && (TargetHost.find(':') != Anope::string::npos || BindHost.find(':') != Anope::string::npos))
IPv6 = true;
-
+
addrinfo hints;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = 0;
@@ -247,7 +247,7 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
sockaddr_in bindaddr;
sockaddr_in6 bindaddr6;
- if (getaddrinfo(BindHost.c_str(), NULL, &hints, &bindar) == 0)
+ if (!getaddrinfo(BindHost.c_str(), NULL, &hints, &bindar))
{
if (IPv6)
memcpy(&bindaddr6, bindar->ai_addr, bindar->ai_addrlen);
@@ -263,26 +263,26 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
bindaddr6.sin6_family = AF_INET6;
if (inet_pton(AF_INET6, BindHost.c_str(), &bindaddr6.sin6_addr) < 1)
- throw SocketException("Invalid bind host: " + std::string(strerror(errno)));
+ throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno));
}
else
{
bindaddr.sin_family = AF_INET;
if (inet_pton(AF_INET, BindHost.c_str(), &bindaddr.sin_addr) < 1)
- throw SocketException("Invalid bind host: " + std::string(strerror(errno)));
+ throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno));
}
}
if (IPv6)
{
- if (bind(sock, reinterpret_cast<sockaddr *>(&bindaddr6), sizeof(bindaddr6)) == -1)
- throw SocketException("Unable to bind to address: " + std::string(strerror(errno)));
+ if (bind(Sock, reinterpret_cast<sockaddr *>(&bindaddr6), sizeof(bindaddr6)) == -1)
+ throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno));
}
else
{
- if (bind(sock, reinterpret_cast<sockaddr *>(&bindaddr), sizeof(bindaddr)) == -1)
- throw SocketException("Unable to bind to address: " + std::string(strerror(errno)));
+ if (bind(Sock, reinterpret_cast<sockaddr *>(&bindaddr), sizeof(bindaddr)) == -1)
+ throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno));
}
}
@@ -290,7 +290,7 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
sockaddr_in6 addr6;
sockaddr_in addr;
- if (getaddrinfo(TargetHost.c_str(), NULL, &hints, &conar) == 0)
+ if (!getaddrinfo(TargetHost.c_str(), NULL, &hints, &conar))
{
if (IPv6)
memcpy(&addr6, conar->ai_addr, conar->ai_addrlen);
@@ -304,12 +304,12 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
if (IPv6)
{
if (inet_pton(AF_INET6, TargetHost.c_str(), &addr6.sin6_addr) < 1)
- throw SocketException("Invalid server host: " + std::string(strerror(errno)));
+ throw SocketException(Anope::string("Invalid server host: ") + strerror(errno));
}
else
{
if (inet_pton(AF_INET, TargetHost.c_str(), &addr.sin_addr) < 1)
- throw SocketException("Invalid server host: " + std::string(strerror(errno)));
+ throw SocketException(Anope::string("Invalid server host: ") + strerror(errno));
}
}
@@ -318,20 +318,16 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
addr6.sin6_family = AF_INET6;
addr6.sin6_port = htons(nPort);
- if (connect(sock, reinterpret_cast<sockaddr *>(&addr6), sizeof(addr6)) == -1)
- {
- throw SocketException("Error connecting to server: " + std::string(strerror(errno)));
- }
+ if (connect(Sock, reinterpret_cast<sockaddr *>(&addr6), sizeof(addr6)) == -1)
+ throw SocketException(Anope::string("Error connecting to server: ") + strerror(errno));
}
else
{
addr.sin_family = AF_INET;
addr.sin_port = htons(nPort);
- if (connect(sock, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)) == -1)
- {
- throw SocketException("Error connecting to server: " + std::string(strerror(errno)));
- }
+ if (connect(Sock, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)) == -1)
+ throw SocketException(Anope::string("Error connecting to server: ") + strerror(errno));
}
this->SetNonBlocking();
@@ -347,7 +343,7 @@ ClientSocket::~ClientSocket()
* @param buf The line
* @return true to continue reading, false to drop the socket
*/
-bool ClientSocket::Read(const std::string &buf)
+bool ClientSocket::Read(const Anope::string &buf)
{
return true;
}
@@ -356,7 +352,7 @@ bool ClientSocket::Read(const std::string &buf)
* @param bind The IP to bind to
* @param port The port to listen on
*/
-ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bindip.find(':') != std::string::npos ? true : false))
+ListenSocket::ListenSocket(const Anope::string &bindip, int port) : Socket(0, (bindip.find(':') != Anope::string::npos ? true : false))
{
Type = SOCKTYPE_LISTEN;
BindIP = bindip;
@@ -364,16 +360,14 @@ ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bin
sockaddr_in sock_addr;
sockaddr_in6 sock_addr6;
-
+
if (IPv6)
{
sock_addr6.sin6_family = AF_INET6;
sock_addr6.sin6_port = htons(port);
-
+
if (inet_pton(AF_INET6, bindip.c_str(), &sock_addr6.sin6_addr) < 1)
- {
- throw SocketException("Invalid bind host: " + std::string(strerror(errno)));
- }
+ throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno));
}
else
{
@@ -381,30 +375,22 @@ ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bin
sock_addr.sin_port = htons(port);
if (inet_pton(AF_INET, bindip.c_str(), &sock_addr.sin_addr) < 1)
- {
- throw SocketException("Invalid bind host: " + std::string(strerror(errno)));
- }
+ throw SocketException(Anope::string("Invalid bind host: ") + strerror(errno));
}
if (IPv6)
{
- if (bind(sock, reinterpret_cast<sockaddr *>(&sock_addr6), sizeof(sock_addr6)) == -1)
- {
- throw SocketException("Unable to bind to address: " + std::string(strerror(errno)));
- }
+ if (bind(Sock, reinterpret_cast<sockaddr *>(&sock_addr6), sizeof(sock_addr6)) == -1)
+ throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno));
}
else
{
- if (bind(sock, reinterpret_cast<sockaddr *>(&sock_addr), sizeof(sock_addr)) == -1)
- {
- throw SocketException("Unable to bind to address: " + std::string(strerror(errno)));
- }
+ if (bind(Sock, reinterpret_cast<sockaddr *>(&sock_addr), sizeof(sock_addr)) == -1)
+ throw SocketException(Anope::string("Unable to bind to address: ") + strerror(errno));
}
- if (listen(sock, 5) == -1)
- {
- throw SocketException("Unable to listen: " + std::string(strerror(errno)));
- }
+ if (listen(Sock, 5) == -1)
+ throw SocketException(Anope::string("Unable to listen: ") + strerror(errno));
this->SetNonBlocking();
}
@@ -419,16 +405,14 @@ ListenSocket::~ListenSocket()
*/
bool ListenSocket::ProcessRead()
{
- int newsock = accept(sock, NULL, NULL);
+ int newsock = accept(Sock, NULL, NULL);
#ifndef _WIN32
# define INVALID_SOCKET 0
#endif
if (newsock > 0 && newsock != INVALID_SOCKET)
- {
return this->OnAccept(new Socket(newsock, IPv6));
- }
return true;
}
@@ -445,9 +429,9 @@ bool ListenSocket::OnAccept(Socket *s)
/** Get the bind IP for this socket
* @return the bind ip
*/
-const std::string &ListenSocket::GetBindIP() const
+const Anope::string &ListenSocket::GetBindIP() const
{
- return BindIP;
+ return BindIP;
}
/** Get the port this socket is bound to
@@ -457,4 +441,3 @@ const int ListenSocket::GetPort() const
{
return Port;
}
-
diff --git a/src/threadengines/threadengine_pthread.cpp b/src/threadengines/threadengine_pthread.cpp
index a85af583e..f63cc066e 100644
--- a/src/threadengines/threadengine_pthread.cpp
+++ b/src/threadengines/threadengine_pthread.cpp
@@ -47,7 +47,7 @@ void ThreadEngine::Start(Thread *thread)
if (pthread_create(&thread->Handle, &threadengine_attr, entry_point, thread))
{
delete thread;
- throw CoreException("Unable to create thread: " + std::string(strerror(errno)));
+ throw CoreException(Anope::string("Unable to create thread: ") + strerror(errno));
}
}
diff --git a/src/threadengines/threadengine_win32.cpp b/src/threadengines/threadengine_win32.cpp
index 54db9529a..a07a75cce 100644
--- a/src/threadengines/threadengine_win32.cpp
+++ b/src/threadengines/threadengine_win32.cpp
@@ -43,7 +43,7 @@ void ThreadEngine::Start(Thread *thread)
if (!thread->Handle)
{
delete thread;
- throw CoreException("Unable to create thread: " + std::string(dlerror()));
+ throw CoreException(Anope::string("Unable to create thread: ") + dlerror());
}
}
diff --git a/src/timers.cpp b/src/timers.cpp
index e4a2ef04b..df3f2d228 100644
--- a/src/timers.cpp
+++ b/src/timers.cpp
@@ -99,7 +99,7 @@ void TimerManager::DelTimer(Timer *T)
*/
void TimerManager::TickTimers(time_t ctime)
{
- while (Timers.size() && (ctime > Timers.front()->GetTimer()))
+ while (Timers.size() && ctime > Timers.front()->GetTimer())
{
Timer *t = Timers.front();
@@ -119,5 +119,5 @@ void TimerManager::TickTimers(time_t ctime)
*/
bool TimerManager::TimerComparison(Timer *one, Timer *two)
{
- return (one->GetTimer() < two->GetTimer());
+ return one->GetTimer() < two->GetTimer();
}
diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h
index cf265c92f..b2e067f87 100644
--- a/src/tools/db-convert.h
+++ b/src/tools/db-convert.h
@@ -704,8 +704,6 @@ int delcore(NickCore *nc)
nclists[HASH(nc->display)] = nc->next;
delete [] nc->display;
- if (nc->pass)
- delete [] nc->pass;
if (nc->email)
delete [] nc->email;
if (nc->greet)
diff --git a/src/users.cpp b/src/users.cpp
index 887929c76..6ccaf9bf0 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -26,15 +26,14 @@ time_t maxusertime;
/*************************************************************************/
/*************************************************************************/
-User::User(const std::string &snick, const std::string &suid)
+User::User(const Anope::string &snick, const Anope::string &suid)
{
if (snick.empty())
- throw "what the craq, empty nick passed to constructor";
+ throw CoreException("what the craq, empty nick passed to constructor");
// XXX: we should also duplicate-check here.
/* we used to do this by calloc, no more. */
- host = hostip = vhost = realname = NULL;
server = NULL;
nc = NULL;
invalid_pw_count = timestamp = my_signon = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0;
@@ -43,7 +42,7 @@ User::User(const std::string &snick, const std::string &suid)
this->nick = snick;
this->uid = suid;
- UserListByNick[snick.c_str()] = this;
+ UserListByNick[snick] = this;
if (!suid.empty())
UserListByUID[suid] = this;
@@ -62,19 +61,19 @@ User::User(const std::string &snick, const std::string &suid)
this->isSuperAdmin = 0; /* always set SuperAdmin to 0 for new users */
}
-void User::SetNewNick(const std::string &newnick)
+void User::SetNewNick(const Anope::string &newnick)
{
/* Sanity check to make sure we don't segfault */
if (newnick.empty())
- throw "User::SetNewNick() got a bad argument";
+ throw CoreException("User::SetNewNick() got a bad argument");
Alog(LOG_DEBUG) << this->nick << " changed nick to " << newnick;
- UserListByNick.erase(this->nick.c_str());
+ UserListByNick.erase(this->nick);
this->nick = newnick;
- UserListByNick[this->nick.c_str()] = this;
+ UserListByNick[this->nick] = this;
OnAccess = false;
NickAlias *na = findnick(this->nick);
@@ -82,14 +81,12 @@ void User::SetNewNick(const std::string &newnick)
OnAccess = is_on_access(this, na->nc);
}
-void User::SetDisplayedHost(const std::string &shost)
+void User::SetDisplayedHost(const Anope::string &shost)
{
if (shost.empty())
- throw "empty host? in MY services? it seems it's more likely than I thought.";
+ throw CoreException("empty host? in MY services? it seems it's more likely than I thought.");
- if (this->vhost)
- delete [] this->vhost;
- this->vhost = sstrdup(shost.c_str());
+ this->vhost = shost;
Alog(LOG_DEBUG) << this->nick << " changed vhost to " << shost;
@@ -99,9 +96,9 @@ void User::SetDisplayedHost(const std::string &shost)
/** Get the displayed vhost of a user record.
* @return The displayed vhost of the user, where ircd-supported, or the user's real host.
*/
-const std::string User::GetDisplayedHost() const
+const Anope::string User::GetDisplayedHost() const
{
- if (ircd->vhost && this->vhost)
+ if (ircd->vhost && !this->vhost.empty())
return this->vhost;
else if (this->HasMode(UMODE_CLOAK) && !this->GetCloakedHost().empty())
return this->GetCloakedHost();
@@ -112,7 +109,7 @@ const std::string User::GetDisplayedHost() const
/** Update the cloaked host of a user
* @param host The cloaked host
*/
-void User::SetCloakedHost(const std::string &newhost)
+void User::SetCloakedHost(const Anope::string &newhost)
{
if (newhost.empty())
throw "empty host in User::SetCloakedHost";
@@ -127,17 +124,17 @@ void User::SetCloakedHost(const std::string &newhost)
/** Get the cloaked host of a user
* @return The cloaked host
*/
-const std::string &User::GetCloakedHost() const
+const Anope::string &User::GetCloakedHost() const
{
return chost;
}
-const std::string &User::GetUID() const
+const Anope::string &User::GetUID() const
{
return this->uid;
}
-void User::SetVIdent(const std::string &sident)
+void User::SetVIdent(const Anope::string &sident)
{
this->vident = sident;
@@ -146,7 +143,7 @@ void User::SetVIdent(const std::string &sident)
this->UpdateHost();
}
-const std::string &User::GetVIdent() const
+const Anope::string &User::GetVIdent() const
{
if (this->HasMode(UMODE_CLOAK))
return this->vident;
@@ -156,7 +153,7 @@ const std::string &User::GetVIdent() const
return this->ident;
}
-void User::SetIdent(const std::string &sident)
+void User::SetIdent(const Anope::string &sident)
{
this->ident = sident;
@@ -165,34 +162,28 @@ void User::SetIdent(const std::string &sident)
this->UpdateHost();
}
-const std::string &User::GetIdent() const
+const Anope::string &User::GetIdent() const
{
return this->ident;
}
-const std::string User::GetMask()
+const Anope::string User::GetMask()
{
std::stringstream buf;
buf << this->nick << "!" << this->ident << "@" << this->host;
return buf.str();
}
-void User::SetRealname(const std::string &srealname)
+void User::SetRealname(const Anope::string &srealname)
{
if (srealname.empty())
- throw "realname empty in SetRealname";
+ throw CoreException("realname empty in SetRealname");
- if (this->realname)
- delete [] this->realname;
- this->realname = sstrdup(srealname.c_str());
+ this->realname = srealname;
NickAlias *na = findnick(this->nick);
if (na && (this->IsIdentified(true) || this->IsRecognized(true)))
- {
- if (na->last_realname)
- delete [] na->last_realname;
- na->last_realname = sstrdup(srealname.c_str());
- }
+ na->last_realname = srealname;
Alog(LOG_DEBUG) << this->nick << " changed realname to " << srealname;
}
@@ -205,11 +196,9 @@ User::~User()
if (Config.LogUsers)
{
- const char *srealname = normalizeBuffer(this->realname);
+ Anope::string srealname = normalizeBuffer(this->realname);
Alog() << "LOGUSERS: " << this->GetMask() << (ircd->vhost ? " => " : " ") << (ircd->vhost ? this->GetDisplayedHost() : "") << " (" << srealname << ") left the network (" << this->server->GetName() << ").";
-
- delete [] srealname;
}
FOREACH_MOD(I_OnUserLogoff, OnUserLogoff(this));
@@ -221,11 +210,11 @@ User::~User()
while (!this->chans.empty())
this->chans.front()->chan->DeleteUser(this);
-
+
if (Config.LimitSessions && !this->server->IsULined())
del_session(this->host);
- UserListByNick.erase(this->nick.c_str());
+ UserListByNick.erase(this->nick);
if (!this->uid.empty())
UserListByUID.erase(this->uid);
@@ -233,20 +222,10 @@ User::~User()
if (na)
na->OnCancel(this);
- delete [] this->host;
-
- if (this->vhost)
- delete [] this->vhost;
-
- if (this->realname)
- delete [] this->realname;
- if (this->hostip)
- delete [] this->hostip;
-
Alog(LOG_DEBUG_2) << "User::~User() done";
}
-void User::SendMessage(const std::string &source, const char *fmt, ...)
+void User::SendMessage(const Anope::string &source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -256,13 +235,13 @@ void User::SendMessage(const std::string &source, const char *fmt, ...)
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
- this->SendMessage(source, std::string(buf));
+ this->SendMessage(source, Anope::string(buf));
va_end(args);
}
}
-void User::SendMessage(const std::string &source, const std::string &msg)
+void User::SendMessage(const Anope::string &source, const Anope::string &msg)
{
/* Send privmsg instead of notice if:
* - UsePrivmsg is enabled
@@ -270,9 +249,9 @@ void User::SendMessage(const std::string &source, const std::string &msg)
* - The user is registered and has set /ns set msg on
*/
if (Config.UsePrivmsg && ((!this->nc && Config.NSDefFlags.HasFlag(NI_MSG)) || (this->nc && this->nc->HasFlag(NI_MSG))))
- ircdproto->SendPrivmsg(findbot(source), this->nick.c_str(), "%s", msg.c_str());
+ ircdproto->SendPrivmsg(findbot(source), this->nick, "%s", msg.c_str());
else
- ircdproto->SendNotice(findbot(source), this->nick.c_str(), "%s", msg.c_str());
+ ircdproto->SendNotice(findbot(source), this->nick, "%s", msg.c_str());
}
/** Collides a nick.
@@ -338,17 +317,15 @@ void User::Collide(NickAlias *na)
if (ircd->svsnick)
{
- std::string guestnick;
+ Anope::string guestnick;
do
{
- char randbuf[17];
- snprintf(randbuf, sizeof(randbuf), "%d", getrandom16());
- guestnick = std::string(Config.NSGuestNickPrefix) + std::string(randbuf);
+ guestnick = Config.NSGuestNickPrefix + stringify(getrandom16());
} while (finduser(guestnick));
notice_lang(Config.s_NickServ, this, FORCENICKCHANGE_CHANGING, guestnick.c_str());
- ircdproto->SendForceNickChange(this, guestnick.c_str(), time(NULL));
+ ircdproto->SendForceNickChange(this, guestnick, time(NULL));
}
else
kill_user(Config.s_NickServ, this->nick, "Services nickname-enforcer kill");
@@ -358,7 +335,7 @@ void User::Collide(NickAlias *na)
* their svid matches the one stored in their nickcore
* @param svid Services id
*/
-void User::CheckAuthenticationToken(const char *svid)
+void User::CheckAuthenticationToken(const Anope::string &svid)
{
NickAlias *na;
@@ -367,12 +344,9 @@ void User::CheckAuthenticationToken(const char *svid)
char *c;
if (na->nc && na->nc->GetExtArray("authenticationtoken", c))
{
- if (svid && c && !strcmp(svid, c))
- {
+ if (!svid.empty() && c && svid.equals_cs(c))
/* Users authentication token matches so they should become identified */
this->Login(na->nc);
- return;
- }
}
}
@@ -382,9 +356,9 @@ void User::CheckAuthenticationToken(const char *svid)
/** Auto identify the user to the given accountname.
* @param account Display nick of account
*/
-void User::AutoID(const std::string &account)
+void User::AutoID(const Anope::string &account)
{
- NickCore *core = findcore(account.c_str());
+ NickCore *core = findcore(account);
if (core)
{
@@ -393,9 +367,7 @@ void User::AutoID(const std::string &account)
NickAlias *na = findnick(this->nick);
if (na && na->nc == core)
{
- if (na->last_realname)
- delete [] na->last_realname;
- na->last_realname = sstrdup(this->realname);
+ na->last_realname = this->realname;
na->last_seen = time(NULL);
this->SetMode(NickServ, UMODE_REGISTERED);
this->UpdateHost();
@@ -433,7 +405,7 @@ void User::Logout()
/** Get the account the user is logged in using
* @reurn The account or NULL
*/
-NickCore *User::Account() const
+NickCore *User::Account()
{
return nc;
}
@@ -442,7 +414,7 @@ NickCore *User::Account() const
* @param CheckNick True to check if the user is identified to the nickname they are on too
* @return true or false
*/
-const bool User::IsIdentified(bool CheckNick) const
+bool User::IsIdentified(bool CheckNick) const
{
if (CheckNick && this->nc)
{
@@ -461,7 +433,7 @@ const bool User::IsIdentified(bool CheckNick) const
* @param CheckSecure Only returns true if the user has secure off
* @return true or false
*/
-const bool User::IsRecognized(bool CheckSecure) const
+bool User::IsRecognized(bool CheckSecure) const
{
if (CheckSecure && OnAccess)
{
@@ -478,7 +450,7 @@ const bool User::IsRecognized(bool CheckSecure) const
*/
void User::UpdateHost()
{
- if (!this->host)
+ if (this->host.empty())
return;
NickAlias *na = findnick(this->nick);
@@ -488,11 +460,8 @@ void User::UpdateHost()
if (na && (this->IsIdentified(true) || this->IsRecognized(true)))
{
- if (na->last_usermask)
- delete [] na->last_usermask;
-
- std::string last_usermask = this->GetIdent() + "@" + this->GetDisplayedHost();
- na->last_usermask = sstrdup(last_usermask.c_str());
+ Anope::string last_usermask = this->GetIdent() + "@" + this->GetDisplayedHost();
+ na->last_usermask = last_usermask;
}
}
@@ -500,7 +469,7 @@ void User::UpdateHost()
* @param Name Mode name
* @return true or false
*/
-const bool User::HasMode(UserModeName Name) const
+bool User::HasMode(UserModeName Name) const
{
return modes.HasFlag(Name);
}
@@ -509,7 +478,7 @@ const bool User::HasMode(UserModeName Name) const
* @param um The user mode
* @param Param The param, if there is one
*/
-void User::SetModeInternal(UserMode *um, const std::string &Param)
+void User::SetModeInternal(UserMode *um, const Anope::string &Param)
{
if (!um)
return;
@@ -530,7 +499,7 @@ void User::RemoveModeInternal(UserMode *um)
return;
modes.UnsetFlag(um->Name);
- std::map<UserModeName, std::string>::iterator it = Params.find(um->Name);
+ std::map<UserModeName, Anope::string>::iterator it = Params.find(um->Name);
if (it != Params.end())
Params.erase(it);
@@ -542,7 +511,7 @@ void User::RemoveModeInternal(UserMode *um)
* @param um The user mode
* @param Param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserMode *um, const std::string &Param)
+void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param)
{
if (!um || HasMode(um->Name))
return;
@@ -556,7 +525,7 @@ void User::SetMode(BotInfo *bi, UserMode *um, const std::string &Param)
* @param Name The mode name
* @param param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserModeName Name, const std::string &Param)
+void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param)
{
SetMode(bi, ModeManager::FindUserModeByName(Name), Param);
}
@@ -566,7 +535,7 @@ void User::SetMode(BotInfo *bi, UserModeName Name, const std::string &Param)
* @param ModeChar The mode char
* @param param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, char ModeChar, const std::string &Param)
+void User::SetMode(BotInfo *bi, char ModeChar, const Anope::string &Param)
{
SetMode(bi, ModeManager::FindUserModeByChar(ModeChar), Param);
}
@@ -610,7 +579,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
- std::string modebuf, sbuf;
+ Anope::string modebuf, sbuf;
int add = -1;
va_start(args, umodes);
vsnprintf(buf, BUFSIZE - 1, umodes, args);
@@ -618,7 +587,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
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)
{
UserMode *um;
@@ -687,15 +656,15 @@ void get_user_stats(long *nusers, long *memuse)
count++;
mem += sizeof(*user);
- if (user->host)
- mem += strlen(user->host) + 1;
+ if (!user->host.empty())
+ mem += user->host.length() + 1;
if (ircd->vhost)
{
- if (user->vhost)
- mem += strlen(user->vhost) + 1;
+ if (!user->vhost.empty())
+ mem += user->vhost.length() + 1;
}
- if (user->realname)
- mem += strlen(user->realname) + 1;
+ if (!user->realname.empty())
+ mem += user->realname.length() + 1;
mem += user->server->GetName().length() + 1;
mem += (sizeof(ChannelContainer) * user->chans.size());
}
@@ -703,21 +672,11 @@ void get_user_stats(long *nusers, long *memuse)
*memuse = mem;
}
-User *finduser(const char *nick)
-{
- return finduser(ci::string(nick));
-}
-
-User *finduser(const std::string &nick)
-{
- return finduser(ci::string(nick.c_str()));
-}
-
-User *finduser(const ci::string &nick)
+User *finduser(const Anope::string &nick)
{
if (isdigit(nick[0]) && ircd->ts6)
{
- user_uid_map::const_iterator it = UserListByUID.find(nick.c_str());
+ user_uid_map::const_iterator it = UserListByUID.find(nick);
if (it != UserListByUID.end())
return it->second;
@@ -735,22 +694,23 @@ User *finduser(const ci::string &nick)
/* Handle a server NICK command. */
-User *do_nick(const char *source, const char *nick, const char *username, const char *host, const char *server, const char *realname, time_t ts, uint32 ip, const char *vhost, const char *uid)
+User *do_nick(const Anope::string &source, const Anope::string &nick, const Anope::string &username, const Anope::string &host, const Anope::string &server, const Anope::string &realname, time_t ts, uint32 ip, const Anope::string &vhost, const Anope::string &uid)
{
User *user = NULL;
+ Anope::string vhost2 = vhost;
- if (!*source)
+ if (source.empty())
{
char ipbuf[16];
struct in_addr addr;
if (ircd->nickvhost)
{
- if (vhost)
+ if (!vhost2.empty())
{
- if (!strcmp(vhost, "*"))
+ if (vhost2.equals_cs("*"))
{
- vhost = NULL;
+ vhost2.clear();
Alog(LOG_DEBUG) << "new user with no vhost in NICK command: " << nick;
}
}
@@ -772,42 +732,39 @@ User *do_nick(const char *source, const char *nick, const char *username, const
/**
* Ugly swap routine for Flop's bug :) XXX
**/
- if (realname)
+ Anope::string logrealname = realname;
+ if (!logrealname.empty())
{
- char *tmp = const_cast<char *>(strchr(realname, '%'));
- while (tmp)
- {
- *tmp = '-';
- tmp = const_cast<char *>(strchr(realname, '%'));
- }
+ size_t tmp;
+ while ((tmp = logrealname.find('%')) != Anope::string::npos)
+ logrealname[tmp] = '-';
}
- const char *logrealname = normalizeBuffer(realname);
+ logrealname = normalizeBuffer(logrealname);
/**
* End of ugly swap
**/
- Alog() << "LOGUSERS: " << nick << " (" << username << "@" << host << (ircd->nickvhost && vhost ? " => " : "") << (ircd->nickvhost && vhost ? vhost : "") << ") (" << logrealname << ") "
+ Alog() << "LOGUSERS: " << nick << " (" << username << "@" << host << (ircd->nickvhost && !vhost2.empty() ? " => " : "") << (ircd->nickvhost && !vhost2.empty() ? vhost2 : "") << ") (" << logrealname << ") "
<< (ircd->nickip ? "[" : "") << (ircd->nickip ? ipbuf : "") << (ircd->nickip ? "]" : "") << " connected to the network (" << serv->GetName() << ").";
- delete [] logrealname;
}
/* Allocate User structure and fill it in. */
- user = new User(nick, uid ? uid : "");
+ user = new User(nick, !uid.empty() ? uid : "");
user->SetIdent(username);
- user->host = sstrdup(host);
+ user->host = host;
user->server = serv;
- user->realname = sstrdup(realname);
+ user->realname = realname;
user->timestamp = ts;
user->my_signon = time(NULL);
- if (vhost)
- user->SetCloakedHost(vhost);
+ if (!vhost2.empty())
+ user->SetCloakedHost(vhost2);
user->SetVIdent(username);
/* We now store the user's ip in the user_ struct,
* because we will use it in serveral places -- DrStein */
if (ircd->nickip)
- user->hostip = sstrdup(ipbuf);
+ user->hostip = ipbuf;
else
- user->hostip = NULL;
+ user->hostip = "";
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnPreUserConnect, OnPreUserConnect(user));
@@ -840,16 +797,14 @@ User *do_nick(const char *source, const char *nick, const char *username, const
if (Config.LogUsers)
{
- const char *logrealname = normalizeBuffer(user->realname);
- Alog() << "LOGUSERS: " << user->nick << " (" << user->GetIdent() << "@" << user->host << (ircd->vhost ? " => " : "") << (ircd->vhost ? user->GetDisplayedHost() : "") << ") ("
- << logrealname << ") " << "changed nick to " << nick << " (" << user->server->GetName() << ").";
- if (logrealname)
- delete [] logrealname;
+ Anope::string logrealname = normalizeBuffer(user->realname);
+ Alog() << "LOGUSERS: " << user->nick << " (" << user->GetIdent() << "@" << user->host << (ircd->vhost ? " => " : "") << (ircd->vhost ? user->GetDisplayedHost() : "") << ") (" << logrealname << ") changed nick to "
+ << nick << " (" << user->server->GetName() << ").";
}
user->timestamp = ts;
- if (!stricmp(nick, user->nick.c_str()))
+ if (user->nick.equals_ci(nick))
/* No need to redo things */
user->SetNewNick(nick);
else
@@ -861,7 +816,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const
if (old_na && (old_na->nc == user->Account() || user->IsRecognized()))
old_na->last_seen = time(NULL);
- std::string oldnick = user->nick;
+ Anope::string oldnick = user->nick;
user->SetNewNick(nick);
FOREACH_MOD(I_OnUserNickChange, OnUserNickChange(user, oldnick));
@@ -903,7 +858,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const
* av[1] = modes
*/
-void do_umode(const char *source, int ac, const char **av)
+void do_umode(const Anope::string &source, int ac, const char **av)
{
User *user;
@@ -923,7 +878,7 @@ void do_umode(const char *source, int ac, const char **av)
* av[0] = reason
*/
-void do_quit(const char *source, int ac, const char **av)
+void do_quit(const Anope::string &source, int ac, const char **av)
{
User *user;
NickAlias *na;
@@ -938,9 +893,7 @@ void do_quit(const char *source, int ac, const char **av)
if ((na = findnick(user->nick)) && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true)))
{
na->last_seen = time(NULL);
- if (na->last_quit)
- delete [] na->last_quit;
- na->last_quit = *av[0] ? sstrdup(av[0]) : NULL;
+ na->last_quit = *av[0] ? av[0] : "";
}
FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, *av[0] ? av[0] : ""));
delete user;
@@ -953,7 +906,7 @@ void do_quit(const char *source, int ac, const char **av)
* av[1] = reason
*/
-void do_kill(const std::string &nick, const std::string &msg)
+void do_kill(const Anope::string &nick, const Anope::string &msg)
{
User *user;
NickAlias *na;
@@ -968,9 +921,7 @@ void do_kill(const std::string &nick, const std::string &msg)
if ((na = findnick(user->nick)) && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true)))
{
na->last_seen = time(NULL);
- if (na->last_quit)
- delete [] na->last_quit;
- na->last_quit = !msg.empty() ? sstrdup(msg.c_str()) : NULL;
+ na->last_quit = msg;
}
delete user;
}
@@ -980,7 +931,7 @@ void do_kill(const std::string &nick, const std::string &msg)
/* Is the given nick an oper? */
-int is_oper(User * user)
+int is_oper(User *user)
{
if (user && user->HasMode(UMODE_OPER))
return 1;
@@ -992,7 +943,7 @@ int is_oper(User * user)
/*************************************************************************/
/* Is the given user ban-excepted? */
-int is_excepted(ChannelInfo * ci, User * user)
+int is_excepted(ChannelInfo *ci, User *user)
{
if (!ci->c || !ModeManager::FindChannelModeByName(CMODE_EXCEPT))
return 0;
@@ -1006,7 +957,7 @@ int is_excepted(ChannelInfo * ci, User * user)
/*************************************************************************/
/* Is the given MASK ban-excepted? */
-int is_excepted_mask(ChannelInfo * ci, const char *mask)
+int is_excepted_mask(ChannelInfo *ci, const Anope::string &mask)
{
if (!ci->c || !ModeManager::FindChannelModeByName(CMODE_EXCEPT))
return 0;
@@ -1023,40 +974,34 @@ int is_excepted_mask(ChannelInfo * ci, const char *mask)
* just user@host)?
*/
-int match_usermask(const char *mask, User * user)
+int match_usermask(const Anope::string &mask, User *user)
{
- char *mask2;
- char *nick, *username, *host;
int result;
- if (!mask || !*mask)
+ if (mask.empty())
return 0;
- mask2 = sstrdup(mask);
-
- if (strchr(mask2, '!'))
+ Anope::string mask2 = mask, nick, username, host;
+ size_t ex = mask2.find('!');
+ if (ex != Anope::string::npos)
{
- nick = strtok(mask2, "!");
- username = strtok(NULL, "@");
+ nick = mask2.substr(0, ex);
+ mask2 = mask2.substr(ex + 1);
}
- else
+ size_t at = mask2.find('@');
+ if (at != Anope::string::npos)
{
- nick = NULL;
- username = strtok(mask2, "@");
+ username = mask2.substr(0, at);
+ host = mask2.substr(at + 1);
}
- host = strtok(NULL, "");
- if (!username || !host)
- {
- delete [] mask2;
+ if (username.empty() || host.empty())
return 0;
- }
- if (nick)
- result = Anope::Match(user->nick, nick, false) && Anope::Match(user->GetIdent().c_str(), username, false) && (Anope::Match(user->host, host, false) || Anope::Match(user->GetDisplayedHost().c_str(), host, false));
+ if (!nick.empty())
+ result = Anope::Match(user->nick, nick) && Anope::Match(user->GetIdent(), username) && (Anope::Match(user->host, host) || Anope::Match(user->GetDisplayedHost(), host));
else
- result = Anope::Match(user->GetIdent().c_str(), username, false) && (Anope::Match(user->host, host, false) || Anope::Match(user->GetDisplayedHost().c_str(), host, false));
+ result = Anope::Match(user->GetIdent(), username) && (Anope::Match(user->host, host) || Anope::Match(user->GetDisplayedHost(), host));
- delete [] mask2;
return result;
}
@@ -1067,49 +1012,37 @@ int match_usermask(const char *mask, User * user)
* appropriate subnet mask (e.g. 35.1.1.1 -> 35.*; 128.2.1.1 -> 128.2.*);
* for named addresses, wildcards the leftmost part of the name unless the
* name only contains two parts. If the username begins with a ~, delete
- * it. The returned character string is malloc'd and should be free'd
- * when done with.
+ * it.
*/
-char *create_mask(User *u)
+Anope::string create_mask(User *u)
{
- char *mask, *s, *end;
- std::string mident = u->GetIdent();
- std::string mhost = u->GetDisplayedHost();
- int ulen = mident.length();
+ Anope::string mask;
+ Anope::string mident = u->GetIdent();
+ Anope::string mhost = u->GetDisplayedHost();
/* Get us a buffer the size of the username plus hostname. The result
* will never be longer than this (and will often be shorter), thus we
* can use strcpy() and sprintf() safely.
*/
- end = mask = new char[ulen + mhost.length() + 3];
if (mident[0] == '~')
- end += sprintf(end, "*%s@", mident.c_str());
+ mask = "*" + mident + "@";
else
- end += sprintf(end, "%s@", mident.c_str());
+ mask = mident + "@";
- // XXX: someone needs to rewrite this godawful kitten murdering pile of crap.
- if (strspn(mhost.c_str(), "0123456789.") == mhost.length()
- && (s = strchr(const_cast<char *>(mhost.c_str()), '.')) // XXX - Potentially unsafe cast
- && (s = strchr(s + 1, '.')) && (s = strchr(s + 1, '.')) && (!strchr(s + 1, '.')))
+ size_t dot;
+ /* To make sure this is an IP, make sure the host contains only numbers and dots, and check to make sure it only contains 3 dots */
+ if (mhost.find_first_not_of("0123456789.") == Anope::string::npos && (dot = mhost.find('.')) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && (dot = mhost.find('.', dot + 1)) != Anope::string::npos && mhost.find('.', dot + 1) == Anope::string::npos)
{ /* IP addr */
- s = sstrdup(mhost.c_str());
- *strrchr(s, '.') = 0;
-
- sprintf(end, "%s.*", s);
- delete [] s;
+ dot = mhost.find('.');
+ mask += mhost.substr(0, dot) + ".*";
}
else
{
- if ((s = strchr(const_cast<char *>(mhost.c_str()), '.')) && strchr(s + 1, '.'))
- {
- s = sstrdup(strchr(mhost.c_str(), '.') - 1);
- *s = '*';
- strcpy(end, s);
- delete [] s;
- }
+ if ((dot = mhost.find('.')) != Anope::string::npos && mhost.find('.', dot + 1) != Anope::string::npos)
+ mask += "*" + mhost.substr(dot);
else
- strcpy(end, mhost.c_str());
+ mask += mhost;
}
return mask;
}
@@ -1183,11 +1116,8 @@ void UserSetInternalModes(User *user, int ac, const char **av)
break;
case UMODE_CLOAK:
case UMODE_VHOST:
- if (!add && user->vhost)
- {
- delete [] user->vhost;
- user->vhost = NULL;
- }
+ if (!add && !user->vhost.empty())
+ user->vhost.clear();
user->UpdateHost();
default:
break;
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index 42f0812f7..1716068d1 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -2,9 +2,9 @@
static bool match_internal(const unsigned char *str, const unsigned char *mask, bool case_sensitive)
{
- unsigned char *cp = NULL, *mp = NULL;
- unsigned char *string = const_cast<unsigned char *>(str); // XXX: unsafe cast
- unsigned char *wild = const_cast<unsigned char *>(mask); // XXX: unsafe cast
+ const unsigned char *cp = NULL, *mp = NULL;
+ const unsigned char *string = str;
+ const unsigned char *wild = mask;
while (*string && *wild != '*')
{
@@ -19,8 +19,8 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
return false;
}
- wild++;
- string++;
+ ++wild;
+ ++string;
}
while (*string)
@@ -71,7 +71,7 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
return !*wild;
}
-bool Anope::Match(const std::string &str, const std::string &mask, bool case_sensitive)
+bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case_sensitive)
{
return match_internal(reinterpret_cast<const unsigned char *>(str.c_str()), reinterpret_cast<const unsigned char *>(mask.c_str()), case_sensitive);
}
diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp
index 6568e860e..9ea3dad09 100644
--- a/src/win32/windows.cpp
+++ b/src/win32/windows.cpp
@@ -47,7 +47,7 @@ int inet_pton(int af, const char *src, void *dst)
return -1;
}
- if (!WSAStringToAddress((LPSTR) src, af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length))
+ if (!WSAStringToAddress(static_cast<LPSTR>(const_cast<char *>(src)), af, NULL, reinterpret_cast<LPSOCKADDR>(&sa), &address_length))
{
switch (af)
{