From e1d69806ed7c92bdfe1bf632064bf68b3d1d266b Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 12 Nov 2014 04:05:56 +0100 Subject: =?UTF-8?q?Rename=20iq=5Fresponder=5Fcallback=5Ft=20to=20irc=5F?= =?UTF-8?q?=E2=80=A6=20and=20add=20the=20equivalent=20to=20wait=20for=20iq?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xmpp/xmpp_component.cpp | 9 +++++++++ src/xmpp/xmpp_component.hpp | 14 ++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'src/xmpp') diff --git a/src/xmpp/xmpp_component.cpp b/src/xmpp/xmpp_component.cpp index 1aa98b0..948e680 100644 --- a/src/xmpp/xmpp_component.cpp +++ b/src/xmpp/xmpp_component.cpp @@ -577,6 +577,15 @@ void XmppComponent::handle_iq(const Stanza& stanza) const Iid iid(to.local); bridge->send_xmpp_version_to_irc(iid, name, version, os); } + else + { + const auto it = this->waiting_iq.find(id); + if (it != this->waiting_iq.end()) + { + it->second(bridge, stanza); + this->waiting_iq.erase(it); + } + } } error_type = "cancel"; error_name = "feature-not-implemented"; diff --git a/src/xmpp/xmpp_component.hpp b/src/xmpp/xmpp_component.hpp index 9f1cec3..6ccc753 100644 --- a/src/xmpp/xmpp_component.hpp +++ b/src/xmpp/xmpp_component.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #define STREAM_NS "http://etherx.jabber.org/streams" #define COMPONENT_NS "jabber:component:accept" @@ -23,6 +24,11 @@ #define STREAMS_NS "urn:ietf:params:xml:ns:xmpp-streams" #define VERSION_NS "jabber:iq:version" #define ADHOC_NS "http://jabber.org/protocol/commands" +/** + * A callback called when the waited iq result is received (it is matched + * against the iq id) + */ +using iq_responder_callback_t = std::function; /** * An XMPP component, communicating with an XMPP server using the protocole @@ -256,6 +262,14 @@ private: std::unordered_map> stanza_handlers; AdhocCommandsHandler adhoc_commands_handler; + /** + * A map of id -> callback. When we want to wait for an iq result, we add + * the callback to this map, with the iq id as the key. When an iq result + * is received, we look for a corresponding callback in this map. If + * found, we call it and remove it. + */ + std::map waiting_iq; + /** * One bridge for each user of the component. Indexed by the user's full * jid -- cgit v1.2.3