summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-03-19 15:54:21 +0100
committerChristian Grothoff <christian@grothoff.org>2016-03-19 15:54:21 +0100
commitae726ea31b8607eacd2896617251cc0cab253111 (patch)
tree7e5d0d57e8ab6ba4542dcb0ef111f9466889528c
parent95ca52f5557b75fc0d5343c7e719b9aa6bcb1c50 (diff)
downloadexchange-ae726ea31b8607eacd2896617251cc0cab253111.tar.gz
exchange-ae726ea31b8607eacd2896617251cc0cab253111.tar.bz2
exchange-ae726ea31b8607eacd2896617251cc0cab253111.zip
remove duplicated JSON parsing code from exchange-lib (#4150)
-rw-r--r--src/exchange-lib/Makefile.am1
-rw-r--r--src/exchange-lib/exchange_api_admin.c1
-rw-r--r--src/exchange-lib/exchange_api_common.c41
-rw-r--r--src/exchange-lib/exchange_api_deposit.c14
-rw-r--r--src/exchange-lib/exchange_api_deposit_wtid.c41
-rw-r--r--src/exchange-lib/exchange_api_handle.c96
-rw-r--r--src/exchange-lib/exchange_api_json.c541
-rw-r--r--src/exchange-lib/exchange_api_json.h352
-rw-r--r--src/exchange-lib/exchange_api_refresh.c55
-rw-r--r--src/exchange-lib/exchange_api_refresh_link.c66
-rw-r--r--src/exchange-lib/exchange_api_reserve.c69
-rw-r--r--src/exchange-lib/exchange_api_wire.c23
-rw-r--r--src/exchange-lib/exchange_api_wire_deposits.c39
13 files changed, 231 insertions, 1108 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index a043e8601..10188c8fe 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -16,7 +16,6 @@ libtalerexchange_la_LDFLAGS = \
libtalerexchange_la_SOURCES = \
exchange_api_common.c exchange_api_common.h \
exchange_api_context.c exchange_api_context.h \
- exchange_api_json.c exchange_api_json.h \
exchange_api_handle.c exchange_api_handle.h \
exchange_api_admin.c \
exchange_api_deposit.c \
diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c
index 4ed761fb2..871a88a6b 100644
--- a/src/exchange-lib/exchange_api_admin.c
+++ b/src/exchange-lib/exchange_api_admin.c
@@ -27,7 +27,6 @@
#include <gnunet/gnunet_json_lib.h>
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
-#include "exchange_api_json.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
diff --git a/src/exchange-lib/exchange_api_common.c b/src/exchange-lib/exchange_api_common.c
index 805c3fc4e..6d2408d93 100644
--- a/src/exchange-lib/exchange_api_common.c
+++ b/src/exchange-lib/exchange_api_common.c
@@ -21,7 +21,7 @@
*/
#include "platform.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
+#include "taler_json_lib.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -66,24 +66,25 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
void *details;
size_t details_size;
const char *type;
- struct MAJ_Specification spec[] = {
- MAJ_spec_amount ("amount",
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("amount",
&amount),
- MAJ_spec_string ("type",
+ GNUNET_JSON_spec_string ("type",
&type),
- MAJ_spec_fixed_auto ("signature",
+ GNUNET_JSON_spec_fixed_auto ("signature",
&sig),
- MAJ_spec_varsize ("details",
+ GNUNET_JSON_spec_varsize ("details",
&details,
&details_size),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
transaction = json_array_get (history,
off);
if (GNUNET_OK !=
- MAJ_parse_json (transaction,
- spec))
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -97,14 +98,14 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
if (details_size != sizeof (struct TALER_DepositRequestPS))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
dr = (const struct TALER_DepositRequestPS *) details;
if (details_size != ntohl (dr->purpose.size))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -114,7 +115,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
&coin_pub->eddsa_pub))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -125,7 +126,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
&amount))
{
GNUNET_break (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
}
@@ -138,14 +139,14 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
if (details_size != sizeof (struct TALER_RefreshMeltCoinAffirmationPS))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
rm = (const struct TALER_RefreshMeltCoinAffirmationPS *) details;
if (details_size != ntohl (rm->purpose.size))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -155,7 +156,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
&coin_pub->eddsa_pub))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
TALER_amount_ntoh (&rm_amount,
@@ -164,7 +165,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
&amount))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
}
@@ -172,7 +173,7 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
{
/* signature not supported, new version on server? */
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -182,10 +183,10 @@ TALER_EXCHANGE_verify_coin_history_ (const char *currency,
{
/* overflow in history already!? inconceivable! Bad exchange! */
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
}
return GNUNET_OK;
}
diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c
index ef7a59e69..8ec45a23f 100644
--- a/src/exchange-lib/exchange_api_deposit.c
+++ b/src/exchange-lib/exchange_api_deposit.c
@@ -29,7 +29,6 @@
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -109,15 +108,16 @@ verify_deposit_signature_ok (const struct TALER_EXCHANGE_DepositHandle *dh,
struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
const struct TALER_EXCHANGE_Keys *key_state;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("sig", &exchange_sig),
- MAJ_spec_fixed_auto ("pub", &exchange_pub),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("sig", &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("pub", &exchange_pub),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
diff --git a/src/exchange-lib/exchange_api_deposit_wtid.c b/src/exchange-lib/exchange_api_deposit_wtid.c
index f3b5d2c0d..1ad1dd019 100644
--- a/src/exchange-lib/exchange_api_deposit_wtid.c
+++ b/src/exchange-lib/exchange_api_deposit_wtid.c
@@ -25,9 +25,9 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
+#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -98,15 +98,16 @@ verify_deposit_wtid_signature_ok (const struct TALER_EXCHANGE_DepositWtidHandle
struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
const struct TALER_EXCHANGE_Keys *key_state;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("exchange_sig", &exchange_sig),
- MAJ_spec_fixed_auto ("exchange_pub", &exchange_pub),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -161,16 +162,17 @@ handle_deposit_wtid_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("wtid", &dwh->depconf.wtid),
- MAJ_spec_absolute_time ("execution_time", &execution_time),
- MAJ_spec_amount ("coin_contribution", &coin_contribution_s),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid),
+ GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
+ TALER_JSON_spec_amount ("coin_contribution", &coin_contribution_s),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
@@ -193,14 +195,15 @@ handle_deposit_wtid_finished (void *cls,
case MHD_HTTP_ACCEPTED:
{
/* Transaction known, but not executed yet */
- struct MAJ_Specification spec[] = {
- MAJ_spec_absolute_time ("execution_time", &execution_time),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_absolute_time ("execution_time", &execution_time),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
diff --git a/src/exchange-lib/exchange_api_handle.c b/src/exchange-lib/exchange_api_handle.c
index d4b3e4deb..aaca8bac1 100644
--- a/src/exchange-lib/exchange_api_handle.c
+++ b/src/exchange-lib/exchange_api_handle.c
@@ -22,13 +22,11 @@
*/
#include "platform.h"
#include <curl/curl.h>
-#include <jansson.h>
-#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
+#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "taler_signatures.h"
#include "exchange_api_context.h"
-#include "exchange_api_json.h"
#include "exchange_api_handle.h"
@@ -189,23 +187,24 @@ parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key,
struct GNUNET_TIME_Absolute valid_from;
struct GNUNET_TIME_Absolute valid_until;
struct GNUNET_TIME_Absolute valid_legal;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("master_sig",
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
&sig),
- MAJ_spec_fixed_auto ("key",
+ GNUNET_JSON_spec_fixed_auto ("key",
&sign_key_issue.signkey_pub),
- MAJ_spec_absolute_time ("stamp_start",
+ GNUNET_JSON_spec_absolute_time ("stamp_start",
&valid_from),
- MAJ_spec_absolute_time ("stamp_expire",
+ GNUNET_JSON_spec_absolute_time ("stamp_expire",
&valid_until),
- MAJ_spec_absolute_time ("stamp_end",
+ GNUNET_JSON_spec_absolute_time ("stamp_end",
&valid_legal),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (sign_key_obj,
- spec))
+ GNUNET_JSON_parse (sign_key_obj,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -264,33 +263,33 @@ parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key,
struct GNUNET_CRYPTO_rsa_PublicKey *pk;
struct GNUNET_CRYPTO_EddsaSignature sig;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("master_sig",
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
&sig),
- MAJ_spec_absolute_time ("stamp_expire_deposit",
+ GNUNET_JSON_spec_absolute_time ("stamp_expire_deposit",
&deposit_valid_until),
- MAJ_spec_absolute_time ("stamp_expire_withdraw",
+ GNUNET_JSON_spec_absolute_time ("stamp_expire_withdraw",
&withdraw_valid_until),
- MAJ_spec_absolute_time ("stamp_start",
+ GNUNET_JSON_spec_absolute_time ("stamp_start",
&valid_from),
- MAJ_spec_absolute_time ("stamp_expire_legal",
+ GNUNET_JSON_spec_absolute_time ("stamp_expire_legal",
&expire_legal),
- MAJ_spec_amount ("value",
+ TALER_JSON_spec_amount ("value",
&value),
- MAJ_spec_amount ("fee_withdraw",
+ TALER_JSON_spec_amount ("fee_withdraw",
&fee_withdraw),
- MAJ_spec_amount ("fee_deposit",
+ TALER_JSON_spec_amount ("fee_deposit",
&fee_deposit),
- MAJ_spec_amount ("fee_refresh",
+ TALER_JSON_spec_amount ("fee_refresh",
&fee_refresh),
- MAJ_spec_rsa_public_key ("denom_pub",
+ GNUNET_JSON_spec_rsa_public_key ("denom_pub",
&pk),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (denom_key_obj,
- spec))
+ GNUNET_JSON_parse (denom_key_obj,
+ spec, NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -337,7 +336,7 @@ parse_json_denomkey (struct TALER_EXCHANGE_DenomPublicKey *denom_key,
return GNUNET_OK;
EXITIF_exit:
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -362,18 +361,19 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
unsigned int off;
unsigned int i;
struct TALER_ExchangeKeyValidityPS kv;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("auditor_pub",
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("auditor_pub",
&auditor->auditor_pub),
- MAJ_spec_json ("denomination_keys",
+ GNUNET_JSON_spec_json ("denomination_keys",
&keys),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
auditor->auditor_url = NULL; /* #3987 */
if (GNUNET_OK !=
- MAJ_parse_json (auditor_obj,
- spec))
+ GNUNET_JSON_parse (auditor_obj,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -391,17 +391,18 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
struct GNUNET_HashCode denom_h;
const struct TALER_EXCHANGE_DenomPublicKey *dk;
unsigned int j;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("denom_pub_h",
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("denom_pub_h",
&denom_h),
- MAJ_spec_fixed_auto ("auditor_sig",
+ GNUNET_JSON_spec_fixed_auto ("auditor_sig",
&auditor_sig),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (key,
- spec))
+ GNUNET_JSON_parse (key,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
continue;
@@ -476,21 +477,22 @@ decode_keys_json (json_t *resp_obj,
hash_context = GNUNET_CRYPTO_hash_context_start ();
/* parse the master public key and issue date of the response */
{
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("master_public_key",
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("master_public_key",
&key_data->master_pub),
- MAJ_spec_fixed_auto ("eddsa_sig",
+ GNUNET_JSON_spec_fixed_auto ("eddsa_sig",
&sig),
- MAJ_spec_fixed_auto ("eddsa_pub",
+ GNUNET_JSON_spec_fixed_auto ("eddsa_pub",
&pub),
- MAJ_spec_absolute_time ("list_issue_date",
+ GNUNET_JSON_spec_absolute_time ("list_issue_date",
&list_issue_date),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
EXITIF (GNUNET_OK !=
- MAJ_parse_json (resp_obj,
- spec));
+ GNUNET_JSON_parse (resp_obj,
+ spec,
+ NULL, NULL));
}
/* parse the signing keys */
diff --git a/src/exchange-lib/exchange_api_json.c b/src/exchange-lib/exchange_api_json.c
deleted file mode 100644
index d6c54be5b..000000000
--- a/src/exchange-lib/exchange_api_json.c
+++ /dev/null
@@ -1,541 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 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
- 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 Affero 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. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange-lib/exchange_api_json.c
- * @brief functions to parse incoming requests (JSON snippets)
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "exchange_api_json.h"
-#include "taler_json_lib.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:
- {
- struct GNUNET_JSON_Specification nspec[] = {
- TALER_JSON_spec_amount (NULL, spec[i].details.amount),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (pos,
- nspec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return i;
- }
- break;
- }
- case MAJ_CMD_TIME_ABSOLUTE:
- {
- struct GNUNET_JSON_Specification nspec[] = {
- GNUNET_JSON_spec_absolute_time (NULL, spec[i].details.abs_time),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (pos,
- nspec,
- NULL, NULL))
- {
- 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_UINT64:
- {
- json_int_t val;
-
- if (! json_is_integer (pos))
- {
- GNUNET_break_op (0);
- return i;
- }
- val = json_integer_value (pos);
- *spec[i].details.u64 = (uint64_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;
-}
-
-
-/**
- * 64-bit integer.
- *
- * @param name name of the JSON field
- * @param[out] u64 where to store the integer found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_uint64 (const char *name,
- uint64_t *u64)
-{
- struct MAJ_Specification ret =
- {
- .cmd = MAJ_CMD_UINT64,
- .field = name,
- .details.u64 = u64
- };
- 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 exchange_api_json.c */
diff --git a/src/exchange-lib/exchange_api_json.h b/src/exchange-lib/exchange_api_json.h
deleted file mode 100644
index 41efcea68..000000000
--- a/src/exchange-lib/exchange_api_json.h
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 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
- 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 Affero 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. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange-lib/exchange_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_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 `uint64_t` integer at the current position.
- */
- MAJ_CMD_UINT64,
-
- /**
- * 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 64-bit integer.
- */
- uint64_t *u64;
-
- /**
- * 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);
-
-
-/**
- * 64-bit integer.
- *
- * @param name name of the JSON field
- * @param[out] u64 where to store the integer found under @a name
- */
-struct MAJ_Specification
-MAJ_spec_uint64 (const char *name,
- uint64_t *u64);
-
-
-/**
- * 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 exchange_api_json.h */
diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c
index bcec13544..2949cf1e8 100644
--- a/src/exchange-lib/exchange_api_refresh.c
+++ b/src/exchange-lib/exchange_api_refresh.c
@@ -28,7 +28,6 @@
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -1086,17 +1085,18 @@ verify_refresh_melt_signature_ok (struct TALER_EXCHANGE_RefreshMeltHandle *rmh,
struct TALER_ExchangeSignatureP exchange_sig;
struct TALER_ExchangePublicKeyP exchange_pub;
const struct TALER_EXCHANGE_Keys *key_state;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("exchange_sig", &exchange_sig),
- MAJ_spec_fixed_auto ("exchange_pub", &exchange_pub),
- MAJ_spec_uint16 ("noreveal_index", noreveal_index),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig", &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub),
+ GNUNET_JSON_spec_uint16 ("noreveal_index", noreveal_index),
+ GNUNET_JSON_spec_end()
};
struct TALER_RefreshMeltConfirmationPS confirm;
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1156,19 +1156,20 @@ verify_refresh_melt_signature_forbidden (struct TALER_EXCHANGE_RefreshMeltHandle
struct TALER_Amount total;
struct TALER_CoinSpendPublicKeyP coin_pub;
unsigned int i;
- struct MAJ_Specification spec[] = {
- MAJ_spec_json ("history", &history),
- MAJ_spec_fixed_auto ("coin_pub", &coin_pub),
- MAJ_spec_amount ("original_value", &original_value),
- MAJ_spec_amount ("requested_value", &melt_value_with_fee),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_json ("history", &history),
+ GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub),
+ TALER_JSON_spec_amount ("original_value", &original_value),
+ TALER_JSON_spec_amount ("requested_value", &melt_value_with_fee),
+ GNUNET_JSON_spec_end()
};
const struct MeltedCoin *mc;
/* parse JSON reply */
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1731,14 +1732,15 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh,
{
unsigned int i;
json_t *jsona;
- struct MAJ_Specification spec[] = {
- MAJ_spec_json ("ev_sigs", &jsona),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_json ("ev_sigs", &jsona),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1765,9 +1767,9 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh,
struct TALER_CoinSpendPublicKeyP coin_pub;
struct GNUNET_HashCode coin_hash;
- struct MAJ_Specification spec[] = {
- MAJ_spec_rsa_signature ("ev_sig", &blind_sig),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_rsa_signature ("ev_sig", &blind_sig),
+ GNUNET_JSON_spec_end()
};
fc = &rrh->md->fresh_coins[rrh->noreveal_index][i];
@@ -1776,8 +1778,9 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshRevealHandle *rrh,
GNUNET_assert (NULL != jsonai);
if (GNUNET_OK !=
- MAJ_parse_json (jsonai,
- spec))
+ GNUNET_JSON_parse (jsonai,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c
index 9576916bc..41d421f58 100644
--- a/src/exchange-lib/exchange_api_refresh_link.c
+++ b/src/exchange-lib/exchange_api_refresh_link.c
@@ -21,11 +21,10 @@
*/
#include "platform.h"
#include <curl/curl.h>
-#include <jansson.h>
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include "taler_exchange_service.h"
-#include "exchange_api_json.h"
+#include "taler_json_lib.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -101,11 +100,11 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
size_t link_enc_size;
struct GNUNET_CRYPTO_rsa_Signature *bsig;
struct GNUNET_CRYPTO_rsa_PublicKey *rpub;
- struct MAJ_Specification spec[] = {
- MAJ_spec_varsize ("link_enc", &link_enc, &link_enc_size),
- MAJ_spec_rsa_public_key ("denom_pub", &rpub),
- MAJ_spec_rsa_signature ("ev_sig", &bsig),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_varsize ("link_enc", &link_enc, &link_enc_size),
+ GNUNET_JSON_spec_rsa_public_key ("denom_pub", &rpub),
+ GNUNET_JSON_spec_rsa_signature ("ev_sig", &bsig),
+ GNUNET_JSON_spec_end()
};
struct TALER_RefreshLinkEncrypted *rle;
struct TALER_RefreshLinkDecrypted *rld;
@@ -113,8 +112,9 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
/* parse reply */
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -126,7 +126,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
if (NULL == rle)
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -136,7 +136,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
&secret))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
rld = TALER_refresh_decrypt (rle,
@@ -144,7 +144,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
if (NULL == rld)
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -158,7 +158,7 @@ parse_refresh_link_coin (const struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
/* clean up */
GNUNET_free (rld);
pub->rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup (rpub);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_OK;
}
@@ -199,15 +199,16 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
for (session=0;session<json_array_size (json); session++)
{
json_t *jsona;
- struct MAJ_Specification spec[] = {
- MAJ_spec_json ("new_coins", &jsona),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_json ("new_coins", &jsona),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json_array_get (json,
- session),
- spec))
+ GNUNET_JSON_parse (json_array_get (json,
+ session),
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -215,13 +216,13 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
if (! json_is_array (jsona))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
/* count all coins over all sessions */
num_coins += json_array_size (jsona);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
}
/* Now that we know how big the 1d array is, allocate
and fill it. */
@@ -240,17 +241,18 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
json_t *jsona;
struct TALER_TransferPublicKeyP trans_pub;
struct TALER_EncryptedLinkSecretP secret_enc;
- struct MAJ_Specification spec[] = {
- MAJ_spec_json ("new_coins", &jsona),
- MAJ_spec_fixed_auto ("transfer_pub", &trans_pub),
- MAJ_spec_fixed_auto ("secret_enc", &secret_enc),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_json ("new_coins", &jsona),
+ GNUNET_JSON_spec_fixed_auto ("transfer_pub", &trans_pub),
+ GNUNET_JSON_spec_fixed_auto ("secret_enc", &secret_enc),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json_array_get (json,
- session),
- spec))
+ GNUNET_JSON_parse (json_array_get (json,
+ session),
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -258,7 +260,7 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
if (! json_is_array (jsona))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -285,10 +287,10 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh,
{
GNUNET_break_op (0);
ret = GNUNET_SYSERR;
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
break;
}
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
} /* end of for (session) */
if (off_coin == num_coins)
diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c
index 1237f7cbe..87d7b37f2 100644
--- a/src/exchange-lib/exchange_api_reserve.c
+++ b/src/exchange-lib/exchange_api_reserve.c
@@ -26,7 +26,7 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include "taler_exchange_service.h"
-#include "exchange_api_json.h"
+#include "taler_json_lib.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -117,19 +117,20 @@ parse_reserve_history (json_t *history,
json_t *transaction;
struct TALER_Amount amount;
const char *type;
- struct MAJ_Specification hist_spec[] = {
- MAJ_spec_string ("type", &type),
- MAJ_spec_amount ("amount",
+ struct GNUNET_JSON_Specification hist_spec[] = {
+ GNUNET_JSON_spec_string ("type", &type),
+ TALER_JSON_spec_amount ("amount",
&amount),
/* 'wire' and 'signature' are optional depending on 'type'! */
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
transaction = json_array_get (history,
off);
if (GNUNET_OK !=
- MAJ_parse_json (transaction,
- hist_spec))
+ GNUNET_JSON_parse (transaction,
+ hist_spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -171,19 +172,20 @@ parse_reserve_history (json_t *history,
struct TALER_ReserveSignatureP sig;
struct TALER_WithdrawRequestPS withdraw_purpose;
struct TALER_Amount amount_from_purpose;
- struct MAJ_Specification withdraw_spec[] = {
- MAJ_spec_fixed_auto ("signature",
+ struct GNUNET_JSON_Specification withdraw_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("signature",
&sig),
- MAJ_spec_fixed_auto ("details",
+ GNUNET_JSON_spec_fixed_auto ("details",
&withdraw_purpose),
- MAJ_spec_end
+ GNUNET_JSON_spec_end()
};
unsigned int i;
rhistory[off].type = TALER_EXCHANGE_RTT_WITHDRAWAL;
if (GNUNET_OK !=
- MAJ_parse_json (transaction,
- withdraw_spec))
+ GNUNET_JSON_parse (transaction,
+ withdraw_spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -196,7 +198,7 @@ parse_reserve_history (json_t *history,
&reserve_pub->eddsa_pub))
{
GNUNET_break_op (0);
- MAJ_parse_free (withdraw_spec);
+ GNUNET_JSON_parse_free (withdraw_spec);
return GNUNET_SYSERR;
}
TALER_amount_ntoh (&amount_from_purpose,
@@ -205,7 +207,7 @@ parse_reserve_history (json_t *history,
&amount_from_purpose))
{
GNUNET_break_op (0);
- MAJ_parse_free (withdraw_spec);
+ GNUNET_JSON_parse_free (withdraw_spec);
return GNUNET_SYSERR;
}
rhistory[off].details.out_authorization_sig = json_object_get (transaction,
@@ -225,7 +227,7 @@ parse_reserve_history (json_t *history,
sizeof (struct GNUNET_HashCode)))
{
GNUNET_break_op (0);
- MAJ_parse_free (withdraw_spec);
+ GNUNET_JSON_parse_free (withdraw_spec);
return GNUNET_SYSERR;
}
}
@@ -238,7 +240,7 @@ parse_reserve_history (json_t *history,
{
/* overflow in history already!? inconceivable! Bad exchange! */
GNUNET_break_op (0);
- MAJ_parse_free (withdraw_spec);
+ GNUNET_JSON_parse_free (withdraw_spec);
return GNUNET_SYSERR;
}
/* end type==WITHDRAW */
@@ -296,14 +298,15 @@ handle_reserve_status_finished (void *cls,
unsigned int len;
struct TALER_Amount balance;
struct TALER_Amount balance_from_history;
- struct MAJ_Specification spec[] = {
- MAJ_spec_amount ("balance", &balance),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("balance", &balance),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
@@ -563,14 +566,15 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh,
struct GNUNET_CRYPTO_rsa_Signature *blind_sig;
struct GNUNET_CRYPTO_rsa_Signature *sig;
struct TALER_DenominationSignature dsig;
- struct MAJ_Specification spec[] = {
- MAJ_spec_rsa_signature ("ev_sig", &blind_sig),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_rsa_signature ("ev_sig", &blind_sig),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -622,14 +626,15 @@ reserve_withdraw_payment_required (struct TALER_EXCHANGE_ReserveWithdrawHandle *
struct TALER_Amount requested_amount;
json_t *history;
size_t len;
- struct MAJ_Specification spec[] = {
- MAJ_spec_amount ("balance", &balance),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("balance", &balance),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c
index 35c443ff5..27ae1dce7 100644
--- a/src/exchange-lib/exchange_api_wire.c
+++ b/src/exchange-lib/exchange_api_wire.c
@@ -25,9 +25,9 @@
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
#include "taler_wire_plugin.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
@@ -311,17 +311,18 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
json_t *methods;
const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_HashContext *hc;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("sig", &exchange_sig),
- MAJ_spec_fixed_auto ("pub", &exchange_pub),
- MAJ_spec_json ("methods", &methods),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("sig", &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("pub", &exchange_pub),
+ GNUNET_JSON_spec_json ("methods", &methods),
+ GNUNET_JSON_spec_end()
};
unsigned int i;
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
return NULL;
@@ -329,7 +330,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
if (! json_is_array (methods))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return NULL;
}
@@ -351,7 +352,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
{
GNUNET_CRYPTO_hash_context_abort (hc);
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return NULL;
}
method = json_string_value (element);
@@ -371,7 +372,7 @@ verify_wire_signature_ok (const struct TALER_EXCHANGE_WireHandle *wh,
&exchange_pub.eddsa_pub))
{
GNUNET_break_op (0);
- MAJ_parse_free (spec);
+ GNUNET_JSON_parse_free (spec);
return NULL;
}
return methods;
diff --git a/src/exchange-lib/exchange_api_wire_deposits.c b/src/exchange-lib/exchange_api_wire_deposits.c
index 406256025..0112f8565 100644
--- a/src/exchange-lib/exchange_api_wire_deposits.c
+++ b/src/exchange-lib/exchange_api_wire_deposits.c
@@ -24,10 +24,9 @@
#include <jansson.h>
#include <microhttpd.h> /* just for HTTP status codes */
#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
#include "taler_exchange_service.h"
#include "exchange_api_common.h"
-#include "exchange_api_json.h"
+#include "taler_json_lib.h"
#include "exchange_api_context.h"
#include "exchange_api_handle.h"
#include "taler_signatures.h"
@@ -102,17 +101,18 @@ handle_wire_deposits_finished (void *cls,
struct TALER_Amount total_amount;
struct TALER_MerchantPublicKeyP merchant_pub;
unsigned int num_details;
- struct MAJ_Specification spec[] = {
- MAJ_spec_fixed_auto ("H_wire", &h_wire),
- MAJ_spec_fixed_auto ("merchant_pub", &merchant_pub),
- MAJ_spec_amount ("total_amount", &total_amount),
- MAJ_spec_json ("details", &details_j),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("H_wire", &h_wire),
+ GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub),
+ TALER_JSON_spec_amount ("total_amount", &total_amount),
+ GNUNET_JSON_spec_json ("details", &details_j),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
@@ -127,18 +127,19 @@ handle_wire_deposits_finished (void *cls,
{
struct TALER_WireDepositDetails *detail = &details[i];
struct json_t *detail_j = json_array_get (details_j, i);
- struct MAJ_Specification spec_detail[] = {
- MAJ_spec_fixed_auto ("H_contract", &detail->h_contract),
- MAJ_spec_amount ("deposit_value", &detail->coin_value),
- MAJ_spec_amount ("deposit_fee", &detail->coin_fee),
- MAJ_spec_uint64 ("transaction_id", &detail->transaction_id),
- MAJ_spec_fixed_auto ("coin_pub", &detail->coin_pub),
- MAJ_spec_end
+ struct GNUNET_JSON_Specification spec_detail[] = {
+ GNUNET_JSON_spec_fixed_auto ("H_contract", &detail->h_contract),
+ TALER_JSON_spec_amount ("deposit_value", &detail->coin_value),
+ TALER_JSON_spec_amount ("deposit_fee", &detail->coin_fee),
+ GNUNET_JSON_spec_uint64 ("transaction_id", &detail->transaction_id),
+ GNUNET_JSON_spec_fixed_auto ("coin_pub", &detail->coin_pub),
+ GNUNET_JSON_spec_end()
};
if (GNUNET_OK !=
- MAJ_parse_json (detail_j,
- spec_detail))
+ GNUNET_JSON_parse (detail_j,
+ spec_detail,
+ NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;