From 655151d88a6ab948949b73682c3a76a0274eb10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 26 Aug 2017 13:51:15 +0200 Subject: Cache the encoding_in database value, to avoid doing a query for each message --- src/bridge/bridge.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index e0cb36d..9fd0a5b 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -22,15 +22,12 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid) { #ifdef USE_DATABASE const auto jid = bridge.get_bare_jid(); - auto options = Database::get_irc_channel_options_with_server_default(jid, iid.get_server(), iid.get_local()); - auto result = options.col(); - if (!result.empty()) - return result; + return Database::get_encoding_in(jid, iid.get_server(), iid.get_local()); #else (void)bridge; (void)iid; -#endif return {"ISO-8859-1"}; +#endif } Bridge::Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller): -- cgit v1.2.3 From 25243f53c2479e2fda0f1a05d1589c8214b70b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 27 Aug 2017 14:32:29 +0200 Subject: =?UTF-8?q?In=20fixed=20mode,=20server=20messages=20come=20from=20?= =?UTF-8?q?biboumi=E2=80=99s=20hostname=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of irc.example.com@biboumi, because that’s actually user named “irc.example.com”, in that case. And that fixes the raw messages in fixed mode. fix #3286 --- src/bridge/bridge.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 9fd0a5b..b1685e0 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -932,7 +932,10 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho const auto encoding = in_encoding_for(*this, {from, this}); for (const auto& resource: this->resources_in_server[from]) { - this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false); + if (Config::get("fixed_irc_server", "").empty()) + this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false); + else + this->xmpp.send_message("", this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false); } } @@ -947,7 +950,7 @@ void Bridge::send_user_join(const std::string& hostname, const std::string& chan const Iid iid(chan_name, hostname, Iid::Type::Channel); this->send_xmpp_invitation(iid, ""); } - else + else { for (const auto& resource: resources) this->send_user_join(hostname, chan_name, user, user_mode, self, resource); -- cgit v1.2.3 From fcaffb9e778ad5962e69dc23c1fc91eb59a27945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 27 Aug 2017 22:30:44 +0200 Subject: Add support for the "history" node on MUC join Supports the "seconds", "maxstanzas", "since" and "maxchars" (but only =0) attributes. fix #3270 --- src/bridge/bridge.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index b1685e0..3bc618f 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -167,10 +167,11 @@ IrcClient* Bridge::find_irc_client(const std::string& hostname) const } bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const std::string& password, - const std::string& resource) + const std::string& resource, HistoryLimit history_limit) { const auto& hostname = iid.get_server(); IrcClient* irc = this->make_irc_client(hostname, nickname); + irc->history_limit = history_limit; this->add_resource_to_server(hostname, resource); auto res_in_chan = this->is_resource_in_chan(ChannelKey{iid.get_local(), hostname}, resource); if (!res_in_chan) @@ -993,17 +994,20 @@ void Bridge::send_topic(const std::string& hostname, const std::string& chan_nam } -void Bridge::send_room_history(const std::string& hostname, const std::string& chan_name) +void Bridge::send_room_history(const std::string& hostname, const std::string& chan_name, const HistoryLimit& history_limit) { for (const auto& resource: this->resources_in_chan[ChannelKey{chan_name, hostname}]) - this->send_room_history(hostname, chan_name, resource); + this->send_room_history(hostname, chan_name, resource, history_limit); } -void Bridge::send_room_history(const std::string& hostname, std::string chan_name, const std::string& resource) +void Bridge::send_room_history(const std::string& hostname, std::string chan_name, const std::string& resource, const HistoryLimit& history_limit) { #ifdef USE_DATABASE const auto coptions = Database::get_irc_channel_options_with_server_and_global_default(this->user_jid, hostname, chan_name); - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, coptions.col()); + auto limit = coptions.col(); + if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) + limit = history_limit.stanzas; + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { @@ -1257,7 +1261,7 @@ void Bridge::generate_channel_join_for_resource(const Iid& iid, const std::strin this->send_user_join(iid.get_server(), iid.get_encoded_local(), self, self->get_most_significant_mode(irc->get_sorted_user_modes()), true, resource); - this->send_room_history(iid.get_server(), iid.get_local(), resource); + this->send_room_history(iid.get_server(), iid.get_local(), resource, irc->history_limit); this->send_topic(iid.get_server(), iid.get_encoded_local(), channel->topic, channel->topic_author, resource); } -- cgit v1.2.3 From dabc48b79b6189c99c246ae01af27fa170fd86a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 30 Aug 2017 16:14:35 +0200 Subject: Mark messages from the IRC server as private and no-copy fix #3284 --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 3bc618f..02ba565 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -934,9 +934,9 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho for (const auto& resource: this->resources_in_server[from]) { if (Config::get("fixed_irc_server", "").empty()) - this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false); + this->xmpp.send_message(from, this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, true); else - this->xmpp.send_message("", this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, false); + this->xmpp.send_message("", this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource, "chat", false, true); } } -- cgit v1.2.3 From bfcf29451787d10c747ad79cb3fd177ac86e9cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 9 Sep 2017 17:09:17 +0200 Subject: Add the persistent_by_default configuration option fix #3293 --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 02ba565..8587264 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -435,7 +435,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con bool persistent = false; #ifdef USE_DATABASE const auto goptions = Database::get_global_options(this->user_jid); - if (goptions.col()) + if (goptions.col()) persistent = true; else { -- cgit v1.2.3 From cb6b50dc0109ee3a201a4012b63f3914cc5ea6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 7 Nov 2017 23:05:05 +0100 Subject: Change how we count the number of connected resources to a server --- src/bridge/bridge.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 8587264..eb1d553 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -894,7 +894,19 @@ void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->user_jid + "/" + res, self, user_requested); if (self) - this->remove_all_resources_from_chan(iid.to_tuple()); + { + // Copy the resources currently in that channel + const auto resources_in_chan = this->resources_in_chan[iid.to_tuple()]; + + this->remove_all_resources_from_chan(iid.to_tuple()); + + // Now, for each resource that was in that channel, remove it from the server if it’s + // not in any other channel + for (const auto& r: resources_in_chan) + if (this->number_of_channels_the_resource_is_in(iid.get_server(), r) == 0) + this->remove_resource_from_server(iid.get_server(), r); + + } } IrcClient* irc = this->find_irc_client(iid.get_server()); @@ -1236,9 +1248,13 @@ std::size_t Bridge::number_of_channels_the_resource_is_in(const std::string& irc std::size_t res = 0; for (auto pair: this->resources_in_chan) { - if (std::get<0>(pair.first) == irc_hostname && pair.second.count(resource) != 0) + if (std::get<1>(pair.first) == irc_hostname && pair.second.count(resource) != 0) res++; } + + IrcClient* irc = this->find_irc_client(irc_hostname); + if (irc && (irc->get_dummy_channel().joined || irc->get_dummy_channel().joining)) + res++; return res; } -- cgit v1.2.3 From 90dd8e8b422efdb1fc6c1fb6bfcbc423a4f700a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 7 Nov 2017 23:06:04 +0100 Subject: Fix #3304 --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index eb1d553..925b226 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -468,9 +468,9 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con "Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.", true, true, resource); this->remove_resource_from_chan(key, resource); + } if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) this->remove_resource_from_server(iid.get_server(), resource); - } } -- cgit v1.2.3 From 24dc05dd979264143223e166faa032e75f986b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 3 Dec 2017 16:28:38 +0100 Subject: Run some of the ci tests against a postgresql docker container --- src/bridge/bridge.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 925b226..57f0628 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1031,6 +1031,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam (void)hostname; (void)chan_name; (void)resource; + (void)history_limit; #endif } -- cgit v1.2.3 From 37340e593ffb61eaccc444a1efdb3aa6f784a14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 26 Dec 2017 19:52:41 +0100 Subject: Add a node on outgoing private MUC messages See https://xmpp.org/extensions/xep-0045.html#privatemessage fix #3321 --- src/bridge/bridge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 57f0628..54bee84 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -862,7 +862,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st const auto chan_name = Iid(Jid(it->second).local, {}).get_local(); for (const auto& resource: this->resources_in_chan[ChannelKey{chan_name, iid.get_server()}]) this->xmpp.send_message(it->second, this->make_xmpp_body(body, encoding), - this->user_jid + "/" + resource, "chat", true, true); + this->user_jid + "/" + + resource, "chat", true, true, true); } else { -- cgit v1.2.3