[Pkg-gnupg-commit] [gnupg2] 83/241: gpg: Change sqlite3_stepx to pass the sqlite3_stmt * to the callback.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Dec 9 20:31:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 421827424fe87855307fe3e803b42ffa02738600
Author: Neal H. Walfield <neal at g10code.com>
Date:   Thu Oct 29 09:36:36 2015 +0100

    gpg: Change sqlite3_stepx to pass the sqlite3_stmt * to the callback.
    
    * g10/sqlite.h (enum sqlite_arg_type): Add SQLITE_ARG_BLOB.
    (sqlite3_stepx_callback): New declaration.
    (sqlite3_stepx): Change the callback's type to sqlite3_stepx_callback,
    which passes an additional parameter, the sqlite3_stmt *.  Update
    users.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
---
 g10/sqlite.c | 11 +++++++++--
 g10/sqlite.h | 20 ++++++++++++++++++--
 g10/tofu.c   | 37 +++++++++++++++++++++++++++++++------
 3 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/g10/sqlite.c b/g10/sqlite.c
index da3ca96..ee7514c 100644
--- a/g10/sqlite.c
+++ b/g10/sqlite.c
@@ -59,7 +59,7 @@ sqlite3_exec_printf (sqlite3 *db,
 int
 sqlite3_stepx (sqlite3 *db,
                sqlite3_stmt **stmtp,
-               int (*callback) (void*,int,char**,char**),
+               sqlite3_stepx_callback callback,
                void *cookie,
                char **errmsg,
                const char *sql, ...)
@@ -150,6 +150,13 @@ sqlite3_stepx (sqlite3 *db,
                 err = sqlite3_bind_text (stmt, i, text, -1, SQLITE_STATIC);
                 break;
               }
+            case SQLITE_ARG_BLOB:
+              {
+                char *blob = va_arg (va, void *);
+                long long length = va_arg (va, long long);
+                err = sqlite3_bind_blob (stmt, i, blob, length, SQLITE_STATIC);
+                break;
+              }
             default:
               /* Internal error.  Likely corruption.  */
               log_fatal ("Bad value for parameter type %d.\n", t);
@@ -201,7 +208,7 @@ sqlite3_stepx (sqlite3 *db,
             }
         }
 
-      if (callback (cookie, cols, (char **) azVals, (char **) azColName))
+      if (callback (cookie, cols, (char **) azVals, (char **) azColName, stmt))
         /* A non-zero result means to abort.  */
         {
           err = SQLITE_ABORT;
diff --git a/g10/sqlite.h b/g10/sqlite.h
index 7ebe8d9..753e37a 100644
--- a/g10/sqlite.h
+++ b/g10/sqlite.h
@@ -27,7 +27,10 @@ enum sqlite_arg_type
     SQLITE_ARG_END = 0xdead001,
     SQLITE_ARG_INT,
     SQLITE_ARG_LONG_LONG,
-    SQLITE_ARG_STRING
+    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
   };
 
 
@@ -36,9 +39,22 @@ int sqlite3_exec_printf (sqlite3 *db,
                          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,
-                   int (*callback) (void*,int,char**,char**),
+                   sqlite3_stepx_callback callback,
                    void *cookie,
                    char **errmsg,
                    const char *sql, ...);
diff --git a/g10/tofu.c b/g10/tofu.c
index 905010c..6dda873 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -418,6 +418,14 @@ get_single_unsigned_long_cb (void *cookie, int argc, char **argv,
   return 0;
 }
 
+static int
+get_single_unsigned_long_cb2 (void *cookie, int argc, char **argv,
+			     char **azColName, sqlite3_stmt *stmt)
+{
+  (void) stmt;
+  return get_single_unsigned_long_cb (cookie, argc, argv, azColName);
+}
+
 /* We expect a single integer column whose name is "version".  COOKIE
    must point to an int.  This function always aborts.  On error or a
    if the version is bad, sets *VERSION to -1.  */
@@ -1050,6 +1058,13 @@ get_single_long_cb (void *cookie, int argc, char **argv, char **azColName)
   return 0;
 }
 
+static int
+get_single_long_cb2 (void *cookie, int argc, char **argv, char **azColName,
+                     sqlite3_stmt *stmt)
+{
+  (void) stmt;
+  return get_single_long_cb (cookie, argc, argv, azColName);
+}
 
 /* Record (or update) a trust policy about a (possibly new)
    binding.
@@ -1109,7 +1124,7 @@ record_binding (struct dbs *dbs, const char *fingerprint, const char *email,
     {
       rc = sqlite3_stepx
 	(db_email->db, &db_email->s.record_binding_get_old_policy,
-         get_single_long_cb, &policy_old, &err,
+         get_single_long_cb2, &policy_old, &err,
 	 "select policy from bindings where fingerprint = ? and email = ?",
 	 SQLITE_ARG_STRING, fingerprint, SQLITE_ARG_STRING, email,
          SQLITE_ARG_END);
@@ -1261,6 +1276,15 @@ strings_collect_cb (void *cookie, int argc, char **argv, char **azColName)
   return 0;
 }
 
+static int
+strings_collect_cb2 (void *cookie, int argc, char **argv, char **azColName,
+                     sqlite3_stmt *stmt)
+{
+  (void) stmt;
+  return strings_collect_cb (cookie, argc, argv, azColName);
+
+}
+
 /* Auxiliary data structure to collect statistics about
    signatures.  */
 struct signature_stats
@@ -1316,7 +1340,7 @@ signature_stats_prepend (struct signature_stats **statsp,
      <fingerprint, policy, time ago, count>.  */
 static int
 signature_stats_collect_cb (void *cookie, int argc, char **argv,
-			    char **azColName)
+			    char **azColName, sqlite3_stmt *stmt)
 {
   struct signature_stats **statsp = cookie;
   char *tail;
@@ -1326,6 +1350,7 @@ signature_stats_collect_cb (void *cookie, int argc, char **argv,
   unsigned long count;
 
   (void) azColName;
+  (void) stmt;
 
   i ++;
 
@@ -1447,7 +1472,7 @@ get_policy (struct dbs *dbs, const char *fingerprint, const char *email,
      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,
-                      strings_collect_cb, &strlist, &err,
+                      strings_collect_cb2, &strlist, &err,
                       "select policy, conflict from bindings\n"
                       " where fingerprint = ? and email = ?",
                       SQLITE_ARG_STRING, fingerprint,
@@ -1692,7 +1717,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
      a new binding.  */
   rc = sqlite3_stepx
     (db->db, &db->s.get_trust_bindings_with_this_email,
-     strings_collect_cb, &bindings_with_this_email, &err,
+     strings_collect_cb2, &bindings_with_this_email, &err,
      "select distinct fingerprint from bindings where email = ?;",
      SQLITE_ARG_STRING, email, SQLITE_ARG_END);
   if (rc)
@@ -1835,7 +1860,7 @@ get_trust (struct dbs *dbs, const char *fingerprint, const char *email,
 	{
 	  rc = sqlite3_stepx
 	    (db_key->db, &db_key->s.get_trust_gather_other_user_ids,
-             strings_collect_cb, &other_user_ids, &err,
+             strings_collect_cb2, &other_user_ids, &err,
              opt.tofu_db_format == TOFU_DB_SPLIT
 	     ? "select user_id, email from bindings where fingerprint = ?;"
 	     : "select user_id, policy from bindings where fingerprint = ?;",
@@ -2519,7 +2544,7 @@ tofu_register (const byte *fingerprint_bin, const char *user_id,
      it again.  */
   rc = sqlite3_stepx
     (db->db, &db->s.register_already_seen,
-     get_single_unsigned_long_cb, &c, &err,
+     get_single_unsigned_long_cb2, &c, &err,
      "select count (*)\n"
      " from signatures left join bindings\n"
      "  on signatures.binding = bindings.oid\n"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list