[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/03: fix json usage
From: |
gnunet |
Subject: |
[taler-anastasis] 02/03: fix json usage |
Date: |
Tue, 22 Dec 2020 13:30:29 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 1d27a8296f56d4ef084479dc606415129a816d92
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Mon Dec 21 19:41:21 2020 +0100
fix json usage
---
contrib/redux.ch.json | 38 ++++----
src/cli/test_anastasis_reducer_enter_secret.sh | 12 +--
src/lib/anastasis.c | 6 +-
src/lib/anastasis_api_backup_redux.c | 125 ++++++++++++-------------
src/lib/anastasis_api_redux.c | 2 +-
5 files changed, 88 insertions(+), 95 deletions(-)
diff --git a/contrib/redux.ch.json b/contrib/redux.ch.json
index 9cfeaec..7e2901e 100644
--- a/contrib/redux.ch.json
+++ b/contrib/redux.ch.json
@@ -1,33 +1,33 @@
{
"required_attributes": [
{
- "type": "string",
- "name": "full_name",
- "label": "Full name",
- "label_i18n":{
- "de_DE":"Vollstaendiger Name",
- "de_CH":"Vollstaendiger Name"
- },
- "widget": "anastasis_gtk_ia_full_name"
+ "type": "string",
+ "name": "full_name",
+ "label": "Full name",
+ "label_i18n":{
+ "de_DE":"Vollstaendiger Name",
+ "de_CH":"Vollstaendiger Name"
+ },
+ "widget": "anastasis_gtk_ia_full_name"
},
{
"type": "date",
"name": "birthdate",
- "label": "Birthdate",
+ "label": "Birthdate",
"label_i18n":{"de_CH":"Geburtsdatum"},
"widget": "anastasis_gtk_ia_birthdate"
},
{
- "type": "string",
- "name": "ahv_number",
- "label": "AHV number",
- "label_i18n":{
- "de_DE":"AHV-Nummer",
- "de_CH":"AHV-Nummer"
- },
- "widget": "anastasis_gtk_ia_ahv",
- "validation-regex":
"^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$",
- "validation-logic": "CH_AVH_check"
+ "type": "string",
+ "name": "ahv_number",
+ "label": "AHV number",
+ "label_i18n":{
+ "de_DE":"AHV-Nummer",
+ "de_CH":"AHV-Nummer"
+ },
+ "widget": "anastasis_gtk_ia_ahv",
+ "validation-regex":
"^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$",
+ "validation-logic": "CH_AVH_check"
}
]
}
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 88b5c98..edd283a 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -291,10 +291,10 @@ then
exit_fail "Expected new state to be POLICIES_PAYING, got $STATE"
fi
-ARRAY_LENGTH=`jq -r -e '.truth_uploads | length' < $TFILE`
-if test $ARRAY_LENGTH -lt 3
+OBJECT_SIZE=`jq -r -e '.truth_uploads | length' < $TFILE`
+if test $OBJECT_SIZE -lt 3
then
- exit_fail "Expected truth_uploads array length to be >= 3, got
$ARRAY_LENGTH"
+ exit_fail "Expected truth_uploads array length to be >= 3, got
$OBJECT_SIZE"
fi
echo " "
@@ -321,10 +321,10 @@ taler-wallet-cli --wallet-db=$WALLET_DB run-until-done
echo " "
echo -e $COLOR$BOLD"Parsing policy uploads for payment-uri"$NORM$NOCOLOR
-ARRAY_LENGTH=`jq -r -e '.recovery_document_uploads | length' < $TFILE`
-for ((INDEX=0; INDEX < $ARRAY_LENGTH; INDEX++))
+OBJECT_SIZE=`jq -r -e '.recovery_document_uploads | length' < $TFILE`
+for ((INDEX=0; INDEX < $OBJECT_SIZE; INDEX++))
do
- PAY_URI=`jq -r -e .recovery_document_uploads[$INDEX].pay_url < $TFILE`
+ PAY_URI=`jq --argjson INDEX $INDEX -r -e '[.recovery_document_uploads |
keys[] as $k | .[$k].pay_url][$INDEX]' < $TFILE`
echo " "
echo "[$INDEX] PAY_URI: $PAY_URI"
# run wallet CLI
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index 05a9e07..fc301da 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1701,11 +1701,7 @@ policy_store_cb (void *cls,
(int) ec,
__FILE__,
__LINE__);
- json_t *error = json_pack ("{s:I, s:s}",
- "code",
- (json_int_t) ec,
- "hint",
- "Unexpected response code!");
+
if (NULL != pss->src)
{
pss->src (pss->src_cls,
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index 88e1168..d72298a 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -1187,7 +1187,7 @@ done_policy_review (json_t *state,
/**
* Check if all uploads have response code 204 or 402.
*
- * @param uploads json array representing uploads (truth, recovery document)
+ * @param uploads json object representing uploads (truth, recovery document)
* @param pass if true, all response codes must be 204 to return true
* @return true if all response codes are 204 or 402, else false
*/
@@ -1195,21 +1195,19 @@ static bool
check_uploads (json_t *uploads,
bool pass)
{
- GNUNET_assert (json_is_array (uploads));
- size_t index;
- json_t *upload;
+ GNUNET_assert (json_is_object (uploads));
+ const char *key;
+ json_t *value;
- json_array_foreach (uploads, index, upload)
+ json_object_foreach (uploads, key, value)
{
- int status = json_integer_value (json_object_get (upload,
+ int status = json_integer_value (json_object_get (value,
"status"));
- if (pass && (status != 204))
+ if (pass && (status != MHD_HTTP_NO_CONTENT))
return false;
- if ((status != 204) &&
- (status != 402) )
- {
+ if ((status != MHD_HTTP_NO_CONTENT) &&
+ (status != MHD_HTTP_PAYMENT_REQUIRED) )
return false;
- }
}
return true;
}
@@ -1225,23 +1223,23 @@ static unsigned int
initialize_payment_details (json_t *state,
struct ANASTASIS_PaymentDetails *pds)
{
- size_t index;
- json_t *upload;
+ const char *upload_key;
+ json_t *upload_value;
json_t *rec_doc_uploads = json_object_get (state,
"recovery_document_uploads");
unsigned int pds_len = 0;
- if (json_array_size (rec_doc_uploads) > 0)
+ if (json_object_size (rec_doc_uploads) > 0)
{
- json_array_foreach (rec_doc_uploads, index, upload)
+ json_object_foreach (rec_doc_uploads, upload_key, upload_value)
{
struct ANASTASIS_PaymentDetails p_details;
const char *pay_uri = json_string_value (
- json_object_get (upload,
+ json_object_get (upload_value,
"pay_url"));
const char *provider_url = json_string_value (
- json_object_get (upload,
+ json_object_get (upload_value,
"provider_url"));
if ((NULL != pay_uri) &&
(NULL != provider_url))
@@ -1266,9 +1264,8 @@ initialize_payment_details (json_t *state,
TALER_MERCHANT_parse_pay_uri_free (&pd);
return 0;
}
- TALER_MERCHANT_parse_pay_uri_free (&pd);
p_details.provider_url = GNUNET_strdup (provider_url);
-
+ TALER_MERCHANT_parse_pay_uri_free (&pd);
GNUNET_array_append (pds,
pds_len,
p_details);
@@ -1288,18 +1285,18 @@ static void
initialize_policies (json_t *state)
{
size_t p_index;
+ json_t *rec_doc_uploads;
+ json_t *truth_uploads;
json_t *json_policy;
json_t *json_policies = json_object_get (state,
"policies");
GNUNET_assert (json_is_array (json_policies));
- json_t *truth_uploads = json_object_get (state,
- "truth_uploads");
-
- GNUNET_assert (json_is_array (truth_uploads));
- json_t *rec_doc_uploads = json_array ();
-
- GNUNET_assert (json_is_array (rec_doc_uploads));
+ truth_uploads = json_object_get (state,
+ "truth_uploads");
+ GNUNET_assert (json_is_object (truth_uploads));
+ rec_doc_uploads = json_object ();
+ GNUNET_assert (json_is_object (rec_doc_uploads));
json_array_foreach (json_policies, p_index, json_policy)
{
@@ -1314,22 +1311,23 @@ initialize_policies (json_t *state)
index,
auth_method)
{
- size_t tu_index;
- json_t *tu;
+ const char *tu_key;
+ json_t *tu_value;
unsigned int auth_method_index = json_integer_value (json_object_get (
auth_method,
"authentication_method"));
- json_array_foreach (truth_uploads, tu_index, tu)
+ json_object_foreach (truth_uploads, tu_key, tu_value)
{
json_t *json_truth
= json_array_get (json_object_get (state, "truths"),
- json_integer_value (
- json_object_get (tu, "truth_index")));
+ atoi (tu_key));
if (json_integer_value (
json_object_get (json_truth, "auth_method_index"))
== auth_method_index)
{
- truths[truth_index] = ANASTASIS_truth_from_json (tu);
+ truths[truth_index] = ANASTASIS_truth_from_json (
+ json_object_get (tu_value,
+ "truth"));
truth_index++;
break;
}
@@ -1337,16 +1335,15 @@ initialize_policies (json_t *state)
{
// initialize recovery document uploads array
bool existing = false;
- size_t upload_index;
- json_t *upload;
+ const char *upload_key;
+ json_t *upload_value;
json_t *provider_id = json_object_get (auth_method,
"provider");
- if (0 < json_array_size (rec_doc_uploads))
+ if (0 < json_object_size (rec_doc_uploads))
{
- json_array_foreach (rec_doc_uploads, upload_index, upload)
+ json_object_foreach (rec_doc_uploads, upload_key, upload_value)
{
- if (1 == json_equal (provider_id, json_object_get (upload,
- "provider")))
+ if (1 == json_equal (provider_id, json_string (upload_key)))
{
existing = true;
break;
@@ -1360,14 +1357,13 @@ initialize_policies (json_t *state)
const char *provider_url = get_provider_url_from_id (id,
state);
GNUNET_assert (0 ==
- json_array_append (rec_doc_uploads,
- json_pack ("{s:I, s:s, s:s}",
- "status",
- (json_int_t) 0,
- "provider",
- id,
- "provider_url",
- provider_url)));
+ json_object_set (rec_doc_uploads,
+ id,
+ json_pack ("{s:I, s:s}",
+ "status",
+ (json_int_t) 0,
+ "provider_url",
+ provider_url)));
}
}
}
@@ -1376,11 +1372,10 @@ initialize_policies (json_t *state)
"recovery_document_uploads",
rec_doc_uploads));
- struct ANASTASIS_Policy *policy = ANASTASIS_policy_create (truths,
- truth_index);
GNUNET_array_append (policy_arr,
policy_arr_length,
- policy);
+ ANASTASIS_policy_create (truths,
+ truth_index));
}
}
@@ -1407,28 +1402,29 @@ secret_share_payment_cb (void *cls,
__FILE__, __LINE__,
taler_pay_url);
- size_t index;
- json_t *upload;
+ const char *upload_key;
+ json_t *upload_value;
struct SecretShareState *sss = cls;
json_t *rec_doc_uploads = json_object_get (sss->state,
"recovery_document_uploads");
- GNUNET_assert (json_is_array (rec_doc_uploads));
+ GNUNET_assert (json_is_object (rec_doc_uploads));
sss->sso = NULL;
- json_array_foreach (rec_doc_uploads, index, upload)
+ json_object_foreach (rec_doc_uploads, upload_key, upload_value)
{
const char *url = json_string_value (
- json_object_get (upload,
+ json_object_get (upload_value,
"provider_url"));
if (0 == strcmp (url, server_url))
{
GNUNET_assert (0 ==
- json_object_set (upload,
+ json_object_set (upload_value,
"status",
- json_integer ((json_int_t) 402)));
+ json_integer (
+ (json_int_t)
MHD_HTTP_PAYMENT_REQUIRED)));
GNUNET_assert (0 ==
- json_object_set (upload,
+ json_object_set (upload_value,
"pay_url",
json_string (taler_pay_url)));
break;
@@ -1491,23 +1487,23 @@ secret_share_result_cb (void *cls,
"At %s:%d we are in SRC\n",
__FILE__, __LINE__);
- size_t index;
- json_t *upload;
+ const char *upload_key;
+ json_t *upload_value;
struct SecretShareState *sss = cls;
json_t *rec_doc_uploads = json_object_get (sss->state,
"recovery_document_uploads");
sss->sso = NULL;
- GNUNET_assert (json_is_array (rec_doc_uploads));
- json_array_foreach (rec_doc_uploads, index, upload)
+ GNUNET_assert (json_is_object (rec_doc_uploads));
+ json_object_foreach (rec_doc_uploads, upload_key, upload_value)
{
const char *url = json_string_value (
- json_object_get (upload,
+ json_object_get (upload_value,
"provider_url"));
if (0 == strcmp (url, server_url))
{
GNUNET_assert (0 ==
- json_object_set (upload,
+ json_object_set (upload_value,
"status",
json_integer ((json_int_t)
http_status)));
break;
@@ -1700,6 +1696,7 @@ truth_upload_cb (void *cls,
"enter_secret or pay");
return;
}
+ tus->truth = t;
truth_uploads = json_object_get (tus->state,
"truth_uploads");
j = ANASTASIS_truth_to_json (tus->truth);
@@ -2092,7 +2089,7 @@ pay_backup (json_t *state,
json_t *truth_uploads = json_object_get (state,
"truth_uploads");
- GNUNET_assert (json_is_array (truth_uploads));
+ GNUNET_assert (json_is_object (truth_uploads));
if (check_uploads (truth_uploads, true))
upload_rec_documents (state,
ctx,
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 38f09de..710082b 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -951,7 +951,7 @@ enter_user_attributes (json_t *state,
json_decref (error);
return NULL;
}
- reglog = json_string_value (json_object_get (attribute_value,
+ reglog = json_string_value (json_object_get (required_attribute,
"validation-logic"));
if ( (NULL != reglog) &&
(NULL != (regfun = dlsym (RTLD_DEFAULT,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.