aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-07-31 23:15:31 +0200
committerChristian Grothoff <christian@grothoff.org>2021-07-31 23:15:31 +0200
commit65d88bf92f74bf755e438228e3cca7977300dc54 (patch)
tree5bb3c850656065a8cbe4632aad7763004e5df4a8
parent1db139a7f3b74b2dc4135ab8b42d625415705d63 (diff)
downloadanastasis-65d88bf92f74bf755e438228e3cca7977300dc54.tar.gz
anastasis-65d88bf92f74bf755e438228e3cca7977300dc54.zip
-eliminating some legacy json_pack calls from Anastasis
m---------contrib/gana0
-rw-r--r--src/reducer/anastasis_api_backup_redux.c82
-rw-r--r--src/reducer/anastasis_api_recovery_redux.c221
-rw-r--r--src/reducer/anastasis_api_redux.c4
4 files changed, 152 insertions, 155 deletions
diff --git a/contrib/gana b/contrib/gana
Subproject 755e752e3a235df0be8d45374835b109f7843c1 Subproject 0f1eb8555b89056fe62e093211e53a1f9ba85d5
diff --git a/src/reducer/anastasis_api_backup_redux.c b/src/reducer/anastasis_api_backup_redux.c
index cea1360..02e2401 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -1440,20 +1440,22 @@ select_policies (struct PolicyBuilder *pb)
1440 GNUNET_assert (NULL != method_arr); 1440 GNUNET_assert (NULL != method_arr);
1441 for (unsigned int i = 0; i < pb->req_methods; i++) 1441 for (unsigned int i = 0; i < pb->req_methods; i++)
1442 { 1442 {
1443 json_t *policy_method = json_pack ("{s:I, s:s}", 1443 json_t *policy_method = GNUNET_JSON_PACK (
1444 "authentication_method", 1444 GNUNET_JSON_pack_uint64 ("authentication_method",
1445 (json_int_t) p->challenges[i], 1445 p->challenges[i]),
1446 "provider", 1446 GNUNET_JSON_pack_string ("provider",
1447 pm->providers[i].provider_name); 1447 pm->providers[i].provider_name));
1448
1448 GNUNET_assert (0 == 1449 GNUNET_assert (0 ==
1449 json_array_append_new (method_arr, 1450 json_array_append_new (method_arr,
1450 policy_method)); 1451 policy_method));
1451 } 1452 }
1452 { 1453 {
1453 json_t *policy = json_pack ("{s:o}", 1454 json_t *policy = GNUNET_JSON_PACK (
1454 "methods", 1455 GNUNET_JSON_pack_array_steal (
1455 method_arr); 1456 "methods",
1456 GNUNET_assert (NULL != policy); 1457 method_arr));
1458
1457 GNUNET_assert (0 == 1459 GNUNET_assert (0 ==
1458 json_array_append_new (pb->policies, 1460 json_array_append_new (pb->policies,
1459 policy)); 1461 policy));
@@ -1616,8 +1618,9 @@ done_authentication (json_t *state,
1616 url, 1618 url,
1617 &salt)) 1619 &salt))
1618 continue; /* skip providers that are down */ 1620 continue; /* skip providers that are down */
1619 provider = json_pack ("{s:s}", 1621 provider = GNUNET_JSON_PACK (
1620 "provider_url", url); 1622 GNUNET_JSON_pack_string ("provider_url",
1623 url));
1621 GNUNET_assert (NULL != provider); 1624 GNUNET_assert (NULL != provider);
1622 GNUNET_assert (0 == 1625 GNUNET_assert (0 ==
1623 json_array_append_new (policy_providers, 1626 json_array_append_new (policy_providers,
@@ -1651,9 +1654,9 @@ done_authentication (json_t *state,
1651 "unworkable provider requested"); 1654 "unworkable provider requested");
1652 return NULL; 1655 return NULL;
1653 } 1656 }
1654 provider = json_pack ("{s:s}", 1657 provider = GNUNET_JSON_PACK (
1655 "provider_url", url); 1658 GNUNET_JSON_pack_string ("provider_url",
1656 GNUNET_assert (NULL != provider); 1659 url_str));
1657 GNUNET_assert (0 == 1660 GNUNET_assert (0 ==
1658 json_array_append_new (policy_providers, 1661 json_array_append_new (policy_providers,
1659 provider)); 1662 provider));
@@ -1968,10 +1971,9 @@ add_policy (json_t *state,
1968 json_t *policy; 1971 json_t *policy;
1969 json_t *idx; 1972 json_t *idx;
1970 1973
1971 policy = json_pack ("{s:o}", 1974 policy = GNUNET_JSON_PACK (
1972 "methods", 1975 GNUNET_JSON_pack_array_steal ("methods",
1973 methods); 1976 methods));
1974 GNUNET_assert (NULL != policy);
1975 idx = json_object_get (arguments, 1977 idx = json_object_get (arguments,
1976 "policy_index"); 1978 "policy_index");
1977 if ( (NULL == idx) || 1979 if ( (NULL == idx) ||
@@ -2447,9 +2449,9 @@ update_expiration_cost (json_t *state,
2447 { 2449 {
2448 json_t *ao; 2450 json_t *ao;
2449 2451
2450 ao = json_pack ("{s:o}", 2452 ao = GNUNET_JSON_PACK (
2451 "fee", 2453 TALER_JSON_pack_amount ("fee",
2452 TALER_JSON_from_amount (&costs->cost)); 2454 &costs->cost));
2453 GNUNET_assert (0 == 2455 GNUNET_assert (0 ==
2454 json_array_append_new (arr, 2456 json_array_append_new (arr,
2455 ao)); 2457 ao));
@@ -2821,11 +2823,11 @@ secret_share_result_cb (void *cls,
2821 = &sr->details.success.pss[i]; 2823 = &sr->details.success.pss[i];
2822 json_t *d; 2824 json_t *d;
2823 2825
2824 d = json_pack ("{s:I, s:o}", 2826 d = GNUNET_JSON_PACK (
2825 "policy_version", 2827 GNUNET_JSON_pack_uint64 ("policy_version",
2826 pssi->policy_version, 2828 pssi->policy_version),
2827 "policy_expiration", 2829 GNUNET_JSON_pack_time_abs ("policy_expiration",
2828 GNUNET_JSON_from_time_abs (pssi->policy_expiration)); 2830 pssi->policy_expiration));
2829 GNUNET_assert (NULL != d); 2831 GNUNET_assert (NULL != d);
2830 GNUNET_assert (0 == 2832 GNUNET_assert (0 ==
2831 json_object_set_new (sa, 2833 json_object_set_new (sa,
@@ -2864,11 +2866,11 @@ secret_share_result_cb (void *cls,
2864 json_t *provider; 2866 json_t *provider;
2865 2867
2866 spr = &sr->details.payment_required.payment_requests[i]; 2868 spr = &sr->details.payment_required.payment_requests[i];
2867 pr = json_pack ("{s:s, s:s}", 2869 pr = GNUNET_JSON_PACK (
2868 "payto", 2870 GNUNET_JSON_pack_string ("payto",
2869 spr->payment_request_url, 2871 spr->payment_request_url),
2870 "provider", 2872 GNUNET_JSON_pack_string ("provider",
2871 spr->provider_url); 2873 spr->provider_url));
2872 GNUNET_assert (0 == 2874 GNUNET_assert (0 ==
2873 json_array_append_new (ra, 2875 json_array_append_new (ra,
2874 pr)); 2876 pr));
@@ -2916,15 +2918,15 @@ secret_share_result_cb (void *cls,
2916 { 2918 {
2917 json_t *details; 2919 json_t *details;
2918 2920
2919 details = json_pack ("{s:s, s:I, s:I, s:s}", 2921 details = GNUNET_JSON_PACK (
2920 "backup_state", 2922 GNUNET_JSON_pack_string ("backup_state",
2921 "ERROR", 2923 "ERROR"),
2922 "http_status", 2924 GNUNET_JSON_pack_uint64 ("http_status",
2923 (json_int_t) sr->details.provider_failure.http_status, 2925 sr->details.provider_failure.http_status),
2924 "upload_status", 2926 GNUNET_JSON_pack_uint64 ("upload_status",
2925 (json_int_t) sr->details.provider_failure.ec, 2927 sr->details.provider_failure.ec),
2926 "provider_url", 2928 GNUNET_JSON_pack_string ("provider_url",
2927 sr->details.provider_failure.provider_url); 2929 sr->details.provider_failure.provider_url));
2928 uc->cb (uc->cb_cls, 2930 uc->cb (uc->cb_cls,
2929 TALER_EC_ANASTASIS_REDUCER_BACKUP_PROVIDER_FAILED, 2931 TALER_EC_ANASTASIS_REDUCER_BACKUP_PROVIDER_FAILED,
2930 details); 2932 details);
diff --git a/src/reducer/anastasis_api_recovery_redux.c b/src/reducer/anastasis_api_recovery_redux.c
index 77f5847..c0fae18 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -452,10 +452,9 @@ answer_feedback_cb (
452 { 452 {
453 json_t *solved; 453 json_t *solved;
454 454
455 solved = json_pack ("{s:s}", 455 solved = GNUNET_JSON_PACK (
456 "state", 456 GNUNET_JSON_pack_string ("state",
457 "solved"); 457 "solved"));
458 GNUNET_assert (NULL != solved);
459 GNUNET_assert (0 == 458 GNUNET_assert (0 ==
460 json_object_set_new (feedback, 459 json_object_set_new (feedback,
461 uuid, 460 uuid,
@@ -470,7 +469,6 @@ answer_feedback_cb (
470 case ANASTASIS_CHALLENGE_STATUS_INSTRUCTIONS: 469 case ANASTASIS_CHALLENGE_STATUS_INSTRUCTIONS:
471 { 470 {
472 json_t *instructions; 471 json_t *instructions;
473 json_t *val;
474 const char *mime; 472 const char *mime;
475 473
476 mime = csr->details.open_challenge.content_type; 474 mime = csr->details.open_challenge.content_type;
@@ -484,14 +482,14 @@ answer_feedback_cb (
484 char *s = GNUNET_strndup (csr->details.open_challenge.body, 482 char *s = GNUNET_strndup (csr->details.open_challenge.body,
485 csr->details.open_challenge.body_size); 483 csr->details.open_challenge.body_size);
486 484
487 instructions = json_pack ( 485 instructions = GNUNET_JSON_PACK (
488 "{s:s, s:s, s:I}", 486 GNUNET_JSON_pack_string ("state",
489 "state", 487 "hint"),
490 "hint", 488 GNUNET_JSON_pack_string ("hint",
491 "hint", 489 s),
492 s, 490 GNUNET_JSON_pack_uint64 ("http_status",
493 "http_status", 491 (json_int_t) csr->details.open_challenge.
494 (json_int_t) csr->details.open_challenge.http_status); 492 http_status));
495 GNUNET_free (s); 493 GNUNET_free (s);
496 } 494 }
497 else if (0 == strcasecmp (mime, 495 else if (0 == strcasecmp (mime,
@@ -510,14 +508,13 @@ answer_feedback_cb (
510 } 508 }
511 else 509 else
512 { 510 {
513 instructions = json_pack ( 511 instructions = GNUNET_JSON_PACK (
514 "{s:s, s:o, s:I}", 512 GNUNET_JSON_pack_string ("state",
515 "state", 513 "details"),
516 "details", 514 GNUNET_JSON_pack_object_steal ("details",
517 "details", 515 body),
518 body, 516 GNUNET_JSON_pack_uint64 ("http_status",
519 "http_status", 517 csr->details.open_challenge.http_status));
520 (json_int_t) csr->details.open_challenge.http_status);
521 } 518 }
522 } 519 }
523 else 520 else
@@ -528,21 +525,18 @@ answer_feedback_cb (
528 } 525 }
529 if (NULL == mime) 526 if (NULL == mime)
530 { 527 {
531 val = GNUNET_JSON_from_data (csr->details.open_challenge.body, 528 instructions = GNUNET_JSON_PACK (
532 csr->details.open_challenge.body_size); 529 GNUNET_JSON_pack_string ("state",
533 GNUNET_assert (NULL != val); 530 "body"),
534 instructions = json_pack ( 531 GNUNET_JSON_pack_data_varsize ("body",
535 "{s:s, s:o, s:I, s:s?}", 532 csr->details.open_challenge.body,
536 "state", 533 csr->details.open_challenge.body_size),
537 "body", 534 GNUNET_JSON_pack_uint64 ("http_status",
538 "body", 535 csr->details.open_challenge.http_status),
539 val, 536 GNUNET_JSON_pack_allow_null (
540 "http_status", 537 GNUNET_JSON_pack_string ("mime_type",
541 (json_int_t) csr->details.open_challenge.http_status, 538 mime)));
542 "mime_type",
543 mime);
544 } 539 }
545 GNUNET_assert (NULL != instructions);
546 GNUNET_assert (0 == 540 GNUNET_assert (0 ==
547 json_object_set_new (feedback, 541 json_object_set_new (feedback,
548 uuid, 542 uuid,
@@ -559,11 +553,11 @@ answer_feedback_cb (
559 { 553 {
560 json_t *redir; 554 json_t *redir;
561 555
562 redir = json_pack ("{s:s, s:s}", 556 redir = GNUNET_JSON_PACK (
563 "state", 557 GNUNET_JSON_pack_string ("state",
564 "redirect", 558 "redirect"),
565 "redirect_url", 559 GNUNET_JSON_pack_string ("redirect_url",
566 csr->details.redirect_url); 560 csr->details.redirect_url));
567 GNUNET_assert (NULL != redir); 561 GNUNET_assert (NULL != redir);
568 GNUNET_assert (0 == 562 GNUNET_assert (0 ==
569 json_object_set_new (feedback, 563 json_object_set_new (feedback,
@@ -581,17 +575,17 @@ answer_feedback_cb (
581 { 575 {
582 json_t *pay; 576 json_t *pay;
583 577
584 pay = json_pack ("{s:s, s:s, s:s, s:o}", 578 pay = GNUNET_JSON_PACK (
585 "state", 579 GNUNET_JSON_pack_string ("state",
586 "payment", 580 "payment"),
587 "taler_pay_uri", 581 GNUNET_JSON_pack_string ("taler_pay_uri",
588 csr->details.payment_required.taler_pay_uri, 582 csr->details.payment_required.
589 "provider", 583 taler_pay_uri),
590 cd->provider_url, 584 GNUNET_JSON_pack_string ("provider",
591 "payment_secret", 585 cd->provider_url),
592 GNUNET_JSON_from_data_auto ( 586 GNUNET_JSON_pack_data_auto (
593 &csr->details.payment_required.payment_secret)); 587 "payment_secret",
594 GNUNET_assert (NULL != pay); 588 &csr->details.payment_required.payment_secret));
595 GNUNET_assert (0 == 589 GNUNET_assert (0 ==
596 json_object_set_new (feedback, 590 json_object_set_new (feedback,
597 uuid, 591 uuid,
@@ -604,11 +598,11 @@ answer_feedback_cb (
604 598
605 GNUNET_assert (NULL != challenge); 599 GNUNET_assert (NULL != challenge);
606 GNUNET_assert (0 == 600 GNUNET_assert (0 ==
607 json_object_set_new (challenge, 601 json_object_set_new (
608 "payment_secret", 602 challenge,
609 GNUNET_JSON_from_data_auto ( 603 "payment_secret",
610 &csr->details.payment_required. 604 GNUNET_JSON_from_data_auto (
611 payment_secret))); 605 &csr->details.payment_required.payment_secret)));
612 } 606 }
613 set_state (sctx->state, 607 set_state (sctx->state,
614 ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING); 608 ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING);
@@ -621,14 +615,14 @@ answer_feedback_cb (
621 { 615 {
622 json_t *err; 616 json_t *err;
623 617
624 err = json_pack ("{s:s, s:I, s:I}", 618 err = GNUNET_JSON_PACK (
625 "state", 619 GNUNET_JSON_pack_string ("state",
626 "server-failure", 620 "server-failure"),
627 "http_status", 621 GNUNET_JSON_pack_uint64 ("http_status",
628 (json_int_t) csr->details.server_failure.http_status, 622 csr->details.server_failure.
629 "error_code", 623 http_status),
630 (json_int_t) csr->details.server_failure.ec); 624 GNUNET_JSON_pack_uint64 ("error_code",
631 GNUNET_assert (NULL != err); 625 csr->details.server_failure.ec));
632 GNUNET_assert (0 == 626 GNUNET_assert (0 ==
633 json_object_set_new (feedback, 627 json_object_set_new (feedback,
634 uuid, 628 uuid,
@@ -646,12 +640,11 @@ answer_feedback_cb (
646 { 640 {
647 json_t *err; 641 json_t *err;
648 642
649 err = json_pack ("{s:s, s:I}", 643 err = GNUNET_JSON_PACK (
650 "state", 644 GNUNET_JSON_pack_string ("state",
651 "truth-unknown", 645 "truth-unknown"),
652 "error_code", 646 GNUNET_JSON_pack_uint64 ("error_code",
653 (json_int_t) TALER_EC_ANASTASIS_TRUTH_UNKNOWN); 647 TALER_EC_ANASTASIS_TRUTH_UNKNOWN));
654 GNUNET_assert (NULL != err);
655 GNUNET_assert (0 == 648 GNUNET_assert (0 ==
656 json_object_set_new (feedback, 649 json_object_set_new (feedback,
657 uuid, 650 uuid,
@@ -668,13 +661,11 @@ answer_feedback_cb (
668 { 661 {
669 json_t *err; 662 json_t *err;
670 663
671 err = json_pack ("{s:s, s:I}", 664 err = GNUNET_JSON_PACK (
672 "state", 665 GNUNET_JSON_pack_string ("state",
673 "rate-limit-exceeded", 666 "rate-limit-exceeded"),
674 "error_code", 667 GNUNET_JSON_pack_uint64 ("error_code",
675 (json_int_t) TALER_EC_ANASTASIS_TRUTH_RATE_LIMITED); 668 TALER_EC_ANASTASIS_TRUTH_RATE_LIMITED));
676
677 GNUNET_assert (NULL != err);
678 GNUNET_assert (0 == 669 GNUNET_assert (0 ==
679 json_object_set_new (feedback, 670 json_object_set_new (feedback,
680 uuid, 671 uuid,
@@ -1585,13 +1576,13 @@ change_version (json_t *state,
1585 "'identity_attributes' missing"); 1576 "'identity_attributes' missing");
1586 return NULL; 1577 return NULL;
1587 } 1578 }
1588 args = json_pack ("{s:I, s:O, s:s}", 1579 args = GNUNET_JSON_PACK (
1589 "version", 1580 GNUNET_JSON_pack_uint64 ("version",
1590 (json_int_t) version, 1581 version),
1591 "identity_attributes", 1582 GNUNET_JSON_pack_object_incref ("identity_attributes",
1592 ia, 1583 (json_t *) ia),
1593 "provider_url", 1584 GNUNET_JSON_pack_string ("provider_url",
1594 provider_url); 1585 provider_url));
1595 if (NULL == args) 1586 if (NULL == args)
1596 { 1587 {
1597 GNUNET_break (0); 1588 GNUNET_break (0);
@@ -2101,12 +2092,13 @@ return_no_policy (struct RecoverSecretState *rss,
2101 2092
2102 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2093 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2103 "No provider online, need user to manually specify providers!\n"); 2094 "No provider online, need user to manually specify providers!\n");
2104 msg = json_pack ("{s:s, s:b}", 2095 msg = GNUNET_JSON_PACK (
2105 "hint", 2096 GNUNET_JSON_pack_string ("hint",
2106 offline ? "could not contact provider" : 2097 offline
2107 "provider does not know you", 2098 ? "could not contact provider"
2108 "offline", 2099 : "provider does not know you"),
2109 offline); 2100 GNUNET_JSON_pack_bool ("offline",
2101 offline));
2110 GNUNET_assert (0 == 2102 GNUNET_assert (0 ==
2111 json_object_set_new (rss->state, 2103 json_object_set_new (rss->state,
2112 "recovery_error", 2104 "recovery_error",
@@ -2179,10 +2171,9 @@ policy_lookup_cb (void *cls,
2179 json_t *cj; 2171 json_t *cj;
2180 2172
2181 cd = ANASTASIS_challenge_get_details (c); 2173 cd = ANASTASIS_challenge_get_details (c);
2182 cj = json_pack ("{s:o}", 2174 cj = GNUNET_JSON_PACK (
2183 "uuid", 2175 GNUNET_JSON_pack_data_auto ("uuid",
2184 GNUNET_JSON_from_data_auto (&cd->uuid)); 2176 &cd->uuid));
2185 GNUNET_assert (NULL != cj);
2186 GNUNET_assert (0 == 2177 GNUNET_assert (0 ==
2187 json_array_append_new (pchallenges, 2178 json_array_append_new (pchallenges,
2188 cj)); 2179 cj));
@@ -2221,29 +2212,33 @@ policy_lookup_cb (void *cls,
2221 return; 2212 return;
2222 } 2213 }
2223 2214
2224 cj = json_pack ("{s:o,s:o?,s:s,s:s}", 2215 cj = GNUNET_JSON_PACK (
2225 "uuid", 2216 GNUNET_JSON_pack_data_auto ("uuid",
2226 GNUNET_JSON_from_data_auto (&cd->uuid), 2217 &cd->uuid),
2227 "cost", 2218 TALER_JSON_pack_amount ("cost",
2228 (GNUNET_NO == ret) 2219 (GNUNET_NO == ret)
2229 ? NULL 2220 ? NULL
2230 : TALER_JSON_from_amount (&cost), 2221 : &cost),
2231 "type", 2222 GNUNET_JSON_pack_string ("type",
2232 cd->type, 2223 cd->type),
2233 "instructions", 2224 GNUNET_JSON_pack_string ("instructions",
2234 cd->instructions); 2225 cd->instructions));
2235 GNUNET_assert (NULL != cj);
2236 GNUNET_assert (0 == 2226 GNUNET_assert (0 ==
2237 json_array_append_new (challenges, 2227 json_array_append_new (challenges,
2238 cj)); 2228 cj));
2239 } /* end for all challenges */ 2229 } /* end for all challenges */
2240 recovery_information = json_pack ("{s:o, s:o, s:s?, s:s, s:I}", 2230 recovery_information = GNUNET_JSON_PACK (
2241 "challenges", challenges, 2231 GNUNET_JSON_pack_array_steal ("challenges",
2242 "policies", policies, 2232 challenges),
2243 "secret_name", ri->secret_name, 2233 GNUNET_JSON_pack_array_steal ("policies",
2244 "provider_url", pd->backend_url, 2234 policies),
2245 "version", (json_int_t) ri->version); 2235 GNUNET_JSON_pack_allow_null (
2246 GNUNET_assert (NULL != recovery_information); 2236 GNUNET_JSON_pack_string ("secret_name",
2237 ri->secret_name)),
2238 GNUNET_JSON_pack_string ("provider_url",
2239 pd->backend_url),
2240 GNUNET_JSON_pack_uint64 ("version",
2241 ri->version));
2247 GNUNET_assert (0 == 2242 GNUNET_assert (0 ==
2248 json_object_set_new (rss->state, 2243 json_object_set_new (rss->state,
2249 "recovery_information", 2244 "recovery_information",
diff --git a/src/reducer/anastasis_api_redux.c b/src/reducer/anastasis_api_redux.c
index 7b7e5d5..4246682 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -1684,8 +1684,8 @@ ANASTASIS_REDUX_load_continents_ ()
1684 if (NULL == ex) 1684 if (NULL == ex)
1685 { 1685 {
1686 ex = GNUNET_JSON_PACK ( 1686 ex = GNUNET_JSON_PACK (
1687 GNUNET_JSON_pack_object_incref ("name", 1687 GNUNET_JSON_pack_string ("name",
1688 (json_t *) continent)); 1688 json_string_value (continent)));
1689 GNUNET_assert (0 == 1689 GNUNET_assert (0 ==
1690 json_array_append_new (continents, 1690 json_array_append_new (continents,
1691 ex)); 1691 ex));