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/utils/time.cpp | 12 ++++++++++++ louloulibs/utils/time.hpp | 9 +++++++++ louloulibs/xmpp/jid.hpp | 7 ++++++- louloulibs/xmpp/xmpp_component.cpp | 21 +++------------------ louloulibs/xmpp/xmpp_component.hpp | 4 ++++ 5 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 louloulibs/utils/time.cpp create mode 100644 louloulibs/utils/time.hpp (limited to 'louloulibs') diff --git a/louloulibs/utils/time.cpp b/louloulibs/utils/time.cpp new file mode 100644 index 0000000..e23def4 --- /dev/null +++ b/louloulibs/utils/time.cpp @@ -0,0 +1,12 @@ +#include + +namespace utils +{ +std::string to_string(const std::time_t& timestamp) +{ + constexpr std::size_t stamp_size = 20; + char date_buf[stamp_size]; + std::strftime(date_buf, stamp_size, "%FT%TZ", std::gmtime(×tamp)); + return {std::begin(date_buf), std::end(date_buf)}; +} +} \ No newline at end of file diff --git a/louloulibs/utils/time.hpp b/louloulibs/utils/time.hpp new file mode 100644 index 0000000..dff1250 --- /dev/null +++ b/louloulibs/utils/time.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +namespace utils +{ +std::string to_string(const std::time_t& timestamp); +} \ No newline at end of file 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