* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2010 InspIRCd Development Team
* See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
struct Parser
{
ParseStack& stack;
- const int flags;
+ int flags;
FILE* const file;
fpos current;
fpos last_tag;
unget(ch);
}
- bool kv()
+ bool kv(std::vector<KeyVal>* items)
{
std::string key;
nextword(key);
while (1)
{
ch = next();
- if (ch == '&')
+ if (ch == '&' && (flags & FLAG_USE_XML))
{
std::string varname;
while (1)
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;
- value.push_back(ch);
+ else
+ value.push_back(ch);
}
- tag->items.push_back(KeyVal(key, value));
+ items->push_back(KeyVal(key, value));
return true;
}
if (name.empty())
throw CoreException("Empty tag name");
- tag = new ConfigTag(name, current.filename, current.line);
+ std::vector<KeyVal>* items;
+ tag = ConfigTag::create(name, current.filename, current.line, items);
- while (kv());
+ while (kv(items));
if (name == "include")
{
}
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));
return src_name + ":" + ConvToStr(src_line);
}
+ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*&items)
+{
+ ConfigTag* rv = new ConfigTag(Tag, file, line);
+ items = &rv->items;
+ return rv;
+}
+
+ConfigTag::ConfigTag(const std::string& Tag, const std::string& file, int line)
+ : tag(Tag), src_name(file), src_line(line)
+{
+}
+
std::string OperInfo::getConfig(const std::string& key)
{
std::string rv;