summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/JID/JID.cpp71
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp7
2 files changed, 15 insertions, 63 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index e8a4700..a31c19f 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -6,4 +6,2 @@
-#define SWIFTEN_CACHE_JID_PREP
-
#include <sstream>
@@ -12,7 +10,2 @@
-#ifdef SWIFTEN_CACHE_JID_PREP
-#include <mutex>
-#include <unordered_map>
-#endif
-
#include <boost/optional.hpp>
@@ -30,11 +23,2 @@ using namespace Swift;
-#ifdef SWIFTEN_CACHE_JID_PREP
-typedef std::unordered_map<std::string, std::string> PrepCache;
-
-static std::mutex namePrepCacheMutex;
-static PrepCache nodePrepCache;
-static PrepCache domainPrepCache;
-static PrepCache resourcePrepCache;
-#endif
-
static const std::vector<char> escapedChars = {' ', '"', '&', '\'', '/', '<', '>', '@', ':'};
@@ -126,50 +110,11 @@ void JID::nameprepAndSetComponents(const std::string& node, const std::string& d
}
-#ifndef SWIFTEN_CACHE_JID_PREP
- node_ = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep);
- domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
- resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep);
-#else
- std::unique_lock<std::mutex> lock(namePrepCacheMutex);
-
- std::pair<PrepCache::iterator, bool> r;
-
- r = nodePrepCache.insert(std::make_pair(node, std::string()));
- if (r.second) {
- try {
- r.first->second = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep);
- }
- catch (...) {
- nodePrepCache.erase(r.first);
- valid_ = false;
- return;
- }
- }
- node_ = r.first->second;
-
- r = domainPrepCache.insert(std::make_pair(domain, std::string()));
- if (r.second) {
- try {
- r.first->second = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
- }
- catch (...) {
- domainPrepCache.erase(r.first);
- valid_ = false;
- return;
- }
- }
- domain_ = r.first->second;
- r = resourcePrepCache.insert(std::make_pair(resource, std::string()));
- if (r.second) {
- try {
- r.first->second = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep);
- }
- catch (...) {
- resourcePrepCache.erase(r.first);
- valid_ = false;
- return;
- }
+ try {
+ node_ = idnConverter->getStringPrepared(node, IDNConverter::XMPPNodePrep);
+ domain_ = idnConverter->getStringPrepared(domain, IDNConverter::NamePrep);
+ resource_ = idnConverter->getStringPrepared(resource, IDNConverter::XMPPResourcePrep);
+ } catch (...) {
+ valid_ = false;
+ return;
}
- resource_ = r.first->second;
-#endif
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp
index 0101a4f..aefda33 100644
--- a/Swiften/JID/UnitTest/JIDTest.cpp
+++ b/Swiften/JID/UnitTest/JIDTest.cpp
@@ -66,2 +66,3 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testGetUnescapedNode_XEP106Examples);
+ CPPUNIT_TEST(testStringPrepFailures);
CPPUNIT_TEST_SUITE_END();
@@ -161,2 +162,8 @@ class JIDTest : public CppUnit::TestFixture
+ void testStringPrepFailures() {
+ CPPUNIT_ASSERT_EQUAL(false, JID("foo@bar", "example.com").isValid());
+ CPPUNIT_ASSERT_EQUAL(false, JID("foo^", "example*com").isValid());
+ CPPUNIT_ASSERT_EQUAL(false, JID("foobar", "example^com").isValid());
+ }
+
void testConstructorWithString_EmptyDomainWithResource() {