diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-29 22:39:10 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-29 22:39:10 +0200 |
commit | e59a1f216e5ac50d734d3936ca739fcd057aba32 (patch) | |
tree | 273697f3c29993cf265b829dafcf7a03913d844a /src/escrow/plugin_escrow_plaintext.c | |
parent | abd526c01164422a086374a1a96ca9ee5e781b01 (diff) | |
download | gnunet-e59a1f216e5ac50d734d3936ca739fcd057aba32.tar.gz gnunet-e59a1f216e5ac50d734d3936ca739fcd057aba32.zip |
refactor anchor_string_to_data and anchor_data_to_string in the plugins
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r-- | src/escrow/plugin_escrow_plaintext.c | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c index eace829ea..215c8127e 100644 --- a/src/escrow/plugin_escrow_plaintext.c +++ b/src/escrow/plugin_escrow_plaintext.c | |||
@@ -457,38 +457,8 @@ struct GNUNET_ESCROW_Anchor * | |||
457 | plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | 457 | plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, |
458 | char *anchorString) | 458 | char *anchorString) |
459 | { | 459 | { |
460 | struct GNUNET_ESCROW_Anchor *anchor; | 460 | return ESCROW_anchor_string_to_data (anchorString, |
461 | uint32_t data_size; | 461 | GNUNET_ESCROW_KEY_PLAINTEXT); |
462 | char *anchorStringCopy, *ptr, *egoNameCopy; | ||
463 | char delimiter[] = ":"; | ||
464 | |||
465 | anchorStringCopy = GNUNET_strdup (anchorString); | ||
466 | |||
467 | // split the string at the first occurrence of the delimiter | ||
468 | ptr = strtok (anchorStringCopy, delimiter); | ||
469 | egoNameCopy = GNUNET_strdup (ptr); | ||
470 | ptr = strtok (NULL, delimiter); | ||
471 | |||
472 | if (NULL == ptr) | ||
473 | { | ||
474 | // delimiter was not found | ||
475 | GNUNET_free (egoNameCopy); | ||
476 | GNUNET_free (anchorStringCopy); | ||
477 | return NULL; | ||
478 | } | ||
479 | |||
480 | data_size = strlen (ptr) + 1; | ||
481 | anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size); | ||
482 | anchor->size = data_size; | ||
483 | anchor->egoName = egoNameCopy; | ||
484 | anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT; | ||
485 | |||
486 | // TODO: deserialize? | ||
487 | GNUNET_memcpy (&anchor[1], ptr, data_size); | ||
488 | |||
489 | GNUNET_free (anchorStringCopy); | ||
490 | |||
491 | return anchor; | ||
492 | } | 462 | } |
493 | 463 | ||
494 | 464 | ||
@@ -504,17 +474,8 @@ char * | |||
504 | plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, | 474 | plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, |
505 | struct GNUNET_ESCROW_Anchor *escrowAnchor) | 475 | struct GNUNET_ESCROW_Anchor *escrowAnchor) |
506 | { | 476 | { |
507 | char *anchorString; | 477 | return ESCROW_anchor_data_to_string (escrowAnchor, |
508 | size_t egoNameSize; | 478 | GNUNET_ESCROW_KEY_PLAINTEXT); |
509 | |||
510 | egoNameSize = strlen (escrowAnchor->egoName); | ||
511 | |||
512 | anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size); | ||
513 | GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize); | ||
514 | anchorString[egoNameSize] = ':'; | ||
515 | GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size); | ||
516 | |||
517 | return anchorString; | ||
518 | } | 479 | } |
519 | 480 | ||
520 | 481 | ||