Thu Jul 21 17:16:17 2016 UTC ()
Add two patches from upstream that fix wide character support.

In particular, this fixes ftp mode.

Investigated with upstream by richard@, thank you very much!

Bump PKGREVISION.


(wiz)
diff -r1.2 -r1.3 pkgsrc/net/libfilezilla/Makefile
diff -r1.3 -r1.4 pkgsrc/net/libfilezilla/distinfo
diff -r0 -r1.4 pkgsrc/net/libfilezilla/patches/patch-lib_string.cpp
diff -r0 -r1.1 pkgsrc/net/libfilezilla/patches/patch-tests_string.cpp

cvs diff -r1.2 -r1.3 pkgsrc/net/libfilezilla/Makefile (expand / switch to unified diff)

--- pkgsrc/net/libfilezilla/Makefile 2016/07/19 18:42:22 1.2
+++ pkgsrc/net/libfilezilla/Makefile 2016/07/21 17:16:17 1.3
@@ -1,16 +1,17 @@ @@ -1,16 +1,17 @@
1# $NetBSD: Makefile,v 1.2 2016/07/19 18:42:22 wiz Exp $ 1# $NetBSD: Makefile,v 1.3 2016/07/21 17:16:17 wiz Exp $
2 2
3DISTNAME= libfilezilla-0.5.3 3DISTNAME= libfilezilla-0.5.3
 4PKGREVISION= 1
4CATEGORIES= devel 5CATEGORIES= devel
5MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=filezilla/} 6MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=filezilla/}
6EXTRACT_SUFX= .tar.bz2 7EXTRACT_SUFX= .tar.bz2
7 8
8MAINTAINER= pkgsrc-users@NetBSD.org 9MAINTAINER= pkgsrc-users@NetBSD.org
9HOMEPAGE= https://lib.filezilla-project.org/ 10HOMEPAGE= https://lib.filezilla-project.org/
10COMMENT= Library for building high-performing, platform-independent programs 11COMMENT= Library for building high-performing, platform-independent programs
11LICENSE= gnu-gpl-v2 12LICENSE= gnu-gpl-v2
12 13
13GNU_CONFIGURE= yes 14GNU_CONFIGURE= yes
14USE_TOOLS+= pkg-config 15USE_TOOLS+= pkg-config
15USE_LANGUAGES= c c++ 16USE_LANGUAGES= c c++
16 17

cvs diff -r1.3 -r1.4 pkgsrc/net/libfilezilla/distinfo (expand / switch to unified diff)

--- pkgsrc/net/libfilezilla/distinfo 2016/07/19 18:42:22 1.3
+++ pkgsrc/net/libfilezilla/distinfo 2016/07/21 17:16:17 1.4
@@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
1$NetBSD: distinfo,v 1.3 2016/07/19 18:42:22 wiz Exp $ 1$NetBSD: distinfo,v 1.4 2016/07/21 17:16:17 wiz Exp $
2 2
3SHA1 (libfilezilla-0.5.3.tar.bz2) = 035c79d677ee7ab00aaf7b3b65e47139e955f072 3SHA1 (libfilezilla-0.5.3.tar.bz2) = 035c79d677ee7ab00aaf7b3b65e47139e955f072
4RMD160 (libfilezilla-0.5.3.tar.bz2) = bcc0905c81030c0b8ec563bd3017b404f82271cd 4RMD160 (libfilezilla-0.5.3.tar.bz2) = bcc0905c81030c0b8ec563bd3017b404f82271cd
5SHA512 (libfilezilla-0.5.3.tar.bz2) = 73c1e5a8940e08dc96f511dc5dce7bdc17d2feada131b4459e8a65c074e48a04b7eb884e55a59ac1e04c72ae47cd596c8f668cd7086f302f86bdbb14a32e83cd 5SHA512 (libfilezilla-0.5.3.tar.bz2) = 73c1e5a8940e08dc96f511dc5dce7bdc17d2feada131b4459e8a65c074e48a04b7eb884e55a59ac1e04c72ae47cd596c8f668cd7086f302f86bdbb14a32e83cd
6Size (libfilezilla-0.5.3.tar.bz2) = 376339 bytes 6Size (libfilezilla-0.5.3.tar.bz2) = 376339 bytes
 7SHA1 (patch-lib_string.cpp) = 00632aede9d27348efa664bfa84f6dbe90f92dd2
 8SHA1 (patch-tests_string.cpp) = 7c55ccccfebdf81e50bbe8f8f44351b41505f554

File Added: pkgsrc/net/libfilezilla/patches/Attic/patch-lib_string.cpp
$NetBSD: patch-lib_string.cpp,v 1.4 2016/07/21 17:16:17 wiz Exp $

SVN 7668

--- lib/string.cpp.orig	2016-06-20 08:08:07.000000000 +0000
+++ lib/string.cpp
@@ -95,6 +95,59 @@ std::wstring to_wstring(std::string cons
 // Depending which one is used, declare iconv_second_arg_type as either char* or char const*
 extern "C" typedef size_t (*iconv_prototype_with_const)(iconv_t, char const**, size_t *, char**, size_t *);
 typedef std::conditional<std::is_same<decltype(&iconv), iconv_prototype_with_const>::value, char const*, char*>::type iconv_second_arg_type;
+
+namespace {
+// On some platforms, e.g. those derived from SunOS, iconv does not understand "WCHAR_T", so we
+// need to guess an encoding.
+char const* const calc_wchar_t_encoding()
+{
+	auto try_encoding = [](char const* const encoding) -> bool {
+		iconv_t cd = iconv_open(encoding, "UTF-8");
+		if (cd == reinterpret_cast<iconv_t>(-1)) {
+			return false;
+		}
+		iconv_close(cd);
+		return true;
+		
+	};
+	if (try_encoding("WCHAR_T")) {
+		return "WCHAR_T";
+	}
+	else {
+		// Explicitly specify endianess, otherwise we'll get a BOM prefixed to everything
+
+		int const i = 1;
+		char const* p = reinterpret_cast<char const*>(&i);
+		bool little_endian = p[0] == 1;
+
+		if (sizeof(wchar_t) == 4) {
+			if (little_endian && try_encoding("UTF-32LE")) {
+				return "UTF-32LE";
+			}
+			if (!little_endian && try_encoding("UTF-32BE")) {
+				return "UTF-32BE";
+			}
+		}
+		else if (sizeof(wchar_t) == 2) {
+			if (little_endian && try_encoding("UTF-16LE")) {
+				return "UTF-16LE";
+			}
+			if (!little_endian && try_encoding("UTF-16BE")) {
+				return "UTF-16BE";
+			}
+		}
+	}
+
+	// Oh dear...
+	return "WCHAR_T";
+}
+
+char const* wchar_t_encoding()
+{
+	static char const* const encoding = calc_wchar_t_encoding();
+	return encoding;
+}
+}
 #endif
 
 std::wstring to_wstring_from_utf8(std::string const& in)
@@ -111,7 +164,7 @@ std::wstring to_wstring_from_utf8(std::s
 			MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, in_p, len, out_p, len);
 		}
 #else
-		iconv_t cd = iconv_open("WCHAR_T", "UTF-8");
+		iconv_t cd = iconv_open(wchar_t_encoding(), "UTF-8");
 		if (cd != reinterpret_cast<iconv_t>(-1)) {
 			auto in_p = const_cast<iconv_second_arg_type>(in.c_str());
 			size_t in_len = in.size();
@@ -175,7 +228,7 @@ std::string FZ_PUBLIC_SYMBOL to_utf8(std
 			WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, in_p, len, out_p, len, 0, 0);
 		}
 #else
-		iconv_t cd = iconv_open("UTF-8", "WCHAR_T");
+		iconv_t cd = iconv_open("UTF-8", wchar_t_encoding());
 		if (cd != reinterpret_cast<iconv_t>(-1)) {
 			auto in_p = reinterpret_cast<iconv_second_arg_type>(const_cast<wchar_t*>(in.c_str()));
 			size_t in_len = in.size() * sizeof(wchar_t);

File Added: pkgsrc/net/libfilezilla/patches/Attic/patch-tests_string.cpp
$NetBSD: patch-tests_string.cpp,v 1.1 2016/07/21 17:16:17 wiz Exp $

SVN 7667

--- tests/string.cpp.orig	2016-01-31 10:35:01.000000000 +0000
+++ tests/string.cpp
@@ -11,6 +11,7 @@ class string_test : public CppUnit::Test
 	CPPUNIT_TEST_SUITE(string_test);
 	CPPUNIT_TEST(test_conversion);
 	CPPUNIT_TEST(test_conversion2);
+	CPPUNIT_TEST(test_conversion_utf8);
 	CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -19,6 +20,7 @@ public:
 
 	void test_conversion();
 	void test_conversion2();
+	void test_conversion_utf8();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(string_test);
@@ -43,7 +45,7 @@ void string_test::test_conversion()
 
 void string_test::test_conversion2()
 {
-	wchar_t p[] = { 'M', 'o', 't', 0xf6, 'r', 'h', 'e', 'a', 'd', 0 };
+	wchar_t const p[] = { 'M', 'o', 't', 0xf6, 'r', 'h', 'e', 'a', 'd', 0 };
 	std::wstring const w(p);
 
 	std::string const s = fz::to_string(w);
@@ -54,3 +56,22 @@ void string_test::test_conversion2()
 
 	ASSERT_EQUAL(w, w2);
 }
+
+void string_test::test_conversion_utf8()
+{
+	wchar_t const p[] = { 'M', 'o', 't', 0xf6, 'r', 'h', 'e', 'a', 'd', 0 };
+	unsigned char const p_utf8[] = { 'M', 'o', 't', 0xc3, 0xb6, 'r', 'h', 'e', 'a', 'd', 0 };
+
+	std::wstring const w(p);
+	std::string const u(reinterpret_cast<char const*>(p_utf8));
+
+	std::string const s = fz::to_utf8(w);
+
+	CPPUNIT_ASSERT(s.size() >= w.size());
+
+	ASSERT_EQUAL(s, u);
+
+	std::wstring const w2 = fz::to_wstring_from_utf8(s);
+
+	ASSERT_EQUAL(w, w2);
+}