aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-08-17 03:24:10 +0200
committerChristian Grothoff <christian@grothoff.org>2015-08-17 03:24:10 +0200
commitb5a58e516c0d0ee48547dd7bb9f3d1a3b9ebf15e (patch)
tree403b68eec26dc7203f045bc013904657a3fce2a8 /src
parent81af01a209b557a4996a50824ae2f1ec75c25eb5 (diff)
fix /refresh/link response handling
Diffstat (limited to 'src')
-rw-r--r--src/mint-lib/mint_api_refresh_link.c135
-rw-r--r--src/mint-lib/test_mint_api.c4
2 files changed, 96 insertions, 43 deletions
diff --git a/src/mint-lib/mint_api_refresh_link.c b/src/mint-lib/mint_api_refresh_link.c
index f17949af0..b4bed98e6 100644
--- a/src/mint-lib/mint_api_refresh_link.c
+++ b/src/mint-lib/mint_api_refresh_link.c
@@ -173,74 +173,123 @@ static int
parse_refresh_link_ok (struct TALER_MINT_RefreshLinkHandle *rlh,
json_t *json)
{
- 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 ("trans_pub", &trans_pub),
- MAJ_spec_fixed_auto ("secret_enc", &secret_enc),
- MAJ_spec_end
- };
+ unsigned int session;
unsigned int num_coins;
int ret;
- if (GNUNET_OK !=
- MAJ_parse_json (json,
- spec))
+ if (! json_is_array (json))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (jsona))
+ num_coins = 0;
+ for (session=0;session<json_array_size (json); session++)
{
- GNUNET_break_op (0);
+ json_t *jsona;
+ struct MAJ_Specification spec[] = {
+ MAJ_spec_json ("new_coins", &jsona),
+ MAJ_spec_end
+ };
+
+ if (GNUNET_OK !=
+ MAJ_parse_json (json_array_get (json,
+ session),
+ spec))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (! json_is_array (jsona))
+ {
+ GNUNET_break_op (0);
+ MAJ_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
+
+ /* count all coins over all sessions */
+ num_coins += json_array_size (jsona);
MAJ_parse_free (spec);
- return GNUNET_SYSERR;
}
-
- /* decode all coins */
- num_coins = json_array_size (json);
{
+ unsigned int off_coin;
unsigned int i;
struct TALER_CoinSpendPrivateKeyP coin_privs[num_coins];
struct TALER_DenominationSignature sigs[num_coins];
struct TALER_DenominationPublicKey pubs[num_coins];
-
- for (i=0;i<num_coins;i++)
+
+ off_coin = 0;
+ for (session=0;session<json_array_size (json); session++)
{
+ 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
+ };
+
if (GNUNET_OK !=
- parse_refresh_link_coin (rlh,
- json_array_get (json, i),
- &trans_pub,
- &secret_enc,
- &coin_privs[i],
- &sigs[i],
- &pubs[i]))
+ MAJ_parse_json (json_array_get (json,
+ session),
+ spec))
{
- GNUNET_break_op (0);
- break;
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
}
+ if (! json_is_array (jsona))
+ {
+ GNUNET_break_op (0);
+ MAJ_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
+
+ /* decode all coins */
+ for (i=0;i<json_array_size (jsona);i++)
+ {
+ if (GNUNET_OK !=
+ parse_refresh_link_coin (rlh,
+ json_array_get (jsona,
+ i),
+ &trans_pub,
+ &secret_enc,
+ &coin_privs[i+off_coin],
+ &sigs[i+off_coin],
+ &pubs[i+off_coin]))
+ {
+ GNUNET_break_op (0);
+ break;
+ }
+ }
+ /* check if we really got all, then invoke callback */
+ if (i != json_array_size (jsona))
+ {
+ GNUNET_break_op (0);
+ ret = GNUNET_SYSERR;
+ MAJ_parse_free (spec);
+ break;
+ }
+ off_coin += json_array_size (jsona);
+ MAJ_parse_free (spec);
}
-
- /* check if we really got all, then invoke callback */
- if (i != num_coins)
- {
- GNUNET_break_op (0);
- ret = GNUNET_SYSERR;
- }
- else
+ if (off_coin == num_coins)
{
rlh->link_cb (rlh->link_cb_cls,
- MHD_HTTP_OK,
- num_coins,
- coin_privs,
- sigs,
- pubs,
- json);
+ MHD_HTTP_OK,
+ num_coins,
+ coin_privs,
+ sigs,
+ pubs,
+ json);
rlh->link_cb = NULL;
ret = GNUNET_OK;
}
+ else
+ {
+ GNUNET_break_op (0);
+ ret = GNUNET_SYSERR;
+ }
/* clean up */
for (i=0;i<num_coins;i++)
diff --git a/src/mint-lib/test_mint_api.c b/src/mint-lib/test_mint_api.c
index 91a3d7628..51f62cc32 100644
--- a/src/mint-lib/test_mint_api.c
+++ b/src/mint-lib/test_mint_api.c
@@ -1009,6 +1009,10 @@ link_cb (void *cls,
return;
}
/* check that the coins match */
+ fprintf (stderr,
+ "Got %u coins\n",
+ num_coins);
+ /* FIXME: note: coins might be legitimately permutated in here... */
for (i=0;i<num_coins;i++)
{
const struct FreshCoin *fc;