diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-05-27 01:01:38 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-05-30 03:58:17 +0200 |
commit | eb9a20187098185cc10ad192e91a90dbba12633a (patch) | |
tree | b8bc59e7120d0c965642de875a8498f50bfd9da4 /src/xmpp/adhoc_commands_handler.hpp | |
parent | 1c93afc9a7ec33d90c81062c3f1077b5cf84c212 (diff) | |
download | biboumi-eb9a20187098185cc10ad192e91a90dbba12633a.tar.gz biboumi-eb9a20187098185cc10ad192e91a90dbba12633a.tar.bz2 biboumi-eb9a20187098185cc10ad192e91a90dbba12633a.tar.xz biboumi-eb9a20187098185cc10ad192e91a90dbba12633a.zip |
Implement the support for adhoc commands
We have two basic example commands. But it’s not entirely finished because
there are some error checks that we don’t do.
ref #2521
Diffstat (limited to 'src/xmpp/adhoc_commands_handler.hpp')
-rw-r--r-- | src/xmpp/adhoc_commands_handler.hpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/xmpp/adhoc_commands_handler.hpp b/src/xmpp/adhoc_commands_handler.hpp new file mode 100644 index 0000000..6e00188 --- /dev/null +++ b/src/xmpp/adhoc_commands_handler.hpp @@ -0,0 +1,56 @@ +#ifndef ADHOC_COMMANDS_HANDLER_HPP +# define ADHOC_COMMANDS_HANDLER_HPP + +/** + * 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(); + ~AdhocCommandsHandler(); + /** + * Returns the list of available commands. + */ + const std::map<const std::string, const AdhocCommand>& get_commands() const; + /** + * 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, XmlNode command_node); +private: + /** + * The list of all available commands. + */ + const 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; + + AdhocCommandsHandler(const AdhocCommandsHandler&) = delete; + AdhocCommandsHandler(AdhocCommandsHandler&&) = delete; + AdhocCommandsHandler& operator=(const AdhocCommandsHandler&) = delete; + AdhocCommandsHandler& operator=(AdhocCommandsHandler&&) = delete; +}; + +#endif // ADHOC_COMMANDS_HANDLER_HPP |