]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add <define> configuration tag
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 18 Oct 2009 17:58:49 +0000 (17:58 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 18 Oct 2009 17:58:49 +0000 (17:58 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11907 e03df62e-2008-0410-955e-edbf42e46eb7

conf/inspircd.conf.example
conf/modules.conf.example
src/configreader.cpp

index dab2519fb0d8f4df06730c49059db16aa05e0b68..726605b16b937808cd641004e873644e27e7a71a 100644 (file)
@@ -46,9 +46,8 @@
 # file you include will be treated as part of the configuration file  #
 # which includes it, in simple terms the inclusion is transparent.    #
 #                                                                     #
-# All paths to config files are relative to the directory of the main #
-# config file inspircd.conf, unless the filename starts with a forward#
-# slash (/) in which case it is treated as an absolute path.          #
+# All paths to config files are relative to the directory that the    #
+# process runs in.                                                    #
 #                                                                     #
 # You may also include an executable file, in which case if you do so #
 # the output of the executable on the standard output will be added   #
 #                                                                     #
 
 
+#-#-#-#-#-#-#-#-#-#-#-#  VARIABLE DEFINITIONS  -#-#-#-#-#-#-#-#-#-#-#-#
+#                                                                     #
+# You can define variables that will be substituted later in the      #
+# configuration file. This can be useful to allow settings to be      #
+# easily changed, or to parameterize a remote includes.               #
+#                                                                     #
+# Variables may be redefined and may reference other variables.       #
+# Value expansion happens at the time the tag is read.                #
+#                                                                     #
+<define name="bindip" value="1.2.2.3">
+<define name="localips" value="&bindip;/24">
+
 #-#-#-#-#-#-#-#-#-#-#-#-  SERVER DESCRIPTION  -#-#-#-#-#-#-#-#-#-#-#-#-
 #                                                                     #
 #   Here is where you enter the information about your server.        #
 
 <bind address="" port="6660-6669" type="clients">
 
-# When linking servers, the openssl and gnutls transports are largely
+# When linking servers, the openssl and gnutls transports are completely
 # link-compatible and can be used alongside each other
 # on each end of the link without any significant issues.
 # Transports can only be used on server blocks.
-# Supported Transports are: "zip", "openssl" and "gnutls".
+# Supported Transports are: "ziplinks", "openssl" and "gnutls".
 # You must load m_ziplinks module for zip, m_ssl_openssl for openssl
 # or m_ssl_gnutls for gnutls.
 
 
          # prefixpart: What (if anything) a users' part message
          # should be prefixed with.
-         prefixpart="\""
+         prefixpart="&quot;"
 
          # suffixpart: What (if anything) a users' part message
          # should be suffixed with.
-         suffixpart="\""
+         suffixpart="&quot;"
 
          # fixedquit: Set all users' quit messages to this value.
          #fixedquit=""
index 9be66715943606b8db1449875993b35787408968..4dca4f3b90f718afa3e2de7bcb2cbc6964f9e086 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 \n. If you wish to use the ACTUAL  #
-#                    characters \ and n together in a line, you must  #
-#                    use the sequence "\\n".                          #
+#                    commands with a newline (&nl;).                  #
 #                                                                     #
 # requires    -      If you provide a value for 'requires' this means #
 #                    the given nickname MUST be online for the alias  #
        qprefix="~"
 
        # aprefix: Prefix (symbol) to use for +a users.
-       aprefix="&"
+       aprefix="&amp;"
 
        # deprotectself: If this value is set (true, yes or 1), it will allow
        # +a and +q users to remove the +a and +q from themselves, otherwise,
index 35196343dd75e4afed7fc84d3dbe8e2e9a29c3c1..b586db5316c0ebc902a156e70d929ed01b3d23f7 100644 (file)
@@ -53,12 +53,17 @@ enum ParseFlags
 struct ParseStack
 {
        std::vector<std::string> reading;
+       std::map<std::string, std::string> vars;
        ConfigDataHash& output;
        std::stringstream& errstr;
 
        ParseStack(ServerConfig* conf)
                : output(conf->config_data), errstr(conf->errstr)
-       { }
+       {
+               vars["amp"] = "&";
+               vars["quot"] = "\"";
+               vars["newline"] = vars["nl"] = "\n";
+       }
        bool ParseFile(const std::string& name, int flags);
        bool ParseExec(const std::string& name, int flags);
        void DoInclude(ConfigTag* includeTag, int flags);
@@ -161,13 +166,27 @@ struct Parser
                while (1)
                {
                        ch = next();
-                       if (ch == '\\')
+                       if (ch == '&')
                        {
-                               ch = next();
-                               if (ch == 'n')
-                                       ch = '\n';
-                               else if (ch == 'r')
-                                       ch = '\r';
+                               std::string varname;
+                               while (1)
+                               {
+                                       ch = next();
+                                       if (isalnum(ch))
+                                               varname.push_back(ch);
+                                       else if (ch == ';')
+                                               break;
+                                       else
+                                       {
+                                               stack.errstr << "Invalid XML entity name in value of <" + tag->tag + ":" + key + ">\n"
+                                                       << "To include an ampersand or quote, use &amp; or &quot;\n";
+                                               throw CoreException("Parse error");
+                                       }
+                               }
+                               std::map<std::string, std::string>::iterator var = stack.vars.find(varname);
+                               if (var == stack.vars.end())
+                                       throw CoreException("Undefined XML entity reference '&" + varname + ";'");
+                               value.append(var->second);
                        }
                        else if (ch == '"')
                                break;
@@ -194,13 +213,21 @@ struct Parser
 
                while (kv());
 
-               if (tag->tag == "include")
+               if (name == "include")
                {
                        stack.DoInclude(tag, flags);
                }
+               else if (name == "define")
+               {
+                       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
                {
-                       stack.output.insert(std::make_pair(tag->tag, tag));
+                       stack.output.insert(std::make_pair(name, tag));
                }
                // this is not a leak; reference<> takes care of the delete
                tag = NULL;