From d872c2b49214c0a4db40a9e2d860802d9eedc563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Tue, 15 Nov 2016 00:23:19 +0100 Subject: Support the ident protocol fix #3211 --- src/xmpp/biboumi_component.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index d6782e2..ca24f3a 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -8,7 +8,6 @@ #include <xmpp/biboumi_adhoc_commands.hpp> #include <bridge/list_element.hpp> #include <config/config.hpp> -#include <utils/sha1.hpp> #include <utils/time.hpp> #include <xmpp/jid.hpp> -- cgit v1.2.3 From eb8f1cbc07aee0c22daa2ff4c24362c244327867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Sun, 4 Dec 2016 23:06:59 +0100 Subject: Avoid a potential nullptr dereference --- src/xmpp/biboumi_component.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index ca24f3a..262596c 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -569,13 +569,11 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) Jid to(stanza.get_tag("to")); const XmlNode* query = stanza.get_child("query", MAM_NS); - std::string query_id; - if (query) - query_id = query->get_tag("queryid"); Iid iid(to.local, {'#', '&'}); - if (iid.type == Iid::Type::Channel && to.resource.empty()) + if (query && iid.type == Iid::Type::Channel && to.resource.empty()) { + const std::string query_id = query->get_tag("queryid"); std::string start; std::string end; const XmlNode* x = query->get_child("x", DATAFORM_NS); -- cgit v1.2.3 From eca31ce8db104f17ac74fd74aa9d7ef7e8f1470a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Sun, 11 Dec 2016 17:05:52 +0100 Subject: Do not change the nick when joining a second room with a different nick As the doc says, the nick changes must be explicit in an already joined room, and not when joining a room. --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 262596c..d646656 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -149,7 +149,7 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) { const std::string own_nick = bridge->get_own_nick(iid); if (!own_nick.empty() && own_nick != to.resource) - bridge->send_irc_nick_change(iid, to.resource); + bridge->send_irc_nick_change(iid, to.resource, from.resource); const XmlNode* x = stanza.get_child("x", MUC_NS); const XmlNode* password = x ? x->get_child("password", MUC_NS): nullptr; bridge->join_irc_channel(iid, to.resource, password ? password->get_inner(): "", -- cgit v1.2.3 From c65ae4754921fe1f9888afc30d26ed11d5275258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 12 Dec 2016 00:36:59 +0100 Subject: Auto accept presence subscription --- src/xmpp/biboumi_component.cpp | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index d646656..f8d2f1d 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -161,6 +161,16 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) bridge->leave_irc_channel(std::move(iid), status ? status->get_inner() : "", from.resource); } } + else if (iid.type == Iid::Type::Server || iid.type == Iid::Type::None) + { + if (type == "subscribe") + { // Auto-accept any subscription request for an IRC server + this->add_to_roster(to_str, from.bare()); + this->accept_subscription(to_str, from.bare()); + this->ask_subscription(to_str, from.bare()); + } + + } else { // A user wants to join an invalid IRC channel, return a presence error to him/her @@ -751,20 +761,6 @@ void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string id, c } -void BiboumiComponent::send_iq_version_request(const std::string& from, - const std::string& jid_to) -{ - Stanza iq("iq"); - iq["type"] = "get"; - iq["id"] = "version_"s + this->next_id(); - iq["from"] = from + "@" + this->served_hostname; - iq["to"] = jid_to; - XmlNode query("query"); - query["xmlns"] = VERSION_NS; - iq.add_child(std::move(query)); - this->send_stanza(iq); -} - void BiboumiComponent::send_ping_request(const std::string& from, const std::string& jid_to, const std::string& id) @@ -863,3 +859,23 @@ void BiboumiComponent::send_invitation(const std::string& room_target, message.add_child(std::move(x)); this->send_stanza(message); } + +void BiboumiComponent::accept_subscription(const std::string& from, const std::string& to) +{ + Stanza presence("presence"); + presence["from"] = from; + presence["to"] = to; + presence["id"] = this->next_id(); + presence["type"] = "subscribed"; + this->send_stanza(presence); +} + +void BiboumiComponent::ask_subscription(const std::string& from, const std::string& to) +{ + Stanza presence("presence"); + presence["from"] = from; + presence["to"] = to; + presence["id"] = this->next_id(); + presence["type"] = "subscribe"; + this->send_stanza(presence); +} -- cgit v1.2.3 From 59a73c93ec48e9fe1171956f08a59dd85b90d5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 12 Dec 2016 00:39:31 +0100 Subject: =?UTF-8?q?Do=20not=20send=20an=20=E2=80=9Cnot-implemented?= =?UTF-8?q?=E2=80=9D=20error=20when=20receiving=20an=20iq=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xmpp/biboumi_component.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index f8d2f1d..246d828 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -289,7 +289,7 @@ void BiboumiComponent::handle_message(const Stanza& stanza) } // We MUST return an iq, whatever happens, except if the type is -// "result". +// "result" or "error". // To do this, we use a scopeguard. If an exception is raised somewhere, an // iq of type error "internal-server-error" is sent. If we handle the // request properly (by calling a function that registers an iq to be sent @@ -557,6 +557,10 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) } } } + else if (type == "error") + { + stanza_error.disable(); + } } catch (const IRCNotConnected& ex) { -- cgit v1.2.3 From 35e1155232ecc3e1cb526d07db3420b11f4717dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 12 Dec 2016 00:43:39 +0100 Subject: Remove a line from a WIP that should not have been added --- src/xmpp/biboumi_component.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 246d828..bd05bdc 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -165,7 +165,6 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) { if (type == "subscribe") { // Auto-accept any subscription request for an IRC server - this->add_to_roster(to_str, from.bare()); this->accept_subscription(to_str, from.bare()); this->ask_subscription(to_str, from.bare()); } -- cgit v1.2.3 From 5a5bb7f63222189ea0dcfbd387d5e34458ccefe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 14 Dec 2016 18:28:44 +0100 Subject: Introduce a XmlSubNode class that automatically adds itself into its parent --- src/xmpp/biboumi_component.cpp | 227 +++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 120 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index bd05bdc..985b252 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -625,39 +625,33 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) void BiboumiComponent::send_archived_message(const db::MucLogLine& log_line, const std::string& from, const std::string& to, const std::string& queryid) { - Stanza message("message"); + Stanza message("message"); + { message["from"] = from; message["to"] = to; - XmlNode result("result"); + XmlSubNode result(message, "result"); result["xmlns"] = MAM_NS; if (!queryid.empty()) result["queryid"] = queryid; result["id"] = log_line.uuid.value(); - XmlNode forwarded("forwarded"); + XmlSubNode forwarded(result, "forwarded"); forwarded["xmlns"] = FORWARD_NS; - XmlNode delay("delay"); + XmlSubNode delay(forwarded, "delay"); delay["xmlns"] = DELAY_NS; delay["stamp"] = utils::to_string(log_line.date.value().timeStamp()); - forwarded.add_child(std::move(delay)); - - XmlNode submessage("message"); + XmlSubNode submessage(forwarded, "message"); submessage["xmlns"] = CLIENT_NS; submessage["from"] = from + "/" + log_line.nick.value(); submessage["type"] = "groupchat"; - XmlNode body("body"); + XmlSubNode body(submessage, "body"); body.set_inner(log_line.body.value()); - submessage.add_child(std::move(body)); - - forwarded.add_child(std::move(submessage)); - result.add_child(std::move(forwarded)); - message.add_child(std::move(result)); - - this->send_stanza(message); + } + this->send_stanza(message); } #endif @@ -699,24 +693,23 @@ std::vector<Bridge*> BiboumiComponent::get_bridges() const void BiboumiComponent::send_self_disco_info(const std::string& id, const std::string& jid_to) { Stanza iq("iq"); - iq["type"] = "result"; - iq["id"] = id; - iq["to"] = jid_to; - iq["from"] = this->served_hostname; - XmlNode query("query"); - query["xmlns"] = DISCO_INFO_NS; - XmlNode identity("identity"); - identity["category"] = "conference"; - identity["type"] = "irc"; - identity["name"] = "Biboumi XMPP-IRC gateway"; - query.add_child(std::move(identity)); - for (const char* ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS}) - { - XmlNode feature("feature"); - feature["var"] = ns; - query.add_child(std::move(feature)); - } - iq.add_child(std::move(query)); + { + iq["type"] = "result"; + iq["id"] = id; + iq["to"] = jid_to; + iq["from"] = this->served_hostname; + XmlSubNode query(iq, "query"); + query["xmlns"] = DISCO_INFO_NS; + XmlSubNode identity(query, "identity"); + identity["category"] = "conference"; + identity["type"] = "irc"; + identity["name"] = "Biboumi XMPP-IRC gateway"; + for (const char *ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS}) + { + XmlSubNode feature(query, "feature"); + feature["var"] = ns; + } + } this->send_stanza(iq); } @@ -724,44 +717,42 @@ void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const s { 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)); + { + iq["type"] = "result"; + iq["id"] = id; + iq["to"] = jid_to; + iq["from"] = jid_from; + XmlSubNode query(iq, "query"); + query["xmlns"] = DISCO_INFO_NS; + XmlSubNode identity(query, "identity"); + identity["category"] = "conference"; + identity["type"] = "irc"; + identity["name"] = "IRC server "s + from.local + " over Biboumi"; + for (const char *ns: {DISCO_INFO_NS, ADHOC_NS, PING_NS, VERSION_NS}) + { + XmlSubNode feature(query, "feature"); + feature["var"] = ns; + } + } this->send_stanza(iq); } void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string id, const std::string& jid_from, const std::string& jid_to) { Stanza iq("iq"); - iq["type"] = "result"; - iq["id"] = id; - iq["from"] = jid_from; - iq["to"] = jid_to; - - XmlNode query("query"); - query["xmlns"] = DISCO_INFO_NS; - query["node"] = MUC_TRAFFIC_NS; - // We drop all “special” traffic (like xhtml-im, chatstates, etc), so - // don’t include any <feature/> - iq.add_child(std::move(query)); - + { + iq["type"] = "result"; + iq["id"] = id; + iq["from"] = jid_from; + iq["to"] = jid_to; + + XmlSubNode query(iq, "query"); + query["xmlns"] = DISCO_INFO_NS; + query["node"] = MUC_TRAFFIC_NS; + // We drop all “special” traffic (like xhtml-im, chatstates, etc), so + // don’t include any <feature/> + } this->send_stanza(iq); - } void BiboumiComponent::send_ping_request(const std::string& from, @@ -769,13 +760,14 @@ void BiboumiComponent::send_ping_request(const std::string& from, const std::string& id) { Stanza iq("iq"); - iq["type"] = "get"; - iq["id"] = id; - iq["from"] = from + "@" + this->served_hostname; - iq["to"] = jid_to; - XmlNode ping("ping"); - ping["xmlns"] = PING_NS; - iq.add_child(std::move(ping)); + { + iq["type"] = "get"; + iq["id"] = id; + iq["from"] = from + "@" + this->served_hostname; + iq["to"] = jid_to; + XmlSubNode ping(iq, "ping"); + ping["xmlns"] = PING_NS; + } this->send_stanza(iq); auto result_cb = [from, id](Bridge* bridge, const Stanza& stanza) @@ -799,48 +791,43 @@ void BiboumiComponent::send_iq_room_list_result(const std::string& id, const std const ResultSetInfo& rs_info) { Stanza iq("iq"); - iq["from"] = from + "@" + this->served_hostname; - iq["to"] = to_jid; - iq["id"] = id; - iq["type"] = "result"; - XmlNode query("query"); - query["xmlns"] = DISCO_ITEMS_NS; + { + iq["from"] = from + "@" + this->served_hostname; + iq["to"] = to_jid; + iq["id"] = id; + iq["type"] = "result"; + XmlSubNode query(iq, "query"); + query["xmlns"] = DISCO_ITEMS_NS; for (auto it = begin; it != end; ++it) - { - XmlNode item("item"); + { + XmlSubNode item(query, "item"); item["jid"] = it->channel + "@" + this->served_hostname; - query.add_child(std::move(item)); - } - - if ((rs_info.max >= 0 || !rs_info.after.empty() || !rs_info.before.empty())) - { - XmlNode set_node("set"); - set_node["xmlns"] = RSM_NS; + } - if (begin != channel_list.channels.cend()) - { - XmlNode first_node("first"); - first_node["index"] = std::to_string(std::distance(channel_list.channels.cbegin(), begin)); - first_node.set_inner(begin->channel + "@" + this->served_hostname); - set_node.add_child(std::move(first_node)); - } - if (end != channel_list.channels.cbegin()) - { - XmlNode last_node("last"); - last_node.set_inner(std::prev(end)->channel + "@" + this->served_hostname); - set_node.add_child(std::move(last_node)); - } - if (channel_list.complete) - { - XmlNode count_node("count"); - count_node.set_inner(std::to_string(channel_list.channels.size())); - set_node.add_child(std::move(count_node)); - } - query.add_child(std::move(set_node)); - } + if ((rs_info.max >= 0 || !rs_info.after.empty() || !rs_info.before.empty())) + { + XmlSubNode set_node(query, "set"); + set_node["xmlns"] = RSM_NS; - iq.add_child(std::move(query)); + if (begin != channel_list.channels.cend()) + { + XmlSubNode first_node(set_node, "first"); + first_node["index"] = std::to_string(std::distance(channel_list.channels.cbegin(), begin)); + first_node.set_inner(begin->channel + "@" + this->served_hostname); + } + if (end != channel_list.channels.cbegin()) + { + XmlSubNode last_node(set_node, "last"); + last_node.set_inner(std::prev(end)->channel + "@" + this->served_hostname); + } + if (channel_list.complete) + { + XmlSubNode count_node(set_node, "count"); + count_node.set_inner(std::to_string(channel_list.channels.size())); + } + } + } this->send_stanza(iq); } @@ -849,17 +836,17 @@ void BiboumiComponent::send_invitation(const std::string& room_target, const std::string& author_nick) { Stanza message("message"); - message["from"] = room_target + "@" + this->served_hostname; - message["to"] = jid_to; - XmlNode x("x"); - x["xmlns"] = MUC_USER_NS; - XmlNode invite("invite"); - if (author_nick.empty()) - invite["from"] = room_target + "@" + this->served_hostname; - else - invite["from"] = room_target + "@" + this->served_hostname + "/" + author_nick; - x.add_child(std::move(invite)); - message.add_child(std::move(x)); + { + message["from"] = room_target + "@" + this->served_hostname; + message["to"] = jid_to; + XmlSubNode x(message, "x"); + x["xmlns"] = MUC_USER_NS; + XmlSubNode invite(x, "invite"); + if (author_nick.empty()) + invite["from"] = room_target + "@" + this->served_hostname; + else + invite["from"] = room_target + "@" + this->served_hostname + "/" + author_nick; + } this->send_stanza(message); } @@ -875,7 +862,7 @@ void BiboumiComponent::accept_subscription(const std::string& from, const std::s void BiboumiComponent::ask_subscription(const std::string& from, const std::string& to) { - Stanza presence("presence"); + Stanza presence("presence"); presence["from"] = from; presence["to"] = to; presence["id"] = this->next_id(); -- cgit v1.2.3 From e397fc837e00cff58081810c8b54cb741299d993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Sun, 18 Dec 2016 17:21:15 +0100 Subject: Send iq error/result when the user changed a MODE command with an iq And add tests for all the mode changes --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 985b252..6971538 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -352,7 +352,7 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) bridge->send_irc_kick(iid, nick, reason, id, from); } else - bridge->forward_affiliation_role_change(iid, nick, affiliation, role); + bridge->forward_affiliation_role_change(iid, from, nick, affiliation, role, id); stanza_error.disable(); } } -- cgit v1.2.3 From e31ff3e9e94d943d4f307eb6ab8cee7fbd11b565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Fri, 6 Jan 2017 23:45:26 +0100 Subject: Fix some issues found by sonar cube --- src/xmpp/biboumi_component.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 6971538..bd6975e 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -136,7 +136,7 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) // stanza_error.disable() call at the end of the function. std::string error_type("cancel"); std::string error_name("internal-server-error"); - utils::ScopeGuard stanza_error([&](){ + utils::ScopeGuard stanza_error([this, &from_str, &to_str, &id, &error_type, &error_name](){ this->send_stanza_error("presence", from_str, to_str, id, error_type, error_name, ""); }); @@ -205,7 +205,7 @@ void BiboumiComponent::handle_message(const Stanza& stanza) std::string error_type("cancel"); std::string error_name("internal-server-error"); - utils::ScopeGuard stanza_error([&](){ + utils::ScopeGuard stanza_error([this, &from_str, &to_str, &id, &error_type, &error_name](){ this->send_stanza_error("message", from_str, to_str, id, error_type, error_name, ""); }); @@ -324,7 +324,7 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) // the scopeguard. std::string error_type("cancel"); std::string error_name("internal-server-error"); - utils::ScopeGuard stanza_error([&](){ + utils::ScopeGuard stanza_error([this, &from, &to_str, &id, &error_type, &error_name](){ this->send_stanza_error("iq", from, to_str, id, error_type, error_name, ""); }); -- cgit v1.2.3 From 8b2f748b1d8de6513ca69e643b50477b0e5a2130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 13 Feb 2017 09:58:54 +0100 Subject: Do not send a not-connected error, on "unavailable" presences fix #3231 --- src/xmpp/biboumi_component.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index bd6975e..52bf2b7 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -179,10 +179,11 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) } catch (const IRCNotConnected& ex) { - this->send_stanza_error("presence", from_str, to_str, id, - "cancel", "remote-server-not-found", - "Not connected to IRC server "s + ex.hostname, - true); + if (type == "unavailable") + this->send_stanza_error("presence", from_str, to_str, id, + "cancel", "remote-server-not-found", + "Not connected to IRC server "s + ex.hostname, + true); } stanza_error.disable(); } -- cgit v1.2.3 From 3a288340df860f6aeaf0f9a59734c1d39d091495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 13 Feb 2017 10:21:25 +0100 Subject: Fix the previous commit fix #3231 --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 52bf2b7..663e92e 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -179,7 +179,7 @@ void BiboumiComponent::handle_presence(const Stanza& stanza) } catch (const IRCNotConnected& ex) { - if (type == "unavailable") + if (type != "unavailable") this->send_stanza_error("presence", from_str, to_str, id, "cancel", "remote-server-not-found", "Not connected to IRC server "s + ex.hostname, -- cgit v1.2.3 From d81c3ad5ac2c12130d90044b7597bf962a7cfe9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Sat, 4 Mar 2017 14:00:53 +0100 Subject: Fix the order of from and to address in muc traffic info reply And add a test for it. fix #3238 --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 663e92e..2783b93 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -738,7 +738,7 @@ void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const s this->send_stanza(iq); } -void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string id, const std::string& jid_from, const std::string& jid_to) +void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string id, const std::string& jid_to, const std::string& jid_from) { Stanza iq("iq"); { -- cgit v1.2.3 From f0bc6c83a8eb548d0a3edbf7c16a6922bfd24ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 8 Mar 2017 19:04:15 +0100 Subject: Pass the shared_ptr by reference, to avoid useless copies --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 2783b93..4ba5e65 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -44,7 +44,7 @@ static std::set<std::string> kickable_errors{ }; -BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& secret): +BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller>& poller, const std::string& hostname, const std::string& secret): XmppComponent(poller, hostname, secret), irc_server_adhoc_commands_handler(*this), irc_channel_adhoc_commands_handler(*this) -- cgit v1.2.3 From 0ab40dc1ab4e689921da54080b135e1d22b1c586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Tue, 14 Mar 2017 21:45:23 +0100 Subject: Refactoring louloulibs and cmake Use OBJECT libraries Remove the louloulibs directory Write FOUND variables in the cache --- src/xmpp/biboumi_component.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 4ba5e65..1c0f65c 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -16,7 +16,6 @@ #include <cstdlib> -#include <louloulibs.h> #include <biboumi.h> #include <uuid/uuid.h> -- cgit v1.2.3 From e8ccfe97be6f7042b0960f40ce29a89801b9982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 29 Mar 2017 23:10:38 +0200 Subject: =?UTF-8?q?Add=20a=20missing=20=E2=80=9Cpass=20by=20reference?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 1c0f65c..41eb4b8 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -737,7 +737,7 @@ void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const s this->send_stanza(iq); } -void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string id, const std::string& jid_to, const std::string& jid_from) +void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string& id, const std::string& jid_to, const std::string& jid_from) { Stanza iq("iq"); { -- cgit v1.2.3 From ce2daa5ea093437bf8f14ba92a467d0ae688e6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 29 Mar 2017 23:24:47 +0200 Subject: Respond to disco#info on MUC JIDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, some client won’t do MAM, since they don’t know biboumi supports it. --- src/xmpp/biboumi_component.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 41eb4b8..ab8e5e0 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -422,7 +422,13 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) } else if (iid.type == Iid::Type::Channel) { - if (node == MUC_TRAFFIC_NS) + log_debug("type_channel"); + if (node.empty()) + { + this->send_irc_channel_disco_info(id, from, to_str); + stanza_error.disable(); + } + else if (node == MUC_TRAFFIC_NS) { this->send_irc_channel_muc_traffic_info(id, from, to_str); stanza_error.disable(); @@ -755,6 +761,32 @@ void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string& id, this->send_stanza(iq); } +void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from) +{ + log_debug("jid_from: ", jid_from); + Jid from(jid_from); + Iid iid(from.local, {}); + Stanza iq("iq"); + { + iq["type"] = "result"; + iq["id"] = id; + iq["to"] = jid_to; + iq["from"] = jid_from; + XmlSubNode query(iq, "query"); + query["xmlns"] = DISCO_INFO_NS; + XmlSubNode identity(query, "identity"); + identity["category"] = "conference"; + identity["type"] = "irc"; + identity["name"] = "IRC channel "s + iid.get_local() + " from server " + iid.get_server() + " over biboumi"; + for (const char *ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS}) + { + XmlSubNode feature(query, "feature"); + feature["var"] = ns; + } + } + this->send_stanza(iq); +} + void BiboumiComponent::send_ping_request(const std::string& from, const std::string& jid_to, const std::string& id) -- cgit v1.2.3 From 52b795d11976802cfec12d886fca508047ffed89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 29 Mar 2017 23:26:09 +0200 Subject: Add a missing namespace in the server disco#info response --- src/xmpp/biboumi_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index ab8e5e0..6dc8ce9 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -734,7 +734,7 @@ void BiboumiComponent::send_irc_server_disco_info(const std::string& id, const s identity["category"] = "conference"; identity["type"] = "irc"; identity["name"] = "IRC server "s + from.local + " over Biboumi"; - for (const char *ns: {DISCO_INFO_NS, ADHOC_NS, PING_NS, VERSION_NS}) + for (const char *ns: {DISCO_INFO_NS, MUC_NS, ADHOC_NS, PING_NS, MAM_NS, VERSION_NS}) { XmlSubNode feature(query, "feature"); feature["var"] = ns; -- cgit v1.2.3 From 1a09c965eb3723cdaab9ea556f30ffbc7f09a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 29 Mar 2017 23:32:43 +0200 Subject: Remove two sneaky log_debug --- src/xmpp/biboumi_component.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 6dc8ce9..df96d62 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -422,7 +422,6 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) } else if (iid.type == Iid::Type::Channel) { - log_debug("type_channel"); if (node.empty()) { this->send_irc_channel_disco_info(id, from, to_str); @@ -763,7 +762,6 @@ void BiboumiComponent::send_irc_channel_muc_traffic_info(const std::string& id, void BiboumiComponent::send_irc_channel_disco_info(const std::string& id, const std::string& jid_to, const std::string& jid_from) { - log_debug("jid_from: ", jid_from); Jid from(jid_from); Iid iid(from.local, {}); Stanza iq("iq"); -- cgit v1.2.3 From e4cc69607c91db43cf154326aaba8afbe97a4c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Tue, 4 Apr 2017 18:40:30 +0200 Subject: Handle some iq of type='error' as valid ping response fix #3251 --- src/xmpp/biboumi_component.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index df96d62..dc57eeb 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -564,6 +564,12 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) else if (type == "error") { stanza_error.disable(); + const auto it = this->waiting_iq.find(id); + if (it != this->waiting_iq.end()) + { + it->second(bridge, stanza); + this->waiting_iq.erase(it); + } } } catch (const IRCNotConnected& ex) @@ -807,8 +813,14 @@ void BiboumiComponent::send_ping_request(const std::string& from, { log_error("Received a corresponding ping result, but the 'to' from " "the response mismatches the 'from' of the request"); + return; } - else + const std::string type = stanza.get_tag("type"); + const XmlNode* error = stanza.get_child("error", COMPONENT_NS); + // Check if what we receive is considered a valid response. And yes, those errors are valid responses + if (type == "result" || + (type == "error" && error && (error->get_child("feature-not-implemented", STANZA_NS) || + error->get_child("service-unavailable", STANZA_NS)))) bridge->send_irc_ping_result({from, bridge}, id); }; this->waiting_iq[id] = result_cb; -- cgit v1.2.3 From 5402a256d1f0ebbeafa32d250d000cf38fe748fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Fri, 7 Apr 2017 18:45:24 +0200 Subject: Apply all the clang-tidy modernize-* fixes --- src/xmpp/biboumi_component.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index dc57eeb..b4b6a45 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -83,10 +83,8 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller>& poller, const std::s void BiboumiComponent::shutdown() { - for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) - { - it->second->shutdown("Gateway shutdown"); - } + for (auto& pair: this->bridges) + pair.second->shutdown("Gateway shutdown"); } void BiboumiComponent::clean() @@ -696,8 +694,8 @@ Bridge* BiboumiComponent::find_user_bridge(const std::string& full_jid) std::vector<Bridge*> BiboumiComponent::get_bridges() const { std::vector<Bridge*> res; - for (auto it = this->bridges.begin(); it != this->bridges.end(); ++it) - res.push_back(it->second.get()); + for (const auto& bridge: this->bridges) + res.push_back(bridge.second.get()); return res; } -- cgit v1.2.3 From 3a8203c366d46ec2937a601868f5e2ed591c923e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 12 Apr 2017 17:07:39 +0200 Subject: Handle the RSM "max" value in the MAM requests fix #3255 --- src/xmpp/biboumi_component.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index b4b6a45..8b2e541 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -619,7 +619,15 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) } } } - const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), -1, start, end); + const XmlNode* set = query->get_child("set", RSM_NS); + int limit = -1; + if (set) + { + const XmlNode* max = set->get_child("max", RSM_NS); + if (max) + limit = std::atoi(max->get_inner().data()); + } + const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end); for (const db::MucLogLine& line: lines) { if (!line.nick.value().empty()) -- cgit v1.2.3 From 54fa739d6b5d2cc0b3704eda32c7abac47708b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Wed, 12 Apr 2017 17:53:44 +0200 Subject: Limit of 100 MAM messages, if no other limit has been set by the client fix #3256 --- src/xmpp/biboumi_component.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index 8b2e541..c808eec 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -627,6 +627,12 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) if (max) limit = std::atoi(max->get_inner().data()); } + // If the archive is really big, and the client didn’t specify any + // limit, we avoid flooding it: we set an arbitrary max limit. + if (limit == -1 && start.empty() && end.empty()) + { + limit = 100; + } const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end); for (const db::MucLogLine& line: lines) { -- cgit v1.2.3 From 984d71838ec98a94101804e48a4536c64d75602c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Mon, 8 May 2017 23:01:21 +0200 Subject: Limit the number of rooms sent by default in the disco#items response fix #3219 --- src/xmpp/biboumi_component.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index c808eec..ad34ace 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -503,6 +503,8 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) rs_info.max = std::atoi(max->get_inner().data()); } + if (rs_info.max == -1) + rs_info.max = 100; bridge->send_irc_channel_list_request(iid, id, from, std::move(rs_info)); stanza_error.disable(); } -- cgit v1.2.3 From 8cf0b833c47314ada66e6a25bbdb9a2178e096d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= <louiz@louiz.org> Date: Thu, 11 May 2017 21:15:43 +0200 Subject: Make the IRC channel configuration form available from the MUC config fix #3250 --- src/xmpp/biboumi_component.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/xmpp/biboumi_component.cpp') diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index ad34ace..ca3a887 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -392,6 +392,11 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) if (this->handle_mam_request(stanza)) stanza_error.disable(); } + else if ((query = stanza.get_child("query", MUC_OWNER_NS))) + { + if (this->handle_room_configuration_form(*query, from, to, id)) + stanza_error.disable(); + } #endif } else if (type == "get") @@ -529,6 +534,13 @@ void BiboumiComponent::handle_iq(const Stanza& stanza) } stanza_error.disable(); } +#ifdef USE_DATABASE + else if ((query = stanza.get_child("query", MUC_OWNER_NS))) + { + if (this->handle_room_configuration_form_request(from, to, id)) + stanza_error.disable(); + } +#endif } else if (type == "result") { @@ -679,6 +691,50 @@ void BiboumiComponent::send_archived_message(const db::MucLogLine& log_line, con this->send_stanza(message); } +bool BiboumiComponent::handle_room_configuration_form_request(const std::string& from, const Jid& to, const std::string& id) +{ + Iid iid(to.local, {'#', '&'}); + + if (iid.type != Iid::Type::Channel) + return false; + + Stanza iq("iq"); + { + iq["from"] = to.full(); + iq["to"] = from; + iq["id"] = id; + iq["type"] = "result"; + XmlSubNode query(iq, "query"); + query["xmlns"] = MUC_OWNER_NS; + Jid requester(from); + insert_irc_channel_configuration_form(query, requester, to); + } + this->send_stanza(iq); + return true; +} + +bool BiboumiComponent::handle_room_configuration_form(const XmlNode& query, const std::string &from, const Jid &to, const std::string &id) +{ + Iid iid(to.local, {'#', '&'}); + + if (iid.type != Iid::Type::Channel) + return false; + + Jid requester(from); + if (!handle_irc_channel_configuration_form(query, requester, to)) + return false; + + Stanza iq("iq"); + iq["type"] = "result"; + iq["from"] = to.full(); + iq["to"] = from; + iq["id"] = id; + + this->send_stanza(iq); + + return true; +} + #endif Bridge* BiboumiComponent::get_user_bridge(const std::string& user_jid) -- cgit v1.2.3