summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/Makefile.am2
-rw-r--r--src/backend/taler-merchant-httpd.c44
-rw-r--r--src/backend/taler-merchant-httpd_auditors.c3
-rw-r--r--src/backend/taler-merchant-httpd_contract.c21
-rw-r--r--src/backend/taler-merchant-httpd_exchanges.c5
-rw-r--r--src/backend/taler-merchant-httpd_parsing.c796
-rw-r--r--src/backend/taler-merchant-httpd_parsing.h343
-rw-r--r--src/backend/taler-merchant-httpd_pay.c54
-rw-r--r--src/backend/taler-merchant-httpd_util.c7
-rw-r--r--src/include/taler_merchant_service.h3
-rw-r--r--src/include/taler_merchantdb_plugin.h1
-rw-r--r--src/lib/Makefile.am4
-rw-r--r--src/lib/merchant_api_json.c491
-rw-r--r--src/lib/merchant_api_json.h331
-rw-r--r--src/lib/merchant_api_pay.c59
-rw-r--r--src/lib/test_merchant_api.c4
16 files changed, 148 insertions, 2020 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 1d92deee..3849ac5c 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -18,8 +18,10 @@ taler_merchant_httpd_SOURCES = \
taler_merchant_httpd_LDADD = \
$(top_srcdir)/src/backenddb/libtalermerchantdb.la \
-ltalerexchange \
+ -ltalerjson \
-ltalerutil \
-ltalerpq \
-lmicrohttpd \
-ljansson \
+ -lgnunetjson \
-lgnunetutil
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 43b8296d..a445b711 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -22,14 +22,15 @@
*/
#include "platform.h"
#include <microhttpd.h>
-#include <jansson.h>
#include <gnunet/gnunet_util_lib.h>
#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
-#include "taler-merchant-httpd_parsing.h"
+#include <taler/taler_wire_plugin.h>
#include "taler-merchant-httpd_responses.h"
#include "taler_merchantdb_lib.h"
#include "taler-merchant-httpd.h"
+#include "taler-merchant-httpd_parsing.h"
#include "taler-merchant-httpd_mhd.h"
#include "taler-merchant-httpd_auditors.h"
#include "taler-merchant-httpd_exchanges.h"
@@ -337,7 +338,7 @@ static int
parse_wireformat_test (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
unsigned long long account_number;
-
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number(cfg,
"wire-test",
@@ -445,19 +446,36 @@ parse_wireformat_sepa (const struct GNUNET_CONFIGURATION_Handle *cfg)
static int
validate_and_hash_wireformat (const char *allowed)
{
- const char *allowed_arr[] = {
- allowed,
- NULL
- };
-
- if (GNUNET_YES !=
- TALER_json_validate_wireformat (allowed_arr,
- j_wire))
+ struct TALER_WIRE_Plugin *plugin;
+ char *lib_name;
+ int ret;
+
+ (void) GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_wire_%s",
+ allowed);
+ plugin = GNUNET_PLUGIN_load (lib_name,
+ NULL);
+ if (NULL == plugin)
+ {
+ GNUNET_free (lib_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Wire transfer method `%s' not supported\n",
+ allowed);
+ return GNUNET_NO;
+ }
+ plugin->library_name = lib_name;
+ ret = plugin->wire_validate (plugin->cls,
+ j_wire,
+ NULL);
+ GNUNET_PLUGIN_unload (lib_name,
+ plugin);
+ GNUNET_free (lib_name);
+ if (GNUNET_YES != ret)
return GNUNET_SYSERR;
if (GNUNET_SYSERR ==
- TALER_hash_json (j_wire,
+ TALER_JSON_hash (j_wire,
&h_wire))
- return MHD_NO;
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
diff --git a/src/backend/taler-merchant-httpd_auditors.c b/src/backend/taler-merchant-httpd_auditors.c
index 6cfa875f..0a892115 100644
--- a/src/backend/taler-merchant-httpd_auditors.c
+++ b/src/backend/taler-merchant-httpd_auditors.c
@@ -20,6 +20,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_auditors.h"
/**
@@ -209,7 +210,7 @@ TMH_AUDITORS_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
json_array_append_new (j_auditors,
json_pack ("{s:s, s:o, s:s}",
"name", auditors[cnt].name,
- "auditor_pub", TALER_json_from_data (&auditors[cnt].public_key,
+ "auditor_pub", GNUNET_JSON_from_data (&auditors[cnt].public_key,
sizeof (struct TALER_AuditorPublicKeyP)),
"uri", auditors[cnt].uri));
return nauditors;
diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c
index 14acda2d..6072a7d1 100644
--- a/src/backend/taler-merchant-httpd_contract.c
+++ b/src/backend/taler-merchant-httpd_contract.c
@@ -21,6 +21,7 @@
#include "platform.h"
#include <jansson.h>
#include <taler/taler_signatures.h>
+#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_parsing.h"
#include "taler-merchant-httpd_auditors.h"
@@ -63,11 +64,11 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
struct TALER_Amount total;
struct TALER_Amount max_fee;
uint64_t transaction_id;
- struct TMH_PARSE_FieldSpecification spec[] = {
- TMH_PARSE_member_amount ("amount", &total),
- TMH_PARSE_member_amount ("max_fee", &max_fee),
- TMH_PARSE_member_uint64 ("transaction_id", &transaction_id),
- TMH_PARSE_MEMBER_END
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("amount", &total),
+ TALER_JSON_spec_amount ("max_fee", &max_fee),
+ GNUNET_JSON_spec_uint64 ("transaction_id", &transaction_id),
+ GNUNET_JSON_spec_end()
};
if (NULL == *connection_cls)
@@ -118,16 +119,16 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
j_auditors);
json_object_set_new (jcontract,
"H_wire",
- TALER_json_from_data (&h_wire,
+ GNUNET_JSON_from_data (&h_wire,
sizeof (h_wire)));
json_object_set_new (jcontract,
"merchant_pub",
- TALER_json_from_data (&pubkey,
+ GNUNET_JSON_from_data (&pubkey,
sizeof (pubkey)));
/* create contract signature */
GNUNET_assert (GNUNET_OK ==
- TALER_hash_json (jcontract,
+ TALER_JSON_hash (jcontract,
&contract.h_contract));
contract.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT);
contract.purpose.size = htonl (sizeof (contract));
@@ -145,9 +146,9 @@ MH_handler_contract (struct TMH_RequestHandler *rh,
MHD_HTTP_OK,
"{s:O, s:O, s:O}",
"contract", jcontract,
- "merchant_sig", TALER_json_from_data (&contract_sig,
+ "merchant_sig", GNUNET_JSON_from_data (&contract_sig,
sizeof (contract_sig)),
- "H_contract", TALER_json_from_data (&contract.h_contract,
+ "H_contract", GNUNET_JSON_from_data (&contract.h_contract,
sizeof (contract.h_contract)));
json_decref (root);
return res;
diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c
index b7a5c7cc..768c119e 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014, 2015, 2016 INRIA
+ (C) 2014, 2015, 2016 INRIA
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
@@ -20,6 +20,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_exchanges.h"
@@ -502,7 +503,7 @@ TMH_EXCHANGES_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
continue;
j_exchange = json_pack ("{s:s, s:o}",
"url", exchange->uri,
- "master_pub", TALER_json_from_data (&exchange->master_pub,
+ "master_pub", GNUNET_JSON_from_data (&exchange->master_pub,
sizeof (struct TALER_MasterPublicKeyP)));
json_array_append_new (trusted_exchanges,
j_exchange);
diff --git a/src/backend/taler-merchant-httpd_parsing.c b/src/backend/taler-merchant-httpd_parsing.c
index 7b13189a..9b0a3863 100644
--- a/src/backend/taler-merchant-httpd_parsing.c
+++ b/src/backend/taler-merchant-httpd_parsing.c
@@ -23,6 +23,7 @@
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
+#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_parsing.h"
#include "taler-merchant-httpd_responses.h"
@@ -166,92 +167,6 @@ TMH_PARSE_post_cleanup_callback (void *con_cls)
/**
- * Release all memory allocated for the variable-size fields in
- * the parser specification.
- *
- * @param spec specification to free
- * @param spec_len number of items in @a spec to look at
- */
-static void
-release_data (struct TMH_PARSE_FieldSpecification *spec,
- unsigned int spec_len)
-{
- unsigned int i;
-
- for (i=0; i < spec_len; i++)
- {
- switch (spec[i].command)
- {
- case TMH_PARSE_JNC_FIELD:
- GNUNET_break (0);
- return;
- case TMH_PARSE_JNC_RET_STRING:
- GNUNET_break (0);
- return;
- case TMH_PARSE_JNC_INDEX:
- GNUNET_break (0);
- return;
- case TMH_PARSE_JNC_RET_DATA:
- break;
- case TMH_PARSE_JNC_RET_DATA_VAR:
- if (NULL != spec[i].destination)
- {
- GNUNET_free (* (void**) spec[i].destination);
- *(void**) spec[i].destination = NULL;
- *spec[i].destination_size_out = 0;
- }
- break;
- case TMH_PARSE_JNC_RET_TYPED_JSON:
- {
- json_t *json;
-
- json = *(json_t **) spec[i].destination;
- if (NULL != json)
- {
- json_decref (json);
- *(json_t**) spec[i].destination = NULL;
- }
- }
- break;
- case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY:
- {
- struct TALER_DenominationPublicKey *pk;
-
- pk = spec[i].destination;
- if (NULL != pk->rsa_public_key)
- {
- GNUNET_CRYPTO_rsa_public_key_free (pk->rsa_public_key);
- pk->rsa_public_key = NULL;
- }
- }
- break;
- case TMH_PARSE_JNC_RET_RSA_SIGNATURE:
- {
- struct TALER_DenominationSignature *sig;
-
- sig = spec[i].destination;
- if (NULL != sig->rsa_signature)
- {
- GNUNET_CRYPTO_rsa_signature_free (sig->rsa_signature);
- sig->rsa_signature = NULL;
- }
- }
- break;
- case TMH_PARSE_JNC_RET_AMOUNT:
- memset (spec[i].destination,
- 0,
- sizeof (struct TALER_Amount));
- break;
- case TMH_PARSE_JNC_RET_TIME_ABSOLUTE:
- break;
- case TMH_PARSE_JNC_RET_UINT64:
- break;
- }
- }
-}
-
-
-/**
* Process a POST request containing a JSON object. This function
* realizes an MHD POST processor that will (incrementally) process
* JSON data uploaded to the HTTP server. It will store the required
@@ -354,589 +269,6 @@ TMH_PARSE_post_json (struct MHD_Connection *connection,
/**
- * Generate line in parser specification for string. The returned
- * string is already nul-terminated internally by JSON, so no length
- * information is provided. The string will live as long as the containg
- * JSON will, and must not be freed by the user
- * @param field name of the field
- * @param[out] pointer to the string
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_string (const char *field,
- char **out)
-{
- struct TMH_PARSE_FieldSpecification ret =
- {field, (void **) out, 0, NULL, TMH_PARSE_JNC_RET_STRING, 0};
- return ret;
-}
-
-/**
- * Generate line in parser specification for 64-bit integer
- * given as an integer in JSON.
- *
- * @param field name of the field
- * @param[out] u64 integer to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_uint64 (const char *field,
- uint64_t *u64)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, (void *) u64, sizeof (uint64_t), NULL, TMH_PARSE_JNC_RET_UINT64, 0 };
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for JSON object value.
- *
- * @param field name of the field
- * @param[out] jsonp address of pointer to JSON to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_object (const char *field,
- json_t **jsonp)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, jsonp, 0, NULL, TMH_PARSE_JNC_RET_TYPED_JSON, JSON_OBJECT };
- *jsonp = NULL;
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for JSON array value.
- *
- * @param field name of the field
- * @param[out] jsonp address of JSON pointer to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_array (const char *field,
- json_t **jsonp)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, jsonp, 0, NULL, TMH_PARSE_JNC_RET_TYPED_JSON, JSON_ARRAY };
- *jsonp = NULL;
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for an absolute time.
- *
- * @param field name of the field
- * @param[out] atime time to initialize
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_time_abs (const char *field,
- struct GNUNET_TIME_Absolute *atime)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, atime, sizeof(struct GNUNET_TIME_Absolute), NULL, TMH_PARSE_JNC_RET_TIME_ABSOLUTE, 0 };
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for RSA public key.
- *
- * @param field name of the field
- * @param[out] pk key to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_denomination_public_key (const char *field,
- struct TALER_DenominationPublicKey *pk)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, pk, 0, NULL, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, 0 };
- pk->rsa_public_key = NULL;
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for RSA public key.
- *
- * @param field name of the field
- * @param sig the signature to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_denomination_signature (const char *field,
- struct TALER_DenominationSignature *sig)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, sig, 0, NULL, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 };
- sig->rsa_signature = NULL;
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for an amount.
- *
- * @param field name of the field
- * @param amount a `struct TALER_Amount *` to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_amount (const char *field,
- struct TALER_Amount *amount)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, amount, sizeof(struct TALER_Amount), NULL, TMH_PARSE_JNC_RET_AMOUNT, 0 };
- memset (amount, 0, sizeof (struct TALER_Amount));
- return ret;
-}
-
-
-/**
- * Generate line in parser specification for variable-size value.
- *
- * @param field name of the field
- * @param[out] ptr pointer to initialize
- * @param[out] ptr_size size to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_variable (const char *field,
- void **ptr,
- size_t *ptr_size)
-{
- struct TMH_PARSE_FieldSpecification ret =
- { field, ptr, 0, ptr_size, TMH_PARSE_JNC_RET_DATA_VAR, 0 };
- *ptr = NULL;
- return ret;
-}
-
-/**
- * Navigate through a JSON tree.
- *
- * Sends an error response if navigation is impossible (i.e.
- * the JSON object is invalid)
- *
- * @param connection the connection to send an error response to
- * @param root the JSON node to start the navigation at.
- * @param ... navigation specification (see
- * `enum TMH_PARSE_JsonNavigationCommand`)
- * @return
- * #GNUNET_YES if navigation was successful
- * #GNUNET_NO if json is malformed, error response was generated
- * #GNUNET_SYSERR on internal error (no response was generated,
- * connection must be closed)
- */
-int
-TMH_PARSE_navigate_json (struct MHD_Connection *connection,
- const json_t *root,
- ...)
-{
- va_list argp;
- int ret;
- json_t *path; /* what's our current path from 'root'? */
-
- path = json_array ();
- va_start (argp, root);
- ret = 2; /* just not any of the valid return values */
- while (2 == ret)
- {
- enum TMH_PARSE_JsonNavigationCommand command
- = va_arg (argp,
- enum TMH_PARSE_JsonNavigationCommand);
-
- switch (command)
- {
- case TMH_PARSE_JNC_FIELD:
- {
- const char *fname = va_arg(argp, const char *);
-
- json_array_append_new (path,
- json_string (fname));
- root = json_object_get (root,
- fname);
- if (NULL == root)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:s, s:O}",
- "error", "missing field in JSON",
- "field", fname,
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- }
- break;
-
- case TMH_PARSE_JNC_INDEX:
- {
- int fnum = va_arg(argp, int);
-
- json_array_append_new (path,
- json_integer (fnum));
- root = json_array_get (root,
- fnum);
- if (NULL == root)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "missing index in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- }
- break;
-
- case TMH_PARSE_JNC_RET_DATA:
- {
- void *where = va_arg (argp, void *);
- size_t len = va_arg (argp, size_t);
- const char *str;
- int res;
-
- str = json_string_value (root);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "string expected",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- res = GNUNET_STRINGS_string_to_data (str, strlen (str),
- where, len);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed binary data in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- ret = GNUNET_OK;
- }
- break;
-
- case TMH_PARSE_JNC_RET_STRING:
- {
- void **where = va_arg (argp, void **);
- *where = (void*) json_string_value (root);
- ret = GNUNET_OK;
- }
- break;
- case TMH_PARSE_JNC_RET_DATA_VAR:
- {
- void **where = va_arg (argp, void **);
- size_t *len = va_arg (argp, size_t *);
- const char *str;
- int res;
-
- str = json_string_value (root);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_internal_error (connection,
- "json_string_value() failed"))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- *len = (strlen (str) * 5) / 8;
- if (NULL != where)
- {
- *where = GNUNET_malloc (*len);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- *where,
- *len);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- GNUNET_free (*where);
- *where = NULL;
- *len = 0;
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed binary data in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- }
- ret = GNUNET_OK;
- }
- break;
-
- case TMH_PARSE_JNC_RET_TYPED_JSON:
- {
- int typ = va_arg (argp, int);
- const json_t **r_json = va_arg (argp, const json_t **);
-
- if ( (NULL == root) ||
- ( (-1 != typ) &&
- (json_typeof (root) != typ)) )
- {
- GNUNET_break_op (0);
- *r_json = NULL;
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:i, s:i, s:O}",
- "error", "wrong JSON field type",
- "type_expected", typ,
- "type_actual", json_typeof (root),
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- *r_json = root;
- json_incref ((json_t *) root);
- ret = GNUNET_OK;
- }
- break;
-
- case TMH_PARSE_JNC_RET_UINT64:
- {
- uint64_t *r_u64 = va_arg (argp, uint64_t *);
-
- if (json_typeof (root) != JSON_INTEGER)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:s, s:i, s:O}",
- "error", "wrong JSON field type",
- "type_expected", "integer",
- "type_actual", json_typeof (root),
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- *r_u64 = (uint64_t) json_integer_value (root);
- ret = GNUNET_OK;
- }
- break;
-
- case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY:
- {
- struct TALER_DenominationPublicKey *where;
- size_t len;
- const char *str;
- int res;
- void *buf;
-
- where = va_arg (argp,
- struct TALER_DenominationPublicKey *);
- str = json_string_value (root);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "string expected",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- len = (strlen (str) * 5) / 8;
- buf = GNUNET_malloc (len);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- buf,
- len);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- GNUNET_free (buf);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed binary data in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- where->rsa_public_key = GNUNET_CRYPTO_rsa_public_key_decode (buf,
- len);
- GNUNET_free (buf);
- if (NULL == where->rsa_public_key)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed RSA public key in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- ret = GNUNET_OK;
- break;
- }
-
- case TMH_PARSE_JNC_RET_RSA_SIGNATURE:
- {
- struct TALER_DenominationSignature *where;
- size_t len;
- const char *str;
- int res;
- void *buf;
-
- where = va_arg (argp,
- struct TALER_DenominationSignature *);
- str = json_string_value (root);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "string expected",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- len = (strlen (str) * 5) / 8;
- buf = GNUNET_malloc (len);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- buf,
- len);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- GNUNET_free (buf);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed binary data in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- where->rsa_signature = GNUNET_CRYPTO_rsa_signature_decode (buf,
- len);
- GNUNET_free (buf);
- if (NULL == where->rsa_signature)
- {
- GNUNET_break_op (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "malformed RSA signature in JSON",
- "path", path))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- ret = GNUNET_OK;
- break;
- }
-
- case TMH_PARSE_JNC_RET_AMOUNT:
- {
- struct TALER_Amount *where = va_arg (argp, void *);
-
- if (GNUNET_OK !=
- TALER_json_to_amount ((json_t *) root,
- where))
- {
- GNUNET_break_op (0);
- ret = (MHD_YES !=
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O}",
- "error", "Bad format",
- "path", path))
- ? GNUNET_SYSERR : GNUNET_NO;
- break;
- }
- if (0 != strcmp (where->currency,
- TMH_merchant_currency_string))
- {
- GNUNET_break_op (0);
- ret = (MHD_YES !=
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:O, s:s}",
- "error", "Currency not supported",
- "path", path,
- "currency", where->currency))
- ? GNUNET_SYSERR : GNUNET_NO;
- memset (where, 0, sizeof (struct TALER_Amount));
- break;
- }
- ret = GNUNET_OK;
- break;
- }
-
- case TMH_PARSE_JNC_RET_TIME_ABSOLUTE:
- {
- struct GNUNET_TIME_Absolute *where = va_arg (argp, void *);
-
- if (GNUNET_OK !=
- TALER_json_to_abs ((json_t *) root,
- where))
- {
- GNUNET_break_op (0);
- ret = (MHD_YES !=
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
- "{s:s, s:s, s:O}",
- "error", "Bad format",
- "hint", "expected absolute time",
- "path", path))
- ? GNUNET_SYSERR : GNUNET_NO;
- break;
- }
- ret = GNUNET_OK;
- break;
- }
-
- default:
- GNUNET_break (0);
- ret = (MHD_YES ==
- TMH_RESPONSE_reply_internal_error (connection,
- "unhandled value in switch"))
- ? GNUNET_NO : GNUNET_SYSERR;
- break;
- }
- }
- va_end (argp);
- json_decref (path);
- return ret;
-}
-
-
-
-/**
* Parse JSON object into components based on the given field
* specification.
*
@@ -946,119 +278,39 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection,
* @return
* #GNUNET_YES if navigation was successful (caller is responsible
* for freeing allocated variable-size data using
- * #TMH_PARSE_release_data() when done)
+ * #GNUNET_JSON_parse_free() when done)
* #GNUNET_NO if json is malformed, error response was generated
* #GNUNET_SYSERR on internal error
*/
int
TMH_PARSE_json_data (struct MHD_Connection *connection,
const json_t *root,
- struct TMH_PARSE_FieldSpecification *spec)
+ struct GNUNET_JSON_Specification *spec)
{
- unsigned int i;
int ret;
-
- ret = GNUNET_YES;
- for (i=0; NULL != spec[i].field_name; i++)
+ const char *error_json_name;
+ unsigned int error_line;
+
+ ret = GNUNET_JSON_parse (root,
+ spec,
+ &error_json_name,
+ &error_line);
+ if (GNUNET_SYSERR == ret)
{
- if (GNUNET_YES != ret)
- break;
- switch (spec[i].command)
- {
- case TMH_PARSE_JNC_FIELD:
- GNUNET_break (0);
- return GNUNET_SYSERR;
- case TMH_PARSE_JNC_INDEX:
- GNUNET_break (0);
- return GNUNET_SYSERR;
- case TMH_PARSE_JNC_RET_DATA:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_DATA,
- spec[i].destination,
- spec[i].destination_size_in);
- break;
- case TMH_PARSE_JNC_RET_DATA_VAR:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_DATA_VAR,
- (void **) spec[i].destination,
- spec[i].destination_size_out);
- break;
- case TMH_PARSE_JNC_RET_STRING:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_STRING,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_TYPED_JSON:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_TYPED_JSON,
- spec[i].type,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_RSA_SIGNATURE:
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_RSA_SIGNATURE,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_AMOUNT:
- GNUNET_assert (sizeof (struct TALER_Amount) ==
- spec[i].destination_size_in);
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_AMOUNT,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_TIME_ABSOLUTE:
- GNUNET_assert (sizeof (struct GNUNET_TIME_Absolute) ==
- spec[i].destination_size_in);
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_TIME_ABSOLUTE,
- spec[i].destination);
- break;
- case TMH_PARSE_JNC_RET_UINT64:
- GNUNET_assert (sizeof (uint64_t) ==
- spec[i].destination_size_in);
- ret = TMH_PARSE_navigate_json (connection,
- root,
- TMH_PARSE_JNC_FIELD,
- spec[i].field_name,
- TMH_PARSE_JNC_RET_UINT64,
- spec[i].destination);
- break;
- }
+ if (NULL == error_json_name)
+ error_json_name = "<no field>";
+ ret = (MHD_YES ==
+ TMH_RESPONSE_reply_json_pack (connection,
+ MHD_HTTP_BAD_REQUEST,
+ "{s:s, s:s, s:I}",
+ "error", "parse error",
+ "field", error_json_name,
+ "line", (json_int_t) error_line))
+ ? GNUNET_NO : GNUNET_SYSERR;
+ return ret;
}
- if (GNUNET_YES != ret)
- release_data (spec,
- i - 1);
- return ret;
+ return GNUNET_YES;
}
-/* end of taler-exchange-httpd_parsing.c */
+/* end of taler-merchant-httpd_parsing.c */
diff --git a/src/backend/taler-merchant-httpd_parsing.h b/src/backend/taler-merchant-httpd_parsing.h
index 9e78768e..45f30458 100644
--- a/src/backend/taler-merchant-httpd_parsing.h
+++ b/src/backend/taler-merchant-httpd_parsing.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2016 GNUnet e.V.
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
@@ -24,8 +24,8 @@
#define TALER_EXCHANGE_HTTPD_PARSING_H
#include <microhttpd.h>
-#include <jansson.h>
#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
/**
* Process a POST request containing a JSON object. This
@@ -71,155 +71,6 @@ TMH_PARSE_post_cleanup_callback (void *con_cls);
/**
- * Constants for JSON navigation description.
- */
-enum TMH_PARSE_JsonNavigationCommand
-{
- /**
- * Access a field.
- * Param: const char *
- */
- TMH_PARSE_JNC_FIELD,
-
- /**
- * Access an array index.
- * Param: int
- */
- TMH_PARSE_JNC_INDEX,
-
- /**
- * Return base32crockford encoded data of
- * constant size.
- * Params: (void *, size_t)
- */
- TMH_PARSE_JNC_RET_DATA,
-
- /**
- * Return base32crockford encoded data of
- * variable size.
- * Params: (void **, size_t *)
- */
- TMH_PARSE_JNC_RET_DATA_VAR,
-
- /**
- * Return a json object, which must be
- * of the given type (JSON_* type constants,
- * or -1 for any type).
- * Params: (int, json_t **)
- */
- TMH_PARSE_JNC_RET_TYPED_JSON,
-
- /**
- * Return a `struct GNUNET_CRYPTO_rsa_PublicKey` which was
- * encoded as variable-size base32crockford encoded data.
- */
- TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY,
-
- /**
- * Return a `struct GNUNET_CRYPTO_rsa_Signature` which was
- * encoded as variable-size base32crockford encoded data.
- */
- TMH_PARSE_JNC_RET_RSA_SIGNATURE,
-
- /**
- * Return a `struct TALER_Amount` which was
- * encoded within its own json object.
- */
- TMH_PARSE_JNC_RET_AMOUNT,
-
- /**
- * Return a `struct GNUNET_TIME_Absolute` which was
- * encoded within its own json object.
- * Param: struct GNUNET_TIME_Absolute *
- */
- TMH_PARSE_JNC_RET_TIME_ABSOLUTE,
-
- /**
- * Return a `uint64_t` which was
- * encoded as a JSON integer.
- * Param: uint64_t *
- */
- TMH_PARSE_JNC_RET_UINT64,
- /**
- * Return a 'char *' as returned from 'json_string_value ()'.
- * So it will live as long as the containg JSON is not freed,
- * and must not be freed by the user
- */
- TMH_PARSE_JNC_RET_STRING
-
-};
-
-
-/**
- * Navigate through a JSON tree.
- *
- * Sends an error response if navigation is impossible (i.e.
- * the JSON object is invalid)
- *
- * @param connection the connection to send an error response to
- * @param root the JSON node to start the navigation at.
- * @param ... navigation specification (see `enum TMH_PARSE_JsonNavigationCommand`)
- * @return
- * #GNUNET_YES if navigation was successful
- * #GNUNET_NO if json is malformed, error response was generated
- * #GNUNET_SYSERR on internal error
- */
-int
-TMH_PARSE_navigate_json (struct MHD_Connection *connection,
- const json_t *root,
- ...);
-
-
-/**
- * @brief Specification for how to parse a JSON field.
- */
-struct TMH_PARSE_FieldSpecification
-{
- /**
- * Name of the field. NULL only to terminate array.
- */
- const char *field_name;
-
- /**
- * Where to store the result. Must have exactly
- * @e destination_size bytes, except if @e destination_size is zero.
- * NULL to skip assignment (but check presence of the value).
- */
- void *destination;
-
- /**
- * How big should the result be, 0 for variable size. In
- * this case, @e destination must be a "void **", pointing
- * to a location that is currently NULL and is to be allocated.
- */
- size_t destination_size_in;
-
- /**
- * @e destination_size_out will then be set to the size of the
- * value that was stored in @e destination (useful for
- * variable-size allocations).
- */
- size_t *destination_size_out;
-
- /**
- * Navigation command to use to extract the value. Note that
- * #TMH_PARSE_JNC_RET_DATA or #TMH_PARSE_JNC_RET_DATA_VAR must be used for @e
- * destination_size_in and @e destination_size_out to have a
- * meaning. #TMH_PARSE_JNC_FIELD and #TMH_PARSE_JNC_INDEX must not be used here!
- */
- enum TMH_PARSE_JsonNavigationCommand command;
-
- /**
- * JSON type to use, only meaningful in connection with a @e command
- * value of #TMH_PARSE_JNC_RET_TYPED_JSON. Typical values are
- * #JSON_ARRAY and #JSON_OBJECT.
- */
- int type;
-
-};
-
-
-/**
* Parse JSON object into components based on the given field
* specification.
*
@@ -229,198 +80,14 @@ struct TMH_PARSE_FieldSpecification
* @return
* #GNUNET_YES if navigation was successful (caller is responsible
* for freeing allocated variable-size data using
- * #TMH_PARSE_release_data() when done)
+ * #GNUNET_JSON_parse_free() when done)
* #GNUNET_NO if json is malformed, error response was generated
* #GNUNET_SYSERR on internal error
*/
int
TMH_PARSE_json_data (struct MHD_Connection *connection,
const json_t *root,
- struct TMH_PARSE_FieldSpecification *spec);
-
-
-/**
- * Release all memory allocated for the variable-size fields in
- * the parser specification.
- *
- * @param spec specification to free
- */
-void
-TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec);
-
-
-/**
- * Generate line in parser specification for fixed-size value.
- *
- * @param field name of the field
- * @param value where to store the value
- */
-#define TMH_PARSE_member_fixed(field,value) { field, value, sizeof (*value), NULL, TMH_PARSE_JNC_RET_DATA, 0 }
-
-
-/**
- * Generate line in parser specification for variable-size value.
- *
- * @param field name of the field
- * @param[out] ptr pointer to initialize
- * @param[out] ptr_size size to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_variable (const char *field,
- void **ptr,
- size_t *ptr_size);
-
-/**
- * Generate line in parser specification for string. The returned
- * string is already nul-terminated internally by JSON, so no length
- * information is provided. The string will live as long as the containg
- * JSON will, and must not be freed by the user
- * @param field name of the field
- * @param[out] pointer to the string
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_string (const char *field,
- char **out);
-
-
-/**
- * Generate line in parser specification for 64-bit integer
- * given as an integer in JSON.
- *
- * @param field name of the field
- * @param[out] u64 integer to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_uint64 (const char *field,
- uint64_t *u64);
-
-
-/**
- * Generate line in parser specification for JSON array value.
- *
- * @param field name of the field
- * @param[out] jsonp address of JSON pointer to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_array (const char *field,
- json_t **jsonp);
-
-
-/**
- * Generate line in parser specification for JSON object value.
- *
- * @param field name of the field
- * @param[out] jsonp address of pointer to JSON to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_object (const char *field,
- json_t **jsonp);
-
-
-/**
- * Generate line in parser specification for RSA public key.
- *
- * @param field name of the field
- * @param[out] pk key to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_denomination_public_key (const char *field,
- struct TALER_DenominationPublicKey *pk);
-
-
-/**
- * Generate line in parser specification for RSA public key.
- *
- * @param field name of the field
- * @param sig the signature to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_denomination_signature (const char *field,
- struct TALER_DenominationSignature *sig);
-
-
-/**
- * Generate line in parser specification for an amount.
- *
- * @param field name of the field
- * @param[out] amount a `struct TALER_Amount *` to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_amount (const char *field,
- struct TALER_Amount *amount);
-
-
-/**
- * Generate line in parser specification for an absolute time.
- *
- * @param field name of the field
- * @param[out] atime time to initialize
- * @return corresponding field spec
- */
-struct TMH_PARSE_FieldSpecification
-TMH_PARSE_member_time_abs (const char *field,
- struct GNUNET_TIME_Absolute *atime);
-
-
-
-/**
- * Generate line in parser specification indicating the end of the spec.
- */
-#define TMH_PARSE_MEMBER_END { NULL, NULL, 0, NULL, TMH_PARSE_JNC_FIELD, 0 }
-
-
-/**
- * Extraxt fixed-size base32crockford encoded data from request.
- *
- * Queues an error response to the connection if the parameter is missing or
- * invalid.
- *
- * @param connection the MHD connection
- * @param param_name the name of the parameter with the key
- * @param[out] out_data pointer to store the result
- * @param out_size expected size of @a out_data
- * @return
- * #GNUNET_YES if the the argument is present
- * #GNUNET_NO if the argument is absent or malformed
- * #GNUNET_SYSERR on internal error (error response could not be sent)
- */
-int
-TMH_PARSE_mhd_request_arg_data (struct MHD_Connection *connection,
- const char *param_name,
- void *out_data,
- size_t out_size);
-
-
-/**
- * Extraxt variable-size base32crockford encoded data from request.
- *
- * Queues an error response to the connection if the parameter is missing
- * or the encoding is invalid.
- *
- * @param connection the MHD connection
- * @param param_name the name of the parameter with the key
- * @param[out] out_data pointer to allocate buffer and store the result
- * @param[out] out_size set to the size of the buffer allocated in @a out_data
- * @return
- * #GNUNET_YES if the the argument is present
- * #GNUNET_NO if the argument is absent or malformed
- * #GNUNET_SYSERR on internal error (error response could not be sent)
- */
-int
-TMH_PARSE_mhd_request_var_arg_data (struct MHD_Connection *connection,
- const char *param_name,
- void **out_data,
- size_t *out_size);
-
-
+ struct GNUNET_JSON_Specification *spec);
-#endif /* TALER_EXCHANGE_HTTPD_PARSING_H */
+#endif /* TALER_MERCHANT_HTTPD_PARSING_H */
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
index 035d6242..136b6ef3 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -426,7 +426,7 @@ process_pay_with_exchange (void *cls,
MHD_HTTP_BAD_REQUEST,
TMH_RESPONSE_make_json_pack ("{s:s, s:o}",
"hint", "unknown denom to exchange",
- "denom_pub", TALER_json_from_rsa_public_key (dc->denom.rsa_public_key)));
+ "denom_pub", GNUNET_JSON_from_rsa_public_key (dc->denom.rsa_public_key)));
return;
}
if (GNUNET_OK !=
@@ -439,7 +439,7 @@ process_pay_with_exchange (void *cls,
MHD_HTTP_BAD_REQUEST,
TMH_RESPONSE_make_json_pack ("{s:s, s:o}",
"hint", "no acceptable auditor for denomination",
- "denom_pub", TALER_json_from_rsa_public_key (dc->denom.rsa_public_key)));
+ "denom_pub", GNUNET_JSON_from_rsa_public_key (dc->denom.rsa_public_key)));
return;
}
if (0 == i)
@@ -477,8 +477,8 @@ process_pay_with_exchange (void *cls,
MHD_HTTP_BAD_REQUEST,
TMH_RESPONSE_make_json_pack ("{s:s, s:o, s:o}",
"hint", "fee higher than coin value",
- "f", TALER_json_from_amount (&dc->percoin_amount),
- "fee_deposit", TALER_json_from_amount (&denom_details->fee_deposit)));
+ "f", TALER_JSON_from_amount (&dc->percoin_amount),
+ "fee_deposit", TALER_JSON_from_amount (&denom_details->fee_deposit)));
return;
}
}
@@ -641,29 +641,29 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
unsigned int coins_index;
struct TALER_MerchantSignatureP merchant_sig;
struct TALER_ContractPS cp;
- struct TMH_PARSE_FieldSpecification spec[] = {
- TMH_PARSE_member_amount ("amount", &pc->amount),
- TMH_PARSE_member_array ("coins", &coins),
- TMH_PARSE_member_fixed ("H_contract", &pc->h_contract),
- TMH_PARSE_member_amount ("max_fee", &pc->max_fee),
- TMH_PARSE_member_fixed ("merchant_sig", &merchant_sig),
- TMH_PARSE_member_string ("exchange", &pc->chosen_exchange),
- TMH_PARSE_member_time_abs ("refund_deadline", &pc->refund_deadline),
- TMH_PARSE_member_time_abs ("timestamp", &pc->timestamp),
- TMH_PARSE_member_uint64 ("transaction_id", &pc->transaction_id),
- TMH_PARSE_MEMBER_END
+ const char *chosen_exchange;
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("amount", &pc->amount),
+ GNUNET_JSON_spec_json ("coins", &coins),
+ GNUNET_JSON_spec_fixed_auto ("H_contract", &pc->h_contract),
+ TALER_JSON_spec_amount ("max_fee", &pc->max_fee),
+ GNUNET_JSON_spec_fixed_auto ("merchant_sig", &merchant_sig),
+ GNUNET_JSON_spec_string ("exchange", &chosen_exchange),
+ GNUNET_JSON_spec_absolute_time ("refund_deadline", &pc->refund_deadline),
+ GNUNET_JSON_spec_absolute_time ("timestamp", &pc->timestamp),
+ GNUNET_JSON_spec_uint64 ("transaction_id", &pc->transaction_id),
+ GNUNET_JSON_spec_end()
};
res = TMH_PARSE_json_data (connection,
root,
spec);
-
if (GNUNET_YES != res)
{
json_decref (root);
return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
-
+ pc->chosen_exchange = GNUNET_strdup (chosen_exchange);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Parsed JSON for /pay.\n");
cp.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_CONTRACT);
@@ -696,9 +696,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
}
else
{
- struct TMH_PARSE_FieldSpecification espec[] = {
- TMH_PARSE_member_time_abs ("edate", &pc->edate),
- TMH_PARSE_MEMBER_END
+ struct GNUNET_JSON_Specification espec[] = {
+ GNUNET_JSON_spec_absolute_time ("edate", &pc->edate),
+ GNUNET_JSON_spec_end()
};
res = TMH_PARSE_json_data (connection,
@@ -731,13 +731,13 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
json_array_foreach (coins, coins_index, coin)
{
struct MERCHANT_DepositConfirmation *dc = &pc->dc[coins_index];
- struct TMH_PARSE_FieldSpecification spec[] = {
- TMH_PARSE_member_denomination_public_key ("denom_pub", &dc->denom),
- TMH_PARSE_member_amount ("f", &dc->percoin_amount),
- TMH_PARSE_member_fixed ("coin_pub", &dc->coin_pub),
- TMH_PARSE_member_denomination_signature ("ub_sig", &dc->ub_sig),
- TMH_PARSE_member_fixed ("coin_sig", &dc->coin_sig),
- TMH_PARSE_MEMBER_END
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_denomination_public_key ("denom_pub", &dc->denom),
+ TALER_JSON_spec_amount ("f", &dc->percoin_amount),
+ GNUNET_JSON_spec_fixed_auto ("coin_pub", &dc->coin_pub),
+ TALER_JSON_spec_denomination_signature ("ub_sig", &dc->ub_sig),
+ GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig),
+ GNUNET_JSON_spec_end()
};
res = TMH_PARSE_json_data (connection,
diff --git a/src/backend/taler-merchant-httpd_util.c b/src/backend/taler-merchant-httpd_util.c
index 8bf60cbb..97d1db67 100644
--- a/src/backend/taler-merchant-httpd_util.c
+++ b/src/backend/taler-merchant-httpd_util.c
@@ -21,6 +21,7 @@
#include "platform.h"
#include <jansson.h>
#include <taler/taler_signatures.h>
+#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_parsing.h"
#include "taler-merchant-httpd_auditors.h"
@@ -85,7 +86,7 @@ MH_handler_hash_contract (struct TMH_RequestHandler *rh,
"missing 'contract' field");
}
- if (GNUNET_OK != TALER_hash_json (jcontract,
+ if (GNUNET_OK != TALER_JSON_hash (jcontract,
&hc))
{
return TMH_RESPONSE_reply_external_error (connection,
@@ -93,14 +94,14 @@ MH_handler_hash_contract (struct TMH_RequestHandler *rh,
}
GNUNET_assert (GNUNET_OK ==
- TALER_hash_json (jcontract,
+ TALER_JSON_hash (jcontract,
&hc));
/* return final response */
res = TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
"{s:O}",
- "hash", TALER_json_from_data (&hc,
+ "hash", GNUNET_JSON_from_data (&hc,
sizeof (hc)));
json_decref (root);
return res;
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 07ff033c..a0982ab0 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -22,6 +22,7 @@
#define _TALER_MERCHANT_SERVICE_H
#include <taler/taler_util.h>
+#include <jansson.h>
/* ********************* event loop *********************** */
@@ -281,7 +282,7 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
const struct TALER_Amount *max_fee,
uint64_t transaction_id,
const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_MerchantPublicKeyP *merchant_sig,
+ const struct TALER_MerchantSignatureP *merchant_sig,
struct GNUNET_TIME_Absolute refund_deadline,
struct GNUNET_TIME_Absolute timestamp,
struct GNUNET_TIME_Absolute execution_deadline,
diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h
index d5251d67..85d8168c 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -23,6 +23,7 @@
#define TALER_MERCHANTDB_PLUGIN_H
#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
/**
* Handle to interact with the database.
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 81ad63fe..0d163d7e 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -15,10 +15,12 @@ libtalermerchant_la_LDFLAGS = \
libtalermerchant_la_SOURCES = \
merchant_api_context.c merchant_api_context.h \
- merchant_api_json.c merchant_api_json.h \
merchant_api_pay.c
libtalermerchant_la_LIBADD = \
+ -ltalerjson \
+ -ltalerutil \
+ -lgnunetjson \
-lgnunetutil \
-ljansson \
$(XLIB)
diff --git a/src/lib/merchant_api_json.c b/src/lib/merchant_api_json.c
deleted file mode 100644
index f3caac30..00000000
--- a/src/lib/merchant_api_json.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015, 2016 GNUnet e.V.
-
- 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
- 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 Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING.LGPL. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/merchant_api_json.c
- * @brief functions to parse incoming requests (JSON snippets)
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "merchant_api_json.h"
-
-/**
- * Navigate and parse data in a JSON tree.
- *
- * @param root the JSON node to start the navigation at.
- * @param spec parse specification array
- * @return offset in @a spec where parsing failed, -1 on success (!)
- */
-static int
-parse_json (json_t *root,
- struct MAJ_Specification *spec)
-{
- int i;
- json_t *pos; /* what's our current position? */
-
- pos = root;
- for (i=0;MAJ_CMD_END != spec[i].cmd;i++)
- {
- pos = json_object_get (root,
- spec[i].field);
- if (NULL == pos)
- {
- GNUNET_break_op (0);
- return i;
- }
- switch (spec[i].cmd)
- {
- case MAJ_CMD_END:
- GNUNET_assert (0);
- return i;
- case MAJ_CMD_AMOUNT:
- if (GNUNET_OK !=
- TALER_json_to_amount (pos,
- spec[i].details.amount))
- {
- GNUNET_break_op (0);
- return i;
- }
- break;
- case MAJ_CMD_TIME_ABSOLUTE:
- if (GNUNET_OK !=
- TALER_json_to_abs (pos,
- spec[i].details.abs_time))
- {
- GNUNET_break_op (0);
- return i;
- }
- break;
-
- case MAJ_CMD_STRING:
- {
- const char *str;
-
- str = json_string_value (pos);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return i;
- }
- *spec[i].details.strptr = str;
- }
- break;
-
- case MAJ_CMD_BINARY_FIXED:
- {
- const char *str;
- int res;
-
- str = json_string_value (pos);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return i;
- }
- res = GNUNET_STRINGS_string_to_data (str, strlen (str),
- spec[i].details.fixed_data.dest,
- spec[i].details.fixed_data.dest_size);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- return i;
- }
- }
- break;
-
- case MAJ_CMD_BINARY_VARIABLE:
- {
- const char *str;
- size_t size;
- void *data;
- int res;
-
- str = json_string_value (pos);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return i;
- }
- size = (strlen (str) * 5) / 8;
- if (size >= 1024)
- {
- GNUNET_break_op (0);
- return i;
- }
- data = GNUNET_malloc (size);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- data,
- size);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- GNUNET_free (data);
- return i;
- }
- *spec[i].details.variable_data.dest_p = data;
- *spec[i].details.variable_data.dest_size_p = size;
- }
- break;
-
- case MAJ_CMD_RSA_PUBLIC_KEY:
- {
- size_t size;
- const char *str;
- int res;
- void *buf;
-
- str = json_string_value (pos);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return i;
- }
- size = (strlen (str) * 5) / 8;
- buf = GNUNET_malloc (size);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- buf,
- size);
- if (GNUNET_OK != res)
- {
- GNUNET_free (buf);
- GNUNET_break_op (0);
- return i;
- }
- *spec[i].details.rsa_public_key
- = GNUNET_CRYPTO_rsa_public_key_decode (buf,
- size);
- GNUNET_free (buf);
- if (NULL == spec[i].details.rsa_public_key)
- {
- GNUNET_break_op (0);
- return i;
- }
- }
- break;
-
- case MAJ_CMD_RSA_SIGNATURE:
- {
- size_t size;
- const char *str;
- int res;
- void *buf;
-
- str = json_string_value (pos);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return i;
- }
- size = (strlen (str) * 5) / 8;
- buf = GNUNET_malloc (size);
- res = GNUNET_STRINGS_string_to_data (str,
- strlen (str),
- buf,
- size);
- if (GNUNET_OK != res)
- {
- GNUNET_free (buf);
- GNUNET_break_op (0);
- return i;
- }
- *spec[i].details.rsa_signature
- = GNUNET_CRYPTO_rsa_signature_decode (buf,
- size);
- GNUNET_free (buf);
- if (NULL == spec[i].details.rsa_signature)
- return i;
- }
- break;
-
- case MAJ_CMD_UINT16:
- {
- json_int_t val;
-
- if (! json_is_integer (pos))
- {
- GNUNET_break_op (0);
- return i;
- }
- val = json_integer_value (pos);
- if ( (0 > val) || (val > UINT16_MAX) )
- {
- GNUNET_break_op (0);
- return i;
- }
- *spec[i].details.u16 = (uint16_t) val;
- }
- break;
-
- case MAJ_CMD_JSON_OBJECT:
- {
- if (! (json_is_object (pos) || json_is_array (pos)) )
- {
- GNUNET_break_op (0);
- return i;
- }
- json_incref (pos);
- *spec[i].details.obj = pos;
- }
- break;
-
- default:
- GNUNET_break (0);
- return i;
- }
- }
- return -1; /* all OK! */
-}
-
-
-/**
- * Free all elements allocated during a
- * #MAJ_parse_json() operation.
- *
- * @param spec specification of the parse operation
- * @param end number of elements in @a spec to process
- */
-static void
-parse_free (struct MAJ_Specification *spec,
- int end)
-{
- int i;
-
- for (i=0;i<end;i++)
- {
- switch (spec[i].cmd)
- {
- case MAJ_CMD_END:
- GNUNET_assert (0);
- return;
- case MAJ_CMD_AMOUNT:
- break;
- case MAJ_CMD_TIME_ABSOLUTE:
- break;
- case MAJ_CMD_BINARY_FIXED:
- break;
- case MAJ_CMD_STRING:
- break;
- case MAJ_CMD_BINARY_VARIABLE:
- GNUNET_free (*spec[i].details.variable_data.dest_p);
- *spec[i].details.variable_data.dest_p = NULL;
- *spec[i].details.variable_data.dest_size_p = 0;
- break;
- case MAJ_CMD_RSA_PUBLIC_KEY:
- GNUNET_CRYPTO_rsa_public_key_free (*spec[i].details.rsa_public_key);
- *spec[i].details.rsa_public_key = NULL;
- break;
- case MAJ_CMD_RSA_SIGNATURE:
- GNUNET_CRYPTO_rsa_signature_free (*spec[i].details.rsa_signature);
- *spec[i].details.rsa_signature = NULL;
- break;
- case MAJ_CMD_JSON_OBJECT:
- json_decref (*spec[i].details.obj);
- *spec[i].details.obj = NULL;
- break;
- default:
- GNUNET_break (0);
- break;
- }
- }
-}
-
-
-/**
- * Navigate and parse data in a JSON tree.
- *
- * @param root the JSON node to start the navigation at.
- * @param spec parse specification array
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-MAJ_parse_json (const json_t *root,
- struct MAJ_Specification *spec)
-{
- int ret;
-
- ret = parse_json ((json_t *) root,
- spec);
- if (-1 == ret)
- return GNUNET_OK;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "JSON field `%s` (%d) had unexpected value\n",
- spec[ret].field,
- ret);
- parse_free (spec, ret);
- return GNUNET_SYSERR;
-}
-
-
-/**
- * Free all elements allocated during a
- * #MAJ_parse_json() operation.
- *
- * @param spec specification of the parse operation
- */
-void
-MAJ_parse_free (struct MAJ_Specification *spec)
-{
- int i;
-
- for (i=0;MAJ_CMD_END != spec[i].cmd;i++) ;
- parse_free (spec, i);
-}
-
-
-/**
- * The expected field stores a string.
- *
- * @param name name of the JSON field
- * @param strptr where to store a pointer to the field
- */
-struct MAJ_Specification
-MAJ_spec_string (const char *name,
- const char **strptr)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_STRING,
- .field = name,
- .details.strptr = strptr
- };
- return ret;
-}
-
-
-/**
- * Specification for parsing an absolute time value.
- *
- * @param name name of the JSON field
- * @param at where to store the absolute time found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_absolute_time (const char *name,
- struct GNUNET_TIME_Absolute *at)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_TIME_ABSOLUTE,
- .field = name,
- .details.abs_time = at
- };
- return ret;
-}
-
-
-/**
- * Specification for parsing an amount value.
- *
- * @param name name of the JSON field
- * @param amount where to store the amount found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_amount (const char *name,
- struct TALER_Amount *amount)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_AMOUNT,
- .field = name,
- .details.amount = amount
- };
- return ret;
-}
-
-
-/**
- * 16-bit integer.
- *
- * @param name name of the JSON field
- * @param[out] u16 where to store the integer found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_uint16 (const char *name,
- uint16_t *u16)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_UINT16,
- .field = name,
- .details.u16 = u16
- };
- return ret;
-}
-
-
-/**
- * JSON object.
- *
- * @param name name of the JSON field
- * @param[out] jsonp where to store the JSON found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_json (const char *name,
- json_t **jsonp)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_JSON_OBJECT,
- .field = name,
- .details.obj = jsonp
- };
- return ret;
-}
-
-
-/**
- * Specification for parsing an RSA public key.
- *
- * @param name name of the JSON field
- * @param pk where to store the RSA key found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_rsa_public_key (const char *name,
- struct GNUNET_CRYPTO_rsa_PublicKey **pk)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_RSA_PUBLIC_KEY,
- .field = name,
- .details.rsa_public_key = pk
- };
- return ret;
-}
-
-
-/**
- * Specification for parsing an RSA signature.
- *
- * @param name name of the JSON field
- * @param sig where to store the RSA signature found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_rsa_signature (const char *name,
- struct GNUNET_CRYPTO_rsa_Signature **sig)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_RSA_SIGNATURE,
- .field = name,
- .details.rsa_signature = sig
- };
- return ret;
-}
-
-
-/* end of merchant_api_json.c */
diff --git a/src/lib/merchant_api_json.h b/src/lib/merchant_api_json.h
deleted file mode 100644
index dad33967..00000000
--- a/src/lib/merchant_api_json.h
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015, 2016 GNUnet e.V.
-
- 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
- Foundation; either version 2.1, 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 Lesser General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING.LGPL. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/merchant_api_json.h
- * @brief functions to parse incoming requests (JSON snippets)
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <taler/taler_util.h>
-#include <jansson.h>
-
-
-/**
- * Enumeration with the various commands for the
- * #MAJ_parse_json interpreter.
- */
-enum MAJ_Command
-{
-
- /**
- * End of command list.
- */
- MAJ_CMD_END,
-
- /**
- * Parse amount at current position.
- */
- MAJ_CMD_AMOUNT,
-
- /**
- * Parse absolute time at current position.
- */
- MAJ_CMD_TIME_ABSOLUTE,
-
- /**
- * Parse fixed binary value at current position.
- */
- MAJ_CMD_BINARY_FIXED,
-
- /**
- * Parse variable-size binary value at current position.
- */
- MAJ_CMD_BINARY_VARIABLE,
-
- /**
- * Parse RSA public key at current position.
- */
- MAJ_CMD_RSA_PUBLIC_KEY,
-
- /**
- * Parse RSA signature at current position.
- */
- MAJ_CMD_RSA_SIGNATURE,
-
- /**
- * Parse `const char *` JSON string at current position.
- */
- MAJ_CMD_STRING,
-
- /**
- * Parse `uint16_t` integer at the current position.
- */
- MAJ_CMD_UINT16,
-
- /**
- * Parse JSON object at the current position.
- */
- MAJ_CMD_JSON_OBJECT,
-
- /**
- * Parse ??? at current position.
- */
- MAJ_CMD_C
-
-};
-
-
-/**
- * @brief Entry in parser specification for #MAJ_parse_json.
- */
-struct MAJ_Specification
-{
-
- /**
- * Command to execute.
- */
- enum MAJ_Command cmd;
-
- /**
- * Name of the field to access.
- */
- const char *field;
-
- /**
- * Further details for the command.
- */
- union {
-
- /**
- * Where to store amount for #MAJ_CMD_AMOUNT.
- */
- struct TALER_Amount *amount;
-
- /**
- * Where to store time, for #MAJ_CMD_TIME_ABSOLUTE.
- */
- struct GNUNET_TIME_Absolute *abs_time;
-
- /**
- * Where to write binary data, for #MAJ_CMD_BINARY_FIXED.
- */
- struct {
- /**
- * Where to write the data.
- */
- void *dest;
-
- /**
- * How many bytes to write to @e dest.
- */
- size_t dest_size;
-
- } fixed_data;
-
- /**
- * Where to write binary data, for #MAJ_CMD_BINARY_VARIABLE.
- */
- struct {
- /**
- * Where to store the pointer with the data (is allocated).
- */
- void **dest_p;
-
- /**
- * Where to store the number of bytes allocated at `*dest`.
- */
- size_t *dest_size_p;
-
- } variable_data;
-
- /**
- * Where to store the RSA public key for #MAJ_CMD_RSA_PUBLIC_KEY
- */
- struct GNUNET_CRYPTO_rsa_PublicKey **rsa_public_key;
-
- /**
- * Where to store the RSA signature for #MAJ_CMD_RSA_SIGNATURE
- */
- struct GNUNET_CRYPTO_rsa_Signature **rsa_signature;
-
- /**
- * Details for #MAJ_CMD_EDDSA_SIGNATURE
- */
- struct {
-
- /**
- * Where to store the purpose.
- */
- struct GNUNET_CRYPTO_EccSignaturePurpose **purpose_p;
-
- /**
- * Key to verify the signature against.
- */
- const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key;
-
- } eddsa_signature;
-
- /**
- * Where to store a pointer to the string.
- */
- const char **strptr;
-
- /**
- * Where to store 16-bit integer.
- */
- uint16_t *u16;
-
- /**
- * Where to store a JSON object.
- */
- json_t **obj;
-
- } details;
-
-};
-
-
-/**
- * Navigate and parse data in a JSON tree.
- *
- * @param root the JSON node to start the navigation at.
- * @param spec parse specification array
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-MAJ_parse_json (const json_t *root,
- struct MAJ_Specification *spec);
-
-
-/**
- * Free all elements allocated during a
- * #MAJ_parse_json() operation.
- *
- * @param spec specification of the parse operation
- */
-void
-MAJ_parse_free (struct MAJ_Specification *spec);
-
-
-/**
- * End of a parser specification.
- */
-#define MAJ_spec_end { .cmd = MAJ_CMD_END }
-
-/**
- * Fixed size object (in network byte order, encoded using Crockford
- * Base32hex encoding).
- *
- * @param name name of the JSON field
- * @param obj pointer where to write the data (type of `*obj` will determine size)
- */
-#define MAJ_spec_fixed_auto(name,obj) { .cmd = MAJ_CMD_BINARY_FIXED, .field = name, .details.fixed_data.dest = obj, .details.fixed_data.dest_size = sizeof (*obj) }
-
-
-/**
- * Variable size object (in network byte order, encoded using Crockford
- * Base32hex encoding).
- *
- * @param name name of the JSON field
- * @param obj pointer where to write the data (a `void **`)
- * @param size where to store the number of bytes allocated for @a obj (of type `size_t *`
- */
-#define MAJ_spec_varsize(name,obj,size) { .cmd = MAJ_CMD_BINARY_VARIABLE, .field = name, .details.variable_data.dest_p = obj, .details.variable_data.dest_size_p = size }
-
-
-/**
- * The expected field stores a string.
- *
- * @param name name of the JSON field
- * @param strptr where to store a pointer to the field
- */
-struct MAJ_Specification
-MAJ_spec_string (const char *name,
- const char **strptr);
-
-
-/**
- * Absolute time.
- *
- * @param name name of the JSON field
- * @param[out] at where to store the absolute time found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_absolute_time (const char *name,
- struct GNUNET_TIME_Absolute *at);
-
-
-/**
- * 16-bit integer.
- *
- * @param name name of the JSON field
- * @param[out] u16 where to store the integer found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_uint16 (const char *name,
- uint16_t *u16);
-
-
-/**
- * JSON object.
- *
- * @param name name of the JSON field
- * @param[out] jsonp where to store the JSON found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_json (const char *name,
- json_t **jsonp);
-
-
-/**
- * Specification for parsing an amount value.
- *
- * @param name name of the JSON field
- * @param amount where to store the amount under @a name
- */
-struct MAJ_Specification
-MAJ_spec_amount (const char *name,
- struct TALER_Amount *amount);
-
-
-/**
- * Specification for parsing an RSA public key.
- *
- * @param name name of the JSON field
- * @param pk where to store the RSA key found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_rsa_public_key (const char *name,
- struct GNUNET_CRYPTO_rsa_PublicKey **pk);
-
-
-/**
- * Specification for parsing an RSA signature.
- *
- * @param name name of the JSON field
- * @param sig where to store the RSA signature found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_rsa_signature (const char *name,
- struct GNUNET_CRYPTO_rsa_Signature **sig);
-
-
-
-
-/* end of merchant_api_json.h */
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 2607f73f..b583dcda 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -25,7 +25,7 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include "taler_merchant_service.h"
-#include "merchant_api_json.h"
+#include <taler/taler_json_lib.h>
#include "merchant_api_context.h"
#include <taler/taler_signatures.h>
@@ -160,17 +160,18 @@ handle_pay_finished (void *cls,
struct TALER_MERCHANT_Pay *
TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
const char *merchant_uri,
- const char *exchange_uri,
- const struct GNUNET_HashCode *h_wire,
const struct GNUNET_HashCode *h_contract,
- struct GNUNET_TIME_Absolute timestamp,
uint64_t transaction_id,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *max_fee,
const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
+ struct GNUNET_TIME_Absolute timestamp,
struct GNUNET_TIME_Absolute refund_deadline,
+ const struct GNUNET_HashCode *h_wire,
+ const char *exchange_uri,
unsigned int num_coins,
const struct TALER_MERCHANT_PayCoin *coins,
- const struct TALER_Amount *max_fee,
- const struct TALER_Amount *amount,
TALER_MERCHANT_PayCallback pay_cb,
void *pay_cb_cls)
{
@@ -220,18 +221,19 @@ TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
}
return TALER_MERCHANT_pay_frontend (merchant,
merchant_uri,
- exchange_uri,
- h_wire,
h_contract,
- timestamp,
+ amount,
+ max_fee,
transaction_id,
merchant_pub,
+ merchant_sig,
refund_deadline,
+ timestamp,
GNUNET_TIME_UNIT_ZERO_ABS,
+ h_wire,
+ exchange_uri,
num_coins,
pc,
- max_fee,
- amount,
pay_cb,
pay_cb_cls);
}
@@ -264,18 +266,19 @@ TALER_MERCHANT_pay_wallet (struct TALER_MERCHANT_Context *merchant,
struct TALER_MERCHANT_Pay *
TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
const char *merchant_uri,
- const char *exchange_uri,
- const struct GNUNET_HashCode *h_wire,
const struct GNUNET_HashCode *h_contract,
- struct GNUNET_TIME_Absolute timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *max_fee,
uint64_t transaction_id,
const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_MerchantSignatureP *merchant_sig,
struct GNUNET_TIME_Absolute refund_deadline,
+ struct GNUNET_TIME_Absolute timestamp,
struct GNUNET_TIME_Absolute execution_deadline,
+ const struct GNUNET_HashCode *h_wire,
+ const char *exchange_uri,
unsigned int num_coins,
const struct TALER_MERCHANT_PaidCoin *coins,
- const struct TALER_Amount *max_fee,
- const struct TALER_Amount *amount,
TALER_MERCHANT_PayCallback pay_cb,
void *pay_cb_cls)
{
@@ -337,12 +340,12 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
j_coin = json_pack ("{s:o, s:o," /* f/coin_pub */
" s:o, s:o," /* denom_pub / ub_sig */
" s:o}", /* coin_sig */
- "f", TALER_json_from_amount (&pc->amount_with_fee),
- "coin_pub", TALER_json_from_data (&pc->coin_pub,
+ "f", TALER_JSON_from_amount (&pc->amount_with_fee),
+ "coin_pub", GNUNET_JSON_from_data (&pc->coin_pub,
sizeof (struct TALER_CoinSpendPublicKeyP)),
- "denom_pub", TALER_json_from_rsa_public_key (pc->denom_pub.rsa_public_key),
- "ub_sig", TALER_json_from_rsa_signature (pc->denom_sig.rsa_signature),
- "coin_sig", TALER_json_from_data (&pc->coin_sig,
+ "denom_pub", GNUNET_JSON_from_rsa_public_key (pc->denom_pub.rsa_public_key),
+ "ub_sig", GNUNET_JSON_from_rsa_signature (pc->denom_sig.rsa_signature),
+ "coin_sig", GNUNET_JSON_from_data (&pc->coin_sig,
sizeof (struct TALER_CoinSpendSignatureP))
);
json_array_append (j_coins,
@@ -405,17 +408,17 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
" s:o, s:s," /* refund_deadline, exchange */
" s:o, s:o," /* coins, max_fee */
" s:o}", /* amount */
- "H_wire", TALER_json_from_data (&h_wire,
+ "H_wire", GNUNET_JSON_from_data (&h_wire,
sizeof (h_wire)),
- "H_contract", TALER_json_from_data (h_contract,
+ "H_contract", GNUNET_JSON_from_data (h_contract,
sizeof (struct GNUNET_HashCode)),
"transaction_id", (json_int_t) transaction_id,
- "timestamp", TALER_json_from_abs (timestamp),
- "refund_deadline", TALER_json_from_abs (refund_deadline),
+ "timestamp", GNUNET_JSON_from_time_abs (timestamp),
+ "refund_deadline", GNUNET_JSON_from_time_abs (refund_deadline),
"exchange", exchange_uri,
"coins", j_coins,
- "max_fee", TALER_json_from_amount (max_fee),
- "amount", TALER_json_from_amount (amount)
+ "max_fee", TALER_JSON_from_amount (max_fee),
+ "amount", TALER_JSON_from_amount (amount)
);
if (0 != execution_deadline.abs_value_us)
@@ -423,7 +426,7 @@ TALER_MERCHANT_pay_frontend (struct TALER_MERCHANT_Context *merchant,
/* Frontend did have an execution date in mind, add it */
json_object_set_new (pay_obj,
"edate",
- TALER_json_from_abs (execution_deadline));
+ GNUNET_JSON_from_time_abs (execution_deadline));
}
ph = GNUNET_new (struct TALER_MERCHANT_Pay);
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index 97964f64..1c8e5f79 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -1059,7 +1059,7 @@ interpreter_run (void *cls,
fail (is);
return;
}
- TALER_hash_json (wire,
+ TALER_JSON_hash (wire,
&h_wire);
json_decref (wire);
@@ -1076,7 +1076,7 @@ interpreter_run (void *cls,
fail (is);
return;
}
- TALER_hash_json (contract,
+ TALER_JSON_hash (contract,
&h_contract);
json_decref (contract);