From d872c2b49214c0a4db40a9e2d860802d9eedc563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 15 Nov 2016 00:23:19 +0100 Subject: Support the ident protocol fix #3211 --- src/bridge/bridge.cpp | 5 +++++ src/bridge/bridge.hpp | 1 + 2 files changed, 6 insertions(+) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index a0ecc6e..6fb03bd 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1033,6 +1033,11 @@ std::unordered_map>& Bridge::get_irc_cli return this->irc_clients; } +const std::unordered_map>& Bridge::get_irc_clients() const +{ + return this->irc_clients; +} + std::set Bridge::get_chantypes(const std::string& hostname) const { IrcClient* irc = this->find_irc_client(hostname); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 18ebfeb..8f2dcef 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -231,6 +231,7 @@ public: */ void trigger_on_irc_message(const std::string& irc_hostname, const IrcMessage& message); std::unordered_map>& get_irc_clients(); + const std::unordered_map>& get_irc_clients() const; std::set get_chantypes(const std::string& hostname) const; #ifdef USE_DATABASE void set_record_history(const bool val); -- cgit v1.2.3 From eca31ce8db104f17ac74fd74aa9d7ef7e8f1470a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= 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/bridge/bridge.cpp | 6 +++++- src/bridge/bridge.hpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 6fb03bd..1841b95 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -393,8 +393,12 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } } -void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick) +void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource) { + // We don’t change the nick if the presence was sent to a channel the resource is not in. + auto res_in_chan = this->is_resource_in_chan(ChannelKey{iid.get_local(), iid.get_server()}, requesting_resource); + if (!res_in_chan) + return; IrcClient* irc = this->get_irc_client(iid.get_server()); irc->send_nick_command(new_nick); } diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 8f2dcef..e92747d 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -80,7 +80,7 @@ public: void send_private_message(const Iid& iid, const std::string& body, const std::string& type="PRIVMSG"); void send_raw_message(const std::string& hostname, const std::string& body); void leave_irc_channel(Iid&& iid, const std::string& status_message, const std::string& resource); - void send_irc_nick_change(const Iid& iid, const std::string& new_nick); + void send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource); void send_irc_kick(const Iid& iid, const std::string& target, const std::string& reason, const std::string& iq_id, const std::string& to_jid); void set_channel_topic(const Iid& iid, const std::string& subject); -- cgit v1.2.3 From e397fc837e00cff58081810c8b54cb741299d993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= 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/bridge/bridge.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/bridge/bridge.hpp | 4 ++-- 2 files changed, 61 insertions(+), 5 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 1841b95..16b1c68 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -263,9 +263,11 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) } } -void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& nick, +void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& from, + const std::string& nick, const std::string& affiliation, - const std::string& role) + const std::string& role, + const std::string& id) { IrcClient* irc = this->get_irc_client(iid.get_server()); IrcChannel* chan = irc->get_channel(iid.get_local()); @@ -273,7 +275,11 @@ void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& return; IrcUser* user = chan->find_user(nick); if (!user) - return; + { + this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", + "item-not-found", "no such nick", false); + return; + } // For each affiliation or role, we have a “maximal” mode that we want to // set. We must remove any superior mode at the same time. For example if // the user already has +o mode, and we set its affiliation to member, we @@ -325,6 +331,56 @@ void Bridge::forward_affiliation_role_change(const Iid& iid, const std::string& std::vector args(nb, nick); args.insert(args.begin(), modes); irc->send_mode_command(iid.get_local(), args); + + irc_responder_callback_t cb = [this, iid, irc, id, from, nick](const std::string& irc_hostname, const IrcMessage& message) -> bool + { + if (irc_hostname != iid.get_server()) + return false; + + if (message.command == "MODE" && message.arguments.size() >= 2) + { + const std::string& chan_name = message.arguments[0]; + if (chan_name != iid.get_local()) + return false; + const std::string actor_nick = IrcUser{message.prefix}.nick; + if (!irc || irc->get_own_nick() != actor_nick) + return false; + + this->xmpp.send_iq_result(id, from, std::to_string(iid)); + } + else if (message.command == "401" && message.arguments.size() >= 2) + { + const std::string target_later = message.arguments[1]; + if (target_later != nick) + return false; + std::string error_message = "No such nick"; + if (message.arguments.size() >= 3) + error_message = message.arguments[2]; + this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "item-not-found", + error_message, false); + } + else if (message.command == "482" && message.arguments.size() >= 2) + { + const std::string chan_name_later = utils::tolower(message.arguments[1]); + if (chan_name_later != iid.get_local()) + return false; + std::string error_message = "You're not channel operator"; + if (message.arguments.size() >= 3) + error_message = message.arguments[2]; + this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "not-allowed", + error_message, false); + } + else if (message.command == "472" && message.arguments.size() >= 2) + { + std::string error_message = "Unknown mode: "s + message.arguments[1]; + if (message.arguments.size() >= 3) + error_message = message.arguments[2]; + this->xmpp.send_stanza_error("iq", from, std::to_string(iid), id, "cancel", "not-allowed", + error_message, false); + } + return true; + }; + this->add_waiting_irc(std::move(cb)); } void Bridge::send_private_message(const Iid& iid, const std::string& body, const std::string& type) diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index e92747d..fc839b4 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -103,8 +103,8 @@ public: bool send_matching_channel_list(const ChannelList& channel_list, const ResultSetInfo& rs_info, const std::string& id, const std::string& to_jid, const std::string& from); - void forward_affiliation_role_change(const Iid& iid, const std::string& nick, - const std::string& affiliation, const std::string& role); + void forward_affiliation_role_change(const Iid& iid, const std::string& from, const std::string& nick, + const std::string& affiliation, const std::string& role, const std::string& id); /** * Directly send a CTCP PING request to the IRC user */ -- cgit v1.2.3 From 5d801ddcd025f68d2ec91edf0462091a32c779c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 22 Jan 2017 21:31:50 +0100 Subject: Add a linger_time configuration option on IRC servers --- src/bridge/bridge.cpp | 22 +++++++++++++++++++++- src/bridge/bridge.hpp | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 16b1c68..ca9c9fa 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -11,6 +11,7 @@ #include #include "result_set_management.hpp" #include +#include using namespace std::string_literals; @@ -865,7 +866,7 @@ void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& me this->user_jid + "/" + res, self); IrcClient* irc = this->find_irc_client(iid.get_server()); if (irc && irc->number_of_joined_channels() == 0) - irc->send_quit_command(""); + this->quit_or_start_linger_timer(iid.get_server()); } void Bridge::send_nick_change(Iid&& iid, @@ -1212,3 +1213,22 @@ void Bridge::set_record_history(const bool val) this->record_history = val; } #endif + +void Bridge::quit_or_start_linger_timer(const std::string& irc_hostname) +{ +#ifdef USE_DATABASE + auto options = Database::get_irc_server_options(this->get_bare_jid(), + irc_hostname); + const auto timeout = std::chrono::seconds(options.lingerTime.value()); +#else + const auto timeout = 0s; +#endif + + const auto event_name = "IRCLINGER:" + irc_hostname + ".." + this->get_bare_jid(); + TimedEvent event(std::chrono::steady_clock::now() + timeout, [this, irc_hostname]() { + IrcClient* irc = this->find_irc_client(irc_hostname); + if (irc) + irc->send_quit_command(""); + }, event_name); + TimedEventsManager::instance().add_event(std::move(event)); +} diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index fc839b4..7d0166c 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -236,6 +236,11 @@ public: #ifdef USE_DATABASE void set_record_history(const bool val); #endif + /** + * Start a timer that will send a QUIT command after the + * configured linger time is expired. + */ + void quit_or_start_linger_timer(const std::string& irc_hostname); private: /** -- cgit v1.2.3 From b660a4736778cde8d0805390ffa857b77c271757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 22 Jan 2017 21:30:57 +0100 Subject: grammar: than <-> as --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index ca9c9fa..cafcbc3 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1029,7 +1029,7 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& const std::string& id) { // Use revstr because the forwarded ping to target XMPP user must not be - // the same that the request iq, but we also need to get it back easily + // the same as the request iq, but we also need to get it back easily // (revstr again) // Forward to the first resource (arbitrary, based on the “order” of the std::set) only const auto resources = this->resources_in_server[hostname]; -- cgit v1.2.3 From 45f7396c8d30ed37570c4ecdaa886388f9beba3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 25 Jan 2017 19:55:45 +0100 Subject: Cancel the IRC server linger timer when we try to-rejoin a channel on it --- src/bridge/bridge.cpp | 7 +++++++ src/bridge/bridge.hpp | 1 + 2 files changed, 8 insertions(+) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index cafcbc3..573e8d7 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -169,6 +169,7 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const const std::string& resource) { const auto hostname = iid.get_server(); + this->cancel_linger_timer(hostname); IrcClient* irc = this->make_irc_client(hostname, nickname); this->add_resource_to_server(hostname, resource); auto res_in_chan = this->is_resource_in_chan(ChannelKey{iid.get_local(), hostname}, resource); @@ -1232,3 +1233,9 @@ void Bridge::quit_or_start_linger_timer(const std::string& irc_hostname) }, event_name); TimedEventsManager::instance().add_event(std::move(event)); } + +void Bridge::cancel_linger_timer(const std::string& irc_hostname) +{ + const auto event_name = "IRCLINGER:" + irc_hostname + ".." + this->get_bare_jid(); + TimedEventsManager::instance().cancel(event_name); +} diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 7d0166c..b165650 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -241,6 +241,7 @@ public: * configured linger time is expired. */ void quit_or_start_linger_timer(const std::string& irc_hostname); + void cancel_linger_timer(const std::string& irc_hostname); private: /** -- cgit v1.2.3 From f0bc6c83a8eb548d0a3edbf7c16a6922bfd24ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Mar 2017 19:04:15 +0100 Subject: Pass the shared_ptr by reference, to avoid useless copies --- src/bridge/bridge.cpp | 2 +- src/bridge/bridge.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 573e8d7..7e2d8c1 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -29,7 +29,7 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid) #endif } -Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr poller): +Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller): user_jid(user_jid), xmpp(xmpp), poller(poller) diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index b165650..73daae7 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -38,7 +38,7 @@ using irc_responder_callback_t = std::function poller); + explicit Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller); ~Bridge() = default; Bridge(const Bridge&) = delete; -- cgit v1.2.3 From 38ff50f5d2ca356f659429ff57546bd2364a0fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Mar 2017 22:09:57 +0100 Subject: =?UTF-8?q?Don=E2=80=99t=20send=20the=20unavailable=20presence=20t?= =?UTF-8?q?o=20all=20resources,=20in=20the=20virtual=20channel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 7e2d8c1..701ee11 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -62,7 +62,7 @@ void Bridge::shutdown(const std::string& exit_message) for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) { it->second->send_quit_command(exit_message); - it->second->leave_dummy_channel(exit_message); + it->second->leave_dummy_channel(exit_message, ""); } } -- cgit v1.2.3 From a0a2de3b4d2facb25bbead59873cbf7f58f1d62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Mar 2017 22:28:00 +0100 Subject: =?UTF-8?q?Revert=20"Don=E2=80=99t=20send=20the=20unavailable=20pr?= =?UTF-8?q?esence=20to=20all=20resources,=20in=20the=20virtual=20channel"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 38ff50f5d2ca356f659429ff57546bd2364a0fef. --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 701ee11..7e2d8c1 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -62,7 +62,7 @@ void Bridge::shutdown(const std::string& exit_message) for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) { it->second->send_quit_command(exit_message); - it->second->leave_dummy_channel(exit_message, ""); + it->second->leave_dummy_channel(exit_message); } } -- cgit v1.2.3 From b7789fe586f375f09134a0817bd3ac19850c048f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Mar 2017 15:39:50 +0100 Subject: Add a Persistent option on channels fix #3230 --- src/bridge/bridge.cpp | 60 +++++++++++++++++++++++++++++++++++---------------- src/bridge/bridge.hpp | 1 + 2 files changed, 43 insertions(+), 18 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 7e2d8c1..d033acc 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -62,7 +62,7 @@ void Bridge::shutdown(const std::string& exit_message) for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) { it->second->send_quit_command(exit_message); - it->second->leave_dummy_channel(exit_message); + it->second->leave_dummy_channel(exit_message, {}); } } @@ -422,33 +422,48 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con if (!this->is_resource_in_chan(key, resource)) return ; + IrcChannel* channel = irc->get_channel(iid.get_local()); + auto nick = channel->get_self()->nick; + const auto resources = this->number_of_resources_in_chan(key); if (resources == 1) { // Do not send a PART message if we actually are not in that channel // or if we already sent a PART but we are just waiting for the // acknowledgment from the server - IrcChannel* channel = irc->get_channel(iid.get_local()); - if (channel->joined && !channel->parting) - irc->send_part_command(iid.get_local(), status_message); + bool persistent = false; +#ifdef USE_DATABASE + const auto coptions = Database::get_irc_channel_options_with_server_default(this->user_jid, + iid.get_server(), iid.get_local()); + persistent = coptions.persistent.value(); +#endif + if (channel->joined && !channel->parting && !persistent) + { + const auto chan_name = iid.get_local(); + if (chan_name.empty()) + irc->leave_dummy_channel(status_message, resource); + else + irc->send_part_command(iid.get_local(), status_message); + } + else + { + this->send_muc_leave(std::move(iid), std::move(nick), "", true, resource); + } // Since there are no resources left in that channel, we don't // want to receive private messages using this room's JID this->remove_all_preferred_from_jid_of_room(iid.get_local()); } else { - IrcChannel* chan = irc->get_channel(iid.get_local()); - if (chan) - { - auto nick = chan->get_self()->nick; - this->remove_resource_from_chan(key, resource); - this->send_muc_leave(std::move(iid), std::move(nick), - "Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.", - true, resource); - if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) - this->remove_resource_from_server(iid.get_server(), resource); - } + if (channel) + this->send_muc_leave(std::move(iid), std::move(nick), + "Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.", + 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); } + } void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource) @@ -862,9 +877,13 @@ void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& me this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), this->user_jid + "/" + resource, self); else - for (const auto& res: this->resources_in_chan[iid.to_tuple()]) - this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), - this->user_jid + "/" + res, self); + { + for (const auto &res: this->resources_in_chan[iid.to_tuple()]) + this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), + this->user_jid + "/" + res, self); + this->remove_all_resources_from_chan(iid.to_tuple()); + + } IrcClient* irc = this->find_irc_client(iid.get_server()); if (irc && irc->number_of_joined_channels() == 0) this->quit_or_start_linger_timer(iid.get_server()); @@ -1137,6 +1156,11 @@ bool Bridge::is_resource_in_chan(const Bridge::ChannelKey& channel, const std::s return false; } +void Bridge::remove_all_resources_from_chan(const Bridge::ChannelKey& channel_key) +{ + this->resources_in_chan.erase(channel_key); +} + void Bridge::add_resource_to_server(const Bridge::IrcHostname& irc_hostname, const std::string& resource) { auto it = this->resources_in_server.find(irc_hostname); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 73daae7..03eb716 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -312,6 +312,7 @@ private: void add_resource_to_chan(const ChannelKey& channel_key, const std::string& resource); void remove_resource_from_chan(const ChannelKey& channel_key, const std::string& resource); bool is_resource_in_chan(const ChannelKey& channel_key, const std::string& resource) const; + void remove_all_resources_from_chan(const ChannelKey& channel_key); std::size_t number_of_resources_in_chan(const ChannelKey& channel_key) const; void add_resource_to_server(const IrcHostname& irc_hostname, const std::string& resource); -- cgit v1.2.3 From 55f74349259fa0037de98d30d70b50396c4804f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 9 Mar 2017 17:37:49 +0100 Subject: Do not remove our resources if the QUIT message doesn't come from us --- src/bridge/bridge.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index d033acc..4632c23 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -881,11 +881,12 @@ void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& me for (const auto &res: this->resources_in_chan[iid.to_tuple()]) this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), this->user_jid + "/" + res, self); - this->remove_all_resources_from_chan(iid.to_tuple()); + if (self) + this->remove_all_resources_from_chan(iid.to_tuple()); } IrcClient* irc = this->find_irc_client(iid.get_server()); - if (irc && irc->number_of_joined_channels() == 0) + if (self && irc && irc->number_of_joined_channels() == 0) this->quit_or_start_linger_timer(iid.get_server()); } -- cgit v1.2.3 From 1a09c965eb3723cdaab9ea556f30ffbc7f09a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 29 Mar 2017 23:32:43 +0200 Subject: Remove two sneaky log_debug --- src/bridge/bridge.cpp | 33 +++++++++++++++++---------------- src/bridge/bridge.hpp | 14 +++++++------- src/bridge/colors.hpp | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 4632c23..0d6ade3 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -29,8 +30,8 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid) #endif } -Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller): - user_jid(user_jid), +Bridge::Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller): + user_jid(std::move(user_jid)), xmpp(xmpp), poller(poller) { @@ -59,10 +60,10 @@ static std::tuple get_role_affiliation_from_irc_mode(c void Bridge::shutdown(const std::string& exit_message) { - for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) + for (auto& pair: this->irc_clients) { - it->second->send_quit_command(exit_message); - it->second->leave_dummy_channel(exit_message, {}); + pair.second->send_quit_command(exit_message); + pair.second->leave_dummy_channel(exit_message, {}); } } @@ -168,7 +169,7 @@ 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 auto hostname = iid.get_server(); + const auto& hostname = iid.get_server(); this->cancel_linger_timer(hostname); IrcClient* irc = this->make_irc_client(hostname, nickname); this->add_resource_to_server(hostname, resource); @@ -439,7 +440,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con #endif if (channel->joined && !channel->parting && !persistent) { - const auto chan_name = iid.get_local(); + const auto& chan_name = iid.get_local(); if (chan_name.empty()) irc->leave_dummy_channel(status_message, resource); else @@ -447,7 +448,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } else { - this->send_muc_leave(std::move(iid), std::move(nick), "", true, resource); + this->send_muc_leave(iid, std::move(nick), "", true, resource); } // Since there are no resources left in that channel, we don't // want to receive private messages using this room's JID @@ -456,7 +457,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con else { if (channel) - this->send_muc_leave(std::move(iid), std::move(nick), + this->send_muc_leave(iid, std::move(nick), "Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.", true, resource); this->remove_resource_from_chan(key, resource); @@ -870,16 +871,16 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text); } -void Bridge::send_muc_leave(Iid&& iid, std::string&& nick, const std::string& message, const bool self, +void Bridge::send_muc_leave(const Iid &iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource) { if (!resource.empty()) - this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), + this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->user_jid + "/" + resource, self); else { for (const auto &res: this->resources_in_chan[iid.to_tuple()]) - this->xmpp.send_muc_leave(std::to_string(iid), std::move(nick), this->make_xmpp_body(message), + this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->user_jid + "/" + res, self); if (self) this->remove_all_resources_from_chan(iid.to_tuple()); @@ -1157,9 +1158,9 @@ bool Bridge::is_resource_in_chan(const Bridge::ChannelKey& channel, const std::s return false; } -void Bridge::remove_all_resources_from_chan(const Bridge::ChannelKey& channel_key) +void Bridge::remove_all_resources_from_chan(const Bridge::ChannelKey& channel) { - this->resources_in_chan.erase(channel_key); + this->resources_in_chan.erase(channel); } void Bridge::add_resource_to_server(const Bridge::IrcHostname& irc_hostname, const std::string& resource) @@ -1191,9 +1192,9 @@ bool Bridge::is_resource_in_server(const Bridge::IrcHostname& irc_hostname, cons return false; } -std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channel_key) const +std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channel) const { - auto it = this->resources_in_chan.find(channel_key); + auto it = this->resources_in_chan.find(channel); if (it == this->resources_in_chan.end()) return 0; return it->second.size(); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 03eb716..53d2136 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -38,7 +38,7 @@ using irc_responder_callback_t = std::function& poller); + explicit Bridge(std::string user_jid, BiboumiComponent& xmpp, std::shared_ptr& poller); ~Bridge() = default; Bridge(const Bridge&) = delete; @@ -169,7 +169,7 @@ public: /** * Send an unavailable presence from this participant */ - void send_muc_leave(Iid&& iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource=""); + void send_muc_leave(const Iid& iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource = ""); /** * Send presences to indicate that an user old_nick (ourself if self == * true) changed his nick to new_nick. The user_mode is needed because @@ -309,11 +309,11 @@ private: /** * Manage which resource is in which channel */ - void add_resource_to_chan(const ChannelKey& channel_key, const std::string& resource); - void remove_resource_from_chan(const ChannelKey& channel_key, const std::string& resource); - bool is_resource_in_chan(const ChannelKey& channel_key, const std::string& resource) const; - void remove_all_resources_from_chan(const ChannelKey& channel_key); - std::size_t number_of_resources_in_chan(const ChannelKey& channel_key) const; + void add_resource_to_chan(const ChannelKey& channel, const std::string& resource); + void remove_resource_from_chan(const ChannelKey& channel, const std::string& resource); + bool is_resource_in_chan(const ChannelKey& channel, const std::string& resource) const; + void remove_all_resources_from_chan(const ChannelKey& channel); + std::size_t number_of_resources_in_chan(const ChannelKey& channel) const; void add_resource_to_server(const IrcHostname& irc_hostname, const std::string& resource); void remove_resource_from_server(const IrcHostname& irc_hostname, const std::string& resource); diff --git a/src/bridge/colors.hpp b/src/bridge/colors.hpp index e2c8a87..dceed74 100644 --- a/src/bridge/colors.hpp +++ b/src/bridge/colors.hpp @@ -51,6 +51,6 @@ static const char irc_format_char[] = { * Returns the body cleaned from any IRC formatting (but without any xhtml), * and the body as XHTML-IM */ -Xmpp::body irc_format_to_xhtmlim(const std::string& str); +Xmpp::body irc_format_to_xhtmlim(const std::string& s); -- cgit v1.2.3 From 7f2127a7ea4c49fc1fbcd6cd6fb13e0265f4d841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 30 Mar 2017 18:16:44 +0200 Subject: Add the archive ID to messages when they are sent to users This makes us compatible with mam 6.0 fix #3249 --- src/bridge/bridge.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 0d6ade3..2da1d96 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -254,15 +254,16 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) else irc->send_channel_message(iid.get_local(), line); + std::string uuid; #ifdef USE_DATABASE const auto xmpp_body = this->make_xmpp_body(line); if (this->record_history) - Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(), + uuid = Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(), std::get<0>(xmpp_body), irc->get_own_nick()); #endif for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) - this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), - this->make_xmpp_body(line), this->user_jid + "/" + resource); + this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line), + this->user_jid + "/" + resource, uuid); } } @@ -839,8 +840,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st #endif for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) { - this->xmpp.send_muc_message(std::to_string(iid), nick, - this->make_xmpp_body(body, encoding), this->user_jid + "/" + resource); + this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding), + this->user_jid + "/" + resource, {}); } } -- cgit v1.2.3 From 0878a0342c5a2ae6abcfaecc2d9f0c9d3fd0dbad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 4 Apr 2017 21:38:53 +0200 Subject: =?UTF-8?q?Do=20not=20allow=20pings=20from=20resources=20that=20ar?= =?UTF-8?q?en=E2=80=99t=20in=20the=20channel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #3252 --- src/bridge/bridge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 2da1d96..4966b0d 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -744,9 +744,10 @@ void Bridge::send_irc_participant_ping_request(const Iid& iid, const std::string const std::string& iq_id, const std::string& to_jid, const std::string& from_jid) { + Jid from(to_jid); IrcClient* irc = this->get_irc_client(iid.get_server()); IrcChannel* chan = irc->get_channel(iid.get_local()); - if (!chan->joined) + if (!chan->joined || !this->is_resource_in_chan(iid.to_tuple(), from.resource)) { this->xmpp.send_stanza_error("iq", to_jid, from_jid, iq_id, "cancel", "not-allowed", "", true); -- cgit v1.2.3 From 5402a256d1f0ebbeafa32d250d000cf38fe748fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 7 Apr 2017 18:45:24 +0200 Subject: Apply all the clang-tidy modernize-* fixes --- src/bridge/colors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/colors.cpp b/src/bridge/colors.cpp index 66f51ee..7662425 100644 --- a/src/bridge/colors.cpp +++ b/src/bridge/colors.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include using namespace std::string_literals; -- cgit v1.2.3 From be9c577de840c7f0dc08b9f5b9ba9bd522d0e2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 7 Apr 2017 19:01:49 +0200 Subject: Apply all the clang-tidy performance-* fixes --- src/bridge/bridge.cpp | 6 +++--- src/bridge/bridge.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 4966b0d..591e947 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -988,16 +988,16 @@ void Bridge::send_room_history(const std::string& hostname, const std::string& c this->send_room_history(hostname, chan_name, resource); } -void Bridge::send_room_history(const std::string& hostname, const 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) { #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.maxHistoryLength.value()); + chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { const auto seconds = line.date.value().timeStamp(); - this->xmpp.send_history_message(chan_name + utils::empty_if_fixed_server("%" + hostname), line.nick.value(), - line.body.value(), + this->xmpp.send_history_message(chan_name, line.nick.value(), line.body.value(), this->user_jid + "/" + resource, seconds); } #endif diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 53d2136..f192545 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -157,7 +157,7 @@ public: * Send the MUC history to the user */ void send_room_history(const std::string& hostname, const std::string& chan_name); - void send_room_history(const std::string& hostname, const std::string& chan_name, const std::string& resource); + void send_room_history(const std::string& hostname, std::string chan_name, const std::string& resource); /** * Send a MUC message from some participant */ -- cgit v1.2.3 From 68d6b829402592d2d7a00e6e7b5013077aaa745c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 9 Apr 2017 23:03:35 +0200 Subject: Properly handle multiline topics fix #3254 --- src/bridge/bridge.cpp | 5 ++++- src/bridge/bridge.hpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 591e947..f263c3f 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -684,9 +684,12 @@ void Bridge::send_irc_kick(const Iid& iid, const std::string& target, const std: this->add_waiting_irc(std::move(cb)); } -void Bridge::set_channel_topic(const Iid& iid, const std::string& subject) +void Bridge::set_channel_topic(const Iid& iid, std::string subject) { IrcClient* irc = this->get_irc_client(iid.get_server()); + std::string::size_type pos{0}; + while ((pos = subject.find('\n', pos)) != std::string::npos) + subject[pos] = ' '; irc->send_topic_command(iid.get_local(), subject); } diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index f192545..1c89bd5 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -83,7 +83,7 @@ public: void send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource); void send_irc_kick(const Iid& iid, const std::string& target, const std::string& reason, const std::string& iq_id, const std::string& to_jid); - void set_channel_topic(const Iid& iid, const std::string& subject); + void set_channel_topic(const Iid& iid, std::string subject); void send_xmpp_version_to_irc(const Iid& iid, const std::string& name, const std::string& version, const std::string& os); void send_irc_ping_result(const Iid& iid, const std::string& id); -- cgit v1.2.3 From 727d887d7bc8a17b88402ae63e0569084a24a84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 20 Apr 2017 00:24:59 +0200 Subject: Fix wrong JID computing when sending iq ping or version in fixed mode fix #3259 --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index f263c3f..69e8c35 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1048,7 +1048,7 @@ void Bridge::send_iq_version_request(const std::string& nick, const std::string& { const auto resources = this->resources_in_server[hostname]; if (resources.begin() != resources.end()) - this->xmpp.send_iq_version_request(utils::tolower(nick) + "%" + utils::empty_if_fixed_server(hostname), + this->xmpp.send_iq_version_request(utils::tolower(nick) + utils::empty_if_fixed_server("%" + hostname), this->user_jid + "/" + *resources.begin()); } @@ -1061,7 +1061,7 @@ void Bridge::send_xmpp_ping_request(const std::string& nick, const std::string& // Forward to the first resource (arbitrary, based on the “order” of the std::set) only const auto resources = this->resources_in_server[hostname]; if (resources.begin() != resources.end()) - this->xmpp.send_ping_request(utils::tolower(nick) + "%" + utils::empty_if_fixed_server(hostname), + this->xmpp.send_ping_request(utils::tolower(nick) + utils::empty_if_fixed_server("%" + hostname), this->user_jid + "/" + *resources.begin(), utils::revstr(id)); } -- cgit v1.2.3 From 51696c091cc7058b05b33f1085b1246f3b5dc59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 19 Apr 2017 23:33:07 +0200 Subject: Make sure the channel is joined before trying to leave it fix #3243 --- src/bridge/bridge.cpp | 12 ++++++------ src/bridge/bridge.hpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 69e8c35..589bd03 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -425,7 +425,6 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con return ; IrcChannel* channel = irc->get_channel(iid.get_local()); - auto nick = channel->get_self()->nick; const auto resources = this->number_of_resources_in_chan(key); if (resources == 1) @@ -447,9 +446,9 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con else irc->send_part_command(iid.get_local(), status_message); } - else + else if (channel->joined) { - this->send_muc_leave(iid, std::move(nick), "", true, resource); + this->send_muc_leave(iid, channel->get_self()->nick, "", true, resource); } // Since there are no resources left in that channel, we don't // want to receive private messages using this room's JID @@ -457,8 +456,8 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } else { - if (channel) - this->send_muc_leave(iid, std::move(nick), + if (channel && channel->joined) + this->send_muc_leave(iid, channel->get_self()->nick, "Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.", true, resource); this->remove_resource_from_chan(key, resource); @@ -876,7 +875,8 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text); } -void Bridge::send_muc_leave(const Iid &iid, std::string&& nick, const std::string& message, const bool self, +void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, + const std::string& message, const bool self, const std::string& resource) { if (!resource.empty()) diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 1c89bd5..d8facad 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -169,7 +169,7 @@ public: /** * Send an unavailable presence from this participant */ - void send_muc_leave(const Iid& iid, std::string&& nick, const std::string& message, const bool self, const std::string& resource = ""); + void send_muc_leave(const Iid& iid, const std::string& nick, const std::string& message, const bool self, const std::string& resource = ""); /** * Send presences to indicate that an user old_nick (ourself if self == * true) changed his nick to new_nick. The user_mode is needed because -- cgit v1.2.3 From e3ee824e5c5548c13605e4f2e2ded9491c1c1479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 20 Apr 2017 10:09:35 +0200 Subject: Revert "Cancel the IRC server linger timer when we try to-rejoin a channel on it" This reverts commit 45f7396c8d30ed37570c4ecdaa886388f9beba3e. --- src/bridge/bridge.cpp | 7 ------- src/bridge/bridge.hpp | 1 - 2 files changed, 8 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 589bd03..0a9a412 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -170,7 +170,6 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const const std::string& resource) { const auto& hostname = iid.get_server(); - this->cancel_linger_timer(hostname); IrcClient* irc = this->make_irc_client(hostname, nickname); this->add_resource_to_server(hostname, resource); auto res_in_chan = this->is_resource_in_chan(ChannelKey{iid.get_local(), hostname}, resource); @@ -1264,9 +1263,3 @@ void Bridge::quit_or_start_linger_timer(const std::string& irc_hostname) }, event_name); TimedEventsManager::instance().add_event(std::move(event)); } - -void Bridge::cancel_linger_timer(const std::string& irc_hostname) -{ - const auto event_name = "IRCLINGER:" + irc_hostname + ".." + this->get_bare_jid(); - TimedEventsManager::instance().cancel(event_name); -} diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index d8facad..ce9c605 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -241,7 +241,6 @@ public: * configured linger time is expired. */ void quit_or_start_linger_timer(const std::string& irc_hostname); - void cancel_linger_timer(const std::string& irc_hostname); private: /** -- cgit v1.2.3 From 5ef674c4862f1ad265e76ea6fabc20e180871243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 20 Apr 2017 10:12:00 +0200 Subject: Revert "Add a linger_time configuration option on IRC servers" This reverts commit 5d801ddcd025f68d2ec91edf0462091a32c779c1. --- src/bridge/bridge.cpp | 22 +--------------------- src/bridge/bridge.hpp | 5 ----- 2 files changed, 1 insertion(+), 26 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 0a9a412..e362822 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -12,7 +12,6 @@ #include #include "result_set_management.hpp" #include -#include using namespace std::string_literals; @@ -892,7 +891,7 @@ void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, } IrcClient* irc = this->find_irc_client(iid.get_server()); if (self && irc && irc->number_of_joined_channels() == 0) - this->quit_or_start_linger_timer(iid.get_server()); + irc->send_quit_command(""); } void Bridge::send_nick_change(Iid&& iid, @@ -1244,22 +1243,3 @@ void Bridge::set_record_history(const bool val) this->record_history = val; } #endif - -void Bridge::quit_or_start_linger_timer(const std::string& irc_hostname) -{ -#ifdef USE_DATABASE - auto options = Database::get_irc_server_options(this->get_bare_jid(), - irc_hostname); - const auto timeout = std::chrono::seconds(options.lingerTime.value()); -#else - const auto timeout = 0s; -#endif - - const auto event_name = "IRCLINGER:" + irc_hostname + ".." + this->get_bare_jid(); - TimedEvent event(std::chrono::steady_clock::now() + timeout, [this, irc_hostname]() { - IrcClient* irc = this->find_irc_client(irc_hostname); - if (irc) - irc->send_quit_command(""); - }, event_name); - TimedEventsManager::instance().add_event(std::move(event)); -} diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index ce9c605..033291c 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -236,11 +236,6 @@ public: #ifdef USE_DATABASE void set_record_history(const bool val); #endif - /** - * Start a timer that will send a QUIT command after the - * configured linger time is expired. - */ - void quit_or_start_linger_timer(const std::string& irc_hostname); private: /** -- cgit v1.2.3 From da701069dc9b607ce2eee300519feb49b31901de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 8 May 2017 18:47:02 +0200 Subject: Little fix and cleanup in the channels list code --- src/bridge/bridge.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index e362822..11fd860 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -478,7 +478,7 @@ void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, c void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq_id, const std::string& to_jid, ResultSetInfo rs_info) { - auto& list = channel_list_cache[iid.get_server()]; + auto& list = this->channel_list_cache[iid.get_server()]; // We fetch the list from the IRC server only if we have a complete // cached list that needs to be invalidated (that is, when the request @@ -501,7 +501,7 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq if (irc_hostname != iid.get_server()) return false; - auto& list = channel_list_cache[iid.get_server()]; + auto& list = this->channel_list_cache[iid.get_server()]; if (message.command == "263" || message.command == "RPL_TRYAGAIN" || message.command == "ERR_TOOMANYMATCHES" || message.command == "ERR_NOSUCHSERVER") @@ -579,7 +579,7 @@ bool Bridge::send_matching_channel_list(const ChannelList& channel_list, const R const std::string& id, const std::string& to_jid, const std::string& from) { auto begin = channel_list.channels.begin(); - auto end = channel_list.channels.begin(); + auto end = channel_list.channels.end(); if (channel_list.complete) { begin = std::find_if(channel_list.channels.begin(), channel_list.channels.end(), [this, &rs_info](const ListElement& element) -- cgit v1.2.3 From f7d4db4812c346ed2624a5885326408b4f794f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 8 May 2017 23:02:14 +0200 Subject: Remove a useless debug log --- src/bridge/bridge.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 11fd860..f2d782c 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -559,7 +559,6 @@ void Bridge::send_irc_channel_list_request(const Iid& iid, const std::string& iq { auto& list = channel_list_cache[iid.get_server()]; const auto res = this->send_matching_channel_list(list, rs_info, iq_id, to_jid, std::to_string(iid)); - log_debug("We added a new channel in our list, can we send the result? ", std::boolalpha, res); return res; } else if (message.command == "323" || message.command == "RPL_LISTEND") -- cgit v1.2.3 From cf1c8f188c64ffe6cce941027190ef3cd90abf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 21 May 2017 12:23:10 +0200 Subject: Remove a few warnings occuring in some build config --- src/bridge/bridge.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/bridge') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index f2d782c..4a41b50 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -25,6 +25,8 @@ static std::string in_encoding_for(const Bridge& bridge, const Iid& iid) auto options = Database::get_irc_channel_options_with_server_default(jid, iid.get_server(), iid.get_local()); return options.encodingIn.value(); #else + (void)bridge; + (void)iid; return {"ISO-8859-1"}; #endif } @@ -1000,6 +1002,10 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam this->xmpp.send_history_message(chan_name, line.nick.value(), line.body.value(), this->user_jid + "/" + resource, seconds); } +#else + (void)hostname; + (void)chan_name; + (void)resource; #endif } -- cgit v1.2.3