commit fdc5aa79c200e8417b554f0b8ec58d0f40ed9456 parent 494fb6558b6e5c3edeb2c989e7d170498ac17226 Author: Christian Grothoff <christian@grothoff.org> Date: Sat, 27 Sep 2025 19:42:21 +0200 fix #10455 Diffstat:
19 files changed, 212 insertions(+), 248 deletions(-)
diff --git a/doc/doxygen/Makefile.in b/doc/doxygen/Makefile.in @@ -335,7 +335,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ EXTRA_DIST = \ - taler.doxy + donau.doxy all: all-am @@ -536,10 +536,10 @@ all: "\tmake full - full documentation with dependency graphs (slow)\n" \ "\tmake fast - fast mode without dependency graphs" -full: taler.doxy +full: donau.doxy doxygen $< -fast: taler.doxy +fast: donau.doxy sed 's/\(HAVE_DOT.*=\).*/\1 NO/' $< | doxygen - clean: diff --git a/src/donau/donau-httpd_charities_get.c b/src/donau/donau-httpd_charities_get.c @@ -46,8 +46,9 @@ charities_cb ( uint64_t charity_id, const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, - struct TALER_Amount max_per_year, - struct TALER_Amount receipts_to_date) + const struct TALER_Amount *max_per_year, + uint32_t current_year, + const struct TALER_Amount *receipts_to_date) { json_t *charities = cls; @@ -60,12 +61,14 @@ charities_cb ( charity_id), GNUNET_JSON_pack_data_auto ("charity_pub", charity_pub), - GNUNET_JSON_pack_string ("name", + GNUNET_JSON_pack_string ("charity_name", charity_name), TALER_JSON_pack_amount ("max_per_year", - &max_per_year), + max_per_year), + GNUNET_JSON_pack_uint64 ("current_year", + current_year), TALER_JSON_pack_amount ("receipts_to_date", - &receipts_to_date)))); + receipts_to_date)))); return GNUNET_OK; } diff --git a/src/donau/donau-httpd_charity_insert.c b/src/donau/donau-httpd_charity_insert.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2024 Taler Systems SA + Copyright (C) 2024, 2025 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 @@ -17,6 +17,7 @@ * @file donau-httpd_charity_insert.c * @brief Handle request to insert a charity. * @author Johannes Casaburi + * @author Christian Grothoff */ #include <donau_config.h> #include <gnunet/gnunet_util_lib.h> @@ -32,101 +33,29 @@ #include "donau-httpd_db.h" -/** - * Closure for #insert_charity() - */ -struct InsertCharityContext -{ - struct DONAU_CharityPublicKeyP charity_pub; - const char *charity_name; - const char *charity_url; - struct TALER_Amount max_per_year; - struct TALER_Amount receipts_to_date; - uint64_t current_year; - uint64_t charity_id; -}; - - -/** - * 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 -insert_charity (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); - switch (qs) - { - case GNUNET_DB_STATUS_SOFT_ERROR: - return qs; - case GNUNET_DB_STATUS_HARD_ERROR: - 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; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - GNUNET_break (0); - *mhd_ret = TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_DONAU_CHARITY_PUB_EXISTS, - NULL); - return GNUNET_DB_STATUS_HARD_ERROR; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - return qs; - } - GNUNET_assert (0); - return GNUNET_DB_STATUS_HARD_ERROR; -} - - MHD_RESULT DH_handler_charity_post (struct DH_RequestContext *rc, const json_t *root, const char *const args[]) { - struct InsertCharityContext icc; + struct DONAU_CharityPublicKeyP charity_pub; + const char *charity_name; + const char *charity_url; + struct TALER_Amount max_per_year; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("charity_pub", - &icc.charity_pub), + &charity_pub), GNUNET_JSON_spec_string ("charity_name", - &icc.charity_name), + &charity_name), GNUNET_JSON_spec_string ("charity_url", - &icc.charity_url), + &charity_url), TALER_JSON_spec_amount ("max_per_year", DH_currency, - &icc.max_per_year), - TALER_JSON_spec_amount ("receipts_to_date", - DH_currency, - &icc.receipts_to_date), - GNUNET_JSON_spec_uint64 ("current_year", - &icc.current_year), + &max_per_year), GNUNET_JSON_spec_end () }; + enum GNUNET_DB_QueryStatus qs; + uint64_t charity_id; (void) args; { @@ -143,30 +72,41 @@ DH_handler_charity_post (struct DH_RequestContext *rc, return MHD_YES; /* failure */ } } - + qs = DH_plugin->insert_charity (DH_plugin->cls, + &charity_pub, + charity_name, + charity_url, + &max_per_year, + &charity_id); + switch (qs) { - MHD_RESULT mhd_ret; - - if (GNUNET_OK != - DH_DB_run_transaction (rc->connection, - "insert_charity", - &mhd_ret, - &insert_charity, - &icc)) - { - return mhd_ret; - } + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert_charity"); + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "insert_charity"); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_CONFLICT, + TALER_EC_DONAU_CHARITY_PUB_EXISTS, + NULL); + return GNUNET_DB_STATUS_HARD_ERROR; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "generated charity id: %lu\n", - icc.charity_id); - return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_CREATED, GNUNET_JSON_pack_uint64 ("charity_id", - icc.charity_id)); + charity_id)); } diff --git a/src/donaudb/0002-donau_charities.sql b/src/donaudb/0002-donau_charities.sql @@ -21,7 +21,7 @@ CREATE TABLE charities ,charity_url TEXT NOT NULL ,max_per_year taler_amount NOT NULL ,receipts_to_date taler_amount NOT NULL DEFAULT (0,0) - ,current_year INT8 NOT NULL + ,current_year INT4 NOT NULL ); COMMENT ON TABLE charities IS 'Table with public keys of all recognized charities.'; diff --git a/src/donaudb/0002-donau_receipts_issued.sql b/src/donaudb/0002-donau_receipts_issued.sql @@ -16,7 +16,7 @@ CREATE TABLE receipts_issued (receipt_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE - ,blinded_sig BYTEA[] NOT nULL + ,blinded_sig BYTEA[] NOT NULL ,charity_id BIGINT NOT NULL REFERENCES charities (charity_id) ON DELETE CASCADE ,receipt_hash BYTEA PRIMARY KEY CHECK (LENGTH(receipt_hash)=64) ,amount taler_amount NOT NULL diff --git a/src/donaudb/donau_do_insert_charity.sql b/src/donaudb/donau_do_insert_charity.sql @@ -0,0 +1,62 @@ +-- +-- This file is part of TALER +-- Copyright (C) 2025 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 +-- 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 General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License along with +-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +-- + +DROP FUNCTION IF EXISTS do_insert_charity; +CREATE FUNCTION do_insert_charity ( + IN in_charity_pub BYTEA + ,IN in_charity_name TEXT + ,IN in_charity_url TEXT + ,IN in_max_per_year taler_amount + ,IN in_current_year INT4 + ,OUT out_charity_id INT8 +) +LANGUAGE plpgsql +AS $$ +BEGIN + INSERT INTO charities + (charity_pub + ,charity_name + ,charity_url + ,max_per_year + ,current_year + ) VALUES ( + in_charity_pub + ,in_charity_name + ,in_charity_url + ,in_max_per_year + ,in_current_year) + ON CONFLICT DO NOTHING + RETURNING charity_id + INTO out_charity_id; + IF NOT FOUND + THEN + SELECT charity_id + INTO out_charity_id + FROM charities + WHERE charity_pub=in_charity_pub + AND charity_url=in_charity_url + AND charity_name=in_charity_name + AND max_per_year=in_max_per_year; + IF NOT FOUND + THEN + out_charity_id = 0; + END IF; + END IF; +END $$; +COMMIT; + +COMMENT ON FUNCTION do_insert_charity + IS 'Insert a charity. Also succeeds if a charity with the same parameters already exists. If a conflicting charity exists, the out_charity_id is set to 0.'; diff --git a/src/donaudb/pg_get_charities.c b/src/donaudb/pg_get_charities.c @@ -76,7 +76,7 @@ get_charities_cb (void *cls, char *charity_name; struct TALER_Amount max_per_year; struct TALER_Amount receipts_to_date; - uint64_t current_year; + uint32_t current_year; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("charity_pub", &charity_pub), @@ -86,10 +86,10 @@ get_charities_cb (void *cls, &charity_name), TALER_PQ_RESULT_SPEC_AMOUNT ("max_per_year", &max_per_year), + GNUNET_PQ_result_spec_uint32 ("current_year", + ¤t_year), TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", &receipts_to_date), - GNUNET_PQ_result_spec_uint64 ("current_year", - ¤t_year), GNUNET_PQ_result_spec_end }; @@ -113,8 +113,9 @@ get_charities_cb (void *cls, charity_id, &charity_pub, charity_name, - max_per_year, - receipts_to_date)) + &max_per_year, + current_year, + &receipts_to_date)) break; } } diff --git a/src/donaudb/pg_insert_charity.c b/src/donaudb/pg_insert_charity.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2023 Taler Systems SA + Copyright (C) 2023--2025 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 @@ -18,6 +18,7 @@ * @brief Implementation of the insert_charity function for Postgres * @author Johannes Casaburi * @author Lukas Matyja + * @author Christian Grothoff */ #include <donau_config.h> #include <taler/taler_error_codes.h> @@ -34,44 +35,39 @@ DH_PG_insert_charity ( const char *charity_name, const char *charity_url, const struct TALER_Amount *max_per_year, - const struct TALER_Amount *receipts_to_date, - uint64_t current_year, uint64_t *charity_id) { struct PostgresClosure *pg = cls; + uint32_t current_year + = GNUNET_TIME_get_current_year (); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (charity_pub), GNUNET_PQ_query_param_string (charity_name), GNUNET_PQ_query_param_string (charity_url), TALER_PQ_query_param_amount (pg->conn, max_per_year), - TALER_PQ_query_param_amount (pg->conn, - receipts_to_date), - GNUNET_PQ_query_param_uint64 (¤t_year), + GNUNET_PQ_query_param_uint32 (¤t_year), GNUNET_PQ_query_param_end }; - struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("charity_id", charity_id), GNUNET_PQ_result_spec_end }; + enum GNUNET_DB_QueryStatus qs; PREPARE (pg, "insert_charity", - "INSERT INTO charities " - "(charity_pub" - ",charity_name" - ",charity_url" - ",max_per_year" - ",receipts_to_date" - ",current_year" - ") VALUES " - "($1, $2, $3, $4, $5, $6)" - " ON CONFLICT DO NOTHING" - " RETURNING charity_id;"); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "insert_charity", - params, - rs); + "SELECT out_charity_id AS charity_id" + " FROM do_insert_charity" + " ($1, $2, $3, $4, $5);"); + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "insert_charity", + params, + rs); + if (qs <= 0) + return qs; + if (0 == *charity_id) + return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + return qs; } diff --git a/src/donaudb/pg_insert_charity.h b/src/donaudb/pg_insert_charity.h @@ -30,11 +30,9 @@ * * @param cls closure * @param charity_pub charity public key - * @param charity_name name - * @param charity_url url + * @param charity_name charity name + * @param charity_url Web site of the charity * @param max_per_year yearly donation limit - * @param receipts_to_date current amount of donations in the current year - * @param current_year current year * @param[out] charity_id set to unique ID assigned to this charity * @return transaction status code */ @@ -45,8 +43,6 @@ DH_PG_insert_charity ( const char *charity_name, const char *charity_url, const struct TALER_Amount *max_per_year, - const struct TALER_Amount *receipts_to_date, - uint64_t current_year, uint64_t *charity_id); #endif diff --git a/src/donaudb/pg_lookup_charity.c b/src/donaudb/pg_lookup_charity.c @@ -47,7 +47,7 @@ DH_PG_lookup_charity ( &meta->max_per_year), TALER_PQ_RESULT_SPEC_AMOUNT ("receipts_to_date", &meta->receipts_to_date), - GNUNET_PQ_result_spec_uint64 ("current_year", + GNUNET_PQ_result_spec_uint32 ("current_year", &meta->current_year), GNUNET_PQ_result_spec_end }; diff --git a/src/donaudb/procedures.sql.in b/src/donaudb/procedures.sql.in @@ -21,5 +21,6 @@ SET search_path TO donau; #include "donau_do_amount_specific.sql" #include "donau_do_insert_submitted_receipts.sql" #include "donau_do_insert_issued_receipts.sql" +#include "donau_do_insert_charity.sql" COMMIT; diff --git a/src/donaudb/test_donaudb.c b/src/donaudb/test_donaudb.c @@ -79,13 +79,15 @@ charities_cb ( uint64_t charity_id, const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, - struct TALER_Amount max_per_year, - struct TALER_Amount receipts_to_date) + const struct TALER_Amount *max_per_year, + uint32_t current_year, + const struct TALER_Amount *receipts_to_date) { (void) cls; (void) charity_id; (void) charity_name; (void) max_per_year; + (void) current_year; (void) receipts_to_date; return GNUNET_OK; } @@ -155,7 +157,6 @@ run (void *cls) const char *charity_url; struct TALER_Amount max_per_year; struct TALER_Amount receipts_to_date; - uint64_t current_year; uint64_t charity_id; // Donation unit information @@ -212,7 +213,6 @@ run (void *cls) &charity_meta)); /* test insert charity */ - current_year = 2024; charity_name = "charity_name"; charity_url = "charity_url"; charities = json_array (); @@ -230,8 +230,6 @@ run (void *cls) charity_name, charity_url, &max_per_year, - &receipts_to_date, - ¤t_year, &charity_id)); /* test get charities */ diff --git a/src/include/donau_service.h b/src/include/donau_service.h @@ -1182,42 +1182,6 @@ DONAU_charity_get_cancel ( /* ********************* POST /charities/ *********************** */ /** - * add or change charity request - */ -struct DONAU_CharityRequest -{ - /** - * name of the charity - */ - const char *name; - - /** - * URL - */ - const char *charity_url; - - /** - * max donation amount per year - */ - struct TALER_Amount max_per_year; - - /** - * max donation amount per year - */ - struct TALER_Amount receipts_to_date; - - /** - * public key of the charity - */ - struct DONAU_CharityPublicKeyP charity_pub; - - /** - * current year - */ - uint64_t current_year; - -}; -/** * @brief A /charities Post Handle */ struct DONAU_CharityPostHandle; @@ -1252,7 +1216,6 @@ struct DONAU_PostCharityResponse */ uint64_t charity_id; - } ok; } details; @@ -1283,7 +1246,10 @@ typedef void * * @param ctx curl context * @param url donau base URL - * @param charity_req contains the name, public key and the max donation amount + * @param charity_name human readable name of the charity + * @param charity_url Web site of the charity + * @param max_per_year max donation amount allowed for the charity per year + * @param charity_pub public key of the charity * @param bearer for authorization * @param cb the callback to call when a reply for this request is available * @param cb_cls closure for the above callback @@ -1294,7 +1260,10 @@ struct DONAU_CharityPostHandle * DONAU_charity_post ( struct GNUNET_CURL_Context *ctx, const char *url, - struct DONAU_CharityRequest *charity_req, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year, + const struct DONAU_CharityPublicKeyP *charity_pub, const struct DONAU_BearerToken *bearer, DONAU_PostCharityResponseCallback cb, void *cb_cls); @@ -1309,8 +1278,10 @@ void DONAU_charity_post_cancel ( struct DONAU_CharityPostHandle *rgh); + /* ********************* PATCH /charities/$CHARITY_ID *********************** */ + /** * @brief A /charities/$CHARITY_ID Patch Handle */ @@ -1354,8 +1325,11 @@ typedef void * * @param ctx curl context * @param url donau base URL - * @param id of the charity - * @param charity_req contains the name, public key and the max donation amount + * @param charity_id of the charity + * @param charity_name human readable name of the charity + * @param charity_url Web site of the charity + * @param max_per_year max donation amount allowed for the charity per year + * @param charity_pub public key of the charity * @param cb the callback to call when a reply for this request is available * @param cb_cls closure for the above callback * @return a handle for this request; NULL if the inputs are invalid (i.e. @@ -1365,8 +1339,11 @@ struct DONAU_CharityPatchHandle * DONAU_charity_patch ( struct GNUNET_CURL_Context *ctx, const char *url, - const uint64_t id, - const struct DONAU_CharityRequest *charity_req, + const uint64_t charity_id, + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year, + const struct DONAU_CharityPublicKeyP *charity_pub, const struct DONAU_BearerToken *bearer, DONAU_PatchCharityResponseCallback cb, void *cb_cls); diff --git a/src/include/donau_testing_lib.h b/src/include/donau_testing_lib.h @@ -67,8 +67,6 @@ TALER_TESTING_cmd_charity_get (const char *label, * @param label the command label. * @param name of the charity * @param url of the charity - * @param max_per_year max donation receipt amount per year - * @param receipts_to_date * @param bearer authorization token * @param expected_response_code expected HTTP response code. * @return the command. @@ -78,8 +76,6 @@ TALER_TESTING_cmd_charity_post (const char *label, const char *name, const char *url, const char *max_per_year, - const char *receipts_to_date, - uint64_t current_year, const struct DONAU_BearerToken *bearer, unsigned int expected_response_code); diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -85,7 +85,7 @@ struct DONAUDB_CharityMetaData /** * Current year */ - uint64_t current_year; + uint32_t current_year; }; @@ -174,8 +174,9 @@ typedef enum GNUNET_GenericReturnValue uint64_t charity_id, const struct DONAU_CharityPublicKeyP *charity_pub, const char *charity_name, - struct TALER_Amount max_per_year, - struct TALER_Amount receipts_to_date); + const struct TALER_Amount *max_per_year, + uint32_t current_year, + const struct TALER_Amount *receipts_to_date); /** * Return history. @@ -405,12 +406,11 @@ struct DONAUDB_Plugin * * @param cls closure * @param charity_pub charity public key - * @param charity_name - * @param charity_url + * @param charity_name name of the charity + * @param charity_url Web site fo the charity * @param max_per_year yearly donation limit - * @param receipts_to_date current amount of donations in the current year - * @param current_year current year - * @param[out] charity_id set to unique ID assigned to this charity + * @param[out] charity_id set to unique ID assigned to this charity, + * set to 0 on conflict (@a charity_pub exists, but with different data) * @return database transaction status */ enum GNUNET_DB_QueryStatus @@ -420,8 +420,6 @@ struct DONAUDB_Plugin const char *charity_name, const char *charity_url, const struct TALER_Amount *max_per_year, - const struct TALER_Amount *receipts_to_date, - uint64_t current_year, uint64_t *charity_id); diff --git a/src/lib/donau_api_charities_get.c b/src/lib/donau_api_charities_get.c @@ -96,7 +96,7 @@ handle_charities_get_ok (const json_t *resp_obj, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_uint64 ("charity_id", &charities[index].charity_id), - GNUNET_JSON_spec_string ("name", + GNUNET_JSON_spec_string ("charity_name", &charities[index].name), TALER_JSON_spec_amount_any ("max_per_year", &charities[index].max_per_year), diff --git a/src/lib/donau_api_charity_post.c b/src/lib/donau_api_charity_post.c @@ -111,10 +111,6 @@ handle_charity_post_finished (void *cls, } } break; - case MHD_HTTP_NO_CONTENT: - pcresp.hr.ec = TALER_JSON_get_error_code (j); - pcresp.hr.hint = TALER_JSON_get_error_hint (j); - break; case MHD_HTTP_FORBIDDEN: pcresp.hr.ec = TALER_JSON_get_error_code (j); pcresp.hr.hint = TALER_JSON_get_error_hint (j); @@ -123,7 +119,7 @@ handle_charity_post_finished (void *cls, pcresp.hr.ec = TALER_JSON_get_error_code (j); pcresp.hr.hint = TALER_JSON_get_error_hint (j); break; - case MHD_HTTP_CONTENT_TOO_LARGE: + case MHD_HTTP_CONFLICT: pcresp.hr.ec = TALER_JSON_get_error_code (j); pcresp.hr.hint = TALER_JSON_get_error_hint (j); break; @@ -153,7 +149,10 @@ struct DONAU_CharityPostHandle * DONAU_charity_post ( struct GNUNET_CURL_Context *ctx, const char *url, - struct DONAU_CharityRequest *charity_req, // make it const + const char *charity_name, + const char *charity_url, + const struct TALER_Amount *max_per_year, + const struct DONAU_CharityPublicKeyP *charity_pub, const struct DONAU_BearerToken *bearer, DONAU_PostCharityResponseCallback cb, void *cb_cls) @@ -184,17 +183,13 @@ DONAU_charity_post ( cph->url); body = GNUNET_JSON_PACK ( GNUNET_JSON_pack_data_auto ("charity_pub", - &charity_req->charity_pub), + charity_pub), GNUNET_JSON_pack_string ("charity_url", - charity_req->charity_url), + charity_url), GNUNET_JSON_pack_string ("charity_name", - charity_req->name), + charity_name), TALER_JSON_pack_amount ("max_per_year", - &charity_req->max_per_year), - TALER_JSON_pack_amount ("receipts_to_date", - &charity_req->receipts_to_date), // really needed? - GNUNET_JSON_pack_uint64 ("current_year", - charity_req->current_year)); + max_per_year)); eh = DONAU_curl_easy_get_ (cph->url); if ( (NULL == eh) || (GNUNET_OK != diff --git a/src/testing/test_donau_api.c b/src/testing/test_donau_api.c @@ -75,8 +75,6 @@ run (void *cls, "example", "example.com", "EUR:10", // max_per_year - "EUR:0", // receipts_to_date - 2025, // current year &bearer, MHD_HTTP_CREATED), TALER_TESTING_cmd_charity_get ("get-charity-by-id", diff --git a/src/testing/testing_api_cmd_charity_post.c b/src/testing/testing_api_cmd_charity_post.c @@ -39,9 +39,24 @@ struct StatusState struct DONAU_CharityPostHandle *cph; /** - * The charity POST request. + * Name of the charity. */ - struct DONAU_CharityRequest charity_req; + const char *charity_name; + + /** + * Web site of the charity. + */ + const char *charity_url; + + /** + * Maximum donation amount for the charity. + */ + struct TALER_Amount max_per_year; + + /** + * Public key of the charity. + */ + struct DONAU_CharityPublicKeyP charity_pub; /** * Private key of the charity, created here. @@ -123,7 +138,10 @@ charity_status_run (void *cls, ss->cph = DONAU_charity_post ( TALER_TESTING_interpreter_get_context (is), TALER_TESTING_get_donau_url (is), - &ss->charity_req, + ss->charity_name, + ss->charity_url, + &ss->max_per_year, + &ss->charity_pub, ss->bearer, &charity_status_cb, ss); @@ -173,7 +191,7 @@ charity_post_traits (void *cls, struct StatusState *ss = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_charity_priv (&ss->charity_priv), - TALER_TESTING_make_trait_charity_pub (&ss->charity_req.charity_pub), + TALER_TESTING_make_trait_charity_pub (&ss->charity_pub), TALER_TESTING_make_trait_charity_id (&ss->charity_id), TALER_TESTING_trait_end () }; @@ -190,8 +208,6 @@ TALER_TESTING_cmd_charity_post (const char *label, const char *name, const char *url, const char *max_per_year, - const char *receipts_to_date, - uint64_t current_year, const struct DONAU_BearerToken *bearer, unsigned int expected_response_code) { @@ -200,13 +216,12 @@ TALER_TESTING_cmd_charity_post (const char *label, ss = GNUNET_new (struct StatusState); GNUNET_CRYPTO_eddsa_key_create (&ss->charity_priv.eddsa_priv); GNUNET_CRYPTO_eddsa_key_get_public (&ss->charity_priv.eddsa_priv, - &ss->charity_req.charity_pub.eddsa_pub); - ss->charity_req.name = name; - ss->charity_req.charity_url = url; - // parse string max_per_year to amount + &ss->charity_pub.eddsa_pub); + ss->charity_name = name; + ss->charity_url = url; if (GNUNET_OK != TALER_string_to_amount (max_per_year, - &ss->charity_req.max_per_year)) + &ss->max_per_year)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse amount `%s' at %s\n", @@ -214,18 +229,6 @@ TALER_TESTING_cmd_charity_post (const char *label, label); GNUNET_assert (0); } - // parse string receipts_to_date to amount - if (GNUNET_OK != - TALER_string_to_amount (receipts_to_date, - &ss->charity_req.receipts_to_date)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to parse amount `%s' at %s\n", - receipts_to_date, - label); - GNUNET_assert (0); - } - ss->charity_req.current_year = current_year; ss->expected_response_code = expected_response_code; ss->bearer = bearer; {