diff options
| author | Remko Tronçon <git@el-tramo.be> | 2011-05-07 12:38:58 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2011-05-07 12:38:58 (GMT) | 
| commit | 49788da022de59de64752fdf4a89d4267d1ca201 (patch) | |
| tree | 0e583966481afe00131057e16f185daeb35299c7 | |
| parent | 56585257474fe4e9daf108d046177a6d36043cf7 (diff) | |
| download | swift-49788da022de59de64752fdf4a89d4267d1ca201.zip swift-49788da022de59de64752fdf4a89d4267d1ca201.tar.bz2 | |
Use naive JID escaping algorithm to work around a bug in GCC4.5+boost1.42.
| -rw-r--r-- | Swiften/JID/JID.cpp | 62 | 
1 files changed, 53 insertions, 9 deletions
| diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp index bbc149c..7945cef 100644 --- a/Swiften/JID/JID.cpp +++ b/Swiften/JID/JID.cpp @@ -34,7 +34,13 @@ static PrepCache resourcePrepCache;  static const std::list<char> escapedChars = boost::assign::list_of(' ')('"')('&')('\'')('/')('<')('>')('@')(':'); -bool getEscapeSequenceValue(const std::string& sequence, unsigned char& value) { +static std::string getEscaped(char c) { +	std::ostringstream s; +	s << '\\' << std::hex << static_cast<int>(c); +	return s.str(); +} + +static bool getEscapeSequenceValue(const std::string& sequence, unsigned char& value) {  	std::stringstream s;  	unsigned int v;  	s << std::hex << sequence; @@ -43,6 +49,9 @@ bool getEscapeSequenceValue(const std::string& sequence, unsigned char& value) {  	return (!s.fail() && !s.bad() && (value == 0x5C || std::find(escapedChars.begin(), escapedChars.end(), value) != escapedChars.end()));  } +// Disabling this code for now, since GCC4.5+boost1.42 (on ubuntu) seems to +// result in a bug. Replacing it with naive code. +#if 0  struct UnescapedCharacterFinder {  	template<typename Iterator>	boost::iterator_range<Iterator> operator()(Iterator begin, Iterator end) {  		for (; begin != end; ++begin) { @@ -99,9 +108,9 @@ struct EscapedCharacterFormatter {  		return boost::copy_range<std::string>(match);  	}  }; +#endif - -namespace Swift { +using namespace Swift;  JID::JID(const char* jid) {  	initializeFromString(std::string(jid)); @@ -201,12 +210,47 @@ int JID::compare(const Swift::JID& o, CompareType compareType) const {  }  std::string JID::getEscapedNode(const std::string& node) { -	return boost::find_format_all_copy(node, UnescapedCharacterFinder(), UnescapedCharacterFormatter()); +	std::string result; +	for (std::string::const_iterator i = node.begin(); i != node.end(); ++i) { +		if (std::find(escapedChars.begin(), escapedChars.end(), *i) != escapedChars.end()) { +			result += getEscaped(*i); +			continue; +		} +		else if (*i == '\\') { +			// Check if we have an escaped dissalowed character sequence +			std::string::const_iterator innerBegin = i + 1; +			if (innerBegin != result.end() && innerBegin + 1 != result.end()) { +				std::string::const_iterator innerEnd = innerBegin + 2; +				unsigned char value; +				if (getEscapeSequenceValue(std::string(innerBegin, innerEnd), value)) { +					result += getEscaped(*i); +					continue; +				} +			} +		} +		result += *i; +	} +	return result; +	//return boost::find_format_all_copy(node, UnescapedCharacterFinder(), UnescapedCharacterFormatter());  } - +					  std::string JID::getUnescapedNode() const { -	return boost::find_format_all_copy(node_, EscapedCharacterFinder(), EscapedCharacterFormatter()); +	std::string result; +	for (std::string::const_iterator j = node_.begin(); j != node_.end();) { +		if (*j == '\\') { +			std::string::const_iterator innerEnd = j + 1; +			for (size_t i = 0; i < 2 && innerEnd != node_.end(); ++i, ++innerEnd) { +			} +			unsigned char value; +			if (getEscapeSequenceValue(std::string(j + 1, innerEnd), value)) { +				result += std::string(reinterpret_cast<const char*>(&value), 1); +				j = innerEnd; +				continue; +			} +		} +		result += *j; +		++j; +	} +	return result; +	//return boost::find_format_all_copy(node_, EscapedCharacterFinder(), EscapedCharacterFormatter());  } - -} // namespace Swift - | 
 Swift
 Swift