gnunet-svn
[Top][All Lists]
Advanced

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

[taler-donau] branch master updated: added post receipt


From: gnunet
Subject: [taler-donau] branch master updated: added post receipt
Date: Sun, 14 Jan 2024 22:02:14 +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 90c9a22  added post receipt
     new 939058c  Merge branch 'master' of ssh://git.taler.net/donau
90c9a22 is described below

commit 90c9a223b539ca534d501dfc26cc5f0debbd239a
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
AuthorDate: Sun Jan 14 22:01:17 2024 +0100

    added post receipt
---
 src/donau/Makefile.am                       |   1 +
 src/donau/donau-httpd_get-history-entry.c   |   7 +-
 src/donau/donau-httpd_post-submit-receipt.c | 155 ++++++++++++++++++++++++++++
 src/donau/donau-httpd_receipt.h             |  41 ++++++++
 src/donaudb/pg_insert_submitted_receipt.c   |   8 +-
 src/donaudb/pg_insert_submitted_receipt.h   |   8 +-
 src/include/donau_service.h                 |  20 +---
 src/include/donaudb_plugin.h                |   2 +-
 8 files changed, 215 insertions(+), 27 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am
index 9cad482..72a3d37 100644
--- a/src/donau/Makefile.am
+++ b/src/donau/Makefile.am
@@ -46,6 +46,7 @@ donau_httpd_SOURCES = \
   donau-httpd_get-charity.c donau-httpd_post-charity.c \
   donau-httpd_get-history-entry.c donau-httpd_history.h \
   donau-httpd_get-history.c \
+  donau-httpd_post-submit-receipt.c donau_httpd_receipt.h \
   donau-httpd_terms.c donau-httpd_terms.h
 
 # Testcases
diff --git a/src/donau/donau-httpd_get-history-entry.c 
b/src/donau/donau-httpd_get-history-entry.c
index fedbd1b..b8eea04 100644
--- a/src/donau/donau-httpd_get-history-entry.c
+++ b/src/donau/donau-httpd_get-history-entry.c
@@ -68,8 +68,8 @@ DH_handler_history_entry_get (
   }
 
   {
-    const struct TALER_Amount *final_amount;
-    const uint64_t donation_year;
+    struct TALER_Amount final_amount;
+    uint64_t donation_year;
     enum GNUNET_DB_QueryStatus qs;
     MHD_RESULT result;
 
@@ -102,11 +102,10 @@ DH_handler_history_entry_get (
       rc->connection,
       MHD_HTTP_OK,
       TALER_JSON_pack_amount ("final_amount",
-                              final_amount),
+                              &final_amount),
       GNUNET_JSON_pack_uint64 ("donation_year",
                                donation_year));
 
-    GNUNET_free (final_amount);
     return result;
   }
 }
diff --git a/src/donau/donau-httpd_post-submit-receipt.c 
b/src/donau/donau-httpd_post-submit-receipt.c
new file mode 100644
index 0000000..cfe8f4f
--- /dev/null
+++ b/src/donau/donau-httpd_post-submit-receipt.c
@@ -0,0 +1,155 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2024 Taler Systems SA
+
+  TALER 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, or (at your option) any later version.
+
+  TALER 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
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file donau-httpd_post-submit-receipt.c
+ * @brief Handle request to insert a submitted receipt.
+ * @author Johannes Casaburi
+ */
+#include "taler/platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler/taler_json_lib.h"
+#include "taler/taler_mhd_lib.h"
+#include "taler/taler_signatures.h"
+#include "donaudb_plugin.h"
+#include "donau-httpd_receipt.h"
+#include "donau-httpd_db.h"
+#include "donau-httpd_metrics.h"
+
+
+/**
+ * Closure for #insert_submitted_receipt()
+ */
+struct InsertReceiptContext
+{
+  struct DONAU_HashDonorTaxId *h_tax_number;
+  union GNUNET_CRYPTO_BlindSessionNonce *nonce;
+  struct DONAU_DonationUnitPublicKey *donation_unit_pub;
+  struct DONAU_DonauSignatureP *donau_sig;
+  uint64_t donation_year;
+};
+
+
+/**
+ * Function implementing insert submit-receipt transaction.
+ *
+ * Runs the transaction logic; IF it returns a non-error code, the
+ * transaction logic MUST NOT queue a MHD response.  IF it returns an hard
+ * error, the transaction logic MUST queue a MHD response and set @a mhd_ret.
+ * IF it returns the soft error code, the function MAY be called again to
+ * retry and MUST not queue a MHD response.
+ *
+ * @param cls closure with a `struct InsertReceiptContext`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ *             if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+insert_submitted_receipt (void *cls,
+                          struct MHD_Connection *connection,
+                          MHD_RESULT *mhd_ret)
+{
+  struct InsertReceiptContext *icc = cls;
+  enum GNUNET_DB_QueryStatus qs;
+
+  qs = DH_plugin->insert_submitted_receipt (DH_plugin->cls,
+                                            icc->h_tax_number,
+                                            icc->nonce,
+                                            icc->donation_unit_pub,
+                                            icc->donau_sig,
+                                            icc->donation_year);
+  if (qs <= 0)
+  {
+    if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
+    {
+      GNUNET_break (0);
+      *mhd_ret = TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                             TALER_EC_GENERIC_DB_STORE_FAILED,
+                                             "insert_submitted_receipt");
+      return GNUNET_DB_STATUS_HARD_ERROR;
+    }
+    return qs;
+  }
+
+  return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+MHD_RESULT
+DH_handler_submit_receipt_post (struct DH_RequestContext *rc,
+                                const json_t *root,
+                                const char *const args[])
+{
+  struct InsertReceiptContext icc;
+
+  struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_fixed_auto ("h_tax_number",
+                                 &icc.h_tax_number),
+    GNUNET_JSON_spec_fixed_auto ("nonce",
+                                 &icc.nonce),
+    GNUNET_JSON_spec_fixed_auto ("donation_unit_pub",
+                                 &icc.donation_unit_pub),
+    GNUNET_JSON_spec_fixed_auto ("donau_sig",
+                                 &icc.donau_sig),
+    GNUNET_JSON_spec_uint64 ("donation_year",
+                             &icc.donation_year),
+    GNUNET_JSON_spec_end ()
+  };
+
+  {
+    enum GNUNET_GenericReturnValue res;
+
+    res = TALER_MHD_parse_json_data (rc->connection,
+                                     root,
+                                     spec);
+    if (GNUNET_SYSERR == res)
+      return MHD_NO; /* hard failure */
+    if (GNUNET_NO == res)
+    {
+      GNUNET_break_op (0);
+      return MHD_YES; /* failure */
+    }
+  }
+
+  {
+    MHD_RESULT mhd_ret;
+
+    if (GNUNET_OK !=
+        DH_DB_run_transaction (rc->connection,
+                               "insert_submitted_receipt",
+                               DH_MT_REQUEST_OTHER,
+                               &mhd_ret,
+                               &insert_submitted_receipt,
+                               &icc))
+    {
+      return mhd_ret;
+    }
+  }
+  return TALER_MHD_reply_static (
+    rc->connection,
+    MHD_HTTP_NO_CONTENT,
+    NULL,
+    NULL,
+    0);
+}
+
+
+/* end of donau-httpd_post-submit-receipt.c */
diff --git a/src/donau/donau-httpd_receipt.h b/src/donau/donau-httpd_receipt.h
new file mode 100644
index 0000000..5d6238d
--- /dev/null
+++ b/src/donau/donau-httpd_receipt.h
@@ -0,0 +1,41 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2024 Taler Systems SA
+
+  TALER 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, or (at your option) any later version.
+
+  TALER 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
+  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file donau-httpd_receipt.h
+ * @brief Handle /submit requests
+ * @author Johannes Casaburi
+ */
+#ifndef DONAU_HTTPD_RECEIPT_H
+#define DONAU_HTTPD_RECEIPT_H
+
+#include <microhttpd.h>
+#include "donau-httpd.h"
+
+
+/**
+ * Handle a POST "/submit" request.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+DH_handler_submit_receipt_post (
+  struct DH_RequestContext *rc,
+  const json_t *root,
+  const char *const args[]);
+
+#endif
diff --git a/src/donaudb/pg_insert_submitted_receipt.c 
b/src/donaudb/pg_insert_submitted_receipt.c
index 8341710..c762bf8 100644
--- a/src/donaudb/pg_insert_submitted_receipt.c
+++ b/src/donaudb/pg_insert_submitted_receipt.c
@@ -29,9 +29,11 @@
 enum GNUNET_DB_QueryStatus
 DH_PG_insert_submitted_receipt (void *cls,
                                 const struct DONAU_HashDonorTaxId 
*h_tax_number,
-                                const union GNUNET_CRYPTO_BlindSessionNonce 
*nonce,
-                                const struct DONAU_DonationUnitPublicKey 
*donation_unit_pub,
-                                const struct TALER_DonauSignatureP *donau_sig,
+                                const union GNUNET_CRYPTO_BlindSessionNonce *
+                                nonce,
+                                const struct
+                                DONAU_DonationUnitPublicKey *donation_unit_pub,
+                                const struct DONAU_DonauSignatureP *donau_sig,
                                 const uint64_t donation_year)
 {
   struct PostgresClosure *pg = cls;
diff --git a/src/donaudb/pg_insert_submitted_receipt.h 
b/src/donaudb/pg_insert_submitted_receipt.h
index 9ff25cb..bb2eeac 100644
--- a/src/donaudb/pg_insert_submitted_receipt.h
+++ b/src/donaudb/pg_insert_submitted_receipt.h
@@ -40,9 +40,11 @@
 enum GNUNET_DB_QueryStatus
 DH_PG_insert_submitted_receipt (void *cls,
                                 const struct DONAU_HashDonorTaxId 
*h_tax_number,
-                                const union GNUNET_CRYPTO_BlindSessionNonce 
*nonce,
-                                const struct DONAU_DonationUnitPublicKey 
*donation_unit_pub,
-                                const struct TALER_DonauSignatureP *donau_sig,
+                                const union GNUNET_CRYPTO_BlindSessionNonce *
+                                nonce,
+                                const struct
+                                DONAU_DonationUnitPublicKey *donation_unit_pub,
+                                const struct DONAU_DonauSignatureP *donau_sig,
                                 const uint64_t donation_year);
 
 #endif
diff --git a/src/include/donau_service.h b/src/include/donau_service.h
index 78c8d65..34c5e94 100644
--- a/src/include/donau_service.h
+++ b/src/include/donau_service.h
@@ -129,9 +129,9 @@ struct DONAU_Keys
    */
   unsigned int num_donation_unit_keys;
 
-    /**
-   * Actual length of the @e donation_unit_keys array (size of allocation).
-   */
+  /**
+ * Actual length of the @e donation_unit_keys array (size of allocation).
+ */
   unsigned int donation_unit_keys_size;
 
   /**
@@ -551,18 +551,6 @@ struct TALER_DonationUnitSignature
 
 };
 
-/**
- * Donau signature
- */
-struct TALER_DonauSignatureP
-{
-  /**
-   * The signature
-   */
-  struct TALER_ExchangeSignatureP sig;
-
-};
-
 /**
  * Donation Receipt
  */
@@ -621,7 +609,7 @@ struct DONAU_DonorReceiptsToStatementResult
        * The donation statment for a requested year. Signature over the total 
amount,
        * the year, the unique identifier hash
        */
-      struct TALER_DonauSignatureP *sig;
+      struct DONAU_DonauSignatureP *sig;
 
     } ok;
 
diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h
index 212b10f..2744a40 100644
--- a/src/include/donaudb_plugin.h
+++ b/src/include/donaudb_plugin.h
@@ -541,7 +541,7 @@ struct DONAUDB_Plugin
     const struct DONAU_HashDonorTaxId *h_tax_number,
     const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
     const struct DONAU_DonationUnitPublicKey *donation_unit_pub,
-    const struct TALER_DonauSignatureP *donau_sig,
+    const struct DONAU_DonauSignatureP *donau_sig,
     const uint64_t donation_year);
 
   /**

-- 
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]