From d1626c929f1d313c2f0f85b7d8b756a8d488d1dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 22 Aug 2016 00:44:17 +0200 Subject: When joining a channel, send the most recent history found in the database --- louloulibs/xmpp/xmpp_component.cpp | 28 ++++++++++++++++++++++++++++ louloulibs/xmpp/xmpp_component.hpp | 5 +++++ 2 files changed, 33 insertions(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index e87cdf7..22121f6 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -16,6 +16,9 @@ #include +#include +#include + #include #ifdef SYSTEMD_FOUND # include @@ -426,6 +429,31 @@ void XmppComponent::send_muc_message(const std::string& muc_name, const std::str this->send_stanza(message); } +void XmppComponent::send_history_message(const std::string& muc_name, const std::string& nick, const std::string& body_txt, const std::string& jid_to, std::time_t timestamp) +{ + Stanza message("message"); + message["to"] = jid_to; + if (!nick.empty()) + message["from"] = muc_name + "@" + this->served_hostname + "/" + nick; + else + message["from"] = muc_name + "@" + this->served_hostname; + message["type"] = "groupchat"; + + XmlNode body("body"); + body.set_inner(body_txt); + message.add_child(std::move(body)); + + XmlNode delay("delay"); + delay["xmlns"] = "urn:xmpp:delay"; + delay["from"] = muc_name + "@" + this->served_hostname; + std::stringstream date_ss; + date_ss << std::put_time(std::gmtime(×tamp), "%FT%Tz") << std::endl; + delay["stamp"] = date_ss.str(); + + message.add_child(std::move(delay)); + this->send_stanza(message); +} + void XmppComponent::send_muc_leave(const std::string& muc_name, std::string&& nick, Xmpp::body&& message, const std::string& jid_to, const bool self) { Stanza presence("presence"); diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 5fc6d2e..3a3b10b 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -134,6 +134,11 @@ public: * Send a (non-private) message to the MUC */ void send_muc_message(const std::string& muc_name, const std::string& nick, Xmpp::body&& body, const std::string& jid_to); + /** + * Send a message, with a element, part of a MUC history + */ + void send_history_message(const std::string& muc_name, const std::string& nick, const std::string& body, + const std::string& jid_to, const std::time_t timestamp); /** * Send an unavailable presence for this nick */ -- cgit v1.2.3 From 5e59cc517ff2c653d796bae01550e5d74b384fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 22 Aug 2016 20:25:41 +0200 Subject: Add missing ctime include --- louloulibs/xmpp/xmpp_component.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 3a3b10b..ba097e5 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #define STREAM_NS "http://etherx.jabber.org/streams" -- cgit v1.2.3 From a195939cdaca343013d32ae902839ffdb28c33cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 23 Aug 2016 20:47:05 +0200 Subject: =?UTF-8?q?Don't=20use=20put=5Ftime()=20because=20it=E2=80=99s=20n?= =?UTF-8?q?ot=20in=20gcc=204.9,=20in=20shitty-debian=20=E2=80=9Cstable?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use strftime instead --- louloulibs/xmpp/xmpp_component.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 22121f6..46c070a 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #ifdef SYSTEMD_FOUND @@ -446,9 +445,10 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std: XmlNode delay("delay"); delay["xmlns"] = "urn:xmpp:delay"; delay["from"] = muc_name + "@" + this->served_hostname; - std::stringstream date_ss; - date_ss << std::put_time(std::gmtime(×tamp), "%FT%Tz") << std::endl; - delay["stamp"] = date_ss.str(); + constexpr std::size_t stamp_size = 20; + char date_buf[stamp_size]; + std::strftime(date_buf, stamp_size, "%FT%Tz", std::gmtime(×tamp)); + delay["stamp"] = date_buf; message.add_child(std::move(delay)); this->send_stanza(message); -- cgit v1.2.3 From b59fc2a834dccb35f12dcfec624b6181e4e2fbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 23 Aug 2016 20:52:37 +0200 Subject: Use Z instead of z in the timestamp format --- louloulibs/xmpp/xmpp_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 46c070a..07d2408 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -447,7 +447,7 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std: delay["from"] = muc_name + "@" + this->served_hostname; constexpr std::size_t stamp_size = 20; char date_buf[stamp_size]; - std::strftime(date_buf, stamp_size, "%FT%Tz", std::gmtime(×tamp)); + std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(×tamp)); delay["stamp"] = date_buf; message.add_child(std::move(delay)); -- cgit v1.2.3 From 7536a1b3f38fbf093c1629b0db209754ada0c906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 25 Aug 2016 19:43:51 +0200 Subject: Respond to MAM requests on a channel JID At the moment, result-set-management is not implemented, the whole history (well, at most 1024 messages) is returned. --- louloulibs/xmpp/jid.hpp | 7 ++++++- louloulibs/xmpp/xmpp_component.cpp | 21 +++------------------ louloulibs/xmpp/xmpp_component.hpp | 4 ++++ 3 files changed, 13 insertions(+), 19 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/jid.hpp b/louloulibs/xmpp/jid.hpp index 08327ef..85e835c 100644 --- a/louloulibs/xmpp/jid.hpp +++ b/louloulibs/xmpp/jid.hpp @@ -26,7 +26,12 @@ public: } std::string full() const { - return this->local + "@" + this->domain + "/" + this->resource; + std::string res = this->domain; + if (!this->local.empty()) + res = this->local + "@" + this->domain; + if (!this->resource.empty()) + res += "/" + this->resource; + return res; } }; diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 07d2408..5db857c 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -7,22 +7,10 @@ #include #include #include - -#include -#include -#include - -#include +#include #include -#include - -#include -#ifdef SYSTEMD_FOUND -# include -#endif - using namespace std::string_literals; static std::set kickable_errors{ @@ -443,12 +431,9 @@ void XmppComponent::send_history_message(const std::string& muc_name, const std: message.add_child(std::move(body)); XmlNode delay("delay"); - delay["xmlns"] = "urn:xmpp:delay"; + delay["xmlns"] = DELAY_NS; delay["from"] = muc_name + "@" + this->served_hostname; - constexpr std::size_t stamp_size = 20; - char date_buf[stamp_size]; - std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(×tamp)); - delay["stamp"] = date_buf; + delay["stamp"] = utils::to_string(timestamp); message.add_child(std::move(delay)); this->send_stanza(message); diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index ba097e5..8359d05 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -26,6 +26,10 @@ #define VERSION_NS "jabber:iq:version" #define ADHOC_NS "http://jabber.org/protocol/commands" #define PING_NS "urn:xmpp:ping" +#define DELAY_NS "urn:xmpp:delay" +#define MAM_NS "urn:xmpp:mam:1" +#define FORWARD_NS "urn:xmpp:forward:0" +#define CLIENT_NS "jabber:client" /** * An XMPP component, communicating with an XMPP server using the protocole -- cgit v1.2.3 From 9727f4cf00e85e90f89c9b5443ec035c44d4c3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 29 Aug 2016 19:20:27 +0200 Subject: Add the missing includes back --- louloulibs/xmpp/xmpp_component.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 5db857c..f437a15 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -9,8 +9,21 @@ #include #include +#include +#include +#include + +#include #include +#include +#include + +#include +#ifdef SYSTEMD_FOUND +# include +#endif + using namespace std::string_literals; static std::set kickable_errors{ -- cgit v1.2.3 From 3047bd41b212390da8e3a4dbcf351e79879042dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 4 Sep 2016 21:04:21 +0200 Subject: MAM results can be filtered by start and end dates --- louloulibs/xmpp/xmpp_component.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 8359d05..b556ce2 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -30,6 +30,7 @@ #define MAM_NS "urn:xmpp:mam:1" #define FORWARD_NS "urn:xmpp:forward:0" #define CLIENT_NS "jabber:client" +#define DATAFORM_NS "jabber:x:data" /** * An XMPP component, communicating with an XMPP server using the protocole -- cgit v1.2.3 From 363a0bf02cf20592b2f9f034de1c5f54c8922b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 29 Sep 2016 20:11:35 +0200 Subject: Look for uuid/uuid.h instead of just uuid.h Avoids a conflict between /usr/include/uuid.h and /usr/local/include/uuid/uuid.h on freebsd --- louloulibs/xmpp/xmpp_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index f437a15..b10479a 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include -- cgit v1.2.3 From ee4cf5dc2d3eaa43794a8ac736a6409e08082882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 29 Sep 2016 20:53:40 +0200 Subject: Add AdhocCommandHandlers::add_command to simplify the usage of this class And make things a little bit clearer --- louloulibs/xmpp/adhoc_commands_handler.cpp | 4 ++-- louloulibs/xmpp/adhoc_commands_handler.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/adhoc_commands_handler.cpp b/louloulibs/xmpp/adhoc_commands_handler.cpp index 17c4e67..573c9ec 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.cpp +++ b/louloulibs/xmpp/adhoc_commands_handler.cpp @@ -15,9 +15,9 @@ const std::map& AdhocCommandsHandler::get return this->commands; } -std::map& AdhocCommandsHandler::get_commands() +void AdhocCommandsHandler::add_command(std::string name, AdhocCommand command) { - return this->commands; + this->commands.emplace(std::make_pair(std::move(name), std::move(command))); } XmlNode AdhocCommandsHandler::handle_request(const std::string& executor_jid, const std::string& to, XmlNode command_node) diff --git a/louloulibs/xmpp/adhoc_commands_handler.hpp b/louloulibs/xmpp/adhoc_commands_handler.hpp index 91eb5bd..e37d913 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.hpp +++ b/louloulibs/xmpp/adhoc_commands_handler.hpp @@ -31,9 +31,9 @@ public: */ const std::map& get_commands() const; /** - * This one can be used to add new commands. + * Add a command into the list, associated with the given name */ - std::map& get_commands(); + void add_command(std::string name, AdhocCommand command); /** * Find the requested command, create a new session or use an existing * one, and process the request (provide a new form, an error, or a -- cgit v1.2.3 From 265b5df61b5f3d4b5f30bbc6518f833f73bda1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 29 Sep 2016 23:10:41 +0200 Subject: Re-add the ad-hoc command the was removed by mistake in the previous commit Thank you, e2e tests --- louloulibs/xmpp/adhoc_commands_handler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/adhoc_commands_handler.cpp b/louloulibs/xmpp/adhoc_commands_handler.cpp index 573c9ec..540cac0 100644 --- a/louloulibs/xmpp/adhoc_commands_handler.cpp +++ b/louloulibs/xmpp/adhoc_commands_handler.cpp @@ -17,6 +17,9 @@ const std::map& AdhocCommandsHandler::get void AdhocCommandsHandler::add_command(std::string name, AdhocCommand command) { + const auto found = this->commands.find(name); + if (found != this->commands.end()) + throw std::runtime_error("Trying to add an ad-hoc command that already exist: "s + name); this->commands.emplace(std::make_pair(std::move(name), std::move(command))); } -- cgit v1.2.3 From 76a8189b46177eb78eee12d1cb3266f282acd380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 3 Oct 2016 00:58:21 +0200 Subject: Implement result-set-management for LIST queries ref #2948 --- louloulibs/xmpp/xmpp_component.hpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index b556ce2..4b6f37d 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -31,6 +31,7 @@ #define FORWARD_NS "urn:xmpp:forward:0" #define CLIENT_NS "jabber:client" #define DATAFORM_NS "jabber:x:data" +#define RSM_NS "http://jabber.org/protocol/rsm" /** * An XMPP component, communicating with an XMPP server using the protocole @@ -219,6 +220,9 @@ public: virtual void after_handshake() {} + const std::string& get_served_hostname() const + { return this->served_hostname; } + /** * Whether or not we ever succeeded our authentication to the XMPP server */ -- cgit v1.2.3 From 1d197ff26ce5a88ba851969edb3ea915759c3477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 4 Oct 2016 19:32:45 +0200 Subject: Respond to muc#traffic requests fix #3069 --- louloulibs/xmpp/xmpp_component.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 4b6f37d..1cb1845 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -32,6 +32,7 @@ #define CLIENT_NS "jabber:client" #define DATAFORM_NS "jabber:x:data" #define RSM_NS "http://jabber.org/protocol/rsm" +#define MUC_TRAFFIC_NS "http://jabber.org/protocol/muc#traffic" /** * An XMPP component, communicating with an XMPP server using the protocole -- cgit v1.2.3 From 8ac8d2b2425d19eb995a36efa808b664979e358f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 7 Oct 2016 23:28:40 +0200 Subject: Correctly set status="110" in the presence for the target of a kick --- louloulibs/xmpp/xmpp_component.cpp | 13 ++++++++----- louloulibs/xmpp/xmpp_component.hpp | 7 ++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index b10479a..1cf3e85 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -509,11 +509,8 @@ void XmppComponent::send_nick_change(const std::string& muc_name, this->send_user_join(muc_name, new_nick, "", affiliation, role, jid_to, self); } -void XmppComponent::kick_user(const std::string& muc_name, - const std::string& target, - const std::string& txt, - const std::string& author, - const std::string& jid_to) +void XmppComponent::kick_user(const std::string& muc_name, const std::string& target, const std::string& txt, + const std::string& author, const std::string& jid_to, const bool self) { Stanza presence("presence"); presence["from"] = muc_name + "@" + this->served_hostname + "/" + target; @@ -535,6 +532,12 @@ void XmppComponent::kick_user(const std::string& muc_name, XmlNode status("status"); status["code"] = "307"; x.add_child(std::move(status)); + if (self) + { + XmlNode status("status"); + status["code"] = "110"; + x.add_child(std::move(status)); + } presence.add_child(std::move(x)); this->send_stanza(presence); } diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 1cb1845..232d47a 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -164,11 +164,8 @@ public: /** * An user is kicked from a room */ - void kick_user(const std::string& muc_name, - const std::string& target, - const std::string& reason, - const std::string& author, - const std::string& jid_to); + void kick_user(const std::string& muc_name, const std::string& target, const std::string& reason, + const std::string& author, const std::string& jid_to, const bool self); /** * Send a generic presence error */ -- cgit v1.2.3 From dfc0793ef2fec12d2613b53b27f1a7f85dae2688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 11 Oct 2016 00:43:46 +0200 Subject: Include a private and no-copy nodes in private to avoid carbon duplication --- louloulibs/xmpp/xmpp_component.cpp | 15 ++++++++++++++- louloulibs/xmpp/xmpp_component.hpp | 5 ++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 1cf3e85..6690567 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -273,7 +273,8 @@ void* XmppComponent::get_receive_buffer(const size_t size) const return this->parser.get_buffer(size); } -void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, const std::string& to, const std::string& type, const bool fulljid) +void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, const std::string& to, + const std::string& type, const bool fulljid, const bool nocopy) { XmlNode node("message"); node["to"] = to; @@ -294,6 +295,18 @@ void XmppComponent::send_message(const std::string& from, Xmpp::body&& body, con html.add_child(std::move(std::get<1>(body))); node.add_child(std::move(html)); } + + if (nocopy) + { + XmlNode private_node("private"); + private_node["xmlns"] = "urn:xmpp:carbons:2"; + node.add_child(std::move(private_node)); + + XmlNode nocopy("no-copy"); + nocopy["xmlns"] = "urn:xmpp:hints"; + node.add_child(std::move(nocopy)); + } + this->send_stanza(node); } diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 232d47a..45a4038 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -109,9 +109,8 @@ public: * If fulljid is false, the provided 'from' doesn't contain the * server-part of the JID and must be added. */ - void send_message(const std::string& from, Xmpp::body&& body, - const std::string& to, const std::string& type, - const bool fulljid=false); + void send_message(const std::string& from, Xmpp::body&& body, const std::string& to, + const std::string& type, const bool fulljid, const bool nocopy=false); /** * Send a join from a new participant */ -- cgit v1.2.3 From 021f025cb039011ad07158b0d94f1b430a409e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Wed, 26 Oct 2016 21:19:53 +0200 Subject: Refactor the sha1 digest into its own function, and do not use sprintf --- louloulibs/xmpp/auth.cpp | 21 +++++++++++++++++++++ louloulibs/xmpp/auth.hpp | 6 ++++++ louloulibs/xmpp/xmpp_component.cpp | 17 +++-------------- 3 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 louloulibs/xmpp/auth.cpp create mode 100644 louloulibs/xmpp/auth.hpp (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/auth.cpp b/louloulibs/xmpp/auth.cpp new file mode 100644 index 0000000..c20f95d --- /dev/null +++ b/louloulibs/xmpp/auth.cpp @@ -0,0 +1,21 @@ +#include + +#include + +#include +#include + +std::string get_handshake_digest(const std::string& stream_id, const std::string& secret) +{ + sha1nfo sha1; + sha1_init(&sha1); + sha1_write(&sha1, stream_id.data(), stream_id.size()); + sha1_write(&sha1, secret.data(), secret.size()); + const uint8_t* result = sha1_result(&sha1); + + std::ostringstream digest; + for (int i = 0; i < HASH_LENGTH; i++) + digest << std::hex << std::setfill('0') << std::setw(2) << static_cast(result[i]); + + return digest.str(); +} diff --git a/louloulibs/xmpp/auth.hpp b/louloulibs/xmpp/auth.hpp new file mode 100644 index 0000000..34a2116 --- /dev/null +++ b/louloulibs/xmpp/auth.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include + +std::string get_handshake_digest(const std::string& stream_id, const std::string& secret); + diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 6690567..17fde20 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -5,15 +5,14 @@ #include #include -#include -#include #include +#include +#include #include #include #include -#include #include #include @@ -139,17 +138,7 @@ void XmppComponent::on_remote_stream_open(const XmlNode& node) } // Try to authenticate - char digest[HASH_LENGTH * 2 + 1]; - sha1nfo sha1; - sha1_init(&sha1); - sha1_write(&sha1, this->stream_id.data(), this->stream_id.size()); - sha1_write(&sha1, this->secret.data(), this->secret.size()); - const uint8_t* result = sha1_result(&sha1); - for (int i=0; i < HASH_LENGTH; i++) - sprintf(digest + (i*2), "%02x", result[i]); - digest[HASH_LENGTH * 2] = '\0'; - - auto data = ""s + digest + ""; + auto data = ""s + get_handshake_digest(this->stream_id, this->secret) + ""; log_debug("XMPP SENDING: ", data); this->send_data(std::move(data)); } -- cgit v1.2.3 From 8c26b4d19f6d3464050a34c782694059b2a7b013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 31 Oct 2016 02:01:01 +0100 Subject: Remove unused roster code --- louloulibs/xmpp/roster.cpp | 21 -------------- louloulibs/xmpp/roster.hpp | 71 ---------------------------------------------- 2 files changed, 92 deletions(-) delete mode 100644 louloulibs/xmpp/roster.cpp delete mode 100644 louloulibs/xmpp/roster.hpp (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/roster.cpp b/louloulibs/xmpp/roster.cpp deleted file mode 100644 index a14a384..0000000 --- a/louloulibs/xmpp/roster.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include - -RosterItem::RosterItem(const std::string& jid, const std::string& name, - std::vector& groups): - jid(jid), - name(name), - groups(groups) -{ -} - -RosterItem::RosterItem(const std::string& jid, const std::string& name): - jid(jid), - name(name), - groups{} -{ -} - -void Roster::clear() -{ - this->items.clear(); -} diff --git a/louloulibs/xmpp/roster.hpp b/louloulibs/xmpp/roster.hpp deleted file mode 100644 index aa1b449..0000000 --- a/louloulibs/xmpp/roster.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - - -#include -#include -#include - -class RosterItem -{ -public: - RosterItem(const std::string& jid, const std::string& name, - std::vector& groups); - RosterItem(const std::string& jid, const std::string& name); - RosterItem() = default; - ~RosterItem() = default; - RosterItem(const RosterItem&) = default; - RosterItem(RosterItem&&) = default; - RosterItem& operator=(const RosterItem&) = default; - RosterItem& operator=(RosterItem&&) = default; - - std::string jid; - std::string name; - std::vector groups; - -private: -}; - -/** - * Keep track of the last known stat of a JID's roster - */ -class Roster -{ -public: - Roster() = default; - ~Roster() = default; - - void clear(); - - template - RosterItem* add_item(ArgsType&&... args) - { - this->items.emplace_back(std::forward(args)...); - auto it = this->items.end() - 1; - return &*it; - } - RosterItem* get_item(const std::string& jid) - { - auto it = std::find_if(this->items.begin(), this->items.end(), - [this, &jid](const auto& item) - { - return item.jid == jid; - }); - if (it != this->items.end()) - return &*it; - return nullptr; - } - const std::vector& get_items() const - { - return this->items; - } - -private: - std::vector items; - - Roster(const Roster&) = delete; - Roster(Roster&&) = delete; - Roster& operator=(const Roster&) = delete; - Roster& operator=(Roster&&) = delete; -}; - - -- cgit v1.2.3 From ae02e58b9dc276b247be84e1d708ca50a1f5bbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 31 Oct 2016 13:54:25 +0100 Subject: Some cleanups --- louloulibs/xmpp/xmpp_component.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 17fde20..3ac617c 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -222,9 +222,8 @@ void XmppComponent::close_document() this->doc_open = false; } -void XmppComponent::handle_handshake(const Stanza& stanza) +void XmppComponent::handle_handshake(const Stanza&) { - (void)stanza; this->authenticated = true; this->ever_auth = true; log_info("Authenticated with the XMPP server"); -- cgit v1.2.3 From b5beb043325ca5625f4eb53cb9451daf499c586b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 7 Nov 2016 21:57:39 +0100 Subject: Remove a never reached (and non-sensical) error --- louloulibs/xmpp/xmpp_component.cpp | 25 ------------------------- louloulibs/xmpp/xmpp_component.hpp | 6 ------ 2 files changed, 31 deletions(-) (limited to 'louloulibs/xmpp') diff --git a/louloulibs/xmpp/xmpp_component.cpp b/louloulibs/xmpp/xmpp_component.cpp index 3ac617c..fa8b0a5 100644 --- a/louloulibs/xmpp/xmpp_component.cpp +++ b/louloulibs/xmpp/xmpp_component.cpp @@ -367,31 +367,6 @@ void XmppComponent::send_invalid_room_error(const std::string& muc_name, this->send_stanza(presence); } -void XmppComponent::send_invalid_user_error(const std::string& user_name, const std::string& to) -{ - Stanza message("message"); - message["from"] = user_name + "@" + this->served_hostname; - message["to"] = to; - message["type"] = "error"; - XmlNode x("x"); - x["xmlns"] = MUC_NS; - message.add_child(std::move(x)); - XmlNode error("error"); - error["type"] = "cancel"; - XmlNode item_not_found("item-not-found"); - item_not_found["xmlns"] = STANZA_NS; - error.add_child(std::move(item_not_found)); - XmlNode text("text"); - text["xmlns"] = STANZA_NS; - text["xml:lang"] = "en"; - text.set_inner(user_name + - " is not a valid IRC user name. A correct user jid is of the form: !@" + - this->served_hostname); - error.add_child(std::move(text)); - message.add_child(std::move(error)); - this->send_stanza(message); -} - void XmppComponent::send_topic(const std::string& from, Xmpp::body&& topic, const std::string& to, const std::string& who) { XmlNode message("message"); diff --git a/louloulibs/xmpp/xmpp_component.hpp b/louloulibs/xmpp/xmpp_component.hpp index 45a4038..5f5f937 100644 --- a/louloulibs/xmpp/xmpp_component.hpp +++ b/louloulibs/xmpp/xmpp_component.hpp @@ -127,12 +127,6 @@ public: void send_invalid_room_error(const std::string& muc_jid, const std::string& nick, const std::string& to); - /** - * Send an error to indicate that the user tried to send a message to an - * invalid user. - */ - void send_invalid_user_error(const std::string& user_name, - const std::string& to); /** * Send the MUC topic to the user */ -- cgit v1.2.3