]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Clean up empty/unused directories
[user/henk/code/inspircd.git] / src / configreader.cpp
index 04763cbaba49c156701e2bca79f64303103c74d0..20cc0c2b3c30f63c3c8d15f9f9ceb7e98aa71713 100644 (file)
  * ---------------------------------------------------
  */
 
-/* $Core */
-/* $CopyInstall: conf/inspircd.quotes.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.rules.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.motd.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.helpop-full.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.helpop.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.censor.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.filter.example $(CONPATH) */
-/* $CopyInstall: conf/inspircd.conf.example $(CONPATH) */
-/* $CopyInstall: conf/modules.conf.example $(CONPATH) */
-/* $CopyInstall: conf/opers.conf.example $(CONPATH) */
-/* $CopyInstall: conf/links.conf.example $(CONPATH) */
-/* $CopyInstall: tools/gdbargs $(BASE)/.gdbargs */
-
 #include "inspircd.h"
 #include <fstream>
 #include "xline.h"
@@ -51,28 +37,29 @@ ServerConfig::ServerConfig()
 void ServerConfig::Update005()
 {
        std::stringstream out(data005);
+       std::vector<std::string> data;
        std::string token;
+       while (out >> token)
+               data.push_back(token);
+       sort(data.begin(), data.end());
+
        std::string line5;
-       int token_counter = 0;
        isupport.clear();
-       while (out >> token)
+       for(unsigned int i=0; i < data.size(); i++)
        {
+               token = data[i];
                line5 = line5 + token + " ";
-               token_counter++;
-               if (token_counter >= 13)
+               if (i % 13 == 12)
                {
-                       char buf[MAXBUF];
-                       snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
-                       isupport.push_back(buf);
+                       line5.append(":are supported by this server");
+                       isupport.push_back(line5);
                        line5.clear();
-                       token_counter = 0;
                }
        }
        if (!line5.empty())
        {
-               char buf[MAXBUF];
-               snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
-               isupport.push_back(buf);
+               line5.append(":are supported by this server");
+               isupport.push_back(line5);
        }
 }
 
@@ -261,9 +248,16 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                for(ClassVector::iterator i = current->Classes.begin(); i != current->Classes.end(); ++i)
                {
                        ConnectClass* c = *i;
-                       std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
-                       typeMask += c->host;
-                       oldBlocksByMask[typeMask] = c;
+                       if (c->name.substr(0, 8) != "unnamed-")
+                       {
+                               oldBlocksByMask["n" + c->name] = c;
+                       }
+                       else if (c->type == CC_ALLOW || c->type == CC_DENY)
+                       {
+                               std::string typeMask = (c->type == CC_ALLOW) ? "a" : "d";
+                               typeMask += c->host;
+                               oldBlocksByMask[typeMask] = c;
+                       }
                }
        }
 
@@ -278,7 +272,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                blk_count = 1;
        }
 
-       ClassMap newBlocksByMask;
        Classes.resize(blk_count);
        std::map<std::string, int> names;
 
@@ -304,22 +297,13 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                                        try_again = true;
                                        // couldn't find parent this time. If it's the last time, we'll never find it.
                                        if (tries >= blk_count)
-                                               throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block " + ConvToStr(i));
+                                               throw CoreException("Could not find parent connect class \"" + parentName + "\" for connect block at " + tag->getTagLocation());
                                        continue;
                                }
                                parent = Classes[parentIter->second];
                        }
 
                        std::string name = tag->getString("name");
-                       if (name.empty())
-                       {
-                               name = "unnamed-" + ConvToStr(i);
-                       }
-
-                       if (names.find(name) != names.end())
-                               throw CoreException("Two connect classes with name \"" + name + "\" defined!");
-                       names[name] = i;
-
                        std::string mask, typeMask;
                        char type;
 
@@ -333,13 +317,29 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                                type = CC_DENY;
                                typeMask = 'd' + mask;
                        }
+                       else if (!name.empty())
+                       {
+                               type = CC_NAMED;
+                               mask = name;
+                               typeMask = 'n' + mask;
+                       }
                        else
                        {
-                               throw CoreException("Connect class must have an allow or deny mask at " + tag->getTagLocation());
+                               throw CoreException("Connect class must have allow, deny, or name specified at " + tag->getTagLocation());
                        }
-                       ClassMap::iterator dupMask = newBlocksByMask.find(typeMask);
-                       if (dupMask != newBlocksByMask.end())
-                               throw CoreException("Two connect classes cannot have the same mask (" + mask + ")");
+
+                       if (name.empty())
+                       {
+                               name = "unnamed-" + ConvToStr(i);
+                       }
+                       else
+                       {
+                               typeMask = 'n' + name;
+                       }
+
+                       if (names.find(name) != names.end())
+                               throw CoreException("Two connect classes with name \"" + name + "\" defined!");
+                       names[name] = i;
 
                        ConnectClass* me = parent ? 
                                new ConnectClass(tag, type, mask, *parent) :
@@ -347,8 +347,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
 
                        me->name = name;
 
-                       tag->readString("password", me->pass);
-                       tag->readString("hash", me->hash);
                        me->registration_timeout = tag->getInt("timeout", me->registration_timeout);
                        me->pingtime = tag->getInt("pingfreq", me->pingtime);
                        std::string sendq;
@@ -370,7 +368,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                        me->fakelag = tag->getBool("fakelag", me->fakelag);
                        me->maxlocal = tag->getInt("localmax", me->maxlocal);
                        me->maxglobal = tag->getInt("globalmax", me->maxglobal);
-                       me->port = tag->getInt("port", me->port);
                        me->maxchans = tag->getInt("maxchans", me->maxchans);
                        me->limit = tag->getInt("limit", me->limit);
 
@@ -383,7 +380,6 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current)
                                delete me;
                                me = old;
                        }
-                       newBlocksByMask[typeMask] = me;
                        Classes[i] = me;
                }
        }
@@ -578,8 +574,6 @@ void ServerConfig::Read()
        }
        if (valid)
        {
-               ReadFile(MOTD, ConfValue("files")->getString("motd"));
-               ReadFile(RULES, ConfValue("files")->getString("rules"));
                DNSServer = ConfValue("dns")->getString("server");
                FindDNS(DNSServer);
        }
@@ -782,34 +776,6 @@ ConfigTagList ServerConfig::ConfTags(const std::string& tag)
        return config_data.equal_range(tag);
 }
 
-/** Read the contents of a file located by `fname' into a file_cache pointed at by `F'.
- */
-bool ServerConfig::ReadFile(file_cache &F, const std::string& fname)
-{
-       if (fname.empty())
-               return false;
-
-       char linebuf[MAXBUF];
-
-       F.clear();
-
-       FileWrapper file(fopen(fname.c_str(), "r"));
-
-       if (!file)
-               return false;
-       while (!feof(file))
-       {
-               if (fgets(linebuf, sizeof(linebuf), file))
-                       linebuf[strlen(linebuf)-1] = 0;
-               else
-                       *linebuf = 0;
-
-               F.push_back(*linebuf ? linebuf : " ");
-       }
-
-       return true;
-}
-
 bool ServerConfig::FileExists(const char* file)
 {
        struct stat sb;