From 28e12bc24a9c85f4f0d1e37567618ec39cb501f6 Mon Sep 17 00:00:00 2001 From: Naram Qashat Date: Sun, 27 Jun 2010 23:15:05 -0400 Subject: The next of a few "CBX OCDing over code style" commits, maybe the last. NOTES: I have been unable to compile the db_mysql_* functions on my system here, so those are untested. db-convert seems to be badly programmed and needs more work in my opinion. --- src/core/os_akill.cpp | 16 +- src/core/os_chankill.cpp | 5 +- src/core/os_chanlist.cpp | 21 +- src/core/os_clearmodes.cpp | 21 +- src/core/os_defcon.cpp | 67 +- src/core/os_global.cpp | 3 +- src/core/os_help.cpp | 6 +- src/core/os_ignore.cpp | 8 +- src/core/os_jupe.cpp | 3 +- src/core/os_kick.cpp | 3 +- src/core/os_mode.cpp | 3 +- src/core/os_modinfo.cpp | 10 +- src/core/os_modlist.cpp | 3 +- src/core/os_modload.cpp | 3 +- src/core/os_modunload.cpp | 3 +- src/core/os_news.cpp | 57 +- src/core/os_noop.cpp | 5 +- src/core/os_oline.cpp | 9 +- src/core/os_quit.cpp | 1 - src/core/os_reload.cpp | 3 +- src/core/os_restart.cpp | 4 +- src/core/os_session.cpp | 11 +- src/core/os_set.cpp | 3 +- src/core/os_shutdown.cpp | 4 +- src/core/os_snline.cpp | 21 +- src/core/os_sqline.cpp | 24 +- src/core/os_staff.cpp | 9 +- src/core/os_stats.cpp | 50 +- src/core/os_svsnick.cpp | 13 +- src/core/os_szline.cpp | 21 +- src/core/os_umode.cpp | 9 +- src/core/os_update.cpp | 3 +- src/core/os_userlist.cpp | 21 +- src/core/ss_main.cpp | 6 +- src/modules/cs_appendtopic.cpp | 30 +- src/modules/cs_enforce.cpp | 31 +- src/modules/cs_tban.cpp | 18 +- src/modules/hs_request.cpp | 81 ++- src/modules/mysql/db_mysql.h | 16 +- src/modules/mysql/db_mysql_execute.cpp | 4 +- src/modules/mysql/db_mysql_read.cpp | 130 +--- src/modules/mysql/db_mysql_write.cpp | 131 ++-- src/modules/ns_maxemail.cpp | 12 +- src/modules/os_info.cpp | 33 +- src/modules/ssl/m_ssl.cpp | 18 +- src/tools/CMakeLists.txt | 4 + src/tools/anopesmtp.c | 604 ------------------ src/tools/anopesmtp.cpp | 521 ++++++++++++++++ src/tools/db-convert.c | 1041 -------------------------------- src/tools/db-convert.cpp | 1026 +++++++++++++++++++++++++++++++ src/tools/db-convert.h | 871 +++++++++++++------------- src/tools/smtp.h | 95 ++- 52 files changed, 2358 insertions(+), 2757 deletions(-) delete mode 100644 src/tools/anopesmtp.c create mode 100644 src/tools/anopesmtp.cpp delete mode 100644 src/tools/db-convert.c create mode 100644 src/tools/db-convert.cpp diff --git a/src/core/os_akill.cpp b/src/core/os_akill.cpp index 06be20d1b..a6eb05632 100644 --- a/src/core/os_akill.cpp +++ b/src/core/os_akill.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -22,7 +21,7 @@ class AkillDelCallback : public NumberList AkillDelCallback(User *_u, const std::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) { } - + ~AkillDelCallback() { if (!Deleted) @@ -83,7 +82,7 @@ class AkillListCallback : public NumberList DoList(u, x, Number); } - + static void DoList(User *u, XLine *x, unsigned Number) { notice_lang(Config.s_OperServ, u, OPER_AKILL_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); @@ -274,11 +273,11 @@ class CommandOSAKill : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SGLine->GetCount(); ++i) + for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i) { XLine *x = SGLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -315,11 +314,11 @@ class CommandOSAKill : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SGLine->GetCount(); ++i) + for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i) { XLine *x = SGLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -394,6 +393,7 @@ class OSAKill : public Module { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(OperServ, new CommandOSAKill()); } }; diff --git a/src/core/os_chankill.cpp b/src/core/os_chankill.cpp index 8a22fa256..f751d6dee 100644 --- a/src/core/os_chankill.cpp +++ b/src/core/os_chankill.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -67,7 +66,7 @@ class CommandOSChanKill : public Command if ((c = findchan(channel))) { - for (CUserList::iterator it = c->users.begin(); it != c->users.end();) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { UserContainer *uc = *it++; diff --git a/src/core/os_chanlist.cpp b/src/core/os_chanlist.cpp index e48cd2b9c..d1a154d2f 100644 --- a/src/core/os_chanlist.cpp +++ b/src/core/os_chanlist.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -38,18 +37,14 @@ class CommandOSChanList : public Command { notice_lang(Config.s_OperServ, u, OPER_CHANLIST_HEADER_USER, u2->nick.c_str()); - for (UChannelList::iterator uit = u2->chans.begin(); uit != u2->chans.end(); ++uit) + for (UChannelList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit) { ChannelContainer *cc = *uit; if (!Modes.empty()) - { - for (std::list::iterator it = Modes.begin(); it != Modes.end(); ++it) - { + for (std::list::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) if (!cc->chan->HasMode(*it)) continue; - } - } notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), chan_get_modes(cc->chan, 1, 1), cc->chan->topic ? cc->chan->topic : ""); } @@ -58,20 +53,16 @@ class CommandOSChanList : public Command { notice_lang(Config.s_OperServ, u, OPER_CHANLIST_HEADER); - for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) + for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) { Channel *c = cit->second; - + if (pattern && !Anope::Match(c->name, pattern, false)) continue; if (!Modes.empty()) - { - for (std::list::iterator it = Modes.begin(); it != Modes.end(); ++it) - { + for (std::list::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) if (!c->HasMode(*it)) continue; - } - } notice_lang(Config.s_OperServ, u, OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), chan_get_modes(c, 1, 1), c->topic ? c->topic : ""); } diff --git a/src/core/os_clearmodes.cpp b/src/core/os_clearmodes.cpp index f3d6223ea..3c73846c4 100644 --- a/src/core/os_clearmodes.cpp +++ b/src/core/os_clearmodes.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -42,10 +41,12 @@ class CommandOSClearModes : public Command else { ci::string s = params.size() > 1 ? params[1] : ""; - if (!s.empty()) { + if (!s.empty()) + { if (s == "ALL") all = 1; - else { + else + { this->OnSyntaxError(u, ""); return MOD_CONT; } @@ -60,7 +61,7 @@ class CommandOSClearModes : public Command ircdproto->SendSVSModeChan(c, "-o", NULL); else { - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -74,11 +75,11 @@ class CommandOSClearModes : public Command ircdproto->SendSVSModeChan(c, "-v", NULL); else { - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; - if (uc->Status->HasFlag(CMODE_VOICE)) + if (uc->Status->HasFlag(CMODE_VOICE)) c->RemoveMode(NULL, CMODE_VOICE, uc->user->nick); } } @@ -90,7 +91,7 @@ class CommandOSClearModes : public Command ircdproto->SendSVSModeChan(c, "-h", NULL); else { - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -110,7 +111,7 @@ class CommandOSClearModes : public Command ircdproto->SendSVSModeChan(c, buf.c_str(), NULL); else { - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -130,7 +131,7 @@ class CommandOSClearModes : public Command ircdproto->SendSVSModeChan(c, buf.c_str(), NULL); else { - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; diff --git a/src/core/os_defcon.cpp b/src/core/os_defcon.cpp index de3c6b030..78e366071 100644 --- a/src/core/os_defcon.cpp +++ b/src/core/os_defcon.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -125,7 +124,7 @@ class CommandOSDEFCON : public Command { syntax_error(Config.s_OperServ, u, "DEFCON", OPER_DEFCON_SYNTAX); } - + void OnServHelp(User *u) { notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_DEFCON); @@ -137,13 +136,11 @@ class OSDEFCON : public Module public: OSDEFCON(const std::string &modname, const std::string &creator) : Module(modname, creator) { - this->SetAuthor("Anope"); - this->SetType(CORE); - if (!Config.DefConLevel) - { throw ModuleException("Invalid configuration settings"); - } + + this->SetAuthor("Anope"); + this->SetType(CORE); Implementation i[] = { I_OnPreUserConnect, I_OnChannelModeSet, I_OnChannelModeUnset, I_OnPreCommandRun, I_OnPreCommand, I_OnUserConnect, I_OnChannelModeAdd, I_OnChannelCreate }; ModuleManager::Attach(i, this, 8); @@ -197,9 +194,7 @@ class OSDEFCON : public Module std::string param; if (GetDefConParam(Name, param)) - { c->SetMode(OperServ, Name, param); - } else c->SetMode(OperServ, Name); @@ -220,9 +215,7 @@ class OSDEFCON : public Module if ((CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY)) && !is_oper(u)) { if (!CheckDefCon(DEFCON_SILENT_OPER_ONLY)) - { notice_lang(bi->nick.c_str(), u, OPER_DEFCON_DENIED); - } return EVENT_STOP; } @@ -236,13 +229,10 @@ class OSDEFCON : public Module { if (command == "SET") { - if (!params.empty() && params[0] == "MLOCK") + if (!params.empty() && params[0] == "MLOCK" && CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) { - if (CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) - { - notice_lang(Config.s_ChanServ, u, OPER_DEFCON_DENIED); - return EVENT_STOP; - } + notice_lang(Config.s_ChanServ, u, OPER_DEFCON_DENIED); + return EVENT_STOP; } } else if (command == "REGISTER" || command == "GROUP") @@ -295,7 +285,7 @@ class OSDEFCON : public Module ircdproto->SendMessage(OperServ, u->nick.c_str(), "%s", Config.SessionLimitDetailsLoc); kill_user(Config.s_OperServ, u->nick, "Session limit exceeded"); - session->hits++; + ++session->hits; if (Config.MaxSessionKill && session->hits >= Config.MaxSessionKill) { SGLine->Add(NULL, NULL, ci::string("*@") + u->host, time(NULL) + Config.SessionAutoKillExpiry, "Session limit exceeded"); @@ -312,21 +302,17 @@ class OSDEFCON : public Module std::string modes = Config.DefConChanModes; if (modes.find(cm->ModeChar) != std::string::npos) - { /* New mode has been added to Anope, check to see if defcon * requires it */ defconParseModeString(Config.DefConChanModes); - } } } void OnChannelCreate(Channel *c) { if (CheckDefCon(DEFCON_FORCE_CHAN_MODES)) - { c->SetModes(OperServ, false, Config.DefConChanModes); - } } }; @@ -398,7 +384,7 @@ void runDefCon() */ void defconParseModeString(const char *str) { - int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ + int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ unsigned char mode; ChannelMode *cm; ChannelModeParam *cmp; @@ -414,7 +400,7 @@ void defconParseModeString(const char *str) ss.GetToken(modes); /* Loop while there are modes to set */ - for (unsigned i = 0; i < modes.size(); ++i) + for (unsigned i = 0, end = modes.size(); i < end; ++i) { mode = modes[i]; @@ -466,34 +452,26 @@ void defconParseModeString(const char *str) DefConModesOn.UnsetFlag(cm->Name); if (cm->Type == MODE_PARAM) - { UnsetDefConParam(cm->Name); - } } } } } - if ((cm = ModeManager::FindChannelModeByName(CMODE_REDIRECT))) + /* We can't mlock +L if +l is not mlocked as well. */ + if ((cm = ModeManager::FindChannelModeByName(CMODE_REDIRECT)) && DefConModesOn.HasFlag(cm->Name) && !DefConModesOn.HasFlag(CMODE_LIMIT)) { - /* We can't mlock +L if +l is not mlocked as well. */ - if (DefConModesOn.HasFlag(cm->Name) && !DefConModesOn.HasFlag(CMODE_LIMIT)) - { - DefConModesOn.UnsetFlag(CMODE_REDIRECT); + DefConModesOn.UnsetFlag(CMODE_REDIRECT); - Alog() << "DefConChanModes must lock mode +l as well to lock mode +L"; - } + Alog() << "DefConChanModes must lock mode +l as well to lock mode +L"; } /* Some ircd we can't set NOKNOCK without INVITE */ /* So check if we need there is a NOKNOCK MODE and that we need INVITEONLY */ - if (ircd->knock_needs_i && (cm = ModeManager::FindChannelModeByName(CMODE_NOKNOCK))) + if (ircd->knock_needs_i && (cm = ModeManager::FindChannelModeByName(CMODE_NOKNOCK)) && DefConModesOn.HasFlag(cm->Name) && !DefConModesOn.HasFlag(CMODE_INVITE)) { - if (DefConModesOn.HasFlag(cm->Name) && !DefConModesOn.HasFlag(CMODE_INVITE)) - { - DefConModesOn.UnsetFlag(CMODE_NOKNOCK); - Alog() << "DefConChanModes must lock mode +i as well to lock mode +K"; - } + DefConModesOn.UnsetFlag(CMODE_NOKNOCK); + Alog() << "DefConChanModes must lock mode +i as well to lock mode +K"; } } @@ -501,13 +479,12 @@ static char *defconReverseModes(const char *modes) { char *newmodes = NULL; unsigned i = 0; - if (!modes) { + if (!modes) return NULL; - } - if (!(newmodes = new char[strlen(modes) + 1])) { + if (!(newmodes = new char[strlen(modes) + 1])) return NULL; - } - for (i = 0; i < strlen(modes); i++) { + for (i = 0; i < strlen(modes); ++i) + { if (modes[i] == '+') newmodes[i] = '-'; else if (modes[i] == '-') diff --git a/src/core/os_global.cpp b/src/core/os_global.cpp index afa040be8..a5abde2ff 100644 --- a/src/core/os_global.cpp +++ b/src/core/os_global.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_help.cpp b/src/core/os_help.cpp index 433d673c7..9ddeda66e 100644 --- a/src/core/os_help.cpp +++ b/src/core/os_help.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -30,7 +29,7 @@ class CommandOSHelp : public Command void OnSyntaxError(User *u, const ci::string &subcommand) { notice_help(Config.s_OperServ, u, OPER_HELP); - for (CommandMap::const_iterator it = NickServ->Commands.begin(); it != NickServ->Commands.end(); ++it) + for (CommandMap::const_iterator it = OperServ->Commands.begin(), it_end = OperServ->Commands.end(); it != it_end; ++it) it->second->OnServHelp(u); notice_help(Config.s_OperServ, u, OPER_HELP_LOGGED); } @@ -43,6 +42,7 @@ class OSHelp : public Module { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(OperServ, new CommandOSHelp()); } }; diff --git a/src/core/os_ignore.cpp b/src/core/os_ignore.cpp index cbee6e3fb..881f79601 100644 --- a/src/core/os_ignore.cpp +++ b/src/core/os_ignore.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -141,12 +140,13 @@ class OSIgnore : public Module { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(OperServ, new CommandOSIgnore()); Implementation i[] = { I_OnDatabaseRead, I_OnDatabaseWrite }; ModuleManager::Attach(i, this, 2); } - + EventReturn OnDatabaseRead(const std::vector ¶ms) { std::string buf; @@ -177,7 +177,7 @@ class OSIgnore : public Module { next = ign->next; - if (ign->time != 0 && ign->time <= now) + if (ign->time && ign->time <= now) { Alog(LOG_DEBUG) << "[os_ignore] Expiring ignore entry " << ign->mask; if (ign->prev) diff --git a/src/core/os_jupe.cpp b/src/core/os_jupe.cpp index cce908949..8718f95d8 100644 --- a/src/core/os_jupe.cpp +++ b/src/core/os_jupe.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_kick.cpp b/src/core/os_kick.cpp index e05764a09..2600814f3 100644 --- a/src/core/os_kick.cpp +++ b/src/core/os_kick.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_mode.cpp b/src/core/os_mode.cpp index 139ef8edf..3f33257fe 100644 --- a/src/core/os_mode.cpp +++ b/src/core/os_mode.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_modinfo.cpp b/src/core/os_modinfo.cpp index e867713f8..d71f146c7 100644 --- a/src/core/os_modinfo.cpp +++ b/src/core/os_modinfo.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -35,7 +34,7 @@ class CommandOSModInfo : public Command tm = *localtime(&m->created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm); notice_lang(Config.s_OperServ, u, OPER_MODULE_INFO_LIST, m->name.c_str(), !m->version.empty() ? m->version.c_str() : "?", !m->author.empty() ? m->author.c_str() : "?", timebuf); - + showModuleCmdLoaded(HostServ, m->name.c_str(), u); showModuleCmdLoaded(OperServ, m->name.c_str(), u); showModuleCmdLoaded(NickServ, m->name.c_str(), u); @@ -73,6 +72,7 @@ class OSModInfo : public Module { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(OperServ, new CommandOSModInfo()); } }; @@ -81,10 +81,10 @@ static int showModuleCmdLoaded(BotInfo *bi, const ci::string &mod_name, User *u) { if (!bi) return 0; - + int display = 0; - for (std::map::iterator it = bi->Commands.begin(); it != bi->Commands.end(); ++it) + for (std::map::iterator it = bi->Commands.begin(), it_end = bi->Commands.end(); it != it_end; ++it) { Command *c = it->second; diff --git a/src/core/os_modlist.cpp b/src/core/os_modlist.cpp index 114327aaa..c719b734d 100644 --- a/src/core/os_modlist.cpp +++ b/src/core/os_modlist.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_modload.cpp b/src/core/os_modload.cpp index 7134aae9f..f70c80c05 100644 --- a/src/core/os_modload.cpp +++ b/src/core/os_modload.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_modunload.cpp b/src/core/os_modunload.cpp index 12dce4300..0988d4473 100644 --- a/src/core/os_modunload.cpp +++ b/src/core/os_modunload.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_news.cpp b/src/core/os_news.cpp index 3626d4e02..c3ebabf3a 100644 --- a/src/core/os_news.cpp +++ b/src/core/os_news.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -18,19 +17,21 @@ /* List of messages for each news type. This simplifies message sending. */ -#define MSG_SYNTAX 0 -#define MSG_LIST_HEADER 1 -#define MSG_LIST_ENTRY 2 -#define MSG_LIST_NONE 3 -#define MSG_ADD_SYNTAX 4 -#define MSG_ADD_FULL 5 -#define MSG_ADDED 6 -#define MSG_DEL_SYNTAX 7 -#define MSG_DEL_NOT_FOUND 8 -#define MSG_DELETED 9 -#define MSG_DEL_NONE 10 -#define MSG_DELETED_ALL 11 -#define MSG_MAX 11 +enum +{ + MSG_SYNTAX, + MSG_LIST_HEADER, + MSG_LIST_ENTRY, + MSG_LIST_NONE, + MSG_ADD_SYNTAX, + MSG_ADD_FULL, + MSG_ADDED, + MSG_DEL_SYNTAX, + MSG_DEL_NOT_FOUND, + MSG_DELETED, + MSG_DEL_NONE, + MSG_DELETED_ALL +}; struct newsmsgs msgarray[] = { {NEWS_LOGON, "LOGON", @@ -96,7 +97,7 @@ static void DisplayNews(User *u, NewsType Type) unsigned displayed = 0; bool NewsExists = false; - for (unsigned i = 0; i < News.size(); ++i) + for (unsigned i = 0, end = News.size(); i < end; ++i) { if (News[i]->type == Type) { @@ -129,18 +130,16 @@ static void DisplayNews(User *u, NewsType Type) } } -static int add_newsitem(User * u, const char *text, NewsType type) +static int add_newsitem(User *u, const char *text, NewsType type) { int num = 0; for (unsigned i = News.size(); i > 0; --i) - { if (News[i - 1]->type == type) { num = News[i - 1]->num; break; } - } NewsItem *news = new NewsItem; news->type = type; @@ -159,27 +158,25 @@ static int del_newsitem(unsigned num, NewsType type) int count = 0; for (unsigned i = News.size(); i > 0; --i) - { if (News[i - 1]->type == type && (num == 0 || News[i - 1]->num == num)) { delete News[i - 1]; News.erase(News.begin() + i - 1); ++count; } - } return count; } static int *findmsgs(NewsType type, const char **type_name) { - for (unsigned i = 0; i < lenof(msgarray); i++) { - if (msgarray[i].type == type) { + for (unsigned i = 0; i < lenof(msgarray); ++i) + if (msgarray[i].type == type) + { if (type_name) *type_name = msgarray[i].name; return msgarray[i].msgs; } - } return NULL; } @@ -192,8 +189,7 @@ class NewsBase : public Command char timebuf[64]; struct tm *tm; - for (unsigned i = 0; i < News.size(); ++i) - { + for (unsigned i = 0, end = News.size(); i < end; ++i) if (News[i]->type == type) { if (!count) @@ -203,7 +199,6 @@ class NewsBase : public Command notice_lang(Config.s_OperServ, u, msgs[MSG_LIST_ENTRY], News[i]->num, timebuf, !News[i]->who.empty() ? News[i]->who.c_str() : "", News[i]->Text.c_str()); ++count; } - } if (!count) notice_lang(Config.s_OperServ, u, msgs[MSG_LIST_NONE]); else @@ -256,11 +251,9 @@ class NewsBase : public Command if (num > 0 && del_newsitem(num, type)) { notice_lang(Config.s_OperServ, u, msgs[MSG_DELETED], num); - for (unsigned i = 0; i < News.size(); ++i) - { + for (unsigned i = 0, end = News.size(); i < end; ++i) if (News[i]->type == type && News[i]->num > num) --News[i]->num; - } } else notice_lang(Config.s_OperServ, u, msgs[MSG_DEL_NOT_FOUND], num); @@ -422,7 +415,7 @@ class OSNews : public Module ~OSNews() { - for (std::vector::iterator it = News.begin(); it != News.end(); ++it) + for (std::vector::iterator it = News.begin(), it_end = News.end(); it != it_end; ++it) delete *it; News.clear(); } @@ -430,9 +423,7 @@ class OSNews : public Module void OnUserModeSet(User *u, UserModeName Name) { if (Name == UMODE_OPER) - { DisplayNews(u, NEWS_OPER); - } } void OnUserConnect(User *u) diff --git a/src/core/os_noop.cpp b/src/core/os_noop.cpp index f6269592a..51337106e 100644 --- a/src/core/os_noop.cpp +++ b/src/core/os_noop.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -39,7 +38,7 @@ class CommandOSNOOP : public Command notice_lang(Config.s_OperServ, u, OPER_NOOP_SET, server); /* Kill all the IRCops of the server */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ) { User *u2 = it->second; ++it; diff --git a/src/core/os_oline.cpp b/src/core/os_oline.cpp index 49d9ed8af..bceea1a49 100644 --- a/src/core/os_oline.cpp +++ b/src/core/os_oline.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -71,13 +70,13 @@ class OSOLine : public Module public: OSOLine(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->omode) + throw ModuleException("Your IRCd does not support OMODE."); + this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSOLine()); - - if (!ircd->omode) - throw ModuleException("Your IRCd does not support OMODE."); } }; diff --git a/src/core/os_quit.cpp b/src/core/os_quit.cpp index 9c3e56bc6..1c5a073bc 100644 --- a/src/core/os_quit.cpp +++ b/src/core/os_quit.cpp @@ -23,7 +23,6 @@ class CommandOSQuit : public Command CommandReturn Execute(User *u, const std::vector ¶ms) { - quitmsg = new char[28 + u->nick.length()]; if (!quitmsg) quitmsg = "QUIT command received, but out of memory!"; diff --git a/src/core/os_reload.cpp b/src/core/os_reload.cpp index 4bad807e5..15a45d0a2 100644 --- a/src/core/os_reload.cpp +++ b/src/core/os_reload.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_restart.cpp b/src/core/os_restart.cpp index bf08fbbcb..04c6d02d6 100644 --- a/src/core/os_restart.cpp +++ b/src/core/os_restart.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -55,6 +54,7 @@ class OSRestart : public Module { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(OperServ, new CommandOSRestart()); } }; diff --git a/src/core/os_session.cpp b/src/core/os_session.cpp index 798ca4021..a0f52877e 100644 --- a/src/core/os_session.cpp +++ b/src/core/os_session.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -144,7 +143,7 @@ class CommandOSSession : public Command notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_HEADER, mincount); notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_COLHEAD); - for (session_map::const_iterator it = SessionList.begin(); it != SessionList.end(); ++it) + for (session_map::const_iterator it = SessionList.begin(), it_end = SessionList.end(); it != it_end; ++it) { Session *session = it->second; @@ -300,7 +299,6 @@ class CommandOSException : public Command int deleted = 0; for (i = 0; i < nexceptions; ++i) - { if (!stricmp(mask, exceptions[i].mask)) { ExceptionDelCallback::DoDel(u, i); @@ -308,7 +306,6 @@ class CommandOSException : public Command deleted = 1; break; } - } if (!deleted && i == nexceptions) notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NOT_FOUND, mask); } @@ -391,7 +388,6 @@ class CommandOSException : public Command bool SentHeader = false; for (i = 0; i < nexceptions; ++i) - { if (!mask || Anope::Match(exceptions[i].mask, mask, false)) { if (!SentHeader) @@ -403,7 +399,6 @@ class CommandOSException : public Command ExceptionListCallback::DoList(u, i); } - } if (!SentHeader) notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NO_MATCH); @@ -425,7 +420,6 @@ class CommandOSException : public Command bool SentHeader = false; for (i = 0; i < nexceptions; ++i) - { if (!mask || Anope::Match(exceptions[i].mask, mask, false)) { if (!SentHeader) @@ -436,7 +430,6 @@ class CommandOSException : public Command ExceptionViewCallback::DoList(u, i); } - } if (!SentHeader) notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NO_MATCH); diff --git a/src/core/os_set.cpp b/src/core/os_set.cpp index 229722e5a..06a5f6886 100644 --- a/src/core/os_set.cpp +++ b/src/core/os_set.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_shutdown.cpp b/src/core/os_shutdown.cpp index 73e6b1bba..acdddac8e 100644 --- a/src/core/os_shutdown.cpp +++ b/src/core/os_shutdown.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -23,7 +22,6 @@ class CommandOSShutdown : public Command CommandReturn Execute(User *u, const std::vector ¶ms) { - quitmsg = new char[32 + u->nick.length()]; if (!quitmsg) quitmsg = "SHUTDOWN command received, but out of memory!"; diff --git a/src/core/os_snline.cpp b/src/core/os_snline.cpp index 5463457de..73706a3dd 100644 --- a/src/core/os_snline.cpp +++ b/src/core/os_snline.cpp @@ -7,10 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * $Id$ - * */ + /*************************************************************************/ #include "module.h" @@ -178,7 +176,8 @@ class CommandOSSNLine : public Command sep.GetToken(mask); std::string reason = sep.GetRemaining(); - if (!mask.empty() && !reason.empty()) { + if (!mask.empty() && !reason.empty()) + { /* Clean up the last character of the mask if it is a space * See bug #761 */ @@ -292,11 +291,11 @@ class CommandOSSNLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SNLine->GetCount(); ++i) + for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i) { XLine *x = SNLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -333,11 +332,11 @@ class CommandOSSNLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SNLine->GetCount(); ++i) + for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i) { XLine *x = SNLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -410,15 +409,13 @@ class OSSNLine : public Module public: OSSNLine(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->snline) + throw ModuleException("Your IRCd does not support SNLine"); this->SetAuthor("Anope"); - this->SetVersion("$Id$"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSSNLine()); - - if (!ircd->snline) - throw ModuleException("Your IRCd does not support SNLine"); } }; diff --git a/src/core/os_sqline.cpp b/src/core/os_sqline.cpp index 6961140f3..39755525a 100644 --- a/src/core/os_sqline.cpp +++ b/src/core/os_sqline.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -27,7 +26,7 @@ class SQLineDelCallback : public NumberList { if (!Deleted) notice_lang(Config.s_OperServ, u, OPER_SQLINE_NO_MATCH); - else if (Deleted == 0) + else if (Deleted == 1) notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_ONE); else notice_lang(Config.s_OperServ, u, OPER_SQLINE_DELETED_SEVERAL, Deleted); @@ -119,8 +118,7 @@ class SQLineViewCallback : public SQLineListCallback tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, -expirebuf, x->Reason.c_str()); + notice_lang(Config.s_OperServ, u, OPER_SQLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); } }; @@ -169,7 +167,7 @@ class CommandOSSQLine : public Command if (mask && *reason) { XLine *x = SQLine->Add(OperServ, u, mask, expires, reason); - + if (!x) return MOD_CONT; @@ -274,11 +272,11 @@ class CommandOSSQLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SQLine->GetCount(); ++i) + for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i) { XLine *x = SQLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -315,11 +313,11 @@ class CommandOSSQLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SQLine->GetCount(); ++i) + for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i) { XLine *x = SQLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -392,13 +390,13 @@ class OSSQLine : public Module public: OSSQLine(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->sqline) + throw ModuleException("Your IRCd does not support QLines."); + this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSSQLine()); - - if (!ircd->sqline) - throw ModuleException("Your IRCd does not support QLines."); } }; diff --git a/src/core/os_staff.cpp b/src/core/os_staff.cpp index 7955367a7..e36aadff8 100644 --- a/src/core/os_staff.cpp +++ b/src/core/os_staff.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -25,7 +24,7 @@ class CommandOSStaff : public Command { notice_lang(Config.s_OperServ, u, OPER_STAFF_LIST_HEADER); - for (std::list >::iterator it = Config.Opers.begin(); it != Config.Opers.end(); ++it) + for (std::list >::iterator it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { int found = 0; ci::string nick = it->first, type = it->second; @@ -34,7 +33,7 @@ class CommandOSStaff : public Command if (na) { /* We have to loop all users as some may be logged into an account but not a nick */ - for (user_map::iterator uit = UserListByNick.begin(); uit != UserListByNick.end(); ++uit) + for (user_map::iterator uit = UserListByNick.begin(), uit_end = UserListByNick.end(); uit != uit_end; ++uit) { User *u2 = uit->second; @@ -48,9 +47,7 @@ class CommandOSStaff : public Command } } if (!found) - { notice_lang(Config.s_OperServ, u, OPER_STAFF_FORMAT, ' ', type.c_str(), na->nick); - } } } diff --git a/src/core/os_stats.cpp b/src/core/os_stats.cpp index 05968540a..f660ffa15 100644 --- a/src/core/os_stats.cpp +++ b/src/core/os_stats.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -25,16 +24,12 @@ static int stats_count_servers(Server *s) { if (!s) return 0; - + int count = 1; if (s->GetLinks()) - { - for (std::list::const_iterator it = s->GetLinks()->begin(); it != s->GetLinks()->end(); ++it) - { + for (std::list::const_iterator it = s->GetLinks()->begin(), it_end = s->GetLinks()->end(); it != it_end; ++it) count += stats_count_servers(*it); - } - } return count; } @@ -147,7 +142,8 @@ class CommandOSStats : public Command notice_lang(Config.s_OperServ, u, OPER_STATS_UPTIME_1DHMS, days, hours, mins, secs); else { - if (hours > 1) { + if (hours > 1) + { if (mins != 1) { if (secs != 1) @@ -207,12 +203,8 @@ class CommandOSStats : public Command std::string buf; for (unsigned j = 0; !Capab_Info[j].Token.empty(); ++j) - { if (Capab.HasFlag(Capab_Info[j].Flag)) - { buf += " " + Capab_Info[j].Token; - } - } if (!buf.empty()) buf.erase(buf.begin()); @@ -314,14 +306,15 @@ class OSStats : public Module void get_operserv_stats(long *nrec, long *memuse) { - unsigned i; + unsigned i, end; long mem = 0, count = 0, mem2 = 0, count2 = 0; XLine *x; - count += SGLine->GetCount(); - mem += SGLine->GetCount() * sizeof(XLine); + end = SGLine->GetCount(); + count += end; + mem += end * sizeof(XLine); - for (i = 0; i < SGLine->GetCount(); ++i) + for (i = 0; i < end; ++i) { x = SGLine->GetEntry(i); @@ -335,10 +328,11 @@ void get_operserv_stats(long *nrec, long *memuse) if (ircd->snline) { - count += SNLine->GetCount(); - mem += SNLine->GetCount() * sizeof(XLine); + end = SNLine->GetCount(); + count += end; + mem += end * sizeof(XLine); - for (i = 0; i < SNLine->GetCount(); ++i) + for (i = 0; i < end; ++i) { x = SNLine->GetEntry(i); @@ -352,10 +346,11 @@ void get_operserv_stats(long *nrec, long *memuse) } if (ircd->sqline) { - count += SQLine->GetCount(); - mem += SGLine->GetCount() * sizeof(XLine); + end = SQLine->GetCount(); + count += end; + mem += end * sizeof(XLine); - for (i = 0; i < SQLine->GetCount(); ++i) + for (i = 0; i < end; ++i) { x = SNLine->GetEntry(i); @@ -369,10 +364,11 @@ void get_operserv_stats(long *nrec, long *memuse) } if (ircd->szline) { - count += SZLine->GetCount(); - mem += SZLine->GetCount() * sizeof(XLine); - - for (i = 0; i < SZLine->GetCount(); ++i) + end = SZLine->GetCount(); + count += end; + mem += end * sizeof(XLine); + + for (i = 0; i < end; ++i) { x = SZLine->GetEntry(i); diff --git a/src/core/os_svsnick.cpp b/src/core/os_svsnick.cpp index c12f87a78..a7a8e7a2c 100644 --- a/src/core/os_svsnick.cpp +++ b/src/core/os_svsnick.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -42,14 +41,12 @@ class CommandOSSVSNick : public Command notice_lang(Config.s_OperServ, u, NICK_X_ILLEGAL, newnick.c_str()); return MOD_CONT; } - for (unsigned i = 0; i < newnick.size(); ++i) - { + for (unsigned i = 0, end = newnick.size(); i < end; ++i) if (!isvalidnick(newnick[i])) { notice_lang(Config.s_OperServ, u, NICK_X_ILLEGAL, newnick.c_str()); return MOD_CONT; } - } /* Check for a nick in use or a forbidden/suspended nick */ if (!(u2 = finduser(nick))) @@ -89,13 +86,13 @@ class OSSVSNick : public Module public: OSSVSNick(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->svsnick) + throw ModuleException("Your IRCd does not support SVSNICK"); + this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSSVSNick()); - - if (!ircd->svsnick) - throw ModuleException("Your IRCd does not support SVSNICK"); } }; diff --git a/src/core/os_szline.cpp b/src/core/os_szline.cpp index 56674dd97..93a6ed38b 100644 --- a/src/core/os_szline.cpp +++ b/src/core/os_szline.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -119,12 +118,10 @@ class SZLineViewCallback : public SZLineListCallback tm = *localtime(&x->Created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); expire_left(u->Account(), expirebuf, sizeof(expirebuf), x->Expires); - notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, -expirebuf, x->Reason.c_str()); + notice_lang(Config.s_OperServ, u, OPER_SZLINE_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), timebuf, expirebuf, x->Reason.c_str()); } }; - class CommandOSSZLine : public Command { private: @@ -274,11 +271,11 @@ class CommandOSSZLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SZLine->GetCount(); ++i) + for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i) { XLine *x = SZLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -313,11 +310,11 @@ class CommandOSSZLine : public Command { bool SentHeader = false; - for (unsigned i = 0; i < SZLine->GetCount(); ++i) + for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i) { XLine *x = SZLine->GetEntry(i); - if (mask.empty() || (mask == x->Mask || Anope::Match(x->Mask, mask))) + if (mask.empty() || mask == x->Mask || Anope::Match(x->Mask, mask)) { if (!SentHeader) { @@ -390,13 +387,13 @@ class OSSZLine : public Module public: OSSZLine(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->szline) + throw ModuleException("Your IRCd does not support ZLINEs"); + this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSSZLine()); - - if (!ircd->szline) - throw ModuleException("Your IRCd does not support ZLINEs"); } }; diff --git a/src/core/os_umode.cpp b/src/core/os_umode.cpp index e20c0329f..cb353a938 100644 --- a/src/core/os_umode.cpp +++ b/src/core/os_umode.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -74,13 +73,13 @@ class OSUMode : public Module public: OSUMode(const std::string &modname, const std::string &creator) : Module(modname, creator) { + if (!ircd->umode) + throw ModuleException("Your IRCd does not support setting umodes"); + this->SetAuthor("Anope"); this->SetType(CORE); this->AddCommand(OperServ, new CommandOSUMode()); - - if (!ircd->umode) - throw ModuleException("Your IRCd does not support setting umodes"); } }; diff --git a/src/core/os_update.cpp b/src/core/os_update.cpp index 7451d974a..68cffd4ba 100644 --- a/src/core/os_update.cpp +++ b/src/core/os_update.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" diff --git a/src/core/os_userlist.cpp b/src/core/os_userlist.cpp index c2f9d8f96..9005016d5 100644 --- a/src/core/os_userlist.cpp +++ b/src/core/os_userlist.cpp @@ -7,9 +7,8 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ + /*************************************************************************/ #include "module.h" @@ -29,26 +28,20 @@ class CommandOSUserList : public Command std::list Modes; if (!opt.empty() && opt == "INVISIBLE") - { Modes.push_back(UMODE_INVIS); - } if (pattern && (c = findchan(pattern))) { notice_lang(Config.s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern); - for (CUserList::iterator cuit = c->users.begin(); cuit != c->users.end(); ++cuit) + for (CUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) { UserContainer *uc = *cuit; if (!Modes.empty()) - { - for (std::list::iterator it = Modes.begin(); it != Modes.end(); ++it) - { + for (std::list::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) if (!uc->user->HasMode(*it)) continue; - } - } notice_lang(Config.s_OperServ, u, OPER_USERLIST_RECORD, uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->GetDisplayedHost().c_str()); } @@ -57,7 +50,7 @@ class CommandOSUserList : public Command { notice_lang(Config.s_OperServ, u, OPER_USERLIST_HEADER); - for (user_map::const_iterator uit = UserListByNick.begin(); uit != UserListByNick.end(); ++uit) + for (user_map::const_iterator uit = UserListByNick.begin(), uit_end = UserListByNick.end(); uit != uit_end; ++uit) { User *u2 = uit->second; @@ -68,13 +61,9 @@ class CommandOSUserList : public Command if (!Anope::Match(mask, pattern, false)) continue; if (!Modes.empty()) - { - for (std::list::iterator it = Modes.begin(); it != Modes.end(); ++it) - { + for (std::list::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) if (!u2->HasMode(*it)) continue; - } - } } notice_lang(Config.s_OperServ, u, OPER_USERLIST_RECORD, u2->nick.c_str(), u2->GetIdent().c_str(), u2->GetDisplayedHost().c_str()); } diff --git a/src/core/ss_main.cpp b/src/core/ss_main.cpp index dc83c6e58..a48b77855 100644 --- a/src/core/ss_main.cpp +++ b/src/core/ss_main.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ #include "module.h" @@ -53,10 +51,8 @@ class SSMain : public Module { if (statserv) { - for (std::map::iterator it = statserv->Commands.begin(); it != statserv->Commands.end(); ++it) - { + for (std::map::iterator it = statserv->Commands.begin(), it_end = statserv->Commands.end(); it != it_end; ++it) this->DelCommand(statserv, it->second); - } ircdproto->SendQuit(statserv, "Quit due to module unload."); delete statserv; diff --git a/src/modules/cs_appendtopic.cpp b/src/modules/cs_appendtopic.cpp index a1c84d0ab..03f20ba6c 100644 --- a/src/modules/cs_appendtopic.cpp +++ b/src/modules/cs_appendtopic.cpp @@ -12,8 +12,8 @@ * Send bug reports to the Anope Coder instead of the module * author, because any changes since the inclusion into anope * are not supported by the original author. - * */ + /*************************************************************************/ #include "module.h" @@ -41,11 +41,13 @@ /* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ /* ---------------------------------------------------------------------- */ -#define LNG_NUM_STRINGS 3 - -#define LNG_CHAN_HELP 0 -#define LNG_CHAN_HELP_APPENDTOPIC 1 -#define LNG_APPENDTOPIC_SYNTAX 2 +enum +{ + LNG_CHAN_HELP, + LNG_CHAN_HELP_APPENDTOPIC, + LNG_APPENDTOPIC_SYNTAX, + LNG_NUM_STRINGS +}; static Module *me; @@ -96,20 +98,14 @@ class CommandCSAppendTopic : public Command if (!check_access(u, ci, CA_TOPIC)) Alog() << Config.s_ChanServ << ": " << u->GetMask() << " changed topic of " << c->name << " as services admin."; - if (ircd->join2set) + if (ircd->join2set && whosends(ci) == ChanServ) { - if (whosends(ci) == ChanServ) - { - ChanServ->Join(c); - ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ); // XXX - } + ChanServ->Join(c); + ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ); // XXX } ircdproto->SendTopic(whosends(ci), c, u->nick.c_str(), topic); - if (ircd->join2set) - { - if (whosends(ci) == ChanServ) - ChanServ->Part(c); - } + if (ircd->join2set && whosends(ci) == ChanServ) + ChanServ->Part(c); } return MOD_CONT; } diff --git a/src/modules/cs_enforce.cpp b/src/modules/cs_enforce.cpp index a3be24c7a..c4cfbecc9 100644 --- a/src/modules/cs_enforce.cpp +++ b/src/modules/cs_enforce.cpp @@ -17,14 +17,16 @@ #define AUTHOR "Anope" -#define LNG_NUM_STRINGS 6 - -#define LNG_CHAN_HELP 0 -#define LNG_ENFORCE_SYNTAX 1 -#define LNG_CHAN_HELP_ENFORCE 2 -#define LNG_CHAN_HELP_ENFORCE_R_ENABLED 3 -#define LNG_CHAN_HELP_ENFORCE_R_DISABLED 4 -#define LNG_CHAN_RESPONSE 5 +enum +{ + LNG_CHAN_HELP, + LNG_ENFORCE_SYNTAX, + LNG_CHAN_HELP_ENFORCE, + LNG_CHAN_HELP_ENFORCE_R_ENABLED, + LNG_CHAN_HELP_ENFORCE_R_DISABLED, + LNG_CHAN_RESPONSE, + LNG_NUM_STRINGS +}; static Module *me; @@ -71,7 +73,7 @@ class CommandCSEnforce : public Command hadsecureops = true; } - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -79,10 +81,7 @@ class CommandCSEnforce : public Command } if (hadsecureops) - { ci->UnsetFlag(CI_SECUREOPS); - } - } void DoRestricted(Channel *c) @@ -101,7 +100,7 @@ class CommandCSEnforce : public Command if (ci->levels[CA_NOJOIN] < 0) ci->levels[CA_NOJOIN] = 0; - for (CUserList::iterator it = c->users.begin(); it != c->users.end();) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { UserContainer *uc = *it++; @@ -128,18 +127,16 @@ class CommandCSEnforce : public Command Alog(LOG_DEBUG) << "[cs_enforce] Enforcing mode +R on " << c->name; - for (CUserList::iterator it = c->users.begin(); it != c->users.end();) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { UserContainer *uc = *it++; - + if (!uc->user->IsIdentified()) { get_idealban(ci, uc->user, mask, sizeof(mask)); reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); if (!c->HasMode(CMODE_REGISTERED)) - { c->SetMode(NULL, CMODE_BAN, mask); - } c->Kick(NULL, uc->user, "%s", reason); } } diff --git a/src/modules/cs_tban.cpp b/src/modules/cs_tban.cpp index 88e541ac8..844606222 100644 --- a/src/modules/cs_tban.cpp +++ b/src/modules/cs_tban.cpp @@ -12,7 +12,6 @@ * Send bug reports to the Anope Coder instead of the module * author, because any changes since the inclusion into anope * are not supported by the original author. - * */ /*************************************************************************/ @@ -29,11 +28,14 @@ void mAddLanguages(); static Module *me = NULL; -#define LANG_NUM_STRINGS 4 -#define TBAN_HELP 0 -#define TBAN_SYNTAX 1 -#define TBAN_HELP_DETAIL 2 -#define TBAN_RESPONSE 3 +enum +{ + TBAN_HELP, + TBAN_SYNTAX, + TBAN_HELP_DETAIL, + TBAN_RESPONSE, + LANG_NUM_STRINGS +}; class CommandCSTBan : public Command { @@ -57,14 +59,12 @@ class CommandCSTBan : public Command else if (!(u2 = finduser(nick))) notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick); else - { if (canBanUser(c, u, u2)) { get_idealban(c->ci, u2, mask, sizeof(mask)); addBan(c, dotime(time), mask); mySendResponse(u, chan, mask, time); } - } return MOD_CONT; } @@ -179,9 +179,7 @@ class TempBan : public CallBack Channel *c; if ((c = findchan(chan)) && c->ci) - { c->RemoveMode(NULL, CMODE_BAN, mask); - } } }; diff --git a/src/modules/hs_request.cpp b/src/modules/hs_request.cpp index 05e5969f2..5399140bc 100644 --- a/src/modules/hs_request.cpp +++ b/src/modules/hs_request.cpp @@ -25,29 +25,31 @@ int HSRequestMemoOper = 0; int HSRequestMemoSetters = 0; /* Language defines */ -#define LNG_NUM_STRINGS 21 - -#define LNG_REQUEST_SYNTAX 0 -#define LNG_REQUESTED 1 -#define LNG_REQUEST_WAIT 2 -#define LNG_REQUEST_MEMO 3 -#define LNG_ACTIVATE_SYNTAX 4 -#define LNG_ACTIVATED 5 -#define LNG_ACTIVATE_MEMO 6 -#define LNG_REJECT_SYNTAX 7 -#define LNG_REJECTED 8 -#define LNG_REJECT_MEMO 9 -#define LNG_REJECT_MEMO_REASON 10 -#define LNG_NO_REQUEST 11 -#define LNG_HELP 12 -#define LNG_HELP_SETTER 13 -#define LNG_HELP_REQUEST 14 -#define LNG_HELP_ACTIVATE 15 -#define LNG_HELP_ACTIVATE_MEMO 16 -#define LNG_HELP_REJECT 17 -#define LNG_HELP_REJECT_MEMO 18 -#define LNG_WAITING_SYNTAX 19 -#define LNG_HELP_WAITING 20 +enum +{ + LNG_REQUEST_SYNTAX, + LNG_REQUESTED, + LNG_REQUEST_WAIT, + LNG_REQUEST_MEMO, + LNG_ACTIVATE_SYNTAX, + LNG_ACTIVATED, + LNG_ACTIVATE_MEMO, + LNG_REJECT_SYNTAX, + LNG_REJECTED, + LNG_REJECT_MEMO, + LNG_REJECT_MEMO_REASON, + LNG_NO_REQUEST, + LNG_HELP, + LNG_HELP_SETTER, + LNG_HELP_REQUEST, + LNG_HELP_ACTIVATE, + LNG_HELP_ACTIVATE_MEMO, + LNG_HELP_REJECT, + LNG_HELP_REJECT_MEMO, + LNG_WAITING_SYNTAX, + LNG_HELP_WAITING, + LNG_NUM_STRINGS +}; void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time); int my_isvalidchar(const char c); @@ -107,9 +109,7 @@ class CommandHSRequest : public Command return MOD_CONT; } else - { for (s = vIdent; *s; ++s) - { if (!my_isvalidchar(*s)) { notice_lang(Config.s_HostServ, u, HOST_SET_IDENT_ERROR); @@ -118,8 +118,6 @@ class CommandHSRequest : public Command delete [] hostmask; return MOD_CONT; } - } - } if (!ircd->vident) { notice_lang(Config.s_HostServ, u, HOST_NO_VIDENT); @@ -157,20 +155,17 @@ class CommandHSRequest : public Command if ((na = findnick(nick))) { - if (HSRequestMemoOper || HSRequestMemoSetters) + if ((HSRequestMemoOper || HSRequestMemoSetters) && Config.MSSendDelay > 0 && u && u->lastmemosend + Config.MSSendDelay > now) { - if (Config.MSSendDelay > 0 && u && u->lastmemosend + Config.MSSendDelay > now) + me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_WAIT, Config.MSSendDelay); + u->lastmemosend = now; + if (vIdent) { - me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_WAIT, Config.MSSendDelay); - u->lastmemosend = now; - if (vIdent) - { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; - return MOD_CONT; + delete [] vIdent; + delete [] rawhostmask; } + delete [] hostmask; + return MOD_CONT; } my_add_host_request(const_cast(nick), vIdent, hostmask, const_cast(u->nick.c_str()), now); @@ -328,7 +323,7 @@ class HSListBase : public Command unsigned display_counter = 0; tm *tm; - for (std::map::iterator it = Requests.begin(); it != Requests.end(); ++it) + for (std::map::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) { HostRequest *hr = it->second; if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax) @@ -721,7 +716,7 @@ class HSRequest : public Module void OnDatabaseWrite(void (*Write)(const std::string &)) { - for (std::map::iterator it = Requests.begin(); it != Requests.end(); ++it) + for (std::map::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) { HostRequest *hr = it->second; std::stringstream buf; @@ -779,7 +774,7 @@ void req_send_memos(User *u, char *vIdent, char *vHost) { int z = 2; char host[BUFSIZE]; - std::list >::iterator it; + std::list >::iterator it, it_end; if (vIdent) snprintf(host, sizeof(host), "%s@%s", vIdent, vHost); @@ -787,13 +782,11 @@ void req_send_memos(User *u, char *vIdent, char *vHost) snprintf(host, sizeof(host), "%s", vHost); if (HSRequestMemoOper == 1) - { - for (it = Config.Opers.begin(); it != Config.Opers.end(); ++it) + for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) { ci::string nick = it->first; my_memo_lang(u, nick.c_str(), z, LNG_REQUEST_MEMO, host); } - } if (HSRequestMemoSetters == 1) { /* Needs to be rethought because of removal of HostSetters in favor of opertype priv -- CyberBotX diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h index f2885408f..34ae50931 100644 --- a/src/modules/mysql/db_mysql.h +++ b/src/modules/mysql/db_mysql.h @@ -1,3 +1,6 @@ +#ifndef DB_MYSQL_H +#define DB_MYSQL_H + #include "module.h" struct NickAliasFlagInfo @@ -117,15 +120,15 @@ MemoFlagInfo MemoFlags[] = { #define MYSQLPP_MYSQL_HEADERS_BURIED #include -inline std::string SQLAssign(const mysqlpp::String& s) { return s.c_str(); } +inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); } class DBMySQL; static DBMySQL *me; -bool ExecuteQuery(mysqlpp::Query& query) +bool ExecuteQuery(mysqlpp::Query &query) { Alog(LOG_DEBUG) << "MySQL: " << query.str(); - + if (!query.execute()) { Alog() << "MySQL: error executing query: " << query.error(); @@ -135,15 +138,13 @@ bool ExecuteQuery(mysqlpp::Query& query) return true; } -mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query& query) +mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query &query) { Alog(LOG_DEBUG) << "MySQL: " << query.str(); mysqlpp::StoreQueryResult result = query.store(); if (!result) - { Alog() << "MySQL: error executing query: " << query.error(); - } return result; } @@ -195,7 +196,7 @@ class DBMySQL : public Module delete Con; throw ModuleException(Error.c_str()); } - + mysqlpp::Query query(Con); query << "SET NAMES 'utf8'"; ExecuteQuery(query); @@ -208,3 +209,4 @@ class DBMySQL : public Module } }; +#endif // DB_MYSQL_H diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 2313edd37..2cc6ab6df 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -75,7 +75,7 @@ class SQLTimer : public Timer if (qres && qres.num_rows()) { - for (size_t i = 0; i < qres.num_rows(); ++i) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) { User *u; NickAlias *na = NULL; @@ -149,7 +149,7 @@ class DBMySQLExecute : public DBMySQL { _SQLTimer = new SQLTimer(); } - + ~DBMySQLExecute() { delete _SQLTimer; diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 3c5fb359a..3ffc82366 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -34,8 +34,7 @@ static void LoadDatabase() qres = StoreQuery(query); if (qres) - { - for (size_t i = 0; i < qres.num_rows(); ++i) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) { NickCore *nc = new NickCore(SQLAssign(qres[i]["display"])); nc->pass = SQLAssign(qres[i]["pass"]); @@ -51,28 +50,20 @@ static void LoadDatabase() spacesepstream sep(SQLAssign(qres[i]["flags"])); std::string buf; while (sep.GetToken(buf)) - { for (int j = 0; NickCoreFlags[j].Flag != -1; ++j) - { if (NickCoreFlags[j].Name == buf) - { nc->SetFlag(NickCoreFlags[j].Flag); - } - } - } nc->language = atoi(qres[i]["language"].c_str()); nc->channelcount = atoi(qres[i]["channelcount"].c_str()); nc->memos.memomax = atoi(qres[i]["memomax"].c_str()); } - } query << "SELECT * FROM `anope_ns_access`"; qres = StoreQuery(query); if (qres) - { - for (size_t i = 0; i < qres.num_rows(); ++i) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) { NickCore *nc = findcore(qres[i]["display"].c_str()); if (!nc) @@ -83,14 +74,12 @@ static void LoadDatabase() nc->AddAccess(SQLAssign(qres[i]["access"])); } - } query << "SELECT * FROM `anope_ns_core_metadata`"; qres = StoreQuery(query); if (qres) - { - for (size_t i = 0; i < qres.num_rows(); ++i) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) { NickCore *nc = findcore(qres[i]["display"].c_str()); if (!nc) @@ -102,14 +91,12 @@ static void LoadDatabase() std::vector Params = MakeVector(SQLAssign(qres[i]["value"])); FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), Params)); } - } query << "SELECT * FROM `anope_ns_alias`"; qres = StoreQuery(query); if (qres) - { - for (size_t i = 0; i < qres.num_rows(); ++i) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) { NickCore *nc = findcore(qres[i]["display"].c_str()); if (!nc) @@ -128,24 +115,16 @@ static void LoadDatabase() spacesepstream