diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-07-12 18:47:03 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-07-12 18:47:03 (GMT) |
commit | 63b311c1bb60469eb5e2ccd2107739e11b189a15 (patch) | |
tree | 870057043f88e91b71b961a821a4dace859fc839 /Swiften/JID/JID.cpp | |
parent | c6819a5fd632d03cfe72a58922054765c7383aa6 (diff) | |
parent | 08536b4ed31c30a25a343c3c2619676e67a0c692 (diff) | |
download | swift-contrib-63b311c1bb60469eb5e2ccd2107739e11b189a15.zip swift-contrib-63b311c1bb60469eb5e2ccd2107739e11b189a15.tar.bz2 |
Merge branch 'swift-1.x'
* swift-1.x:
Fixed bug with illegal resource in JID resulting in empty resource.
Updated the german translation
Conflicts:
Swiften/IDN/StringPrep.cpp
Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp
Diffstat (limited to 'Swiften/JID/JID.cpp')
-rw-r--r-- | Swiften/JID/JID.cpp | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index 2ebbdd6..653ac6a 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -110,24 +110,25 @@ struct EscapedCharacterFormatter { }; #endif -JID::JID(const char* jid) { +JID::JID(const char* jid) : valid_(true) { initializeFromString(std::string(jid)); } -JID::JID(const std::string& jid) { +JID::JID(const std::string& jid) : valid_(true) { initializeFromString(jid); } -JID::JID(const std::string& node, const std::string& domain) : hasResource_(false) { +JID::JID(const std::string& node, const std::string& domain) : valid_(true), hasResource_(false) { nameprepAndSetComponents(node, domain, ""); } -JID::JID(const std::string& node, const std::string& domain, const std::string& resource) : hasResource_(true) { +JID::JID(const std::string& node, const std::string& domain, const std::string& resource) : valid_(true), hasResource_(true) { nameprepAndSetComponents(node, domain, resource); } void JID::initializeFromString(const std::string& jid) { if (String::beginsWith(jid, '@')) { + valid_ = false; return; } @@ -153,31 +154,40 @@ void JID::initializeFromString(const std::string& jid) { void JID::nameprepAndSetComponents(const std::string& node, const std::string& domain, const std::string& resource) { + try { #ifndef SWIFTEN_CACHE_JID_PREP - node_ = StringPrep::getPrepared(node, StringPrep::NamePrep); - domain_ = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); - resource_ = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep); + node_ = StringPrep::getPrepared(node, StringPrep::NamePrep); + domain_ = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); + resource_ = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep); #else - std::pair<PrepCache::iterator, bool> r; + 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 = 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())); - if (r.second) { - r.first->second = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); - } - domain_ = r.first->second; + r = domainPrepCache.insert(std::make_pair(domain, std::string())); + if (r.second) { + r.first->second = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep); + } + domain_ = r.first->second; + if (domain_.empty()) { + valid_ = false; + return; + } - r = resourcePrepCache.insert(std::make_pair(resource, std::string())); - if (r.second) { - r.first->second = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep); - } - resource_ = r.first->second; + r = resourcePrepCache.insert(std::make_pair(resource, std::string())); + if (r.second) { + r.first->second = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep); + } + resource_ = r.first->second; #endif + } + catch (const std::exception&) { + valid_ = false; + } } std::string JID::toString() const { |