donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 6ff3a1c769589c9fcbd1c9b2abee18065a54c477
parent 95de67adc9e72b23c3e6d62c1966e0bcba411efd
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Tue, 19 Mar 2024 01:17:10 +0100

[donau] work on issue receipts

Diffstat:
Msrc/donau/Makefile.am | 3++-
Msrc/donau/donau-httpd.c | 9+++++++++
Asrc/donau/donau-httpd_batch-issue.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/donau/donau-httpd_issue-receipts.h | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/donau/donau-httpd_post-batch-issue.c | 269+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/donau/donau-httpd_post-charity.c | 4++--
Dsrc/donau/donau-httpd_post-submit-receipt.c | 155-------------------------------------------------------------------------------
Asrc/donau/donau-httpd_post-submit-receipts.c | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/donau/donau-httpd_receipt.h | 41-----------------------------------------
Asrc/donau/donau-httpd_submit-receipts.h | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/lib/donau_api_handle.c | 2+-
Asrc/testing/.donau-httpd.log.swo | 0
Asrc/testing/.donau-httpd.log.swp | 0
Msrc/testing/test_donau_api.c | 10+++++-----
Msrc/testing/testing_api_cmd_get_donau.c | 2+-
Msrc/testing/testing_api_cmd_issue_receipts.c | 3++-
16 files changed, 569 insertions(+), 207 deletions(-)

diff --git a/src/donau/Makefile.am b/src/donau/Makefile.am @@ -46,7 +46,8 @@ donau_httpd_SOURCES = \ donau-httpd_charity_delete.c \ donau-httpd_get-charity.c donau-httpd_post-charity.c \ donau-httpd_get-history.c \ - donau-httpd_post-submit-receipt.c donau_httpd_receipt.h \ + donau-httpd_post-submit-receipts.c donau_httpd_submit-receipts.h \ + donau-httpd_post-batch-issue.c donau_httpd_batch-issue.h \ donau-httpd_terms.c donau-httpd_terms.h # Testcases diff --git a/src/donau/donau-httpd.c b/src/donau/donau-httpd.c @@ -34,6 +34,7 @@ #include "donau-httpd_config.h" #include "donau-httpd_keys.h" #include "donau-httpd_charity.h" +#include "donau-httpd_batch-issue.h" #include "donau-httpd_history.h" #include "donau-httpd_terms.h" #include "donaudb_plugin.h" @@ -496,6 +497,14 @@ handle_mhd_request (void *cls, .nargs = 1, .nargs_is_upper_bound = true }, + /* POST batch issue receipts */ + { + .url = "batch-issue", + .method = MHD_HTTP_METHOD_POST, + .handler.post = &DH_handler_issue_receipts_post, + .nargs = 1, + .nargs_is_upper_bound = true + }, /** etc diff --git a/src/donau/donau-httpd_batch-issue.h b/src/donau/donau-httpd_batch-issue.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_batch-issue.h + * @brief Handle /batch-issue requests + * @author Lukas Matyja + */ +#ifndef DONAU_HTTPD_ISSUE_RECEIPTS_H +#define DONAU_HTTPD_ISSUE_RECEIPTS_H + +#include <microhttpd.h> +#include "donau-httpd.h" + + +/** + * Handle a POST "/batch-issue" request. + * + * @param connection the MHD connection to handle + * @param root uploaded JSON data + * @return MHD result code + */ +MHD_RESULT +DH_handler_issue_receipts_post ( + struct DH_RequestContext *rc, + const json_t *root, + const char *const args[]); + +#endif diff --git a/src/donau/donau-httpd_issue-receipts.h b/src/donau/donau-httpd_issue-receipts.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_batch-issue.h + * @brief Handle /batch-issue requests + * @author Lukas Matyja + */ +#ifndef DONAU_HTTPD_ISSUE_RECEIPTS_H +#define DONAU_HTTPD_ISSUE_RECEIPTS_H + +#include <microhttpd.h> +#include "donau-httpd.h" + + +/** + * Handle a POST "/batch-issue" request. + * + * @param connection the MHD connection to handle + * @param root uploaded JSON data + * @return MHD result code + */ +MHD_RESULT +DH_handler_issue_receipts_post ( + struct DH_RequestContext *rc, + const json_t *root, + const char *const args[]); + +#endif diff --git a/src/donau/donau-httpd_post-batch-issue.c b/src/donau/donau-httpd_post-batch-issue.c @@ -0,0 +1,269 @@ +/* + 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-batch-issue.c + * @brief Handle request to insert a charity. + * @author Lukas Matyja + */ +#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_charity.h" +#include "donau-httpd_db.h" +#include "donau-httpd_metrics.h" + + +/** + * Closure for #insert_charity() + */ +struct IssueReceiptsContext +{ + struct DONAU_CharityPublicKeyP charity_pub; + struct DONAU_CharitySignatureP charity_sig; + const struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp; + uint64_t year; +}; + +/** + * Parse a bkp encoded in JSON. + * + * @param[out] bkp where to return the result + * @param bkp_key_obj json to parse + * @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if @a bkp_key_obj + * is malformed. + */ +static enum GNUNET_GenericReturnValue +parse_json_bkp (struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp, + const json_t *bkp_key_obj) +{ + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_fixed_auto ("h_du_pub", + &bkp->h_donation_unit_pub), + GNUNET_JSON_spec_fixed_auto ("blinded_udi", + &bkp->blinded_udi), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (bkp_key_obj, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + +/** + * Function implementing insert charity 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 InsertCharityContext` + * @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 +//issue_receipts (void *cls, +// struct MHD_Connection *connection, +// MHD_RESULT *mhd_ret) +//{ +// struct InsertCharityContext *icc = cls; +// enum GNUNET_DB_QueryStatus qs; +// +// qs = DH_plugin->insert_charity (DH_plugin->cls, +// &icc->charity_pub, +// icc->charity_name, +// icc->charity_url, +// &icc->max_per_year, +// &icc->receipts_to_date, +// &icc->current_year, +// &icc->charity_id); +// 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_charity"); +// return GNUNET_DB_STATUS_HARD_ERROR; +// } +// return qs; +// } +// +// return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; +//} + + +MHD_RESULT +DH_handler_issue_receipts_post (struct DH_RequestContext *rc, + const json_t *root, + const char *const args[1]) +{ + unsigned long long charity_id; + char dummy; + + if ( (NULL == args[0]) || + (1 != sscanf (args[0], + "%llu%c", + &charity_id, + &dummy)) ) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "charity_id"); + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "issue receipts for charity id: %llu\n", + charity_id); + + struct IssueReceiptsContext irc; + const json_t *budikeypairs; + + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_array_const ("budikeypairs", + &budikeypairs), + GNUNET_JSON_spec_fixed_auto ("charity_sig", + &irc.charity_sig), + GNUNET_JSON_spec_uint64 ("year", + &irc.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 */ + } + } + + /* parse the budikeypairs array */ + const uint64_t num_bkp + = json_array_size (budikeypairs); + if (0 != num_bkp) + { + json_t *bkp_obj; + unsigned int index; + + struct DONAU_BlindedUniqueDonationIdentifierKeyPair *bkp = GNUNET_new_array (num_bkp, + struct DONAU_BlindedUniqueDonationIdentifierKeyPair); + json_array_foreach (budikeypairs, index, bkp_obj) { + if (GNUNET_SYSERR == + parse_json_bkp(&bkp[index], bkp_obj)) { + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "budikeypairs"); + } + } + irc.bkp = bkp; + } else { + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "budikeypairs"); + } + + /* verify charity signature */ + //TODO: Get charity pub + if (GNUNET_OK != + DONAU_charity_budi_key_pair_verify(num_bkp, &irc.bkp, + &irc.charity_pub, + &irc.charity_sig)) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error ( + rc->connection, + MHD_HTTP_FORBIDDEN, + DONAU_CHARITY_SIGNATURE_INVALID, + NULL); + } + + /* request already made? -> idempotent */ + + + /* check annual limit and change it -> Rollback if we could not save the request*/ + /* save Request (charity signature, charity id, amount, hash over bkps) and make it idempotent*/ + /* sign budis and send the signatures back */ + + +// { +// MHD_RESULT mhd_ret; +// +// if (GNUNET_OK != +// DH_DB_run_transaction (rc->connection, +// "issue_receipts", +// DH_MT_REQUEST_OTHER, +// &mhd_ret, +// &issue_receipts, +// &irc)) +// { +// return mhd_ret; +// } +// } +// +// GNUNET_log (GNUNET_ERROR_TYPE_INFO, +// "receipts were successfully issued\n"); +// +// result = TALER_MHD_REPLY_JSON_PACK ( +// rc->connection, +// MHD_HTTP_OK, +// GNUNET_JSON_pack_data_auto ("charity_pub", +// &meta.charity_pub), +// GNUNET_JSON_pack_string ("url", +// meta.charity_url), +// GNUNET_JSON_pack_string ("name", +// meta.charity_name), +// TALER_JSON_pack_amount ("max_per_year", +// &meta.max_per_year), +// TALER_JSON_pack_amount ("receipts_to_date", +// &meta.receipts_to_date), +// GNUNET_JSON_pack_uint64 ("current_year", +// meta.current_year)); + + + MHD_RESULT result; + return result; +} + + +/* end of donau-httpd_post-batch-issue.c */ diff --git a/src/donau/donau-httpd_post-charity.c b/src/donau/donau-httpd_post-charity.c @@ -152,8 +152,8 @@ DH_handler_charity_post (struct DH_RequestContext *rc, } } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "generated charity id: %lu\n", + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "generated charity id: %lu\n", icc.charity_id); return TALER_MHD_REPLY_JSON_PACK ( diff --git a/src/donau/donau-httpd_post-submit-receipt.c b/src/donau/donau-httpd_post-submit-receipt.c @@ -1,155 +0,0 @@ -/* - 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_post-submit-receipts.c b/src/donau/donau-httpd_post-submit-receipts.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-receipts.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_submit-receipts.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-receipts.c */ diff --git a/src/donau/donau-httpd_receipt.h b/src/donau/donau-httpd_receipt.h @@ -1,41 +0,0 @@ -/* - 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/donau/donau-httpd_submit-receipts.h b/src/donau/donau-httpd_submit-receipts.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_submit-receipts.h + * @brief Handle /submit requests + * @author Johannes Casaburi + */ +#ifndef DONAU_HTTPD_SUBMIT_RECEIPT_H +#define DONAU_HTTPD_SUBMIT_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/lib/donau_api_handle.c b/src/lib/donau_api_handle.c @@ -265,7 +265,7 @@ decode_keys_json (const json_t *resp_obj, const char *currency; struct GNUNET_JSON_Specification mspec[] = { GNUNET_JSON_spec_array_const ( - "sign_keys", // naming convention? + "sign_keys", &sign_keys_array), GNUNET_JSON_spec_string ( "currency", diff --git a/src/testing/.donau-httpd.log.swo b/src/testing/.donau-httpd.log.swo Binary files differ. diff --git a/src/testing/.donau-httpd.log.swp b/src/testing/.donau-httpd.log.swp Binary files differ. diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c @@ -72,7 +72,7 @@ run (void *cls, TALER_TESTING_cmd_system_start ("start-donau", config_file, "-D", - NULL), + "NULL"), TALER_TESTING_cmd_get_donau ("get-donau", cred.cfg, true), @@ -91,10 +91,10 @@ run (void *cls, TALER_TESTING_cmd_charities_get ("get-charities", &bearer, MHD_HTTP_OK), - TALER_TESTING_cmd_issue_receipts ("issue-receipts", - "post-charity", - 2024, - MHD_HTTP_CREATED), +// TALER_TESTING_cmd_issue_receipts ("issue-receipts", +// "post-charity", +// 2024, +// MHD_HTTP_CREATED), TALER_TESTING_cmd_charity_delete("delete-charity", "post-charity", // cmd trait reference &bearer, diff --git a/src/testing/testing_api_cmd_get_donau.c b/src/testing/testing_api_cmd_get_donau.c @@ -167,7 +167,7 @@ get_donau_cleanup (void *cls, } DONAU_keys_decref (ges->keys); ges->keys = NULL; - //GNUNET_free (ges->donau_url); + GNUNET_free (ges->donau_url); ges->donau_url = NULL; GNUNET_free (ges); } diff --git a/src/testing/testing_api_cmd_issue_receipts.c b/src/testing/testing_api_cmd_issue_receipts.c @@ -148,7 +148,8 @@ status_run (void *cls, ss->charity_id = (uint64_t) *(charity_id); } - // TODO: build bkps with traits from /keys request + // TODO: build bkps with traits from /keys request, use the public sign key from the + // DONAU to verify the signatures ss->birh = DONAU_charity_issue_receipt ( TALER_TESTING_interpreter_get_context (is),