mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-05-07 05:53:06 +00:00
Replaced old conversion functions with those in bctoolbox
This commit is contained in:
parent
b9be1a84f3
commit
e3736438a1
2 changed files with 4 additions and 111 deletions
|
|
@ -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 <ctype.h>
|
||||
#include <langinfo.h>
|
||||
#include <locale.h>
|
||||
#include <iconv.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
#else
|
||||
#include <Windows.h>
|
||||
#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<int>(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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <sqlite3.h>
|
||||
|
||||
|
|
@ -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 <langinfo.h>
|
||||
# include <locale.h>
|
||||
# include <iconv.h>
|
||||
# include <string.h>
|
||||
#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<LPWSTR>(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<char *>(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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue