diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-06-11 00:42:55 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-06-11 00:49:42 +0200 |
commit | 5d1a567ea5b6407deff81f1ea02422d7a49441ec (patch) | |
tree | 6f0723676df12916758ff0197910feabe46b0fb0 | |
parent | 3ea029dd98e41b32609571512359277259e81057 (diff) | |
download | biboumi-5d1a567ea5b6407deff81f1ea02422d7a49441ec.tar.gz biboumi-5d1a567ea5b6407deff81f1ea02422d7a49441ec.tar.bz2 biboumi-5d1a567ea5b6407deff81f1ea02422d7a49441ec.tar.xz biboumi-5d1a567ea5b6407deff81f1ea02422d7a49441ec.zip |
Handle the 'cancel' ad-hoc action, and return an error for unsupported actions
ref #2521
-rw-r--r-- | src/xmpp/adhoc_commands_handler.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/xmpp/adhoc_commands_handler.cpp b/src/xmpp/adhoc_commands_handler.cpp index d288b40..7e1738a 100644 --- a/src/xmpp/adhoc_commands_handler.cpp +++ b/src/xmpp/adhoc_commands_handler.cpp @@ -31,8 +31,6 @@ const std::map<const std::string, const AdhocCommand>& AdhocCommandsHandler::get XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid, XmlNode command_node) { - // TODO check the type of action. Currently it assumes it is always - // 'execute'. std::string action = command_node.get_tag("action"); if (action.empty()) action = "execute"; @@ -88,7 +86,7 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid, error.close(); command_node.add_child(std::move(error)); } - else + else if (action == "execute" || action == "next" || action == "complete") { // execute the step AdhocSession& session = session_it->second; @@ -112,10 +110,23 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid, command_node.add_child(std::move(actions)); } } + else if (action == "cancel") + { + this->sessions.erase(session_it); + command_node["status"] = "canceled"; + TimedEventsManager::instance().cancel("adhocsession"s + sessionid + executor_jid); + } + else // unsupported action + { + XmlNode error(ADHOC_NS":error"); + error["type"] = "modify"; + XmlNode condition(STANZA_NS":bad-request"); + condition.close(); + error.add_child(std::move(condition)); + error.close(); + command_node.add_child(std::move(error)); + } } - // TODO remove that once we make sure so session can stay there for ever, - // by mistake. - log_debug("Number of existing sessions: " << this->sessions.size()); return std::move(command_node); } |