From 19666d2ffd3ce36b7edd4044143fe535ef85dbd9 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 18 Sep 2015 21:52:11 +0200 Subject: Store the target jid in the AdhocSession objects --- louloulibs/xmpp/adhoc_commands_handler.cpp | 4 ++-- louloulibs/xmpp/adhoc_commands_handler.hpp | 2 +- louloulibs/xmpp/adhoc_session.cpp | 6 ++++-- louloulibs/xmpp/adhoc_session.hpp | 16 +++++++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'louloulibs') diff --git a/louloulibs/xmpp/adhoc_commands_handler.cpp b/louloulibs/xmpp/adhoc_commands_handler.cpp index 458a22c..714c440 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.cpp +++ b/louloulibs/xmpp/adhoc_commands_handler.cpp @@ -20,7 +20,7 @@ std::map& AdhocCommandsHandler::get_comma return this->commands; } -XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, XmlNode command_node) +XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node) { std::string action = command_node.get_tag("action"); if (action.empty()) @@ -57,7 +57,7 @@ XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, Xm command_node["sessionid"] = sessionid; this->sessions.emplace(std::piecewise_construct, std::forward_as_tuple(sessionid, executor_jid), - std::forward_as_tuple(command_it->second, executor_jid)); + std::forward_as_tuple(command_it->second, executor_jid, to)); TimedEventsManager::instance().add_event(TimedEvent(std::chrono::steady_clock::now() + 3600s, std::bind(&AdhocCommandsHandler::remove_session, this, sessionid, executor_jid), "adhocsession"s + sessionid + executor_jid)); diff --git a/louloulibs/xmpp/adhoc_commands_handler.hpp b/louloulibs/xmpp/adhoc_commands_handler.hpp index 1083c44..cf9ca17 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.hpp +++ b/louloulibs/xmpp/adhoc_commands_handler.hpp @@ -41,7 +41,7 @@ public: * Takes a copy of the 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); + 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 diff --git a/louloulibs/xmpp/adhoc_session.cpp b/louloulibs/xmpp/adhoc_session.cpp index fc60bb7..bf8d292 100644 --- a/louloulibs/xmpp/adhoc_session.cpp +++ b/louloulibs/xmpp/adhoc_session.cpp @@ -3,9 +3,11 @@ #include -AdhocSession::AdhocSession(const AdhocCommand& command, const std::string& jid): +AdhocSession::AdhocSession(const AdhocCommand& command, const std::string& owner_jid, + const std::string& to_jid): command(command), - owner_jid(jid), + owner_jid(owner_jid), + to_jid(to_jid), current_step(0), terminated(false) { diff --git a/louloulibs/xmpp/adhoc_session.hpp b/louloulibs/xmpp/adhoc_session.hpp index ddfb2fe..da7913f 100644 --- a/louloulibs/xmpp/adhoc_session.hpp +++ b/louloulibs/xmpp/adhoc_session.hpp @@ -23,7 +23,8 @@ typedef std::function AdhocStep; class AdhocSession { public: - explicit AdhocSession(const AdhocCommand& command, const std::string& jid); + explicit AdhocSession(const AdhocCommand& command, const std::string& owner_jid, + const std::string& to_jid); ~AdhocSession(); /** * Return the function to be executed, found in our AdhocCommand, for the @@ -41,6 +42,15 @@ public: */ void terminate(); bool is_terminated() const; + std::string get_target_jid() const + { + return this->to_jid; + } + std::string get_owner_jid() const + { + return this->owner_jid; + } + private: /** @@ -54,6 +64,10 @@ private: * this session. */ const std::string& owner_jid; + /** + * The 'to' attribute in the request stanza. This is the target of the current session. + */ + const std::string& to_jid; /** * The current step we are at. It starts at zero. It is used to index the * associated AdhocCommand::callbacks vector. -- cgit v1.2.3