From e43999d275ff27970ba973edd2be68fb6b998aaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Mon, 4 Jun 2012 19:15:34 +0200
Subject: Added ICU support.


diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot
index 098df0a..16c05c3 100644
--- a/BuildTools/SCons/SConscript.boot
+++ b/BuildTools/SCons/SConscript.boot
@@ -41,6 +41,7 @@ vars.Add(PathVariable("boost_libdir", "Boost library location", None, PathVariab
 vars.Add(PathVariable("expat_includedir", "Expat headers location", None, PathVariable.PathAccept))
 vars.Add(PathVariable("expat_libdir", "Expat library location", None, PathVariable.PathAccept))
 vars.Add("expat_libname", "Expat library name", "libexpat" if os.name == "nt" else "expat")
+vars.Add(PackageVariable("icu", "ICU library location", "no"))
 vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept))
 vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept))
 vars.Add("libidn_libname", "LibIDN library name", "libidn" if os.name == "nt" else "idn")
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct
index e91dd6e..eef7a80 100644
--- a/BuildTools/SCons/SConstruct
+++ b/BuildTools/SCons/SConstruct
@@ -294,6 +294,27 @@ if not env.get("HAVE_EXPAT", 0) and not env.get("HAVE_LIBXML", 0) :
 	env["HAVE_EXPAT"] = 1
 	env["EXPAT_BUNDLED"] = True
 
+################################################################################
+# IDN library
+################################################################################
+
+# ICU
+icu_env = conf_env.Clone()
+use_icu = bool(env["icu"])
+icu_prefix = env["icu"] if isinstance(env["icu"], str) else ""
+icu_flags = {}
+if icu_prefix :
+	icu_flags = { "CPPPATH": [os.path.join(icu_prefix, "include")] }
+	icu_flags["LIBPATH"] = [os.path.join(icu_prefix, "lib")]
+	icu_env.MergeFlags(icu_flags)
+
+icu_conf = Configure(icu_env)
+if use_icu and icu_conf.CheckCHeader("unicode/usprep.h") :
+	env["HAVE_ICU"] = 1
+	env["ICU_FLAGS"] = icu_flags
+	env["ICU_FLAGS"]["LIBS"] = ["icuuc"]
+icu_conf.Finish()
+
 # LibIDN
 libidn_conf_env = conf_env.Clone()
 libidn_flags = {}
@@ -303,14 +324,16 @@ if env.get("libidn_includedir", None) :
 	libidn_flags["CPPPATH"] = [env["libidn_includedir"]]
 libidn_conf_env.MergeFlags(libidn_flags)
 conf = Configure(libidn_conf_env)
-if conf.CheckCHeader("idna.h") and conf.CheckLib(env["libidn_libname"]) :
+if not env.get("HAVE_ICU") and conf.CheckCHeader("idna.h") and conf.CheckLib(env["libidn_libname"]) :
 	env["HAVE_LIBIDN"] = 1
 	env["LIBIDN_FLAGS"] = { "LIBS": [env["libidn_libname"]] }
 	env["LIBIDN_FLAGS"].update(libidn_flags)
-else :
-	env["LIBIDN_BUNDLED"] = 1
 conf.Finish()
 
+# Fallback to bundled LibIDN
+if not env.get("HAVE_ICU", False) and not env.get("HAVE_LIBIDN", False) :
+	env["LIBIDN_BUNDLED"] = 1
+
 # LibMiniUPnPc
 if env["experimental"] :
 	#libminiupnpc_conf_env = conf_env.Clone()
diff --git a/Limber/SConscript b/Limber/SConscript
index bc05f7f..d49fc94 100644
--- a/Limber/SConscript
+++ b/Limber/SConscript
@@ -22,12 +22,7 @@ elif env["SCONS_STAGE"] == "build" :
 	myenv.BuildVersion("BuildVersion.h", project = "limber")
 	myenv.UseFlags(env["LIMBER_FLAGS"])
 	myenv.UseFlags(env["SWIFTEN_FLAGS"])
-	myenv.UseFlags(env["LIBIDN_FLAGS"])
-	myenv.UseFlags(env.get("LIBXML_FLAGS", ""))
-	myenv.UseFlags(env.get("EXPAT_FLAGS", ""))
-	myenv.UseFlags(env["OPENSSL_FLAGS"])
-	myenv.UseFlags(env["BOOST_FLAGS"])
-	myenv.UseFlags(myenv["PLATFORM_FLAGS"])
+	myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"])
 	myenv.Program("limber", ["main.cpp"])
 
 	env.Append(UNITTEST_SOURCES = [
diff --git a/QA/UnitTest/SConscript b/QA/UnitTest/SConscript
index 3a19ea5..10301b9 100644
--- a/QA/UnitTest/SConscript
+++ b/QA/UnitTest/SConscript
@@ -15,14 +15,7 @@ if env["TEST"] :
 		myenv.UseFlags(env.get("LIMBER_FLAGS",""))
 		myenv.UseFlags(env.get("SWIFTEN_FLAGS",""))
 		myenv.UseFlags(env.get("CPPUNIT_FLAGS",""))
-		myenv.UseFlags(env.get("LIBIDN_FLAGS", ""))
-		myenv.UseFlags(env.get("BOOST_FLAGS", ""))
-		myenv.UseFlags(env.get("SQLITE_FLAGS", ""))
-		myenv.UseFlags(env.get("LIBXML_FLAGS", ""))
-		myenv.UseFlags(env.get("EXPAT_FLAGS", ""))
-		myenv.UseFlags(env.get("ZLIB_FLAGS", ""))
-		myenv.UseFlags(env.get("OPENSSL_FLAGS", ""))
-		myenv.UseFlags(env["PLATFORM_FLAGS"])
+		myenv.UseFlags(env.get("SWIFTEN_DEP_FLAGS", ""))
 		if env.get("HAVE_LIBXML") :
 			myenv.Append(CPPDEFINES = ["HAVE_LIBXML"])
 		if env.get("HAVE_EXPAT") :
@@ -35,4 +28,6 @@ if env["TEST"] :
 			for i in ["HOME", "USERPROFILE", "APPDATA"]:
 				if os.environ.get(i, "") :
 					myenv["ENV"][i] = os.environ[i]
+			if myenv["PLATFORM"] == "darwin" :
+				myenv["ENV"]["DYLD_LIBRARY_PATH"] = ":".join(map(lambda x : str(x), myenv.get("LIBPATH", [])))
 			myenv.Test(checker, is_checker = True)
diff --git a/Slimber/CLI/SConscript b/Slimber/CLI/SConscript
index 04e4976..e17996d 100644
--- a/Slimber/CLI/SConscript
+++ b/Slimber/CLI/SConscript
@@ -5,12 +5,7 @@ myenv.UseFlags(env["SLIMBER_FLAGS"])
 myenv.UseFlags(env["LIMBER_FLAGS"])
 myenv.UseFlags(env["SWIFTOOLS_FLAGS"])
 myenv.UseFlags(env["SWIFTEN_FLAGS"])
-myenv.UseFlags(env["LIBIDN_FLAGS"])
-myenv.UseFlags(env["BOOST_FLAGS"])
-myenv.UseFlags(env.get("LIBXML_FLAGS", {}))
-myenv.UseFlags(env.get("EXPAT_FLAGS", {}))
-myenv.UseFlags(env.get("AVAHI_FLAGS", {}))
-myenv.UseFlags(myenv["PLATFORM_FLAGS"])
+myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"])
 
 myenv.Program("slimber", [
 		"main.cpp",
diff --git a/Slimber/Cocoa/SConscript b/Slimber/Cocoa/SConscript
index 1283dc7..441dc27 100644
--- a/Slimber/Cocoa/SConscript
+++ b/Slimber/Cocoa/SConscript
@@ -5,13 +5,7 @@ myenv.UseFlags(env["LIMBER_FLAGS"])
 myenv.MergeFlags(env["SLIMBER_FLAGS"])
 myenv.MergeFlags(env["SWIFTOOLS_FLAGS"])
 myenv.MergeFlags(env["SWIFTEN_FLAGS"])
-myenv.MergeFlags(env["LIBIDN_FLAGS"])
-myenv.MergeFlags(env["BOOST_FLAGS"])
-myenv.MergeFlags(env.get("LIBXML_FLAGS", ""))
-myenv.MergeFlags(env.get("EXPAT_FLAGS", ""))
-myenv.Append(CXXFLAGS = myenv["OBJCCFLAGS"])
-myenv.Append(FRAMEWORKS = "Cocoa")
-myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
+myenv.MergeFlags(env["SWIFTEN_DEP_FLAGS"])
 
 myenv.Program("Slimber", [
 		"main.mm",
diff --git a/Swiften/Examples/LinkLocalTool/SConscript b/Swiften/Examples/LinkLocalTool/SConscript
index 8318515..788f5c1 100644
--- a/Swiften/Examples/LinkLocalTool/SConscript
+++ b/Swiften/Examples/LinkLocalTool/SConscript
@@ -2,15 +2,7 @@ Import("env")
 
 myenv = env.Clone()
 myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
-myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
-myenv.MergeFlags(myenv["BOOST_FLAGS"])
-myenv.MergeFlags(myenv["ZLIB_FLAGS"])
-myenv.MergeFlags(myenv["OPENSSL_FLAGS"])
-myenv.MergeFlags(myenv.get("SQLITE_FLAGS", {}))
-myenv.MergeFlags(myenv.get("LIBXML_FLAGS", {}))
-myenv.MergeFlags(myenv.get("EXPAT_FLAGS", {}))
-myenv.MergeFlags(myenv.get("AVAHI_FLAGS", {}))
-myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
+myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
 
 linkLocalTool = myenv.Program("LinkLocalTool", [
 		"main.cpp"
diff --git a/Swiften/Examples/ParserTester/SConscript b/Swiften/Examples/ParserTester/SConscript
index e3df0ba..09cffc9 100644
--- a/Swiften/Examples/ParserTester/SConscript
+++ b/Swiften/Examples/ParserTester/SConscript
@@ -2,10 +2,6 @@ Import("env")
 
 myenv = env.Clone()
 myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
-myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
-myenv.MergeFlags(myenv["BOOST_FLAGS"])
-myenv.MergeFlags(myenv.get("LIBXML_FLAGS", ""))
-myenv.MergeFlags(myenv.get("EXPAT_FLAGS", ""))
-myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
+myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
 
 myenv.Program("ParserTester", ["ParserTester.cpp"])
diff --git a/Swiften/IDN/ICUConverter.h b/Swiften/IDN/ICUConverter.h
new file mode 100644
index 0000000..6ed760a
--- /dev/null
+++ b/Swiften/IDN/ICUConverter.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2012 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+
+#include <unicode/ucnv.h>
+#include <cassert>
+#include <string>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <Swiften/Base/ByteArray.h>
+#include <Swiften/Base/SafeByteArray.h>
+
+namespace Swift {
+
+	class ICUConverter {
+		public:
+			typedef std::vector<UChar, SafeAllocator<UChar> > ICUString;
+
+			ICUConverter() {
+				UErrorCode status = U_ZERO_ERROR;
+				icuConverter.reset(ucnv_open("utf-8", &status), ucnv_close);
+				assert(U_SUCCESS(status));
+			}
+
+			template<typename T>
+			ICUString convertToICUString(const T& s) {
+				ICUString result;
+				result.resize(s.size());
+				UErrorCode status = U_ZERO_ERROR;
+				int icuResultLength = ucnv_toUChars(icuConverter.get(), vecptr(result), result.size(), toConstCharArray(s), s.size(), &status);
+				if (status == U_BUFFER_OVERFLOW_ERROR) {
+					status = U_ZERO_ERROR;
+					result.resize(icuResultLength);
+					icuResultLength = ucnv_toUChars(icuConverter.get(), vecptr(result), result.size(), toConstCharArray(s), s.size(), &status);
+				}
+				assert(U_SUCCESS(status));
+				result.resize(icuResultLength);
+				return result;
+			}
+
+			std::string convertToString(const ICUString& input) {
+				return std::string(vecptr(convertToArray(input)));
+			}
+
+			std::vector<char, SafeAllocator<char> > convertToArray(const ICUString& input) {
+				std::vector<char, SafeAllocator<char> > result;
+				result.resize(input.size());
+				UErrorCode status = U_ZERO_ERROR;
+				int inputLength = ucnv_fromUChars(icuConverter.get(), vecptr(result), result.size(), vecptr(input), input.size(), &status);
+				if (status == U_BUFFER_OVERFLOW_ERROR) {
+					status = U_ZERO_ERROR;
+					result.resize(inputLength);
+					inputLength = ucnv_fromUChars(icuConverter.get(), vecptr(result), result.size(), vecptr(input), input.size(), &status);
+				}
+				assert(U_SUCCESS(status));
+
+				result.resize(inputLength + 1);
+				result[result.size() - 1] = '\0';
+				return result;
+			}
+
+		private:
+			static const char* toConstCharArray(const std::string& input) {
+				return input.c_str();
+			}
+
+			static const char* toConstCharArray(const std::vector<unsigned char, SafeAllocator<unsigned char> >& input) {
+				return reinterpret_cast<const char*>(vecptr(input));
+			}
+
+		private:
+			boost::shared_ptr<UConverter> icuConverter;
+	};
+
+}
diff --git a/Swiften/IDN/IDNA.cpp b/Swiften/IDN/IDNA.cpp
index 16b4183..f2ac8fb 100644
--- a/Swiften/IDN/IDNA.cpp
+++ b/Swiften/IDN/IDNA.cpp
@@ -1,19 +1,51 @@
 /*
- * Copyright (c) 2010 Remko Tronçon
+ * 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/IDNA.h>
 
-#include <stringprep.h>
 #include <vector>
 #include <cstdlib>
+#if defined(HAVE_ICU)
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include <Swiften/IDN/ICUConverter.h>
+#include <unicode/uidna.h>
+#elif defined(HAVE_LIBIDN)
+#include <stringprep.h>
 #include <idna.h>
+#endif
+#include <Swiften/Base/ByteArray.h>
+#include <boost/shared_ptr.hpp>
 
 namespace Swift {
 
 std::string IDNA::getEncoded(const std::string& domain) {
+#if defined(HAVE_ICU)
+	UErrorCode status = U_ZERO_ERROR;
+	ICUConverter converter;
+
+	ICUConverter::ICUString icuInput = converter.convertToICUString(domain);
+	ICUConverter::ICUString icuResult;
+	icuResult.resize(icuInput.size());
+	UParseError parseError;
+	int icuResultLength = uidna_IDNToASCII(vecptr(icuInput), icuInput.size(), vecptr(icuResult), icuResult.size(), UIDNA_DEFAULT, &parseError, &status);
+	if (status == U_BUFFER_OVERFLOW_ERROR) {
+		status = U_ZERO_ERROR;
+		icuResult.resize(icuResultLength);
+		icuResultLength = uidna_IDNToASCII(vecptr(icuInput), icuInput.size(), vecptr(icuResult), icuResult.size(), UIDNA_DEFAULT, &parseError, &status);
+	}
+	if (U_FAILURE(status)) {
+		return domain;
+	}
+	icuResult.resize(icuResultLength);
+
+	return converter.convertToString(icuResult);
+
+#elif defined(HAVE_LIBIDN)
+
+
 	char* output;
 	if (idna_to_ascii_8z(domain.c_str(), &output, 0) == IDNA_SUCCESS) {
 		std::string result(output);
@@ -23,6 +55,7 @@ std::string IDNA::getEncoded(const std::string& domain) {
 	else {
 		return domain;
 	}
+#endif
 }
 
 }
diff --git a/Swiften/IDN/SConscript b/Swiften/IDN/SConscript
index 99b35fd..1433318 100644
--- a/Swiften/IDN/SConscript
+++ b/Swiften/IDN/SConscript
@@ -1,7 +1,12 @@
 Import("swiften_env", "env")
 
 myenv = swiften_env.Clone()
-myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
+if myenv.get("HAVE_ICU") :
+	myenv.MergeFlags(swiften_env["ICU_FLAGS"])
+	myenv.Append(CPPDEFINES = ["HAVE_ICU"])
+elif myenv.get("HAVE_LIBIDN") :
+	myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
+	myenv.Append(CPPDEFINES = ["HAVE_LIBIDN"])
 
 objects = myenv.SwiftenObject([
 			"StringPrep.cpp",
@@ -11,4 +16,5 @@ swiften_env.Append(SWIFTEN_OBJECTS = [objects])
 
 env.Append(UNITTEST_SOURCES = [
 			File("UnitTest/StringPrepTest.cpp"),
+			File("UnitTest/IDNATest.cpp"),
 	])
diff --git a/Swiften/IDN/StringPrep.cpp b/Swiften/IDN/StringPrep.cpp
index 9085569..dfaba06 100644
--- a/Swiften/IDN/StringPrep.cpp
+++ b/Swiften/IDN/StringPrep.cpp
@@ -1,23 +1,101 @@
 /*
- * Copyright (c) 2010 Remko Tronçon
+ * 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>
 
-extern "C"
-{
+#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;
 
-	namespace {
+#if defined(HAVE_ICU)
+
+namespace {
+	static UStringPrepProfileType getICUProfileType(StringPrep::Profile profile) {
+		switch(profile) {
+			case StringPrep::NamePrep: return USPREP_RFC3491_NAMEPREP; break;
+			case StringPrep::XMPPNodePrep: return USPREP_RFC3920_NODEPREP; break;
+			case StringPrep::XMPPResourcePrep: return USPREP_RFC3920_RESOURCEPREP; break;
+			case StringPrep::SASLPrep: return USPREP_RFC4013_SASLPREP; break;
+		}
+		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) {
@@ -63,3 +141,6 @@ SafeByteArray StringPrep::getPrepared(const SafeByteArray& s, Profile profile) {
 }
 
 }
+
+#endif
+
diff --git a/Swiften/IDN/UnitTest/IDNATest.cpp b/Swiften/IDN/UnitTest/IDNATest.cpp
new file mode 100644
index 0000000..09e79c8
--- /dev/null
+++ b/Swiften/IDN/UnitTest/IDNATest.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/IDN/IDNA.h>
+
+using namespace Swift;
+
+class IDNATest : public CppUnit::TestFixture {
+		CPPUNIT_TEST_SUITE(IDNATest);
+		CPPUNIT_TEST(testGetEncoded);
+		CPPUNIT_TEST(testGetEncoded_International);
+		CPPUNIT_TEST_SUITE_END();
+
+	public:
+		void testGetEncoded() {
+			std::string result = IDNA::getEncoded("www.swift.im");
+
+			CPPUNIT_ASSERT_EQUAL(std::string("www.swift.im"), result);
+		}
+
+		void testGetEncoded_International() {
+			std::string result = IDNA::getEncoded("www.tron\xc3\x87on.com");
+
+			CPPUNIT_ASSERT_EQUAL(std::string("www.xn--tronon-zua.com"), result);
+		}
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IDNATest);
+
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index 9b47ef7..0822595 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -19,7 +19,6 @@
 #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>
diff --git a/Swiften/JID/SConscript b/Swiften/JID/SConscript
index d347cd9..12565fc 100644
--- a/Swiften/JID/SConscript
+++ b/Swiften/JID/SConscript
@@ -1,8 +1,6 @@
 Import("swiften_env")
 
 myenv = swiften_env.Clone()
-myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
-
 objects = myenv.SwiftenObject([
 			"JID.cpp",
 		])
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index ecd7be9..54565b4 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -1,7 +1,6 @@
 Import("swiften_env")
 
 myenv = swiften_env.Clone()
-myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
 
 sourceList = [
 			"HTTPConnectProxiedConnection.cpp",
diff --git a/Swiften/QA/NetworkTest/SConscript b/Swiften/QA/NetworkTest/SConscript
index f9308f6..e1dea26 100644
--- a/Swiften/QA/NetworkTest/SConscript
+++ b/Swiften/QA/NetworkTest/SConscript
@@ -8,10 +8,8 @@ if env["TEST"] :
 		myenv.Append(CPPDEFINES = ["TEST_IPV6"])
 	myenv.MergeFlags(myenv["CHECKER_FLAGS"])
 	myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
+	myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
 	myenv.MergeFlags(myenv["CPPUNIT_FLAGS"])
-	myenv.MergeFlags(myenv["BOOST_FLAGS"])
-	myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
-	myenv.MergeFlags(env["PLATFORM_FLAGS"])
 
 	tester = myenv.Program("NetworkTest", [
 			"BoostConnectionServerTest.cpp",
diff --git a/Swiften/QA/TLSTest/SConscript b/Swiften/QA/TLSTest/SConscript
index 14e2de0..18f6998 100644
--- a/Swiften/QA/TLSTest/SConscript
+++ b/Swiften/QA/TLSTest/SConscript
@@ -7,13 +7,8 @@ if env["TEST"] :
 	myenv.MergeFlags(myenv["CHECKER_FLAGS"])
 	myenv.MergeFlags(myenv["SWIFTOOLS_FLAGS"])
 	myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
+	myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
 	myenv.MergeFlags(myenv["CPPUNIT_FLAGS"])
-	myenv.MergeFlags(myenv["BOOST_FLAGS"])
-	myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
-	if myenv.get("HAVE_OPENSSL") :
-		myenv.MergeFlags(myenv["OPENSSL_FLAGS"])
-		myenv.Append(CPPDEFINES = ["HAVE_OPENSSL"])
-	myenv.MergeFlags(myenv["PLATFORM_FLAGS"])
 	
 	tester = myenv.Program("TLSTest", [
 			"CertificateTest.cpp",
diff --git a/Swiften/SASL/SConscript b/Swiften/SASL/SConscript
index 085e49d..3a67938 100644
--- a/Swiften/SASL/SConscript
+++ b/Swiften/SASL/SConscript
@@ -1,7 +1,6 @@
 Import("swiften_env", "env")
 
 myenv = swiften_env.Clone()
-myenv.MergeFlags(swiften_env["LIBIDN_FLAGS"])
 
 objects = myenv.SwiftenObject([
 		"ClientAuthenticator.cpp",
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 2e0b73b..340e8a5 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -6,7 +6,7 @@ Import("env")
 # Flags
 ################################################################################
 
-swiften_dep_modules = ["BOOST", "GCONF", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP"]
+swiften_dep_modules = ["BOOST", "GCONF", "ICU", "LIBIDN", "ZLIB", "OPENSSL", "LIBXML", "EXPAT", "AVAHI", "LIBMINIUPNPC", "LIBNATPMP"]
 
 if env["SCONS_STAGE"] == "flags" :
 	env["SWIFTEN_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift")
-- 
cgit v0.10.2-6-g49f6