]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add <config:format> to avoid breaking existing configuration files with XML entity...
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 25 Oct 2009 00:02:28 +0000 (00:02 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 25 Oct 2009 00:02:28 +0000 (00:02 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11974 e03df62e-2008-0410-955e-edbf42e46eb7

conf/inspircd.conf.example
conf/modules.conf.example
include/configparser.h
src/configparser.cpp

index d5c9874df0955cb8c622b1cf294c702d48bb88a2..47ecd5889aeb63e537f2ab34a8e6a90a667efe06 100644 (file)
 # Variables may be redefined and may reference other variables.       #
 # Value expansion happens at the time the tag is read.                #
 #                                                                     #
+# Using variable definitions REQUIRES that the config format be       #
+# changed to "xml" from the default "compat" that uses escape         #
+# sequences such as "\"" and "\n", and does not support <define>      #
+<config format="xml">
 <define name="bindip" value="1.2.2.3">
 <define name="localips" value="&bindip;/24">
 
          # prefixpart: What (if anything) a users' part message
          # should be prefixed with.
          prefixpart="&quot;"
+         # NOTE: Use "\"" instead of "&quot;" if not using <config format="xml">
 
          # suffixpart: What (if anything) a users' part message
          # should be suffixed with.
index e9a306e3fc5310dc3c44dec4ef6d4aa71d70c063..91e45eb918f263f5063982039d965dc941afd372 100644 (file)
 #                    "baz qux quz" and $2 will contain "bar". You may #
 #                    also use the special variables: $nick, $ident,   #
 #                    $host and $vhost, and you may separate multiple  #
-#                    commands with a newline (&nl;).                  #
+#                    commands with a newline (which can be written in #
+#                    the file literally, or encoded as &nl; or \n     #
+#                    depending on the config format setting).         #
 #                                                                     #
 # requires    -      If you provide a value for 'requires' this means #
 #                    the given nickname MUST be online for the alias  #
index a1d7aff5bad5a6a0f994f3916bc341a92f601eb0..3240ff5f9360874afffff7d2ae79f18d66693460 100644 (file)
@@ -12,8 +12,9 @@ struct fpos
 
 enum ParseFlags
 {
-       FLAG_NO_EXEC = 1,
-       FLAG_NO_INC = 2
+       FLAG_USE_XML = 1,
+       FLAG_NO_EXEC = 2,
+       FLAG_NO_INC = 4
 };
 
 struct ParseStack
index 1373ae5af3b91d5ec120fc0746117fe6dd49f6f3..495d38fff4659336e23d68fa10c32914646d8030 100644 (file)
@@ -18,7 +18,7 @@
 struct Parser
 {
        ParseStack& stack;
-       const int flags;
+       int flags;
        FILE* const file;
        fpos current;
        fpos last_tag;
@@ -112,7 +112,7 @@ struct Parser
                while (1)
                {
                        ch = next();
-                       if (ch == '&')
+                       if (ch == '&' && (flags & FLAG_USE_XML))
                        {
                                std::string varname;
                                while (1)
@@ -134,6 +134,16 @@ struct Parser
                                        throw CoreException("Undefined XML entity reference '&" + varname + ";'");
                                value.append(var->second);
                        }
+                       else if (ch == '\\' && !(flags & FLAG_USE_XML))
+                       {
+                               int esc = next();
+                               if (esc == 'n')
+                                       value.push_back('\n');
+                               else if (isalpha(esc))
+                                       throw CoreException("Unknown escape character \\" + std::string(1, esc));
+                               else
+                                       value.push_back(esc);
+                       }
                        else if (ch == '"')
                                break;
                        else
@@ -169,12 +179,24 @@ struct Parser
                }
                else if (name == "define")
                {
+                       if (!(flags & FLAG_USE_XML))
+                               throw CoreException("<define> tags may only be used in XML-style config (add <config format=\"xml\">)");
                        std::string varname = tag->getString("name");
                        std::string value = tag->getString("value");
                        if (varname.empty())
                                throw CoreException("Variable definition must include variable name");
                        stack.vars[varname] = value;
                }
+               else if (name == "config")
+               {
+                       std::string format = tag->getString("format");
+                       if (format == "xml")
+                               flags |= FLAG_USE_XML;
+                       else if (format == "compat")
+                               flags &= ~FLAG_USE_XML;
+                       else if (!format.empty())
+                               throw CoreException("Unknown configuration format " + format);
+               }
                else
                {
                        stack.output.insert(std::make_pair(name, tag));