summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/JID/JID.cpp')
-rw-r--r--Swiften/JID/JID.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index 66d6ff6..9b47ef7 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -6,35 +6,37 @@
#define SWIFTEN_CACHE_JID_PREP
#include <vector>
#include <list>
#include <iostream>
#include <string>
#ifdef SWIFTEN_CACHE_JID_PREP
+#include <boost/thread/mutex.hpp>
#include <boost/unordered_map.hpp>
#endif
#include <boost/assign/list_of.hpp>
#include <boost/algorithm/string/find_format.hpp>
#include <boost/algorithm/string/finder.hpp>
#include <sstream>
#include <stringprep.h>
#include <Swiften/Base/String.h>
#include <Swiften/JID/JID.h>
#include <Swiften/IDN/StringPrep.h>
using namespace Swift;
#ifdef SWIFTEN_CACHE_JID_PREP
typedef boost::unordered_map<std::string, std::string> PrepCache;
+static boost::mutex namePrepCacheMutex;
static PrepCache nodePrepCache;
static PrepCache domainPrepCache;
static PrepCache resourcePrepCache;
#endif
static const std::list<char> escapedChars = boost::assign::list_of(' ')('"')('&')('\'')('/')('<')('>')('@')(':');
static std::string getEscaped(char c) {
return makeString() << '\\' << std::hex << static_cast<int>(c);
@@ -148,24 +150,30 @@ void JID::initializeFromString(const std::string& jid) {
nameprepAndSetComponents("", nodeAndDomain.first, resource);
}
else {
nameprepAndSetComponents(nodeAndDomain.first, nodeAndDomain.second, resource);
}
}
void JID::nameprepAndSetComponents(const std::string& node, const std::string& domain, const std::string& resource) {
+ if (domain.empty()) {
+ valid_ = false;
+ return;
+ }
try {
#ifndef SWIFTEN_CACHE_JID_PREP
node_ = StringPrep::getPrepared(node, StringPrep::NamePrep);
domain_ = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep);
resource_ = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep);
#else
+ boost::mutex::scoped_lock lock(namePrepCacheMutex);
+
std::pair<PrepCache::iterator, bool> r;
r = nodePrepCache.insert(std::make_pair(node, std::string()));
if (r.second) {
r.first->second = StringPrep::getPrepared(node, StringPrep::NamePrep);
}
node_ = r.first->second;
r = domainPrepCache.insert(std::make_pair(domain, std::string()));