summaryrefslogtreecommitdiff
path: root/src/configparser.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-02 16:47:25 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-02 16:47:25 +0000
commitf2256deeefe9a9f57f6f6b902604c01138ad16cc (patch)
tree2180cffd6bec0487e3d8b5a7d5894b258782e39c /src/configparser.cpp
parentf288993a85681c09e3d92d8c3ab9742826923e99 (diff)
Executable include for MOTD and more
This introduces an <execfiles> tag that reads files from the output of a command, in the same way as executable includes. The files specified here can also be used anywhere a file is used (opermotd, randquote, etc) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12354 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/configparser.cpp')
-rw-r--r--src/configparser.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp
index 0e77cbb36..558c49117 100644
--- a/src/configparser.cpp
+++ b/src/configparser.cpp
@@ -177,6 +177,20 @@ struct Parser
{
stack.DoInclude(tag, flags);
}
+ else if (name == "files")
+ {
+ for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+ {
+ stack.DoReadFile(i->first, i->second, flags, false);
+ }
+ }
+ else if (name == "execfiles")
+ {
+ for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++)
+ {
+ stack.DoReadFile(i->first, i->second, flags, true);
+ }
+ }
else if (name == "define")
{
if (!(flags & FLAG_USE_XML))
@@ -275,6 +289,29 @@ void ParseStack::DoInclude(ConfigTag* tag, int flags)
}
}
+void ParseStack::DoReadFile(const std::string& key, const std::string& name, int flags, bool exec)
+{
+ if (flags & FLAG_NO_INC)
+ throw CoreException("Invalid <files> tag in file included with noinclude=\"yes\"");
+ if (exec && (flags & FLAG_NO_EXEC))
+ throw CoreException("Invalid <execfiles> tag in file included with noexec=\"yes\"");
+
+ FileWrapper file(exec ? popen(name.c_str(), "r") : fopen(name.c_str(), "r"));
+ if (!file)
+ throw CoreException("Could not read \"" + name + "\" for \"" + key + "\" file");
+
+ file_cache& cache = FilesOutput[key];
+ cache.clear();
+
+ char linebuf[MAXBUF*10];
+ while (fgets(linebuf, sizeof(linebuf), file))
+ {
+ int len = strlen(linebuf);
+ if (len)
+ cache.push_back(std::string(linebuf, len - 1));
+ }
+}
+
bool ParseStack::ParseFile(const std::string& name, int flags)
{
ServerInstance->Logs->Log("CONFIG", DEBUG, "Reading file %s", name.c_str());