Commit 53371ac2 authored by johan's avatar johan

Revert "sqlite vfs moved from liblinphone to bctoolbox"

This reverts commit cea177ef.
sqlite3 vfs back to liblinphone to solve static linkage problem
parent 94e724ef
......@@ -38,7 +38,6 @@ option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_POLARSSL "Enable polarssl support" ON)
option(ENABLE_MBEDTLS "Enable mabedtls support" ON)
option(ENABLE_DECAF "Enable Elliptic Curve Cryptography support" ON)
option(ENABLE_SQLITE_VFS "Enable Sqlite3 Virtual File System support" ON)
option(ENABLE_STRICT "Pass strict flags to the compiler" ON)
option(ENABLE_TESTS_COMPONENT "Enable compilation of tests helper library" ON)
option(ENABLE_TESTS "Enable compilation of tests" ON)
......@@ -92,11 +91,6 @@ if(ENABLE_POLARSSL AND NOT MBEDTLS_FOUND)
endif()
endif()
if(ENABLE_SQLITE_VFS)
find_package(Sqlite3 REQUIRED)
endif()
if(HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
message(STATUS "DTLS SRTP available")
set(HAVE_DTLS_SRTP 1)
......
############################################################################
# FindSqlite3.cmake
# Copyright (C) 2014 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
#
# - Find the sqlite3 include file and library
#
# SQLITE3_FOUND - system has sqlite3
# SQLITE3_INCLUDE_DIRS - the sqlite3 include directory
# SQLITE3_LIBRARIES - The libraries needed to use sqlite3
if(APPLE AND NOT IOS)
set(SQLITE3_HINTS "/usr")
endif()
if(SQLITE3_HINTS)
set(SQLITE3_LIBRARIES_HINTS "${SQLITE3_HINTS}/lib")
endif()
find_path(SQLITE3_INCLUDE_DIRS
NAMES sqlite3.h
HINTS "${SQLITE3_HINTS}"
PATH_SUFFIXES include
)
if(SQLITE3_INCLUDE_DIRS)
set(HAVE_SQLITE3_H 1)
endif()
find_library(SQLITE3_LIBRARIES
NAMES sqlite3
HINTS "${SQLITE3_LIBRARIES_HINTS}"
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Sqlite3
DEFAULT_MSG
SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES HAVE_SQLITE3_H
)
mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES HAVE_SQLITE3_H)
......@@ -46,11 +46,6 @@ if(MBEDTLS_FOUND OR POLARSSL_FOUND)
list(APPEND HEADER_FILES crypto.hh)
endif()
if (ENABLE_SQLITE_VFS)
list(APPEND HEADER_FILES sqlite3_vfs.h)
endif()
if(ENABLE_TESTS_COMPONENT)
list(APPEND HEADER_FILES tester.h)
endif()
......
/*
* Copyright (c) 2010-2019 Belledonne Communications SARL.
*
* This file is part of Liblinphone.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BCTBX_SQLITE3_VFS_H
#define BCTBX_SQLITE3_VFS_H
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <bctoolbox/vfs.h>
#include "sqlite3.h"
#define BCTBX_SQLITE3_VFS "sqlite3bctbx_vfs"
/*
** The maximum pathname length supported by this VFS.
*/
#define MAXPATHNAME 512
#ifdef __cplusplus
extern "C"{
#endif
/**
* sqlite3_bctbx_file_t VFS file structure.
*/
typedef struct sqlite3_bctbx_file_t sqlite3_bctbx_file_t;
struct sqlite3_bctbx_file_t {
sqlite3_file base; /* Base class. Must be first. */
bctbx_vfs_file_t* pbctbx_file;
char *filename;
};
/**
* Very simple VFS structure based on sqlite3_vfs.
* Only the Open function is implemented,
*/
typedef struct sqlite3_bctbx_vfs_t sqlite3_bctbx_vfs_t;
struct sqlite3_bctbx_vfs_t {
sqlite3_bctbx_vfs_t *pNext; /* Next registered VFS */
const char *vfsName; /* Virtual file system name */
int (*xOpen)(sqlite3_vfs* pVfs, const char *fName, sqlite3_file *pFile,int flags, int *pOutFlags);
};
/****************************************************
VFS API to register this VFS to sqlite3 VFS
*****************************************************/
/**
* Registers sqlite3bctbx_vfs to SQLite VFS. If makeDefault is 1,
* the VFS will be used by default.
* Methods not implemented by sqlite3_bctbx_vfs_t are initialized to the one
* used by the unix-none VFS where all locking file operations are no-ops.
* @param makeDefault set to 1 to make the newly registered VFS be the default one, set to 0 instead.
*/
BCTBX_PUBLIC void sqlite3_bctbx_vfs_register(int makeDefault);
/**
* Unregisters sqlite3bctbx_vfs from SQLite.
*/
BCTBX_PUBLIC void sqlite3_bctbx_vfs_unregister(void);
/*
* Helper function to open a db file
*
* @param[in] db_file path to the db file to open/create
* @param[out] db pointer to the sqlite3 db opened
* @param[in] vfs_name if not null sqlite uses this virtual file system instead of the default one
*
**/
BCTBX_PUBLIC int bctbx_sqlite3_open(const char *db_file, sqlite3 **db, const char *vfs_name);
#ifdef __cplusplus
}
#endif
#endif /* BCTBX_SQLITE3_VFS_H */
......@@ -55,10 +55,6 @@ if(APPLE)
)
endif()
if (ENABLE_SQLITE_VFS)
list(APPEND BCTOOLBOX_CXX_SOURCE_FILES vfs/sqlite3_vfs.cc)
endif()
if(ANDROID)
list(APPEND BCTOOLBOX_CXX_SOURCE_FILES conversion/charconv_android.cc)
elseif(WIN32)
......@@ -251,17 +247,6 @@ if(DECAF_FOUND)
target_link_libraries(bctoolbox PRIVATE ${DECAF_TARGETNAME})
endif()
endif()
if(SQLITE3_FOUND)
if(ENABLE_STATIC)
target_include_directories(bctoolbox-static PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_link_libraries(bctoolbox-static PUBLIC ${SQLITE3_LIBRARIES})
endif()
if(ENABLE_SHARED)
target_include_directories(bctoolbox PRIVATE ${SQLITE3_INCLUDE_DIRS})
target_link_libraries(bctoolbox PRIVATE ${SQLITE3_LIBRARIES})
endif()
endif()
if(ENABLE_TESTS_COMPONENT)
if(ENABLE_STATIC)
......
This diff is collapsed.
......@@ -41,10 +41,6 @@ if(ENABLE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
if(APPLE)
list(APPEND TESTER_SOURCES ios_utils.cc)
endif()
if(SQLITE3_FOUND)
list(APPEND TESTER_SOURCES sqlite3_vfs.c)
endif()
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
......@@ -64,9 +60,6 @@ if(ENABLE_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
if(DECAF_FOUND)
target_link_libraries(bctoolbox_tester_exe PRIVATE ${DECAF_TARGETNAME})
endif()
if(SQLITE3_FOUND)
target_link_libraries(bctoolbox_tester_exe PRIVATE ${SQLITE3_LIBRARIES})
endif()
set_target_properties(bctoolbox_tester_exe PROPERTIES XCODE_ATTRIBUTE_WARNING_CFLAGS "")
add_test(NAME bctoolbox_tester COMMAND bctoolbox_tester --verbose)
endif()
......@@ -50,9 +50,8 @@ void bctoolbox_tester_init(void(*ftester_printf)(int level, const char *fmt, va_
#endif
bc_tester_add_suite(&parser_test_suite);
#ifdef __APPLE__
bc_tester_add_suite(&ios_utils_test_suite);
bc_tester_add_suite(&ios_utils_test_suite);
#endif
bc_tester_add_suite(&sqlite3_vfs_test_suite);
bc_tester_add_suite(&encrypted_vfs_test_suite);
}
......
......@@ -38,7 +38,6 @@ extern test_suite_t utils_test_suite;
extern test_suite_t crypto_test_suite;
extern test_suite_t parser_test_suite;
extern test_suite_t ios_utils_test_suite;
extern test_suite_t sqlite3_vfs_test_suite;
extern test_suite_t encrypted_vfs_test_suite;
#ifdef __cplusplus
......
/*
* Copyright (c) 2020 Belledonne Communications SARL.
*
* This file is part of bctoolbox.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include "bctoolbox_tester.h"
#include "bctoolbox/sqlite3_vfs.h"
#include "sqlite3.h"
void basic_test() {
/* register sqlite3_vfs as default */
sqlite3_bctbx_vfs_register(1);
/* create a database */
sqlite3 *db=NULL;
char *dbFile = bc_tester_file("sqlite3_vfs_basic.sqlite");;
remove(dbFile);
bctbx_sqlite3_open(dbFile, &db, NULL);
/* insert a table */
char* errmsg=NULL;
int ret=sqlite3_exec(db,"CREATE TABLE IF NOT EXISTS table1 ("
"id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
"a_blob BLOB NOT NULL DEFAULT '000000000000',"
"some_text TEXT NOT NULL DEFAULT 'unset',"
"an_int INTEGER DEFAULT 0"
");",
0,0,&errmsg);
if(ret != SQLITE_OK) {
sqlite3_free(errmsg);
sqlite3_bctbx_vfs_unregister();
BC_FAIL("Unable to create table1");
return;
}
/* close databse */
sqlite3_close(db);
/* unregister the bxtbx_vfs or it will stay as default one */
sqlite3_bctbx_vfs_unregister();
/* cleaning */
remove(dbFile);
}
static test_t sqlite3_vfs_tests[] = {
TEST_NO_TAG("basic access", basic_test)
};
test_suite_t sqlite3_vfs_test_suite = {"Sqlite3_vfs", NULL, NULL, NULL, NULL,
sizeof(sqlite3_vfs_tests) / sizeof(sqlite3_vfs_tests[0]), sqlite3_vfs_tests};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment