mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpg: Avoid name spaces clash with future sqlite versions.
* g10/sqlite.c: Rename to gpgsql.c. Change function prefixes to gpgsql_. * g10/sqlite.h: Rename to gpgsql.h. * g10/tofu.c: Adjust for changes. -- We used for our own extensions symbols with an sqlite_ names prefix. This may in theory lead to duplicated symbols but more important, it is harder to understand what is from gpg and what is from libsqlite. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
006a612613
commit
b1ba460d8f
@ -74,7 +74,7 @@ trust_source = trustdb.c trustdb.h tdbdump.c tdbio.c tdbio.h
|
||||
endif
|
||||
|
||||
if USE_TOFU
|
||||
tofu_source = tofu.h tofu.c sqlite.c sqlite.h
|
||||
tofu_source = tofu.h tofu.c gpgsql.c gpgsql.h
|
||||
else
|
||||
tofu_source =
|
||||
endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* sqlite.c - SQLite helper functions.
|
||||
/* gpgsql.c - SQLite helper functions.
|
||||
* Copyright (C) 2015 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
@ -26,15 +26,15 @@
|
||||
#include "util.h"
|
||||
#include "logging.h"
|
||||
|
||||
#include "sqlite.h"
|
||||
#include "gpgsql.h"
|
||||
|
||||
/* This is a convenience function that combines sqlite3_mprintf and
|
||||
sqlite3_exec. */
|
||||
int
|
||||
sqlite3_exec_printf (sqlite3 *db,
|
||||
int (*callback)(void*,int,char**,char**), void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...)
|
||||
gpgsql_exec_printf (sqlite3 *db,
|
||||
int (*callback)(void*,int,char**,char**), void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rc;
|
||||
@ -56,12 +56,12 @@ sqlite3_exec_printf (sqlite3 *db,
|
||||
}
|
||||
|
||||
int
|
||||
sqlite3_stepx (sqlite3 *db,
|
||||
sqlite3_stmt **stmtp,
|
||||
sqlite3_stepx_callback callback,
|
||||
void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...)
|
||||
gpgsql_stepx (sqlite3 *db,
|
||||
sqlite3_stmt **stmtp,
|
||||
gpgsql_stepx_callback callback,
|
||||
void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...)
|
||||
{
|
||||
int rc;
|
||||
int err = 0;
|
||||
@ -69,7 +69,7 @@ sqlite3_stepx (sqlite3 *db,
|
||||
|
||||
va_list va;
|
||||
int args;
|
||||
enum sqlite_arg_type t;
|
||||
enum gpgsql_arg_type t;
|
||||
int i;
|
||||
|
||||
int cols;
|
||||
@ -128,7 +128,7 @@ sqlite3_stepx (sqlite3 *db,
|
||||
{
|
||||
for (i = 1; i <= args; i ++)
|
||||
{
|
||||
t = va_arg (va, enum sqlite_arg_type);
|
||||
t = va_arg (va, enum gpgsql_arg_type);
|
||||
switch (t)
|
||||
{
|
||||
case SQLITE_ARG_INT:
|
||||
@ -169,7 +169,7 @@ sqlite3_stepx (sqlite3 *db,
|
||||
}
|
||||
|
||||
}
|
||||
t = va_arg (va, enum sqlite_arg_type);
|
||||
t = va_arg (va, enum gpgsql_arg_type);
|
||||
log_assert (t == SQLITE_ARG_END);
|
||||
va_end (va);
|
||||
|
61
g10/gpgsql.h
Normal file
61
g10/gpgsql.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* gpgsql.h - SQLite helper functions.
|
||||
* Copyright (C) 2015 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* GnuPG is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GnuPG is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GNUPG_GPGSQL_H
|
||||
#define GNUPG_GPGSQL_H
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
enum gpgsql_arg_type
|
||||
{
|
||||
SQLITE_ARG_END = 0xdead001,
|
||||
SQLITE_ARG_INT,
|
||||
SQLITE_ARG_LONG_LONG,
|
||||
SQLITE_ARG_STRING,
|
||||
/* This takes two arguments: the blob as a void * and the length
|
||||
of the blob as a long long. */
|
||||
SQLITE_ARG_BLOB
|
||||
};
|
||||
|
||||
int gpgsql_exec_printf (sqlite3 *db,
|
||||
int (*callback)(void*,int,char**,char**), void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...);
|
||||
|
||||
typedef int (*gpgsql_stepx_callback) (void *cookie,
|
||||
/* number of columns. */
|
||||
int cols,
|
||||
/* columns as text. */
|
||||
char **values,
|
||||
/* column names. */
|
||||
char **names,
|
||||
/* The prepared statement so
|
||||
* that it is possible to use
|
||||
* something like
|
||||
* sqlite3_column_blob(). */
|
||||
sqlite3_stmt *statement);
|
||||
|
||||
int gpgsql_stepx (sqlite3 *db,
|
||||
sqlite3_stmt **stmtp,
|
||||
gpgsql_stepx_callback callback,
|
||||
void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...);
|
||||
|
||||
#endif /*GNUPG_GPGSQL_H*/
|
62
g10/sqlite.h
62
g10/sqlite.h
@ -1,62 +0,0 @@
|
||||
/* sqlite.h - SQLite helper functions.
|
||||
* Copyright (C) 2015 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
* GnuPG is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GnuPG is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GNUPG_SQLITE_H
|
||||
#define GNUPG_SQLITE_H
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
enum sqlite_arg_type
|
||||
{
|
||||
SQLITE_ARG_END = 0xdead001,
|
||||
SQLITE_ARG_INT,
|
||||
SQLITE_ARG_LONG_LONG,
|
||||
SQLITE_ARG_STRING,
|
||||
/* This takes two arguments: the blob as a void * and the length
|
||||
of the blob as a long long. */
|
||||
SQLITE_ARG_BLOB
|
||||
};
|
||||
|
||||
|
||||
int sqlite3_exec_printf (sqlite3 *db,
|
||||
int (*callback)(void*,int,char**,char**), void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...);
|
||||
|
||||
typedef int (*sqlite3_stepx_callback) (void *cookie,
|
||||
/* number of columns. */
|
||||
int cols,
|
||||
/* columns as text. */
|
||||
char **values,
|
||||
/* column names. */
|
||||
char **names,
|
||||
/* The prepared statement so
|
||||
that it is possible to use
|
||||
something like
|
||||
sqlite3_column_blob(). */
|
||||
sqlite3_stmt *statement);
|
||||
|
||||
int sqlite3_stepx (sqlite3 *db,
|
||||
sqlite3_stmt **stmtp,
|
||||
sqlite3_stepx_callback callback,
|
||||
void *cookie,
|
||||
char **errmsg,
|
||||
const char *sql, ...);
|
||||
|
||||
#endif
|
38
g10/tofu.c
38
g10/tofu.c
@ -39,7 +39,7 @@
|
||||
#include "ttyio.h"
|
||||
#include "trustdb.h"
|
||||
#include "mkdir_p.h"
|
||||
#include "sqlite.h"
|
||||
#include "gpgsql.h"
|
||||
#include "status.h"
|
||||
|
||||
#include "tofu.h"
|
||||
@ -262,7 +262,7 @@ begin_transaction (struct db *db, int only_batch)
|
||||
|
||||
if (batch_update && ! db->batch_update)
|
||||
{
|
||||
rc = sqlite3_stepx (db->db, &db->s.savepoint_batch,
|
||||
rc = gpgsql_stepx (db->db, &db->s.savepoint_batch,
|
||||
NULL, NULL, &err,
|
||||
"savepoint batch;", SQLITE_ARG_END);
|
||||
if (rc)
|
||||
@ -281,7 +281,7 @@ begin_transaction (struct db *db, int only_batch)
|
||||
if (only_batch)
|
||||
return 0;
|
||||
|
||||
rc = sqlite3_stepx (db->db, &db->s.savepoint_inner,
|
||||
rc = gpgsql_stepx (db->db, &db->s.savepoint_inner,
|
||||
NULL, NULL, &err,
|
||||
"savepoint inner;", SQLITE_ARG_END);
|
||||
if (rc)
|
||||
@ -316,7 +316,7 @@ end_transaction (struct db *db, int only_batch)
|
||||
{
|
||||
db->batch_update = 0;
|
||||
|
||||
rc = sqlite3_stepx (db->db, &db->s.savepoint_batch_commit,
|
||||
rc = gpgsql_stepx (db->db, &db->s.savepoint_batch_commit,
|
||||
NULL, NULL, &err,
|
||||
"release batch;", SQLITE_ARG_END);
|
||||
if (rc)
|
||||
@ -337,7 +337,7 @@ end_transaction (struct db *db, int only_batch)
|
||||
if (only_batch)
|
||||
return 0;
|
||||
|
||||
rc = sqlite3_stepx (db->db, &db->s.savepoint_inner_commit,
|
||||
rc = gpgsql_stepx (db->db, &db->s.savepoint_inner_commit,
|
||||
NULL, NULL, &err,
|
||||
"release inner;", SQLITE_ARG_END);
|
||||
if (rc)
|
||||
@ -640,7 +640,7 @@ initdb (sqlite3 *db, enum db_type type)
|
||||
* know why this occurred, we also set conflict to 0xbaddecaf.
|
||||
*/
|
||||
if (type == DB_EMAIL || type == DB_COMBINED)
|
||||
rc = sqlite3_exec_printf
|
||||
rc = gpgsql_exec_printf
|
||||
(db, NULL, NULL, &err,
|
||||
"create table bindings\n"
|
||||
" (oid INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
@ -659,7 +659,7 @@ initdb (sqlite3 *db, enum db_type type)
|
||||
|
||||
Note: since the data is split on the email address, there is no
|
||||
need to index the email column. */
|
||||
rc = sqlite3_exec_printf
|
||||
rc = gpgsql_exec_printf
|
||||
(db, NULL, NULL, &err,
|
||||
"create table bindings\n"
|
||||
" (oid INTEGER PRIMARY KEY AUTOINCREMENT,\n"
|
||||
@ -1220,7 +1220,7 @@ record_binding (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
purposes, there is no need to start a transaction or to die if
|
||||
there is a failure. */
|
||||
{
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db_email->db, &db_email->s.record_binding_get_old_policy,
|
||||
get_single_long_cb2, &policy_old, &err,
|
||||
"select policy from bindings where fingerprint = ? and email = ?",
|
||||
@ -1259,7 +1259,7 @@ record_binding (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db_email->db, &db_email->s.record_binding_update, NULL, NULL, &err,
|
||||
"insert or replace into bindings\n"
|
||||
" (oid, fingerprint, email, user_id, time, policy)\n"
|
||||
@ -1287,7 +1287,7 @@ record_binding (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
{
|
||||
log_assert (opt.tofu_db_format == TOFU_DB_SPLIT);
|
||||
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db_key->db, &db_key->s.record_binding_update2, NULL, NULL, &err,
|
||||
"insert or replace into bindings\n"
|
||||
" (oid, fingerprint, email, user_id)\n"
|
||||
@ -1520,7 +1520,7 @@ get_policy (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
(TOFU_POLICY_NONE cannot appear in the DB. Thus, if POLICY is
|
||||
still TOFU_POLICY_NONE after executing the query, then the
|
||||
result set was empty.) */
|
||||
rc = sqlite3_stepx (db->db, &db->s.get_policy_select_policy_and_conflict,
|
||||
rc = gpgsql_stepx (db->db, &db->s.get_policy_select_policy_and_conflict,
|
||||
strings_collect_cb2, &strlist, &err,
|
||||
"select policy, conflict from bindings\n"
|
||||
" where fingerprint = ? and email = ?",
|
||||
@ -1773,7 +1773,7 @@ get_trust (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
address. Note: if the binding in question is in the DB, it will
|
||||
also be returned. Thus, if the result set is empty, then this is
|
||||
a new binding. */
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db->db, &db->s.get_trust_bindings_with_this_email,
|
||||
strings_collect_cb2, &bindings_with_this_email, &err,
|
||||
"select distinct fingerprint from bindings where email = ?;",
|
||||
@ -1942,7 +1942,7 @@ get_trust (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
|
||||
if (db_key)
|
||||
{
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db_key->db, &db_key->s.get_trust_gather_other_user_ids,
|
||||
strings_collect_cb2, &other_user_ids, &err,
|
||||
opt.tofu_db_format == TOFU_DB_SPLIT
|
||||
@ -1993,7 +1993,7 @@ get_trust (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
/* XXX: When generating the statistics, do we want the time
|
||||
embedded in the signature (column 'sig_time') or the time that
|
||||
we first verified the signature (column 'time'). */
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db->db, &db->s.get_trust_gather_other_keys,
|
||||
signature_stats_collect_cb, &stats, &err,
|
||||
"select fingerprint, policy, time_ago, count(*)\n"
|
||||
@ -2223,7 +2223,7 @@ get_trust (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
if (! may_ask)
|
||||
/* If we weren't allowed to ask, also update this key as
|
||||
conflicting with itself. */
|
||||
rc = sqlite3_exec_printf
|
||||
rc = gpgsql_exec_printf
|
||||
(db->db, NULL, NULL, &err,
|
||||
"update bindings set policy = %d, conflict = %Q"
|
||||
" where email = %Q"
|
||||
@ -2231,7 +2231,7 @@ get_trust (tofu_dbs_t dbs, const char *fingerprint, const char *email,
|
||||
TOFU_POLICY_ASK, fingerprint, email, TOFU_POLICY_AUTO,
|
||||
TOFU_POLICY_ASK, fingerprint);
|
||||
else
|
||||
rc = sqlite3_exec_printf
|
||||
rc = gpgsql_exec_printf
|
||||
(db->db, NULL, NULL, &err,
|
||||
"update bindings set policy = %d, conflict = %Q"
|
||||
" where email = %Q and fingerprint != %Q and policy = %d;",
|
||||
@ -2438,7 +2438,7 @@ show_statistics (tofu_dbs_t dbs, const char *fingerprint,
|
||||
|
||||
fingerprint_pp = format_hexfingerprint (fingerprint, NULL, 0);
|
||||
|
||||
rc = sqlite3_exec_printf
|
||||
rc = gpgsql_exec_printf
|
||||
(db->db, strings_collect_cb, &strlist, &err,
|
||||
"select count (*), strftime('%%s','now') - min (signatures.time),\n"
|
||||
" strftime('%%s','now') - max (signatures.time)\n"
|
||||
@ -2731,7 +2731,7 @@ tofu_register (ctrl_t ctrl, PKT_public_key *pk, const char *user_id,
|
||||
|
||||
/* If we've already seen this signature before, then don't add
|
||||
it again. */
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db->db, &db->s.register_already_seen,
|
||||
get_single_unsigned_long_cb2, &c, &err,
|
||||
"select count (*)\n"
|
||||
@ -2781,7 +2781,7 @@ tofu_register (ctrl_t ctrl, PKT_public_key *pk, const char *user_id,
|
||||
|
||||
log_assert (c == 0);
|
||||
|
||||
rc = sqlite3_stepx
|
||||
rc = gpgsql_stepx
|
||||
(db->db, &db->s.register_insert, NULL, NULL, &err,
|
||||
"insert into signatures\n"
|
||||
" (binding, sig_digest, origin, sig_time, time)\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user