From 6cfac0ff44cc80983838542107208da278c1109c Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Tue, 17 May 2016 11:11:49 +0200 Subject: [PATCH] Using newly created functions bctbx_file_close_and_free, bctbx_file_create_and_open. in lpconfig.c. Changing check on file descriptor return value : should be different from -1 if open was successful . Using bctbx_file_open and bctbx_file_close in sqlite3bctbx_Open and sqlite3bctbx_Close. Registers the VFS as default incall_log.c, friend.c and mesage_storage.c . --- coreapi/call_log.c | 6 +++--- coreapi/friend.c | 2 +- coreapi/lpconfig.c | 30 +++++++++++++++--------------- coreapi/message_storage.c | 19 +------------------ coreapi/sqlite3_bctbx_vfs.c | 15 +++++++-------- 5 files changed, 27 insertions(+), 45 deletions(-) diff --git a/coreapi/call_log.c b/coreapi/call_log.c index 7626e0780..14f98f701 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -373,9 +373,9 @@ void linphone_core_call_log_storage_init(LinphoneCore *lc) { int ret; const char *errmsg; sqlite3 *db; - sqlite3_vfs_register(sqlite3_bctbx_vfs_create(), 1); - sqlite3_vfs* t = sqlite3_vfs_find("sql3_bctbx_vfs"); - sqlite3_vfs_register(t, 1); + + sqlite3_bctbx_vfs_register(1); + linphone_core_call_log_storage_close(lc); ret=_linphone_sqlite3_open(lc->logs_db_file, &db); diff --git a/coreapi/friend.c b/coreapi/friend.c index 2fa01e36d..32b309246 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -1135,7 +1135,7 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) { const char *errmsg; sqlite3 *db; const MSList *friends_lists = NULL; - + sqlite3_bctbx_vfs_register(1); linphone_core_friends_storage_close(lc); ret = _linphone_sqlite3_open(lc->friends_db_file, &db); diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index aa5e4b2af..e9e4f4327 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -428,7 +428,7 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa #endif /*_WIN32*/ /*open with r+ to check if we can write on it later*/ int fd; - pFile = bctbx_file_open(lpconfig->g_bctbx_vfs,lpconfig->filename, "r+"); + pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs,lpconfig->filename, "r+"); fd = pFile->fd; lpconfig->pFile = pFile; @@ -440,9 +440,9 @@ LpConfig *lp_config_new_with_factory(const char *config_filename, const char *fa } } #endif - if (fd > 0){ + if (fd != -1){ lp_config_parse(lpconfig, pFile); - bctbx_file_close(pFile); + bctbx_file_close_and_free(pFile); lpconfig->pFile = NULL; lpconfig->modified=0; } @@ -460,12 +460,12 @@ fail: int lp_config_read_file(LpConfig *lpconfig, const char *filename){ char* path = lp_realpath(filename, NULL); int fd=-1; - bctbx_vfs_file* pFile = bctbx_file_open(lpconfig->g_bctbx_vfs, path, "r"); + bctbx_vfs_file* pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs, path, "r"); fd = pFile->fd; - if (fd > 0){ + if (fd != -1){ ms_message("Reading config information from %s", path); lp_config_parse(lpconfig, pFile); - bctbx_file_close(pFile); + bctbx_file_close_and_free(pFile); ms_free(path); return 0; } @@ -756,7 +756,7 @@ int lp_config_sync(LpConfig *lpconfig){ /* don't create group/world-accessible files */ (void) umask(S_IRWXG | S_IRWXO); #endif - bctbx_vfs_file *pFile = bctbx_file_open(lpconfig->g_bctbx_vfs,lpconfig->tmpfilename, "w"); + bctbx_vfs_file *pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs,lpconfig->tmpfilename, "w"); lpconfig->pFile = pFile; fd = pFile->fd; if (fd < 0 ){ @@ -766,7 +766,7 @@ int lp_config_sync(LpConfig *lpconfig){ } ms_list_for_each2(lpconfig->sections,(void (*)(void *,void*))lp_section_write,(void *)lpconfig); - bctbx_file_close(pFile); + bctbx_file_close_and_free(pFile); #ifdef RENAME_REQUIRES_NONEXISTENT_NEW_PATH /* On windows, rename() does not accept that the newpath is an existing file, while it is accepted on Unix. @@ -897,10 +897,10 @@ bool_t lp_config_relative_file_exists(const LpConfig *lpconfig, const char *file if(realfilepath == NULL) return FALSE; - pFile = bctbx_file_open(lpconfig->g_bctbx_vfs,realfilepath, "r"); + pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs,realfilepath, "r"); ms_free(realfilepath); - if (pFile->fd > 0) { - bctbx_file_close(pFile); + if (pFile->fd != -1) { + bctbx_file_close_and_free(pFile); } return pFile->fd > 0; } @@ -930,7 +930,7 @@ void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filenam goto end; } - pFile = bctbx_file_open(lpconfig->g_bctbx_vfs,realfilepath, "w"); + pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs,realfilepath, "w"); fd = pFile->fd; if(fd < 0) { @@ -938,7 +938,7 @@ void lp_config_write_relative_file(const LpConfig *lpconfig, const char *filenam goto end; } bctbx_file_fprintf(pFile, 0, "%s",data); - bctbx_file_close(pFile); + bctbx_file_close_and_free(pFile); end: ms_free(dup_config_file); @@ -966,7 +966,7 @@ int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, goto err; } - pFile = bctbx_file_open(lpconfig->g_bctbx_vfs,realfilepath,"r"); + pFile = bctbx_file_create_and_open(lpconfig->g_bctbx_vfs,realfilepath,"r"); if (pFile !=NULL) fd = pFile->fd; @@ -982,7 +982,7 @@ int lp_config_read_relative_file(const LpConfig *lpconfig, const char *filename, } - bctbx_file_close(pFile); + bctbx_file_close_and_free(pFile); ms_free(dup_config_file); ms_free(filepath); diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index 52e75d6c7..5e6bb2017 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -662,24 +662,7 @@ void linphone_core_message_storage_init(LinphoneCore *lc){ int ret; const char *errmsg; sqlite3 *db = NULL; - sqlite3_vfs_register(sqlite3_bctbx_vfs_create(), 1); - sqlite3_vfs* t = sqlite3_vfs_find("sql3_bctbx_vfs"); - sqlite3_vfs* pDefault = sqlite3_vfs_find("unix-none"); - t->xAccess = pDefault->xAccess; - t->xCurrentTime = pDefault->xCurrentTime; - t->xCurrentTimeInt64 = pDefault->xCurrentTimeInt64; - t->xFullPathname = pDefault->xFullPathname; - t->xDelete = pDefault->xDelete; - t->xSleep = pDefault->xSleep; - t->xRandomness = pDefault->xRandomness; - t->xGetLastError = pDefault->xGetLastError; - t->xGetSystemCall = pDefault->xGetSystemCall; - t->xSetSystemCall = pDefault->xSetSystemCall; - t->xNextSystemCall = pDefault->xNextSystemCall; - //t->xOpen = pDefault->xOpen; - //t->pAppData = pDefault->pAppData; - sqlite3_vfs_unregister(t); - sqlite3_vfs_register(t, 1); + sqlite3_bctbx_vfs_register(1); linphone_core_message_storage_close(lc); ret=_linphone_sqlite3_open(lc->chat_db_file,&db); diff --git a/coreapi/sqlite3_bctbx_vfs.c b/coreapi/sqlite3_bctbx_vfs.c index 0b82e55be..2ba15d433 100644 --- a/coreapi/sqlite3_bctbx_vfs.c +++ b/coreapi/sqlite3_bctbx_vfs.c @@ -33,12 +33,11 @@ static int sqlite3bctbx_Close(sqlite3_file *p){ int ret; sqlite3_bctbx_file *pFile = (sqlite3_bctbx_file*) p; - ret = close(pFile->bctbx_file.fd); + ret = bctbx_file_close(&pFile->bctbx_file); if (!ret){ return SQLITE_OK; } else{ - printf("sqlite3bctbx_Close error %s", strerror(errno)); free(pFile); return SQLITE_IOERR_CLOSE ; } @@ -256,7 +255,7 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file }; sqlite3_bctbx_file * pFile = (sqlite3_bctbx_file*)p; /*File handle sqlite3_bctbx_file*/ - sqlite_int64 size; /* File size */ +// sqlite_int64 size; /* File size */ int openFlags = 0; @@ -271,8 +270,8 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file if( flags&SQLITE_OPEN_READONLY ) openFlags |= O_RDONLY; if( flags&SQLITE_OPEN_READWRITE ) openFlags |= O_RDWR; - pFile->bctbx_file.fd = open(fName, openFlags, S_IRUSR | S_IWUSR); - if( pFile->bctbx_file.fd == -1 ){ + int ret = bctbx_file_open(bc_create_vfs(), &pFile->bctbx_file, fName, openFlags); + if( ret == -1 ){ return SQLITE_CANTOPEN; } @@ -280,11 +279,11 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file *pOutFlags = flags; } pFile->base.pMethods = &sqlite3_bctbx_io; - pFile->bctbx_file.pMethods = get_bcio(); +// pFile->bctbx_file.pMethods = get_bcio(); pFile->bctbx_file.filename = (char*)fName; - pFile->base.pMethods->xFileSize(p, &size); - pFile->bctbx_file.size = size; +// pFile->base.pMethods->xFileSize(p, &size); +// pFile->bctbx_file.size = size; return SQLITE_OK; }