]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
Re-added required parts of connection.h
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index a01048e8548f8c6cab7ac2e936256eec19695b82..aa5d5af65cb35137ae2b18599aa09ca7f9ab2d1f 100644 (file)
@@ -179,7 +179,7 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors
                return "";
        }
        // firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces
-       for (int d = 0; d < strlen(buffer); d++)
+       for (unsigned int d = 0; d < strlen(buffer); d++)
                if ((buffer[d]) == 9)
                        buffer[d] = ' ';
        while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++;
@@ -189,7 +189,7 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors
                return "";
        else if (buffer[0] == '#')
                return "";
-       for (int c = 0; c < strlen(buffer); c++)
+       for (unsigned int c = 0; c < strlen(buffer); c++)
        {
                // convert all spaces that are OUTSIDE quotes into hardspace (0xA0) as this will make them easier to
                // search and replace later :)
@@ -276,7 +276,7 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors
        }
 
        // turn our hardspace back into softspace
-       for (int d = 0; d < parsedata.length(); d++)
+       for (unsigned int d = 0; d < parsedata.length(); d++)
        {
                if (parsedata[d] == '\xA0')
                        parsedata[d] = ' ';
@@ -286,6 +286,20 @@ std::string ConfProcess(char* buffer, long linenumber, std::stringstream* errors
        return parsedata;
 }
 
+int fgets_safe(char* buffer, size_t maxsize, FILE* &file)
+{
+       char c_read = '\0';
+       unsigned int bufptr = 0;
+       while ((!feof(file)) && (c_read != '\n') && (c_read != '\r') && (bufptr < maxsize))
+       {
+               c_read = fgetc(file);
+               if ((c_read != '\n') && (c_read != '\r'))
+                       buffer[bufptr++] = c_read;
+       }
+       buffer[bufptr] = '\0';
+       return bufptr;
+}
+
 bool LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream)
 {
        target->str("");
@@ -299,7 +313,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
        }
        // Fix the chmod of the file to restrict it to the current user and group
        chmod(filename,0600);
-       for (int t = 0; t < include_stack.size(); t++)
+       for (unsigned int t = 0; t < include_stack.size(); t++)
        {
                if (std::string(filename) == include_stack[t])
                {
@@ -315,7 +329,7 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
        {
                while (!feof(conf))
                {
-                       if (fgets(buffer, MAXBUF, conf))
+                       if (fgets_safe(buffer, MAXBUF, conf))
                        {
                                if ((!feof(conf)) && (buffer) && (strlen(buffer)))
                                {
@@ -327,8 +341,10 @@ bool LoadConf(const char* filename, std::stringstream *target, std::stringstream
                                                        char confpath[10240],newconf[10240];
                                                        // include file directive
                                                        buf += 15;      // advance to filename
-                                                       for (int j = 0; j < strlen(buffer); j++)
+                                                       for (unsigned int j = 0; j < strlen(buf); j++)
                                                        {
+                                                               if (buf[j] == '\\')
+                                                                       buf[j] = '/';
                                                                if (buf[j] == '"')
                                                                {
                                                                        buf[j] = '\0';
@@ -558,7 +574,7 @@ int ReadConf(std::stringstream *config, const char* tag, const char* var, int in
 {
        int ptr = 0;
        char buffer[65535], c_tag[MAXBUF], c, lastc;
-       int in_token, in_quotes, tptr, j, idx = 0;
+       int in_token, in_quotes, tptr, idx = 0;
        char* key;
 
        const char* buf = config->str().c_str();
@@ -626,7 +642,7 @@ int ReadConf(std::stringstream *config, const char* tag, const char* var, int in
                                                                key++;
                                                        }
                                                        key++;
-                                                       for (j = 0; j < strlen(key); j++)
+                                                       for (unsigned j = 0; j < strlen(key); j++)
                                                        {
                                                                if (key[j] == '"')
                                                                {