diff --git a/include/libtorrent/ConvertUTF.h b/include/libtorrent/ConvertUTF.h index 5de653063..3e328bd82 100644 --- a/include/libtorrent/ConvertUTF.h +++ b/include/libtorrent/ConvertUTF.h @@ -87,12 +87,21 @@ bit mask & shift operations. ------------------------------------------------------------------------ */ -#include +#ifdef __cplusplus #include "libtorrent/config.hpp" +// these are standard C types, but they might +// not be available in c++ +#include +typedef boost::uint32_t uint32_t; +typedef boost::uint16_t uint16_t; +typedef boost::uint8_t uint8_t; +#else +#define TORRENT_EXPORT +#endif -typedef boost::uint32_t UTF32; /* at least 32 bits */ -typedef boost::uint16_t UTF16; /* at least 16 bits */ -typedef boost::uint8_t UTF8; /* typically 8 bits */ +typedef uint32_t UTF32; /* at least 32 bits */ +typedef uint16_t UTF16; /* at least 16 bits */ +typedef uint8_t UTF8; /* typically 8 bits */ typedef unsigned char Boolean; /* 0 or 1 */ /* Some fundamental constants */ diff --git a/src/GeoIP.c b/src/GeoIP.c index a249a3ebd..773079000 100644 --- a/src/GeoIP.c +++ b/src/GeoIP.c @@ -20,6 +20,8 @@ #include "libtorrent/GeoIP.h" +#include "libtorrent/ConvertUTF.h" + #ifndef WIN32 #include #include @@ -345,7 +347,16 @@ int _check_mtime(GeoIP *gi) { /* refresh filehandle */ fclose(gi->GeoIPDatabase); #ifdef WIN32 - gi->GeoIPDatabase = _wfopen(libtorrent::safe_convert(gi->file_path).c_str(),L"rb"); + assert(sizeof(wchar_t) == 2); + int name_len = strlen(gi->file_path); + wchar_t* wfilename = malloc((name_len + 1) * sizeof(wchar_t)); + wchar_t const* dst_start = wfilename; + char const* src_start = gi->file_path; + ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start + + name_len, (UTF16**)&dst_start, (UTF16*)dst_start + name_len + 1 + , lenientConversion); + gi->GeoIPDatabase = _wfopen(wfilename,L"rb"); + free(wfilename); #else gi->GeoIPDatabase = fopen(gi->file_path,"rb"); #endif @@ -529,11 +540,6 @@ GeoIP* GeoIP_new (int flags) { } */ -namespace libtorrent -{ - std::wstring safe_convert(std::string const& s); -} - GeoIP* GeoIP_open (const char * filename, int flags) { struct stat buf; GeoIP * gi; @@ -550,7 +556,16 @@ GeoIP* GeoIP_open (const char * filename, int flags) { } strncpy(gi->file_path, filename, len); #ifdef WIN32 - gi->GeoIPDatabase = _wfopen(libtorrent::safe_convert(filename).c_str(),L"rb"); + assert(sizeof(wchar_t) == 2); + int name_len = strlen(filename); + wchar_t* wfilename = malloc((name_len + 1) * sizeof(wchar_t)); + wchar_t const* dst_start = wfilename; + char const* src_start = filename; + ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start + + name_len, (UTF16**)&dst_start, (UTF16*)dst_start + name_len + 1 + , lenientConversion); + gi->GeoIPDatabase = _wfopen(wfilename,L"rb"); + free(wfilename); #else gi->GeoIPDatabase = fopen(filename,"rb"); #endif diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 3ca3b7067..665cb129e 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -76,6 +76,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/kademlia/dht_tracker.hpp" #include "libtorrent/enum_net.hpp" #include "libtorrent/config.hpp" +#include "libtorrent/utf8.hpp" #ifndef TORRENT_WINDOWS #include @@ -347,7 +348,7 @@ namespace aux { if (m_asnum_db) GeoIP_delete(m_asnum_db); std::string utf8; wchar_utf8(file, utf8); - m_asnum_db = GeoIP_open(utf8, GEOIP_STANDARD); + m_asnum_db = GeoIP_open(utf8.c_str(), GEOIP_STANDARD); return m_asnum_db; } @@ -365,7 +366,7 @@ namespace aux { if (m_country_db) GeoIP_delete(m_country_db); std::string utf8; wchar_utf8(file, utf8); - m_country_db = GeoIP_open(utf8, GEOIP_STANDARD); + m_country_db = GeoIP_open(utf8.c_str(), GEOIP_STANDARD); return m_country_db; }