]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Replace some C-isms with C++-isms.
authorPeter Powell <petpow@saberuk.com>
Mon, 6 May 2013 10:49:50 +0000 (11:49 +0100)
committerPeter Powell <petpow@saberuk.com>
Wed, 15 May 2013 02:32:56 +0000 (03:32 +0100)
* 'const char*' to 'const std::string&'.
* snprintf to std::string concatenation.
* Replace duplicated OneOfMatches with InspIRCd::MatchMask.

27 files changed:
include/channels.h
include/hashcomp.h
include/inspircd.h
src/channels.cpp
src/commands/cmd_kick.cpp
src/commands/cmd_oper.cpp
src/commands/cmd_stats.cpp
src/commands/cmd_time.cpp
src/configreader.cpp
src/modmanager_dynamic.cpp
src/modules/extra/m_ldapoper.cpp
src/modules/m_chanhistory.cpp
src/modules/m_chanlog.cpp
src/modules/m_cloaking.cpp
src/modules/m_customtitle.cpp
src/modules/m_dnsbl.cpp
src/modules/m_messageflood.cpp
src/modules/m_namedmodes.cpp
src/modules/m_sqloper.cpp
src/modules/m_sslinfo.cpp
src/server.cpp
src/socketengines/socketengine_poll.cpp
src/usermanager.cpp
src/userprocess.cpp
src/users.cpp
src/wildcard.cpp
src/xline.cpp

index 2b2681eace1fc43e0b39f6e570704fdb3d08ef83..56e1a5a49e9660c677fc2dc18aed5307dbe5aa85 100644 (file)
@@ -176,7 +176,7 @@ class CoreExport Channel : public Extensible, public InviteBase
         * @param user The user being kicked (must be on this channel)
         * @param reason The reason for the kick
         */
-       void KickUser(User *src, User *user, const char* reason);
+       void KickUser(User *src, User *user, const std::string& reason);
 
        /** Part a user from this channel with the given reason.
         * If the reason field is NULL, no reason will be sent.
index 3c00844bebb765364d8657e62d3e322dbb46229e..3963f96e7b89fb347b0e46236b73bd7c153296f8 100644 (file)
@@ -284,7 +284,7 @@ namespace irc
                 * mode changes to be obtained.
                 */
                int GetStackedLine(std::vector<std::string> &result, int max_line_size = 360);
-               
+
        };
 
        /** irc::tokenstream reads a string formatted as per RFC1459 and RFC2812.
index b0cd8f675a60d722e2d40485b3b41794ae6fafd3..c37658515531ee236e071ce296fe092d4ec9449a 100644 (file)
@@ -597,7 +597,7 @@ class CoreExport InspIRCd
         * @param map The character map to use when matching.
         */
        static bool Match(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
-       static bool Match(const  char *str, const char *mask, unsigned const char *map = NULL);
+       static bool Match(const char *str, const char *mask, unsigned const char *map = NULL);
 
        /** Match two strings using pattern matching, optionally, with a map
         * to check case against (may be NULL). If map is null, match will be case insensitive.
@@ -607,7 +607,14 @@ class CoreExport InspIRCd
         * @param map The character map to use when matching.
         */
        static bool MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map = NULL);
-       static bool MatchCIDR(const  char *str, const char *mask, unsigned const char *map = NULL);
+       static bool MatchCIDR(const char *str, const char *mask, unsigned const char *map = NULL);
+
+       /** Matches a hostname and IP against a space delimited list of hostmasks.
+        * @param masks The space delimited masks to match against.
+        * @param hostname The hostname to try and match.
+        * @param ipaddr The IP address to try and match.
+        */
+       static bool MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr);
 
        /** Return true if the given parameter is a valid nick!user\@host mask
         * @param mask A nick!user\@host masak to match against
@@ -683,7 +690,7 @@ class CoreExport InspIRCd
        /** Returns the full version string of this ircd
         * @return The version string
         */
-       std::string GetVersionString(bool rawversion = false);
+       std::string GetVersionString(bool getFullVersion = false);
 
        /** Attempt to write the process id to a given file
         * @param filename The PID file to attempt to write to
index 9e9ad670aef0fc1ed77a1c90a5230058d9bc86cc..39ff8d59cce60fcddd44cf64de11b39b866bb1a6 100644 (file)
@@ -472,10 +472,9 @@ bool Channel::CheckBan(User* user, const std::string& mask)
        if (at == std::string::npos)
                return false;
 
-       char tomatch[MAXBUF];
-       snprintf(tomatch, MAXBUF, "%s!%s", user->nick.c_str(), user->ident.c_str());
+       const std::string nickIdent = user->nick + "!" + user->ident;
        std::string prefix = mask.substr(0, at);
-       if (InspIRCd::Match(tomatch, prefix, NULL))
+       if (InspIRCd::Match(nickIdent, prefix, NULL))
        {
                std::string suffix = mask.substr(at + 1);
                if (InspIRCd::Match(user->host, suffix, NULL) ||
@@ -532,9 +531,9 @@ void Channel::PartUser(User *user, std::string &reason)
        this->DelUser(user);
 }
 
-void Channel::KickUser(User *src, User *user, const char* reason)
+void Channel::KickUser(User *src, User *user, const std::string& reason)
 {
-       if (!src || !user || !reason)
+       if (!src || !user)
                return;
 
        Membership* memb = GetUser(user);
@@ -585,7 +584,7 @@ void Channel::KickUser(User *src, User *user, const char* reason)
                CUList except_list;
                FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
 
-               WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason);
+               WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), user->nick.c_str(), reason.c_str());
 
                user->chans.erase(this);
                this->RemoveAllPrefixes(user);
@@ -611,18 +610,15 @@ void Channel::WriteChannel(User* user, const char* text, ...)
 
 void Channel::WriteChannel(User* user, const std::string &text)
 {
-       char tb[MAXBUF];
-
        if (!user)
                return;
 
-       snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
-       std::string out = tb;
+       const std::string message = ":" + user->GetFullHost() + " " + text;
 
        for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
        {
                if (IS_LOCAL(i->first))
-                       i->first->Write(out);
+                       i->first->Write(message);
        }
 }
 
@@ -643,15 +639,12 @@ void Channel::WriteChannelWithServ(const std::string& ServName, const char* text
 
 void Channel::WriteChannelWithServ(const std::string& ServName, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s", ServName.empty() ? ServerInstance->Config->ServerName.c_str() : ServName.c_str(), text.c_str());
-       std::string out = tb;
+       const std::string message = ":" + (ServName.empty() ? ServerInstance->Config->ServerName : ServName) + " " + text;
 
        for (UserMembIter i = userlist.begin(); i != userlist.end(); i++)
        {
                if (IS_LOCAL(i->first))
-                       i->first->Write(out);
+                       i->first->Write(message);
        }
 }
 
@@ -691,12 +684,8 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList
 
 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName.c_str() : user->GetFullHost().c_str(), text.c_str());
-       std::string out = tb;
-
-       this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
+       const std::string message = ":" + (serversource ? ServerInstance->Config->ServerName : user->GetFullHost()) + " " + text;
+       this->RawWriteAllExcept(user, serversource, status, except_list, message);
 }
 
 void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
index 3c5fb00527ae8e94d73e72b6f16cb8a35e4c2c1a..87ee1da6d01bb589ce1e871a2b180bdeb91c53cf 100644 (file)
@@ -77,7 +77,7 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
                reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
        }
 
-       c->KickUser(user, u, reason.c_str());
+       c->KickUser(user, u, reason);
 
        return CMD_SUCCESS;
 }
index 1178137197e1e442cc4083e6dd117ef6930ef5f1..15ee9c969f06a959b21457bbbf3cec78192c2a49 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "inspircd.h"
 
-bool OneOfMatches(const char* host, const char* ip, const char* hostlist);
-
 /** Handle /OPER. These command handlers can be reloaded by the core,
  * and handle basic RFC1459 commands. Commands within modules work
  * the same way, however, they can be fully unloaded, where these
@@ -43,30 +41,14 @@ class CommandOper : public SplitCommand
        CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
 };
 
-bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
 {
-       char TheHost[MAXBUF];
-       char TheIP[MAXBUF];
        bool match_login = false;
        bool match_pass = false;
        bool match_hosts = false;
 
-       snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
-       snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString().c_str());
+       const std::string userHost = user->ident + "@" + user->host;
+       const std::string userIP = user->ident + "@" + user->GetIPString();
 
        OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
        if (i != ServerInstance->Config->oper_blocks.end())
@@ -75,7 +57,7 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
                ConfigTag* tag = ifo->oper_block;
                match_login = true;
                match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
-               match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host"));
+               match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
 
                if (match_pass && match_hosts)
                {
index ccf753956f701ab5b3c50aace927299df970ef5e..d9f3c1496070f751faad2bb66d6b94395e1f30d4 100644 (file)
@@ -283,7 +283,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                                double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
                                double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
                                double per = (n_eaten/n_elapsed);
-                               
+
                                char percent[30];
 
                                snprintf(percent, 30, "%03.5f%%", per);
index db452d38173f81c5779f58de84beaa0876009c1d..8c516ac424472cd890173b0a9877cdce71fc39f6 100644 (file)
@@ -50,16 +50,13 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User
 {
        if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
                return CMD_SUCCESS;
-       struct tm* timeinfo;
-       time_t local = ServerInstance->Time();
-
-       timeinfo = localtime(&local);
 
-       char tms[26];
-       snprintf(tms,26,"%s",asctime(timeinfo));
-       tms[24] = 0;
+       time_t local = ServerInstance->Time();
+       struct tm* timeinfo = localtime(&local);
+       const std::string& humanTime = asctime(timeinfo);
 
-       user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),tms);
+       user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),
+               ServerInstance->Config->ServerName.c_str(), humanTime.c_str());
 
        return CMD_SUCCESS;
 }
index dcf4b7162c237dc6df175f507c076f36bc0a6eb9..cd6122b25f36715d77f0f17fb7361fd475c78dc2 100644 (file)
@@ -335,13 +335,13 @@ struct DeprecatedConfig
 {
        /** Tag name. */
        std::string tag;
-       
+
        /** Attribute key. */
        std::string key;
-       
+
        /** Attribute value. */
        std::string value;
-       
+
        /** Reason for deprecation. */
        std::string reason;
 };
@@ -595,14 +595,14 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
                ServerInstance->BindPorts(pl);
                if (pl.size())
                {
-                       errstr << "Not all your client ports could be bound.\nThe following port(s) failed to bind:\n";
+                       errstr << "Not all your client ports could be bound." << std::endl
+                               << "The following port(s) failed to bind:" << std::endl;
 
                        int j = 1;
                        for (FailedPortList::iterator i = pl.begin(); i != pl.end(); i++, j++)
                        {
-                               char buf[MAXBUF];
-                               snprintf(buf, MAXBUF, "%d.   Address: %s   Reason: %s\n", j, i->first.empty() ? "<all>" : i->first.c_str(), i->second.c_str());
-                               errstr << buf;
+                               errstr << j << ".\tAddress: " << (i->first.empty() ? "<all>" : i->first.c_str()) << "\tReason: "
+                                       << i->second << std::endl;
                        }
                }
        }
index a153accbb55b7ec1e59999245b7ab4e727d8b5af..b586976793844028a3dc80a69d1cc31c9f6404f6 100644 (file)
@@ -37,10 +37,9 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
        if (filename.find('/') != std::string::npos)
                return false;
 
-       char modfile[MAXBUF];
-       snprintf(modfile,MAXBUF,"%s/%s",ServerInstance->Config->ModPath.c_str(),filename.c_str());
+       const std::string moduleFile = ServerInstance->Config->ModPath + "/" + filename;
 
-       if (!ServerConfig::FileExists(modfile))
+       if (!ServerConfig::FileExists(moduleFile.c_str()))
        {
                LastModuleError = "Module file could not be found: " + filename;
                ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, LastModuleError);
@@ -55,7 +54,7 @@ bool ModuleManager::Load(const std::string& filename, bool defer)
        }
 
        Module* newmod = NULL;
-       DLLManager* newhandle = new DLLManager(modfile);
+       DLLManager* newhandle = new DLLManager(moduleFile.c_str());
 
        try
        {
index 856e42dc36648295b9f8bbae42d989cbf5f1ee27..f10773ec98411e3349b5a41c841c312c604ff6f3 100644 (file)
 /* $ModDesc: Adds the ability to authenticate opers via LDAP */
 /* $LinkerFlags: -lldap */
 
-// Duplicated code, also found in cmd_oper and m_sqloper
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 struct RAIILDAPString
 {
        char *str;
@@ -97,7 +82,7 @@ class ModuleLDAPAuth : public Module
 
                std::string acceptedhosts = tag->getString("host");
                std::string hostname = user->ident + "@" + user->host;
-               if (!OneOfMatches(hostname.c_str(), user->GetIPString().c_str(), acceptedhosts))
+               if (!InspIRCd::MatchMask(acceptedhosts, hostname, user->GetIPString()))
                        return false;
 
                if (!LookupOper(opername, inputpass))
index 3ee823b4a99c82d906036df2b00b8b6d044a37c4..6633e9582f7b3d284e61f880afedc4c867396f54 100644 (file)
@@ -133,7 +133,7 @@ class ModuleChanHistory : public Module
                sendnotice = tag->getBool("notice", true);
        }
 
-       void OnUserMessage(User* user,void* dest,int target_type, const std::string &text, char status, const CUList&)
+       void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList&)
        {
                if (target_type == TYPE_CHANNEL && status == 0)
                {
@@ -141,10 +141,8 @@ class ModuleChanHistory : public Module
                        HistoryList* list = m.ext.get(c);
                        if (list)
                        {
-                               char buf[MAXBUF];
-                               snprintf(buf, MAXBUF, ":%s PRIVMSG %s :%s",
-                                       user->GetFullHost().c_str(), c->name.c_str(), text.c_str());
-                               list->lines.push_back(HistoryItem(buf));
+                               const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + text;
+                               list->lines.push_back(HistoryItem(line));
                                if (list->lines.size() > list->maxlen)
                                        list->lines.pop_front();
                        }
index 4bfce210837a8d9c331cff3cda365892251df3d3..0f53ceedfa93df3c14982c1ec2ca149cee0c83a6 100644 (file)
@@ -73,16 +73,15 @@ class ModuleChanLog : public Module
                if (itpair.first == itpair.second)
                        return MOD_RES_PASSTHRU;
 
-               char buf[MAXBUF];
-               snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
+               const std::string snotice = "\2" + desc + "\2: " + msg;
 
                for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
                {
                        Channel *c = ServerInstance->FindChan(it->second);
                        if (c)
                        {
-                               c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
-                               ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
+                               c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), snotice.c_str());
+                               ServerInstance->PI->SendChannelPrivmsg(c, 0, snotice);
                        }
                }
 
index 691b61138f9cf0400bd0821dc76ce9457bb6837e..31b361b6f8e169f03db1b30e85edc2df94ab5691 100644 (file)
@@ -295,9 +295,8 @@ class ModuleCloaking : public Module
                /* Check if they have a cloaked host, but are not using it */
                if (cloak && *cloak != user->dhost)
                {
-                       char cmask[MAXBUF];
-                       snprintf(cmask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), cloak->c_str());
-                       if (InspIRCd::Match(cmask,mask))
+                       const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak;
+                       if (InspIRCd::Match(cloakMask, mask))
                                return MOD_RES_DENY;
                }
                return MOD_RES_PASSTHRU;
index 1fc49190b653d0c47938408fb4d91acb71c9656c..6b100605e71cdefe76e44094b3243ecab9539daa 100644 (file)
@@ -35,27 +35,10 @@ class CommandTitle : public Command
                syntax = "<user> <password>";
        }
 
-       bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
-       {
-               std::stringstream hl(hostlist);
-               std::string xhost;
-               while (hl >> xhost)
-               {
-                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-                       {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        CmdResult Handle(const std::vector<std::string> &parameters, User* user)
        {
-               char TheHost[MAXBUF];
-               char TheIP[MAXBUF];
-
-               snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
-               snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString().c_str());
+               const std::string userHost = user->ident + "@" + user->host;
+               const std::string userIP = user->ident + "@" + user->GetIPString();
 
                ConfigTagList tags = ServerInstance->Config->ConfTags("title");
                for (ConfigIter i = tags.first; i != tags.second; ++i)
@@ -67,7 +50,8 @@ class CommandTitle : public Command
                        std::string title = i->second->getString("title");
                        std::string vhost = i->second->getString("vhost");
 
-                       if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+                       if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
+                               InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
                        {
                                ctitle.set(user, title);
 
index 9e0b89fc398b0787eb5648d64c17dd862aac7e07..a0ff5b84a5b81a281e7549377018a6949aa1b2b3 100644 (file)
@@ -361,16 +361,12 @@ class ModuleDNSBL : public Module
                        ServerInstance->Logs->Log("m_dnsbl", LOG_DEBUG, "User has no connect class in OnSetUserIP");
 
                unsigned char a, b, c, d;
-               char reversedipbuf[128];
-               std::string reversedip;
-
                d = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 24) & 0xFF;
                c = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 16) & 0xFF;
                b = (unsigned char) (user->client_sa.in4.sin_addr.s_addr >> 8) & 0xFF;
                a = (unsigned char) user->client_sa.in4.sin_addr.s_addr & 0xFF;
 
-               snprintf(reversedipbuf, 128, "%d.%d.%d.%d", d, c, b, a);
-               reversedip = std::string(reversedipbuf);
+               const std::string reversedip = ConvToStr(d) + "." + ConvToStr(c) + "." + ConvToStr(b) + "." + ConvToStr(a);
 
                countExt.set(user, DNSBLConfEntries.size());
 
index 9ff17924d1c38bbb154c4a959fa151824894a221..a367ecda37c974b03add9431675badf89be0e954 100644 (file)
@@ -160,10 +160,10 @@ class ModuleMsgFlood : public Module
                                        ServerInstance->SendGlobalMode(parameters, ServerInstance->FakeClient);
                                }
 
-                               char kickmessage[MAXBUF];
-                               snprintf(kickmessage, MAXBUF, "Channel flood triggered (limit is %u lines in %u secs)", f->lines, f->secs);
+                               const std::string kickMessage = "Channel flood triggered (limit is " + ConvToStr(f->lines) +
+                                       " in " + ConvToStr(f->secs) + " secs)";
 
-                               dest->KickUser(ServerInstance->FakeClient, user, kickmessage);
+                               dest->KickUser(ServerInstance->FakeClient, user, kickMessage);
 
                                return MOD_RES_DENY;
                        }
index 4db1f70b92c78e9a0d5da781f99c0114a0eec90e..7d0d3a040a7af2df6530658cf773f01aa5eb0101 100644 (file)
@@ -35,9 +35,8 @@ static void DisplayList(User* user, Channel* channel)
                if (mh->GetNumParams(true))
                        items << " " << channel->GetModeParameter(letter);
        }
-       char pfx[MAXBUF];
-       snprintf(pfx, MAXBUF, ":%s 961 %s %s", ServerInstance->Config->ServerName.c_str(), user->nick.c_str(), channel->name.c_str());
-       user->SendText(std::string(pfx), items);
+       const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name;
+       user->SendText(line, items);
        user->WriteNumeric(960, "%s %s :End of mode list", user->nick.c_str(), channel->name.c_str());
 }
 
index b5b020d9d6807a79a9e081d8446768a262141566..87ab7d46f32f54a88199ff979127e1a23a7665d3 100644 (file)
 
 /* $ModDesc: Allows storage of oper credentials in an SQL table */
 
-static bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
-       std::stringstream hl(hostlist);
-       std::string xhost;
-       while (hl >> xhost)
-       {
-               if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
 class OpMeQuery : public SQLQuery
 {
  public:
@@ -106,7 +92,7 @@ class OpMeQuery : public SQLQuery
 
                hostname.append("@").append(user->host);
 
-               if (OneOfMatches(hostname.c_str(), user->GetIPString().c_str(), pattern.c_str()))
+               if (InspIRCd::MatchMask(pattern, hostname, user->GetIPString()))
                {
                        /* Opertype and host match, looks like this is it. */
 
index 7c8cc12f233468f80981cd6028a81b0b8141258d..f0f4fc155d7eb9d2452851f46093170d08cdfe66 100644 (file)
@@ -158,20 +158,6 @@ class ModuleSSLInfo : public Module
                }
        }
 
-       bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
-       {
-               std::stringstream hl(hostlist);
-               std::string xhost;
-               while (hl >> xhost)
-               {
-                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-                       {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
        {
                if ((command == "OPER") && (validated))
index 6790b45e77715a37020345b72db58948635c90f9..c2068d75bb169e4e084f30734c5848137afba6e7 100644 (file)
@@ -66,17 +66,11 @@ void RehashHandler::Call(const std::string &reason)
        }
 }
 
-std::string InspIRCd::GetVersionString(bool operstring)
+std::string InspIRCd::GetVersionString(bool getFullVersion)
 {
-       char versiondata[MAXBUF];
-       if (operstring)
-       {
-               std::string sename = SE->GetName();
-               snprintf(versiondata,MAXBUF,"%s %s :%s [%s,%s,%s]",VERSION, Config->ServerName.c_str(), SYSTEM,REVISION, sename.c_str(), Config->sid.c_str());
-       }
-       else
-               snprintf(versiondata,MAXBUF,"%s %s :%s",BRANCH,Config->ServerName.c_str(),Config->CustomVersion.c_str());
-       return versiondata;
+       if (getFullVersion)
+               return VERSION " " + Config->ServerName + " :" SYSTEM " [" REVISION "," + SE->GetName() + "," + Config->sid + "]";
+       return BRANCH " " + Config->ServerName + " :" + Config->CustomVersion;
 }
 
 const char InspIRCd::LogHeader[] =
index fd3360c36f058a374a1f6a84321b0c2ac0f202ed..1080aa1324f1f45a5ff749d288eda89a53953301 100644 (file)
@@ -272,7 +272,7 @@ int PollEngine::DispatchEvents()
                                        // whoops, deleted out from under us
                                        continue;
                        }
-                       
+
                        if (events[index].revents & POLLOUT)
                        {
                                int mask = eh->GetEventMask();
index ba1f5f9e6b34f4b9db6f99b9617a0a426c53e3dc..8ed87a338015230a2da8ddb6aaa036eacb248cca 100644 (file)
@@ -326,18 +326,17 @@ void UserManager::ServerNoticeAll(const char* text, ...)
                return;
 
        char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
        va_list argsPtr;
        va_start (argsPtr, text);
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
+       const std::string message = "NOTICE $" + ServerInstance->Config->ServerName + " :" + textbuffer;
 
        for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
        {
                User* t = *i;
-               t->WriteServ(std::string(formatbuffer));
+               t->WriteServ(message);
        }
 }
 
@@ -347,18 +346,17 @@ void UserManager::ServerPrivmsgAll(const char* text, ...)
                return;
 
        char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
        va_list argsPtr;
        va_start (argsPtr, text);
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer);
+       const std::string message = "PRIVMSG $" + ServerInstance->Config->ServerName + " :" + textbuffer;
 
        for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++)
        {
                User* t = *i;
-               t->WriteServ(std::string(formatbuffer));
+               t->WriteServ(message);
        }
 }
 
index c78f0bb0bbccb16ea9f52c20257751b457f9f00d..40fd35c5901e6fc8f25fd2af0a229cd52b945740 100644 (file)
@@ -66,8 +66,7 @@ void InspIRCd::DoBackgroundUserStuff()
                                        if (!curr->lastping)
                                        {
                                                time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
-                                               char message[MAXBUF];
-                                               snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
+                                               const std::string message = "Ping timeout: " + ConvToStr(time) + (time == 1 ? " seconds" : " second");
                                                curr->lastping = 1;
                                                curr->nping = Time() + curr->MyClass->GetPingTime();
                                                this->Users->QuitUser(curr, message);
index 7e95dc0121740618e2f70906a6542ccf475044ae..9f4060968e61792847619598e76c1e586445db8f 100644 (file)
@@ -1081,11 +1081,8 @@ void User::WriteNumeric(unsigned int numeric, const std::string &text)
 
 void User::WriteFrom(User *user, const std::string &text)
 {
-       char tb[MAXBUF];
-
-       snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(),text.c_str());
-
-       this->Write(std::string(tb));
+       const std::string message = ":" + user->GetFullHost() + " " + text;
+       this->Write(message);
 }
 
 
@@ -1199,18 +1196,13 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
 
 void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
 {
-       char tb1[MAXBUF];
-       char tb2[MAXBUF];
-
        if (this->registered != REG_ALL)
                return;
 
        already_sent_t uniq_id = ++LocalUser::already_sent_id;
 
-       snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
-       snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
-       std::string out1 = tb1;
-       std::string out2 = tb2;
+       const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
+       const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
 
        UserChanList include_c(chans);
        std::map<User*,bool> exceptions;
@@ -1224,7 +1216,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
                {
                        u->already_sent = uniq_id;
                        if (i->second)
-                               u->Write(u->IsOper() ? out2 : out1);
+                               u->Write(u->IsOper() ? operMessage : normalMessage);
                }
        }
        for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
@@ -1236,7 +1228,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
                        if (u && !u->quitting && (u->already_sent != uniq_id))
                        {
                                u->already_sent = uniq_id;
-                               u->Write(u->IsOper() ? out2 : out1);
+                               u->Write(u->IsOper() ? operMessage : normalMessage);
                        }
                }
        }
@@ -1341,8 +1333,6 @@ bool User::ChangeName(const char* gecos)
 
 void User::DoHostCycle(const std::string &quitline)
 {
-       char buffer[MAXBUF];
-
        if (!ServerInstance->Config->CycleHosts)
                return;
 
@@ -1373,18 +1363,17 @@ void User::DoHostCycle(const std::string &quitline)
        for (UCListIter v = include_c.begin(); v != include_c.end(); ++v)
        {
                Channel* c = *v;
-               snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
-               std::string joinline(buffer);
                Membership* memb = c->GetUser(this);
-               std::string modeline = memb->modes;
-               if (modeline.length() > 0)
+               const std::string joinline = ":" + GetFullHost() + " JOIN " + c->name;
+               std::string modeline;
+
+               if (!memb->modes.empty())
                {
-                       for(unsigned int i=0; i < memb->modes.length(); i++)
+                       modeline = ":" + (ServerInstance->Config->CycleHostsFromUser ? GetFullHost() : ServerInstance->Config->ServerName)
+                               + " MODE " + c->name + " +" + memb->modes;
+
+                       for (size_t i = 0; i < memb->modes.length(); i++)
                                modeline.append(" ").append(nick);
-                       snprintf(buffer, MAXBUF, ":%s MODE %s +%s",
-                               ServerInstance->Config->CycleHostsFromUser ? GetFullHost().c_str() : ServerInstance->Config->ServerName.c_str(),
-                               c->name.c_str(), modeline.c_str());
-                       modeline = buffer;
                }
 
                const UserMembList *ulist = c->GetUsers();
@@ -1402,7 +1391,7 @@ void User::DoHostCycle(const std::string &quitline)
                                u->already_sent = seen_id;
                        }
                        u->Write(joinline);
-                       if (modeline.length() > 0)
+                       if (!memb->modes.empty())
                                u->Write(modeline);
                }
        }
@@ -1459,20 +1448,18 @@ bool User::ChangeIdent(const char* newident)
 void User::SendAll(const char* command, const char* text, ...)
 {
        char textbuffer[MAXBUF];
-       char formatbuffer[MAXBUF];
        va_list argsPtr;
 
        va_start(argsPtr, text);
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       snprintf(formatbuffer,MAXBUF,":%s %s $* :%s", this->GetFullHost().c_str(), command, textbuffer);
-       std::string fmt = formatbuffer;
+       const std::string message = ":" + this->GetFullHost() + " " + command + " $* :" + textbuffer;
 
        for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
                if ((*i)->registered == REG_ALL)
-                       (*i)->Write(fmt);
+                       (*i)->Write(message);
        }
 }
 
index eb9151293d8e185747de8ba4a3caaa729a5b1588..b64d2d6e89b633f21e30e8748a6d5f48f038a8b2 100644 (file)
@@ -78,7 +78,7 @@ static bool match_internal(const unsigned char *str, const unsigned char *mask,
  * Below here is all wrappers around match_internal
  ********************************************************************/
 
-CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::Match(const std::string &str, const std::string &mask, unsigned const char *map)
 {
        if (!map)
                map = national_case_insensitive_map;
@@ -86,14 +86,14 @@ CoreExport bool InspIRCd::Match(const std::string &str, const std::string &mask,
        return match_internal((const unsigned char *)str.c_str(), (const unsigned char *)mask.c_str(), map);
 }
 
-CoreExport bool InspIRCd::Match(const  char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::Match(const char *str, const char *mask, unsigned const char *map)
 {
        if (!map)
                map = national_case_insensitive_map;
        return match_internal((const unsigned char *)str, (const unsigned char *)mask, map);
 }
 
-CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const std::string &str, const std::string &mask, unsigned const char *map)
 {
        if (irc::sockets::MatchCIDR(str, mask, true))
                return true;
@@ -105,7 +105,7 @@ CoreExport bool InspIRCd::MatchCIDR(const std::string &str, const std::string &m
        return InspIRCd::Match(str, mask, map);
 }
 
-CoreExport bool InspIRCd::MatchCIDR(const  char *str, const char *mask, unsigned const char *map)
+bool InspIRCd::MatchCIDR(const char *str, const char *mask, unsigned const char *map)
 {
        if (irc::sockets::MatchCIDR(str, mask, true))
                return true;
@@ -117,3 +117,17 @@ CoreExport bool InspIRCd::MatchCIDR(const  char *str, const char *mask, unsigned
        return InspIRCd::Match(str, mask, map);
 }
 
+bool InspIRCd::MatchMask(const std::string& masks, const std::string& hostname, const std::string& ipaddr)
+{
+       std::stringstream masklist(masks);
+       std::string mask;
+       while (masklist >> mask)
+       {
+               if (InspIRCd::Match(hostname, mask, ascii_case_insensitive_map) || 
+                       InspIRCd::MatchCIDR(ipaddr, mask, ascii_case_insensitive_map))
+               {
+                       return true;
+               }
+       }
+       return false;
+}
index fd82ea2dfe7308ac6d7901509eeb76a5dd075f0b..ff86997bb8dc6e608df61a03de1d2689b7667291 100644 (file)
@@ -531,15 +531,15 @@ bool XLine::IsBurstable()
 
 void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
 {
-       char sreason[MAXBUF];
-       snprintf(sreason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason.c_str());
+       const std::string banReason = line + "-Lined: " + reason;
+
        if (!ServerInstance->Config->MoronBanner.empty())
                u->WriteNotice("*** " + ServerInstance->Config->MoronBanner);
 
        if (ServerInstance->Config->HideBans)
-               ServerInstance->Users->QuitUser(u, line + "-Lined", sreason);
+               ServerInstance->Users->QuitUser(u, line + "-Lined", banReason.c_str());
        else
-               ServerInstance->Users->QuitUser(u, sreason);
+               ServerInstance->Users->QuitUser(u, banReason);
 
 
        if (bancache)