From bf7b05ef72bbdac97704d262ddfe418908267535 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 6 Nov 2013 20:51:05 +0100 Subject: Implement the Bridge class to translate between the two protocols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add all useful classes as well: Jid, Iid, IrcChannel, IrcUser etc to properly keep the informations about what we receive from the IRC server. Only handle the MUC join stanza, and send the list of users in the IRC channel to the XMPP user, and the IRC channel’s topic, for now. --- src/irc/irc_channel.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/irc/irc_channel.cpp (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp new file mode 100644 index 0000000..223305b --- /dev/null +++ b/src/irc/irc_channel.cpp @@ -0,0 +1,24 @@ +#include +#include + +IrcChannel::IrcChannel(): + joined(false), + self(nullptr) +{ +} + +void IrcChannel::set_self(const std::string& name) +{ + this->self = std::make_unique(name); +} + +IrcUser* IrcChannel::add_user(const std::string& name) +{ + this->users.emplace_back(std::make_unique(name)); + return this->users.back().get(); +} + +IrcUser* IrcChannel::get_self() const +{ + return this->self.get(); +} -- cgit v1.2.3 From 7c671499350e22f8bfba2f72b9827aa5b200f7b0 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 9 Nov 2013 23:17:48 +0100 Subject: Implement part and join, both ways --- src/irc/irc_channel.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 223305b..6daf708 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -22,3 +22,27 @@ IrcUser* IrcChannel::get_self() const { return this->self.get(); } + +IrcUser* IrcChannel::find_user(const std::string& name) +{ + IrcUser user(name); + for (const auto& u: this->users) + { + if (u->nick == user.nick) + return u.get(); + } + return nullptr; +} + +void IrcChannel::remove_user(const IrcUser* user) +{ + for (auto it = this->users.begin(); it != this->users.end(); ++it) + { + IrcUser* u = it->get(); + if (u->nick == user->nick) + { + this->users.erase(it); + break ; + } + } +} -- cgit v1.2.3 From acf769d83a40e971ccc1346225688841465b36ee Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 29 Dec 2013 19:57:43 +0100 Subject: Use isupport informations to know the user modes when joining Also remove the duplicate send_self_join methods, user only send_user_join --- src/irc/irc_channel.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 6daf708..80e9b24 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -12,9 +12,10 @@ void IrcChannel::set_self(const std::string& name) this->self = std::make_unique(name); } -IrcUser* IrcChannel::add_user(const std::string& name) +IrcUser* IrcChannel::add_user(const std::string& name, + const std::map prefix_to_mode) { - this->users.emplace_back(std::make_unique(name)); + this->users.emplace_back(std::make_unique(name, prefix_to_mode)); return this->users.back().get(); } -- cgit v1.2.3 From e840704b58a984351971e8034e74f5e9fdfaf114 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 4 Jan 2014 01:30:03 +0100 Subject: Convert received modes into roles and affiliations --- src/irc/irc_channel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 80e9b24..99783fa 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -24,7 +24,7 @@ IrcUser* IrcChannel::get_self() const return this->self.get(); } -IrcUser* IrcChannel::find_user(const std::string& name) +IrcUser* IrcChannel::find_user(const std::string& name) const { IrcUser user(name); for (const auto& u: this->users) -- cgit v1.2.3 From 020325dbb071f1735bceb80de9f982aefcd2de47 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 13 Apr 2014 15:37:56 +0200 Subject: [WIP] DummyIrcChannel --- src/irc/irc_channel.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 99783fa..0604528 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -47,3 +47,9 @@ void IrcChannel::remove_user(const IrcUser* user) } } } + +DummyIrcChannel::DummyIrcChannel(): + IrcChannel(), + joining(false) +{ +} -- cgit v1.2.3 From 5739d418e2b35dfc038fe1a12f8b5c7eeeed6868 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 15 Apr 2014 04:56:50 +0200 Subject: Better way to leave the dummy room --- src/irc/irc_channel.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 0604528..7b0e766 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -48,6 +48,12 @@ void IrcChannel::remove_user(const IrcUser* user) } } +void IrcChannel::remove_all_users() +{ + this->users.clear(); + this->self.reset(); +} + DummyIrcChannel::DummyIrcChannel(): IrcChannel(), joining(false) -- cgit v1.2.3 From c6059e5a215624e205cae401183f3a8bb1bf87d0 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 28 Apr 2014 18:46:25 +0200 Subject: Upgrade to C++14 --- src/irc/irc_channel.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 7b0e766..2c0f8b1 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -1,5 +1,4 @@ #include -#include IrcChannel::IrcChannel(): joined(false), -- cgit v1.2.3 From 720e31a5113c25e48d7754bb812ab84c6c31d1d9 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 17 Dec 2014 13:37:57 +0100 Subject: Fix a few issues reported by static analyzers --- src/irc/irc_channel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 2c0f8b1..b1b3983 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -12,7 +12,7 @@ void IrcChannel::set_self(const std::string& name) } IrcUser* IrcChannel::add_user(const std::string& name, - const std::map prefix_to_mode) + const std::map& prefix_to_mode) { this->users.emplace_back(std::make_unique(name, prefix_to_mode)); return this->users.back().get(); -- cgit v1.2.3 From 2d11a5f49454717c404b25825f18e696281207d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 8 Jun 2016 01:32:39 +0200 Subject: Support multiple nick session, except for IQs ref #2556 --- src/irc/irc_channel.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index b1b3983..9801513 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -1,4 +1,5 @@ #include +#include IrcChannel::IrcChannel(): joined(false), @@ -36,15 +37,11 @@ IrcUser* IrcChannel::find_user(const std::string& name) const void IrcChannel::remove_user(const IrcUser* user) { - for (auto it = this->users.begin(); it != this->users.end(); ++it) - { - IrcUser* u = it->get(); - if (u->nick == user->nick) - { - this->users.erase(it); - break ; - } - } + this->users.erase(std::remove_if(this->users.begin(), this->users.end(), + [user](const std::unique_ptr& u) + { + return user->nick == u->nick; + }), this->users.end()); } void IrcChannel::remove_all_users() -- cgit v1.2.3 From 57263961b487bd839cbce5fe7547933240792fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 23 Jun 2016 22:14:32 +0200 Subject: Fix a use after free in IrcChannel::remove_user --- src/irc/irc_channel.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/irc/irc_channel.cpp') diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 9801513..e769245 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -37,11 +37,14 @@ IrcUser* IrcChannel::find_user(const std::string& name) const void IrcChannel::remove_user(const IrcUser* user) { - this->users.erase(std::remove_if(this->users.begin(), this->users.end(), - [user](const std::unique_ptr& u) - { - return user->nick == u->nick; - }), this->users.end()); + const auto nick = user->nick; + const auto it = std::find_if(this->users.begin(), this->users.end(), + [nick](const std::unique_ptr& u) + { + return nick == u->nick; + }); + if (it != this->users.end()) + this->users.erase(it); } void IrcChannel::remove_all_users() -- cgit v1.2.3