aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_gns.c
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-08-29 22:39:10 +0200
committerjospaeth <spaethj@in.tum.de>2020-08-29 22:39:10 +0200
commite59a1f216e5ac50d734d3936ca739fcd057aba32 (patch)
tree273697f3c29993cf265b829dafcf7a03913d844a /src/escrow/plugin_escrow_gns.c
parentabd526c01164422a086374a1a96ca9ee5e781b01 (diff)
downloadgnunet-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_gns.c')
-rw-r--r--src/escrow/plugin_escrow_gns.c47
1 files changed, 4 insertions, 43 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c
index 94ce175c5..121fdc4af 100644
--- a/src/escrow/plugin_escrow_gns.c
+++ b/src/escrow/plugin_escrow_gns.c
@@ -1668,38 +1668,8 @@ struct GNUNET_ESCROW_Anchor *
1668gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, 1668gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
1669 char *anchorString) 1669 char *anchorString)
1670{ 1670{
1671 struct GNUNET_ESCROW_Anchor *anchor; 1671 return ESCROW_anchor_string_to_data (anchorString,
1672 uint32_t data_size; 1672 GNUNET_ESCROW_KEY_GNS);
1673 char *anchorStringCopy, *ptr, *egoNameCopy;
1674 char delimiter[] = ":";
1675
1676 anchorStringCopy = GNUNET_strdup (anchorString);
1677
1678 // split the string at the first occurrence of the delimiter
1679 ptr = strtok (anchorStringCopy, delimiter);
1680 egoNameCopy = GNUNET_strdup (ptr);
1681 ptr = strtok (NULL, delimiter);
1682
1683 if (NULL == ptr)
1684 {
1685 // delimiter was not found
1686 GNUNET_free (egoNameCopy);
1687 GNUNET_free (anchorStringCopy);
1688 return NULL;
1689 }
1690
1691 data_size = strlen (ptr) + 1;
1692 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + data_size);
1693 anchor->size = data_size;
1694 anchor->egoName = egoNameCopy;
1695 anchor->method = GNUNET_ESCROW_KEY_GNS;
1696
1697 // TODO: deserialize?
1698 GNUNET_memcpy (&anchor[1], ptr, data_size);
1699
1700 GNUNET_free (anchorStringCopy);
1701
1702 return anchor;
1703} 1673}
1704 1674
1705 1675
@@ -1715,17 +1685,8 @@ char *
1715gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h, 1685gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
1716 struct GNUNET_ESCROW_Anchor *escrowAnchor) 1686 struct GNUNET_ESCROW_Anchor *escrowAnchor)
1717{ 1687{
1718 char *anchorString; 1688 return ESCROW_anchor_data_to_string (escrowAnchor,
1719 size_t egoNameSize; 1689 GNUNET_ESCROW_KEY_GNS);
1720
1721 egoNameSize = strlen (escrowAnchor->egoName);
1722
1723 anchorString = GNUNET_malloc (egoNameSize + 1 + escrowAnchor->size);
1724 GNUNET_memcpy (anchorString, escrowAnchor->egoName, egoNameSize);
1725 anchorString[egoNameSize] = ':';
1726 GNUNET_memcpy (anchorString + egoNameSize + 1, &escrowAnchor[1], escrowAnchor->size);
1727
1728 return anchorString;
1729} 1690}
1730 1691
1731 1692