From 77494b746ad3baa510ddf751c046b0fa802bfd5f Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Sun, 14 Apr 2019 18:45:38 +0200 Subject: RECLAIM/REST: Fix attribute update/rest store --- src/reclaim/gnunet-service-reclaim.c | 7 ++++--- src/reclaim/json_reclaim.c | 17 +++++++++-------- src/reclaim/plugin_rest_reclaim.c | 5 +++-- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index a49962b4d..0f0de86d3 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c @@ -778,9 +778,10 @@ attr_store_task (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); buf = GNUNET_malloc (buf_size); - // Give the ash a new id - ash->claim->id = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); + // Give the ash a new id if unset + if (0 == ash->claim->id) + ash->claim->id = + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); label = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, sizeof (uint64_t)); diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 79110490a..9c186b64a 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c @@ -44,10 +44,10 @@ static int parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) { struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; - const char *name_str; - const char *val_str; - const char *type_str; - const char *id_str; + const char *name_str = NULL; + const char *val_str = NULL; + const char *type_str = NULL; + const char *id_str = NULL; char *data; int unpack_state; uint32_t type; @@ -62,10 +62,11 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) } // interpret single attribute unpack_state = - json_unpack (root, "{s:s, s:s, s:s, s:s!}", "name", &name_str, "id", + json_unpack (root, "{s:s, s?s, s:s, s:s!}", "name", &name_str, "id", &id_str, "type", &type_str, "value", &val_str); - if (0 != unpack_state) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || + (NULL == type_str)) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error json object has a wrong format!\n"); return GNUNET_SYSERR; } @@ -76,7 +77,7 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) return GNUNET_SYSERR; } attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); - if (0 == strlen (id_str)) + if ((NULL == id_str) || (0 == strlen (id_str))) attr->id = 0; else GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &attr->id, diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 74071d97b..1a3784e64 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c @@ -539,8 +539,9 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, /** * New ID for attribute */ - attribute->id = - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); + if (0 == attribute->id) + attribute->id = + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); handle->idp = GNUNET_RECLAIM_connect (cfg); exp = GNUNET_TIME_UNIT_HOURS; handle->idp_op = GNUNET_RECLAIM_attribute_store ( -- cgit v1.2.3