summaryrefslogtreecommitdiff
path: root/src/xmpp/jid.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-12-08 20:14:12 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-12-08 20:14:12 +0100
commitb11126a19dbaadf4c32fb8dbec22754ad0712c26 (patch)
tree140a9c33a264adfb4eee7a0e2add0b6c5ec1671c /src/xmpp/jid.cpp
parentcb718def0cb51aac4c2125e3864522740fcb2573 (diff)
downloadbiboumi-b11126a19dbaadf4c32fb8dbec22754ad0712c26.tar.gz
biboumi-b11126a19dbaadf4c32fb8dbec22754ad0712c26.tar.bz2
biboumi-b11126a19dbaadf4c32fb8dbec22754ad0712c26.tar.xz
biboumi-b11126a19dbaadf4c32fb8dbec22754ad0712c26.zip
Provide a JID for IRC users, and add a stringprep dependency for this
Diffstat (limited to 'src/xmpp/jid.cpp')
-rw-r--r--src/xmpp/jid.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/xmpp/jid.cpp b/src/xmpp/jid.cpp
index 29a5302..4f9917b 100644
--- a/src/xmpp/jid.cpp
+++ b/src/xmpp/jid.cpp
@@ -1,4 +1,12 @@
#include <xmpp/jid.hpp>
+#include <config.h>
+#include <cstring>
+
+#ifdef LIBIDN_FOUND
+ #include <stringprep.h>
+#endif
+
+#include <logger/logger.hpp>
Jid::Jid(const std::string& jid)
{
@@ -19,3 +27,41 @@ Jid::Jid(const std::string& jid)
this->domain = jid.substr(at, slash - at);
}
+
+#include <iostream>
+
+static constexpr size_t max_jid_part_len = 1023;
+
+std::string jidprep(const std::string& original)
+{
+#ifdef LIBIDN_FOUND
+ // TODO: cache the result
+ const std::string error_msg("Failed to convert " + original + " into a valid JID:");
+ Jid jid(original);
+
+ char local[max_jid_part_len] = {};
+ memcpy(local, jid.local.data(), jid.local.size());
+ Stringprep_rc rc = static_cast<Stringprep_rc>(::stringprep(local, max_jid_part_len,
+ static_cast<Stringprep_profile_flags>(0), stringprep_xmpp_nodeprep));
+ if (rc != STRINGPREP_OK)
+ {
+ log_error(error_msg + stringprep_strerror(rc));
+ return "";
+ }
+
+ char domain[max_jid_part_len] = {};
+ memcpy(domain, jid.domain.data(), jid.domain.size());
+ rc = static_cast<Stringprep_rc>(::stringprep(domain, max_jid_part_len,
+ static_cast<Stringprep_profile_flags>(0), stringprep_nameprep));
+ if (rc != STRINGPREP_OK)
+ {
+ log_error(error_msg + stringprep_strerror(rc));
+ return "";
+ }
+
+ return std::string(local) + "@" + domain;
+#else
+ (void)original;
+ return "";
+#endif
+}