gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: fix db helpers


From: gnunet
Subject: [taler-donau] branch master updated: fix db helpers
Date: Mon, 18 Mar 2024 20:05:21 +0100

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

johannes-casaburi pushed a commit to branch master
in repository donau.

The following commit(s) were added to refs/heads/master by this push:
     new e9b05aa  fix db helpers
     new 9007b2b  Merge branch 'master' of ssh://git.taler.net/donau
e9b05aa is described below

commit e9b05aa69d6257fc694cf83502dfe001c5e3e676
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
AuthorDate: Mon Mar 18 20:04:04 2024 +0100

    fix db helpers
---
 src/donaudb/Makefile.am                 |   2 +-
 src/donaudb/pg_insert_donation_unit.c   |   3 +-
 src/donaudb/pg_iterate_donation_units.c |   7 +-
 src/include/Makefile.am                 |   1 +
 src/pq/Makefile.am                      |  33 ++++----
 src/pq/pq_query_helper.c                |   2 +-
 src/pq/pq_result_helper.c               | 135 ++++++++++++++++++++------------
 src/pq/test_pq.c                        |   2 +-
 8 files changed, 112 insertions(+), 73 deletions(-)

diff --git a/src/donaudb/Makefile.am b/src/donaudb/Makefile.am
index 8fdd7f6..0904ee2 100644
--- a/src/donaudb/Makefile.am
+++ b/src/donaudb/Makefile.am
@@ -95,8 +95,8 @@ libtaler_plugin_donaudb_postgres_la_SOURCES = \
 
 libtaler_plugin_donaudb_postgres_la_LIBADD = \
   $(LTLIBINTL) \
-  $(top_builddir)/src/util/libdonauutil.la \
   $(top_builddir)/src/pq/libdonaupq.la \
+  $(top_builddir)/src/util/libdonauutil.la \
   -ltalerpq \
   -ltalerutil \
   -lgnunetpq \
diff --git a/src/donaudb/pg_insert_donation_unit.c 
b/src/donaudb/pg_insert_donation_unit.c
index 3f6972e..0a329ea 100644
--- a/src/donaudb/pg_insert_donation_unit.c
+++ b/src/donaudb/pg_insert_donation_unit.c
@@ -24,6 +24,7 @@
 #include <taler/taler_pq_lib.h>
 #include "pg_insert_donation_unit.h"
 #include "pg_helper.h"
+#include "donau_pq_lib.h"
 
 
 enum GNUNET_DB_QueryStatus
@@ -37,7 +38,7 @@ DH_PG_insert_donation_unit (
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam iparams[] = {
     GNUNET_PQ_query_param_auto_from_type (h_donation_unit_pub),
-    GNUNET_PQ_query_param_auto_from_type (donation_unit_pub),
+    DONAU_PQ_query_param_donation_unit_pub (donation_unit_pub),
     GNUNET_PQ_query_param_uint64 (&validity_year),
     TALER_PQ_query_param_amount (pg->conn, value),
     GNUNET_PQ_query_param_end
diff --git a/src/donaudb/pg_iterate_donation_units.c 
b/src/donaudb/pg_iterate_donation_units.c
index 5db1e82..77f5246 100644
--- a/src/donaudb/pg_iterate_donation_units.c
+++ b/src/donaudb/pg_iterate_donation_units.c
@@ -1,6 +1,6 @@
 /*
    This file is part of TALER
-   Copyright (C) 2023 Taler Systems SA
+   Copyright (C) 2024 Taler Systems SA
 
    TALER 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
@@ -24,6 +24,7 @@
 #include <taler/taler_pq_lib.h>
 #include "pg_iterate_donation_units.h"
 #include "pg_helper.h"
+#include "donau_pq_lib.h"
 
 /**
  * Closure for #get_donation_units_cb().
@@ -71,8 +72,8 @@ iterate_donation_units_cb (void *cls,
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_auto_from_type ("h_donation_unit_pub",
                                             &h_donation_unit_pub),
-      GNUNET_PQ_result_spec_auto_from_type ("donation_unit_pub",
-                                            &donation_unit_pub),
+      DONAU_PQ_result_spec_donation_unit_pub ("donation_unit_pub",
+                                              &donation_unit_pub),
       GNUNET_PQ_result_spec_uint64 ("validity_year",
                                     &validity_year),
       TALER_PQ_result_spec_amount ("value",
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index caf16d5..5ac227a 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -7,5 +7,6 @@ talerinclude_HEADERS = \
   donaudb_lib.h \
   donaudb_plugin.h \
   donau_testing_lib.h \
+  donau_pq_lib.h \
   donau_json_lib.h 
 
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index 4fcf524..7c68eb5 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -23,19 +23,20 @@ libdonaupq_la_LDFLAGS = \
   -version-info 0:0:0 \
   -no-undefined
 
-#check_PROGRAMS= \
-# test_pq
-#
-#TESTS = \
-# $(check_PROGRAMS)
-#
-#test_pq_SOURCES = \
-#  test_pq.c
-#test_pq_LDADD = \
-#  libdonaupq.la \
-#  $(top_builddir)/src/util/libdonauutil.la  \
-#  -lgnunetpq \
-#  -lgnunetutil \
-#  -ljansson \
-#  -lpq \
-#  $(XLIB)
+check_PROGRAMS= \
+ test_pq
+
+TESTS = \
+ $(check_PROGRAMS)
+
+test_pq_SOURCES = \
+  test_pq.c
+test_pq_LDADD = \
+  libdonaupq.la \
+  $(top_builddir)/src/util/libdonauutil.la  \
+  -lgnunetpq \
+  -ltalerpq \
+  -lgnunetutil \
+  -ljansson \
+  -lpq \
+  $(XLIB)
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 2b85d90..ddd4471 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -109,7 +109,7 @@ qconv_donation_unit_pub (void *cls,
 
 
 struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_donation_unit_pub (
+DONAU_PQ_query_param_donation_unit_pub (
   const struct DONAU_DonationUnitPublicKey *donation_unit_pub)
 {
   struct GNUNET_PQ_QueryParam res = {
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 436a1e7..7aa87ac 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014-2022 Taler Systems SA
+  Copyright (C) 2024 Taler Systems SA
 
   TALER 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
@@ -16,40 +16,39 @@
 /**
  * @file pq/pq_result_helper.c
  * @brief functions to initialize parameter arrays
- * @author Christian Grothoff
+ * @author Johannes Casaburi
  */
 #include <taler/platform.h>
-//#include <gnunet/gnunet_util_lib.h>
-//#include "pq_common.h"
 #include <taler/taler_pq_lib.h>
+#include <donau_util.h>
 
 /**
  * Extract data from a Postgres database @a result at row @a row.
  *
  * @param cls closure
  * @param result where to extract data from
- * @param row row to extract data from
+ * @param row the row to extract data from
  * @param fname name (or prefix) of the fields to extract from
  * @param[in,out] dst_size where to store size of result, may be NULL
  * @param[out] dst where to store the result
  * @return
  *   #GNUNET_YES if all results could be extracted
- *   #GNUNET_NO if at least one result was NULL
- *   #GNUNET_SYSERR if a result was invalid (non-existing field)
+ *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
  */
 static enum GNUNET_GenericReturnValue
-extract_json (void *cls,
-              PGresult *result,
-              int row,
-              const char *fname,
-              size_t *dst_size,
-              void *dst)
+extract_donation_unit_pub (void *cls,
+                           PGresult *result,
+                           int row,
+                           const char *fname,
+                           size_t *dst_size,
+                           void *dst)
 {
-  json_t **j_dst = dst;
+  struct DONAU_DonationUnitPublicKey *pk = dst;
+  struct GNUNET_CRYPTO_BlindSignPublicKey *bpk;
+  size_t len;
   const char *res;
   int fnum;
-  json_error_t json_error;
-  size_t slen;
+  uint32_t be[1];
 
   (void) cls;
   (void) dst_size;
@@ -57,35 +56,73 @@ extract_json (void *cls,
                     fname);
   if (fnum < 0)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Field `%s' does not exist in result\n",
-                fname);
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
   if (PQgetisnull (result,
                    row,
                    fnum))
     return GNUNET_NO;
-  slen = PQgetlength (result,
-                      row,
-                      fnum);
-  res = (const char *) PQgetvalue (result,
-                                   row,
-                                   fnum);
-  *j_dst = json_loadb (res,
-                       slen,
-                       JSON_REJECT_DUPLICATES,
-                       &json_error);
-  if (NULL == *j_dst)
+
+  /* if a field is null, continue but
+   * remember that we now return a different result */
+  len = PQgetlength (result,
+                     row,
+                     fnum);
+  res = PQgetvalue (result,
+                    row,
+                    fnum);
+  if (len < sizeof (be))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Failed to parse JSON result for field `%s': %s (%s)\n",
-                fname,
-                json_error.text,
-                json_error.source);
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
-  return GNUNET_OK;
+  GNUNET_memcpy (be,
+                 res,
+                 sizeof (be));
+  res += sizeof (be);
+  len -= sizeof (be);
+  bpk = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+  bpk->cipher = ntohl (be[0]);
+  bpk->rc = 1;
+  switch (bpk->cipher)
+  {
+  case GNUNET_CRYPTO_BSA_INVALID:
+    break;
+  case GNUNET_CRYPTO_BSA_RSA:
+    bpk->details.rsa_public_key
+      = GNUNET_CRYPTO_rsa_public_key_decode (res,
+                                             len);
+    if (NULL == bpk->details.rsa_public_key)
+    {
+      GNUNET_break (0);
+      GNUNET_free (bpk);
+      return GNUNET_SYSERR;
+    }
+    pk->bsign_pub_key = bpk;
+    GNUNET_CRYPTO_hash (res,
+                        len,
+                        &bpk->pub_key_hash);
+    return GNUNET_OK;
+  case GNUNET_CRYPTO_BSA_CS:
+    if (sizeof (bpk->details.cs_public_key) != len)
+    {
+      GNUNET_break (0);
+      GNUNET_free (bpk);
+      return GNUNET_SYSERR;
+    }
+    GNUNET_memcpy (&bpk->details.cs_public_key,
+                   res,
+                   len);
+    pk->bsign_pub_key = bpk;
+    GNUNET_CRYPTO_hash (res,
+                        len,
+                        &bpk->pub_key_hash);
+    return GNUNET_OK;
+  }
+  GNUNET_break (0);
+  GNUNET_free (bpk);
+  return GNUNET_SYSERR;
 }
 
 
@@ -97,28 +134,26 @@ extract_json (void *cls,
  * @param rd result data to clean up
  */
 static void
-clean_json (void *cls,
-            void *rd)
+clean_donation_unit_pub (void *cls,
+                         void *rd)
 {
-  json_t **dst = rd;
+  struct DONAU_DonationUnitPublicKey *donation_unit_pub = rd;
 
   (void) cls;
-  if (NULL != *dst)
-  {
-    json_decref (*dst);
-    *dst = NULL;
-  }
+  DONAU_donation_unit_pub_free (donation_unit_pub);
 }
 
+
 struct GNUNET_PQ_ResultSpec
-TALER_PQ_result_spec_json (const char *name,
-                           json_t **jp)
+DONAU_PQ_result_spec_donation_unit_pub (const char *name,
+                                        struct DONAU_DonationUnitPublicKey *
+                                        donation_unit_pub)
 {
   struct GNUNET_PQ_ResultSpec res = {
-    .conv = &extract_json,
-    .cleaner = &clean_json,
-    .dst = (void *) jp,
-    .fname  = name
+    .conv = &extract_donation_unit_pub,
+    .cleaner = &clean_donation_unit_pub,
+    .dst = (void *) donation_unit_pub,
+    .fname = name
   };
 
   return res;
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index 5dded15..2acf331 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  (C) 2015, 2016, 2023 Taler Systems SA
+  (C) 2024 Taler Systems SA
 
   TALER 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

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]