summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp8
-rw-r--r--src/utils/reload.cpp13
-rw-r--r--src/utils/reload.hpp10
-rw-r--r--src/xmpp/adhoc_command.cpp12
-rw-r--r--src/xmpp/adhoc_command.hpp1
-rw-r--r--src/xmpp/adhoc_commands_handler.cpp3
6 files changed, 40 insertions, 7 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 94c3cb5..148412e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,6 +3,7 @@
#include <network/poller.hpp>
#include <config/config.hpp>
#include <logger/logger.hpp>
+#include <utils/reload.hpp>
#include <iostream>
#include <memory>
@@ -123,13 +124,8 @@ int main(int ac, char** av)
}
if (reload)
{
- // Closing the config will just force it to be reopened the next time
- // a configuration option is needed
log_info("Signal received, reloading the config...");
- Config::close();
- // Destroy the logger instance, to be recreated the next time a log
- // line needs to be written
- Logger::instance().reset();
+ ::reload_process();
reload.store(false);
}
// Reconnect to the XMPP server if this was not intended. This may have
diff --git a/src/utils/reload.cpp b/src/utils/reload.cpp
new file mode 100644
index 0000000..6600c75
--- /dev/null
+++ b/src/utils/reload.cpp
@@ -0,0 +1,13 @@
+#include <config/config.hpp>
+#include <logger/logger.hpp>
+
+void reload_process()
+{
+ // Closing the config will just force it to be reopened the next time
+ // a configuration option is needed
+ Config::close();
+ // Destroy the logger instance, to be recreated the next time a log
+ // line needs to be written
+ Logger::instance().reset();
+ log_debug("Configuration and logger reloaded.");
+}
diff --git a/src/utils/reload.hpp b/src/utils/reload.hpp
new file mode 100644
index 0000000..16d64f7
--- /dev/null
+++ b/src/utils/reload.hpp
@@ -0,0 +1,10 @@
+#ifndef RELOAD_HPP_INCLUDED
+#define RELOAD_HPP_INCLUDED
+
+/**
+ * Reload the server's configuration, and close the logger (so that it
+ * closes its files etc, to take into account the new configuration)
+ */
+void reload_process();
+
+#endif /* RELOAD_HPP_INCLUDED */
diff --git a/src/xmpp/adhoc_command.cpp b/src/xmpp/adhoc_command.cpp
index e1bfc97..c20976a 100644
--- a/src/xmpp/adhoc_command.cpp
+++ b/src/xmpp/adhoc_command.cpp
@@ -3,6 +3,8 @@
#include <bridge/bridge.hpp>
+#include <utils/reload.hpp>
+
using namespace std::string_literals;
AdhocCommand::AdhocCommand(std::vector<AdhocStep>&& callbacks, const std::string& name, const bool admin_only):
@@ -198,3 +200,13 @@ void DisconnectUserStep2(XmppComponent* xmpp_component, AdhocSession& session, X
session.terminate();
}
+void Reload(XmppComponent*, AdhocSession& session, XmlNode& command_node)
+{
+ ::reload_process();
+ command_node.delete_all_children();
+ XmlNode note("note");
+ note["type"] = "info";
+ note.set_inner("Configuration reloaded.");
+ note.close();
+ command_node.add_child(std::move(note));
+}
diff --git a/src/xmpp/adhoc_command.hpp b/src/xmpp/adhoc_command.hpp
index 60f7d6c..622d6b9 100644
--- a/src/xmpp/adhoc_command.hpp
+++ b/src/xmpp/adhoc_command.hpp
@@ -40,5 +40,6 @@ void HelloStep1(XmppComponent*, AdhocSession& session, XmlNode& command_node);
void HelloStep2(XmppComponent*, AdhocSession& session, XmlNode& command_node);
void DisconnectUserStep1(XmppComponent*, AdhocSession& session, XmlNode& command_node);
void DisconnectUserStep2(XmppComponent*, AdhocSession& session, XmlNode& command_node);
+void Reload(XmppComponent*, AdhocSession& session, XmlNode& command_node);
#endif // ADHOC_COMMAND_HPP
diff --git a/src/xmpp/adhoc_commands_handler.cpp b/src/xmpp/adhoc_commands_handler.cpp
index a0defdd..def1dcb 100644
--- a/src/xmpp/adhoc_commands_handler.cpp
+++ b/src/xmpp/adhoc_commands_handler.cpp
@@ -15,7 +15,8 @@ AdhocCommandsHandler::AdhocCommandsHandler(XmppComponent* xmpp_component):
commands{
{"ping", AdhocCommand({&PingStep1}, "Do a ping", false)},
{"hello", AdhocCommand({&HelloStep1, &HelloStep2}, "Receive a custom greeting", false)},
- {"disconnect-user", AdhocCommand({&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect a user from the gateway", true)}
+ {"disconnect-user", AdhocCommand({&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect a user from the gateway", true)},
+ {"reload", AdhocCommand({&Reload}, "Reload biboumi’s configuration", true)}
}
{
}