summaryrefslogtreecommitdiff
path: root/src/xmpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-11-12 04:05:56 +0100
committerFlorent Le Coz <louiz@louiz.org>2014-11-12 06:17:25 +0100
commite1d69806ed7c92bdfe1bf632064bf68b3d1d266b (patch)
treea2aa251c02c074e7f0babd970bff4388f22310b4 /src/xmpp
parentdccd8039ad44669452fa47d9b620114fd97af604 (diff)
downloadbiboumi-e1d69806ed7c92bdfe1bf632064bf68b3d1d266b.tar.gz
biboumi-e1d69806ed7c92bdfe1bf632064bf68b3d1d266b.tar.bz2
biboumi-e1d69806ed7c92bdfe1bf632064bf68b3d1d266b.tar.xz
biboumi-e1d69806ed7c92bdfe1bf632064bf68b3d1d266b.zip
Rename iq_responder_callback_t to irc_… and add the equivalent to wait for iqs
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/xmpp_component.cpp9
-rw-r--r--src/xmpp/xmpp_component.hpp14
2 files changed, 23 insertions, 0 deletions
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 <unordered_map>
#include <memory>
#include <string>
+#include <map>
#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<void(Bridge* bridge, const Stanza& stanza)>;
/**
* An XMPP component, communicating with an XMPP server using the protocole
@@ -257,6 +263,14 @@ private:
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<std::string, iq_responder_callback_t> waiting_iq;
+
+ /**
* One bridge for each user of the component. Indexed by the user's full
* jid
*/