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));
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;
}
// 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;
}
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,
/**
* 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 (