summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/jid.cpp
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2017-06-24 09:21:37 +0200
committerJonas Smedegaard <dr@jones.dk>2017-06-24 09:21:37 +0200
commit3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb (patch)
tree9a5684babcd16d302fbe59c56b6045660ad62488 /louloulibs/xmpp/jid.cpp
parentf9cee98aacd6aea8ccb7f5677b4ff1e1e234e4d1 (diff)
parentc21cbbf9667991d2b928562a9c199e625d3f9bba (diff)
downloadbiboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.gz
biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.bz2
biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.tar.xz
biboumi-3d39f109ba8ea7ae9778c58bd1665b9e8e0f45cb.zip
Updated version 5.0 from 'upstream/5.0'
with Debian dir 2ae31d03ffb1d79153a692af23c7b2b097cc4b2b
Diffstat (limited to 'louloulibs/xmpp/jid.cpp')
-rw-r--r--louloulibs/xmpp/jid.cpp99
1 files changed, 0 insertions, 99 deletions
diff --git a/louloulibs/xmpp/jid.cpp b/louloulibs/xmpp/jid.cpp
deleted file mode 100644
index 7b62f3e..0000000
--- a/louloulibs/xmpp/jid.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#include <xmpp/jid.hpp>
-#include <algorithm>
-#include <cstring>
-#include <map>
-
-#include <louloulibs.h>
-#ifdef LIBIDN_FOUND
- #include <stringprep.h>
-#endif
-
-#include <logger/logger.hpp>
-
-Jid::Jid(const std::string& jid)
-{
- std::string::size_type slash = jid.find('/');
- if (slash != std::string::npos)
- {
- this->resource = jid.substr(slash + 1);
- }
-
- std::string::size_type at = jid.find('@');
- if (at != std::string::npos && at < slash)
- {
- this->local = jid.substr(0, at);
- at++;
- }
- else
- at = 0;
-
- this->domain = jid.substr(at, slash - at);
-}
-
-static constexpr size_t max_jid_part_len = 1023;
-
-std::string jidprep(const std::string& original)
-{
-#ifdef LIBIDN_FOUND
- using CacheType = std::map<std::string, std::string>;
- static CacheType cache;
- std::pair<CacheType::iterator, bool> cached = cache.insert({original, {}});
- if (std::get<1>(cached) == false)
- { // Insertion failed: the result is already in the cache, return it
- return std::get<0>(cached)->second;
- }
-
- 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(), std::min(max_jid_part_len, 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(), std::min(max_jid_part_len, 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 "";
- }
- std::replace_if(std::begin(domain), domain + ::strlen(domain),
- [](const char c) -> bool
- {
- return !((c >= 'a' && c <= 'z') || c == '-' ||
- (c >= '0' && c <= '9') || c == '.');
- }, '-');
-
- // If there is no resource, stop here
- if (jid.resource.empty())
- {
- std::get<0>(cached)->second = std::string(local) + "@" + domain;
- return std::get<0>(cached)->second;
- }
-
- // Otherwise, also process the resource part
- char resource[max_jid_part_len] = {};
- memcpy(resource, jid.resource.data(), std::min(max_jid_part_len, jid.resource.size()));
- rc = static_cast<Stringprep_rc>(::stringprep(resource, max_jid_part_len,
- static_cast<Stringprep_profile_flags>(0), stringprep_xmpp_resourceprep));
- if (rc != STRINGPREP_OK)
- {
- log_error(error_msg + stringprep_strerror(rc));
- return "";
- }
- std::get<0>(cached)->second = std::string(local) + "@" + domain + "/" + resource;
- return std::get<0>(cached)->second;
-
-#else
- (void)original;
- return "";
-#endif
-}