summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/adhoc_commands_handler.hpp
diff options
context:
space:
mode:
authorVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
committerVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
commit4e4de7284e6e4d89d182ea459823bbec1e408842 (patch)
tree47e0ed5216b48649b138f168f61fddca2b0c076a /louloulibs/xmpp/adhoc_commands_handler.hpp
parentdfb3a6edfacf2f16a8a63690b3e8058b6295d1a3 (diff)
parenteda4b75b1cff83336e87da90efca9fd6b4ced2c7 (diff)
downloadbiboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.gz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.bz2
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.xz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.zip
Updated version 3.0 from 'upstream/3.0'
with Debian dir 0f18938e98f5a466f36719f60cef0490163ab845
Diffstat (limited to 'louloulibs/xmpp/adhoc_commands_handler.hpp')
-rw-r--r--louloulibs/xmpp/adhoc_commands_handler.hpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/louloulibs/xmpp/adhoc_commands_handler.hpp b/louloulibs/xmpp/adhoc_commands_handler.hpp
new file mode 100644
index 0000000..91eb5bd
--- /dev/null
+++ b/louloulibs/xmpp/adhoc_commands_handler.hpp
@@ -0,0 +1,71 @@
+#pragma once
+
+/**
+ * Manage a list of available AdhocCommands and the list of ongoing
+ * AdhocCommandSessions.
+ */
+
+#include <xmpp/adhoc_command.hpp>
+#include <xmpp/xmpp_stanza.hpp>
+
+#include <utility>
+#include <string>
+#include <map>
+
+class AdhocCommandsHandler
+{
+public:
+ explicit AdhocCommandsHandler(XmppComponent& xmpp_component):
+ xmpp_component(xmpp_component),
+ commands{}
+ { }
+ ~AdhocCommandsHandler() = default;
+
+ AdhocCommandsHandler(const AdhocCommandsHandler&) = delete;
+ AdhocCommandsHandler(AdhocCommandsHandler&&) = delete;
+ AdhocCommandsHandler& operator=(const AdhocCommandsHandler&) = delete;
+ AdhocCommandsHandler& operator=(AdhocCommandsHandler&&) = delete;
+
+ /**
+ * Returns the list of available commands.
+ */
+ const std::map<const std::string, const AdhocCommand>& get_commands() const;
+ /**
+ * This one can be used to add new commands.
+ */
+ std::map<const std::string, const AdhocCommand>& get_commands();
+ /**
+ * Find the requested command, create a new session or use an existing
+ * one, and process the request (provide a new form, an error, or a
+ * result).
+ *
+ * Returns a (moved) XmlNode that will be inserted in the iq response. It
+ * should be a <command/> node containing one or more useful children. If
+ * it contains an <error/> node, the iq response will have an error type.
+ *
+ * Takes a copy of the <command/> node so we can actually edit it and use
+ * it as our return value.
+ */
+ XmlNode handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node);
+ /**
+ * Remove the session from the list. This is done to avoid filling the
+ * memory with waiting session (for example due to a client that starts
+ * multi-steps command but never finishes them).
+ */
+ void remove_session(const std::string& session_id, const std::string& initiator_jid);
+private:
+ /**
+ * To access basically anything in the gateway.
+ */
+ XmppComponent& xmpp_component;
+ /**
+ * The list of all available commands.
+ */
+ std::map<const std::string, const AdhocCommand> commands;
+ /**
+ * The list of all currently on-going commands.
+ *
+ * Of the form: {{session_id, owner_jid}, session}.
+ */
+ std::map<std::pair<const std::string, const std::string>, AdhocSession> sessions;
+};