summaryrefslogtreecommitdiff
path: root/src/lib/merchant_api_get_product.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/merchant_api_get_product.c')
-rw-r--r--src/lib/merchant_api_get_product.c147
1 files changed, 53 insertions, 94 deletions
diff --git a/src/lib/merchant_api_get_product.c b/src/lib/merchant_api_get_product.c
index 94d38ec7..3f026bf3 100644
--- a/src/lib/merchant_api_get_product.c
+++ b/src/lib/merchant_api_get_product.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018, 2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -79,9 +79,9 @@ handle_get_product_finished (void *cls,
{
struct TALER_MERCHANT_ProductGetHandle *pgh = cls;
const json_t *json = response;
- struct TALER_MERCHANT_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_MERCHANT_ProductGetResponse pgr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
pgh->job = NULL;
@@ -92,121 +92,80 @@ handle_get_product_finished (void *cls,
{
case MHD_HTTP_OK:
{
- const char *description;
- json_t *description_i18n;
- const char *unit;
- struct TALER_Amount price;
- const char *image;
- json_t *taxes;
- int64_t total_stock;
- uint64_t total_sold;
- uint64_t total_lost;
- json_t *address;
- bool rst_ok = true;
- struct GNUNET_TIME_Timestamp next_restock
- = GNUNET_TIME_UNIT_ZERO_TS;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("description",
- &description),
- GNUNET_JSON_spec_json ("description_i18n",
- &description_i18n),
- GNUNET_JSON_spec_string ("unit",
- &unit),
- TALER_JSON_spec_amount_any ("price",
- &price),
- GNUNET_JSON_spec_string ("image",
- &image),
- GNUNET_JSON_spec_json ("taxes",
- &taxes),
- GNUNET_JSON_spec_int64 ("total_stock",
- &total_stock),
- GNUNET_JSON_spec_uint64 ("total_sold",
- &total_sold),
- GNUNET_JSON_spec_uint64 ("total_lost",
- &total_lost),
- GNUNET_JSON_spec_json ("address",
- &address),
+ GNUNET_JSON_spec_string (
+ "description",
+ &pgr.details.ok.description),
+ GNUNET_JSON_spec_object_const (
+ "description_i18n",
+ &pgr.details.ok.description_i18n),
+ GNUNET_JSON_spec_string (
+ "unit",
+ &pgr.details.ok.unit),
+ TALER_JSON_spec_amount_any (
+ "price",
+ &pgr.details.ok.price),
+ GNUNET_JSON_spec_string (
+ "image",
+ &pgr.details.ok.image),
+ GNUNET_JSON_spec_array_const (
+ "taxes",
+ &pgr.details.ok.taxes),
+ GNUNET_JSON_spec_int64 (
+ "total_stock",
+ &pgr.details.ok.total_stock),
+ GNUNET_JSON_spec_uint64 (
+ "total_sold",
+ &pgr.details.ok.total_sold),
+ GNUNET_JSON_spec_uint64 (
+ "total_lost",
+ &pgr.details.ok.total_lost),
+ GNUNET_JSON_spec_object_const (
+ "address",
+ &pgr.details.ok.location),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("next_restock",
+ &pgr.details.ok.next_restock),
+ NULL),
GNUNET_JSON_spec_end ()
};
- if (NULL !=
- json_object_get (json,
- "next_restock"))
- {
- struct GNUNET_JSON_Specification spect[] = {
- GNUNET_JSON_spec_timestamp ("next_restock",
- &next_restock),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spect,
- NULL, NULL))
- rst_ok = false;
- }
-
-
- if ( (rst_ok) &&
- (GNUNET_OK ==
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL)) )
+ if (GNUNET_OK ==
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
pgh->cb (pgh->cb_cls,
- &hr,
- description,
- description_i18n,
- unit,
- &price,
- image,
- taxes,
- total_stock,
- total_sold,
- total_lost,
- address,
- next_restock);
+ &pgr);
GNUNET_JSON_parse_free (spec);
TALER_MERCHANT_product_get_cancel (pgh);
return;
}
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- GNUNET_JSON_parse_free (spec);
+ pgr.hr.http_status = 0;
+ pgr.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);
+ pgr.hr.ec = TALER_JSON_get_error_code (json);
+ pgr.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);
+ pgr.hr.ec = TALER_JSON_get_error_code (json);
+ pgr.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);
+ pgr.hr.ec = TALER_JSON_get_error_code (json);
+ pgr.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) pgr.hr.ec);
break;
}
pgh->cb (pgh->cb_cls,
- &hr,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- 0,
- NULL,
- GNUNET_TIME_UNIT_FOREVER_TS);
+ &pgr);
TALER_MERCHANT_product_get_cancel (pgh);
}