diff options
| author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-04 06:40:24 +0000 |
|---|---|---|
| committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-04 06:40:24 +0000 |
| commit | b462814760cb7c0830072275acc97291a9fb905b (patch) | |
| tree | 56cfe6caee408eb852f728cd8aaa2d18e4365228 | |
| parent | 2708eea5d13c249143b83fbaa8b552992f0ac8b6 (diff) | |
Changed 'char *' fields in BotInfo to 'std::string', cleanup of bots.cpp, changed many other functions to use 'const std::string &' arguments as a chain reaction.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2733 5417fbe8-f217-4b02-8779-1006273d7864
| -rw-r--r-- | include/bots.h | 16 | ||||
| -rw-r--r-- | include/commands.h | 4 | ||||
| -rw-r--r-- | include/extern.h | 16 | ||||
| -rw-r--r-- | include/modules.h | 4 | ||||
| -rw-r--r-- | include/services.h | 8 | ||||
| -rw-r--r-- | include/users.h | 9 | ||||
| -rw-r--r-- | src/actions.c | 2 | ||||
| -rw-r--r-- | src/bots.cpp | 97 | ||||
| -rw-r--r-- | src/botserv.c | 23 | ||||
| -rw-r--r-- | src/channels.c | 28 | ||||
| -rw-r--r-- | src/chanserv.c | 22 | ||||
| -rw-r--r-- | src/commands.c | 14 | ||||
| -rw-r--r-- | src/core/bs_assign.c | 6 | ||||
| -rw-r--r-- | src/core/bs_bot.c | 42 | ||||
| -rw-r--r-- | src/core/bs_botlist.c | 4 | ||||
| -rw-r--r-- | src/core/bs_info.c | 8 | ||||
| -rw-r--r-- | src/core/bs_set.c | 4 | ||||
| -rw-r--r-- | src/core/cs_akick.c | 16 | ||||
| -rw-r--r-- | src/core/db_plain.cpp | 4 | ||||
| -rw-r--r-- | src/core/os_defcon.c | 8 | ||||
| -rw-r--r-- | src/core/ss_main.c | 2 | ||||
| -rw-r--r-- | src/init.c | 9 | ||||
| -rw-r--r-- | src/messages.c | 46 | ||||
| -rw-r--r-- | src/misc.c | 7 | ||||
| -rw-r--r-- | src/nickserv.c | 2 | ||||
| -rw-r--r-- | src/protocol/bahamut.c | 10 | ||||
| -rw-r--r-- | src/protocol/inspircd11.c | 11 | ||||
| -rw-r--r-- | src/protocol/inspircd12.cpp | 10 | ||||
| -rw-r--r-- | src/protocol/ratbox.c | 10 | ||||
| -rw-r--r-- | src/protocol/unreal32.c | 14 | ||||
| -rw-r--r-- | src/send.c | 2 | ||||
| -rw-r--r-- | src/servers.c | 2 | ||||
| -rw-r--r-- | src/users.c | 4 |
33 files changed, 201 insertions, 263 deletions
diff --git a/include/bots.h b/include/bots.h index 80ac08c1f..4645ea3b0 100644 --- a/include/bots.h +++ b/include/bots.h @@ -41,10 +41,10 @@ class CoreExport BotInfo : public Extensible, public Flags<BotFlag> BotInfo *next, *prev; std::string uid; /* required for UID supporting servers, as opposed to the shitty struct Uid. */ - char *nick; /* Nickname of the bot */ - char *user; /* Its user name */ - char *host; /* Its hostname */ - char *real; /* Its real name */ + std::string nick; /* Nickname of the bot */ + std::string user; /* Its user name */ + std::string host; /* Its hostname */ + std::string real; /* Its real name */ time_t created; /* Birth date ;) */ int16 chancount; /* Number of channels that use the bot. */ /* Dynamic data */ @@ -52,17 +52,12 @@ class CoreExport BotInfo : public Extensible, public Flags<BotFlag> CommandHash **cmdTable; /** Create a new bot. - * XXX: Note - this constructor is considered obsolete. Use the four parameter form. - * @param nick The nickname to assign to the bot. - */ - BotInfo(const char *nick); - /** Create a new bot. * @param nick The nickname to assign to the bot. * @param user The ident to give the bot. * @param host The hostname to give the bot. * @param real The realname to give the bot. */ - BotInfo(const char *nick, const char *user, const char *host, const char *real); + BotInfo(const std::string &nick, const std::string &user = "", const std::string &host = "", const std::string &real = ""); /** Destroy a bot, clearing up appropriately. */ @@ -90,4 +85,3 @@ class CoreExport BotInfo : public Extensible, public Flags<BotFlag> */ void UnAssign(User *u, ChannelInfo *ci); }; - diff --git a/include/commands.h b/include/commands.h index 408374cd2..5e40ad899 100644 --- a/include/commands.h +++ b/include/commands.h @@ -21,8 +21,8 @@ */ extern MDE Command *lookup_cmd(Command *list, char *name); -extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); -extern MDE void mod_run_cmd(char *service, User *u, CommandHash *cmdTable[],const char *cmd); +extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[], const char *cmd); +extern MDE void mod_run_cmd(const std::string &service, User *u, CommandHash *cmdTable[], const char *cmd); //extern MDE void do_help_limited(char *service, User * u, Command * c); /*************************************************************************/ diff --git a/include/extern.h b/include/extern.h index 473279de2..2a5a95bd4 100644 --- a/include/extern.h +++ b/include/extern.h @@ -95,7 +95,7 @@ E const char *get_xop_level(int level); E void do_cmode(const char *source, int ac, const char **av); E void do_join(const char *source, int ac, const char **av); -E void do_kick(const char *source, int ac, const char **av); +E void do_kick(const std::string &source, int ac, const char **av); E void do_part(const char *source, int ac, const char **av); E void do_sjoin(const char *source, int ac, const char **av); E void do_topic(const char *source, int ac, const char **av); @@ -108,7 +108,7 @@ E Entry *entry_create(char *mask); E Entry *entry_add(EList *list, const char *mask); E void entry_delete(EList *list, Entry *e); E EList *list_create(); -E int entry_match(Entry *e, const char *nick, const char *user, const char *host, uint32 ip); +E int entry_match(Entry *e, const std::string &nick, const std::string &user, const std::string &host, uint32 ip); E int entry_match_mask(Entry *e, const char *mask, uint32 ip); E Entry *elist_match(EList *list, const char *nick, const char *user, const char *host, uint32 ip); E Entry *elist_match_mask(EList *list, const char *mask, uint32 ip); @@ -146,7 +146,7 @@ E void record_topic(const char *chan); E void restore_topic(const char *chan); E int check_topiclock(Channel * c, time_t topic_time); -E ChannelInfo *cs_findchan(const char *chan); +E ChannelInfo *cs_findchan(const std::string &chan); E int check_access(User * user, ChannelInfo * ci, int what); E bool IsFounder(User *user, ChannelInfo *ci); E bool IsRealFounder(User *user, ChannelInfo *ci); @@ -199,7 +199,7 @@ E void hostserv_init(); /**** init.c ****/ -E void introduce_user(const char *user); +E void introduce_user(const std::string &user); E int init_primary(int ac, char **av); E int init_secondary(int ac, char **av); E Uplink *uplink_server; @@ -299,9 +299,9 @@ E int delmemo(MemoInfo * mi, int num); E int m_nickcoll(const char *user); E int m_away(const char *source, const char *msg); -E int m_kill(const char *nick, const char *msg); +E int m_kill(const std::string &nick, const char *msg); E int m_motd(const char *source); -E int m_privmsg(const char *source, const char *receiver, const char *msg); +E int m_privmsg(const char *source, const std::string &receiver, const char *msg); E int m_stats(const char *source, int ac, const char **av); E int m_whois(const char *source, const char *who); E int m_time(const char *source, int ac, const char **av); @@ -345,7 +345,7 @@ E char *myStrGetTokenRemainder(const char *str, const char dilim, E char *stripModePrefix(const char *str); E int myNumToken(const char *str, const char dilim); E void doCleanBuffer(char *str); -E void EnforceQlinedNick(const char *nick, const char *killer); +E void EnforceQlinedNick(const std::string &nick, const char *killer); E int nickIsServices(const char *nick, int bot); E void add_entropy_userkeys(); @@ -485,7 +485,7 @@ E void notice_server(char *source, Server * s, const char *fmt, ...) FORMAT(printf,3,4); E void notice_list(const char *source, const char *dest, char **text); // MARK_DEPRECATED; -E void notice_lang(const char *source, User *dest, int message, ...); // MARK_DEPRECATED; +E void notice_lang(const std::string &source, User *dest, int message, ...); // MARK_DEPRECATED; E void notice_help(const char *source, User *dest, int message, ...); // MARK_DEPRECATED; diff --git a/include/modules.h b/include/modules.h index bfd8b3928..c25016bdd 100644 --- a/include/modules.h +++ b/include/modules.h @@ -537,7 +537,7 @@ class CoreExport Module * @param c The command class (if it exists) * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommandRun(const char *service, User *u, const char *cmd, Command *c) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommandRun(const std::string &service, User *u, const char *cmd, Command *c) { return EVENT_CONTINUE; } /** Called before a command is due to be executed. * @param u The user executing the command @@ -1101,7 +1101,7 @@ enum Implementation I_OnPostLoadDatabases, I_OnSaveDatabase, I_OnLoadDatabase, I_OnBackupDatabase, I_OnDatabaseExpire, I_OnDatabaseWrite, I_OnDatabaseRead, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata, - + /* Modules */ I_OnModuleLoad, I_OnModuleUnload, diff --git a/include/services.h b/include/services.h index 0465fa631..d92f84f63 100644 --- a/include/services.h +++ b/include/services.h @@ -523,11 +523,11 @@ class HostInfo * @param time When the vhost was craated */ void SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t time = time(NULL)); - + /** Remove a users vhost **/ void RemoveVhost(); - + /** Check if the user has a vhost * @return true or false */ @@ -1267,7 +1267,7 @@ class CoreExport IRCDProto virtual void SendSVSMode(User *, int, const char **) = 0; virtual void SendMode(BotInfo *bi, Channel *dest, const char *fmt, ...); virtual void SendMode(BotInfo *bi, User *u, const char *fmt, ...); - virtual void SendClientIntroduction(const char *, const char *, const char *, const char *, const char *, const char *uid) = 0; + virtual void SendClientIntroduction(const std::string &, const std::string &, const std::string &, const std::string &, const char *, const std::string &uid) = 0; virtual void SendKick(BotInfo *bi, Channel *chan, User *user, const char *fmt, ...); virtual void SendNoticeChanops(BotInfo *bi, Channel *dest, const char *fmt, ...); virtual void SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...); @@ -1286,7 +1286,7 @@ class CoreExport IRCDProto virtual void SendQuit(BotInfo *bi, const char *fmt, ...); virtual void SendPong(const char *servname, const char *who); virtual void SendJoin(BotInfo *bi, const char *, time_t) = 0; - virtual void SendSQLineDel(const char *) = 0; + virtual void SendSQLineDel(const std::string &) = 0; virtual void SendInvite(BotInfo *bi, const char *chan, const char *nick); virtual void SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...); virtual void SendGlobops(BotInfo *source, const char *fmt, ...); diff --git a/include/users.h b/include/users.h index 0d702bb19..0458c0455 100644 --- a/include/users.h +++ b/include/users.h @@ -67,7 +67,7 @@ class CoreExport User : public Extensible /** Destroy a user. */ ~User(); - + /** Update the nickname of a user record accordingly, should be * called from ircd protocol. */ @@ -131,10 +131,9 @@ class CoreExport User : public Extensible * @param source Sender nick * @param fmt Format of the Message * @param ... any number of parameters - * @return void */ - void SendMessage(const char *source, const char *fmt, ...); - void SendMessage(const char *source, const std::string &msg); + void SendMessage(const std::string &source, const char *fmt, ...); + void SendMessage(const std::string &source, const std::string &msg); /** Check if the user should become identified because * their svid matches the one stored in their nickcore @@ -155,7 +154,7 @@ class CoreExport User : public Extensible /** Update the last usermask stored for a user, and check to see if they are recognized */ void UpdateHost(); - + /** Check if the user has a mode * @param Name Mode name * @return true or false diff --git a/src/actions.c b/src/actions.c index 0e15f2cf4..1d2b7d2e4 100644 --- a/src/actions.c +++ b/src/actions.c @@ -158,7 +158,7 @@ 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().c_str(), u->GetDisplayedHost().c_str(), ip)) ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask); } } diff --git a/src/bots.cpp b/src/bots.cpp index ddd517b77..bb8b8a06f 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -12,75 +12,42 @@ #include "services.h" #include "modules.h" -BotInfo::BotInfo(const char *nnick) +BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal) { - this->nick = sstrdup(nnick); + this->nick = nnick; + this->user = nuser; + this->host = nhost; + this->real = nreal; this->lastmsg = this->created = time(NULL); this->uid = ts6_uid_retrieve(); // XXX is this safe? has ts6 been setup yet? - nbots++; + ++nbots; this->cmdTable = NULL; this->chancount = 0; - if (Config.s_ChanServ && !stricmp(Config.s_ChanServ, nnick)) + ci::string ci_nick(nnick.c_str()); + if (Config.s_ChanServ && ci_nick == Config.s_ChanServ) this->SetFlag(BI_CHANSERV); - else if (Config.s_BotServ && !stricmp(Config.s_BotServ, nnick)) + else if (Config.s_BotServ && ci_nick == Config.s_BotServ) this->SetFlag(BI_BOTSERV); - else if (Config.s_HostServ && !stricmp(Config.s_HostServ, nnick)) + else if (Config.s_HostServ && ci_nick == Config.s_HostServ) this->SetFlag(BI_HOSTSERV); - else if (Config.s_OperServ && !stricmp(Config.s_OperServ, nnick)) + else if (Config.s_OperServ && ci_nick == Config.s_OperServ) this->SetFlag(BI_OPERSERV); - else if (Config.s_MemoServ && !stricmp(Config.s_MemoServ, nnick)) + else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ) this->SetFlag(BI_MEMOSERV); - else if (Config.s_NickServ && !stricmp(Config.s_NickServ, nnick)) + else if (Config.s_NickServ && ci_nick == Config.s_NickServ) this->SetFlag(BI_NICKSERV); - else if (Config.s_GlobalNoticer && !stricmp(Config.s_GlobalNoticer, nnick)) + else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer) this->SetFlag(BI_GLOBAL); - - FOREACH_MOD(I_OnBotPreLoad, OnBotPreLoad(this)); - - insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL. - - // If we're synchronised with the uplink already, call introduce_user() for this bot. - alog("serv_uplink is %p and status is %d", static_cast<void *>(serv_uplink), serv_uplink ? serv_uplink->sync == SSYNC_DONE : 0); - if (serv_uplink && serv_uplink->sync == SSYNC_DONE) - ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid.c_str()); -} -BotInfo::BotInfo(const char *nnick, const char *nuser, const char *nhost, const char *nreal) -{ - this->nick = sstrdup(nnick); - this->user = sstrdup(nuser); - this->host = sstrdup(nhost); - this->real = sstrdup(nreal); - this->lastmsg = this->created = time(NULL); - this->uid = ts6_uid_retrieve(); // XXX is this safe? has ts6 been setup yet? - nbots++; - this->cmdTable = NULL; - this->chancount = 0; - - if (Config.s_ChanServ && !stricmp(Config.s_ChanServ, nnick)) - this->SetFlag(BI_CHANSERV); - else if (Config.s_BotServ && !stricmp(Config.s_BotServ, nnick)) - this->SetFlag(BI_BOTSERV); - else if (Config.s_HostServ && !stricmp(Config.s_HostServ, nnick)) - this->SetFlag(BI_HOSTSERV); - else if (Config.s_OperServ && !stricmp(Config.s_OperServ, nnick)) - this->SetFlag(BI_OPERSERV); - else if (Config.s_MemoServ && !stricmp(Config.s_MemoServ, nnick)) - this->SetFlag(BI_MEMOSERV); - else if (Config.s_NickServ && !stricmp(Config.s_NickServ, nnick)) - this->SetFlag(BI_NICKSERV); - else if (Config.s_GlobalNoticer && !stricmp(Config.s_GlobalNoticer, nnick)) - this->SetFlag(BI_GLOBAL); - FOREACH_MOD(I_OnBotPreLoad, OnBotPreLoad(this)); - + insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL. // If we're synchronised with the uplink already, call introduce_user() for this bot. alog("serv_uplink is %p and status is %d", static_cast<void *>(serv_uplink), serv_uplink ? serv_uplink->sync == SSYNC_DONE : 0); if (serv_uplink && serv_uplink->sync == SSYNC_DONE) - ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid.c_str()); + ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid); } BotInfo::~BotInfo() @@ -88,7 +55,7 @@ BotInfo::~BotInfo() int i; ChannelInfo *ci; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; ++i) for (ci = chanlists[i]; ci; ci = ci->next) if (ci->bi == this) ci->bi = NULL; @@ -98,14 +65,9 @@ BotInfo::~BotInfo() if (this->prev) this->prev->next = this->next; else - botlists[tolower(*this->nick)] = this->next; + botlists[tolower(this->nick[0])] = this->next; - nbots--; - - delete [] this->nick; - delete [] this->user; - delete [] this->host; - delete [] this->real; + --nbots; } @@ -116,11 +78,9 @@ void BotInfo::ChangeNick(const char *newnick) if (this->prev) this->prev->next = this->next; else - botlists[tolower(*this->nick)] = this->next; + botlists[tolower(this->nick[0])] = this->next; - if (this->nick) - delete [] this->nick; - this->nick = sstrdup(newnick); + this->nick = newnick; insert_bot(this); } @@ -130,7 +90,7 @@ void BotInfo::RejoinAll() int i; ChannelInfo *ci; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; ++i) for (ci = chanlists[i]; ci; ci = ci->next) if (ci->bi == this && ci->c && (ci->c->usercount >= Config.BSMinUsers)) bot_join(ci); @@ -144,15 +104,10 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) return; if (ci->bi) - { - if (u) - ci->bi->UnAssign(u, ci); - else - ci->bi->UnAssign(NULL, ci); - } + ci->bi->UnAssign(u, ci); ci->bi = this; - this->chancount++; + ++this->chancount; if (ci->c && ci->c->usercount >= Config.BSMinUsers) bot_join(ci); } @@ -172,8 +127,6 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci) ircdproto->SendPart(ci->bi, ci->c, ""); } - ci->bi->chancount--; + --ci->bi->chancount; ci->bi = NULL; } - - diff --git a/src/botserv.c b/src/botserv.c index f145e7028..148d71b97 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -52,10 +52,10 @@ void get_botserv_stats(long *nrec, long *memuse) for (bi = botlists[i]; bi; bi = bi->next) { count++; mem += sizeof(*bi); - mem += strlen(bi->nick) + 1; - mem += strlen(bi->user) + 1; - mem += strlen(bi->host) + 1; - mem += strlen(bi->real) + 1; + mem += bi->nick.size() + 1; + mem += bi->user.size() + 1; + mem += bi->host.size() + 1; + mem += bi->real.size() + 1; } } @@ -463,17 +463,18 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) /* Inserts a bot in the bot list. I can't be much explicit mh? */ -void insert_bot(BotInfo * bi) +void insert_bot(BotInfo *bi) { BotInfo *ptr, *prev; - for (prev = NULL, ptr = botlists[tolower(*bi->nick)]; - ptr != NULL && stricmp(ptr->nick, bi->nick) < 0; + ci::string ci_bi_nick(bi->nick.c_str()); + for (prev = NULL, ptr = botlists[tolower(bi->nick[0])]; + ptr != NULL && ci_bi_nick > ptr->nick.c_str(); prev = ptr, ptr = ptr->next); bi->prev = prev; bi->next = ptr; if (!prev) - botlists[tolower(*bi->nick)] = bi; + botlists[tolower(bi->nick[0])] = bi; else prev->next = bi; if (ptr) @@ -648,7 +649,7 @@ void bot_join(ChannelInfo * ci) || (limit && ci->c->usercount >= limit)) ircdproto->SendNoticeChanops(ci->bi, ci->c, "%s invited %s into the channel.", - ci->bi->nick, ci->bi->nick); + ci->bi->nick.c_str(), ci->bi->nick.c_str()); } ircdproto->SendJoin(ci->bi, ci->c->name.c_str(), ci->c->creation_time); ci->c->SetMode(NULL, CMODE_PROTECT, ci->bi->nick); @@ -756,7 +757,7 @@ void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, kav[1] = nick; if (!reason) { - kav[2] = ci->bi->nick; + kav[2] = ci->bi->nick.c_str(); } else { if (strlen(reason) > 200) (*const_cast<char **>(&reason))[200] = '\0'; // Unsafe cast -- will review later -- CyberBotX @@ -801,7 +802,7 @@ void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, av[1] = nick; if (!reason) { - av[2] = ci->bi->nick; + av[2] = ci->bi->nick.c_str(); } else { if (strlen(reason) > 200) (*const_cast<char **>(&reason))[200] = '\0'; // Unsafe cast -- will review later -- CyberBotX diff --git a/src/channels.c b/src/channels.c index 5e9ca98de..85b026b40 100644 --- a/src/channels.c +++ b/src/channels.c @@ -50,7 +50,7 @@ Channel::Channel(const std::string &name, time_t ts) this->server_modetime = this->chanserv_modetime = 0; this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_sync = 0; - this->ci = cs_findchan(this->name.c_str()); + this->ci = cs_findchan(this->name); if (this->ci) { this->ci->c = this; @@ -1139,7 +1139,7 @@ void do_join(const char *source, int ac, const char **av) * av[2] = reason */ -void do_kick(const char *source, int ac, const char **av) +void do_kick(const std::string &source, int ac, const char **av) { BotInfo *bi; ChannelInfo *ci; @@ -2309,32 +2309,26 @@ 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 char *nick, const char *user, const char *host, uint32 ip) +int entry_match(Entry *e, const std::string &nick, const std::string &user, const std::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; - if (ircd->cidrchanbei && (e->HasFlag(ENTRYTYPE_CIDR4)) && - (!ip || (ip && ((ip & e->cidr_mask) != e->cidr_ip)))) + 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 || stricmp(e->nick, nick) != 0)) + if (e->HasFlag(ENTRYTYPE_NICK) && (nick.empty() || nick != e->nick)) return 0; - if ((e->HasFlag(ENTRYTYPE_USER)) - && (!user || stricmp(e->user, user) != 0)) + if (e->HasFlag(ENTRYTYPE_USER) && (user.empty() || user != e->user)) return 0; - if ((e->HasFlag(ENTRYTYPE_HOST)) - && (!user || stricmp(e->host, host) != 0)) + if (e->HasFlag(ENTRYTYPE_HOST) && (host.empty() || host != e->host)) return 0; - if ((e->HasFlag(ENTRYTYPE_NICK_WILD)) - && !Anope::Match(nick, e->nick, false)) + if (e->HasFlag(ENTRYTYPE_NICK_WILD) && !Anope::Match(nick, e->nick, false)) return 0; - if ((e->HasFlag(ENTRYTYPE_USER_WILD)) - && !Anope::Match(user, e->user, false)) + if (e->HasFlag(ENTRYTYPE_USER_WILD) && !Anope::Match(user, e->user, false)) return 0; - if ((e->HasFlag(ENTRYTYPE_HOST_WILD)) - && !Anope::Match(host, e->host, false)) + if (e->HasFlag(ENTRYTYPE_HOST_WILD) && !Anope::Match(host, e->host, false)) return 0; return 1; diff --git a/src/chanserv.c b/src/chanserv.c index a9ab953fc..5fcfee37f 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -131,7 +131,7 @@ class ChanServTimer : public Timer void Tick(time_t ctime) { - ChannelInfo *ci = cs_findchan(channel.c_str()); + ChannelInfo *ci = cs_findchan(channel); if (ci) ci->UnsetFlag(CI_INHABIT); @@ -472,7 +472,7 @@ int check_valid_op(User * user, Channel * chan, int servermode) chan->RemoveMode(NULL, CMODE_OP, user->nick); if (halfop && !check_access(user, chan->ci, CA_AUTOHALFOP)) chan->RemoveMode(NULL, CMODE_HALFOP, user->nick); - + return 0; } @@ -511,7 +511,7 @@ int check_should_op(User * user, char *chan) if (check_access(user, ci, CA_AUTOOP)) { - ci->c->SetMode(NULL, CMODE_OP, user->nick); + ci->c->SetMode(NULL, CMODE_OP, user->nick); return 1; } @@ -968,11 +968,11 @@ void cs_remove_nick(const NickCore * nc) /* Return the ChannelInfo structure for the given channel, or NULL if the * channel isn't registered. */ -ChannelInfo *cs_findchan(const char *chan) +ChannelInfo *cs_findchan(const std::string &chan) { ChannelInfo *ci; - if (!chan || !*chan) { + if (chan.empty()) { if (debug) { alog("debug: cs_findchan() called with NULL values"); } @@ -981,7 +981,7 @@ ChannelInfo *cs_findchan(const char *chan) for (ci = chanlists[static_cast<unsigned char>(tolower(chan[1]))]; ci; ci = ci->next) { - if (stricmp(ci->name.c_str(), chan) == 0) + if (ci::string(ci->name.c_str()) == chan) return ci; } return NULL; @@ -1094,7 +1094,7 @@ bool IsFounder(User *user, ChannelInfo *ci) if (IsRealFounder(user, ci)) return true; - + if (user->nc) access = ci->GetAccess(user->nc); else @@ -1103,7 +1103,7 @@ bool IsFounder(User *user, ChannelInfo *ci) if (na) access = ci->GetAccess(na->nc); } - + /* If they're QOP+ and theyre identified or theyre recognized and the channel isn't secure */ if (access && access->level >= ACCESS_QOP && (user->nc || (user->IsRecognized() && !(ci->HasFlag(CI_SECURE))))) return true; @@ -1148,10 +1148,10 @@ int get_access(User *user, ChannelInfo *ci) /* SuperAdmin always has highest level */ if (user->isSuperAdmin) return ACCESS_SUPERADMIN; - + if (IsFounder(user, ci)) return ACCESS_FOUNDER; - + if (nick_identified(user)) { access = ci->GetAccess(user->nc); @@ -1292,7 +1292,7 @@ AutoKick *is_stuck(ChannelInfo * ci, const char *mask) { if (!ci) return NULL; - + for (unsigned i = 0; i < ci->GetAkickCount(); ++i) { AutoKick *akick = ci->GetAkick(i); diff --git a/src/commands.c b/src/commands.c index 553bc2442..f8a1bba62 100644 --- a/src/commands.c +++ b/src/commands.c @@ -48,7 +48,7 @@ Command *lookup_cmd(Command * list, char *cmd) * @param cmd Command * @return void */ -void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *cmd) +void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], const char *cmd) { Command *c = findCommand(cmdTable, cmd); int retVal = MOD_CONT; @@ -58,10 +58,10 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char * FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(service, u, cmd, c)); if (MOD_RESULT == EVENT_STOP) return; - + if (!c) { - notice_lang(service, u, UNKNOWN_COMMAND_HELP, cmd, service); + notice_lang(service, u, UNKNOWN_COMMAND_HELP, cmd, service.c_str()); return; } @@ -71,7 +71,7 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char * if (!nick_identified(u)) { notice_lang(service, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); - alog("Access denied for unregistered user %s with service %s and command %s", u->nick.c_str(), service, cmd); + alog("Access denied for unregistered user %s with service %s and command %s", u->nick.c_str(), service.c_str(), cmd); return; } } @@ -122,14 +122,14 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char * { notice_lang(service, u, CHAN_X_FORBIDDEN, ci->name.c_str()); alog("Access denied for user %s with service %s and command %s because of FORBIDDEN channel %s", - u->nick.c_str(), service, cmd, ci->name.c_str()); + u->nick.c_str(), service.c_str(), cmd, ci->name.c_str()); return; } else if ((ci->HasFlag(CI_SUSPENDED)) && (!c->HasFlag(CFLAG_ALLOW_SUSPENDED))) { notice_lang(service, u, CHAN_X_FORBIDDEN, ci->name.c_str()); alog("Access denied for user %s with service %s and command %s because of SUSPENDED channel %s", - u->nick.c_str(), service, cmd, ci->name.c_str()); + u->nick.c_str(), service.c_str(), cmd, ci->name.c_str()); return; } } @@ -153,7 +153,7 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char * if (!u->nc->HasCommand(c->permission)) { notice_lang(service, u, ACCESS_DENIED); - alog("Access denied for user %s with service %s and command %s", u->nick.c_str(), service, cmd); + alog("Access denied for user %s with service %s and command %s", u->nick.c_str(), service.c_str(), cmd); return; } diff --git a/src/core/bs_assign.c b/src/core/bs_assign.c index 56912559e..bf9fdc5b2 100644 --- a/src/core/bs_assign.c +++ b/src/core/bs_assign.c @@ -55,14 +55,14 @@ class CommandBSAssign : public Command return MOD_CONT; } - if ((ci->bi) && (stricmp(ci->bi->nick, nick) == 0)) + if (ci->bi && ci::string(ci->bi->nick.c_str()) == nick) { - notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick, chan); + notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan); return MOD_CONT; } |
