mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
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 .
This commit is contained in:
parent
ae7e1b7b0f
commit
6cfac0ff44
5 changed files with 27 additions and 45 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue