[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: MYSQL: phase out
From: |
gnunet |
Subject: |
[gnunet] branch master updated: MYSQL: phase out |
Date: |
Sun, 24 Sep 2023 11:13:07 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 757fe3927 MYSQL: phase out
757fe3927 is described below
commit 757fe39278b2f3f29459f33c5ec41f0181142e18
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Sun Sep 24 11:13:02 2023 +0200
MYSQL: phase out
---
README | 5 +-
configure.ac | 92 --
po/POTFILES.in | 5 -
src/Makefile.am | 5 -
src/datastore/Makefile.am | 64 --
.../perf_plugin_datastore_data_mysql.conf | 10 -
src/datastore/plugin_datastore_mysql.c | 1204 --------------------
src/datastore/test_datastore_api_data_mysql.conf | 10 -
.../test_plugin_datastore_data_mysql.conf | 9 -
src/include/Makefile.am | 3 -
src/include/gnunet_my_lib.h | 511 ---------
src/include/gnunet_mysql_compat.h.in | 57 -
src/include/gnunet_mysql_lib.h | 151 ---
src/my/.gitignore | 1 -
src/my/Makefile.am | 41 -
src/my/meson.build | 15 -
src/my/my.c | 270 -----
src/my/my_query_helper.c | 401 -------
src/my/my_result_helper.c | 868 --------------
src/my/test_my.c | 301 -----
src/my/test_my.conf | 0
src/mysql/Makefile.am | 18 -
src/mysql/meson.build | 13 -
src/mysql/mysql.c | 485 --------
src/regex/Makefile.am | 29 +-
25 files changed, 15 insertions(+), 4553 deletions(-)
diff --git a/README b/README
index 9c6c7081a..2981a9597 100644
--- a/README
+++ b/README
@@ -121,7 +121,6 @@ Direct dependencies of GNUnet:
Dependencies of optional components/functionality:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Database plugins (alternatives to sqlite):
- * mysql >= 5.1
* postgres >= 9.5
- Transport plugins:
* bluez (bluetooth transport)
@@ -315,9 +314,7 @@ traversal).
GNUnet requires the GNU MP library (https://www.gnu.org/software/gmp/)
and libgcrypt (https://www.gnupg.org/). You can specify the path to
-libgcrypt by passing "--with-gcrypt=PATH" to configure. You will also
-need either sqlite (http://www.sqlite.org/), MySQL
-(http://www.mysql.org/) or PostGres (http://www.postgres.org/).
+libgcrypt by passing "--with-gcrypt=PATH" to configure.
If you install from source, you need to install GNU libextractor first
(download from https://www.gnu.org/software/libextractor/). We also
diff --git a/configure.ac b/configure.ac
index 53a640291..34c8608f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -904,89 +904,6 @@ AM_CONDITIONAL([HAVE_POSTGRESQL], [test "x$postgres" =
"x1"])
AC_DEFINE_UNQUOTED([HAVE_POSTGRESQL], [$postgres],
[Define to 1 if Postgres is available])
-# check for mysql
-SAVE_LDFLAGS="$LDFLAGS"
-SAVE_CPPFLAGS="$CPPFLAGS"
-AC_ARG_WITH([mysql],
- [AS_HELP_STRING([--with-mysql=PFX], [base of mysql installation])],
- [AS_CASE([$withval],
- [no],
- [],
- [yes|""],
- [AC_CHECK_HEADERS([mysql/mysql.h],
- [AC_CHECK_LIB([mysqlclient], [mysql_init],
- [mysql=true], [mysql=false])])],
- [LDFLAGS="-L$with_mysql/lib -L$with_mysql/lib/mysql $LDFLAGS $ZLIBS"
- CPPFLAGS="-I$with_mysql/include $CPPFLAGS"
- AC_CHECK_HEADERS([mysql/mysql.h],
- [AC_CHECK_LIB([mysqlclient], [mysql_init],
- [MYSQL_LDFLAGS="-L$with_mysql/lib
-L$with_mysql/lib/mysql"
- MYSQL_CPPFLAGS="-I$with_mysql/include"
- mysql=true],
- [mysql=false])])])],
- [AS_IF([test -d "/usr/lib64/mysql"],
- [MYSQL_LIBDIR="/usr/lib64/mysql"],
- [AS_IF([test -d "/usr/lib/mysql"],
- [MYSQL_LIBDIR="/usr/lib/mysql"],
- [MYSQL_LIBDIR="/usr/lib"])])
- LDFLAGS="-L$MYSQL_LIBDIR $LDFLAGS $ZLIBS"
- AC_CHECK_LIB([mysqlclient], [mysql_init],
- [AC_CHECK_HEADERS([mysql/mysql.h],
- [MYSQL_LDFLAGS="-L$MYSQL_LIBDIR"
- mysql=true],
- [mysql=false])],
- [mysql=false])])
-AC_SUBST(MYSQL_LDFLAGS)
-AC_SUBST(MYSQL_CPPFLAGS)
-
-mysql_bool="bool"
-# check for my_bool
-AS_IF([test "x$mysql" = "xtrue"],
- [AC_MSG_CHECKING([for my_bool])
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
- [[#include <mysql/mysql.h>]
- [typedef int my_bool;]])], # Hint: this fails if my_bool is defined
already
- [AC_MSG_RESULT([no])
- mysql_bool="bool"],
- [AC_MSG_RESULT([yes])
- mysql_bool="my_bool"])])
-
-AC_SUBST([mysql_bool])
-
-# additional version checks for mysql
-AS_IF([test "x$mysql" = "xtrue"],
- [AC_MSG_CHECKING([for mysql version])
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
- [[#include <mysql/mysql.h>]],
- [[#if (MYSQL_VERSION_ID < 40100)
-#error required at least version 4.1
-#endif]])],
- [mysql=true],
- [mysql=false])
- AS_IF([test "x$mysql" = "xfalse"],
- [AC_MSG_RESULT([< 4.1])
- AC_MSG_RESULT([mysql version >= 4.1 required. Will not use MySQL])])
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
- [[#include <mysql/mysql.h>]],
- [[#if (MYSQL_VERSION_ID < 80000)
-#error needs at least version 8.0
-#endif]])],
- [mysql8=true],
- [mysql8=false])])
-
-AS_IF([test "x$mysql" = "xtrue"],
- [AS_IF([test "x$mysql8" = "xfalse"],
- [AC_MSG_RESULT([between 4.1 and 8.0])],
- [AC_MSG_RESULT([> 8.0])
- AC_DEFINE([HAVE_MYSQL8], [1],
- [Define to 1 if MySQL is at least version 8])])])
-
-AM_CONDITIONAL([HAVE_MYSQL], [test "x$mysql" = "xtrue"])
-AM_CONDITIONAL([HAVE_MYSQLE], [false])
-
-AS_IF([test "x$sqlite3" = "x0" && test "x$mysql" = "xfalse" && test
"x$postgres" = "x0"],
- [AC_MSG_ERROR([GNUnet requires either SQLite, MySQL/MariaDB or PostgreSQL])])
-
LDFLAGS="$SAVE_LDFLAGS"
CPPFLAGS="$SAVE_CPPFLAGS"
@@ -1347,12 +1264,10 @@ src/identity/Makefile
src/identity/identity.conf
src/include/Makefile
src/include/gnunet_config.h
-src/include/gnunet_mysql_compat.h
src/integration-tests/Makefile
src/json/Makefile
src/hostlist/Makefile
src/my/Makefile
-src/mysql/Makefile
src/namecache/Makefile
src/namecache/namecache.conf
src/namestore/Makefile
@@ -1432,7 +1347,6 @@ pkgconfig/gnunetidentity.pc
pkgconfig/gnunetjson.pc
pkgconfig/gnunetmessenger.pc
pkgconfig/gnunetmicrophone.pc
-pkgconfig/gnunetmysql.pc
pkgconfig/gnunetnamestore.pc
pkgconfig/gnunetnat.pc
pkgconfig/gnunetnse.pc
@@ -1574,11 +1488,6 @@ AS_IF([test "x$sqlite3" = "x1"],
features_msg="sqlite $features_msg"],
[sqlite_msg="no"])
-AS_IF([test "x$mysql" = "xtrue"],
- [mysql_msg="yes"
- features_msg="mysql $features_msg"],
- [mysql_msg="no"])
-
AS_IF([test "x$postgres" = "x1"],
[postgres_msg="yes"
features_msg="postgres $features_msg"],
@@ -1607,7 +1516,6 @@ Build Target: ${build_target}
Default Interface: ${interface_msg}
sqlite3: ${sqlite_msg}
-MySQL: ${mysql_msg}
PostgreSQL: ${postgres_msg}
cURL TLS backend: ${curl_tls_backend}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index bc8be7a54..3d6c2f6d1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -89,7 +89,6 @@ src/datastore/datastore_api.c
src/datastore/gnunet-datastore.c
src/datastore/gnunet-service-datastore.c
src/datastore/plugin_datastore_heap.c
-src/datastore/plugin_datastore_mysql.c
src/datastore/plugin_datastore_postgres.c
src/datastore/plugin_datastore_sqlite.c
src/datastore/plugin_datastore_template.c
@@ -233,10 +232,6 @@ src/messenger/messenger_api_util.c
src/messenger/plugin_gnsrecord_messenger.c
src/messenger/testing_messenger_barrier.c
src/messenger/testing_messenger_setup.c
-src/my/my.c
-src/my/my_query_helper.c
-src/my/my_result_helper.c
-src/mysql/mysql.c
src/namecache/gnunet-namecache.c
src/namecache/gnunet-service-namecache.c
src/namecache/namecache_api.c
diff --git a/src/Makefile.am b/src/Makefile.am
index d7c0b51f0..8fb984d4b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,10 +25,6 @@ if HAVE_SQLITE
SQLITE_DIR = sq
endif
-if HAVE_MYSQL
- MYSQL_DIR = mysql my
-endif
-
if HAVE_POSTGRESQL
POSTGRES_DIR = pq
endif
@@ -50,7 +46,6 @@ SUBDIRS = \
$(REST_DIR) \
peerinfo \
$(SQLITE_DIR) \
- $(MYSQL_DIR) \
$(POSTGRES_DIR) \
datacache \
datastore \
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index b73a0497b..595c7da3d 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -56,19 +56,6 @@ gnunet_datastore_LDADD = \
$(GN_LIBINTL)
-if HAVE_MYSQL
- MYSQL_PLUGIN = libgnunet_plugin_datastore_mysql.la
-if HAVE_BENCHMARKS
- MYSQL_BENCHMARKS = \
- perf_datastore_api_mysql \
- perf_plugin_datastore_mysql
-endif
- MYSQL_TESTS = \
- test_datastore_api_mysql \
- test_datastore_api_management_mysql \
- test_plugin_datastore_mysql \
- $(MYSQL_BENCHMARKS)
-endif
if HAVE_SQLITE
SQLITE_PLUGIN = libgnunet_plugin_datastore_sqlite.la
if HAVE_BENCHMARKS
@@ -98,7 +85,6 @@ endif
plugin_LTLIBRARIES = \
$(SQLITE_PLUGIN) \
- $(MYSQL_PLUGIN) \
$(POSTGRES_PLUGIN) \
libgnunet_plugin_datastore_heap.la
@@ -128,18 +114,6 @@ libgnunet_plugin_datastore_heap_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
-libgnunet_plugin_datastore_mysql_la_SOURCES = \
- plugin_datastore_mysql.c
-libgnunet_plugin_datastore_mysql_la_LIBADD = \
- $(top_builddir)/src/my/libgnunetmy.la \
- $(top_builddir)/src/mysql/libgnunetmysql.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) $(Z_LIBS) -lmysqlclient
-libgnunet_plugin_datastore_mysql_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS) $(MYSQL_LDFLAGS) -lmysqlclient
-libgnunet_plugin_datastore_mysql_la_CPPFLAGS = \
- $(MYSQL_CPPFLAGS) $(AM_CPPFLAGS)
-
libgnunet_plugin_datastore_postgres_la_SOURCES = \
plugin_datastore_postgres.c
libgnunet_plugin_datastore_postgres_la_LIBADD = \
@@ -167,7 +141,6 @@ check_PROGRAMS = \
perf_plugin_datastore_heap \
test_plugin_datastore_heap \
$(SQLITE_TESTS) \
- $(MYSQL_TESTS) \
$(POSTGRES_TESTS)
if ENABLE_TEST_RUN
@@ -243,40 +216,6 @@ test_plugin_datastore_sqlite_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la
-test_datastore_api_mysql_SOURCES = \
- test_datastore_api.c
-test_datastore_api_mysql_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- libgnunetdatastore.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-test_datastore_api_management_mysql_SOURCES = \
- test_datastore_api_management.c
-test_datastore_api_management_mysql_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- libgnunetdatastore.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_datastore_api_mysql_SOURCES = \
- perf_datastore_api.c
-perf_datastore_api_mysql_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- libgnunetdatastore.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-test_plugin_datastore_mysql_SOURCES = \
- test_plugin_datastore.c
-test_plugin_datastore_mysql_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-perf_plugin_datastore_mysql_SOURCES = \
- perf_plugin_datastore.c
-perf_plugin_datastore_mysql_LDADD = \
- $(top_builddir)/src/testing/libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-
test_datastore_api_postgres_SOURCES = \
test_datastore_api.c
test_datastore_api_postgres_LDADD = \
@@ -319,9 +258,6 @@ EXTRA_DIST = \
test_datastore_api_data_heap.conf \
perf_plugin_datastore_data_heap.conf \
test_plugin_datastore_data_heap.conf \
- test_datastore_api_data_mysql.conf \
- perf_plugin_datastore_data_mysql.conf \
- test_plugin_datastore_data_mysql.conf \
test_datastore_api_data_postgres.conf \
perf_plugin_datastore_data_postgres.conf \
test_plugin_datastore_data_postgres.conf \
diff --git a/src/datastore/perf_plugin_datastore_data_mysql.conf
b/src/datastore/perf_plugin_datastore_data_mysql.conf
deleted file mode 100644
index a32b830c3..000000000
--- a/src/datastore/perf_plugin_datastore_data_mysql.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-@INLINE@ test_defaults.conf
-[PATHS]
-GNUNET_TEST_HOME = $GNUNET_TMP/perf-gnunet-datastore-mysql/
-
-[datastore]
-DATABASE = mysql
-
-[datastore-mysql]
-DATABASE = gnunetcheck
-
diff --git a/src/datastore/plugin_datastore_mysql.c
b/src/datastore/plugin_datastore_mysql.c
deleted file mode 100644
index f62c51778..000000000
--- a/src/datastore/plugin_datastore_mysql.c
+++ /dev/null
@@ -1,1204 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2009, 2010, 2011 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file datastore/plugin_datastore_mysql.c
- * @brief mysql-based datastore backend
- * @author Igor Wronsky
- * @author Christian Grothoff
- * @author Christophe Genevey
- *
- * NOTE: This db module does NOT work with mysql prior to 4.1 since
- * it uses prepared statements. MySQL 5.0.46 promises to fix a bug
- * in MyISAM that is causing us grief. At the time of this writing,
- * that version is yet to be released. In anticipation, the code
- * will use MyISAM with 5.0.46 (and higher). If you run such a
- * version, please run "make check" to verify that the MySQL bug
- * was actually fixed in your version (and if not, change the
- * code below to use MyISAM for gn071).
- *
- * HIGHLIGHTS
- *
- * Pros
- * + On up-to-date hardware where mysql can be used comfortably, this
- * module will have better performance than the other db choices
- * (according to our tests).
- * + Its often possible to recover the mysql database from internal
- * inconsistencies. The other db choices do not support repair!
- * Cons
- * - Memory usage (Comment: "I have 1G and it never caused me trouble")
- * - Manual setup
- *
- * MANUAL SETUP INSTRUCTIONS
- *
- * 1) in gnunet.conf, set
- * @verbatim
- [datastore]
- DATABASE = "mysql"
- @endverbatim
- * 2) Then access mysql as root,
- * @verbatim
- $ mysql -u root -p
- @endverbatim
- * and do the following. [You should replace $USER with the username
- * that will be running the gnunetd process].
- * @verbatim
- CREATE DATABASE gnunet;
- GRANT select,insert,update,delete,create,alter,drop,create temporary
tables
- ON gnunet.* TO $USER@localhost;
- SET PASSWORD FOR $USER@localhost=PASSWORD('$the_password_you_like');
- FLUSH PRIVILEGES;
- @endverbatim
- * 3) In the $HOME directory of $USER, create a ".my.cnf" file
- * with the following lines
- * @verbatim
- [client]
- user=$USER
- password=$the_password_you_like
- @endverbatim
- *
- * That's it. Note that .my.cnf file is a security risk unless its on
- * a safe partition etc. The $HOME/.my.cnf can of course be a symbolic
- * link. Even greater security risk can be achieved by setting no
- * password for $USER. Luckily $USER has only privileges to mess
- * up GNUnet's tables, nothing else (unless you give them more,
- * of course).<p>
- *
- * 4) Still, perhaps you should briefly try if the DB connection
- * works. First, login as $USER. Then use,
- *
- * @verbatim
- $ mysql -u $USER -p $the_password_you_like
- mysql> use gnunet;
- @endverbatim
- *
- * If you get the message "Database changed" it probably works.
- *
- * [If you get "ERROR 2002: Can't connect to local MySQL server
- * through socket '/tmp/mysql.sock' (2)" it may be resolvable by
- * "ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock"
- * so there may be some additional trouble depending on your mysql setup.]
- *
- * REPAIRING TABLES
- *
- * - Its probably healthy to check your tables for inconsistencies
- * every now and then.
- * - If you get odd SEGVs on gnunetd startup, it might be that the mysql
- * databases have been corrupted.
- * - The tables can be verified/fixed in two ways;
- * 1) by running mysqlcheck -A, or
- * 2) by executing (inside of mysql using the GNUnet database):
- * @verbatim
- mysql> REPAIR TABLE gn090;
- @endverbatim
- *
- * PROBLEMS?
- *
- * If you have problems related to the mysql module, your best
- * friend is probably the mysql manual. The first thing to check
- * is that mysql is basically operational, that you can connect
- * to it, create tables, issue queries etc.
- */
-
-#include "platform.h"
-#include "gnunet_datastore_plugin.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_mysql_lib.h"
-#include "gnunet_mysql_compat.h"
-#include "gnunet_my_lib.h"
-
-#define MAX_DATUM_SIZE 65536
-
-
-/**
- * Context for all functions in this plugin.
- */
-struct Plugin
-{
- /**
- * Our execution environment.
- */
- struct GNUNET_DATASTORE_PluginEnvironment *env;
-
- /**
- * Handle to talk to MySQL.
- */
- struct GNUNET_MYSQL_Context *mc;
-
- /**
- * Prepared statements.
- */
-#define INSERT_ENTRY \
- "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value)
VALUES (?,?,?,?,?,?,?,?,?)"
- struct GNUNET_MYSQL_StatementHandle *insert_entry;
-
-#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
- struct GNUNET_MYSQL_StatementHandle *delete_entry_by_uid;
-
-#define DELETE_ENTRY_BY_HASH_VALUE "DELETE FROM gn090 " \
- "WHERE hash = ? AND " \
- "value = ? " \
- "LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *delete_entry_by_hash_value;
-
-#define RESULT_COLUMNS "repl, type, prio, anonLevel, expire, hash, value, uid"
-
-#define SELECT_ENTRY "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "WHERE uid >= ? AND " \
- "(rvalue >= ? OR 0 = ?) " \
- "ORDER BY uid LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_entry;
-
-#define SELECT_ENTRY_BY_HASH "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_hash_type_uid) " \
- "WHERE hash=? AND " \
- "uid >= ? AND " \
- "(rvalue >= ? OR 0 = ?) " \
- "ORDER BY uid LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash;
-
-#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_hash_type_uid) " \
- "WHERE hash = ? AND " \
- "type = ? AND " \
- "uid >= ? AND " \
- "(rvalue >= ? OR 0 = ?) " \
- "ORDER BY uid LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_entry_by_hash_and_type;
-
-#define UPDATE_ENTRY "UPDATE gn090 SET " \
- "prio = prio + ?, " \
- "repl = repl + ?, " \
- "expire = GREATEST(expire, ?) " \
- "WHERE hash = ? AND vhash = ?"
- struct GNUNET_MYSQL_StatementHandle *update_entry;
-
-#define DEC_REPL "UPDATE gn090 SET repl=GREATEST (1, repl) - 1 WHERE uid=?"
- struct GNUNET_MYSQL_StatementHandle *dec_repl;
-
-#define SELECT_SIZE "SELECT SUM(LENGTH(value)+256) FROM gn090"
- struct GNUNET_MYSQL_StatementHandle *get_size;
-
-#define SELECT_IT_NON_ANONYMOUS "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_anonLevel_type_rvalue) " \
- "WHERE anonLevel=0 AND " \
- "type=? AND " \
- "uid >= ? " \
- "ORDER BY uid LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *zero_iter;
-
-#define SELECT_IT_EXPIRATION "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_expire) " \
- "WHERE expire < ? " \
- "ORDER BY expire ASC LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_expiration;
-
-#define SELECT_IT_PRIORITY "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_prio) " \
- "ORDER BY prio ASC LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_priority;
-
-#define SELECT_IT_REPLICATION "SELECT " RESULT_COLUMNS " FROM gn090 " \
- "FORCE INDEX (idx_repl_rvalue) " \
- "WHERE repl=? AND " \
- " (rvalue>=? OR" \
- " NOT EXISTS (SELECT 1 FROM gn090 FORCE INDEX (idx_repl_rvalue) WHERE
repl=? AND rvalue>=?)) " \
- "ORDER BY rvalue ASC " \
- "LIMIT 1"
- struct GNUNET_MYSQL_StatementHandle *select_replication;
-
-#define SELECT_MAX_REPL "SELECT MAX(repl) FROM gn090"
- struct GNUNET_MYSQL_StatementHandle *max_repl;
-
-#define GET_ALL_KEYS "SELECT hash from gn090"
- struct GNUNET_MYSQL_StatementHandle *get_all_keys;
-};
-
-#define MAX_PARAM 16
-
-/**
- * Delete an entry from the gn090 table.
- *
- * @param plugin plugin context
- * @param uid unique ID of the entry to delete
- * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists,
#GNUNET_SYSERR on error
- */
-static int
-do_delete_entry (struct Plugin *plugin,
- unsigned long long uid)
-{
- int ret;
- uint64_t uid64 = (uint64_t) uid;
- struct GNUNET_MY_QueryParam params_delete[] = {
- GNUNET_MY_query_param_uint64 (&uid64),
- GNUNET_MY_query_param_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting value %llu from gn090 table\n",
- uid);
- ret = GNUNET_MY_exec_prepared (plugin->mc,
- plugin->delete_entry_by_uid,
- params_delete);
- if (ret >= 0)
- {
- return GNUNET_OK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Deleting value %llu from gn090 table failed\n",
- (unsigned long long) uid);
- return ret;
-}
-
-
-/**
- * Get an estimate of how much space the database is
- * currently using.
- *
- * @param cls our `struct Plugin *`
- * @return number of bytes used on disk
- */
-static void
-mysql_plugin_estimate_size (void *cls,
- unsigned long long *estimate)
-{
- struct Plugin *plugin = cls;
- uint64_t total;
- int ret;
- struct GNUNET_MY_QueryParam params_get[] = {
- GNUNET_MY_query_param_end
- };
- struct GNUNET_MY_ResultSpec results_get[] = {
- GNUNET_MY_result_spec_uint64 (&total),
- GNUNET_MY_result_spec_end
- };
-
- ret = GNUNET_MY_exec_prepared (plugin->mc,
- plugin->get_size,
- params_get);
- *estimate = 0;
- total = UINT64_MAX;
- if ((GNUNET_OK == ret) &&
- (GNUNET_OK ==
- GNUNET_MY_extract_result (plugin->get_size,
- results_get)))
- {
- *estimate = (unsigned long long) total;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Size estimate for MySQL payload is %lld\n",
- (long long) total);
- GNUNET_assert (UINT64_MAX != total);
- GNUNET_break (GNUNET_NO ==
- GNUNET_MY_extract_result (plugin->get_size,
- NULL));
- }
-}
-
-
-/**
- * Store an item in the datastore.
- *
- * @param cls closure
- * @param key key for the item
- * @param absent true if the key was not found in the bloom filter
- * @param size number of bytes in @a data
- * @param data content stored
- * @param type type of the content
- * @param priority priority of the content
- * @param anonymity anonymity-level for the content
- * @param replication replication-level for the content
- * @param expiration expiration time for the content
- * @param cont continuation called with success or failure status
- * @param cont_cls closure for @a cont
- */
-static void
-mysql_plugin_put (void *cls,
- const struct GNUNET_HashCode *key,
- bool absent,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- PluginPutCont cont,
- void *cont_cls)
-{
- struct Plugin *plugin = cls;
- uint64_t lexpiration = expiration.abs_value_us;
- struct GNUNET_HashCode vhash;
-
- GNUNET_CRYPTO_hash (data,
- size,
- &vhash);
- if (! absent)
- {
- struct GNUNET_MY_QueryParam params_update[] = {
- GNUNET_MY_query_param_uint32 (&priority),
- GNUNET_MY_query_param_uint32 (&replication),
- GNUNET_MY_query_param_uint64 (&lexpiration),
- GNUNET_MY_query_param_auto_from_type (key),
- GNUNET_MY_query_param_auto_from_type (&vhash),
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_MY_exec_prepared (plugin->mc,
- plugin->update_entry,
- params_update))
- {
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- _ ("MySQL statement run failure"));
- return;
- }
-
- MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry);
- my_ulonglong rows = mysql_stmt_affected_rows (stmt);
-
- GNUNET_break (GNUNET_NO ==
- GNUNET_MY_extract_result (plugin->update_entry,
- NULL));
- if (0 != rows)
- {
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
- return;
- }
- }
-
- uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- struct GNUNET_MY_QueryParam params_insert[] = {
- GNUNET_MY_query_param_uint32 (&replication),
- GNUNET_MY_query_param_uint32 (&type),
- GNUNET_MY_query_param_uint32 (&priority),
- GNUNET_MY_query_param_uint32 (&anonymity),
- GNUNET_MY_query_param_uint64 (&lexpiration),
- GNUNET_MY_query_param_uint64 (&lrvalue),
- GNUNET_MY_query_param_auto_from_type (key),
- GNUNET_MY_query_param_auto_from_type (&vhash),
- GNUNET_MY_query_param_fixed_size (data, size),
- GNUNET_MY_query_param_end
- };
-
- if (size > MAX_DATUM_SIZE)
- {
- GNUNET_break (0);
- cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large"));
- return;
- }
-
- if (GNUNET_OK !=
- GNUNET_MY_exec_prepared (plugin->mc,
- plugin->insert_entry,
- params_insert))
- {
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- _ ("MySQL statement run failure"));
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inserted value `%s' with size %u into gn090 table\n",
- GNUNET_h2s (key),
- (unsigned int) size);
- if (size > 0)
- plugin->env->duc (plugin->env->cls,
- size);
- GNUNET_break (GNUNET_NO ==
- GNUNET_MY_extract_result (plugin->insert_entry,
- NULL));
- cont (cont_cls,
- key,
- size,
- GNUNET_OK,
- NULL);
-}
-
-
-/**
- * Run the given select statement and call 'proc' on the resulting
- * values (which must be in particular positions).
- *
- * @param plugin the plugin handle
- * @param stmt select statement to run
- * @param proc function to call on result
- * @param proc_cls closure for @a proc
- * @param params_select arguments to initialize stmt
- */
-static void
-execute_select (struct Plugin *plugin,
- struct GNUNET_MYSQL_StatementHandle *stmt,
- PluginDatumProcessor proc,
- void *proc_cls,
- struct GNUNET_MY_QueryParam *params_select)
-{
- int ret;
- uint32_t replication;
- uint32_t type;
- uint32_t priority;
- uint32_t anonymity;
- uint64_t uid;
- size_t value_size;
- void *value;
- struct GNUNET_HashCode key;
- struct GNUNET_TIME_Absolute expiration;
- struct GNUNET_MY_ResultSpec results_select[] = {
- GNUNET_MY_result_spec_uint32 (&replication),
- GNUNET_MY_result_spec_uint32 (&type),
- GNUNET_MY_result_spec_uint32 (&priority),
- GNUNET_MY_result_spec_uint32 (&anonymity),
- GNUNET_MY_result_spec_absolute_time (&expiration),
- GNUNET_MY_result_spec_auto_from_type (&key),
- GNUNET_MY_result_spec_variable_size (&value, &value_size),
- GNUNET_MY_result_spec_uint64 (&uid),
- GNUNET_MY_result_spec_end
- };
-
- ret = GNUNET_MY_exec_prepared (plugin->mc,
- stmt,
- params_select);
- if (GNUNET_OK != ret)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
-
- ret = GNUNET_MY_extract_result (stmt,
- results_select);
- if (GNUNET_OK != ret)
- {
- proc (proc_cls,
- NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found %u-byte value under key `%s' with prio %u, anon %u,
expire %s selecting from gn090 table\n",
- (unsigned int) value_size,
- GNUNET_h2s (&key),
- (unsigned int) priority,
- (unsigned int) anonymity,
- GNUNET_STRINGS_absolute_time_to_string (expiration));
- GNUNET_assert (value_size < MAX_DATUM_SIZE);
- GNUNET_break (GNUNET_NO ==
- GNUNET_MY_extract_result (stmt,
- NULL));
- ret = proc (proc_cls,
- &key,
- value_size,
- value,
- type,
- priority,
- anonymity,
- replication,
- expiration,
- uid);
- GNUNET_MY_cleanup_result (results_select);
- if (GNUNET_NO == ret)
- {
- do_delete_entry (plugin, uid);
- if (0 != value_size)
- plugin->env->duc (plugin->env->cls,
- -value_size);
- }
-}
-
-
-/**
- * Get one of the results for a particular key in the datastore.
- *
- * @param cls closure
- * @param next_uid return the result with lowest uid >= next_uid
- * @param random if true, return a random result instead of using next_uid
- * @param key key to match, never NULL
- * @param type entries of which type are relevant?
- * Use 0 for any type.
- * @param proc function to call on the matching value,
- * with NULL for if no value matches
- * @param proc_cls closure for @a proc
- */
-static void
-mysql_plugin_get_key (void *cls,
- uint64_t next_uid,
- bool random,
- const struct GNUNET_HashCode *key,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
-{
- struct Plugin *plugin = cls;
- uint64_t rvalue;
-
- if (random)
- {
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- next_uid = 0;
- }
- else
- rvalue = 0;
-
- if (NULL == key)
- {
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_uint64 (&next_uid),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_end
- };
-
- execute_select (plugin,
- plugin->select_entry,
- proc,
- proc_cls,
- params_select);
- }
- else if (type != GNUNET_BLOCK_TYPE_ANY)
- {
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_auto_from_type (key),
- GNUNET_MY_query_param_uint32 (&type),
- GNUNET_MY_query_param_uint64 (&next_uid),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_end
- };
-
- execute_select (plugin,
- plugin->select_entry_by_hash_and_type,
- proc,
- proc_cls,
- params_select);
- }
- else
- {
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_auto_from_type (key),
- GNUNET_MY_query_param_uint64 (&next_uid),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_end
- };
-
- execute_select (plugin,
- plugin->select_entry_by_hash,
- proc,
- proc_cls,
- params_select);
- }
-}
-
-
-/**
- * Get a zero-anonymity datum from the datastore.
- *
- * @param cls our `struct Plugin *`
- * @param next_uid return the result with lowest uid >= next_uid
- * @param type entries of which type should be considered?
- * Must not be zero (ANY).
- * @param proc function to call on a matching value;
- * will be called with NULL if no value matches
- * @param proc_cls closure for @a proc
- */
-static void
-mysql_plugin_get_zero_anonymity (void *cls,
- uint64_t next_uid,
- enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
- void *proc_cls)
-{
- struct Plugin *plugin = cls;
- uint32_t typei = (uint32_t) type;
-
- struct GNUNET_MY_QueryParam params_zero_iter[] = {
- GNUNET_MY_query_param_uint32 (&typei),
- GNUNET_MY_query_param_uint64 (&next_uid),
- GNUNET_MY_query_param_end
- };
-
- execute_select (plugin,
- plugin->zero_iter,
- proc,
- proc_cls,
- params_zero_iter);
-}
-
-
-/**
- * Context for #repl_proc() function.
- */
-struct ReplCtx
-{
- /**
- * Plugin handle.
- */
- struct Plugin *plugin;
-
- /**
- * Function to call for the result (or the NULL).
- */
- PluginDatumProcessor proc;
-
- /**
- * Closure for @e proc.
- */
- void *proc_cls;
-};
-
-
-/**
- * Wrapper for the processor for #mysql_plugin_get_replication().
- * Decrements the replication counter and calls the original
- * iterator.
- *
- * @param cls closure
- * @param key key for the content
- * @param size number of bytes in @a data
- * @param data content stored
- * @param type type of the content
- * @param priority priority of the content
- * @param anonymity anonymity-level for the content
- * @param replication replication-level for the content
- * @param expiration expiration time for the content
- * @param uid unique identifier for the datum;
- * maybe 0 if no unique identifier is available
- * @return #GNUNET_SYSERR to abort the iteration, #GNUNET_OK to continue
- * (continue on call to "next", of course),
- * #GNUNET_NO to delete the item and continue (if supported)
- */
-static int
-repl_proc (void *cls,
- const struct GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
-{
- struct ReplCtx *rc = cls;
- struct Plugin *plugin = rc->plugin;
- int ret;
- int iret;
-
- ret = rc->proc (rc->proc_cls,
- key,
- size,
- data,
- type,
- priority,
- anonymity,
- replication,
- expiration,
- uid);
- if (NULL != key)
- {
- struct GNUNET_MY_QueryParam params_proc[] = {
- GNUNET_MY_query_param_uint64 (&uid),
- GNUNET_MY_query_param_end
- };
-
- iret = GNUNET_MY_exec_prepared (plugin->mc,
- plugin->dec_repl,
- params_proc);
- if (GNUNET_SYSERR == iret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to reduce replication counter\n");
- return GNUNET_SYSERR;
- }
- }
- return ret;
-}
-
-
-/**
- * Get a random item for replication. Returns a single, not expired,
- * random item from those with the highest replication counters. The
- * item's replication counter is decremented by one IF it was positive
- * before. Call @a proc with all values ZERO or NULL if the datastore
- * is empty.
- *
- * @param cls closure
- * @param proc function to call the value (once only).
- * @param proc_cls closure for @a proc
- */
-static void
-mysql_plugin_get_replication (void *cls,
- PluginDatumProcessor proc,
- void *proc_cls)
-{
- struct Plugin *plugin = cls;
- uint64_t rvalue;
- uint32_t repl;
- struct ReplCtx rc;
- struct GNUNET_MY_QueryParam params_get[] = {
- GNUNET_MY_query_param_end
- };
- struct GNUNET_MY_ResultSpec results_get[] = {
- GNUNET_MY_result_spec_uint32 (&repl),
- GNUNET_MY_result_spec_end
- };
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_uint32 (&repl),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_uint32 (&repl),
- GNUNET_MY_query_param_uint64 (&rvalue),
- GNUNET_MY_query_param_end
- };
-
- rc.plugin = plugin;
- rc.proc = proc;
- rc.proc_cls = proc_cls;
-
- if (1 !=
- GNUNET_MY_exec_prepared (plugin->mc,
- plugin->max_repl,
- params_get))
- {
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
-
- if (GNUNET_OK !=
- GNUNET_MY_extract_result (plugin->max_repl,
- results_get))
- {
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- GNUNET_break (GNUNET_NO ==
- GNUNET_MY_extract_result (plugin->max_repl,
- NULL));
- rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
-
- execute_select (plugin,
- plugin->select_replication,
- &repl_proc,
- &rc,
- params_select);
-}
-
-
-/**
- * Get all of the keys in the datastore.
- *
- * @param cls closure
- * @param proc function to call on each key
- * @param proc_cls closure for @a proc
- */
-static void
-mysql_plugin_get_keys (void *cls,
- PluginKeyProcessor proc,
- void *proc_cls)
-{
- struct Plugin *plugin = cls;
- int ret;
- MYSQL_STMT *statement;
- unsigned int cnt;
- struct GNUNET_HashCode key;
- struct GNUNET_HashCode last;
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_end
- };
- struct GNUNET_MY_ResultSpec results_select[] = {
- GNUNET_MY_result_spec_auto_from_type (&key),
- GNUNET_MY_result_spec_end
- };
-
- GNUNET_assert (NULL != proc);
- statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys);
- if (GNUNET_OK !=
- GNUNET_MY_exec_prepared (plugin->mc,
- plugin->get_all_keys,
- params_select))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("`%s' for `%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute",
- GET_ALL_KEYS,
- __FILE__,
- __LINE__,
- mysql_stmt_error (statement));
- GNUNET_MYSQL_statements_invalidate (plugin->mc);
- proc (proc_cls, NULL, 0);
- return;
- }
- memset (&last, 0, sizeof(last)); /* make static analysis happy */
- ret = GNUNET_YES;
- cnt = 0;
- while (ret == GNUNET_YES)
- {
- ret = GNUNET_MY_extract_result (plugin->get_all_keys,
- results_select);
- if (0 != GNUNET_memcmp (&last,
- &key))
- {
- if (0 != cnt)
- proc (proc_cls,
- &last,
- cnt);
- cnt = 1;
- last = key;
- }
- else
- {
- cnt++;
- }
- }
- if (0 != cnt)
- proc (proc_cls,
- &last,
- cnt);
- /* finally, let app know we are done */
- proc (proc_cls,
- NULL,
- 0);
- if (GNUNET_SYSERR == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__,
- __LINE__,
- mysql_stmt_error (statement));
- GNUNET_MYSQL_statements_invalidate (plugin->mc);
- return;
- }
-}
-
-
-/**
- * Context for #expi_proc() function.
- */
-struct ExpiCtx
-{
- /**
- * Plugin handle.
- */
- struct Plugin *plugin;
-
- /**
- * Function to call for the result (or the NULL).
- */
- PluginDatumProcessor proc;
-
- /**
- * Closure for @e proc.
- */
- void *proc_cls;
-};
-
-
-/**
- * Wrapper for the processor for #mysql_plugin_get_expiration().
- * If no expired value was found, we do a second query for
- * low-priority content.
- *
- * @param cls closure
- * @param key key for the content
- * @param size number of bytes in data
- * @param data content stored
- * @param type type of the content
- * @param priority priority of the content
- * @param anonymity anonymity-level for the content
- * @param replication replication-level for the content
- * @param expiration expiration time for the content
- * @param uid unique identifier for the datum;
- * maybe 0 if no unique identifier is available
- * @return #GNUNET_SYSERR to abort the iteration, #GNUNET_OK to continue
- * (continue on call to "next", of course),
- * #GNUNET_NO to delete the item and continue (if supported)
- */
-static int
-expi_proc (void *cls,
- const struct GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
- uint64_t uid)
-{
- struct ExpiCtx *rc = cls;
- struct Plugin *plugin = rc->plugin;
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_end
- };
-
- if (NULL == key)
- {
- execute_select (plugin,
- plugin->select_priority,
- rc->proc,
- rc->proc_cls,
- params_select);
- return GNUNET_SYSERR;
- }
- return rc->proc (rc->proc_cls,
- key,
- size,
- data,
- type,
- priority,
- anonymity,
- replication,
- expiration,
- uid);
-}
-
-
-/**
- * Get a random item for expiration.
- * Call @a proc with all values ZERO or NULL if the datastore is empty.
- *
- * @param cls closure
- * @param proc function to call the value (once only).
- * @param proc_cls closure for @a proc
- */
-static void
-mysql_plugin_get_expiration (void *cls,
- PluginDatumProcessor proc,
- void *proc_cls)
-{
- struct Plugin *plugin = cls;
- struct GNUNET_TIME_Absolute now = { 0 };
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_absolute_time (&now),
- GNUNET_MY_query_param_end
- };
- struct ExpiCtx rc;
-
- rc.plugin = plugin;
- rc.proc = proc;
- rc.proc_cls = proc_cls;
- now = GNUNET_TIME_absolute_get ();
- execute_select (plugin,
- plugin->select_expiration,
- expi_proc,
- &rc,
- params_select);
-}
-
-
-/**
- * Drop database.
- *
- * @param cls the `struct Plugin *`
- */
-static void
-mysql_plugin_drop (void *cls)
-{
- struct Plugin *plugin = cls;
-
- if (GNUNET_OK !=
- GNUNET_MYSQL_statement_run (plugin->mc,
- "DROP TABLE gn090"))
- return; /* error */
- plugin->env->duc (plugin->env->cls, 0);
-}
-
-
-/**
- * Remove a particular key in the datastore.
- *
- * @param cls closure
- * @param key key for the content
- * @param size number of bytes in data
- * @param data content stored
- * @param cont continuation called with success or failure status
- * @param cont_cls continuation closure for @a cont
- */
-static void
-mysql_plugin_remove_key (void *cls,
- const struct GNUNET_HashCode *key,
- uint32_t size,
- const void *data,
- PluginRemoveCont cont,
- void *cont_cls)
-{
- struct Plugin *plugin = cls;
- struct GNUNET_MY_QueryParam params_delete[] = {
- GNUNET_MY_query_param_auto_from_type (key),
- GNUNET_MY_query_param_fixed_size (data, size),
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK !=
- GNUNET_MY_exec_prepared (plugin->mc,
- plugin->delete_entry_by_hash_value,
- params_delete))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Removing key `%s' from gn090 table failed\n",
- GNUNET_h2s (key));
- cont (cont_cls,
- key,
- size,
- GNUNET_SYSERR,
- _ ("MySQL statement run failure"));
- return;
- }
-
- MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (
- plugin->delete_entry_by_hash_value);
- my_ulonglong rows = mysql_stmt_affected_rows (stmt);
-
- if (0 == rows)
- {
- cont (cont_cls,
- key,
- size,
- GNUNET_NO,
- NULL);
- return;
- }
- plugin->env->duc (plugin->env->cls,
- -size);
- cont (cont_cls,
- key,
- size,
- GNUNET_OK,
- NULL);
-}
-
-
-/**
- * Entry point for the plugin.
- *
- * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment *`
- * @return our `struct Plugin *`
- */
-void *
-libgnunet_plugin_datastore_mysql_init (void *cls)
-{
- struct GNUNET_DATASTORE_PluginEnvironment *env = cls;
- struct GNUNET_DATASTORE_PluginFunctions *api;
- struct Plugin *plugin;
-
- plugin = GNUNET_new (struct Plugin);
- plugin->env = env;
- plugin->mc = GNUNET_MYSQL_context_create (env->cfg,
- "datastore-mysql");
- if (NULL == plugin->mc)
- {
- GNUNET_free (plugin);
- return NULL;
- }
-#define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a))
-#define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \
- b)))
- if (MRUNS
- ("CREATE TABLE IF NOT EXISTS gn090 ("
- " repl INT(11) UNSIGNED NOT NULL DEFAULT 0,"
- " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
- " prio INT(11) UNSIGNED NOT NULL DEFAULT 0,"
- " anonLevel INT(11) UNSIGNED NOT NULL DEFAULT 0,"
- " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
- " rvalue BIGINT UNSIGNED NOT NULL,"
- " hash BINARY(64) NOT NULL DEFAULT '',"
- " vhash BINARY(64) NOT NULL DEFAULT '',"
- " value BLOB NOT NULL DEFAULT '',"
- " uid BIGINT NOT NULL AUTO_INCREMENT,"
- " PRIMARY KEY (uid),"
- " INDEX idx_hash_type_uid (hash(64),type,rvalue),"
- " INDEX idx_prio (prio),"
- " INDEX idx_repl_rvalue (repl,rvalue),"
- " INDEX idx_expire (expire),"
- " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)"
- ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") ||
- PINIT (plugin->insert_entry, INSERT_ENTRY) ||
- PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
- PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) ||
- PINIT (plugin->select_entry, SELECT_ENTRY) ||
- PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
- PINIT (plugin->select_entry_by_hash_and_type,
- SELECT_ENTRY_BY_HASH_AND_TYPE) ||
- PINIT (plugin->get_size, SELECT_SIZE) ||
- PINIT (plugin->update_entry, UPDATE_ENTRY) ||
- PINIT (plugin->dec_repl, DEC_REPL) ||
- PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
- PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
- PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
- PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
- PINIT (plugin->get_all_keys, GET_ALL_KEYS) ||
- PINIT (plugin->select_replication, SELECT_IT_REPLICATION) ||
- false)
- {
- GNUNET_MYSQL_context_destroy (plugin->mc);
- GNUNET_free (plugin);
- return NULL;
- }
-#undef PINIT
-#undef MRUNS
-
- api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
- api->cls = plugin;
- api->estimate_size = &mysql_plugin_estimate_size;
- api->put = &mysql_plugin_put;
- api->get_key = &mysql_plugin_get_key;
- api->get_replication = &mysql_plugin_get_replication;
- api->get_expiration = &mysql_plugin_get_expiration;
- api->get_zero_anonymity = &mysql_plugin_get_zero_anonymity;
- api->get_keys = &mysql_plugin_get_keys;
- api->drop = &mysql_plugin_drop;
- api->remove_key = &mysql_plugin_remove_key;
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
- _ ("Mysql database running\n"));
- return api;
-}
-
-
-/**
- * Exit point from the plugin.
- *
- * @param cls our `struct Plugin *`
- * @return always NULL
- */
-void *
-libgnunet_plugin_datastore_mysql_done (void *cls)
-{
- struct GNUNET_DATASTORE_PluginFunctions *api = cls;
- struct Plugin *plugin = api->cls;
-
- GNUNET_MYSQL_context_destroy (plugin->mc);
- GNUNET_free (plugin);
- GNUNET_free (api);
- return NULL;
-}
-
-
-/* end of plugin_datastore_mysql.c */
diff --git a/src/datastore/test_datastore_api_data_mysql.conf
b/src/datastore/test_datastore_api_data_mysql.conf
deleted file mode 100644
index c0052c5ea..000000000
--- a/src/datastore/test_datastore_api_data_mysql.conf
+++ /dev/null
@@ -1,10 +0,0 @@
-@INLINE@ test_defaults.conf
-[PATHS]
-GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-datastore-mysql/
-
-[datastore]
-QUOTA = 10 MB
-DATABASE = mysql
-
-[datastore-mysql]
-DATABASE = gnunetcheck
diff --git a/src/datastore/test_plugin_datastore_data_mysql.conf
b/src/datastore/test_plugin_datastore_data_mysql.conf
deleted file mode 100644
index 07d3ec58e..000000000
--- a/src/datastore/test_plugin_datastore_data_mysql.conf
+++ /dev/null
@@ -1,9 +0,0 @@
-@INLINE@ test_defaults.conf
-[PATHS]
-GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-datastore-plugin-mysql/
-
-[datastore]
-DATABASE = mysql
-
-[datastore-mysql]
-DATABASE = gnunetcheck
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 8519883c9..ef18ab01b 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -75,9 +75,6 @@ gnunetinclude_HEADERS = \
gnunet_microphone_lib.h \
gnunet_mst_lib.h \
gnunet_mq_lib.h \
- gnunet_my_lib.h \
- gnunet_mysql_compat.h \
- gnunet_mysql_lib.h \
gnunet_namecache_plugin.h \
gnunet_namecache_service.h \
gnunet_namestore_plugin.h \
diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h
deleted file mode 100644
index 283b2f7e6..000000000
--- a/src/include/gnunet_my_lib.h
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @addtogroup lib_extra
- * @{
- *
- * @author Christian Grothoff
- * @author Christophe Genevey
- * @author Martin Schanzenbach
- *
- * @file
- * Helper library to access a MySQL database
- *
- * @defgroup mysql MySQL library
- * Helper library to access a MySQL database.
- * @{
- */
-#ifndef GNUNET_MY_LIB_H
-#define GNUNET_MY_LIB_H
-
-
-#include "gnunet_util_lib.h"
-#include "gnunet_mysql_lib.h"
-#include <mysql/mysql.h>
-
-#ifndef MYSQL_BOOL
-#error "You need to define MYSQL_BOOL. See (or include) gnunet_mysql_compat.h"
-#endif
-
-#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
-
-/**
- * Information we pass to #GNUNET_MY_exec_prepared() to
- * initialize the arguments of the prepared statement.
- */
-struct GNUNET_MY_QueryParam;
-
-
-/**
- * Function called to convert input argument into SQL parameters.
- *
- * @param cls closure
- * @param pq data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-typedef int
-(*GNUNET_MY_QueryConverter)(void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind);
-
-
-/**
- * Function called to cleanup result data.
- *
- * @param cls closure
- * @param rs spec to clean up
- */
-typedef void
-(*GNUNET_MY_QueryCleanup)(void *cls,
- MYSQL_BIND *qbind);
-/**
- * Information we pass to #GNUNET_MY_exec_prepared() to
- * initialize the arguments of the prepared statement.
- */
-
-
-struct GNUNET_MY_QueryParam
-{
- /**
- * Function to call for the type conversion.
- */
- GNUNET_MY_QueryConverter conv;
-
- /**
- * Function to call for cleaning up the query. Can be NULL.
- */
- GNUNET_MY_QueryCleanup cleaner;
-
- /**
- * Closure for @e conv.
- */
- void *conv_cls;
-
- /**
- * Number of arguments the @a conv converter expects to initialize.
- */
- unsigned int num_params;
-
- /**
- * Information to pass to @e conv.
- */
- const void *data;
-
- /**
- * Information to pass to @e conv. Size of @a data.
- */
- unsigned long data_len;
-};
-
-/**
- * End of query parameter specification.
- *
- * @return array last entry for the result specification to use
- */
-#define GNUNET_MY_query_param_end { NULL, NULL, NULL, 0, NULL, 0 }
-
-
-/**
- * Generate query parameter for a buffer @a ptr of
- * @a ptr_size bytes.FG
- *
- * @param ptr pointer to the query parameter to pass
- * @param ptr_size number of bytes in @a ptr
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_fixed_size (const void *ptr,
- size_t ptr_size);
-
-
-/**
- * Run a prepared SELECT statement.
- *
- * @param mc mysql context
- * @param sh handle to SELECT statement
- * @param params parameters to the statement
- * @return TBD
- */
-int
-GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
- struct GNUNET_MYSQL_StatementHandle *sh,
- struct GNUNET_MY_QueryParam *params);
-
-
-/**
- * Information we pass to #GNUNET_MY_extract_result() to
- * initialize the arguments of the prepared statement.
- */
-struct GNUNET_MY_ResultParam;
-
-/**
- * Information we pass to #GNUNET_MY_extract_result() to
- * initialize the arguments of the prepared statement.
- */
-struct GNUNET_MY_ResultSpec;
-
-/**
- * Function called to convert input argument into SQL parameters.
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return -1 on error
- */
-typedef int
-(*GNUNET_MY_ResultConverter)(void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results);
-
-/**
- * Function called to cleanup result data.
- *
- * @param cls closure
- * @param rs spec to clean up
- */
-typedef void
-(*GNUNET_MY_ResultCleanup)(void *cls,
- struct GNUNET_MY_ResultSpec *rs);
-
-
-/**
- * Information we pass to #GNUNET_MY_extract_result() to
- * initialize the arguments of the prepared statement.
- */
-struct GNUNET_MY_ResultSpec
-{
- /**
- * Function to call to initialize the MYSQL_BIND array.
- */
- GNUNET_MY_ResultConverter pre_conv;
-
- /**
- * Function to call for converting the result. Can be NULL.
- */
- GNUNET_MY_ResultConverter post_conv;
-
- /**
- * Function to call for cleaning up the result. Can be NULL.
- */
- GNUNET_MY_ResultCleanup cleaner;
-
- /**
- * Closure for @e conv.
- */
- void *conv_cls;
-
- /**
- * Destination for the data.
- */
- void *dst;
-
- /**
- * Allowed size for the data, 0 for variable-size
- * (in this case, the type of @e dst is a `void **`
- * and we need to allocate a buffer of the right size).
- */
- size_t dst_size;
-
- /**
- * Where to store actual size of the result.
- */
- size_t *result_size;
-
- /**
- * How many fields does this result specification occupy
- * in the result returned by MySQL.
- */
- unsigned int num_fields;
-
- /**
- * Location where we temporarily store the output buffer
- * length from MySQL. Internal to libgnunetmy.
- */
- unsigned long mysql_bind_output_length;
-
- /**
- * Memory for MySQL to notify us about NULL values.
- */
- MYSQL_BOOL is_null;
-};
-
-
-/**
- * End of result speceter specification.
- *
- * @return array last entry for the result specification to use
- */
-#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL, 0, 0 }
-
-
-/**
- * Obtain fixed size result of @a ptr_size bytes from
- * MySQL, store in already allocated buffer at @a ptr.
- *
- * @spec ptr where to write the result
- * @param ptr_size number of bytes available at @a ptr
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_fixed_size (void *ptr,
- size_t ptr_size);
-
-/**
- * Generate query parameter for a string
- *
- * @param ptr pointer to the string query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_string (const char *ptr);
-
-/**
- * Generate fixed-size query parameter with size determined
- * by variable type.
- *
- * @param x pointer to the query parameter to pass
- */
-#define GNUNET_MY_query_param_auto_from_type( \
- x) GNUNET_MY_query_param_fixed_size ((x), sizeof(*(x)))
-
-/**
- * Generate query parameter for an RSA public key. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_rsa_public_key (const struct
- GNUNET_CRYPTO_RsaPublicKey *x);
-
-/**
- * Generate query parameter for an RSA signature. The
- * database must contain a BLOB type in the respective position
- *
- *@param x the query parameter to pass
- *@return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_rsa_signature (const struct
- GNUNET_CRYPTO_RsaSignature *x);
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- *@param x pointer to the query parameter to pass
- *@return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- *@param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_absolute_time_nbo (const struct
- GNUNET_TIME_AbsoluteNBO *x);
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint16 (const uint16_t *x);
-
-/**
- * Generate query parameter for an uint32_t in host byte order
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint32 (const uint32_t *x);
-
-/**
- * Generate query parameter for an uint64_t in host byte order
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint64 (const uint64_t *x);
-
-/**
- * We expect a fixed-size result, with size determined by the type of `* dst`
- *
- * @spec name name of the field in the table
- * @spec dst point to where to store the result, type fits expected result size
- * @return array entry for the result specification to use
- */
-#define GNUNET_MY_result_spec_auto_from_type( \
- dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof(*(dst)))
-
-
-/**
- * Variable-size result expected
- *
- * @param[out] dst where to store the result, allocated
- * @param[out] ptr_size where to store the size of @a dst
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_variable_size (void **dst,
- size_t *ptr_size);
-
-/**
- * RSA public key expected
- *
- * @param name name of the field in the table
- * @param[out] rsa where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
-
-
-/**
- * RSA signature expected.
- *
- * @param[out] sig where to store the result;
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
-
-/**
- * 0- terminated string exprected.
- *
- * @param[out] dst where to store the result, allocated
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_string (char **dst);
-
-/**
- * Absolute time expected
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
-
-/**
- * Absolute time in network byte order expected
- *
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
-
-/**
- * uint16_t expected
- *
- * @param[out] u16 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint16 (uint16_t *u16);
-
-/**
- * uint32_t expected
- *
- * @param[out] u32 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint32 (uint32_t *u32);
-
-/**
- * uint64_t expected.
- *
- * @param[out] u64 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint64 (uint64_t *u64);
-
-
-/**
- * Extract results from a query result according to the given
- * specification. Always fetches the next row.
- *
- * @param sh statement that returned results
- * @param rs specification to extract for
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if there is no more data in the result set
- * #GNUNET_SYSERR if a result was invalid
- */
-int
-GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
- struct GNUNET_MY_ResultSpec *specs);
-
-
-/**
- * Free all memory that was allocated in @a qp during
- * #GNUNET_MY_exect_prepared().
- *
- * @param qp query specification to clean up
- * @param qbind mysql query
- */
-void
-GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind);
-
-
-/**
- * Free all memory that was allocated in @a rs during
- * #GNUNET_MY_extract_result().
- *
- * @param rs reult specification to clean up
- */
-void
-GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs);
-
-
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/** @} */ /* end of group */
-
-/** @} */ /* end of group addition to lib_extra */
diff --git a/src/include/gnunet_mysql_compat.h.in
b/src/include/gnunet_mysql_compat.h.in
deleted file mode 100644
index 6218386aa..000000000
--- a/src/include/gnunet_mysql_compat.h.in
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2022 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @author Martin Schanzenbach
- *
- * @file
- * MySQL/MariaDB compatibility insanity helper header
- * Note: gnunet_mysql_compat.h is AUTOGENERATED from gnunet_mysql_compat.h.in
- * Please do not modify or commit gnunet_mysql_compat.h
- *
- * @defgroup mysql MySQL library
- * Helper library to access a MySQL database.
- * @{
- */
-#ifndef GNUNET_MYSQL_COMPAT_H
-#define GNUNET_MYSQL_COMPAT_H
-
-
-#include <mysql/mysql.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
-#define MYSQL_BOOL @mysql_bool@
-
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/** @} */ /* end of group */
diff --git a/src/include/gnunet_mysql_lib.h b/src/include/gnunet_mysql_lib.h
deleted file mode 100644
index 52be3ff11..000000000
--- a/src/include/gnunet_mysql_lib.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2012 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @author Christian Grothoff
- *
- * @file
- * Helper library to access a MySQL database
- *
- * @defgroup mysql MySQL library
- * Helper library to access a MySQL database.
- * @{
- */
-#ifndef GNUNET_MYSQL_LIB_H
-#define GNUNET_MYSQL_LIB_H
-
-
-#include "gnunet_util_lib.h"
-#include <mysql/mysql.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
-/**
- * Mysql context.
- */
-struct GNUNET_MYSQL_Context;
-
-
-/**
- * Handle for a prepared statement.
- */
-struct GNUNET_MYSQL_StatementHandle;
-
-
-/**
- * Type of a callback that will be called for each
- * data set returned from MySQL.
- *
- * @param cls user-defined argument
- * @param num_values number of elements in values
- * @param values values returned by MySQL
- * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort
- */
-typedef int
-(*GNUNET_MYSQL_DataProcessor) (void *cls,
- unsigned int num_values,
- MYSQL_BIND *values);
-
-
-/**
- * Create a mysql context.
- *
- * @param cfg configuration
- * @param section configuration section to use to get MySQL configuration
options
- * @return the mysql context
- */
-struct GNUNET_MYSQL_Context *
-GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section);
-
-
-/**
- * Destroy a mysql context. Also frees all associated prepared statements.
- *
- * @param mc context to destroy
- */
-void
-GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc);
-
-
-/**
- * Close database connection and all prepared statements (we got a DB
- * error). The connection will automatically be re-opened and
- * statements will be re-prepared if they are needed again later.
- *
- * @param mc mysql context
- */
-void
-GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc);
-
-
-/**
- * Get internal handle for a prepared statement. This function should rarely
- * be used, and if, with caution! On failures during the interaction with
- * the handle, you must call #GNUNET_MYSQL_statements_invalidate()!
- *
- * @param sh prepared statement to introspect
- * @return MySQL statement handle, NULL on error
- */
-MYSQL_STMT *
-GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh);
-
-
-/**
- * Prepare a statement. Prepared statements are automatically discarded
- * when the MySQL context is destroyed.
- *
- * @param mc mysql context
- * @param query query text
- * @return prepared statement, NULL on error
- */
-struct GNUNET_MYSQL_StatementHandle *
-GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
- const char *query);
-
-
-/**
- * Run a SQL statement.
- *
- * @param mc mysql context
- * @param sql SQL statement to run
- * @return #GNUNET_OK on success
- * #GNUNET_SYSERR if there was a problem
- */
-int
-GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc,
- const char *sql);
-
-
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/** @} */ /* end of group */
diff --git a/src/my/.gitignore b/src/my/.gitignore
deleted file mode 100644
index 3338ba2ea..000000000
--- a/src/my/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-test_my
diff --git a/src/my/Makefile.am b/src/my/Makefile.am
deleted file mode 100644
index 51e20e6bf..000000000
--- a/src/my/Makefile.am
+++ /dev/null
@@ -1,41 +0,0 @@
-# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
-
-if USE_COVERAGE
- AM_CFLAGS = --coverage
-endif
-
-if HAVE_MYSQL
-lib_LTLIBRARIES = libgnunetmy.la
-endif
-
-libgnunetmy_la_SOURCES = \
- my.c \
- my_query_helper.c \
- my_result_helper.c
-
-libgnunetmy_la_LIBADD = $(MYSQL_LDFLAGS) -lmysqlclient \
- $(top_builddir)/src/mysql/libgnunetmysql.la \
- $(top_builddir)/src/util/libgnunetutil.la
-libgnunetmy_la_LDFLAGS = \
- $(GN_LIB_LDFLAGS) \
- -version-info 0:0:0
-
-if ENABLE_TEST_RUN
-TESTS = \
- test_my
-endif
-
-EXTRA_DIST = \
- test_my.conf
-
-check_PROGRAMS= \
- test_my
-
-test_my_SOURCES = \
- test_my.c
-test_my_LDADD = \
- libgnunetmy.la \
- $(top_builddir)/src/mysql/libgnunetmysql.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- -lmysqlclient $(XLIB)
diff --git a/src/my/meson.build b/src/my/meson.build
deleted file mode 100644
index 877e80560..000000000
--- a/src/my/meson.build
+++ /dev/null
@@ -1,15 +0,0 @@
-libgnunetmy_src = ['my.c',
- 'my_query_helper.c',
- 'my_result_helper.c']
-
-if get_option('monolith') == false
- libgnunetmy = library('gnunetmy',
- libgnunetmy_src,
- dependencies: [libgnunetutil_dep, libgnunetmysq_dep, my_dep],
- include_directories: [incdir, configuration_inc])
- libgnunetmy_dep = declare_dependency(link_with : libgnunetmy)
-else
- foreach p : libgnunetmy_src
- gnunet_src += 'my/' + p
- endforeach
-endif
diff --git a/src/my/my.c b/src/my/my.c
deleted file mode 100644
index b667af4f9..000000000
--- a/src/my/my.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2016, 2018 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file my/my.c
- * @brief library to help with access to a MySQL database
- * @author Christophe Genevey
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <mysql/mysql.h>
-#include "gnunet_mysql_compat.h"
-#include "gnunet_my_lib.h"
-
-
-/**
- * Run a prepared SELECT statement.
- *
- * @param mc mysql context
- * @param sh handle to SELECT statement
- * @param params parameters to the statement
- * @return
- #GNUNET_YES if we can prepare all statement
- #GNUNET_SYSERR if we can't prepare all statement
- */
-int
-GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc,
- struct GNUNET_MYSQL_StatementHandle *sh,
- struct GNUNET_MY_QueryParam *params)
-{
- const struct GNUNET_MY_QueryParam *p;
- unsigned int num;
- MYSQL_STMT *stmt;
-
- num = 0;
- for (unsigned int i = 0; NULL != params[i].conv; i++)
- num += params[i].num_params;
- {
- MYSQL_BIND qbind[num];
- unsigned int off;
-
- memset (qbind,
- 0,
- sizeof(qbind));
- off = 0;
- for (unsigned int i = 0; NULL != (p = ¶ms[i])->conv; i++)
- {
- if (GNUNET_OK !=
- p->conv (p->conv_cls,
- p,
- &qbind[off]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Conversion for MySQL query failed at offset %u\n",
- i);
- return GNUNET_SYSERR;
- }
- off += p->num_params;
- }
- stmt = GNUNET_MYSQL_statement_get_stmt (sh);
- if (mysql_stmt_bind_param (stmt,
- qbind))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "my",
- _ ("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_param",
- __FILE__, __LINE__,
- mysql_stmt_error (stmt));
- GNUNET_MYSQL_statements_invalidate (mc);
- return GNUNET_SYSERR;
- }
-
- if (mysql_stmt_execute (stmt))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "my",
- _ ("`%s' failed at %s:%d with error: %s\n"),
- "mysql_stmt_execute", __FILE__, __LINE__,
- mysql_stmt_error (stmt));
- GNUNET_MYSQL_statements_invalidate (mc);
- return GNUNET_SYSERR;
- }
- GNUNET_MY_cleanup_query (params,
- qbind);
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Free all memory that was allocated in @a qp during
- * #GNUNET_MY_exec_prepared().
- *
- * @param qp query specification to clean up
- * @param qbind array of parameter to clean up
- */
-void
-GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- for (unsigned int i = 0; NULL != qp[i].conv; i++)
- if (NULL != qp[i].cleaner)
- qp[i].cleaner (qp[i].conv_cls,
- &qbind[i]);
-}
-
-
-/**
- * Extract results from a query result according to the given
- * specification. Always fetches the next row.
- *
- * @param sh statement that returned results
- * @param rs specification to extract for
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if there is no more data in the result set
- * #GNUNET_SYSERR if a result was invalid
- */
-int
-GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh,
- struct GNUNET_MY_ResultSpec *rs)
-{
- unsigned int num_fields;
- int ret;
- MYSQL_STMT *stmt;
-
- stmt = GNUNET_MYSQL_statement_get_stmt (sh);
- if (NULL == stmt)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if (NULL == rs)
- {
- mysql_stmt_free_result (stmt);
- return GNUNET_NO;
- }
-
- num_fields = 0;
- for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
- num_fields += rs[i].num_fields;
-
- if (mysql_stmt_field_count (stmt) != num_fields)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Number of fields mismatch between SQL result and result
specification\n");
- return GNUNET_SYSERR;
- }
-
- {
- MYSQL_BIND result[num_fields];
- unsigned int field_off;
-
- memset (result, 0, sizeof(MYSQL_BIND) * num_fields);
- field_off = 0;
- for (unsigned int i = 0; NULL != rs[i].pre_conv; i++)
- {
- struct GNUNET_MY_ResultSpec *rp = &rs[i];
-
- if (GNUNET_OK !=
- rp->pre_conv (rp->conv_cls,
- rp,
- stmt,
- field_off,
- &result[field_off]))
-
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Pre-conversion for MySQL result failed at offset %u\n",
- i);
- return GNUNET_SYSERR;
- }
- field_off += rp->num_fields;
- }
-
- if (mysql_stmt_bind_result (stmt, result))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "my",
- _ ("%s failed at %s:%d with error: %s\n"),
- "mysql_stmt_bind_result",
- __FILE__, __LINE__,
- mysql_stmt_error (stmt));
- return GNUNET_SYSERR;
- }
-#if TEST_OPTIMIZATION
- (void) mysql_stmt_store_result (stmt);
-#endif
- ret = mysql_stmt_fetch (stmt);
- if (MYSQL_NO_DATA == ret)
- {
- mysql_stmt_free_result (stmt);
- return GNUNET_NO;
- }
- if (1 == ret)
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "my",
- _ ("%s failed at %s:%d with error: %s\n"),
- "mysql_stmt_fetch",
- __FILE__, __LINE__,
- mysql_stmt_error (stmt));
- GNUNET_MY_cleanup_result (rs);
- mysql_stmt_free_result (stmt);
- return GNUNET_SYSERR;
- }
- field_off = 0;
- for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
- {
- struct GNUNET_MY_ResultSpec *rp = &rs[i];
-
- if (NULL != rp->post_conv)
- if (GNUNET_OK !=
- rp->post_conv (rp->conv_cls,
- rp,
- stmt,
- field_off,
- &result[field_off]))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Post-conversion for MySQL result failed at offset %u\n",
- i);
- mysql_stmt_free_result (stmt);
- for (unsigned int j = 0; j < i; j++)
- if (NULL != rs[j].cleaner)
- rs[j].cleaner (rs[j].conv_cls,
- rs[j].dst);
- return GNUNET_SYSERR;
- }
- field_off += rp->num_fields;
- }
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Free all memory that was allocated in @a rs during
- * #GNUNET_MY_extract_result().
- *
- * @param rs result specification to clean up
- */
-void
-GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs)
-{
- for (unsigned int i = 0; NULL != rs[i].post_conv; i++)
- if (NULL != rs[i].cleaner)
- rs[i].cleaner (rs[i].conv_cls,
- &rs[i]);
-}
-
-
-/* end of my.c */
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c
deleted file mode 100644
index c12970876..000000000
--- a/src/my/my_query_helper.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file my/my_query_helper.c
- * @brief library to help with access to a MySQL database
- * @author Christian Grothoff
- * @author Christophe Genevey
- */
-#include "platform.h"
-#include <mysql/mysql.h>
-#include "gnunet_mysql_compat.h"
-#include "gnunet_my_lib.h"
-
-
-/**
- * Function called to clean up memory allocated
- * by a #GNUNET_MY_QueryConverter.
- *
- * @param cls closure
- * @param qbind array of parameter to clean up
- */
-static void
-my_clean_query (void *cls,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_free (qbind[0].buffer);
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters.
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_fixed_size (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- qbind->buffer = (void *) qp->data;
- qbind->buffer_length = qp->data_len;
- qbind->buffer_type = MYSQL_TYPE_BLOB;
-
- return 1;
-}
-
-
-/**
- * Generate query parameter for a buffer @a ptr of
- * @a ptr_size bytes.
- *
- * @param ptr pointer to the query parameter to pass
- * @param ptr_size number of bytes in @a ptr
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_fixed_size (const void *ptr,
- size_t ptr_size)
-{
- struct GNUNET_MY_QueryParam qp = {
- .conv = &my_conv_fixed_size,
- .cleaner = NULL,
- .conv_cls = NULL,
- .num_params = 1,
- .data = ptr,
- .data_len = (unsigned long) ptr_size
- };
-
- return qp;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters.
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_string (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- qbind->buffer = (void *) qp->data;
- qbind->buffer_length = qp->data_len;
- qbind->buffer_type = MYSQL_TYPE_STRING;
- return 1;
-}
-
-
-/**
- * Generate query parameter for a string
- *
- * @param ptr pointer to the string query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_string (const char *ptr)
-{
- struct GNUNET_MY_QueryParam qp = {
- .conv = &my_conv_string,
- .cleaner = NULL,
- .conv_cls = NULL,
- .num_params = 1,
- .data = ptr,
- .data_len = strlen (ptr)
- };
-
- return qp;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_uint16 (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- qbind->buffer = (void *) qp->data;
- qbind->buffer_length = sizeof(uint16_t);
- qbind->buffer_type = MYSQL_TYPE_SHORT;
- qbind->is_unsigned = 1;
- return 1;
-}
-
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint16 (const uint16_t *x)
-{
- struct GNUNET_MY_QueryParam res = {
- .conv = &my_conv_uint16,
- .cleaner = NULL,
- .conv_cls = NULL,
- .num_params = 1,
- .data = x,
- .data_len = sizeof(*x)
- };
-
- return res;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_uint32 (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- qbind->buffer = (void *) qp->data;
- qbind->buffer_length = sizeof(uint32_t);
- qbind->buffer_type = MYSQL_TYPE_LONG;
- qbind->is_unsigned = 1;
- return 1;
-}
-
-
-/**
- * Generate query parameter for an uint32_t in host byte order
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint32 (const uint32_t *x)
-{
- struct GNUNET_MY_QueryParam res = {
- .conv = &my_conv_uint32,
- .cleaner = NULL,
- .conv_cls = NULL,
- .num_params = 1,
- .data = x,
- .data_len = sizeof(*x)
- };
-
- return res;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_uint64 (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- qbind->buffer = (void *) qp->data;
- qbind->buffer_length = sizeof(uint64_t);
- qbind->buffer_type = MYSQL_TYPE_LONGLONG;
- qbind->is_unsigned = 1;
- return 1;
-}
-
-
-/**
- * Generate query parameter for an uint64_t in host byte order
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_uint64 (const uint64_t *x)
-{
- struct GNUNET_MY_QueryParam res = {
- .conv = &my_conv_uint64,
- .cleaner = NULL,
- .conv_cls = NULL,
- .num_params = 1,
- .data = x,
- .data_len = sizeof(*x)
- };
-
- return res;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters
- *
- * @param cls closure
- * @param qp data about the query
- * @param qbind array of parameters to initialize
- * @return -1 on error
- */
-static int
-my_conv_rsa_public_key (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data;
- void *buf;
- size_t buf_size;
-
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
- &buf);
- qbind->buffer = buf;
- qbind->buffer_length = buf_size;
- qbind->buffer_type = MYSQL_TYPE_BLOB;
- return 1;
-}
-
-
-/**
- * Generate query parameter for an RSA public key. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_rsa_public_key (const struct
- GNUNET_CRYPTO_RsaPublicKey *x)
-{
- struct GNUNET_MY_QueryParam res = {
- .conv = &my_conv_rsa_public_key,
- .cleaner = &my_clean_query,
- .conv_cls = NULL,
- .num_params = 1,
- .data = x,
- .data_len = 0
- };
-
- return res;
-}
-
-
-/**
- * Function called to convert input argument into SQL parameters
- *
- *@param cls closure
- *@param qp data about the query
- *@param qbind array of parameters to initialize
- *@return -1 on error
- */
-static int
-my_conv_rsa_signature (void *cls,
- const struct GNUNET_MY_QueryParam *qp,
- MYSQL_BIND *qbind)
-{
- const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data;
- void *buf;
- size_t buf_size;
-
- (void) cls;
- GNUNET_assert (1 == qp->num_params);
- buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
- &buf);
- qbind->buffer = buf;
- qbind->buffer_length = buf_size;
- qbind->buffer_type = MYSQL_TYPE_BLOB;
- return 1;
-}
-
-
-/**
- * Generate query parameter for an RSA signature. The
- * database must contain a BLOB type in the respective position
- *
- * @param x the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature
*x)
-{
- struct GNUNET_MY_QueryParam res = {
- .conv = &my_conv_rsa_signature,
- .cleaner = &my_clean_query,
- .conv_cls = NULL,
- .num_params = 1,
- .data = (x),
- .data_len = 0
- };
-
- return res;
-}
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
-{
- return GNUNET_MY_query_param_uint64 (&x->abs_value_us);
-}
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- */
-struct GNUNET_MY_QueryParam
-GNUNET_MY_query_param_absolute_time_nbo (const struct
- GNUNET_TIME_AbsoluteNBO *x)
-{
- return GNUNET_MY_query_param_auto_from_type (&x->abs_value_us__);
-}
-
-
-/* end of my_query_helper.c */
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c
deleted file mode 100644
index ceebc6f37..000000000
--- a/src/my/my_result_helper.c
+++ /dev/null
@@ -1,868 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2014, 2015, 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file my/my_result_helper.c
- * @brief functions to extract result values
- * @author Christophe Genevey
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_mysql_compat.h"
-#include "gnunet_my_lib.h"
-
-
-/**
- * extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] result mysql result
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid
- */
-static int
-pre_extract_varsize_blob (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = NULL;
- results[0].buffer_length = 0;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid
- */
-static int
-post_extract_varsize_blob (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- void *buf;
- size_t size;
-
- if (*results->is_null)
- return GNUNET_SYSERR;
- size = (size_t) rs->mysql_bind_output_length;
-
- if (rs->mysql_bind_output_length != size)
- return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
-
- buf = GNUNET_malloc (size);
-
- results[0].buffer = buf;
- results[0].buffer_length = size;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
-
- if (0 !=
- mysql_stmt_fetch_column (stmt,
- results,
- column,
- 0))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
-
- *(void **) rs->dst = buf;
- *rs->result_size = size;
-
- return GNUNET_OK;
-}
-
-
-/**
- * extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- */
-static void
-cleanup_varsize_blob (void *cls,
- struct GNUNET_MY_ResultSpec *rs)
-{
- void **ptr = (void **) rs->dst;
-
- if (NULL != *ptr)
- {
- GNUNET_free (*ptr);
- *ptr = NULL;
- }
-}
-
-
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_variable_size (void **dst,
- size_t *ptr_size)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_varsize_blob,
- .post_conv = &post_extract_varsize_blob,
- .cleaner = &cleanup_varsize_blob,
- .dst = (void *) (dst),
- .result_size = ptr_size,
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
- */
-static int
-pre_extract_fixed_blob (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = rs->dst;
- results[0].buffer_length = rs->dst_size;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Check size of extracted fixed size data from a Mysql database @a
- * result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL)
- */
-static int
-post_extract_fixed_blob (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- if (*results->is_null)
- return GNUNET_SYSERR;
- if (rs->dst_size != rs->mysql_bind_output_length)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-
-/**
- * Fixed-size result expected.
- *
- * @param name name of the field in the table
- * @param[out] dst where to store the result
- * @param ptr_size number of bytes in @a dst
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_fixed_size (void *ptr,
- size_t ptr_size)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_fixed_blob,
- .post_conv = &post_extract_fixed_blob,
- .cleaner = NULL,
- .dst = (void *) (ptr),
- .dst_size = ptr_size,
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-pre_extract_rsa_public_key (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = NULL;
- results[0].buffer_length = 0;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Check size of extracted fixed size data from a Mysql database @a
- * result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-post_extract_rsa_public_key (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-
-{
- struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
- void *buf;
- size_t size;
-
- if (*results->is_null)
- return GNUNET_SYSERR;
- size = (size_t) rs->mysql_bind_output_length;
-
- if (rs->mysql_bind_output_length != size)
- return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
- buf = GNUNET_malloc (size);
-
- results[0].buffer = buf;
- results[0].buffer_length = size;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- if (0 !=
- mysql_stmt_fetch_column (stmt,
- results,
- column,
- 0))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
-
- *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
- size);
- GNUNET_free (buf);
- if (NULL == *pk)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Results contains bogus public key value (fail to decode)\n");
- return GNUNET_SYSERR;
- }
-
- return GNUNET_OK;
-}
-
-
-/**
- * Function called to clean up memory allocated
- * by a #GNUNET_MY_ResultConverter.
- *
- * @param cls closure
- * @param rs result data to clean up
- */
-static void
-clean_rsa_public_key (void *cls,
- struct GNUNET_MY_ResultSpec *rs)
-{
- struct GNUNET_CRYPTO_RsaPublicKey **pk = rs->dst;
-
- if (NULL != *pk)
- {
- GNUNET_CRYPTO_rsa_public_key_free (*pk);
- *pk = NULL;
- }
-}
-
-
-/**
- * RSA public key expected
- *
- * @param name name of the field in the table
- * @param[out] rsa where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_rsa_public_key,
- .post_conv = &post_extract_rsa_public_key,
- .cleaner = &clean_rsa_public_key,
- .dst = (void *) rsa,
- .dst_size = 0,
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a Mysql database @a result at row @a row.
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-pre_extract_rsa_signature (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = 0;
- results[0].buffer_length = 0;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Extract data from a Mysql database @a result at row @a row.
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-post_extract_rsa_signature (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
- void *buf;
- size_t size;
-
- if (*results->is_null)
- return GNUNET_SYSERR;
- size = (size_t) rs->mysql_bind_output_length;
-
- if (rs->mysql_bind_output_length != size)
- return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */
- buf = GNUNET_malloc (size);
-
- results[0].buffer = buf;
- results[0].buffer_length = size;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- if (0 !=
- mysql_stmt_fetch_column (stmt,
- results,
- column,
- 0))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
-
- *sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
- size);
- GNUNET_free (buf);
- if (NULL == *sig)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Resuls contains bogus signature value (fails to decode)\n");
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Function called to clean up memory allocated
- * by a #GNUNET_MY_ResultConverter.
- *
- * @param cls closure
- * @param rd result data to clean up
- */
-static void
-clean_rsa_signature (void *cls,
- struct GNUNET_MY_ResultSpec *rs)
-{
- struct GNUNET_CRYPTO_RsaSignature **sig = rs->dst;
-
- if (NULL != *sig)
- {
- GNUNET_CRYPTO_rsa_signature_free (*sig);
- *sig = NULL;
- }
-}
-
-
-/**
- * RSA signature expected.
- *
- * @param[out] sig where to store the result;
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_rsa_signature,
- .post_conv = &post_extract_rsa_signature,
- .cleaner = &clean_rsa_signature,
- .dst = (void *) sig,
- .dst_size = 0,
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a Mysql database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
- */
-static int
-pre_extract_string (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = NULL;
- results[0].buffer_length = 0;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Check size of extracted fixed size data from a Mysql database
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non existing field or NULL)
- */
-static int
-post_extract_string (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- size_t size = (size_t) rs->mysql_bind_output_length;
- char *buf;
-
- if (rs->mysql_bind_output_length != size)
- return GNUNET_SYSERR;
- if (*results->is_null)
- {
- *(void **) rs->dst = NULL;
- return GNUNET_OK;
- }
-
- buf = GNUNET_malloc (size);
- results[0].buffer = buf;
- results[0].buffer_length = size;
- results[0].buffer_type = MYSQL_TYPE_BLOB;
-
- if (0 !=
- mysql_stmt_fetch_column (stmt,
- results,
- column,
- 0))
- {
- GNUNET_free (buf);
- return GNUNET_SYSERR;
- }
- buf[size] = '\0';
- *(void **) rs->dst = buf;
- return GNUNET_OK;
-}
-
-
-/**
- * 0- terminated string exprected.
- *
- * @param[out] dst where to store the result, allocated
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_string (char **dst)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_string,
- .post_conv = &post_extract_string,
- .cleaner = NULL,
- .dst = (void *) dst,
- .dst_size = 0,
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Absolute time expected
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
-{
- return GNUNET_MY_result_spec_uint64 (&at->abs_value_us);
-}
-
-
-/**
- * Absolute time in network byte order expected
- *
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
-{
- struct GNUNET_MY_ResultSpec res =
- GNUNET_MY_result_spec_auto_from_type (&at->abs_value_us__);
-
- return res;
-}
-
-
-/**
- * Extract data from a Postgres database @a result at row @a row.
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-pre_extract_uint16 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = rs->dst;
- results[0].buffer_length = rs->dst_size;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_SHORT;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Check size of extracted fixed size data from a Mysql database.
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-post_extract_uint16 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- if (rs->dst_size != rs->mysql_bind_output_length)
- return GNUNET_SYSERR;
- if (*results->is_null)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-
-/**
- * uint16_t expected
- *
- * @param[out] u16 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint16 (uint16_t *u16)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_uint16,
- .post_conv = &post_extract_uint16,
- .cleaner = NULL,
- .dst = (void *) u16,
- .dst_size = sizeof(*u16),
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a MYSQL database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-pre_extract_uint32 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- results[0].buffer = rs->dst;
- results[0].buffer_length = rs->dst_size;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_LONG;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Extract data from a MYSQL database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-post_extract_uint32 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- if (rs->dst_size != rs->mysql_bind_output_length)
- return GNUNET_SYSERR;
- if (*results->is_null)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-
-/**
- * uint32_t expected
- *
- * @param[out] u32 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint32 (uint32_t *u32)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_uint32,
- .post_conv = &post_extract_uint32,
- .cleaner = NULL,
- .dst = (void *) u32,
- .dst_size = sizeof(*u32),
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/**
- * Extract data from a MYSQL database @a result at row @a row
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-pre_extract_uint64 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- if (sizeof(uint64_t) != rs->dst_size)
- return GNUNET_SYSERR;
- results[0].buffer = rs->dst;
- results[0].buffer_length = rs->dst_size;
- results[0].length = &rs->mysql_bind_output_length;
- results[0].buffer_type = MYSQL_TYPE_LONGLONG;
- results[0].is_null = &rs->is_null;
- rs->is_null = 0;
-
- return GNUNET_OK;
-}
-
-
-/**
- * Check size of extracted fixed-size data from a Mysql database
- *
- * @param cls closure
- * @param[in,out] rs
- * @param stmt the mysql statement that is being run
- * @param column the column that is being processed
- * @param[out] results
- * @return
- * #GNUNET_OK if all results could be extracted
- * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
- */
-static int
-post_extract_uint64 (void *cls,
- struct GNUNET_MY_ResultSpec *rs,
- MYSQL_STMT *stmt,
- unsigned int column,
- MYSQL_BIND *results)
-{
- if (sizeof(uint64_t) != rs->dst_size)
- return GNUNET_SYSERR;
- if (*results->is_null)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-
-/**
- * uint64_t expected.
- *
- * @param[out] u64 where to store the result
- * @return array entry for the result specification to use
- */
-struct GNUNET_MY_ResultSpec
-GNUNET_MY_result_spec_uint64 (uint64_t *u64)
-{
- struct GNUNET_MY_ResultSpec res = {
- .pre_conv = &pre_extract_uint64,
- .post_conv = &post_extract_uint64,
- .cleaner = NULL,
- .dst = (void *) u64,
- .dst_size = sizeof(*u64),
- .num_fields = 1
- };
-
- return res;
-}
-
-
-/* end of my_result_helper.c */
diff --git a/src/my/test_my.c b/src/my/test_my.c
deleted file mode 100644
index e646c0fd5..000000000
--- a/src/my/test_my.c
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2016 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file my/test_my.c
- * @brief Tests for convenience MySQL database
- * @author Christophe Genevey
- */
-#include "platform.h"
-#include <mysql/mysql.h>
-#include "gnunet_mysql_compat.h"
-#include "gnunet_my_lib.h"
-#include "gnunet_mysql_lib.h"
-#include "gnunet_util_lib.h"
-
-
-/**
- * Run actual test queries.
- *
- * @param contexte the current context of mysql
- * @return 0 on success
- */
-static int
-run_queries (struct GNUNET_MYSQL_Context *context)
-{
- struct GNUNET_CRYPTO_RsaPublicKey *pub = NULL;
- struct GNUNET_CRYPTO_RsaPublicKey *pub2 = NULL;
- struct GNUNET_CRYPTO_RsaSignature *sig = NULL;;
- struct GNUNET_CRYPTO_RsaSignature *sig2 = NULL;
- struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get ();
- struct GNUNET_TIME_Absolute abs_time2;
- struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
- struct GNUNET_TIME_Absolute forever2;
- const struct GNUNET_TIME_AbsoluteNBO abs_time_nbo =
- GNUNET_TIME_absolute_hton (abs_time);
- struct GNUNET_HashCode hc;
- struct GNUNET_HashCode hc2;
- const char msg[] = "hello";
- void *msg2 = NULL;
- size_t msg2_len;
-
- const char msg3[] = "world";
- char *msg4 = "";
-
- uint16_t u16;
- uint16_t u162;
- uint32_t u32;
- uint32_t u322;
- uint64_t u64;
- uint64_t u642;
-
- int ret;
-
- struct GNUNET_MYSQL_StatementHandle *statements_handle_insert = NULL;
- struct GNUNET_MYSQL_StatementHandle *statements_handle_select = NULL;
-
- struct GNUNET_CRYPTO_RsaPrivateKey *priv = NULL;
- struct GNUNET_HashCode hmsg;
-
- priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
- pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
- memset (&hmsg, 42, sizeof(hmsg));
- sig = GNUNET_CRYPTO_rsa_sign_fdh (priv,
- &hmsg);
- u16 = 16;
- u32 = 32;
- u64 = UINT64_MAX;
-
- memset (&hc, 0, sizeof(hc));
- memset (&hc2, 0, sizeof(hc2));
-
- statements_handle_insert
- = GNUNET_MYSQL_statement_prepare (context,
- "INSERT INTO test_my2 ("
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",abs_time_nbo"
- ",hash"
- ",vsize"
- ",str"
- ",u16"
- ",u32"
- ",u64"
- ") VALUES "
- "( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
-
- if (NULL == statements_handle_insert)
- {
- fprintf (stderr, "Failed to prepared statement INSERT\n");
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
- return 1;
- }
-
- struct GNUNET_MY_QueryParam params_insert[] = {
- GNUNET_MY_query_param_rsa_public_key (pub),
- GNUNET_MY_query_param_rsa_signature (sig),
- GNUNET_MY_query_param_absolute_time (&abs_time),
- GNUNET_MY_query_param_absolute_time (&forever),
- GNUNET_MY_query_param_absolute_time_nbo (&abs_time_nbo),
- GNUNET_MY_query_param_auto_from_type (&hc),
- GNUNET_MY_query_param_fixed_size (msg, strlen (msg)),
- GNUNET_MY_query_param_string (msg3),
- GNUNET_MY_query_param_uint16 (&u16),
- GNUNET_MY_query_param_uint32 (&u32),
- GNUNET_MY_query_param_uint64 (&u64),
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK != GNUNET_MY_exec_prepared (context,
- statements_handle_insert,
- params_insert))
- {
- fprintf (stderr, "Failed to execute prepared statement INSERT\n");
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
- return 1;
- }
-
- statements_handle_select
- = GNUNET_MYSQL_statement_prepare (context,
- "SELECT"
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",hash"
- ",vsize"
- ",str"
- ",u16"
- ",u32"
- ",u64"
- " FROM test_my2");
-
- if (NULL == statements_handle_select)
- {
- fprintf (stderr, "Failed to prepared statement SELECT\n");
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
- return 1;
- }
-
- struct GNUNET_MY_QueryParam params_select[] = {
- GNUNET_MY_query_param_end
- };
-
- if (GNUNET_OK != GNUNET_MY_exec_prepared (context,
- statements_handle_select,
- params_select))
- {
- fprintf (stderr, "Failed to execute prepared statement SELECT\n");
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
- return 1;
- }
-
- struct GNUNET_MY_ResultSpec results_select[] = {
- GNUNET_MY_result_spec_rsa_public_key (&pub2),
- GNUNET_MY_result_spec_rsa_signature (&sig2),
- GNUNET_MY_result_spec_absolute_time (&abs_time2),
- GNUNET_MY_result_spec_absolute_time (&forever2),
- GNUNET_MY_result_spec_auto_from_type (&hc2),
- GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len),
- GNUNET_MY_result_spec_string (&msg4),
- GNUNET_MY_result_spec_uint16 (&u162),
- GNUNET_MY_result_spec_uint32 (&u322),
- GNUNET_MY_result_spec_uint64 (&u642),
- GNUNET_MY_result_spec_end
- };
-
- ret = GNUNET_MY_extract_result (statements_handle_select,
- results_select);
-
- GNUNET_assert (GNUNET_YES == ret);
- GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us);
- GNUNET_break (forever.abs_value_us == forever2.abs_value_us);
- GNUNET_break (0 ==
- memcmp (&hc,
- &hc2,
- sizeof(struct GNUNET_HashCode)));
-
- GNUNET_assert (NULL != sig2);
- GNUNET_assert (NULL != pub2);
- GNUNET_break (0 ==
- GNUNET_CRYPTO_rsa_signature_cmp (sig,
- sig2));
- GNUNET_break (0 ==
- GNUNET_CRYPTO_rsa_public_key_cmp (pub,
- pub2));
-
- GNUNET_break (strlen (msg) == msg2_len);
- GNUNET_break (0 ==
- strncmp (msg,
- msg2,
- msg2_len));
-
- GNUNET_break (strlen (msg3) == strlen (msg4));
- GNUNET_break (0 ==
- strcmp (msg3,
- msg4));
-
- GNUNET_break (16 == u162);
- GNUNET_break (32 == u322);
- GNUNET_break (UINT64_MAX == u642);
-
- GNUNET_MY_cleanup_result (results_select);
-
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
-
- if (GNUNET_OK != ret)
- return 1;
-
- return 0;
-}
-
-
-int
-main (int argc, const char *const argv[])
-{
- struct GNUNET_CONFIGURATION_Handle *config;
- struct GNUNET_MYSQL_Context *context;
- int ret;
-
- GNUNET_log_setup ("test-my",
- "WARNING",
- NULL);
-
- config = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse (config, "test_my.conf"))
- {
- fprintf (stderr, "Failed to parse configuration\n");
- return 1;
- }
-
- context = GNUNET_MYSQL_context_create (config,
- "datastore-mysql");
- if (NULL == context)
- {
- fprintf (stderr, "Failed to connect to database\n");
- return 77;
- }
-
- (void) GNUNET_MYSQL_statement_run (context,
- "DROP TABLE test_my2;");
-
- if (GNUNET_OK !=
- GNUNET_MYSQL_statement_run (context,
- "CREATE TABLE IF NOT EXISTS test_my2("
- " pub BLOB NOT NULL"
- ",sig BLOB NOT NULL"
- ",abs_time BIGINT NOT NULL"
- ",forever BIGINT NOT NULL"
- ",abs_time_nbo BIGINT NOT NULL"
- ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)"
- ",vsize BLOB NOT NULL"
- ",str BLOB NOT NULL"
- ",u16 SMALLINT NOT NULL"
- ",u32 INT NOT NULL"
- ",u64 BIGINT NOT NULL"
- ")"))
- {
- fprintf (stderr,
- "Failed to create table. Database likely not setup correctly.\n");
- GNUNET_MYSQL_statements_invalidate (context);
- GNUNET_MYSQL_context_destroy (context);
-
- return 77;
- }
-
- ret = run_queries (context);
-
- GNUNET_MYSQL_context_destroy (context);
- GNUNET_free (config);
-
- return ret;
-}
diff --git a/src/my/test_my.conf b/src/my/test_my.conf
deleted file mode 100644
index e69de29bb..000000000
diff --git a/src/mysql/Makefile.am b/src/mysql/Makefile.am
deleted file mode 100644
index 3bfb929cd..000000000
--- a/src/mysql/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
-
-if USE_COVERAGE
- AM_CFLAGS = --coverage
-endif
-
-if HAVE_MYSQL
-lib_LTLIBRARIES = libgnunetmysql.la
-endif
-
-libgnunetmysql_la_SOURCES = \
- mysql.c
-libgnunetmysql_la_LIBADD = $(MYSQL_LDFLAGS) -lmysqlclient \
- $(top_builddir)/src/util/libgnunetutil.la
-libgnunetmysql_la_LDFLAGS = \
- $(GN_LIB_LDFLAGS) \
- -version-info 0:0:0
diff --git a/src/mysql/meson.build b/src/mysql/meson.build
deleted file mode 100644
index 1464fc45e..000000000
--- a/src/mysql/meson.build
+++ /dev/null
@@ -1,13 +0,0 @@
-libgnunetmysq_src = ['mysql.c']
-
-if get_option('monolith') == false
- libgnunetmysq = library('gnunetmysq',
- libgnunetmysq_src,
- dependencies: [libgnunetutil_dep, my_dep],
- include_directories: [incdir, configuration_inc])
- libgnunetmysq_dep = declare_dependency(link_with : libgnunetmysq)
-else
- foreach p : libgnunetmysq_src
- gnunet_src += 'mysql/' + p
- endforeach
-endif
diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c
deleted file mode 100644
index 056c2f07f..000000000
--- a/src/mysql/mysql.c
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2012 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file mysql/mysql.c
- * @brief library to help with access to a MySQL database
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <mysql/mysql.h>
-#include "gnunet_mysql_lib.h"
-#include "gnunet_mysql_compat.h"
-
-/**
- * Maximum number of supported parameters for a prepared
- * statement. Increase if needed.
- */
-#define MAX_PARAM 16
-
-
-/**
- * Die with an error message that indicates
- * a failure of the command 'cmd' with the message given
- * by strerror(errno).
- */
-#define DIE_MYSQL(cmd, dbh) \
- do \
- { \
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, \
- "mysql", \
- _ ("`%s' failed at %s:%d with error: %s\n"), \
- cmd, \
- __FILE__, \
- __LINE__, \
- mysql_error ((dbh)->dbf)); \
- GNUNET_assert (0); \
- } while (0);
-
-/**
- * Log an error message at log-level 'level' that indicates
- * a failure of the command 'cmd' on file 'filename'
- * with the message given by strerror(errno).
- */
-#define LOG_MYSQL(level, cmd, dbh) \
- do \
- { \
- GNUNET_log_from (level, \
- "mysql", \
- _ ("`%s' failed at %s:%d with error: %s\n"), \
- cmd, \
- __FILE__, \
- __LINE__, \
- mysql_error ((dbh)->dbf)); \
- } while (0);
-
-
-/**
- * Mysql context.
- */
-struct GNUNET_MYSQL_Context
-{
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Our section.
- */
- const char *section;
-
- /**
- * Handle to the mysql database.
- */
- MYSQL *dbf;
-
- /**
- * Head of list of our prepared statements.
- */
- struct GNUNET_MYSQL_StatementHandle *shead;
-
- /**
- * Tail of list of our prepared statements.
- */
- struct GNUNET_MYSQL_StatementHandle *stail;
-
- /**
- * Filename of "my.cnf" (msyql configuration).
- */
- char *cnffile;
-};
-
-
-/**
- * Handle for a prepared statement.
- */
-struct GNUNET_MYSQL_StatementHandle
-{
- /**
- * Kept in a DLL.
- */
- struct GNUNET_MYSQL_StatementHandle *next;
-
- /**
- * Kept in a DLL.
- */
- struct GNUNET_MYSQL_StatementHandle *prev;
-
- /**
- * Mysql Context the statement handle belongs to.
- */
- struct GNUNET_MYSQL_Context *mc;
-
- /**
- * Original query string.
- */
- char *query;
-
- /**
- * Handle to MySQL prepared statement.
- */
- MYSQL_STMT *statement;
-
- /**
- * Is the MySQL prepared statement valid, or do we need to re-initialize it?
- */
- int valid;
-};
-
-
-/**
- * Obtain the location of ".my.cnf".
- *
- * @param cfg our configuration
- * @param section the section
- * @return NULL on error
- */
-static char *
-get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
-{
- char *cnffile;
- char *home_dir;
- struct stat st;
-
- struct passwd *pw;
-
- int configured;
-
- pw = getpwuid (getuid ());
- if (! pw)
- {
- GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid");
- return NULL;
- }
- if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- section,
- "CONFIG",
- &cnffile));
- configured = GNUNET_YES;
- }
- else
- {
- home_dir = GNUNET_strdup (pw->pw_dir);
- GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
- GNUNET_free (home_dir);
- configured = GNUNET_NO;
- }
-
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
- "mysql",
- _ ("Trying to use file `%s' for MySQL configuration.\n"),
- cnffile);
- if ((0 != stat (cnffile, &st)) || (0 != access (cnffile, R_OK)) ||
- (! S_ISREG (st.st_mode)))
- {
- if (configured == GNUNET_YES)
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "mysql",
- _ ("Could not access file `%s': %s\n"),
- cnffile,
- strerror (errno));
- GNUNET_free (cnffile);
- return NULL;
- }
- return cnffile;
-}
-
-
-/**
- * Open the connection with the database (and initialize
- * our default options).
- *
- * @param mc database context to initialize
- * @return #GNUNET_OK on success
- */
-static int
-iopen (struct GNUNET_MYSQL_Context *mc)
-{
- char *mysql_dbname;
- char *mysql_server;
- char *mysql_user;
- char *mysql_password;
- unsigned long long mysql_port;
- MYSQL_BOOL reconnect;
- unsigned int timeout;
-
- mc->dbf = mysql_init (NULL);
- if (mc->dbf == NULL)
- return GNUNET_SYSERR;
- if (mc->cnffile != NULL)
- mysql_options (mc->dbf, MYSQL_READ_DEFAULT_FILE, mc->cnffile);
- mysql_options (mc->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
- reconnect = 0;
- mysql_options (mc->dbf, MYSQL_OPT_RECONNECT, &reconnect);
- mysql_options (mc->dbf, MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
- mysql_options (mc->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
- timeout = 60; /* in seconds */
- mysql_options (mc->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
- mysql_options (mc->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
- mysql_dbname = NULL;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "DATABASE"))
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mc->cfg,
- mc->section,
- "DATABASE",
- &mysql_dbname));
- else
- mysql_dbname = GNUNET_strdup ("gnunet");
- mysql_user = NULL;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "USER"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mc->cfg,
- mc->section,
- "USER",
- &mysql_user));
- }
- mysql_password = NULL;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PASSWORD"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mc->cfg,
- mc->section,
- "PASSWORD",
- &mysql_password));
- }
- mysql_server = NULL;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "HOST"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mc->cfg,
- mc->section,
- "HOST",
- &mysql_server));
- }
- mysql_port = 0;
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (mc->cfg, mc->section, "PORT"))
- {
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (mc->cfg,
- mc->section,
- "PORT",
- &mysql_port));
- }
-
- GNUNET_assert (mysql_dbname != NULL);
- mysql_real_connect (mc->dbf,
- mysql_server,
- mysql_user,
- mysql_password,
- mysql_dbname,
- (unsigned int) mysql_port,
- NULL,
- CLIENT_IGNORE_SIGPIPE);
- GNUNET_free (mysql_server);
- GNUNET_free (mysql_user);
- GNUNET_free (mysql_password);
- GNUNET_free (mysql_dbname);
- if (mysql_error (mc->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", mc);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Create a mysql context.
- *
- * @param cfg configuration
- * @param section configuration section to use to get MySQL configuration
options
- * @return the mysql context
- */
-struct GNUNET_MYSQL_Context *
-GNUNET_MYSQL_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section)
-{
- struct GNUNET_MYSQL_Context *mc;
-
- mc = GNUNET_new (struct GNUNET_MYSQL_Context);
- mc->cfg = cfg;
- mc->section = section;
- mc->cnffile = get_my_cnf_path (cfg, section);
-
- return mc;
-}
-
-
-/**
- * Close database connection and all prepared statements (we got a DB
- * error).
- *
- * @param mc mysql context
- */
-void
-GNUNET_MYSQL_statements_invalidate (struct GNUNET_MYSQL_Context *mc)
-{
- struct GNUNET_MYSQL_StatementHandle *sh;
-
- for (sh = mc->shead; NULL != sh; sh = sh->next)
- {
- if (GNUNET_YES == sh->valid)
- {
- mysql_stmt_close (sh->statement);
- sh->valid = GNUNET_NO;
- }
- sh->statement = NULL;
- }
- if (NULL != mc->dbf)
- {
- mysql_close (mc->dbf);
- mc->dbf = NULL;
- }
-}
-
-
-/**
- * Destroy a mysql context. Also frees all associated prepared statements.
- *
- * @param mc context to destroy
- */
-void
-GNUNET_MYSQL_context_destroy (struct GNUNET_MYSQL_Context *mc)
-{
- struct GNUNET_MYSQL_StatementHandle *sh;
-
- GNUNET_MYSQL_statements_invalidate (mc);
- while (NULL != (sh = mc->shead))
- {
- GNUNET_CONTAINER_DLL_remove (mc->shead, mc->stail, sh);
- GNUNET_free (sh->query);
- GNUNET_free (sh);
- }
- GNUNET_free (mc);
- mysql_library_end ();
-}
-
-
-/**
- * Prepare a statement. Prepared statements are automatically discarded
- * when the MySQL context is destroyed.
- *
- * @param mc mysql context
- * @param query query text
- * @return prepared statement, NULL on error
- */
-struct GNUNET_MYSQL_StatementHandle *
-GNUNET_MYSQL_statement_prepare (struct GNUNET_MYSQL_Context *mc,
- const char *query)
-{
- struct GNUNET_MYSQL_StatementHandle *sh;
-
- sh = GNUNET_new (struct GNUNET_MYSQL_StatementHandle);
- sh->mc = mc;
- sh->query = GNUNET_strdup (query);
- GNUNET_CONTAINER_DLL_insert (mc->shead, mc->stail, sh);
- return sh;
-}
-
-
-/**
- * Run a SQL statement.
- *
- * @param mc mysql context
- * @param sql SQL statement to run
- * @return #GNUNET_OK on success
- * #GNUNET_SYSERR if there was a problem
- */
-int
-GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql)
-{
- if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
- return GNUNET_SYSERR;
- mysql_query (mc->dbf, sql);
- if (mysql_error (mc->dbf)[0])
- {
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc);
- GNUNET_MYSQL_statements_invalidate (mc);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Prepare a statement for running.
- *
- * @param sh statement handle to prepare
- * @return #GNUNET_OK on success
- */
-static int
-prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh)
-{
- struct GNUNET_MYSQL_Context *mc = sh->mc;
-
- if (GNUNET_YES == sh->valid)
- return GNUNET_OK;
- if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc)))
- return GNUNET_SYSERR;
- sh->statement = mysql_stmt_init (mc->dbf);
- if (NULL == sh->statement)
- {
- GNUNET_MYSQL_statements_invalidate (mc);
- return GNUNET_SYSERR;
- }
- if (0 != mysql_stmt_prepare (sh->statement, sh->query, strlen (sh->query)))
- {
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
- "mysql",
- "prepare_statement: %s\n",
- sh->query);
- LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", mc);
- mysql_stmt_close (sh->statement);
- sh->statement = NULL;
- GNUNET_MYSQL_statements_invalidate (mc);
- return GNUNET_SYSERR;
- }
- sh->valid = GNUNET_YES;
- return GNUNET_OK;
-}
-
-
-/**
- * Get internal handle for a prepared statement. This function should rarely
- * be used, and if, with caution! On failures during the interaction with
- * the handle, you must call 'GNUNET_MYSQL_statements_invalidate'!
- *
- * @param sh prepared statement to introspect
- * @return MySQL statement handle, NULL on error
- */
-MYSQL_STMT *
-GNUNET_MYSQL_statement_get_stmt (struct GNUNET_MYSQL_StatementHandle *sh)
-{
- (void) prepare_statement (sh);
- return sh->statement;
-}
-
-
-/* end of mysql.c */
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index a6c9c0903..b7d14bc41 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -78,21 +78,20 @@ libgnunet_plugin_block_regex_la_LDFLAGS = \
$(GN_LIBINTL) \
$(GN_PLUGIN_LDFLAGS)
-if HAVE_MYSQL
-noinst_mysql_progs = \
- gnunet-regex-simulation-profiler
-
-gnunet_regex_simulation_profiler_SOURCES = \
- $(REGEX_INTERNAL) gnunet-regex-simulation-profiler.c
-gnunet_regex_simulation_profiler_LDADD = \
- libgnunetregexblock.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/dht/libgnunetdht.la \
- $(top_builddir)/src/my/libgnunetmy.la \
- $(top_builddir)/src/mysql/libgnunetmysql.la \
- $(top_builddir)/src/block/libgnunetblock.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la
-endif
+# FIXME we phased out mysql. If we want to keep, needs rewrite
+#if HAVE_MYSQL
+#noinst_mysql_progs = \
+# gnunet-regex-simulation-profiler
+
+#gnunet_regex_simulation_profiler_SOURCES = \
+# $(REGEX_INTERNAL) gnunet-regex-simulation-profiler.c
+#gnunet_regex_simulation_profiler_LDADD = \
+# libgnunetregexblock.la \
+# $(top_builddir)/src/util/libgnunetutil.la \
+# $(top_builddir)/src/dht/libgnunetdht.la \
+# $(top_builddir)/src/block/libgnunetblock.la \
+# $(top_builddir)/src/statistics/libgnunetstatistics.la
+#endif
noinst_PROGRAMS = $(noinst_mysql_progs) \
perf-regex \
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: MYSQL: phase out,
gnunet <=