summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-04-18 20:27:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-18 20:27:42 (GMT)
commit603f4622bad15da3b800bab5277091904a47f972 (patch)
treed5d454b13515cdc1ff290a6d77736dde8c6f2d8f /Swiften/IDN/StringPrep.cpp
parent2a1b34a623e6e4f28481400637a3a99d5f7adc53 (diff)
downloadswift-603f4622bad15da3b800bab5277091904a47f972.zip
swift-603f4622bad15da3b800bab5277091904a47f972.tar.bz2
Fix ICU compilation.
Change-Id: I87be125a96f3b9f6755c52c58ba02bb85d945bf9
Diffstat (limited to 'Swiften/IDN/StringPrep.cpp')
-rw-r--r--Swiften/IDN/StringPrep.cpp146
1 files changed, 0 insertions, 146 deletions
diff --git a/Swiften/IDN/StringPrep.cpp b/Swiften/IDN/StringPrep.cpp
deleted file mode 100644
index a0d067e..0000000
--- a/Swiften/IDN/StringPrep.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include <Swiften/IDN/StringPrep.h>
-
-#if defined(HAVE_ICU)
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#include <Swiften/IDN/ICUConverter.h>
-#include <unicode/usprep.h>
-#include <unicode/ucnv.h>
-#elif defined(HAVE_LIBIDN)
-extern "C" {
- #include <stringprep.h>
-}
-#endif
-
-#include <vector>
-#include <cassert>
-#include <Swiften/Base/SafeAllocator.h>
-#include <boost/shared_ptr.hpp>
-
-using namespace Swift;
-
-#if defined(HAVE_ICU)
-
-namespace {
- static UStringPrepProfileType getICUProfileType(StringPrep::Profile profile) {
- switch(profile) {
- case StringPrep::NamePrep: return USPREP_RFC3491_NAMEPREP;
- case StringPrep::XMPPNodePrep: return USPREP_RFC3920_NODEPREP;
- case StringPrep::XMPPResourcePrep: return USPREP_RFC3920_RESOURCEPREP;
- case StringPrep::SASLPrep: return USPREP_RFC4013_SASLPREP;
- }
- assert(false);
- return USPREP_RFC3491_NAMEPREP;
- }
-
- template<typename StringType>
- std::vector<char, SafeAllocator<char> > getStringPrepared(const StringType& s, StringPrep::Profile profile) {
- UErrorCode status = U_ZERO_ERROR;
- ICUConverter converter;
-
- boost::shared_ptr<UStringPrepProfile> icuProfile(usprep_openByType(getICUProfileType(profile), &status), usprep_close);
- assert(U_SUCCESS(status));
-
- ICUConverter::ICUString icuInput = converter.convertToICUString(s);
- ICUConverter::ICUString icuResult;
- UParseError parseError;
- icuResult.resize(icuInput.size());
- int icuResultLength = usprep_prepare(icuProfile.get(), vecptr(icuInput), icuInput.size(), vecptr(icuResult), icuResult.size(), USPREP_ALLOW_UNASSIGNED, &parseError, &status); icuResult.resize(icuResultLength);
- if (status == U_BUFFER_OVERFLOW_ERROR) {
- status = U_ZERO_ERROR;
- icuResult.resize(icuResultLength);
- icuResultLength = usprep_prepare(icuProfile.get(), vecptr(icuInput), icuInput.size(), vecptr(icuResult), icuResult.size(), USPREP_ALLOW_UNASSIGNED, &parseError, &status); icuResult.resize(icuResultLength);
- }
- if (U_FAILURE(status)) {
- return std::vector<char, SafeAllocator<char> >();
- }
- icuResult.resize(icuResultLength);
-
- return converter.convertToArray(icuResult);
- }
-}
-
-namespace Swift {
-
-std::string StringPrep::getPrepared(const std::string& s, Profile profile) {
- if (s.empty()) {
- return "";
- }
- std::vector<char, SafeAllocator<char> > preparedData = getStringPrepared(s, profile);
- if (preparedData.empty()) {
- throw std::exception();
- }
- return std::string(vecptr(preparedData));
-}
-
-SafeByteArray StringPrep::getPrepared(const SafeByteArray& s, Profile profile) {
- if (s.empty()) {
- return SafeByteArray();
- }
- std::vector<char, SafeAllocator<char> > preparedData = getStringPrepared(s, profile);
- if (preparedData.empty()) {
- throw std::exception();
- }
- return createSafeByteArray(reinterpret_cast<const char*>(vecptr(preparedData)));
-}
-
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-#elif defined(HAVE_LIBIDN)
-
-namespace {
- static const int MAX_STRINGPREP_SIZE = 1024;
-
- const Stringprep_profile* getLibIDNProfile(StringPrep::Profile profile) {
- switch(profile) {
- case StringPrep::NamePrep: return stringprep_nameprep;
- case StringPrep::XMPPNodePrep: return stringprep_xmpp_nodeprep;
- case StringPrep::XMPPResourcePrep: return stringprep_xmpp_resourceprep;
- case StringPrep::SASLPrep: return stringprep_saslprep;
- }
- assert(false);
- return 0;
- }
-
- template<typename StringType, typename ContainerType>
- ContainerType getStringPrepared(const StringType& s, StringPrep::Profile profile) {
- ContainerType input(s.begin(), s.end());
- input.resize(MAX_STRINGPREP_SIZE);
- if (stringprep(&input[0], MAX_STRINGPREP_SIZE, static_cast<Stringprep_profile_flags>(0), getLibIDNProfile(profile)) == 0) {
- return input;
- }
- else {
- return ContainerType();
- }
- }
-}
-
-namespace Swift {
-
-std::string StringPrep::getPrepared(const std::string& s, Profile profile) {
- std::vector<char> preparedData = getStringPrepared< std::string, std::vector<char> >(s, profile);
- if (preparedData.empty()) {
- throw std::exception();
- }
- return std::string(vecptr(preparedData));
-}
-
-SafeByteArray StringPrep::getPrepared(const SafeByteArray& s, Profile profile) {
- std::vector<char, SafeAllocator<char> > preparedData = getStringPrepared<SafeByteArray, std::vector<char, SafeAllocator<char> > >(s, profile);
- if (preparedData.empty()) {
- throw std::exception();
- }
- return createSafeByteArray(reinterpret_cast<const char*>(vecptr(preparedData)));
-}
-
-}
-
-#endif
-