diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-06-20 20:39:40 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-06-20 20:39:40 +0200 |
commit | c4b37438f88051d4271af0b3db3aed6deb6ec3d8 (patch) | |
tree | 9160b0ab6bf92adb3b4861b44535b6721c97dfca /src/testing/testing_api_cmd_backup_upload.c | |
parent | cfd614b0151a9804cd5b53ebc7c47a4fafa9c5fa (diff) | |
download | sync-c4b37438f88051d4271af0b3db3aed6deb6ec3d8.tar.gz sync-c4b37438f88051d4271af0b3db3aed6deb6ec3d8.tar.bz2 sync-c4b37438f88051d4271af0b3db3aed6deb6ec3d8.zip |
-modernize sync API for 0.9.3
Diffstat (limited to 'src/testing/testing_api_cmd_backup_upload.c')
-rw-r--r-- | src/testing/testing_api_cmd_backup_upload.c | 149 |
1 files changed, 69 insertions, 80 deletions
diff --git a/src/testing/testing_api_cmd_backup_upload.c b/src/testing/testing_api_cmd_backup_upload.c index d2c3851..090e74b 100644 --- a/src/testing/testing_api_cmd_backup_upload.c +++ b/src/testing/testing_api_cmd_backup_upload.c @@ -1,6 +1,6 @@ /* This file is part of SYNC - Copyright (C) 2014-2019 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA SYNC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -126,100 +126,89 @@ struct BackupUploadState * Function called with the results of a #SYNC_upload(). * * @param cls closure - * @param ec Taler error code - * @param http_status HTTP status of the request * @param ud details about the upload operation */ static void backup_upload_cb (void *cls, - enum TALER_ErrorCode ec, - unsigned int http_status, const struct SYNC_UploadDetails *ud) { struct BackupUploadState *bus = cls; bus->uo = NULL; - if (http_status != bus->http_status) + if (ud->http_status != bus->http_status) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unexpected response code %u to command %s in %s:%u\n", - http_status, - bus->is->commands[bus->is->ip].label, - __FILE__, - __LINE__); - TALER_TESTING_interpreter_fail (bus->is); - return; + TALER_TESTING_unexpected_status (bus->is, + ud->http_status); } - if (NULL != ud) + switch (ud->us) { - switch (ud->us) + case SYNC_US_SUCCESS: + if (0 != GNUNET_memcmp ( + &bus->curr_hash, + ud->details.success.curr_backup_hash)) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; + } + break; + case SYNC_US_PAYMENT_REQUIRED: { - case SYNC_US_SUCCESS: - if (0 != GNUNET_memcmp (&bus->curr_hash, - ud->details.curr_backup_hash)) + struct TALER_MERCHANT_PayUriData pd; + + if (GNUNET_OK != + TALER_MERCHANT_parse_pay_uri ( + ud->details.payment_required.payment_request, + &pd)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (bus->is); return; } - break; - case SYNC_US_PAYMENT_REQUIRED: - { - struct TALER_MERCHANT_PayUriData pd; - - if (GNUNET_OK != - TALER_MERCHANT_parse_pay_uri (ud->details.payment_request, - &pd)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - } - bus->payment_order_id = GNUNET_strdup (pd.order_id); - if (NULL != pd.claim_token) - bus->token = *pd.claim_token; - TALER_MERCHANT_parse_pay_uri_free (&pd); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Order ID from Sync service is `%s'\n", - bus->payment_order_id); - memset (&bus->curr_hash, - 0, - sizeof (struct GNUNET_HashCode)); - } - break; - case SYNC_US_CONFLICTING_BACKUP: + bus->payment_order_id = GNUNET_strdup (pd.order_id); + if (NULL != pd.claim_token) + bus->token = *pd.claim_token; + TALER_MERCHANT_parse_pay_uri_free (&pd); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Order ID from Sync service is `%s'\n", + bus->payment_order_id); + memset (&bus->curr_hash, + 0, + sizeof (struct GNUNET_HashCode)); + } + break; + case SYNC_US_CONFLICTING_BACKUP: + { + const struct TALER_TESTING_Command *ref; + const struct GNUNET_HashCode *h; + + ref = TALER_TESTING_interpreter_lookup_command + (bus->is, + bus->last_upload); + GNUNET_assert (NULL != ref); + GNUNET_assert (GNUNET_OK == + SYNC_TESTING_get_trait_hash (ref, + SYNC_TESTING_TRAIT_HASH_CURRENT, + &h)); + if (0 != GNUNET_memcmp (h, + &ud->details.recovered_backup. + existing_backup_hash)) { - const struct TALER_TESTING_Command *ref; - const struct GNUNET_HashCode *h; - - ref = TALER_TESTING_interpreter_lookup_command - (bus->is, - bus->last_upload); - GNUNET_assert (NULL != ref); - GNUNET_assert (GNUNET_OK == - SYNC_TESTING_get_trait_hash (ref, - SYNC_TESTING_TRAIT_HASH_CURRENT, - &h)); - if (0 != GNUNET_memcmp (h, - &ud->details.recovered_backup. - existing_backup_hash)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - } + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; } - case SYNC_US_HTTP_ERROR: - break; - case SYNC_US_CLIENT_ERROR: - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; - case SYNC_US_SERVER_ERROR: - GNUNET_break (0); - TALER_TESTING_interpreter_fail (bus->is); - return; } + case SYNC_US_HTTP_ERROR: + break; + case SYNC_US_CLIENT_ERROR: + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; + case SYNC_US_SERVER_ERROR: + GNUNET_break (0); + TALER_TESTING_interpreter_fail (bus->is); + return; } TALER_TESTING_interpreter_next (bus->is); } @@ -294,7 +283,7 @@ backup_upload_run (void *cls, } if (0 != (SYNC_TESTING_UO_REFERENCE_ORDER_ID & bus->uopt)) { - const char **order_id; + const char *order_id; if (GNUNET_OK != TALER_TESTING_get_trait_order_id (ref, @@ -304,7 +293,7 @@ backup_upload_run (void *cls, TALER_TESTING_interpreter_fail (bus->is); return; } - bus->payment_order_req = *order_id; + bus->payment_order_req = order_id; if (NULL == bus->payment_order_req) { GNUNET_break (0); @@ -326,7 +315,7 @@ backup_upload_run (void *cls, GNUNET_CRYPTO_hash (bus->backup, bus->backup_size, &bus->curr_hash); - bus->uo = SYNC_upload (is->ctx, + bus->uo = SYNC_upload (TALER_TESTING_interpreter_get_context (is), bus->sync_url, &bus->sync_priv, ( ( (NULL != bus->prev_upload) && @@ -387,7 +376,7 @@ backup_upload_cleanup (void *cls, * @param index index number of the object to extract. * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue backup_upload_traits (void *cls, const void **ret, const char *trait, @@ -404,7 +393,7 @@ backup_upload_traits (void *cls, &bus->sync_pub), SYNC_TESTING_make_trait_account_priv (0, &bus->sync_priv), - TALER_TESTING_make_trait_order_id (&bus->payment_order_id), + TALER_TESTING_make_trait_order_id (bus->payment_order_id), TALER_TESTING_trait_end () }; struct TALER_TESTING_Trait ftraits[] = { @@ -413,7 +402,7 @@ backup_upload_traits (void *cls, &bus->sync_pub), SYNC_TESTING_make_trait_account_priv (0, &bus->sync_priv), - TALER_TESTING_make_trait_order_id (&bus->payment_order_id), + TALER_TESTING_make_trait_order_id (bus->payment_order_id), TALER_TESTING_trait_end () }; |