summaryrefslogtreecommitdiff
path: root/src/xmpp/biboumi_component.hpp
diff options
context:
space:
mode:
authorVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
committerVasudev Kamath <vasudev@copyninja.info>2016-10-23 21:09:41 +0530
commit4e4de7284e6e4d89d182ea459823bbec1e408842 (patch)
tree47e0ed5216b48649b138f168f61fddca2b0c076a /src/xmpp/biboumi_component.hpp
parentdfb3a6edfacf2f16a8a63690b3e8058b6295d1a3 (diff)
parenteda4b75b1cff83336e87da90efca9fd6b4ced2c7 (diff)
downloadbiboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.gz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.bz2
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.tar.xz
biboumi-4e4de7284e6e4d89d182ea459823bbec1e408842.zip
Updated version 3.0 from 'upstream/3.0'
with Debian dir 0f18938e98f5a466f36719f60cef0490163ab845
Diffstat (limited to 'src/xmpp/biboumi_component.hpp')
-rw-r--r--src/xmpp/biboumi_component.hpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp
new file mode 100644
index 0000000..24d768a
--- /dev/null
+++ b/src/xmpp/biboumi_component.hpp
@@ -0,0 +1,109 @@
+#pragma once
+
+
+#include <xmpp/xmpp_component.hpp>
+
+#include <bridge/bridge.hpp>
+
+#include <memory>
+#include <string>
+#include <map>
+
+struct ListElement;
+
+/**
+ * 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)>;
+
+/**
+ * Interact with the Biboumi Bridge
+ */
+class BiboumiComponent: public XmppComponent
+{
+public:
+ explicit BiboumiComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret);
+ ~BiboumiComponent() = default;
+
+ BiboumiComponent(const BiboumiComponent&) = delete;
+ BiboumiComponent(BiboumiComponent&&) = delete;
+ BiboumiComponent& operator=(const BiboumiComponent&) = delete;
+ BiboumiComponent& operator=(BiboumiComponent&&) = delete;
+
+ /**
+ * Returns the bridge for the given user. If it does not exist, return
+ * nullptr.
+ */
+ Bridge* find_user_bridge(const std::string& full_jid);
+ /**
+ * Return a list of all the managed bridges.
+ */
+ std::vector<Bridge*> get_bridges() const;
+
+ /**
+ * Send a "close" message to all our connected peers. That message
+ * depends on the protocol used (this may be a QUIT irc message, or a
+ * <stream/>, etc). We may also directly close the connection, or we may
+ * wait for the remote peer to acknowledge it before closing.
+ */
+ void shutdown();
+ /**
+ * Run a check on all bridges, to remove all disconnected (socket is
+ * closed, or no channel is joined) IrcClients. Some kind of garbage collector.
+ */
+ void clean();
+ /**
+ * Send a result IQ with the gateway disco informations.
+ */
+ void send_self_disco_info(const std::string& id, const std::string& jid_to);
+ /**
+ * Send an iq version request
+ */
+ void send_iq_version_request(const std::string& from,
+ const std::string& jid_to);
+ /**
+ * Send a ping request
+ */
+ void send_ping_request(const std::string& from,
+ const std::string& jid_to,
+ const std::string& id);
+ /**
+ * Send the channels list in one big stanza
+ */
+ void send_iq_room_list_result(const std::string& id, const std::string& to_jid,
+ const std::string& from,
+ const std::vector<ListElement>& rooms_list);
+ /**
+ * Handle the various stanza types
+ */
+ void handle_presence(const Stanza& stanza);
+ void handle_message(const Stanza& stanza);
+ void handle_iq(const Stanza& stanza);
+
+private:
+ /**
+ * Return the bridge associated with the bare JID. Create a new one
+ * if none already exist.
+ */
+ Bridge* get_user_bridge(const std::string& user_jid);
+
+ /**
+ * 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 bare
+ * jid
+ */
+ std::unordered_map<std::string, std::unique_ptr<Bridge>> bridges;
+
+ AdhocCommandsHandler irc_server_adhoc_commands_handler;
+ AdhocCommandsHandler irc_channel_adhoc_commands_handler;
+};
+
+