diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 0f887b101..8fcbef6ac 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -47,6 +47,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mediastreamer2/msjpegwriter.h" #include "mediastreamer2/msogl.h" #include "mediastreamer2/msvolume.h" +#include "bctoolbox/charconv.h" #include "chat/chat-room/client-group-chat-room-p.h" #include "chat/chat-room/server-group-chat-room-p.h" @@ -6364,50 +6365,6 @@ void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook #ifdef SQLITE_STORAGE_ENABLED -#ifndef _WIN32 - #if !defined(__QNXNTO__) && !defined(__ANDROID__) - #include - #include - #include - #include - #include - #endif -#else - #include -#endif - -#define MAX_DB_PATH_SIZE 1024 - -static char *utf8_convert(const char *filename){ - char db_file_utf8[MAX_DB_PATH_SIZE] = ""; -#if defined(_WIN32) - wchar_t db_file_utf16[MAX_DB_PATH_SIZE]={0}; - MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, filename, -1, db_file_utf16, MAX_DB_PATH_SIZE); - WideCharToMultiByte(CP_UTF8, 0, db_file_utf16, -1, db_file_utf8, sizeof(db_file_utf8), NULL, NULL); -#elif defined(__QNXNTO__) || defined(__ANDROID__) - strncpy(db_file_utf8, filename, MAX_DB_PATH_SIZE - 1); -#else - char db_file_locale[MAX_DB_PATH_SIZE] = {'\0'}; - char *inbuf=db_file_locale, *outbuf=db_file_utf8; - size_t inbyteleft = MAX_DB_PATH_SIZE, outbyteleft = MAX_DB_PATH_SIZE; - iconv_t cb; - - if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) { - strncpy(db_file_utf8, filename, MAX_DB_PATH_SIZE - 1); - } else { - strncpy(db_file_locale, filename, MAX_DB_PATH_SIZE-1); - cb = iconv_open("UTF-8", nl_langinfo(CODESET)); - if (cb != (iconv_t)-1) { - int ret; - ret = static_cast(iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft)); - if(ret == -1) db_file_utf8[0] = '\0'; - iconv_close(cb); - } - } -#endif - return ms_strdup(db_file_utf8); -} - int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) { char* errmsg = NULL; int ret; @@ -6421,7 +6378,7 @@ int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) { /*since we plug our vfs into sqlite, we convert to UTF-8. * On Windows, the filename has to be converted back to windows native charset.*/ - char *utf8_filename = utf8_convert(db_file); + char *utf8_filename = bctbx_locale_to_utf8(db_file); ret = sqlite3_open_v2(utf8_filename, db, flags, LINPHONE_SQLITE3_VFS); ms_free(utf8_filename); diff --git a/coreapi/sqlite3_bctbx_vfs.c b/coreapi/sqlite3_bctbx_vfs.c index d4f122ee6..629c1b879 100755 --- a/coreapi/sqlite3_bctbx_vfs.c +++ b/coreapi/sqlite3_bctbx_vfs.c @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef SQLITE_STORAGE_ENABLED #include "private.h" +#include "bctoolbox/charconv.h" #include "sqlite3_bctbx_vfs.h" #include @@ -28,17 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #endif /*_WIN32_WCE*/ -#ifndef _WIN32 -#if !defined(__QNXNTO__) && !defined(__ANDROID__) -# include -# include -# include -# include -#endif - -#endif - - /** * Closes the file whose file descriptor is stored in the file handle p. * @param p sqlite3_file file handle pointer. @@ -252,60 +242,6 @@ static int sqlite3bctbx_Sync(sqlite3_file *p, int flags){ /************************ END OF PLACE HOLDER FUNCTIONS ***********************/ - - -static char* ConvertFromUtf8Filename(const char* fName){ -#if _WIN32 - char* convertedFilename; - int nChar, nb_byte; - LPWSTR wideFilename; - - nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, NULL, 0); - if (nChar == 0) return NULL; - wideFilename = reinterpret_cast(bctbx_malloc(nChar*sizeof(wideFilename[0]))); - if (wideFilename == NULL) return NULL; - nChar = MultiByteToWideChar(CP_UTF8, 0, fName, -1, wideFilename, nChar); - if (nChar == 0) { - bctbx_free(wideFilename); - wideFilename = 0; - } - - nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, 0, 0, 0, 0); - if (nb_byte == 0) return NULL; - convertedFilename = reinterpret_cast(bctbx_malloc(nb_byte)); - if (convertedFilename == NULL) return NULL; - nb_byte = WideCharToMultiByte(CP_ACP, 0, wideFilename, -1, convertedFilename, nb_byte, 0, 0); - if (nb_byte == 0) { - bctbx_free(convertedFilename); - convertedFilename = 0; - } - bctbx_free(wideFilename); - return convertedFilename; -#elif defined(__QNXNTO__) || defined(__ANDROID__) - return bctbx_strdup(fName); -#else - #define MAX_PATH_SIZE 1024 - char db_file_utf8[MAX_PATH_SIZE] = {'\0'}; - char db_file_locale[MAX_PATH_SIZE] = ""; - char *outbuf=db_file_locale, *inbuf=db_file_utf8; - size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE; - iconv_t cb; - - if (strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) { - strncpy(db_file_locale, fName, MAX_PATH_SIZE - 1); - } else { - strncpy(db_file_utf8, fName, MAX_PATH_SIZE-1); - cb = iconv_open(nl_langinfo(CODESET), "UTF-8"); - if (cb != (iconv_t)-1) { - int ret = (int)iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft); - if(ret == -1) db_file_locale[0] = '\0'; - iconv_close(cb); - } - } - return bctbx_strdup(db_file_locale); -#endif -} - /** * Opens the file fName and populates the structure pointed by p * with the necessary io_methods @@ -355,7 +291,7 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file #if defined(_WIN32) openFlags |= O_BINARY; #endif - wFname = ConvertFromUtf8Filename(fName); + wFname = bctbx_utf8_to_locale(fName); if (wFname != NULL) { pFile->pbctbx_file = bctbx_file_open2(bctbx_vfs_get_default(), wFname, openFlags); bctbx_free(wFname);