summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-18 17:58:49 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-18 17:58:49 +0000
commit1db755d190e2a6f099905d1ba11ca01c6b273dc9 (patch)
tree9f40951697015e92294cd13bf28c0d5611627fd4 /src
parent4fca1ffbc43dd0eda8e6df665dac0fa83512daf8 (diff)
Add <define> configuration tag
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11907 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp45
1 files changed, 36 insertions, 9 deletions
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;