]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Merge pull request #544 from SaberUK/master+kill-maxbuf
authorAttila Molnar <attilamolnar@hush.com>
Thu, 6 Jun 2013 00:52:39 +0000 (17:52 -0700)
committerAttila Molnar <attilamolnar@hush.com>
Thu, 6 Jun 2013 00:52:39 +0000 (17:52 -0700)
Purge MAXBUF in favour of a configuration option.

28 files changed:
configure
include/configreader.h
include/inspircd.h
include/users.h
make/configure.pm
src/commands/cmd_commands.cpp
src/commands/cmd_stats.cpp
src/commands/cmd_whois.cpp
src/configparser.cpp
src/configreader.cpp
src/logger.cpp
src/mode.cpp
src/modules/extra/m_ldapauth.cpp
src/modules/extra/m_mssql.cpp
src/modules/extra/m_ssl_gnutls.cpp
src/modules/m_alias.cpp
src/modules/m_blockcaps.cpp
src/modules/m_check.cpp
src/modules/m_ident.cpp
src/modules/m_messageflood.cpp
src/modules/m_permchannels.cpp
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/utils.cpp
src/modules/m_xline_db.cpp
src/socket.cpp
src/users.cpp
win/config.h.cmake
win/inspircd_win32wrapper.h

index ed301c988b684b49db0ba1a1c519090dd82d2b37..0af698ed0eb1b39b454ef9c7d083b15be6b0005e 100755 (executable)
--- a/configure
+++ b/configure
@@ -54,7 +54,7 @@ use make::configure;
 ###############################################################################################
 
 our ($opt_use_gnutls, $opt_use_openssl, $opt_nointeractive, $opt_ports, $opt_epoll, $opt_kqueue,
-     $opt_noports, $opt_noepoll, $opt_nokqueue, $opt_maxbuf, $opt_freebsd_port, $opt_system, $opt_uid);
+     $opt_noports, $opt_noepoll, $opt_nokqueue, $opt_freebsd_port, $opt_system, $opt_uid);
 
 our ($opt_cc, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir, $opt_data_dir, $opt_log_dir);
 
@@ -80,7 +80,6 @@ GetOptions (
        'disable-epoll' => \$opt_noepoll,
        'disable-kqueue' => \$opt_nokqueue,
        'with-cc=s' => \$opt_cc,
-       'with-maxbuf=i' => \$opt_maxbuf,
        'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
        'prefix=s' => \$opt_base_dir,
        'config-dir=s' => \$opt_config_dir,
@@ -123,7 +122,6 @@ our $interactive = !(
        (defined $opt_nokqueue) ||
        (defined $opt_noepoll) ||
        (defined $opt_noports) ||
-       (defined $opt_maxbuf) ||
        (defined $opt_system) ||
        (defined $opt_uid) ||
        (defined $opt_use_gnutls) ||
@@ -250,7 +248,6 @@ our $exec = $config{CC} . " -dumpversion | cut -c 1";
 chomp($config{GCCVER}          = `$exec`);                             # Major GCC Version
 $exec = $config{CC} . " -dumpversion | cut -c 3";
 chomp($config{GCCMINOR}                = `$exec`);
-$config{MAXBUF}                        = "512";                                # Max buffer size
 
 if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) {
        $config{HAS_OPENSSL} = $1;
@@ -836,7 +833,6 @@ sub writefiles {
 #define MOD_PATH "$config{MODULE_DIR}"
 
 EOF
-print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
 
                if ($config{OSNAME} =~ /SunOS/i) {
                        print FILEHANDLE "#define IS_SOLARIS\n";
index cc14120963d8ccf5e080ca6ebea78303b6d6820d..a17c5cf3eb294223ca2115e02ee33c3318c96f5f 100644 (file)
@@ -93,14 +93,16 @@ class ServerLimits
        size_t MaxGecos;
        /** Maximum away message length */
        size_t MaxAway;
+       /** Maximum line length */
+       size_t MaxLine;
 
        /** Creating the class initialises it to the defaults
         * as in 1.1's ./configure script. Reading other values
         * from the config will change these values.
         */
-       ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
-       {
-       }
+       ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12),
+               MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200),
+               MaxLine(512) { }
 };
 
 struct CommandLineConf
@@ -519,6 +521,12 @@ class CoreExport ServerConfig
         * @return True if the file exists and is readable.
         */
        static bool FileExists(const char* file);
+       
+       /** Escapes a value for storage in a configuration key.
+        * @param str The string to escape.
+        * @param xml Are we using the XML config format?
+        */
+       static std::string Escape(const std::string& str, bool xml = true);
 
        /** If this value is true, invites will bypass more than just +i
         */
index 957032da2f227c23a51d7d1c32dc9b0d6ac232d9..f86945903d9f2b00bf93ecc058d7d51e2d2fa42a 100644 (file)
@@ -82,20 +82,19 @@ CoreExport extern InspIRCd* ServerInstance;
  */
 template<typename T> inline std::string ConvNumeric(const T &in)
 {
-       if (in == 0) return "0";
-       char res[MAXBUF];
-       char* out = res;
+       if (in == 0)
+               return "0";
        T quotient = in;
-       while (quotient) {
-               *out = "0123456789"[ std::abs( (long)quotient % 10 ) ];
-               ++out;
+       std::string out;
+       while (quotient)
+       {
+               out += "0123456789"[ std::abs( (long)quotient % 10 ) ];
                quotient /= 10;
        }
        if (in < 0)
-               *out++ = '-';
-       *out = 0;
-       std::reverse(res,out);
-       return res;
+               out += '-';
+       std::reverse(out.begin(), out.end());
+       return out;
 }
 
 /** Template function to convert any input type to std::string
index 52f3e4a8897614967fd6f0708034697b9bd0064d..941e576671811e3181034b96e143a8417b55847f 100644 (file)
@@ -403,7 +403,7 @@ class CoreExport User : public Extensible
        /** Create a displayable mode string for this users snomasks
         * @return The notice mask character sequence
         */
-       const char* FormatNoticeMasks();
+       std::string FormatNoticeMasks();
 
        /** Process a snomask modifier string, e.g. +abc-de
         * @param sm A sequence of notice mask characters
@@ -481,12 +481,6 @@ class CoreExport User : public Extensible
         */
        virtual bool HasModePermission(unsigned char mode, ModeType type);
 
-       /** Creates a wildcard host.
-        * Takes a buffer to use and fills the given buffer with the host in the format *!*\@hostname
-        * @return The wildcarded hostname in *!*\@host form
-        */
-       char* MakeWildHost();
-
        /** Creates a usermask with real host.
         * Takes a buffer to use and fills the given buffer with the hostmask in the format user\@host
         * @return the usermask in the format user\@host
@@ -607,7 +601,7 @@ class CoreExport User : public Extensible
         * @param LinePrefix text to prefix each complete line with
         * @param TextStream the text to send to the user
         */
-       void SendText(const std::string &LinePrefix, std::stringstream &TextStream);
+       void SendText(const std::string& linePrefix, std::stringstream& textStream);
 
        /** Write to the user, routing the line if the user is remote.
         */
index d76b1143d88e45029236c01f021e063bbe57d1f7..2ae9c7fa029c036d6db7fed134bbcac2c34953f8 100644 (file)
@@ -297,9 +297,6 @@ InspIRCd 1.0.x, are also allowed.
                                to select() [not set]
   --with-cc=[filename]         Use an alternative compiler to
                                build InspIRCd [g++]
-  --with-maxbuf=[n]            Change the per message buffer size [512]
-                               DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
-                               AS IT *WILL* BREAK CLIENTS!!!
   --prefix=[directory]         Base directory to install into (if defined,
                                can automatically define config, module, bin
                                and library dirs as subdirectories of prefix)
index 36408b3638ec3e3aa0eca58d3f526ca3ff157365..99acdfe963cb13f756d65eed39bcc7b2f4540646 100644 (file)
@@ -53,12 +53,9 @@ CmdResult CommandCommands::Handle (const std::vector<std::string>&, User *user)
                        continue;
 
                Module* src = i->second->creator;
-               char buffer[MAXBUF];
-               snprintf(buffer, MAXBUF, ":%s %03d %s :%s %s %d %d",
-                       ServerInstance->Config->ServerName.c_str(), RPL_COMMANDS, user->nick.c_str(),
-                       i->second->name.c_str(), src->ModuleSourceFile.c_str(),
-                       i->second->min_params, i->second->Penalty);
-               list.push_back(buffer);
+               list.push_back(InspIRCd::Format(":%s %03d %s :%s %s %d %d", ServerInstance->Config->ServerName.c_str(),
+                       RPL_COMMANDS, user->nick.c_str(), i->second->name.c_str(), src->ModuleSourceFile.c_str(),
+                       i->second->min_params, i->second->Penalty));
        }
        sort(list.begin(), list.end());
        for(unsigned int i=0; i < list.size(); i++)
index 3145940be415d1452d3691ebbc69c40995406147..9fef7bbd4297b02ba09c283436d31356a3b5b91d 100644 (file)
@@ -271,9 +271,9 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                        }
 
                        FILETIME CreationTime;
-               FILETIME ExitTime;
-               FILETIME KernelTime;
-               FILETIME UserTime;
+                       FILETIME ExitTime;
+                       FILETIME KernelTime;
+                       FILETIME UserTime;
                        LARGE_INTEGER ThisSample;
                        if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) &&
                                QueryPerformanceCounter(&ThisSample))
@@ -301,15 +301,13 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
 
                case 'T':
                {
-                       char buffer[MAXBUF];
                        results.push_back(sn+" 249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused));
                        results.push_back(sn+" 249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown));
                        results.push_back(sn+" 249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions));
                        results.push_back(sn+" 249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad));
                        results.push_back(sn+" 249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects));
-                       snprintf(buffer,MAXBUF," 249 %s :bytes sent %5.2fK recv %5.2fK",
-                               user->nick.c_str(),ServerInstance->stats->statsSent / 1024.0,ServerInstance->stats->statsRecv / 1024.0);
-                       results.push_back(sn+buffer);
+                       results.push_back(InspIRCd::Format("%s 249 %s :bytes sent %5.2fK recv %5.2fK", sn.c_str(), user->nick.c_str(),
+                               ServerInstance->stats->statsSent / 1024.0, ServerInstance->stats->statsRecv / 1024.0));
                }
                break;
 
@@ -382,15 +380,15 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
                         * Craig suggested this, and it seemed a good idea so in it went */
                        if (stime->tm_year > 70)
                        {
-                               char buffer[MAXBUF];
-                               snprintf(buffer,MAXBUF," 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",user->nick.c_str(),(stime->tm_year-70),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
-                               results.push_back(sn+buffer);
+                               results.push_back(InspIRCd::Format("%s 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",
+                                       sn.c_str(), user->nick.c_str(), stime->tm_year - 70, stime->tm_yday, stime->tm_hour,
+                                       stime->tm_min, stime->tm_sec));
                        }
                        else
                        {
-                               char buffer[MAXBUF];
-                               snprintf(buffer,MAXBUF," 242 %s :Server up %d days, %.2d:%.2d:%.2d",user->nick.c_str(),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec);
-                               results.push_back(sn+buffer);
+                               results.push_back(InspIRCd::Format("%s 242 %s :Server up %d days, %.2d:%.2d:%.2d",
+                                       sn.c_str(), user->nick.c_str(), stime->tm_yday, stime->tm_hour, stime->tm_min,
+                                       stime->tm_sec));
                        }
                }
                break;
index fea14f375bb1c12efe85a803ac9cf6117e3e14dc..de3d71152bd2cda7ce2cf70cf776975325e71746 100644 (file)
@@ -152,7 +152,7 @@ void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigne
        {
                if (dest->IsModeSet('s') != 0)
                {
-                       ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks());
+                       ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks().c_str());
                }
                else
                {
index 61cdb55fa160ded9627f7b90cc369bfc6793aaa2..31d3141482aaef9452339d1838863daa7c45b09d 100644 (file)
@@ -327,7 +327,7 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
        file_cache& cache = FilesOutput[key];
        cache.clear();
 
-       char linebuf[MAXBUF*10];
+       char linebuf[5120];
        while (fgets(linebuf, sizeof(linebuf), file))
        {
                size_t len = strlen(linebuf);
index a8c0abe89056b4ed9fc11f5d47ab81ffa3285360..905eb786af84b0646b6ae4eca423e172cb903935 100644 (file)
@@ -367,10 +367,15 @@ void ServerConfig::Fill()
        else
        {
                if (ServerName != ConfValue("server")->getString("name"))
-                       throw CoreException("You must restart to change the server name or SID");
+                       throw CoreException("You must restart to change the server name");
+
                std::string nsid = ConfValue("server")->getString("id");
                if (!nsid.empty() && nsid != sid)
-                       throw CoreException("You must restart to change the server name or SID");
+                       throw CoreException("You must restart to change the server id");
+
+               if (Limits.MaxLine != static_cast<size_t>(ConfValue("limits")->getInt("maxline", 512)))
+                       throw CoreException("You must restart to change the maximum line length");
+
        }
        diepass = ConfValue("power")->getString("diepass");
        restartpass = ConfValue("power")->getString("restartpass");
@@ -423,6 +428,7 @@ void ServerConfig::Fill()
        Limits.MaxKick = ConfValue("limits")->getInt("maxkick", 255);
        Limits.MaxGecos = ConfValue("limits")->getInt("maxgecos", 128);
        Limits.MaxAway = ConfValue("limits")->getInt("maxaway", 200);
+       Limits.MaxLine = ConfValue("limits")->getInt("maxline", 512);
        InvBypassModes = options->getBool("invitebypassmodes", true);
        NoSnoticeStack = options->getBool("nosnoticestack", false);
 
@@ -767,14 +773,31 @@ bool ServerConfig::FileExists(const char* file)
        if ((sb.st_mode & S_IFDIR) > 0)
                return false;
 
-       FILE *input = fopen(file, "r");
-       if (input == NULL)
-               return false;
-       else
+       return !access(file, F_OK);
+}
+
+std::string ServerConfig::Escape(const std::string& str, bool xml)
+{
+       std::string escaped;
+       for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
        {
-               fclose(input);
-               return true;
+               switch (*it)
+               {
+                       case '"':
+                               escaped += xml ? "&quot;" : "\"";
+                               break;
+                       case '&':
+                               escaped += xml ? "&amp;" : "&";
+                               break;
+                       case '\\':
+                               escaped += xml ? "\\" : "\\\\";
+                               break;
+                       default:
+                               escaped += *it;
+                               break;
+               }
        }
+       return escaped;
 }
 
 const char* ServerConfig::CleanFilename(const char* name)
index 1a63499d6afaa7b01c334e2fd2b5a55589e9d1b6..03960f4a1655188189e6bafe2178c2cae398bcc3 100644 (file)
@@ -116,10 +116,10 @@ void LogManager::OpenFileLogs()
                std::map<std::string, FileWriter*>::iterator fwi = logmap.find(target);
                if (fwi == logmap.end())
                {
-                       char realtarget[MAXBUF];
+                       char realtarget[256];
                        time_t time = ServerInstance->Time();
                        struct tm *mytime = gmtime(&time);
-                       strftime(realtarget, MAXBUF, target.c_str(), mytime);
+                       strftime(realtarget, sizeof(realtarget), target.c_str(), mytime);
                        FILE* f = fopen(realtarget, "a");
                        fw = new FileWriter(f);
                        logmap.insert(std::make_pair(target, fw));
index 578fc2c27a518469d35db84ea721ce05bf921df7..ac0b111b14dd20b316021680f4628bd3004c2e18 100644 (file)
@@ -190,7 +190,7 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ
                        /* Display user's current mode string */
                        user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes());
                        if ((targetuser->IsOper()))
-                               user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks());
+                               user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks().c_str());
                        return;
                }
                else
index 2d1551b43958536164c134f023eee45757eeb8e0..0a0698fc2946679f67957a2503e2b63b54fbdc3f 100644 (file)
@@ -212,7 +212,7 @@ public:
                        std::string> &replacements)
        {
                std::string result;
-               result.reserve(MAXBUF);
+               result.reserve(text.length());
 
                for (unsigned int i = 0; i < text.length(); ++i) {
                        char c = text[i];
index 244aa0922a006cecc04020d867ae2a71c60976c6..9d9622fde40a4254fdfc42ed63b6c75c8cfac2b4 100644 (file)
@@ -472,8 +472,8 @@ class SQLConn : public classbase
                                                if (sock->res_info->row_count > 0)
                                                {
                                                        int cols = sock->res_info->num_cols;
-                                                       char** name = new char*[MAXBUF];
-                                                       char** data = new char*[MAXBUF];
+                                                       char** name = new char*[512];
+                                                       char** data = new char*[512];
                                                        for (int j=0; j<cols; j++)
                                                        {
                                                                TDSCOLUMN* col = sock->current_results->columns[j];
index 8faee2da7b710e6708ccf43f256020f73cbc9ea3..f9fddd5a1d6af4b03d7f02cdd6322232e6e14ccb 100644 (file)
@@ -803,8 +803,8 @@ class ModuleSSLGnuTLS : public Module
                int ret;
                unsigned int cert_list_size;
                gnutls_x509_crt_t cert;
-               char name[MAXBUF];
-               unsigned char digest[MAXBUF];
+               char name[512];
+               unsigned char digest[512];
                size_t digest_size = sizeof(digest);
                size_t name_size = sizeof(name);
                ssl_cert* certinfo = new ssl_cert;
index 118cedeea014c1b066d415df8deee77a12fc6fe1..7343dd21ba58d9f907859b4d1216c115a529b5cf 100644 (file)
@@ -309,7 +309,7 @@ class ModuleAlias : public Module
        void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line)
        {
                std::string result;
-               result.reserve(MAXBUF);
+               result.reserve(newline.length());
                for (unsigned int i = 0; i < newline.length(); i++)
                {
                        char c = newline[i];
index 0e1fa945ffecfdd5ef391d71b6a431d592fc1692..c13549db87c6d2632821c2b08e42b9f6eff4e364 100644 (file)
@@ -119,7 +119,7 @@ public:
                        ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
                        percent = 100;
                }
-               if (minlen < 1 || minlen > MAXBUF-1)
+               if (minlen < 1 || minlen > ServerInstance->Config->Limits.MaxLine)
                {
                        ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
                        minlen = 1;
index fda211cf80eb03061972ab36471cd3a51817439a..734089c5b5bb29e0b2e0140db90dc60de84c09a0 100644 (file)
@@ -194,12 +194,13 @@ class CommandCheck : public Command
                        /* note that unlike /names, we do NOT check +i vs in the channel */
                        for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
                        {
-                               char tmpbuf[MAXBUF];
                                /*
-                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
-                                */
-                               snprintf(tmpbuf, MAXBUF, "%-3lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
-                               user->SendText(checkstr + " member " + tmpbuf);
+                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
+                                */
+                               user->SendText("%s member %-3lu %s%s (%s@%s) %s ",
+                                       checkstr.c_str(), ServerInstance->Users->GlobalCloneCount(i->first),
+                                       targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(),
+                                       i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
                        }
 
                        // We know that the mode handler for bans is in the core and is derived from ListModeBase
index 00ff75f59383df0f42a691c9ac8a558bded4d3c6..9f67a62423907e73bd3fe6ea6724fefd4102f846 100644 (file)
@@ -213,8 +213,8 @@ class IdentRequestSocket : public EventHandler
                /* We don't really need to buffer for incomplete replies here, since IDENT replies are
                 * extremely short - there is *no* sane reason it'd be in more than one packet
                 */
-               char ibuf[MAXBUF];
-               int recvresult = ServerInstance->SE->Recv(this, ibuf, MAXBUF-1, 0);
+               char ibuf[256];
+               int recvresult = ServerInstance->SE->Recv(this, ibuf, sizeof(ibuf)-1, 0);
 
                /* Close (but don't delete from memory) our socket
                 * and flag as done since the ident lookup has finished
index 970087befeec85ee9db7476de7b86edb2a3a705a..65c3354a9212b5ec624639995bf0d738bdcbd96d 100644 (file)
@@ -155,7 +155,7 @@ class ModuleMsgFlood : public Module
                                        std::vector<std::string> parameters;
                                        parameters.push_back(dest->name);
                                        parameters.push_back("+b");
-                                       parameters.push_back(user->MakeWildHost());
+                                       parameters.push_back("*!*@" + user->dhost);
                                        ServerInstance->SendGlobalMode(parameters, ServerInstance->FakeClient);
                                }
 
index 41477ba35000246c0949f4a4467a483f5c90bd4d..ff1a35ba913e62bbe3ed1cf1cb4daac0daa703ed 100644 (file)
@@ -19,6 +19,7 @@
 
 
 #include "inspircd.h"
+#include <fstream>
 
 /* $ModDesc: Provides support for channel mode +P to provide permanent channels */
 
 static std::string permchannelsconf;
 static bool WriteDatabase()
 {
-       FILE *f;
-
-       if (permchannelsconf.empty())
-       {
-               // Fake success.
-               return true;
-       }
-
-       std::string tempname = permchannelsconf + ".tmp";
-
        /*
         * We need to perform an atomic write so as not to fuck things up.
-        * So, let's write to a temporary file, flush and sync the FD, then rename the file..
-        *              -- w00t
+        * So, let's write to a temporary file, flush it, then rename the file..
+        *     -- w00t
         */
-       f = fopen(tempname.c_str(), "w");
-       if (!f)
+       
+       // If the user has not specified a configuration file then we don't write one.
+       if (permchannelsconf.empty())
+               return true;
+
+       std::string permchannelsnewconf = permchannelsconf + ".tmp";
+       std::ofstream stream(permchannelsnewconf.c_str());
+       if (!stream.is_open())
        {
                ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot create database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno);
                return false;
        }
+       
+       stream << "# This file is automatically generated by m_permchannels. Any changes will be overwritten." << std::endl
+               << "<config format=\"xml\">" << std::endl;
 
-       fputs("# Permchannels DB\n# This file is autogenerated; any changes will be overwritten!\n<config format=\"compat\">\n", f);
-       // Now, let's write.
        for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
        {
                Channel* chan = i->second;
                if (!chan->IsModeSet('P'))
                        continue;
 
-               char line[1024];
-               const char* items[] =
-               {
-                       "<permchannels channel=",
-                       chan->name.c_str(),
-                       " topic=",
-                       chan->topic.c_str(),
-                       " modes=",
-                       chan->ChanModes(true),
-                       ">\n"
-               };
-
-               int lpos = 0, item = 0, ipos = 0;
-               while (lpos < 1022 && item < 7)
-               {
-                       char c = items[item][ipos++];
-                       if (c == 0)
-                       {
-                               // end of this string; hop to next string, insert a quote
-                               item++;
-                               ipos = 0;
-                               c = '"';
-                       }
-                       else if (c == '\\' || c == '"')
-                       {
-                               line[lpos++] = '\\';
-                       }
-                       line[lpos++] = c;
-               }
-               line[--lpos] = 0;
-               fputs(line, f);
+               stream << "<permchannels channel=\"" << ServerConfig::Escape(chan->name)
+                       << "\" topic=\"" << ServerConfig::Escape(chan->topic)
+                       << "\" modes=\"" << ServerConfig::Escape(chan->ChanModes(true))
+                       << "\">" << std::endl;
        }
 
-       int write_error = 0;
-       write_error = ferror(f);
-       write_error |= fclose(f);
-       if (write_error)
+       if (stream.fail())
        {
                ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                return false;
        }
+       stream.close();
 
 #ifdef _WIN32
        if (remove(permchannelsconf.c_str()))
@@ -109,7 +78,7 @@ static bool WriteDatabase()
        }
 #endif
        // Use rename to move temporary to new db - this is guarenteed not to fuck up, even in case of a crash.
-       if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0)
+       if (rename(permchannelsnewconf.c_str(), permchannelsconf.c_str()) < 0)
        {
                ServerInstance->Logs->Log("m_permchannels", LOG_DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
                ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
@@ -120,7 +89,6 @@ static bool WriteDatabase()
 }
 
 
-
 /** Handles the +P channel mode
  */
 class PermChannel : public ModeHandler
index 8daaefd8ad489eac1467971f7c1ff1d144b5a454..89c8046f594719c1dfc3e28d251c4e11af6b5c02 100644 (file)
@@ -66,18 +66,14 @@ void TreeSocket::DoBurst(TreeServer* s)
  */
 void TreeSocket::SendServers(TreeServer* Current, TreeServer* s)
 {
-       char command[MAXBUF];
        for (unsigned int q = 0; q < Current->ChildCount(); q++)
        {
                TreeServer* recursive_server = Current->GetChild(q);
                if (recursive_server != s)
                {
-                       std::string recursive_servername = recursive_server->GetName();
-                       snprintf(command, MAXBUF, ":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(), recursive_servername.c_str(),
-                                       recursive_server->GetID().c_str(),
-                                       recursive_server->GetDesc().c_str());
-                       this->WriteLine(command);
-                       this->WriteLine(":"+recursive_server->GetID()+" VERSION :"+recursive_server->GetVersion());
+                       this->WriteLine(InspIRCd::Format(":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(),
+                               recursive_server->GetName().c_str(), recursive_server->GetID().c_str(), recursive_server->GetDesc().c_str()));
+                       this->WriteLine(":" + recursive_server->GetID() + " VERSION :" + recursive_server->GetVersion());
                        /* down to next level */
                        this->SendServers(recursive_server, s);
                }
@@ -119,8 +115,6 @@ void TreeSocket::SendFJoins(Channel* c)
 /** Send all XLines we know about */
 void TreeSocket::SendXLines()
 {
-       char data[MAXBUF];
-
        std::vector<std::string> types = ServerInstance->XLines->GetAllTypes();
 
        for (std::vector<std::string>::const_iterator it = types.begin(); it != types.end(); ++it)
@@ -139,15 +133,14 @@ void TreeSocket::SendXLines()
                                if (!i->second->IsBurstable())
                                        break;
 
-                               snprintf(data, MAXBUF, ":%s ADDLINE %s %s %s %lu %lu :%s",
-                                               ServerInstance->Config->GetSID().c_str(),
-                                               it->c_str(),
-                                               i->second->Displayable().c_str(),
-                                               i->second->source.c_str(),
-                                               (unsigned long)i->second->set_time,
-                                               (unsigned long)i->second->duration,
-                                               i->second->reason.c_str());
-                               this->WriteLine(data);
+                               this->WriteLine(InspIRCd::Format(":%s ADDLINE %s %s %s %lu %lu :%s",
+                                       ServerInstance->Config->GetSID().c_str(),
+                                       it->c_str(),
+                                       i->second->Displayable().c_str(),
+                                       i->second->source.c_str(),
+                                       (unsigned long)i->second->set_time,
+                                       (unsigned long)i->second->duration,
+                                       i->second->reason.c_str()));
                        }
                }
        }
@@ -156,16 +149,15 @@ void TreeSocket::SendXLines()
 /** Send channel topic, modes and metadata */
 void TreeSocket::SyncChannel(Channel* chan)
 {
-       char data[MAXBUF];
-
        SendFJoins(chan);
 
        // If the topic was ever set, send it, even if it's empty now
        // because a new empty topic should override an old non-empty topic
        if (chan->topicset != 0)
        {
-               snprintf(data,MAXBUF,":%s FTOPIC %s %lu %lu %s :%s", ServerInstance->Config->GetSID().c_str(), chan->name.c_str(), (unsigned long) chan->age, (unsigned long)chan->topicset, chan->setby.c_str(), chan->topic.c_str());
-               this->WriteLine(data);
+               this->WriteLine(InspIRCd::Format(":%s FTOPIC %s %lu %lu %s :%s", ServerInstance->Config->GetSID().c_str(),
+                       chan->name.c_str(), (unsigned long)chan->age, (unsigned long)chan->topicset,
+                       chan->setby.c_str(), chan->topic.c_str()));
        }
 
        for (Extensible::ExtensibleStore::const_iterator i = chan->GetExtList().begin(); i != chan->GetExtList().end(); i++)
@@ -182,7 +174,6 @@ void TreeSocket::SyncChannel(Channel* chan)
 /** send all users and their oper state/modes */
 void TreeSocket::SendUsers()
 {
-       char data[MAXBUF];
        for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
        {
                if (u->second->registered == REG_ALL)
@@ -190,28 +181,27 @@ void TreeSocket::SendUsers()
                        TreeServer* theirserver = Utils->FindServer(u->second->server);
                        if (theirserver)
                        {
-                               snprintf(data,MAXBUF,":%s UID %s %lu %s %s %s %s %s %lu +%s :%s",
-                                               theirserver->GetID().c_str(),   /* Prefix: SID */
-                                               u->second->uuid.c_str(),        /* 0: UUID */
-                                               (unsigned long)u->second->age,  /* 1: TS */
-                                               u->second->nick.c_str(),        /* 2: Nick */
-                                               u->second->host.c_str(),        /* 3: Displayed Host */
-                                               u->second->dhost.c_str(),       /* 4: Real host */
-                                               u->second->ident.c_str(),       /* 5: Ident */
-                                               u->second->GetIPString().c_str(),       /* 6: IP string */
-                                               (unsigned long)u->second->signon, /* 7: Signon time for WHOWAS */
-                                               u->second->FormatModes(true),   /* 8...n: Modes and params */
-                                               u->second->fullname.c_str());   /* size-1: GECOS */
-                               this->WriteLine(data);
+                               this->WriteLine(InspIRCd::Format(":%s UID %s %lu %s %s %s %s %s %lu +%s :%s",
+                                       theirserver->GetID().c_str(),     // Prefix: SID
+                                       u->second->uuid.c_str(),          // 0: UUID
+                                       (unsigned long)u->second->age,    // 1: TS
+                                       u->second->nick.c_str(),          // 2: Nick
+                                       u->second->host.c_str(),          // 3: Real host
+                                       u->second->dhost.c_str(),         // 4: Display host
+                                       u->second->ident.c_str(),         // 5: Ident
+                                       u->second->GetIPString().c_str(), // 6: IP address
+                                       (unsigned long)u->second->signon, // 7: Signon time
+                                       u->second->FormatModes(true),     // 8...n: User modes and params
+                                       u->second->fullname.c_str()));    // size-1: GECOS
+
                                if (u->second->IsOper())
                                {
-                                       snprintf(data,MAXBUF,":%s OPERTYPE :%s", u->second->uuid.c_str(), u->second->oper->name.c_str());
-                                       this->WriteLine(data);
+                                       this->WriteLine(InspIRCd::Format(":%s OPERTYPE :%s", u->second->uuid.c_str(), u->second->oper->name.c_str()));
                                }
                                if (u->second->IsAway())
                                {
-                                       snprintf(data,MAXBUF,":%s AWAY %ld :%s", u->second->uuid.c_str(), (long)u->second->awaytime, u->second->awaymsg.c_str());
-                                       this->WriteLine(data);
+                                       this->WriteLine(InspIRCd::Format(":%s AWAY %ld :%s", u->second->uuid.c_str(), (long)u->second->awaytime,
+                                               u->second->awaymsg.c_str()));
                                }
                        }
 
index 157679ed7f2adda19bbe8add6e33ef9d39597d45..c469f41a29cc17c2e154dd6bb78b38d03d775c41 100644 (file)
@@ -197,7 +197,7 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis
 std::string SpanningTreeUtilities::ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params)
 {
        std::string FullLine;
-       FullLine.reserve(MAXBUF);
+       FullLine.reserve(1024);
        FullLine = ":" + prefix + " " + command;
        for (parameterlist::const_iterator x = params.begin(); x != params.end(); ++x)
        {
index e325fc088558d7953abdf8bdf6b28f7dfcf47d7e..0b3361953ac76e372e0c5f3e36e8f2cc3b82c23d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "inspircd.h"
 #include "xline.h"
+#include <fstream>
 
 /* $ModConfig: <xlinedb filename="data/xline.db">
  *  Specify the filename for the xline database here*/
@@ -85,18 +86,16 @@ class ModuleXLineDB : public Module
 
        bool WriteDatabase()
        {
-               FILE *f;
-
                /*
                 * We need to perform an atomic write so as not to fuck things up.
-                * So, let's write to a temporary file, flush and sync the FD, then rename the file..
+                * So, let's write to a temporary file, flush it, then rename the file..
                 * Technically, that means that this can block, but I have *never* seen that.
-                *              -- w00t
+                *     -- w00t
                 */
                ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Opening temporary database");
                std::string xlinenewdbpath = xlinedbpath + ".new";
-               f = fopen(xlinenewdbpath.c_str(), "w");
-               if (!f)
+               std::ofstream stream(xlinenewdbpath.c_str());
+               if (!stream.is_open())
                {
                        ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot create database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot create new db: %s (%d)", strerror(errno), errno);
@@ -112,7 +111,7 @@ class ModuleXLineDB : public Module
                 * semblance of backwards compatibility for reading on startup..
                 *              -- w00t
                 */
-               fprintf(f, "VERSION 1\n");
+               stream << "VERSION 1" << std::endl;
 
                // Now, let's write.
                std::vector<std::string> types = ServerInstance->XLines->GetAllTypes();
@@ -125,26 +124,21 @@ class ModuleXLineDB : public Module
                        for (LookupIter i = lookup->begin(); i != lookup->end(); ++i)
                        {
                                XLine* line = i->second;
-                               fprintf(f, "LINE %s %s %s %lu %lu :%s\n",
-                                       line->type.c_str(),
-                                       line->Displayable().c_str(),
-                                       ServerInstance->Config->ServerName.c_str(),
-                                       (unsigned long)line->set_time,
-                                       (unsigned long)line->duration, line->reason.c_str());
+                               stream << "LINE " << line->type << " " << line->Displayable() << " "
+                                       << ServerInstance->Config->ServerName << " " << line->set_time << " "
+                                       << line->duration << " " << line->reason << std::endl;
                        }
                }
 
                ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Finished writing XLines. Checking for error..");
 
-               int write_error = 0;
-               write_error = ferror(f);
-               write_error |= fclose(f);
-               if (write_error)
+               if (stream.fail())
                {
                        ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot write to new database! %s (%d)", strerror(errno), errno);
                        ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
                        return false;
                }
+               stream.close();
 
 #ifdef _WIN32
                if (remove(xlinedbpath.c_str()))
@@ -167,42 +161,23 @@ class ModuleXLineDB : public Module
 
        bool ReadDatabase()
        {
-               FILE *f;
-               char linebuf[MAXBUF];
+               // If the xline database doesn't exist then we don't need to load it.
+               if (!ServerConfig::FileExists(xlinedbpath.c_str()))
+                       return true;
 
-               f = fopen(xlinedbpath.c_str(), "r");
-               if (!f)
+               std::ifstream stream(xlinedbpath.c_str());
+               if (!stream.is_open())
                {
-                       if (errno == ENOENT)
-                       {
-                               /* xline.db doesn't exist, fake good return value (we don't care about this) */
-                               return true;
-                       }
-                       else
-                       {
-                               /* this might be slightly more problematic. */
-                               ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno);
-                               ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno);
-                               return false;
-                       }
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Cannot read database! %s (%d)", strerror(errno), errno);
+                       ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read db: %s (%d)", strerror(errno), errno);
+                       return false;
                }
-
-               while (fgets(linebuf, MAXBUF, f))
+               
+               std::string line;
+               while (std::getline(stream, line))
                {
-                       char *c = linebuf;
-
-                       while (c && *c)
-                       {
-                               if (*c == '\n')
-                               {
-                                       *c = '\0';
-                               }
-
-                               c++;
-                       }
-
                        // Inspired by the command parser. :)
-                       irc::tokenstream tokens(linebuf);
+                       irc::tokenstream tokens(line);
                        int items = 0;
                        std::string command_p[7];
                        std::string tmp;
@@ -213,7 +188,7 @@ class ModuleXLineDB : public Module
                                items++;
                        }
 
-                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Processing %s", linebuf);
+                       ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: Processing %s", line.c_str());
 
                        if (command_p[0] == "VERSION")
                        {
@@ -223,7 +198,7 @@ class ModuleXLineDB : public Module
                                }
                                else
                                {
-                                       fclose(f);
+                                       stream.close();
                                        ServerInstance->Logs->Log("m_xline_db", LOG_DEBUG, "xlinedb: I got database version %s - I don't understand it", command_p[1].c_str());
                                        ServerInstance->SNO->WriteToSnoMask('a', "database: I got a database version (%s) I don't understand", command_p[1].c_str());
                                        return false;
@@ -251,8 +226,7 @@ class ModuleXLineDB : public Module
                                        delete xl;
                        }
                }
-
-               fclose(f);
+               stream.close();
                return true;
        }
 
index 12fb632a756598fbcf0284d248362c3b5c9387e7..9ec7544f24f67ae440c295d72804b0589da12cf0 100644 (file)
@@ -221,24 +221,22 @@ static const char all_zero[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
 
 std::string irc::sockets::sockaddrs::str() const
 {
-       char buffer[MAXBUF];
        if (sa.sa_family == AF_INET)
        {
-               const uint8_t* bits = reinterpret_cast<const uint8_t*>(&in4.sin_addr);
-               sprintf(buffer, "%d.%d.%d.%d:%u", bits[0], bits[1], bits[2], bits[3], ntohs(in4.sin_port));
+               char ipaddr[INET_ADDRSTRLEN];
+               inet_ntop(AF_INET, &in4.sin_addr, ipaddr, sizeof(ipaddr));
+               return InspIRCd::Format("%s:%u", ipaddr, ntohs(in4.sin_port));
        }
-       else if (sa.sa_family == AF_INET6)
+
+       if (sa.sa_family == AF_INET6)
        {
-               buffer[0] = '[';
-               if (!inet_ntop(AF_INET6, &in6.sin6_addr, buffer+1, MAXBUF - 10))
-                       return "<unknown>"; // should never happen, buffer is large enough
-               int len = strlen(buffer);
-               // no need for snprintf, buffer has at least 9 chars left, max short len = 5
-               sprintf(buffer + len, "]:%u", ntohs(in6.sin6_port));
+               char ipaddr[INET6_ADDRSTRLEN];
+               inet_ntop(AF_INET6, &in6.sin6_addr, ipaddr, sizeof(ipaddr));
+               return InspIRCd::Format("[%s]:%u", ipaddr, ntohs(in6.sin6_port));
        }
-       else
-               return "<unknown>";
-       return std::string(buffer);
+
+       // This should never happen.
+       return "<unknown>";
 }
 
 int irc::sockets::sockaddrs::sa_size() const
index 44834330b1e654d450e821686dec2983d89f57c0..468c2aa36e92980402ccf29c8dd22f31c6baa803 100644 (file)
@@ -122,18 +122,16 @@ void User::SetNoticeMask(unsigned char sm, bool value)
        snomasks[sm-65] = value;
 }
 
-const char* User::FormatNoticeMasks()
+std::string User::FormatNoticeMasks()
 {
-       static char data[MAXBUF];
-       int offset = 0;
+       std::string data;
 
-       for (int n = 0; n < 64; n++)
+       for (unsigned char n = 0; n < 64; n++)
        {
                if (snomasks[n])
-                       data[offset++] = n+65;
+                       data.push_back(n + 65); 
        }
 
-       data[offset] = 0;
        return data;
 }
 
@@ -220,18 +218,8 @@ const std::string& User::MakeHost()
        if (!this->cached_makehost.empty())
                return this->cached_makehost;
 
-       char nhost[MAXBUF];
-       /* This is much faster than snprintf */
-       char* t = nhost;
-       for(const char* n = ident.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '@';
-       for(const char* n = host.c_str(); *n; n++)
-               *t++ = *n;
-       *t = 0;
-
-       this->cached_makehost.assign(nhost);
-
+       // XXX: Is there really a need to cache this?
+       this->cached_makehost = ident + "@" + host;
        return this->cached_makehost;
 }
 
@@ -240,18 +228,8 @@ const std::string& User::MakeHostIP()
        if (!this->cached_hostip.empty())
                return this->cached_hostip;
 
-       char ihost[MAXBUF];
-       /* This is much faster than snprintf */
-       char* t = ihost;
-       for(const char* n = ident.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '@';
-       for(const char* n = this->GetIPString().c_str(); *n; n++)
-               *t++ = *n;
-       *t = 0;
-
-       this->cached_hostip = ihost;
-
+       // XXX: Is there really a need to cache this?
+       this->cached_hostip = ident + "@" + this->GetIPString();
        return this->cached_hostip;
 }
 
@@ -260,54 +238,18 @@ const std::string& User::GetFullHost()
        if (!this->cached_fullhost.empty())
                return this->cached_fullhost;
 
-       char result[MAXBUF];
-       char* t = result;
-       for(const char* n = nick.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '!';
-       for(const char* n = ident.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '@';
-       for(const char* n = dhost.c_str(); *n; n++)
-               *t++ = *n;
-       *t = 0;
-
-       this->cached_fullhost = result;
-
+       // XXX: Is there really a need to cache this?
+       this->cached_fullhost = nick + "!" + ident + "@" + dhost;
        return this->cached_fullhost;
 }
 
-char* User::MakeWildHost()
-{
-       static char nresult[MAXBUF];
-       char* t = nresult;
-       *t++ = '*';     *t++ = '!';
-       *t++ = '*';     *t++ = '@';
-       for(const char* n = dhost.c_str(); *n; n++)
-               *t++ = *n;
-       *t = 0;
-       return nresult;
-}
-
 const std::string& User::GetFullRealHost()
 {
        if (!this->cached_fullrealhost.empty())
                return this->cached_fullrealhost;
 
-       char fresult[MAXBUF];
-       char* t = fresult;
-       for(const char* n = nick.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '!';
-       for(const char* n = ident.c_str(); *n; n++)
-               *t++ = *n;
-       *t++ = '@';
-       for(const char* n = host.c_str(); *n; n++)
-               *t++ = *n;
-       *t = 0;
-
-       this->cached_fullrealhost = fresult;
-
+       // XXX: Is there really a need to cache this?
+       this->cached_fullrealhost = nick + "!" + ident + "@" + host;
        return this->cached_fullrealhost;
 }
 
@@ -428,7 +370,7 @@ void UserIOHandler::OnDataReady()
        while (user->CommandFloodPenalty < penaltymax && getSendQSize() < sendqmax)
        {
                std::string line;
-               line.reserve(MAXBUF);
+               line.reserve(ServerInstance->Config->Limits.MaxLine);
                std::string::size_type qpos = 0;
                while (qpos < recvq.length())
                {
@@ -443,7 +385,7 @@ void UserIOHandler::OnDataReady()
                        case '\n':
                                goto eol_found;
                        }
-                       if (line.length() < MAXBUF - 2)
+                       if (line.length() < ServerInstance->Config->Limits.MaxLine - 2)
                                line.push_back(c);
                }
                // if we got here, the recvq ran out before we found a newline
@@ -995,10 +937,10 @@ void LocalUser::Write(const std::string& text)
        if (!ServerInstance->SE->BoundsCheckFd(&eh))
                return;
 
-       if (text.length() > MAXBUF - 2)
+       if (text.length() > ServerInstance->Config->Limits.MaxLine - 2)
        {
                // this should happen rarely or never. Crop the string at 512 and try again.
-               std::string try_again = text.substr(0, MAXBUF - 2);
+               std::string try_again = text.substr(0, ServerInstance->Config->Limits.MaxLine - 2);
                Write(try_again);
                return;
        }
@@ -1051,16 +993,16 @@ void User::WriteNumeric(unsigned int numeric, const char* text, ...)
 
 void User::WriteNumeric(unsigned int numeric, const std::string &text)
 {
-       char textbuffer[MAXBUF];
        ModResult MOD_RESULT;
 
        FIRST_MOD_RESULT(OnNumeric, MOD_RESULT, (this, numeric, text));
 
        if (MOD_RESULT == MOD_RES_DENY)
                return;
-
-       snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName.c_str(), numeric, text.c_str());
-       this->Write(std::string(textbuffer));
+       
+       const std::string message = InspIRCd::Format(":%s %03u %s", ServerInstance->Config->ServerName.c_str(),
+               numeric, text.c_str());
+       this->Write(message);
 }
 
 void User::WriteFrom(User *user, const std::string &text)
@@ -1217,28 +1159,21 @@ void User::SendText(const char *text, ...)
        SendText(line);
 }
 
-void User::SendText(const std::string &LinePrefix, std::stringstream &TextStream)
+void User::SendText(const std::string& linePrefix, std::stringstream& textStream)
 {
-       char line[MAXBUF];
-       int start_pos = LinePrefix.length();
-       int pos = start_pos;
-       memcpy(line, LinePrefix.data(), pos);
-       std::string Word;
-       while (TextStream >> Word)
+       std::string line;
+       std::string word;
+       while (textStream >> word)
        {
-               int len = Word.length();
-               if (pos + len + 12 > MAXBUF)
+               size_t lineLength = linePrefix.length() + line.length() + word.length() + 3; // "\s\n\r"
+               if (lineLength > ServerInstance->Config->Limits.MaxLine)
                {
-                       line[pos] = '\0';
-                       SendText(std::string(line));
-                       pos = start_pos;
+                       SendText(linePrefix + line);
+                       line.clear();
                }
-               line[pos] = ' ';
-               memcpy(line + pos + 1, Word.data(), len);
-               pos += len + 1;
+               line += " " + word;
        }
-       line[pos] = '\0';
-       SendText(std::string(line));
+       SendText(linePrefix + line);
 }
 
 /* return 0 or 1 depending if users u and u2 share one or more common channels
index 05c3ce2f99f98277ff42fc19f4ee9bea2e08eafb..dbe705ceb1cf27048aafab7e0f59f3f503261020 100644 (file)
@@ -9,7 +9,6 @@
 #define MOD_PATH "@MODULE_PATH@"\r
 #define DATA_PATH "@DATA_PATH@"\r
 #define LOG_PATH "@LOG_PATH@"\r
-#define MAXBUF 514\r
 \r
 #include "inspircd_win32wrapper.h"\r
 #include "threadengines/threadengine_win32.h"\r
index 38754d5df4abf0bac8d5741b109ade9c8cf2c6d0..8234dfefecbab615bdf1c9714990cc6b8c9cd451 100644 (file)
@@ -101,6 +101,9 @@ __inline void sleep(int seconds) { Sleep(seconds * 1000); }
 #define popen _popen
 #define pclose _pclose
 
+/* _access */
+#define access _access
+
 /* IPV4 only convert string to address struct */
 __inline int inet_aton(const char *cp, struct in_addr *addr)
 {