X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fidentity-attribute%2Fidentity_attribute.c;h=dc2753fcab9c5a88113f585ff8711fdbbbc6c102;hb=f40acfa927bb605c81c99ed250277d51bf951e25;hp=a8aae6ced7593da8382436837fd1cedb80243ddc;hpb=02861d7594513ad336f86ff20162a861489f20b1;p=oweals%2Fgnunet.git diff --git a/src/identity-attribute/identity_attribute.c b/src/identity-attribute/identity_attribute.c index a8aae6ced..dc2753fca 100644 --- a/src/identity-attribute/identity_attribute.c +++ b/src/identity-attribute/identity_attribute.c @@ -19,7 +19,7 @@ */ /** - * @file identity-provider/identity_attribute.c + * @file identity-attribute/identity_attribute.c * @brief helper library to manage identity attributes * @author Martin Schanzenbach */ @@ -206,7 +206,7 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, /** * Create a new attribute. * - * @param name the attribute name + * @param attr_name the attribute name * @param type the attribute type * @param data the attribute value * @param data_size the attribute value size @@ -214,7 +214,7 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type, */ struct GNUNET_IDENTITY_ATTRIBUTE_Claim * GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, - uint32_t attr_type, + uint32_t type, const void* data, size_t data_size) { @@ -224,7 +224,7 @@ GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, attr = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + strlen (attr_name) + 1 + data_size); - attr->type = attr_type; + attr->type = type; attr->data_size = data_size; attr->version = 0; write_ptr = (char*)&attr[1]; @@ -240,6 +240,34 @@ GNUNET_IDENTITY_ATTRIBUTE_claim_new (const char* attr_name, return attr; } +/** + * Add a new claim list entry. + * + * @param claim_list the attribute name + * @param attr_name the attribute name + * @param type the attribute type + * @param data the attribute value + * @param data_size the attribute value size + * @return + */ +void +GNUNET_IDENTITY_ATTRIBUTE_list_add (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *claim_list, + const char* attr_name, + uint32_t type, + const void* data, + size_t data_size) +{ + struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; + le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); + le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (attr_name, + type, + data, + data_size); + GNUNET_CONTAINER_DLL_insert (claim_list->list_head, + claim_list->list_tail, + le); +} + size_t GNUNET_IDENTITY_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs) { @@ -308,18 +336,15 @@ GNUNET_IDENTITY_ATTRIBUTE_list_dup (const struct GNUNET_IDENTITY_ATTRIBUTE_Claim struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le; struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *result_le; struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *result; - size_t len; result = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList); for (le = attrs->list_head; NULL != le; le = le->next) { result_le = GNUNET_new (struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry); - len = sizeof (struct GNUNET_IDENTITY_ATTRIBUTE_Claim) + le->claim->data_size; - result_le->claim = GNUNET_malloc (len); - GNUNET_memcpy (result_le->claim, - le->claim, - len); - result_le->claim->name = (const char*)&result_le->claim[1]; + result_le->claim = GNUNET_IDENTITY_ATTRIBUTE_claim_new (le->claim->name, + le->claim->type, + le->claim->data, + le->claim->data_size); GNUNET_CONTAINER_DLL_insert (result->list_head, result->list_tail, result_le);