]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configparser.cpp
m_callerid Remove redundant includes
[user/henk/code/inspircd.git] / src / configparser.cpp
index 4a0c9b58da3dcd76ff604036f7acfe54f2721dd9..a8e36f6e0048c1c1c2a91a719ee81d575dcccbcb 100644 (file)
@@ -1,16 +1,22 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include <fstream>
 #include "configparser.h"
@@ -76,7 +82,7 @@ struct Parser
                int ch = next();
                while (isspace(ch))
                        ch = next();
-               while (isalnum(ch) || ch == '_')
+               while (isalnum(ch) || ch == '_'|| ch == '-')
                {
                        rv.push_back(ch);
                        ch = next();
@@ -84,7 +90,7 @@ struct Parser
                unget(ch);
        }
 
-       bool kv(std::vector<KeyVal>* items)
+       bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen)
        {
                std::string key;
                nextword(key);
@@ -149,6 +155,10 @@ struct Parser
                        else
                                value.push_back(ch);
                }
+
+               if (!seen.insert(key).second)
+                       throw CoreException("Duplicate key '" + key + "' found");
+
                items->push_back(KeyVal(key, value));
                return true;
        }
@@ -169,9 +179,10 @@ struct Parser
                        throw CoreException("Empty tag name");
 
                std::vector<KeyVal>* items;
+               std::set<std::string> seen;
                tag = ConfigTag::create(name, current.filename, current.line, items);
 
-               while (kv(items));
+               while (kv(items, seen));
 
                if (name == "include")
                {
@@ -306,9 +317,13 @@ void ParseStack::DoReadFile(const std::string& key, const std::string& name, int
        char linebuf[MAXBUF*10];
        while (fgets(linebuf, sizeof(linebuf), file))
        {
-               int len = strlen(linebuf);
+               size_t len = strlen(linebuf);
                if (len)
-                       cache.push_back(std::string(linebuf, len - 1));
+               {
+                       if (linebuf[len-1] == '\n')
+                               len--;
+                       cache.push_back(std::string(linebuf, len));
+               }
        }
 }