[libgda] sqlcipher: embedded SQLCipher 3.4.2



commit afe5c6b2b89955469f5f4c8d502b08daf4c3d583
Author: Daniel Espinosa <esodan gmail com>
Date:   Fri Oct 26 09:58:53 2018 -0500

    sqlcipher: embedded SQLCipher 3.4.2

 .gitlab-ci.yml                                     |      1 +
 libgda/sqlite/meson.build                          |     35 +-
 meson.build                                        |     12 +
 meson_options.txt                                  |      1 +
 providers/meson.build                              |      4 +
 providers/sqlcipher/NOTE_for_new_SQLCipher_version |     17 -
 providers/sqlcipher/meson.build                    |    112 +
 providers/sqlcipher/sqlcipher.patch                | 127696 ------------------
 tests/providers/check_sqlcipher.c                  |     69 +
 tests/providers/meson.build                        |     26 +
 10 files changed, 258 insertions(+), 127715 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ab3af4391..b0cea0cab 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,6 +21,7 @@ variables:
                 libxslt1-dev
                 libjson-glib-dev
                 libgcrypt20-dev
+                libssl-dev
                 libldap2-dev
                 libgoocanvas-2.0-dev
                 libhsqldb1.8.0-java
diff --git a/libgda/sqlite/meson.build b/libgda/sqlite/meson.build
index 67467664e..0bbb550c1 100644
--- a/libgda/sqlite/meson.build
+++ b/libgda/sqlite/meson.build
@@ -20,7 +20,7 @@ sqlitehanderbinc = files([
 sqlitehanderbinh = files([
        'gda-sqlite-handler-bin.h'
        ])
-sqlitesources = files([
+sqlitesources_provider = files([
        'gda-sqlite-blob-op.c',
        'gda-sqlite-blob-op.h',
        'gda-sqlite-ddl.c',
@@ -41,6 +41,8 @@ sqlitesources = files([
        'gda-symbols-util.h',
        'gda-symbols-util.c'
        ])
+sqlitesources = []
+sqlitesources += sqlitesources_provider
 sqlitesources += sqliteheaders
 sqlitesources += xml_embeddedh
 sqlitesources += sqlitehanderbinc
@@ -68,4 +70,33 @@ else
        sqlite_deps += sqlite_dep
 endif
 
-sqlite_cargs += ['-DSEARCH_LIB_PATH="'+sqlite_path+'"']
\ No newline at end of file
+sqlite_cargs += ['-DSEARCH_LIB_PATH="'+sqlite_path+'"']
+
+if libcrypto_dep.found ()
+sqlcipher_deps = []
+
+sqlcipher_sources = []
+sqlcipher_sources += sqlitesources_provider
+sqlcipher_sources += sqliteheaders
+sqlcipher_sources += sqlitehanderbinc
+sqlcipher_sources += sqlitehanderbinh
+
+sqlcipher_cargs = [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DPNAME="SQLCipher"', '-DCLASS_PREFIX="GdaSQLCipher"',
+               '-DSTATIC_SQLITE', '-DSQLITE_HAS_CODEC'
+       ]
+
+sqlcipher_path = ''
+if sqlcipher_internal
+else
+       sqlcipher_path = sqlcipher_dep.get_pkgconfig_variable('libdir')
+       sqlcipher_cargs += ['-DHAVE_SQLITE']
+       sqlcipher_deps += sqlcipher_dep
+endif
+
+
+sqlcipher_cargs += ['-DSEARCH_LIB_PATH="'+sqlcipher_path+'"']
+
+endif
\ No newline at end of file
diff --git a/meson.build b/meson.build
index 25215603e..db86d3dbd 100644
--- a/meson.build
+++ b/meson.build
@@ -98,6 +98,16 @@ if sqlite_dep.found()
        endif
 endif
 
+
+sqlcipher_dep = dependency ('sqlcipher', version: '>= 3.4.1', required: false)
+sqlcipher_internal = true
+if sqlcipher_dep.found() and get_option('system-sqlcipher')
+       sqlcipher_table_column_metadata = compiler.find_library('sqlcipher_table_column_metadata', required: 
false)
+       if sqlcipher_table_column_metadata.found()
+               sqlcipher_internal = false
+       endif
+endif
+
 if sqlite_internal
        ldl = compiler.find_library('dl')
 endif
@@ -218,6 +228,8 @@ if libcryp_config.found()
   conf.set('HAVE_LIBCRYPT_CONFIG', 1)
 endif
 
+libcrypto_dep = dependency('libcrypto', version : '>=1.1', required: false)
+
 soup_dep = dependency('libsoup-2.4', required: false)
 if soup_dep.found() and get_option('with-libsoup')
   libgda_dep += [soup_dep]
diff --git a/meson_options.txt b/meson_options.txt
index ec6ff9777..3b1d8e650 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,4 +12,5 @@ option('with-gnome-keyring', type : 'boolean', value : false, description : 'Ena
 option('enable-debug', type : 'boolean', value : false, description : 'Enable debug mode')
 option('system-sqlite', type : 'boolean', value : false, description : 'Use SQLite installed on the system 
[default=false')
 option('with-examples', type : 'boolean', value : false, description : 'Compile examples [default=false')
+option('system-sqlcipher', type : 'boolean', value : false, description : 'Use SQLCipher installed on the 
system [default=false')
 
diff --git a/providers/meson.build b/providers/meson.build
index 2ee29e811..c42b2c372 100644
--- a/providers/meson.build
+++ b/providers/meson.build
@@ -4,6 +4,10 @@ subdir('reuseable')
 subdir('sqlite')
 subdir('skel-implementation')
 
+if libcrypto_dep.found ()
+subdir('sqlcipher')
+endif
+
 if postgres_dep.found()
 subdir('postgres')
 endif
diff --git a/providers/sqlcipher/meson.build b/providers/sqlcipher/meson.build
new file mode 100644
index 000000000..323ce89ed
--- /dev/null
+++ b/providers/sqlcipher/meson.build
@@ -0,0 +1,112 @@
+inc_libgda_sqlcipherh = include_directories ('.')
+inc_libgda_sqlcipherh_dep = declare_dependency (include_directories : inc_libgda_sqlcipherh)
+
+sqlcipher_xml_fnames = [
+       'sqlcipher_specs_add_column',
+       'sqlcipher_specs_auth',
+       'sqlcipher_specs_create_db',
+       'sqlcipher_specs_create_index',
+       'sqlcipher_specs_create_table',
+       'sqlcipher_specs_create_view',
+       'sqlcipher_specs_drop_db',
+       'sqlcipher_specs_drop_index',
+       'sqlcipher_specs_drop_table',
+       'sqlcipher_specs_drop_view',
+       'sqlcipher_specs_dsn',
+       'sqlcipher_specs_rename_table'
+       ]
+
+xml_res = []
+foreach xt : sqlcipher_xml_fnames
+       i18n.merge_file(
+               input: xt+'.xml.in',
+               output: xt+'.xml',
+               type: 'xml',
+               po_dir: 'po',
+               install_dir: join_paths(get_option('datadir'),project_package)
+               )
+       xml_res += custom_target(xt+'.raw.xml',
+               command: [raw_spec,
+                       '-o', meson.current_build_dir(),
+                       '@INPUT@'
+                       ],
+               input: xt+'.xml.in',
+               output: xt+'.raw.xml',
+               )
+endforeach
+
+sqlcipher_resourcesc = custom_target('sqlcipher_resourcesc',
+       command: [compile_resources,
+               '--sourcedir='+meson.current_build_dir(),
+               '--sourcedir='+join_paths(meson.source_root(),'providers','sqlcipher'),
+               '--generate-source',
+               '--target', '@OUTPUT@',
+               '--internal',
+               '@INPUT@'
+               ],
+       input: 'sqlcipher.gresource.xml',
+       output: 'sqlcipher_resource.c',
+       depends: xml_res,
+       install: false
+       )
+
+sqlcipher_resourcesh = custom_target('sqlcipher_resourcesh',
+       command: [compile_resources,
+               '--sourcedir='+meson.current_build_dir(),
+               '--sourcedir='+join_paths(meson.source_root(),'providers','sqlcipher'),
+               '--generate-header',
+               '--target', '@OUTPUT@',
+               '--internal',
+               '@INPUT@'
+               ],
+       input: 'sqlcipher.gresource.xml',
+       output: 'sqlcipher_resource.h',
+       depends: xml_res,
+       install: false
+       )
+sqlcipher_resources = []
+sqlcipher_resources += sqlcipher_resourcesc
+sqlcipher_resources += sqlcipher_resourcesh
+
+libgda_sqlcipher_sources = files([
+       'libmain.c'
+       ])
+libgda_sqlcipher_sources += sqlcipher_resources
+libgda_sqlcipher_sources += sqlcipher_sources
+
+if sqlcipher_internal
+libgda_sqlcipher_sources += files([
+       'sqlite3.h',
+       'sqlite3.c',
+       ])
+sqlcipher_deps += ldl
+endif
+
+sqlcipher_cargs += [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DSQLITE_HAS_CODEC',
+               '-DSQLITE_API=',
+               '-DSQLITE_PRIVATE=',
+               '-DSQLITE_ENABLE_COLUMN_METADATA',
+               '-DSQLITE_THREADSAFE=1'
+               ]
+
+libgda_sqlcipher_providerpc = configure_file(output : 'libgda-sqlcipher-'+project_api_version+'.pc',
+                       configuration : conf,
+                       install_dir: join_paths(get_option('libdir'),'pkgconfig')
+                       )
+libgda_sqlcipher_provider = library ('gda-sqlcipher-'+project_api_version,
+       libgda_sqlcipher_sources,
+       dependencies: [
+               libgda_dep,
+               sqlcipher_deps,
+               libcrypto_dep,
+               inc_libgda_sqlcipherh_dep,
+               inc_sqliteh_dep,
+               ],
+       c_args: sqlcipher_cargs,
+       link_with: libgda,
+       install: true,
+       install_dir: join_paths(get_option('libdir'), project_package, 'providers')
+       )
diff --git a/tests/providers/check_sqlcipher.c b/tests/providers/check_sqlcipher.c
new file mode 100644
index 000000000..3dbeb4617
--- /dev/null
+++ b/tests/providers/check_sqlcipher.c
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2007 - 2013 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * 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.
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#define PROVIDER "SQLCipher"
+#include "prov-test-common.h"
+
+extern GdaProviderInfo *pinfo;
+extern GdaConnection   *cnc;
+extern gboolean         params_provided;
+extern gboolean         fork_tests;
+
+int
+main (int argc, char **argv)
+{
+       int number_failed = 0;
+       fork_tests = FALSE;
+
+       gda_init ();
+
+       pinfo = gda_config_get_provider_info (PROVIDER);
+       if (!pinfo) {
+               g_warning ("Could not find provider information for %s", PROVIDER);
+               return EXIT_FAILURE;
+       }
+       g_print ("Provider now tested: %s\n", pinfo->id);
+
+       number_failed = prov_test_common_setup ();
+
+       if (cnc) {
+               number_failed += prov_test_common_check_timestamp ();
+               number_failed += prov_test_common_check_date ();
+               number_failed += prov_test_common_check_bigint ();
+               number_failed += prov_test_common_check_meta ();
+               number_failed += prov_test_common_check_meta_identifiers (TRUE, TRUE);
+               number_failed += prov_test_common_check_meta_identifiers (TRUE, FALSE);
+               number_failed += prov_test_common_check_meta_identifiers (FALSE, TRUE);
+               number_failed += prov_test_common_check_meta_identifiers (FALSE, FALSE);
+               number_failed += prov_test_common_load_data ();
+               number_failed += prov_test_common_check_cursor_models ();
+               number_failed += prov_test_common_check_data_select ();
+               number_failed += prov_test_common_clean ();
+       }
+
+       if (! params_provided)
+               return EXIT_SUCCESS;
+       else {
+               g_print ("Test %s\n", (number_failed == 0) ? "Ok" : "failed");
+               return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+       }
+}
+
diff --git a/tests/providers/meson.build b/tests/providers/meson.build
index ec2858893..65fb72eaa 100644
--- a/tests/providers/meson.build
+++ b/tests/providers/meson.build
@@ -28,6 +28,32 @@ test('ProviderSQLite', tchksqlite,
                ]
        )
 
+if libcrypto_dep.found ()
+
+tchksqlcipher = executable('check_sqlcipher',
+       ['check_sqlcipher.c']+providers_common_sources+common_sources+tests_sources,
+       c_args: [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DCHECK_SQL_FILES="'+meson.source_root()+'"',
+               ],
+       link_with: libgda,
+       dependencies: [
+               libgda_dep,
+               inc_rooth_dep,
+               inc_sqliteh_dep,
+               inc_testsh_dep
+               ],
+       install: false
+       )
+test('ProviderSQLCipher', tchksqlcipher,
+       env: [
+               'GDA_TOP_SRC_DIR='+meson.source_root(),
+               'GDA_TOP_BUILD_DIR='+meson.build_root()
+               ]
+       )
+endif
+
 if postgres_dep.found ()
 
 tchkpg = executable('check_postgres',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]