summaryrefslogtreecommitdiff
path: root/louloulibs
diff options
context:
space:
mode:
Diffstat (limited to 'louloulibs')
-rw-r--r--louloulibs/utils/time.cpp12
-rw-r--r--louloulibs/utils/time.hpp9
-rw-r--r--louloulibs/xmpp/jid.hpp7
-rw-r--r--louloulibs/xmpp/xmpp_component.cpp21
-rw-r--r--louloulibs/xmpp/xmpp_component.hpp4
5 files changed, 34 insertions, 19 deletions
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 <utils/time.hpp>
+
+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(&timestamp));
+ 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 <ctime>
+#include <string>
+
+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 <config/config.hpp>
#include <xmpp/jid.hpp>
#include <utils/sha1.hpp>
-
-#include <stdexcept>
-#include <iostream>
-#include <set>
-
-#include <stdio.h>
+#include <utils/time.hpp>
#include <uuid.h>
-#include <cstdlib>
-
-#include <louloulibs.h>
-#ifdef SYSTEMD_FOUND
-# include <systemd/sd-daemon.h>
-#endif
-
using namespace std::string_literals;
static std::set<std::string> 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(&timestamp));
- 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