summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/inspircd.conf.example25
-rw-r--r--conf/modules.conf.example6
-rw-r--r--src/configreader.cpp45
3 files changed, 56 insertions, 20 deletions
diff --git a/conf/inspircd.conf.example b/conf/inspircd.conf.example
index dab2519fb..726605b16 100644
--- a/conf/inspircd.conf.example
+++ b/conf/inspircd.conf.example
@@ -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 #
@@ -63,6 +62,18 @@
# #
+#-#-#-#-#-#-#-#-#-#-#-# 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. #
@@ -150,11 +161,11 @@
<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.
@@ -461,11 +472,11 @@
# 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=""
diff --git a/conf/modules.conf.example b/conf/modules.conf.example
index 9be667159..4dca4f3b9 100644
--- a/conf/modules.conf.example
+++ b/conf/modules.conf.example
@@ -126,9 +126,7 @@
# "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 #
@@ -414,7 +412,7 @@
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,
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 35196343d..b586db531 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -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;