]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
It compiles; ship it.
[user/henk/code/inspircd.git] / src / configreader.cpp
index 993183b4151076650048e7595c1246cfa4d8bc9e..47c8ec234e164047149133273c31376b32317e99 100644 (file)
@@ -1142,6 +1142,15 @@ void ServerConfig::Read(bool bail, User* user, int pass)
                 * at this point
                 */
 
+               if (pass == 0)
+               {
+                       if (isatty(0) && isatty(1) && isatty(2))
+                               printf("Downloading configuration ");
+
+                       TotalDownloaded = 0;
+                       FileErrors = 0;
+               }
+
                if (!ServerInstance->Res)
                        ServerInstance->Res = new DNS(ServerInstance);
                /** Note: This is safe, the method checks for user == NULL */
@@ -1255,28 +1264,26 @@ bool ServerConfig::Downloading()
                fflush(stdout);
        }
 
+       ServerInstance->Log(DEBUG, "ServerConfig::Downloading %d %d", TotalDownloaded, IncludedFiles.size());
+
        /* Returns true if there are still files in the process of downloading */
        return (TotalDownloaded < IncludedFiles.size());
 }
 
 void ServerConfig::Complete(const std::string &filename, bool error)
 {
+       ServerInstance->Log(DEBUG,"Flag complete: %s %d", filename.c_str(), error);
        std::map<std::string, std::istream*>::iterator x = IncludedFiles.find(filename);
 
        if (x != IncludedFiles.end())
        {
-               TotalDownloaded++;
                if (error)
                {
                        delete x->second;
                        x->second = NULL;
                        FileErrors++;
                }
-
-               /* We should parse the new file here and check it for another level of include files */
-               CompletedFiles[filename] = true;
-               LoadConf(this->newconfig, filename, errstr, 0, x->second);
-               StartDownloads();
+               TotalDownloaded++;
        }
 
        return;
@@ -1284,20 +1291,15 @@ void ServerConfig::Complete(const std::string &filename, bool error)
 
 void ServerConfig::StartDownloads()
 {
-       if (isatty(0) && isatty(1) && isatty(2))
-               printf("Downloading configuration ");
-
-       TotalDownloaded = 0;
-       FileErrors = 0;
+       ServerInstance->Log(DEBUG,"((((((((((((((((((((((((( StartDownloads() size=%d )))))))))))))))))))))))))))))))))))))", IncludedFiles.size());
 
        /* Reads all local files into the IncludedFiles map, then initiates sockets for the remote ones */
        for (std::map<std::string, std::istream*>::iterator x = IncludedFiles.begin(); x != IncludedFiles.end(); ++x)
        {
                if (CompletedFiles.find(x->first) != CompletedFiles.end())
-               {
-                       ServerInstance->Log(DEBUG, "Already fetched: %s", x->first.c_str());
                        continue;
-               }
+
+               ServerInstance->Log(DEBUG,"StartDownloads File: %s", x->first.c_str());
 
                std::string file = x->first;
                if ((file[0] == '/') || (file.substr(0, 7) == "file://"))
@@ -1339,9 +1341,7 @@ void ServerConfig::StartDownloads()
                                x->second = NULL;
                        }
                }
-
-               CompletedFiles[file] = true;
-               ServerInstance->Log(DEBUG, "Flagging as already fetched: %s", file.c_str());
+               CompletedFiles[x->first] = true;
        }
 }
 
@@ -1377,7 +1377,6 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                errorstream << "File " << filename << " could not be opened." << std::endl;
                                return false;
                        }
-                       CompletedFiles[filename] = true;
                }
        }
        else
@@ -1387,13 +1386,10 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                {
                        if (pass == 0)
                        {
-                               if (CompletedFiles.find(filename) == CompletedFiles.end())
-                               {
-                                       ServerInstance->Log(DEBUG,"Push include file %s onto map", filename);
-                                       /* First pass, we insert the file into a map, and just return true */
-                                       IncludedFiles.insert(std::make_pair(filename,new std::stringstream));
-                                       return true;
-                               }
+                               ServerInstance->Log(DEBUG,"Push include file %s onto map", filename);
+                               /* First pass, we insert the file into a map, and just return true */
+                               IncludedFiles.insert(std::make_pair(filename,new std::stringstream));
+                               return true;
                        }
                        else
                        {
@@ -1435,7 +1431,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                if ((character_count++ < 2) && (ch == '\xFF' || ch == '\xFE'))
                {
                        errorstream << "File " << filename << " cannot be read, as it is encoded in braindead UTF-16. Save your file as plain ASCII!" << std::endl;
-                       delete conf;
+                       if (!scan_for_includes_only)
+                               delete conf;
                        return false;
                }
 
@@ -1491,7 +1488,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        else
                        {
                                errorstream << "End of file after a \\, what did you want to escape?: " << filename << ":" << linenumber << std::endl;
-                               delete conf;
+                               if (!scan_for_includes_only)
+                                       delete conf;
                                return false;
                        }
                }
@@ -1506,7 +1504,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                if (!in_quote)
                                {
                                        errorstream << "Got another opening < when the first one wasn't closed: " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                        }
@@ -1515,7 +1514,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                if (in_quote)
                                {
                                        errorstream << "We're in a quote but outside a tag, interesting. " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                                else
@@ -1568,7 +1568,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
 
                                        if (!this->ParseLine(target, line, linenumber, errorstream, pass, scan_for_includes_only))
                                        {
-                                               delete conf;
+                                               if (!scan_for_includes_only)
+                                                       delete conf;
                                                return false;
                                        }
 
@@ -1577,7 +1578,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                else
                                {
                                        errorstream << "Got a closing > when we weren't inside a tag: " << filename << ":" << linenumber << std::endl;
-                                       delete conf;
+                                       if (!scan_for_includes_only)
+                                               delete conf;
                                        return false;
                                }
                        }
@@ -1591,7 +1593,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        is a newline missing from the end of the file: " << filename << ":" << linenumber << std::endl;
        }
 
-       delete conf;
+       if (!scan_for_includes_only)
+               delete conf;
        return true;
 }
 
@@ -1699,14 +1702,7 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long &li
                                                got_key = false;
 
                                                if ((tagname == "include") && (current_key == "file"))
-                                               {
-                                                       if (scan_for_includes_only && (CompletedFiles.find(current_key) != CompletedFiles.end()))
-                                                       {
-                                                               current_key.clear();
-                                                               current_value.clear();
-                                                               continue;
-                                                       }
-                                                       
+                                               {       
                                                        if (!this->DoInclude(target, current_value, errorstream, pass, scan_for_includes_only))
                                                                return false;
                                                }
@@ -1727,7 +1723,8 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long &li
        }
 
        /* Finished parsing the tag, add it to the config hash */
-       target.insert(std::pair<std::string, KeyValList > (tagname, results));
+       if (!scan_for_includes_only)
+               target.insert(std::pair<std::string, KeyValList > (tagname, results));
 
        return true;
 }
@@ -1758,7 +1755,7 @@ bool ServerConfig::DoInclude(ConfigDataHash &target, const std::string &file, st
                }
        }
 
-       return LoadConf(target, newfile, errorstream, pass);
+       return LoadConf(target, newfile, errorstream, pass, scan_for_includes_only);
 }
 
 bool ServerConfig::ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds)