diff options
Diffstat (limited to 'src/lib/merchant_api_get_template.c')
-rw-r--r-- | src/lib/merchant_api_get_template.c | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/src/lib/merchant_api_get_template.c b/src/lib/merchant_api_get_template.c index 920333b6..9bbcc93a 100644 --- a/src/lib/merchant_api_get_template.c +++ b/src/lib/merchant_api_get_template.c @@ -79,9 +79,9 @@ handle_get_template_finished (void *cls, { struct TALER_MERCHANT_TemplateGetHandle *tgh = cls; const json_t *json = response; - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_MERCHANT_TemplateGetResponse tgr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; tgh->job = NULL; @@ -92,67 +92,55 @@ handle_get_template_finished (void *cls, { case MHD_HTTP_OK: { - const char *template_description; - const char *image; - json_t *template_contract; - bool rst_ok = true; + const json_t *contract; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_description", - &template_description), + &tgr.details.ok.template_description), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_string ("image", - &image), + GNUNET_JSON_spec_string ("otp_id", + &tgr.details.ok.otp_id), NULL), - GNUNET_JSON_spec_json ("template_contract", - &template_contract), + GNUNET_JSON_spec_object_const ("template_contract", + &contract), GNUNET_JSON_spec_end () }; - - if ( (rst_ok) && - (GNUNET_OK == - GNUNET_JSON_parse (json, - spec, - NULL, NULL)) ) + if (GNUNET_OK == + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { + tgr.details.ok.template_contract = contract; tgh->cb (tgh->cb_cls, - &hr, - template_description, - image, - template_contract); - GNUNET_JSON_parse_free (spec); + &tgr); TALER_MERCHANT_template_get_cancel (tgh); return; } - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - GNUNET_JSON_parse_free (spec); + tgr.hr.http_status = 0; + tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } case MHD_HTTP_UNAUTHORIZED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); /* Nothing really to verify, merchant says we need to authenticate. */ break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.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) hr.ec); + (int) tgr.hr.ec); break; } tgh->cb (tgh->cb_cls, - &hr, - NULL, - NULL, - NULL); + &tgr); TALER_MERCHANT_template_get_cancel (tgh); } |