merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 04b3192dbba7262bfa2714ff15cf44b55185bd89
parent f0ce8a0d390a7fde83775fbf449384d049198f74
Author: bohdan-potuzhnyi <bohdan.potuzhnyi@gmail.com>
Date:   Mon, 14 Jul 2025 21:29:35 +0200

uncrustify all *donau* files

Diffstat:
Msrc/backend/taler-merchant-donaukeyupdate.c | 269++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c | 53+++++++++++++++++++++++++++--------------------------
Msrc/backend/taler-merchant-httpd_private-get-donau-instances.c | 33+++++++++++++++++----------------
Msrc/backend/taler-merchant-httpd_private-get-donau-instances.h | 1-
Msrc/backend/taler-merchant-httpd_private-post-donau-instance.c | 71++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/backenddb/pg_insert_donau_instance.c | 10+++++-----
Msrc/backenddb/pg_select_donau_instance.c | 70+++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/backenddb/pg_upsert_donau_keys.c | 22+++++++++++-----------
Msrc/backenddb/pg_upsert_donau_keys.h | 4++--
Msrc/lib/merchant_api_delete_donau_instance.c | 51+++++++++++++++++++++++++++++----------------------
Msrc/lib/merchant_api_get_donau_instance.c | 160+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/lib/merchant_api_post_donau_instance.c | 66++++++++++++++++++++++++++++++++++--------------------------------
Msrc/testing/testing_api_cmd_delete_donau_instances.c | 47++++++++++++++++++++++++++++-------------------
Msrc/testing/testing_api_cmd_get_donau_instances.c | 60+++++++++++++++++++++++++++++++++---------------------------
Msrc/testing/testing_api_cmd_post_donau_charity_merchant.c | 20+++++++++++---------
Msrc/testing/testing_api_cmd_post_donau_instances.c | 72++++++++++++++++++++++++++++++++++++++----------------------------------
16 files changed, 532 insertions(+), 477 deletions(-)

diff --git a/src/backend/taler-merchant-donaukeyupdate.c b/src/backend/taler-merchant-donaukeyupdate.c @@ -32,9 +32,9 @@ /** * Maximum frequency for the Donau interaction. */ -#define DONAU_MAXFREQ GNUNET_TIME_relative_multiply( \ - GNUNET_TIME_UNIT_MINUTES, \ - 5) +#define DONAU_MAXFREQ GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MINUTES, \ + 5) /** * How many inquiries do we process concurrently at most. @@ -194,12 +194,12 @@ end_inquiry (void) NULL != d; d = d->next) { - if (!d->limited) + if (! d->limited) continue; d->limited = false; /* done synchronously so that the active_inquiries is updated immediately */ - download_keys(d); + download_keys (d); if (at_limit) break; } @@ -208,13 +208,14 @@ end_inquiry (void) (0 == active_inquiries) && (test_mode) ) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "No more open inquiries and in test mode. Exiting.\n"); - GNUNET_SCHEDULER_shutdown(); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No more open inquiries and in test mode. Exiting.\n"); + GNUNET_SCHEDULER_shutdown (); return; } } + /** * Update Donau keys in the database. * @@ -222,12 +223,14 @@ end_inquiry (void) * @return transaction status */ static enum GNUNET_DB_QueryStatus -insert_donau_keys_data(const struct DONAU_Keys *keys) +insert_donau_keys_data (const struct DONAU_Keys *keys) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Inserting Donau keys into the database %s\n", keys->donau_url); - return db_plugin->upsert_donau_keys(db_plugin->cls, keys); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Inserting Donau keys into the database %s\n", keys->donau_url); + return db_plugin->upsert_donau_keys (db_plugin->cls, keys); } + /** * Store Donau keys in the database and handle retries. * @@ -235,38 +238,41 @@ insert_donau_keys_data(const struct DONAU_Keys *keys) * @return true on success */ static bool -store_donau_keys(struct DONAU_Keys *keys) +store_donau_keys (struct DONAU_Keys *keys) { enum GNUNET_DB_QueryStatus qs; - db_plugin->preflight(db_plugin->cls); + db_plugin->preflight (db_plugin->cls); for (unsigned int r = 0; r < MAX_RETRIES; r++) { if (GNUNET_OK != - db_plugin->start(db_plugin->cls, - "update donau key data")) + db_plugin->start (db_plugin->cls, + "update donau key data")) { - db_plugin->rollback(db_plugin->cls); + db_plugin->rollback (db_plugin->cls); GNUNET_break (0); return false; } - qs = insert_donau_keys_data(keys); + qs = insert_donau_keys_data (keys); if (qs < 0) { - db_plugin->rollback(db_plugin->cls); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error while inserting Donau keys into the database: status %d", qs); + db_plugin->rollback (db_plugin->cls); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error while inserting Donau keys into the database: status %d", + qs); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) continue; GNUNET_break (0); return false; } - qs = db_plugin->commit(db_plugin->cls); + qs = db_plugin->commit (db_plugin->cls); if (qs < 0) { db_plugin->rollback (db_plugin->cls); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to commit Donau keys to the database: status %d", qs); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to commit Donau keys to the database: status %d", qs); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) continue; GNUNET_break (0); @@ -281,6 +287,7 @@ store_donau_keys(struct DONAU_Keys *keys) return true; } + /** * Callback after Donau keys are fetched. * @@ -289,7 +296,7 @@ store_donau_keys(struct DONAU_Keys *keys) * @param keys the keys of the Donau instance */ static void -donau_cert_cb( +donau_cert_cb ( void *cls, const struct DONAU_KeysResponse *kr, struct DONAU_Keys *keys) @@ -307,56 +314,57 @@ donau_cert_cb( if (! store_donau_keys (keys)) break; - d->keys = DONAU_keys_incref(keys); + d->keys = DONAU_keys_incref (keys); /* Reset back-off */ d->retry_delay = DONAU_MAXFREQ; /* limit retry */ d->first_retry = - GNUNET_TIME_relative_to_absolute( + GNUNET_TIME_relative_to_absolute ( DONAU_MAXFREQ); - //Fixme: hardcoded retry delay + // Fixme: hardcoded retry delay n = GNUNET_TIME_absolute_max (d->first_retry, - GNUNET_TIME_relative_to_absolute( - GNUNET_TIME_relative_multiply( + GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_MONTHS, 3))); if (NULL != d->retry_task) - GNUNET_SCHEDULER_cancel(d->retry_task); - d->retry_task = GNUNET_SCHEDULER_add_at(n, - &download_keys, - d); + GNUNET_SCHEDULER_cancel (d->retry_task); + d->retry_task = GNUNET_SCHEDULER_add_at (n, + &download_keys, + d); - end_inquiry(); + end_inquiry (); return; default: break; } d->retry_delay - = GNUNET_TIME_STD_BACKOFF(d->retry_delay); - n = GNUNET_TIME_absolute_max( + = GNUNET_TIME_STD_BACKOFF (d->retry_delay); + n = GNUNET_TIME_absolute_max ( d->first_retry, - GNUNET_TIME_relative_to_absolute(d->retry_delay)); + GNUNET_TIME_relative_to_absolute (d->retry_delay)); if (NULL != d->retry_task) - GNUNET_SCHEDULER_cancel(d->retry_task); + GNUNET_SCHEDULER_cancel (d->retry_task); d->retry_task - = GNUNET_SCHEDULER_add_at(n, - &download_keys, - d); + = GNUNET_SCHEDULER_add_at (n, + &download_keys, + d); - end_inquiry(); + end_inquiry (); } + /** * Initiate the download of Donau keys. * * @param cls closure with a `struct Donau *` */ static void -download_keys(void *cls) +download_keys (void *cls) { struct Donau *d = cls; @@ -371,11 +379,11 @@ download_keys(void *cls) return; } d->retry_delay - = GNUNET_TIME_STD_BACKOFF(d->retry_delay); - d->conn = DONAU_get_keys(ctx, - d->donau_url, - &donau_cert_cb, - d); + = GNUNET_TIME_STD_BACKOFF (d->retry_delay); + d->conn = DONAU_get_keys (ctx, + d->donau_url, + &donau_cert_cb, + d); if (NULL != d->conn) { @@ -385,16 +393,17 @@ download_keys(void *cls) { struct GNUNET_TIME_Relative n; - n = GNUNET_TIME_relative_max(d->retry_delay, - DONAU_MAXFREQ); + n = GNUNET_TIME_relative_max (d->retry_delay, + DONAU_MAXFREQ); d->retry_task - = GNUNET_SCHEDULER_add_delayed(n, - &download_keys, - d); + = GNUNET_SCHEDULER_add_delayed (n, + &download_keys, + d); } } + /** * Lookup donau by @a donau_url. Create one * if it does not exist. @@ -403,23 +412,23 @@ download_keys(void *cls) * @return NULL if not found */ static struct Donau * -lookup_donau(const char *donau_url) +lookup_donau (const char *donau_url) { for (struct Donau *d = d_head; NULL != d; d = d->next) - if (0 == strcmp(d->donau_url, - donau_url)) + if (0 == strcmp (d->donau_url, + donau_url)) return d; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Got notification about unknown Donau `%s'\n", - donau_url); - + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Got notification about unknown Donau `%s'\n", + donau_url); return NULL; } + /** * Force immediate (re)loading of /keys for an donau. * @@ -428,9 +437,9 @@ lookup_donau(const char *donau_url) * @param extra_len number of bytes in @a extra */ static void -force_donau_keys(void *cls, - const void *extra, - size_t extra_len) +force_donau_keys (void *cls, + const void *extra, + size_t extra_len) { const char *url = extra; struct Donau *d; @@ -450,27 +459,27 @@ force_donau_keys(void *cls, "Received keys update notification: reload `%s'\n", url); - d = lookup_donau(url); + d = lookup_donau (url); if (NULL == d) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Donau instance `%s' not found. Creating new instance.\n", url); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Donau instance `%s' not found. Creating new instance.\n", url); // Create a new Donau instance dynamically - d = GNUNET_new(struct Donau); - d->donau_url = GNUNET_strdup(url); + d = GNUNET_new (struct Donau); + d->donau_url = GNUNET_strdup (url); d->keys = NULL; d->conn = NULL; d->retry_task = NULL; d->retry_delay = DONAU_MAXFREQ; - d->first_retry = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_ZERO); + d->first_retry = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); d->limited = false; // Insert the new instance into the linked list - GNUNET_CONTAINER_DLL_insert(d_head, d_tail, d); + GNUNET_CONTAINER_DLL_insert (d_head, d_tail, d); // Schedule a keys download for the newly created instance - download_keys(d); + download_keys (d); } if (NULL != d->conn) { @@ -487,14 +496,15 @@ force_donau_keys(void *cls, d->first_retry), true)); if (NULL != d->retry_task) - GNUNET_SCHEDULER_cancel(d->retry_task); + GNUNET_SCHEDULER_cancel (d->retry_task); d->retry_task - = GNUNET_SCHEDULER_add_at(d->first_retry, - &download_keys, - d); + = GNUNET_SCHEDULER_add_at (d->first_retry, + &download_keys, + d); } + /** * Function called on each configuration section. Finds sections * about donau, parses the entries. @@ -503,35 +513,35 @@ force_donau_keys(void *cls, * @param section name of the section */ static void -accept_donau(void *cls, - const char *section) +accept_donau (void *cls, + const char *section) { char *url; char *currency; - //char *mks; + // char *mks; if (0 != - strncasecmp(section, - "merchant-donau-", - strlen ("merchant-donau-"))) + strncasecmp (section, + "merchant-donau-", + strlen ("merchant-donau-"))) return; if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno(cfg, - section, - "DISABLE")) + GNUNET_CONFIGURATION_get_value_yesno (cfg, + section, + "DISABLE")) return; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string(cfg, - section, - "DONAU_URL", - &url)) + GNUNET_CONFIGURATION_get_value_string (cfg, + section, + "DONAU_URL", + &url)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, "DONAU_BASE_URL"); global_ret = EXIT_NOTCONFIGURED; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); return; } @@ -548,7 +558,7 @@ accept_donau(void *cls, section); GNUNET_free (url); global_ret = EXIT_NOTCONFIGURED; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); return; } } @@ -613,8 +623,8 @@ accept_donau(void *cls, struct DONAU_Keys *keys; qs = db_plugin->lookup_donau_keys (db_plugin->cls, - url, - &keys); + url, + &keys); if (qs < 0) { @@ -657,8 +667,8 @@ accept_donau(void *cls, else { d->retry_task - = GNUNET_SCHEDULER_add_at (GNUNET_TIME_relative_to_absolute( - GNUNET_TIME_relative_multiply( + = GNUNET_SCHEDULER_add_at (GNUNET_TIME_relative_to_absolute ( + GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_MONTHS, 3)), &download_keys, @@ -671,6 +681,7 @@ accept_donau(void *cls, } } + /** * We're being aborted with CTRL-C (or SIGTERM). Shut down. * @@ -728,6 +739,7 @@ shutdown_task (void *cls) } } + /** * First task. * @@ -737,20 +749,20 @@ shutdown_task (void *cls) * @param c configuration */ static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { (void) args; (void) cfgfile; cfg = c; - GNUNET_SCHEDULER_add_shutdown(&shutdown_task, - NULL); - ctx = GNUNET_CURL_init(&GNUNET_CURL_gnunet_scheduler_reschedule, - &rc); - rc = GNUNET_CURL_gnunet_rc_create(ctx); + GNUNET_SCHEDULER_add_shutdown (&shutdown_task, + NULL); + ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, + &rc); + rc = GNUNET_CURL_gnunet_rc_create (ctx); if (NULL == ctx) { GNUNET_break (0); @@ -765,8 +777,8 @@ run(void *cls, global_ret = EXIT_FAILURE; return; } - if( NULL == - (db_plugin = TALER_MERCHANTDB_plugin_load(cfg)) ) + if (NULL == + (db_plugin = TALER_MERCHANTDB_plugin_load (cfg)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); @@ -785,30 +797,31 @@ run(void *cls, } { struct GNUNET_DB_EventHeaderP es = { - .size = ntohs(sizeof(es)), - .type = ntohs(TALER_DBEVENT_MERCHANT_DONAU_KEYS) + .size = ntohs (sizeof(es)), + .type = ntohs (TALER_DBEVENT_MERCHANT_DONAU_KEYS) }; - eh = db_plugin->event_listen(db_plugin->cls, - &es, - GNUNET_TIME_UNIT_FOREVER_REL, - &force_donau_keys, - NULL); + eh = db_plugin->event_listen (db_plugin->cls, + &es, + GNUNET_TIME_UNIT_FOREVER_REL, + &force_donau_keys, + NULL); } - GNUNET_CONFIGURATION_iterate_sections(cfg, - &accept_donau, - NULL); + GNUNET_CONFIGURATION_iterate_sections (cfg, + &accept_donau, + NULL); if ( (0 == active_inquiries) && (test_mode) ) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "No donaukeys inquiries to start, exiting.\n"); - GNUNET_SCHEDULER_shutdown(); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "No donaukeys inquiries to start, exiting.\n"); + GNUNET_SCHEDULER_shutdown (); return; } } + /** * The main function of taler-merchant-donaukeyupdate * @@ -816,26 +829,27 @@ run(void *cls, * @param argv command line arguments * @return 0 ok, 1 on error */ -int main(int argc, - char *const *argv) +int +main (int argc, + char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_option_timetravel('T', - "timetravel"), - GNUNET_GETOPT_option_flag('t', - "test", - "run in test mode and exit when idle", - &test_mode), - GNUNET_GETOPT_option_version(VERSION "-" VCS_VERSION), + GNUNET_GETOPT_option_timetravel ('T', + "timetravel"), + GNUNET_GETOPT_option_flag ('t', + "test", + "run in test mode and exit when idle", + &test_mode), + GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION), GNUNET_GETOPT_OPTION_END }; enum GNUNET_GenericReturnValue ret; - ret = GNUNET_PROGRAM_run( + ret = GNUNET_PROGRAM_run ( TALER_MERCHANT_project_data (), argc, argv, "taler-merchant-donaukeyupdate", - gettext_noop( + gettext_noop ( "background process that ensures our key and configuration data on Donau is up-to-date"), options, &run, NULL); @@ -846,4 +860,5 @@ int main(int argc, return global_ret; } + /* end of taler-merchant-donaukeyupdate.c */ diff --git a/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c b/src/backend/taler-merchant-httpd_private-delete-donau-instance-ID.c @@ -45,43 +45,44 @@ TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, char dummy; (void) rh; - GNUNET_assert(NULL != mi); + GNUNET_assert (NULL != mi); - if (1 != sscanf(hc->infix, "%lu%c", &charity_id, &dummy)) + if (1 != sscanf (hc->infix, "%lu%c", &charity_id, &dummy)) { - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - hc->infix); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + hc->infix); } - qs = TMH_db->delete_donau_instance(TMH_db->cls, charity_id); + qs = TMH_db->delete_donau_instance (TMH_db->cls, charity_id); switch (qs) { - case GNUNET_DB_STATUS_HARD_ERROR: - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "delete_donau_instance"); + case GNUNET_DB_STATUS_HARD_ERROR: + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "delete_donau_instance"); - case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break(0); - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, - "delete_donau_instance (soft)"); + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, + "delete_donau_instance (soft)"); - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, - hc->infix); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, + hc->infix); - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - return TALER_MHD_reply_static(connection, MHD_HTTP_NO_CONTENT, NULL, NULL, 0); + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + return TALER_MHD_reply_static (connection, MHD_HTTP_NO_CONTENT, NULL, NULL, + 0); } - GNUNET_assert(0); + GNUNET_assert (0); return MHD_NO; } \ No newline at end of file diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.c b/src/backend/taler-merchant-httpd_private-get-donau-instances.c @@ -74,7 +74,7 @@ add_donau_instance (void *cls, current_year), GNUNET_JSON_pack_object_incref ("donau_keys_json", (json_t *) donau_keys_json) - ))); + ))); } @@ -91,28 +91,29 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, struct MHD_Connection *connection, struct TMH_HandlerContext *hc) { - json_t *json_donau_instances = json_array(); + json_t *json_donau_instances = json_array (); enum GNUNET_DB_QueryStatus qs; GNUNET_assert (NULL != json_donau_instances); - TMH_db->preflight(TMH_db->cls); - qs = TMH_db->select_donau_instance(TMH_db->cls, - &add_donau_instance, - json_donau_instances); + TMH_db->preflight (TMH_db->cls); + qs = TMH_db->select_donau_instance (TMH_db->cls, + &add_donau_instance, + json_donau_instances); if (0 > qs) { - GNUNET_break(0); - json_decref(json_donau_instances); - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - NULL); + GNUNET_break (0); + json_decref (json_donau_instances); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); } /* Return the JSON array as the response */ - return TALER_MHD_REPLY_JSON_PACK(connection, - MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal("donau_instances", - json_donau_instances)); + return TALER_MHD_REPLY_JSON_PACK (connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ( + "donau_instances", + json_donau_instances)); } \ No newline at end of file diff --git a/src/backend/taler-merchant-httpd_private-get-donau-instances.h b/src/backend/taler-merchant-httpd_private-get-donau-instances.h @@ -40,4 +40,3 @@ TMH_private_get_donau_instances (const struct TMH_RequestHandler *rh, struct TMH_HandlerContext *hc); #endif - diff --git a/src/backend/taler-merchant-httpd_private-post-donau-instance.c b/src/backend/taler-merchant-httpd_private-post-donau-instance.c @@ -52,11 +52,12 @@ TMH_private_post_donau_instance (const struct TMH_RequestHandler *rh, TALER_JSON_spec_amount_any ("max_per_year", &charity.max_per_year), TALER_JSON_spec_amount_any ("receipts_to_date", &charity.receipts_to_date), GNUNET_JSON_spec_uint64 ("current_year", &charity.current_year), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; // Parse JSON body of the request - if (GNUNET_OK != TALER_MHD_parse_json_data(connection, hc->request_body, spec)) + if (GNUNET_OK != TALER_MHD_parse_json_data (connection, hc->request_body, + spec)) { return MHD_NO; } @@ -64,45 +65,45 @@ TMH_private_post_donau_instance (const struct TMH_RequestHandler *rh, // Validate the required parameters if (NULL == donau_url || NULL == charity.name) { - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "Missing donau_url or charity_name"); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "Missing donau_url or charity_name"); } // Try to insert the new Donau instance into the database - enum GNUNET_DB_QueryStatus qs = TMH_db->insert_donau_instance(TMH_db->cls, - donau_url, - &charity, - charity_id); + enum GNUNET_DB_QueryStatus qs = TMH_db->insert_donau_instance (TMH_db->cls, + donau_url, + &charity, + charity_id); switch (qs) { - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - struct GNUNET_DB_EventHeaderP es = { - .size = ntohs (sizeof (es)), - .type = ntohs (TALER_DBEVENT_MERCHANT_DONAU_KEYS) - }; + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + struct GNUNET_DB_EventHeaderP es = { + .size = ntohs (sizeof (es)), + .type = ntohs (TALER_DBEVENT_MERCHANT_DONAU_KEYS) + }; - TMH_db->event_notify(TMH_db->cls, - &es, - donau_url, - strlen(donau_url) + 1); + TMH_db->event_notify (TMH_db->cls, + &es, + donau_url, + strlen (donau_url) + 1); - return TALER_MHD_reply_static(connection, - MHD_HTTP_NO_CONTENT, - NULL, NULL, - 0); - case GNUNET_DB_STATUS_HARD_ERROR: - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "Failed to insert Donau instance"); - case GNUNET_DB_STATUS_SOFT_ERROR: - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - default: - return TALER_MHD_reply_with_error(connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_COMMIT_FAILED, - "Database operation failed"); + return TALER_MHD_reply_static (connection, + MHD_HTTP_NO_CONTENT, + NULL, NULL, + 0); + case GNUNET_DB_STATUS_HARD_ERROR: + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_STORE_FAILED, + "Failed to insert Donau instance"); + case GNUNET_DB_STATUS_SOFT_ERROR: + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + default: + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_COMMIT_FAILED, + "Database operation failed"); } } diff --git a/src/backenddb/pg_insert_donau_instance.c b/src/backenddb/pg_insert_donau_instance.c @@ -32,7 +32,7 @@ TMH_PG_insert_donau_instance ( void *cls, const char *donau_url, const struct DONAU_Charity *charity, - const uint64_t charity_id ) + const uint64_t charity_id) { struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { @@ -48,7 +48,7 @@ TMH_PG_insert_donau_instance ( GNUNET_PQ_query_param_end }; - check_connection(pg); + check_connection (pg); PREPARE (pg, "insert_donau_instance", "INSERT INTO merchant_donau_instances" @@ -60,7 +60,7 @@ TMH_PG_insert_donau_instance ( ",charity_receipts_to_date" ",current_year)" "VALUES ($1, $2, $3, $4, $5, $6, $7);"); - return GNUNET_PQ_eval_prepared_non_select(pg->conn, - "insert_donau_instance", - params); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_donau_instance", + params); } \ No newline at end of file diff --git a/src/backenddb/pg_select_donau_instance.c b/src/backenddb/pg_select_donau_instance.c @@ -97,28 +97,28 @@ select_donau_instance_cb (void *cls, // Extract result for each row if (GNUNET_OK != - GNUNET_PQ_extract_result(result, - rs, - i)) + GNUNET_PQ_extract_result (result, + rs, + i)) { - GNUNET_break(0); // Break on failure + GNUNET_break (0); // Break on failure sdc->extract_failed = true; return; } // Call the callback function with the individual values - sdc->cb(sdc->cb_cls, - donau_url, - charity_name, - &charity_pub_key, - charity_id, - &charity_max_per_year, - &charity_receipts_to_date, - current_year, - donau_keys_json); + sdc->cb (sdc->cb_cls, + donau_url, + charity_name, + &charity_pub_key, + charity_id, + &charity_max_per_year, + &charity_receipts_to_date, + current_year, + donau_keys_json); // Clean up any dynamically allocated results in the result spec - GNUNET_PQ_cleanup_result(rs); + GNUNET_PQ_cleanup_result (rs); } } @@ -149,27 +149,27 @@ TMH_PG_select_donau_instance (void *cls, }; enum GNUNET_DB_QueryStatus qs; - check_connection(pg); - PREPARE(pg, - "select_donau_instances", - "SELECT" - " di.donau_url" - ",di.charity_name" - ",di.charity_pub_key" - ",di.charity_id" - ",di.charity_max_per_year" - ",di.charity_receipts_to_date" - ",di.current_year" - ",dk.keys_json" - " FROM merchant_donau_instances di" - " JOIN merchant_donau_keys dk" - " ON di.donau_url = dk.donau_url"); - - qs = GNUNET_PQ_eval_prepared_multi_select(pg->conn, - "select_donau_instances", - params, - &select_donau_instance_cb, - &sdc); + check_connection (pg); + PREPARE (pg, + "select_donau_instances", + "SELECT" + " di.donau_url" + ",di.charity_name" + ",di.charity_pub_key" + ",di.charity_id" + ",di.charity_max_per_year" + ",di.charity_receipts_to_date" + ",di.current_year" + ",dk.keys_json" + " FROM merchant_donau_instances di" + " JOIN merchant_donau_keys dk" + " ON di.donau_url = dk.donau_url"); + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "select_donau_instances", + params, + &select_donau_instance_cb, + &sdc); /* If there was an error inside select_donau_instance_cb, return a hard error. */ if (sdc.extract_failed) diff --git a/src/backenddb/pg_upsert_donau_keys.c b/src/backenddb/pg_upsert_donau_keys.c @@ -34,24 +34,24 @@ TMH_PG_upsert_donau_keys ( { enum GNUNET_DB_QueryStatus qs; struct PostgresClosure *pg = cls; - json_t *jkeys = DONAU_keys_to_json(keys); + json_t *jkeys = DONAU_keys_to_json (keys); - if(NULL == jkeys) + if (NULL == jkeys) return GNUNET_DB_STATUS_HARD_ERROR; struct GNUNET_PQ_QueryParam params[] = { - TALER_PQ_query_param_json(jkeys), - GNUNET_PQ_query_param_string(keys->donau_url), + TALER_PQ_query_param_json (jkeys), + GNUNET_PQ_query_param_string (keys->donau_url), GNUNET_PQ_query_param_end }; - check_connection(pg); - PREPARE(pg, - "insert_donau_keys", - "INSERT INTO merchant_donau_keys" - "(keys_json" - ",donau_url" - ") VALUES ($1, $2);"); + check_connection (pg); + PREPARE (pg, + "insert_donau_keys", + "INSERT INTO merchant_donau_keys" + "(keys_json" + ",donau_url" + ") VALUES ($1, $2);"); PREPARE (pg, "update_donau_keys", "UPDATE merchant_donau_keys SET" diff --git a/src/backenddb/pg_upsert_donau_keys.h b/src/backenddb/pg_upsert_donau_keys.h @@ -35,8 +35,8 @@ * @return GNUNET_DB_QueryStatus transaction status */ enum GNUNET_DB_QueryStatus -TMH_PG_upsert_donau_keys(void *cls, - const struct DONAU_Keys *keys); +TMH_PG_upsert_donau_keys (void *cls, + const struct DONAU_Keys *keys); #endif diff --git a/src/lib/merchant_api_delete_donau_instance.c b/src/lib/merchant_api_delete_donau_instance.c @@ -95,28 +95,29 @@ handle_delete_donau_instance_finished (void *cls, switch (response_code) { - case MHD_HTTP_NO_CONTENT: - /* Successful deletion */ - break; - case MHD_HTTP_NOT_FOUND: - case MHD_HTTP_UNAUTHORIZED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); - break; - default: - /* Unexpected response */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u/%d for DELETE /donau/$charity_id\n", - (unsigned int) response_code, - (int) hr.ec); - break; + case MHD_HTTP_NO_CONTENT: + /* Successful deletion */ + break; + case MHD_HTTP_NOT_FOUND: + case MHD_HTTP_UNAUTHORIZED: + hr.ec = TALER_JSON_get_error_code (json); + hr.hint = TALER_JSON_get_error_hint (json); + break; + default: + /* Unexpected response */ + hr.ec = TALER_JSON_get_error_code (json); + hr.hint = TALER_JSON_get_error_hint (json); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u/%d for DELETE /donau/$charity_id\n", + (unsigned int) response_code, + (int) hr.ec); + break; } ddh->cb (ddh->cb_cls, &hr); TALER_MERCHANT_donau_instance_delete_cancel (ddh); } + /** * Initiates the DELETE /donau/$charity_id operation. * @@ -131,12 +132,13 @@ struct TALER_MERCHANT_DonauInstanceDeleteHandle * TALER_MERCHANT_donau_instance_delete (struct GNUNET_CURL_Context *ctx, const char *backend_url, uint64_t charity_id, - TALER_MERCHANT_DonauInstanceDeleteCallback cb, + TALER_MERCHANT_DonauInstanceDeleteCallback + cb, void *cb_cls) { struct TALER_MERCHANT_DonauInstanceDeleteHandle *ddh; char *charity_id_str; - + GNUNET_asprintf (&charity_id_str, "private/donau/%ld", charity_id); if (NULL == charity_id_str) return NULL; @@ -159,19 +161,24 @@ TALER_MERCHANT_donau_instance_delete (struct GNUNET_CURL_Context *ctx, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting URL '%s'\n", ddh->url); CURL *eh = TALER_MERCHANT_curl_easy_get_ (ddh->url); - GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_CUSTOMREQUEST, "DELETE")); - ddh->job = GNUNET_CURL_job_add (ctx, eh, &handle_delete_donau_instance_finished, ddh); + GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, CURLOPT_CUSTOMREQUEST, + "DELETE")); + ddh->job = GNUNET_CURL_job_add (ctx, eh, + &handle_delete_donau_instance_finished, ddh); return ddh; } + /** * Cancel the DELETE /donau/$charity_id operation. * * @param ddh the handle for the operation to be canceled */ void -TALER_MERCHANT_donau_instance_delete_cancel (struct TALER_MERCHANT_DonauInstanceDeleteHandle *ddh) +TALER_MERCHANT_donau_instance_delete_cancel (struct + TALER_MERCHANT_DonauInstanceDeleteHandle + *ddh) { if (NULL != ddh->job) GNUNET_CURL_job_cancel (ddh->job); diff --git a/src/lib/merchant_api_get_donau_instance.c b/src/lib/merchant_api_get_donau_instance.c @@ -78,60 +78,62 @@ parse_donau_instances (const json_t *ia, struct TALER_MERCHANT_DonauInstanceGetResponse *igr, struct TALER_MERCHANT_DonauInstanceGetHandle *dgh) { - unsigned int instances_len = (unsigned int) json_array_size(ia); + unsigned int instances_len = (unsigned int) json_array_size (ia); - if ((json_array_size(ia) != (size_t)instances_len)) + if ((json_array_size (ia) != (size_t) instances_len)) { - GNUNET_break(0); + GNUNET_break (0); return GNUNET_SYSERR; } - struct TALER_MERCHANT_DonauInstanceEntry instances[GNUNET_NZL (instances_len)]; + struct TALER_MERCHANT_DonauInstanceEntry instances[GNUNET_NZL ( + instances_len)]; size_t index; json_t *value; - json_array_foreach(ia, index, value) + json_array_foreach (ia, index, value) { struct TALER_MERCHANT_DonauInstanceEntry *instance = &instances[index]; /* Specification for parsing each instance */ struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string("donau_url", - &instance->donau_url), - GNUNET_JSON_spec_string("charity_name", - &instance->charity_name), - GNUNET_JSON_spec_fixed_auto("charity_pub_key", - &instance->charity_pub_key), - GNUNET_JSON_spec_uint64("charity_id", - &instance->charity_id), - TALER_JSON_spec_amount_any("charity_max_per_year", - &instance->charity_max_per_year), - TALER_JSON_spec_amount_any("charity_receipts_to_date", - &instance->charity_receipts_to_date), - GNUNET_JSON_spec_int64("current_year", - &instance->current_year), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_string ("donau_url", + &instance->donau_url), + GNUNET_JSON_spec_string ("charity_name", + &instance->charity_name), + GNUNET_JSON_spec_fixed_auto ("charity_pub_key", + &instance->charity_pub_key), + GNUNET_JSON_spec_uint64 ("charity_id", + &instance->charity_id), + TALER_JSON_spec_amount_any ("charity_max_per_year", + &instance->charity_max_per_year), + TALER_JSON_spec_amount_any ("charity_receipts_to_date", + &instance->charity_receipts_to_date), + GNUNET_JSON_spec_int64 ("current_year", + &instance->current_year), + GNUNET_JSON_spec_end () }; - if (GNUNET_OK != GNUNET_JSON_parse(value, spec, NULL, NULL)) + if (GNUNET_OK != GNUNET_JSON_parse (value, spec, NULL, NULL)) { - GNUNET_break_op(0); + GNUNET_break_op (0); return GNUNET_SYSERR; } /* Parse the Donau keys */ - const json_t *donau_keys_json = json_object_get(value, "donau_keys_json"); + const json_t *donau_keys_json = json_object_get (value, "donau_keys_json"); if (NULL == donau_keys_json) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to parse donau keys JSON\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse donau keys JSON\n"); return GNUNET_SYSERR; } /* Convert donau_keys_json to donau_keys struct */ - struct DONAU_Keys *donau_keys_ptr = DONAU_keys_from_json(donau_keys_json); + struct DONAU_Keys *donau_keys_ptr = DONAU_keys_from_json (donau_keys_json); if (NULL == donau_keys_ptr) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to convert donau keys from JSON\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to convert donau keys from JSON\n"); return GNUNET_SYSERR; } @@ -141,12 +143,13 @@ parse_donau_instances (const json_t *ia, igr->details.ok.donau_instances_length = instances_len; igr->details.ok.donau_instances = instances; - dgh->cb(dgh->cb_cls, igr); + dgh->cb (dgh->cb_cls, igr); dgh->cb = NULL; /* just to be sure */ return GNUNET_OK; } + /** * Function called when we're done processing the * HTTP /donau request. @@ -156,42 +159,42 @@ parse_donau_instances (const json_t *ia, * @param response response body, NULL if not in JSON */ static void -handle_get_donau_instances_finished(void *cls, - long response_code, - const void *response) +handle_get_donau_instances_finished (void *cls, + long response_code, + const void *response) { struct TALER_MERCHANT_DonauInstanceGetHandle *dgh = cls; const json_t *json = response; struct TALER_MERCHANT_DonauInstanceGetResponse igr = { - .hr.http_status = (unsigned int)response_code, + .hr.http_status = (unsigned int) response_code, .hr.reply = json }; dgh->job = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Got /donau response with status code %u\n", - (unsigned int)response_code); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got /donau response with status code %u\n", + (unsigned int) response_code); switch (response_code) { - case MHD_HTTP_OK: + case MHD_HTTP_OK: { const json_t *donau_instances; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_array_const("donau_instances", &donau_instances), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_array_const ("donau_instances", &donau_instances), + GNUNET_JSON_spec_end () }; - if (GNUNET_OK != GNUNET_JSON_parse(json, spec, NULL, NULL)) + if (GNUNET_OK != GNUNET_JSON_parse (json, spec, NULL, NULL)) { igr.hr.http_status = 0; igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } - if (GNUNET_OK == parse_donau_instances(donau_instances, &igr, dgh)) + if (GNUNET_OK == parse_donau_instances (donau_instances, &igr, dgh)) { - TALER_MERCHANT_donau_instances_get_cancel(dgh); + TALER_MERCHANT_donau_instances_get_cancel (dgh); return; } @@ -200,30 +203,31 @@ handle_get_donau_instances_finished(void *cls, break; } - case MHD_HTTP_UNAUTHORIZED: - igr.hr.ec = TALER_JSON_get_error_code(json); - igr.hr.hint = TALER_JSON_get_error_hint(json); - break; - - case MHD_HTTP_NOT_FOUND: - igr.hr.ec = TALER_JSON_get_error_code(json); - igr.hr.hint = TALER_JSON_get_error_hint(json); - break; - - default: - igr.hr.ec = TALER_JSON_get_error_code(json); - igr.hr.hint = TALER_JSON_get_error_hint(json); - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u/%d\n", - (unsigned int)response_code, - (int)igr.hr.ec); - break; + case MHD_HTTP_UNAUTHORIZED: + igr.hr.ec = TALER_JSON_get_error_code (json); + igr.hr.hint = TALER_JSON_get_error_hint (json); + break; + + case MHD_HTTP_NOT_FOUND: + igr.hr.ec = TALER_JSON_get_error_code (json); + igr.hr.hint = TALER_JSON_get_error_hint (json); + break; + + default: + igr.hr.ec = TALER_JSON_get_error_code (json); + igr.hr.hint = TALER_JSON_get_error_hint (json); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) igr.hr.ec); + break; } - dgh->cb(dgh->cb_cls, &igr); - TALER_MERCHANT_donau_instances_get_cancel(dgh); + dgh->cb (dgh->cb_cls, &igr); + TALER_MERCHANT_donau_instances_get_cancel (dgh); } + /** * Initiate the GET /donau request. * @@ -235,47 +239,51 @@ handle_get_donau_instances_finished(void *cls, */ struct TALER_MERCHANT_DonauInstanceGetHandle * TALER_MERCHANT_donau_instances_get (struct GNUNET_CURL_Context *ctx, - const char *backend_url, - TALER_MERCHANT_DonauInstanceGetCallback cb, - void *cb_cls) + const char *backend_url, + TALER_MERCHANT_DonauInstanceGetCallback cb, + void *cb_cls) { struct TALER_MERCHANT_DonauInstanceGetHandle *dgh; CURL *eh; - dgh = GNUNET_new(struct TALER_MERCHANT_DonauInstanceGetHandle); + dgh = GNUNET_new (struct TALER_MERCHANT_DonauInstanceGetHandle); dgh->ctx = ctx; dgh->cb = cb; dgh->cb_cls = cb_cls; - dgh->url = TALER_url_join(backend_url, "private/donau", NULL); + dgh->url = TALER_url_join (backend_url, "private/donau", NULL); if (NULL == dgh->url) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not construct request URL.\n"); - GNUNET_free(dgh); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not construct request URL.\n"); + GNUNET_free (dgh); return NULL; } - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Requesting URL '%s'\n", dgh->url); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Requesting URL '%s'\n", dgh->url); - eh = TALER_MERCHANT_curl_easy_get_(dgh->url); - dgh->job = GNUNET_CURL_job_add(ctx, eh, &handle_get_donau_instances_finished, dgh); + eh = TALER_MERCHANT_curl_easy_get_ (dgh->url); + dgh->job = GNUNET_CURL_job_add (ctx, eh, &handle_get_donau_instances_finished, + dgh); return dgh; } + /** * Cancel the GET /donau operation. * * @param dgh the handle for the operation to be canceled */ void -TALER_MERCHANT_donau_instances_get_cancel (struct TALER_MERCHANT_DonauInstanceGetHandle *dgh) +TALER_MERCHANT_donau_instances_get_cancel (struct + TALER_MERCHANT_DonauInstanceGetHandle + *dgh) { if (NULL != dgh->job) - GNUNET_CURL_job_cancel(dgh->job); + GNUNET_CURL_job_cancel (dgh->job); - GNUNET_free(dgh->url); - GNUNET_free(dgh); + GNUNET_free (dgh->url); + GNUNET_free (dgh); } diff --git a/src/lib/merchant_api_post_donau_instance.c b/src/lib/merchant_api_post_donau_instance.c @@ -104,25 +104,25 @@ handle_post_donau_finished (void *cls, switch (response_code) { - case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - break; - case MHD_HTTP_NO_CONTENT: - break; - case MHD_HTTP_BAD_REQUEST: - case MHD_HTTP_INTERNAL_SERVER_ERROR: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); - break; - default: - TALER_MERCHANT_parse_error_details_ (json, - response_code, - &hr); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u/%d\n", - (unsigned int) response_code, - (int) hr.ec); - break; + case 0: + hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; + case MHD_HTTP_NO_CONTENT: + break; + case MHD_HTTP_BAD_REQUEST: + case MHD_HTTP_INTERNAL_SERVER_ERROR: + hr.ec = TALER_JSON_get_error_code (json); + hr.hint = TALER_JSON_get_error_hint (json); + break; + default: + TALER_MERCHANT_parse_error_details_ (json, + response_code, + &hr); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u/%d\n", + (unsigned int) response_code, + (int) hr.ec); + break; } dph->cb (dph->cb_cls, @@ -188,7 +188,7 @@ TALER_MERCHANT_donau_instances_post ( &charity->receipts_to_date), GNUNET_JSON_pack_uint64 ("current_year", charity->current_year) - ); + ); dph = GNUNET_new (struct TALER_MERCHANT_DonauInstancePostHandle); dph->ctx = ctx; @@ -209,27 +209,28 @@ TALER_MERCHANT_donau_instances_post ( { CURL *eh; - eh = TALER_MERCHANT_curl_easy_get_(dph->url); - if (GNUNET_OK != TALER_curl_easy_post(&dph->post_ctx, eh, req_obj)) + eh = TALER_MERCHANT_curl_easy_get_ (dph->url); + if (GNUNET_OK != TALER_curl_easy_post (&dph->post_ctx, eh, req_obj)) { - GNUNET_break(0); - curl_easy_cleanup(eh); - json_decref(req_obj); - GNUNET_free(dph); + GNUNET_break (0); + curl_easy_cleanup (eh); + json_decref (req_obj); + GNUNET_free (dph); return NULL; } - json_decref(req_obj); + json_decref (req_obj); - dph->job = GNUNET_CURL_job_add2(ctx, - eh, - dph->post_ctx.headers, - &handle_post_donau_finished, - dph); + dph->job = GNUNET_CURL_job_add2 (ctx, + eh, + dph->post_ctx.headers, + &handle_post_donau_finished, + dph); } return dph; } + void TALER_MERCHANT_donau_instances_post_cancel ( struct TALER_MERCHANT_DonauInstancePostHandle *dph) @@ -244,4 +245,5 @@ TALER_MERCHANT_donau_instances_post_cancel ( GNUNET_free (dph); } + /* end of merchant_api_post_donau_instance.c */ \ No newline at end of file diff --git a/src/testing/testing_api_cmd_delete_donau_instances.c b/src/testing/testing_api_cmd_delete_donau_instances.c @@ -74,33 +74,37 @@ delete_donau_cb (void *cls, if (dds->expected_http_status != hr->http_status) { - TALER_TESTING_unexpected_status_with_body( + TALER_TESTING_unexpected_status_with_body ( dds->is, hr->http_status, dds->expected_http_status, hr->reply); - TALER_TESTING_interpreter_fail(dds->is); + TALER_TESTING_interpreter_fail (dds->is); return; } switch (hr->http_status) { case MHD_HTTP_NO_CONTENT: - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DELETE /donau succeeded\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DELETE /donau succeeded\n"); break; case MHD_HTTP_NOT_FOUND: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DELETE /donau: Charity not found\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "DELETE /donau: Charity not found\n"); break; case MHD_HTTP_UNAUTHORIZED: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DELETE /donau: Unauthorized access\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "DELETE /donau: Unauthorized access\n"); break; default: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unhandled HTTP status %u\n", hr->http_status); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unhandled HTTP status %u\n", + hr->http_status); } - TALER_TESTING_interpreter_next(dds->is); + TALER_TESTING_interpreter_next (dds->is); } + /** * Run the DELETE /donau/$charity_id test command. * @@ -116,8 +120,8 @@ delete_donau_run (void *cls, struct DeleteDonauState *dds = cls; dds->is = is; - dds->ddh = TALER_MERCHANT_donau_instance_delete( - TALER_TESTING_interpreter_get_context(is), + dds->ddh = TALER_MERCHANT_donau_instance_delete ( + TALER_TESTING_interpreter_get_context (is), dds->url, dds->charity_id, &delete_donau_cb, @@ -125,12 +129,14 @@ delete_donau_run (void *cls, if (NULL == dds->ddh) { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to initiate DELETE /donau/$charity_id\n"); - TALER_TESTING_interpreter_fail(is); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to initiate DELETE /donau/$charity_id\n"); + TALER_TESTING_interpreter_fail (is); return; } } + /** * Clean up state for DELETE /donau/$charity_id command. * @@ -145,12 +151,14 @@ delete_donau_cleanup (void *cls, if (NULL != dds->ddh) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DELETE /donau/$charity_id operation did not complete\n"); - TALER_MERCHANT_donau_instance_delete_cancel(dds->ddh); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "DELETE /donau/$charity_id operation did not complete\n"); + TALER_MERCHANT_donau_instance_delete_cancel (dds->ddh); } - GNUNET_free(dds); + GNUNET_free (dds); } + /** * Create a DELETE /donau/$charity_id testing command. * @@ -161,12 +169,13 @@ delete_donau_cleanup (void *cls, * @return a TALER_TESTING_Command for DELETE /donau/$charity_id. */ struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_delete_donau_instance(const char *label, - const char *url, - uint64_t charity_id, - unsigned int expected_http_status) +TALER_TESTING_cmd_merchant_delete_donau_instance (const char *label, + const char *url, + uint64_t charity_id, + unsigned int + expected_http_status) { - struct DeleteDonauState *dds = GNUNET_new(struct DeleteDonauState); + struct DeleteDonauState *dds = GNUNET_new (struct DeleteDonauState); dds->url = url; dds->charity_id = charity_id; diff --git a/src/testing/testing_api_cmd_get_donau_instances.c b/src/testing/testing_api_cmd_get_donau_instances.c @@ -54,10 +54,10 @@ struct GetDonauInstancesState */ unsigned int expected_http_status; - /** - * The number of instances in the `instances` array. - */ - unsigned int instances_length; + /** + * The number of instances in the `instances` array. + */ + unsigned int instances_length; }; /** @@ -68,7 +68,8 @@ struct GetDonauInstancesState */ static void get_donau_instances_cb (void *cls, - const struct TALER_MERCHANT_DonauInstanceGetResponse *response) + const struct + TALER_MERCHANT_DonauInstanceGetResponse *response) { struct GetDonauInstancesState *gis = cls; @@ -91,9 +92,10 @@ get_donau_instances_cb (void *cls, unsigned int instance_count = response->details.ok.donau_instances_length; if (instance_count != gis->instances_length) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected %u instances, but got %u\n", + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Expected %u instances, but got %u\n", gis->instances_length, instance_count); - TALER_TESTING_interpreter_fail(gis->is); + TALER_TESTING_interpreter_fail (gis->is); return; } } @@ -102,6 +104,7 @@ get_donau_instances_cb (void *cls, TALER_TESTING_interpreter_next (gis->is); } + /** * Run the "GET donau instance" CMD. * @@ -110,22 +113,23 @@ get_donau_instances_cb (void *cls, * @param is interpreter state. */ static void -get_donau_instances_run(void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) +get_donau_instances_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) { struct GetDonauInstancesState *gis = cls; gis->is = is; - gis->dgh = TALER_MERCHANT_donau_instances_get( - TALER_TESTING_interpreter_get_context(is), + gis->dgh = TALER_MERCHANT_donau_instances_get ( + TALER_TESTING_interpreter_get_context (is), gis->url, &get_donau_instances_cb, gis); - GNUNET_assert(NULL != gis->dgh); // Ensure the request handle is valid + GNUNET_assert (NULL != gis->dgh); // Ensure the request handle is valid } + /** * Free the state of a "GET donau instance" CMD, and possibly * cancel a pending operation thereof. @@ -134,20 +138,22 @@ get_donau_instances_run(void *cls, * @param cmd command being run. */ static void -get_donau_instances_cleanup(void *cls, - const struct TALER_TESTING_Command *cmd) +get_donau_instances_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) { struct GetDonauInstancesState *gis = cls; if (NULL != gis->dgh) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "GET /donau instances operation did not complete\n"); - TALER_MERCHANT_donau_instances_get_cancel(gis->dgh); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "GET /donau instances operation did not complete\n"); + TALER_MERCHANT_donau_instances_get_cancel (gis->dgh); } - GNUNET_free(gis); // Free the state + GNUNET_free (gis); // Free the state } + /** * Create a new command to GET Donau instances. * @@ -157,22 +163,23 @@ get_donau_instances_cleanup(void *cls, * @return a new testing command */ struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_donau_instances(const char *label, - const char *url, - unsigned int instance_count, - unsigned int expected_http_status, - ...) +TALER_TESTING_cmd_merchant_get_donau_instances (const char *label, + const char *url, + unsigned int instance_count, + unsigned int + expected_http_status, + ...) { struct GetDonauInstancesState *gis; - gis = GNUNET_new(struct GetDonauInstancesState); + gis = GNUNET_new (struct GetDonauInstancesState); gis->url = url; gis->expected_http_status = expected_http_status; gis->instances_length = instance_count; va_list ap; - va_start(ap, expected_http_status); - va_end(ap); + va_start (ap, expected_http_status); + va_end (ap); struct TALER_TESTING_Command cmd = { .cls = gis, @@ -183,4 +190,3 @@ TALER_TESTING_cmd_merchant_get_donau_instances(const char *label, return cmd; } - diff --git a/src/testing/testing_api_cmd_post_donau_charity_merchant.c b/src/testing/testing_api_cmd_post_donau_charity_merchant.c @@ -102,6 +102,7 @@ charity_post_traits (void *cls, index); } + /** * Check that the reserve balance and HTTP response code are * both acceptable. @@ -200,21 +201,22 @@ cleanup (void *cls, GNUNET_free (ss); } + struct TALER_TESTING_Command TALER_TESTING_cmd_charity_post_merchant (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, - const char *merchant_reference, - unsigned int expected_response_code) + 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, + const char *merchant_reference, + unsigned int expected_response_code) { struct StatusState *ss; ss = GNUNET_new (struct StatusState); - + ss->merchant_reference = merchant_reference; ss->charity_req.name = name; ss->charity_req.charity_url = url; diff --git a/src/testing/testing_api_cmd_post_donau_instances.c b/src/testing/testing_api_cmd_post_donau_instances.c @@ -87,12 +87,12 @@ post_donau_cb (void *cls, pds->dph = NULL; if (pds->http_status != hr->http_status) { - TALER_TESTING_unexpected_status_with_body( + TALER_TESTING_unexpected_status_with_body ( pds->is, hr->http_status, pds->http_status, hr->reply); - TALER_TESTING_interpreter_fail(pds->is); + TALER_TESTING_interpreter_fail (pds->is); return; } @@ -101,26 +101,27 @@ post_donau_cb (void *cls, case MHD_HTTP_NO_CONTENT: break; /* Test passes */ case MHD_HTTP_BAD_REQUEST: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "POST /donau returned BAD REQUEST: %s\n", - json_dumps(hr->reply, JSON_INDENT(2))); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "POST /donau returned BAD REQUEST: %s\n", + json_dumps (hr->reply, JSON_INDENT (2))); break; case MHD_HTTP_UNAUTHORIZED: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "POST /donau returned UNAUTHORIZED\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "POST /donau returned UNAUTHORIZED\n"); break; case MHD_HTTP_NOT_FOUND: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "POST /donau returned NOT FOUND\n"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "POST /donau returned NOT FOUND\n"); break; default: - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unhandled HTTP status %u for POST /donau\n", - hr->http_status); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unhandled HTTP status %u for POST /donau\n", + hr->http_status); } - TALER_TESTING_interpreter_next(pds->is); + TALER_TESTING_interpreter_next (pds->is); } + /** * Run the "POST /donau" CMD. * @@ -137,10 +138,10 @@ post_donau_run (void *cls, pds->is = is; - //Replacing the url of the charity - pds->charity.charity_url = TALER_TESTING_get_donau_url(is); + // Replacing the url of the charity + pds->charity.charity_url = TALER_TESTING_get_donau_url (is); - //Fetching the publick key of the merchant + // Fetching the publick key of the merchant if (NULL != pds->merchant_reference) { const struct TALER_TESTING_Command *mc; @@ -157,8 +158,8 @@ post_donau_run (void *cls, pds->charity.charity_pub.eddsa_pub = merchant_pub->eddsa_pub; } - pds->dph = TALER_MERCHANT_donau_instances_post( - TALER_TESTING_interpreter_get_context(is), + pds->dph = TALER_MERCHANT_donau_instances_post ( + TALER_TESTING_interpreter_get_context (is), pds->merchant_url, &pds->charity, pds->auth_token, @@ -167,12 +168,13 @@ post_donau_run (void *cls, if (NULL == pds->dph) { - GNUNET_break(0); - TALER_TESTING_interpreter_fail(pds->is); + GNUNET_break (0); + TALER_TESTING_interpreter_fail (pds->is); return; } } + /** * Free the state of a "POST /donau" CMD, and possibly * cancel a pending operation thereof. @@ -188,13 +190,14 @@ post_donau_cleanup (void *cls, if (NULL != pds->dph) { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "POST /donau operation did not complete\n"); - TALER_MERCHANT_donau_instances_post_cancel(pds->dph); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "POST /donau operation did not complete\n"); + TALER_MERCHANT_donau_instances_post_cancel (pds->dph); } - GNUNET_free(pds); + GNUNET_free (pds); } + /** * Create a new testing command for POST /donau. * @@ -204,22 +207,23 @@ post_donau_cleanup (void *cls, * @return the created command. */ struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_post_donau_instance(const char *label, - const char *merchant_url, - const char *merchant_reference, - unsigned int http_status, - ...) +TALER_TESTING_cmd_merchant_post_donau_instance (const char *label, + const char *merchant_url, + const char *merchant_reference, + unsigned int http_status, + ...) { - struct PostDonauState *pds = GNUNET_new(struct PostDonauState); + struct PostDonauState *pds = GNUNET_new (struct PostDonauState); - //FIXME: I need to steal the charity_pub->eddsa_pub from the merchant_pub->eddsa_pub - struct DONAU_CharityPublicKeyP *charity_pub = GNUNET_new(struct DONAU_CharityPublicKeyP); + // FIXME: I need to steal the charity_pub->eddsa_pub from the merchant_pub->eddsa_pub + struct DONAU_CharityPublicKeyP *charity_pub = GNUNET_new (struct + DONAU_CharityPublicKeyP); struct TALER_Amount max_amount; struct TALER_Amount date_amount; - const char* mamount = "EUR:100"; - const char* damount = "EUR:20"; + const char*mamount = "EUR:100"; + const char*damount = "EUR:20"; GNUNET_assert (GNUNET_OK == TALER_string_to_amount (mamount,