diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 15:23:44 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 15:23:44 +0200 |
commit | 494af3383d2a5d3402e1f03209cb574af86079a8 (patch) | |
tree | 6b457d61846e2f18c3f1b4ace0e3e58480e3e15c /src/reclaim/gnunet-reclaim.c | |
parent | a277e037fefe605c93d81869ac514f87cad25768 (diff) | |
download | gnunet-494af3383d2a5d3402e1f03209cb574af86079a8.tar.gz gnunet-494af3383d2a5d3402e1f03209cb574af86079a8.zip |
RECLAIM: bugfixes; add delete attribute API
Diffstat (limited to 'src/reclaim/gnunet-reclaim.c')
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index 1c3b4174d..a9d6f67d2 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -157,6 +157,16 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task; | |||
157 | */ | 157 | */ |
158 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 158 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; |
159 | 159 | ||
160 | /** | ||
161 | * Claim to delete | ||
162 | */ | ||
163 | static char *attr_delete; | ||
164 | |||
165 | /** | ||
166 | * Claim object to delete | ||
167 | */ | ||
168 | static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete; | ||
169 | |||
160 | static void | 170 | static void |
161 | do_cleanup (void *cls) | 171 | do_cleanup (void *cls) |
162 | { | 172 | { |
@@ -177,6 +187,8 @@ do_cleanup (void *cls) | |||
177 | GNUNET_free (abe_key); | 187 | GNUNET_free (abe_key); |
178 | if (NULL != attr_list) | 188 | if (NULL != attr_list) |
179 | GNUNET_free (attr_list); | 189 | GNUNET_free (attr_list); |
190 | if (NULL != attr_to_delete) | ||
191 | GNUNET_free (attr_to_delete); | ||
180 | } | 192 | } |
181 | 193 | ||
182 | static void | 194 | static void |
@@ -208,6 +220,7 @@ process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | |||
208 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 220 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) |
209 | { | 221 | { |
210 | char *value_str; | 222 | char *value_str; |
223 | char *id; | ||
211 | const char *attr_type; | 224 | const char *attr_type; |
212 | 225 | ||
213 | if (NULL == identity) { | 226 | if (NULL == identity) { |
@@ -222,8 +235,10 @@ process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | |||
222 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, | 235 | value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, |
223 | attr->data_size); | 236 | attr->data_size); |
224 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 237 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
225 | fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, value_str, | 238 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); |
226 | attr_type, attr->version, attr->id); | 239 | fprintf (stdout, "Name: %s; Value: %s (%s); Version %u; ID: %s\n", attr->name, |
240 | value_str, attr_type, attr->version, id); | ||
241 | GNUNET_free (id); | ||
227 | } | 242 | } |
228 | 243 | ||
229 | static void | 244 | static void |
@@ -284,6 +299,19 @@ process_rvk (void *cls, int success, const char *msg) | |||
284 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 299 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
285 | } | 300 | } |
286 | 301 | ||
302 | |||
303 | static void | ||
304 | process_delete (void *cls, int success, const char *msg) | ||
305 | { | ||
306 | reclaim_op = NULL; | ||
307 | if (GNUNET_OK != success) { | ||
308 | fprintf (stderr, "Deletion failed.\n"); | ||
309 | ret = 1; | ||
310 | } | ||
311 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
312 | } | ||
313 | |||
314 | |||
287 | static void | 315 | static void |
288 | iter_finished (void *cls) | 316 | iter_finished (void *cls) |
289 | { | 317 | { |
@@ -315,6 +343,15 @@ iter_finished (void *cls) | |||
315 | &process_rvk, NULL); | 343 | &process_rvk, NULL); |
316 | return; | 344 | return; |
317 | } | 345 | } |
346 | if (attr_delete) { | ||
347 | if (NULL == attr_to_delete) { | ||
348 | fprintf (stdout, "No such attribute ``%s''\n", attr_delete); | ||
349 | return; | ||
350 | } | ||
351 | reclaim_op = GNUNET_RECLAIM_attribute_delete ( | ||
352 | reclaim_handle, pkey, attr_to_delete, &process_delete, NULL); | ||
353 | return; | ||
354 | } | ||
318 | if (attr_name) { | 355 | if (attr_name) { |
319 | if (NULL == type_str) | 356 | if (NULL == type_str) |
320 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; | 357 | type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING; |
@@ -348,6 +385,8 @@ iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | |||
348 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 385 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
349 | char *attrs_tmp; | 386 | char *attrs_tmp; |
350 | char *attr_str; | 387 | char *attr_str; |
388 | char *label; | ||
389 | char *id; | ||
351 | const char *attr_type; | 390 | const char *attr_type; |
352 | 391 | ||
353 | if ((NULL != attr_name) && (NULL != claim)) { | 392 | if ((NULL != attr_name) && (NULL != claim)) { |
@@ -373,12 +412,22 @@ iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | |||
373 | break; | 412 | break; |
374 | } | 413 | } |
375 | GNUNET_free (attrs_tmp); | 414 | GNUNET_free (attrs_tmp); |
415 | } else if (attr_delete && (NULL == attr_to_delete)) { | ||
416 | label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); | ||
417 | if (0 == strcasecmp (attr_delete, label)) { | ||
418 | attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new ( | ||
419 | attr->name, attr->type, attr->data, attr->data_size); | ||
420 | attr_to_delete->id = attr->id; | ||
421 | } | ||
422 | GNUNET_free (label); | ||
376 | } else if (list) { | 423 | } else if (list) { |
377 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, | 424 | attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data, |
378 | attr->data_size); | 425 | attr->data_size); |
379 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); | 426 | attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); |
380 | fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, attr_str, | 427 | id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); |
381 | attr_type, attr->version, attr->id); | 428 | fprintf (stdout, "Name: %s; Value: %s (%s); Version %u; ID: %s\n", |
429 | attr->name, attr_str, attr_type, attr->version, id); | ||
430 | GNUNET_free (id); | ||
382 | } | 431 | } |
383 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); | 432 | GNUNET_RECLAIM_get_attributes_next (attr_iterator); |
384 | } | 433 | } |
@@ -474,7 +523,9 @@ main (int argc, char *const argv[]) | |||
474 | GNUNET_GETOPT_option_string ('a', "add", "NAME", | 523 | GNUNET_GETOPT_option_string ('a', "add", "NAME", |
475 | gettext_noop ("Add an attribute NAME"), | 524 | gettext_noop ("Add an attribute NAME"), |
476 | &attr_name), | 525 | &attr_name), |
477 | 526 | GNUNET_GETOPT_option_string ('d', "delete", "ID", | |
527 | gettext_noop ("Add an attribute with ID"), | ||
528 | &attr_delete), | ||
478 | GNUNET_GETOPT_option_string ('V', "value", "VALUE", | 529 | GNUNET_GETOPT_option_string ('V', "value", "VALUE", |
479 | gettext_noop ("The attribute VALUE"), | 530 | gettext_noop ("The attribute VALUE"), |
480 | &attr_value), | 531 | &attr_value), |