WIP: switch from libdbi to lbisqlite3

The choice of libdbi was one of the biggest early mistakes in (back
then) OpenBSC development.  A database abstraction library that
prevents you from using proper prepared statements.  Let's finally
abandon it and use sqlite3 directly, just like we do in osmo-hlr.

Change-Id: Ia334904289f92d014e7bd16b02b3b5817c12c790
This commit is contained in:
Harald Welte 2022-05-14 15:35:49 +02:00
parent 24f14a5191
commit ef097fc030
10 changed files with 637 additions and 355 deletions

View File

@ -110,10 +110,6 @@ fi
AM_CONDITIONAL(BUILD_IU, test "x$osmo_ac_iu" = "xyes")
AC_SUBST(osmo_ac_iu)
dnl checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(dbi/dbd.h,,AC_MSG_ERROR(DBI library is not installed))
# Coverage build taken from WebKit's configure.in
AC_MSG_CHECKING([whether to enable code coverage support])
AC_ARG_ENABLE(coverage,

View File

@ -27,13 +27,11 @@ URL: https://osmocom.org/projects/osmomsc
Source: %{name}-%{version}.tar.xz
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libdbi-drivers-dbd-sqlite3
BuildRequires: libtool
%if 0%{?suse_version}
BuildRequires: systemd-rpm-macros
%endif
BuildRequires: pkgconfig >= 0.20
BuildRequires: pkgconfig(dbi)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(libcrypto) >= 0.9.5
BuildRequires: pkgconfig(libosmo-gsup-client) >= 1.4.0
@ -55,11 +53,6 @@ BuildRequires: lksctp-tools-devel
BuildRequires: pkgconfig(libasn1c) >= 0.9.30
BuildRequires: pkgconfig(libosmo-ranap) >= 0.8.0
%endif
%if 0%{?suse_version}
Requires: libdbi-drivers-dbd-sqlite3
%else
Requires: libdbi-dbd-sqlite
%endif
%description
The Mobile Switching Center (MSC) is the heart of 2G/3G

4
debian/control vendored
View File

@ -9,8 +9,6 @@ Build-Depends: debhelper (>=9),
automake,
libtool,
pkg-config,
libdbi-dev,
libdbd-sqlite3,
libsqlite3-dev,
libsctp-dev,
libtalloc-dev,
@ -33,7 +31,7 @@ Homepage: https://osmocom.org/projects/osmomsc
Package: osmo-msc
Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}, libdbd-sqlite3
Depends: ${misc:Depends}, ${shlibs:Depends}
Recommends: osmo-mgw
Description: OsmoMSC: Osmocom's Mobile Switching Center for 2G and 3G circuit-switched mobile networks
The Mobile Switching Center (MSC) is the heart of 2G/3G

View File

@ -1,5 +1,6 @@
/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2022 by Harald Welte <laforge@osmocom.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
@ -30,7 +31,7 @@ struct gsm_network;
struct gsm_sms;
/* one time initialisation */
int db_init(const char *name);
int db_init(void *ctx, const char *fname, bool enable_sqlite_logging);
int db_prepare(void);
int db_fini(void);

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,5 @@ osmo_msc_LDADD = \
$(LIBOSMOMGCPCLIENT_LIBS) \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
-ldbi \
-lsctp \
$(NULL)

View File

@ -685,7 +685,7 @@ TODO: we probably want some of the _net_ ctrl commands from bsc_base_ctrl_cmds_i
if (msc_cmdline_config.database_name)
osmo_talloc_replace_string(msc_network, &msc_network->sms_db_file_path, msc_cmdline_config.database_name);
if (db_init(msc_network->sms_db_file_path)) {
if (db_init(tall_msc_ctx, msc_network->sms_db_file_path, true)) {
fprintf(stderr, "DB: Failed to init database: %s\n",
osmo_quote_str((char*)msc_network->sms_db_file_path, -1));
return 4;

View File

@ -49,5 +49,4 @@ db_sms_test_LDADD = \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
$(LIBRARY_GSM) \
-ldbi \
$(NULL)

View File

@ -538,7 +538,7 @@ int main(int argc, char **argv)
* the test output is not deterministic. Let's suppress this
* message by increasing the log level to LOGL_ERROR. */
log_parse_category_mask(osmo_stderr_target, "DDB,7");
rc = db_init(":memory:");
rc = db_init(talloc_ctx, ":memory:", true);
OSMO_ASSERT(rc == 0);
/* HACK: relax log level back to LOGL_DEBUG (see note above) */

View File

@ -46,7 +46,6 @@ sms_queue_test_LDADD = \
$(LIBOSMOGSUPCLIENT_LIBS) \
$(LIBSQLITE3_LIBS) \
$(LIBRARY_GSM) \
-ldbi \
$(NULL)
sms_queue_test_LDFLAGS = \