diff options
author | louiz’ <louiz@louiz.org> | 2016-09-22 19:01:31 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-09-22 19:01:31 +0200 |
commit | 2922c68e8315190bfc1aa81fbf4959dbb052be3b (patch) | |
tree | 84bd7d43f70b82d4c826bb142bf75d8c5498b3eb /src/xmpp | |
parent | 07e2209596a1fbcc1d6f97d68bfda8e2add19ea2 (diff) | |
download | biboumi-2922c68e8315190bfc1aa81fbf4959dbb052be3b.tar.gz biboumi-2922c68e8315190bfc1aa81fbf4959dbb052be3b.tar.bz2 biboumi-2922c68e8315190bfc1aa81fbf4959dbb052be3b.tar.xz biboumi-2922c68e8315190bfc1aa81fbf4959dbb052be3b.zip |
Respond to disco#info requests on IRC server JIDs
This makes it possible to execute an ad-hoc command on a server, with
clients like Gajim, for example.
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/biboumi_component.cpp | 36 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.hpp | 4 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index fad87f9..4a741f3 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -399,9 +399,10 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) const XmlNode* query; if ((query = stanza.get_child("query", DISCO_INFO_NS))) { // Disco info + Iid iid(to.local, {}); + const std::string node = query->get_tag("node"); if (to_str == this->served_hostname) { - const std::string node = query->get_tag("node"); if (node.empty()) { // On the gateway itself @@ -409,6 +410,14 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) stanza_error.disable(); } } + else if (iid.type == Iid::Type::Server) + { + if (node.empty()) + { + this->send_irc_server_disco_info(id, from, to_str); + stanza_error.disable(); + } + } } else if ((query = stanza.get_child("query", VERSION_NS))) { @@ -684,6 +693,31 @@ void BiboumiComponent::send_self_disco_info(const std::string& id, const std::st this->send_stanza(iq); } +void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from) +{ + Jid from(jid_from); + Stanza iq("iq"); + iq["type"] = "result"; + iq["id"] = id; + iq["to"] = jid_to; + iq["from"] = jid_from; + XmlNode query("query"); + query["xmlns"] = DISCO_INFO_NS; + XmlNode identity("identity"); + identity["category"] = "conference"; + identity["type"] = "irc"; + identity["name"] = "IRC server "s + from.local + " over Biboumi"; + query.add_child(std::move(identity)); + for (const char* ns: {DISCO_INFO_NS, ADHOC_NS, PING_NS, VERSION_NS}) + { + XmlNode feature("feature"); + feature["var"] = ns; + query.add_child(std::move(feature)); + } + iq.add_child(std::move(query)); + this->send_stanza(iq); +} + void BiboumiComponent::send_iq_version_request(const std::string& from, const std::string& jid_to) { diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp index 1844451..8b2ac78 100644 --- a/src/xmpp/biboumi_component.hpp +++ b/src/xmpp/biboumi_component.hpp @@ -62,6 +62,10 @@ public: */ void send_self_disco_info(const std::string& id, const std::string& jid_to); /** + * Send a result IQ with the disco informations regarding IRC server JIDs. + */ + void send_irc_server_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from); + /** * Send an iq version request */ void send_iq_version_request(const std::string& from, |