aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 16:52:39 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 16:52:39 +0200
commit079beb884ac4236f993736c664660c3892560c9b (patch)
tree44697c4f22dc0ec92c56da4c3e05c1d87ce6b608 /src
parent6ab14a20690a499ad32e3f2ad448d64d4e6b65fc (diff)
downloadgnunet-079beb884ac4236f993736c664660c3892560c9b.tar.gz
gnunet-079beb884ac4236f993736c664660c3892560c9b.zip
-fix serialization
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_reclaim_lib.h11
-rw-r--r--src/reclaim/Makefile.am11
-rw-r--r--src/reclaim/gnunet-service-reclaim.c15
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c12
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c10
-rw-r--r--src/reclaim/reclaim_api.c5
-rw-r--r--src/reclaim/reclaim_attribute.c51
-rw-r--r--src/reclaim/reclaim_attribute.h20
-rw-r--r--src/reclaim/test_reclaim_attribute.c51
9 files changed, 138 insertions, 48 deletions
diff --git a/src/include/gnunet_reclaim_lib.h b/src/include/gnunet_reclaim_lib.h
index 4f2d6dba5..7d521ffa8 100644
--- a/src/include/gnunet_reclaim_lib.h
+++ b/src/include/gnunet_reclaim_lib.h
@@ -65,6 +65,7 @@ extern "C" {
65 */ 65 */
66#define GNUNET_RECLAIM_ID_LENGTH (256 / 8) 66#define GNUNET_RECLAIM_ID_LENGTH (256 / 8)
67 67
68GNUNET_NETWORK_STRUCT_BEGIN
68/** 69/**
69 * A reclaim identifier 70 * A reclaim identifier
70 * FIXME maybe put this in a different namespace 71 * FIXME maybe put this in a different namespace
@@ -74,6 +75,8 @@ struct GNUNET_RECLAIM_Identifier
74 char id[GNUNET_RECLAIM_ID_LENGTH]; 75 char id[GNUNET_RECLAIM_ID_LENGTH];
75}; 76};
76 77
78GNUNET_NETWORK_STRUCT_END
79
77static const struct GNUNET_RECLAIM_Identifier GNUNET_RECLAIM_ID_ZERO; 80static const struct GNUNET_RECLAIM_Identifier GNUNET_RECLAIM_ID_ZERO;
78 81
79#define GNUNET_RECLAIM_id_is_equal(a,b) ((0 == \ 82#define GNUNET_RECLAIM_id_is_equal(a,b) ((0 == \
@@ -361,11 +364,13 @@ GNUNET_RECLAIM_attribute_serialize (const struct GNUNET_RECLAIM_Attribute *attr,
361 * 364 *
362 * @param data the serialized attribute 365 * @param data the serialized attribute
363 * @param data_size the length of the serialized data 366 * @param data_size the length of the serialized data
367 * @param attr deserialized attribute. Will be allocated. Must be free'd
364 * 368 *
365 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller 369 * @return number of bytes read or -1 for error
366 */ 370 */
367struct GNUNET_RECLAIM_Attribute * 371ssize_t
368GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size); 372GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size,
373 struct GNUNET_RECLAIM_Attribute **attr);
369 374
370 375
371/** 376/**
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index a9829c47e..9b75c11aa 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -152,11 +152,20 @@ gnunet_reclaim_LDADD = \
152 $(top_builddir)/src/identity/libgnunetidentity.la \ 152 $(top_builddir)/src/identity/libgnunetidentity.la \
153 $(GN_LIBINTL) 153 $(GN_LIBINTL)
154 154
155test_reclaim_attribute_SOURCES = \
156 test_reclaim_attribute.c
157test_reclaim_attribute_LDADD = \
158 $(top_builddir)/src/util/libgnunetutil.la \
159 libgnunetreclaim.la \
160 $(GN_LIBINTL)
161
155check_SCRIPTS = \ 162check_SCRIPTS = \
156 test_reclaim_attribute.sh \ 163 test_reclaim_attribute.sh \
157 test_reclaim_issue.sh \ 164 test_reclaim_issue.sh \
158 test_reclaim_consume.sh 165 test_reclaim_consume.sh
159# test_reclaim_revoke.sh 166
167check_PROGRAMS = \
168 test_reclaim_attribute
160 169
161if ENABLE_TEST_RUN 170if ENABLE_TEST_RUN
162 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 171 AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 0cd8c10a5..84afd482e 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -732,6 +732,7 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
732 struct TicketIssueOperation *tio; 732 struct TicketIssueOperation *tio;
733 struct IdpClient *idp = cls; 733 struct IdpClient *idp = cls;
734 struct GNUNET_RECLAIM_AttributeList *attrs; 734 struct GNUNET_RECLAIM_AttributeList *attrs;
735 struct GNUNET_RECLAIM_AttributeListEntry *le;
735 size_t attrs_len; 736 size_t attrs_len;
736 737
737 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n");
@@ -739,6 +740,10 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
739 attrs_len = ntohs (im->attr_len); 740 attrs_len = ntohs (im->attr_len);
740 attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1], 741 attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1],
741 attrs_len); 742 attrs_len);
743 for (le = attrs->list_head; NULL != le; le = le->next)
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "List entry: %s\n", le->attribute->name);
746
742 tio->r_id = ntohl (im->id); 747 tio->r_id = ntohl (im->id);
743 tio->client = idp; 748 tio->client = idp;
744 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio); 749 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio);
@@ -1053,8 +1058,9 @@ handle_attribute_store_message (void *cls,
1053 data_len = ntohs (sam->attr_len); 1058 data_len = ntohs (sam->attr_len);
1054 1059
1055 ash = GNUNET_new (struct AttributeStoreHandle); 1060 ash = GNUNET_new (struct AttributeStoreHandle);
1056 ash->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1], 1061 GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1],
1057 data_len); 1062 data_len,
1063 &ash->claim);
1058 1064
1059 ash->r_id = ntohl (sam->id); 1065 ash->r_id = ntohl (sam->id);
1060 ash->identity = sam->identity; 1066 ash->identity = sam->identity;
@@ -1548,8 +1554,9 @@ handle_attribute_delete_message (void *cls,
1548 data_len = ntohs (dam->attr_len); 1554 data_len = ntohs (dam->attr_len);
1549 1555
1550 adh = GNUNET_new (struct AttributeDeleteHandle); 1556 adh = GNUNET_new (struct AttributeDeleteHandle);
1551 adh->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1], 1557 GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1],
1552 data_len); 1558 data_len,
1559 &adh->claim);
1553 adh->attest = NULL; 1560 adh->attest = NULL;
1554 1561
1555 adh->r_id = ntohl (dam->id); 1562 adh->r_id = ntohl (dam->id);
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index 7e6b07514..af01d8ec7 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -694,8 +694,9 @@ rvk_move_attr_cb (void *cls,
694 { 694 {
695 /** find a new place for this attribute **/ 695 /** find a new place for this attribute **/
696 struct GNUNET_RECLAIM_Attribute *claim; 696 struct GNUNET_RECLAIM_Attribute *claim;
697 claim = GNUNET_RECLAIM_attribute_deserialize (rd[i].data, 697 GNUNET_RECLAIM_attribute_deserialize (rd[i].data,
698 rd[i].data_size); 698 rd[i].data_size,
699 &claim);
699 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
700 "Attribute to update: Name=%s\n", 701 "Attribute to update: Name=%s\n",
701 claim->name); 702 claim->name);
@@ -1029,8 +1030,8 @@ process_parallel_lookup_result (void *cls,
1029 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) 1030 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type)
1030 { 1031 {
1031 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); 1032 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1032 attr_le->attribute = 1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size); 1034 &attr_le->attribute);
1034 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, 1035 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1035 cth->attrs->list_tail, 1036 cth->attrs->list_tail,
1036 attr_le); 1037 attr_le);
@@ -1298,6 +1299,9 @@ issue_ticket (struct TicketIssueHandle *ih)
1298 i = 0; 1299 i = 0;
1299 for (le = ih->attrs->list_head; NULL != le; le = le->next) 1300 for (le = ih->attrs->list_head; NULL != le; le = le->next)
1300 { 1301 {
1302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1303 "Adding list entry: %s\n", le->attribute->name);
1304
1301 attrs_record[i].data = &le->attribute->id; 1305 attrs_record[i].data = &le->attribute->id;
1302 attrs_record[i].data_size = sizeof(le->attribute->id); 1306 attrs_record[i].data_size = sizeof(le->attribute->id);
1303 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; 1307 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 06e1b0061..3221c1cce 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -1041,10 +1041,15 @@ oidc_attest_collect_finished_cb (void *cls)
1041{ 1041{
1042 struct RequestHandle *handle = cls; 1042 struct RequestHandle *handle = cls;
1043 struct GNUNET_RECLAIM_AttributeList *merged_list; 1043 struct GNUNET_RECLAIM_AttributeList *merged_list;
1044 struct GNUNET_RECLAIM_AttributeListEntry *le_m;
1044 1045
1045 handle->attest_it = NULL; 1046 handle->attest_it = NULL;
1046 merged_list = attribute_list_merge (handle->attr_idtoken_list, 1047 merged_list = attribute_list_merge (handle->attr_idtoken_list,
1047 handle->attr_userinfo_list); 1048 handle->attr_userinfo_list);
1049 for (le_m = merged_list->list_head; NULL != le_m; le_m = le_m->next)
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051 "List Attibute in ticket to issue: %s\n",
1052 le_m->attribute->name);
1048 handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp, 1053 handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp,
1049 &handle->priv_key, 1054 &handle->priv_key,
1050 &handle->oidc->client_pkey, 1055 &handle->oidc->client_pkey,
@@ -2131,13 +2136,12 @@ consume_ticket (void *cls,
2131 char *result_str; 2136 char *result_str;
2132 handle->idp_op = NULL; 2137 handle->idp_op = NULL;
2133 2138
2134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attr: %s\n", attr->name);
2135 if (NULL == identity) 2139 if (NULL == identity)
2136 { 2140 {
2137 result_str = OIDC_generate_userinfo (&handle->ticket.identity, 2141 result_str = OIDC_generate_userinfo (&handle->ticket.identity,
2138 handle->attr_userinfo_list, 2142 handle->attr_userinfo_list,
2139 handle->attests_list); 2143 handle->attests_list);
2140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Userinfo: %s\n", result_str); 2144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Userinfo: %s\n", result_str);
2141 resp = GNUNET_REST_create_response (result_str); 2145 resp = GNUNET_REST_create_response (result_str);
2142 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 2146 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
2143 GNUNET_free (result_str); 2147 GNUNET_free (result_str);
@@ -2156,6 +2160,8 @@ consume_ticket (void *cls,
2156 GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head, 2160 GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head,
2157 handle->attr_userinfo_list->list_tail, 2161 handle->attr_userinfo_list->list_tail,
2158 ale); 2162 ale);
2163 if (NULL == attest)
2164 return;
2159 for (atle = handle->attests_list->list_head; NULL != atle; atle = atle->next) 2165 for (atle = handle->attests_list->list_head; NULL != atle; atle = atle->next)
2160 { 2166 {
2161 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->attestation->id, 2167 if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->attestation->id,
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index d73241a6f..b432b4f2a 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -747,7 +747,8 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
747 747
748 { 748 {
749 struct GNUNET_RECLAIM_Attribute *attr; 749 struct GNUNET_RECLAIM_Attribute *attr;
750 attr = GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len); 750 GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len,
751 &attr);
751 if (NULL != it) 752 if (NULL != it)
752 { 753 {
753 if (NULL != it->proc) 754 if (NULL != it->proc)
@@ -1573,7 +1574,7 @@ GNUNET_RECLAIM_ticket_consume (
1573 if (NULL != h->mq) 1574 if (NULL != h->mq)
1574 GNUNET_MQ_send_copy (h->mq, op->env); 1575 GNUNET_MQ_send_copy (h->mq, op->env);
1575 else 1576 else
1576 reconnect(h); 1577 reconnect (h);
1577 return op; 1578 return op;
1578} 1579}
1579 1580
diff --git a/src/reclaim/reclaim_attribute.c b/src/reclaim/reclaim_attribute.c
index 05bdc1ac6..971bfce23 100644
--- a/src/reclaim/reclaim_attribute.c
+++ b/src/reclaim/reclaim_attribute.c
@@ -306,7 +306,6 @@ GNUNET_RECLAIM_attribute_list_serialize_get_size (
306 { 306 {
307 GNUNET_assert (NULL != ale->attribute); 307 GNUNET_assert (NULL != ale->attribute);
308 len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); 308 len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
309 len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry);
310 } 309 }
311 return len; 310 return len;
312} 311}
@@ -355,27 +354,28 @@ GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size)
355 struct GNUNET_RECLAIM_AttributeListEntry *ale; 354 struct GNUNET_RECLAIM_AttributeListEntry *ale;
356 size_t attr_len; 355 size_t attr_len;
357 const char *read_ptr; 356 const char *read_ptr;
357 size_t left = data_size;
358 358
359 al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 359 al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
360 if (data_size < sizeof(struct Attribute) + sizeof(struct 360 if (data_size < sizeof(struct Attribute))
361 GNUNET_RECLAIM_AttributeListEntry))
362 return al; 361 return al;
363 read_ptr = data; 362 read_ptr = data;
364 while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) 363 while (left >= sizeof(struct Attribute))
365 { 364 {
366 ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); 365 ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
367 ale->attribute = 366 attr_len =
368 GNUNET_RECLAIM_attribute_deserialize (read_ptr, 367 GNUNET_RECLAIM_attribute_deserialize (read_ptr,
369 data_size - (read_ptr - data)); 368 left,
370 if (NULL == ale->attribute) 369 &ale->attribute);
370 if (-1 == attr_len)
371 { 371 {
372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 372 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
373 "Failed to deserialize malformed attribute.\n"); 373 "Failed to deserialize malformed attribute.\n");
374 GNUNET_free (ale); 374 GNUNET_free (ale);
375 return al; 375 return al;
376 } 376 }
377 left -= attr_len;
377 GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); 378 GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale);
378 attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
379 read_ptr += attr_len; 379 read_ptr += attr_len;
380 } 380 }
381 return al; 381 return al;
@@ -503,17 +503,18 @@ GNUNET_RECLAIM_attribute_serialize (
503 * 503 *
504 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller 504 * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
505 */ 505 */
506struct GNUNET_RECLAIM_Attribute * 506ssize_t
507GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) 507GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size,
508 struct GNUNET_RECLAIM_Attribute **attr)
508{ 509{
509 struct GNUNET_RECLAIM_Attribute *attr;
510 struct Attribute *attr_ser; 510 struct Attribute *attr_ser;
511 struct GNUNET_RECLAIM_Attribute *attribute;
511 size_t data_len; 512 size_t data_len;
512 size_t name_len; 513 size_t name_len;
513 char *write_ptr; 514 char *write_ptr;
514 515
515 if (data_size < sizeof(struct Attribute)) 516 if (data_size < sizeof(struct Attribute))
516 return NULL; 517 return -1;
517 518
518 attr_ser = (struct Attribute *) data; 519 attr_ser = (struct Attribute *) data;
519 data_len = ntohs (attr_ser->data_size); 520 data_len = ntohs (attr_ser->data_size);
@@ -522,25 +523,27 @@ GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size)
522 { 523 {
523 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 524 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
524 "Buffer too small to deserialize\n"); 525 "Buffer too small to deserialize\n");
525 return NULL; 526 return -1;
526 } 527 }
527 attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) 528 attribute = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute)
528 + data_len + name_len + 1); 529 + data_len + name_len + 1);
529 attr->type = ntohs (attr_ser->attribute_type); 530 attribute->type = ntohs (attr_ser->attribute_type);
530 attr->flag = ntohl (attr_ser->attribute_flag); 531 attribute->flag = ntohl (attr_ser->attribute_flag);
531 attr->id = attr_ser->attribute_id; 532 attribute->id = attr_ser->attribute_id;
532 attr->attestation = attr_ser->attestation_id; 533 attribute->attestation = attr_ser->attestation_id;
533 attr->data_size = data_len; 534 attribute->data_size = data_len;
534 535
535 write_ptr = (char *) &attr[1]; 536 write_ptr = (char *) &attribute[1];
536 GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); 537 GNUNET_memcpy (write_ptr, &attr_ser[1], name_len);
537 write_ptr[name_len] = '\0'; 538 write_ptr[name_len] = '\0';
538 attr->name = write_ptr; 539 attribute->name = write_ptr;
539 540
540 write_ptr += name_len + 1; 541 write_ptr += name_len + 1;
541 GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); 542 GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len,
542 attr->data = write_ptr; 543 attribute->data_size);
543 return attr; 544 *attr = attribute;
545 attribute->data = write_ptr;
546 return sizeof(struct Attribute) + data_len + name_len;
544} 547}
545 548
546 549
diff --git a/src/reclaim/reclaim_attribute.h b/src/reclaim/reclaim_attribute.h
index e54b210b9..203c88a34 100644
--- a/src/reclaim/reclaim_attribute.h
+++ b/src/reclaim/reclaim_attribute.h
@@ -28,6 +28,8 @@
28 28
29#include "gnunet_reclaim_service.h" 29#include "gnunet_reclaim_service.h"
30 30
31GNUNET_NETWORK_STRUCT_BEGIN
32
31/** 33/**
32 * Serialized claim 34 * Serialized claim
33 */ 35 */
@@ -36,12 +38,12 @@ struct Attribute
36 /** 38 /**
37 * Attribute type 39 * Attribute type
38 */ 40 */
39 uint32_t attribute_type; 41 uint32_t attribute_type GNUNET_PACKED;
40 42
41 /** 43 /**
42 * Attribute flag 44 * Attribute flag
43 */ 45 */
44 uint32_t attribute_flag; 46 uint32_t attribute_flag GNUNET_PACKED;
45 47
46 /** 48 /**
47 * Attribute ID 49 * Attribute ID
@@ -56,12 +58,12 @@ struct Attribute
56 /** 58 /**
57 * Name length 59 * Name length
58 */ 60 */
59 uint32_t name_len; 61 uint32_t name_len GNUNET_PACKED;
60 62
61 /** 63 /**
62 * Data size 64 * Data size
63 */ 65 */
64 uint32_t data_size; 66 uint32_t data_size GNUNET_PACKED;
65 67
66 // followed by data_size Attribute value data 68 // followed by data_size Attribute value data
67}; 69};
@@ -74,12 +76,12 @@ struct Attestation
74 /** 76 /**
75 * Attestation type 77 * Attestation type
76 */ 78 */
77 uint32_t attestation_type; 79 uint32_t attestation_type GNUNET_PACKED;
78 80
79 /** 81 /**
80 * Attestation flag 82 * Attestation flag
81 */ 83 */
82 uint32_t attestation_flag; 84 uint32_t attestation_flag GNUNET_PACKED;
83 85
84 /** 86 /**
85 * Attestation ID 87 * Attestation ID
@@ -89,14 +91,16 @@ struct Attestation
89 /** 91 /**
90 * Name length 92 * Name length
91 */ 93 */
92 uint32_t name_len; 94 uint32_t name_len GNUNET_PACKED;
93 95
94 /** 96 /**
95 * Data size 97 * Data size
96 */ 98 */
97 uint32_t data_size; 99 uint32_t data_size GNUNET_PACKED;
98 100
99 // followed by data_size Attestation value data 101 // followed by data_size Attestation value data
100}; 102};
101 103
104GNUNET_NETWORK_STRUCT_BEGIN
105
102#endif 106#endif
diff --git a/src/reclaim/test_reclaim_attribute.c b/src/reclaim/test_reclaim_attribute.c
new file mode 100644
index 000000000..f71d86b56
--- /dev/null
+++ b/src/reclaim/test_reclaim_attribute.c
@@ -0,0 +1,51 @@
1#include "platform.h"
2#include "gnunet_common.h"
3#include "gnunet_reclaim_lib.h"
4#include "gnunet_container_lib.h"
5
6int
7main (int argc, char *argv[])
8{
9 struct GNUNET_RECLAIM_AttributeList *al;
10 struct GNUNET_RECLAIM_AttributeList *al_two;
11 struct GNUNET_RECLAIM_AttributeListEntry *ale;
12 struct GNUNET_RECLAIM_Attribute *attr;
13 char attrname[100];
14 char attrdata[100];
15 size_t ser_len_claimed;
16 size_t ser_len_actual;
17 ssize_t deser_len;
18 char *ser_data;
19 int count = 0;
20
21 al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
22 for (int i = 0; i < 12; i++)
23 {
24 memset (attrname, 0, 100);
25 memset (attrdata, 0, 100);
26 sprintf (attrname, "attr%d", i);
27 sprintf (attrdata, "%d", i);
28 ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
29 ale->attribute = GNUNET_RECLAIM_attribute_new (attrname,
30 &GNUNET_RECLAIM_ID_ZERO,
31 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
32 attrdata,
33 strlen (attrdata));
34 GNUNET_CONTAINER_DLL_insert (al->list_head,
35 al->list_tail,
36 ale);
37 }
38 ser_len_claimed = GNUNET_RECLAIM_attribute_list_serialize_get_size (al);
39 ser_data = GNUNET_malloc (ser_len_claimed);
40 ser_len_actual = GNUNET_RECLAIM_attribute_list_serialize (al,
41 ser_data);
42 GNUNET_assert (ser_len_claimed == ser_len_actual);
43 al_two = GNUNET_RECLAIM_attribute_list_deserialize (ser_data,
44 ser_len_actual);
45 for (ale = al_two->list_head; NULL != ale; ale = ale->next)
46 count++;
47 GNUNET_assert (12 == count);
48 //GNUNET_assert (-1 != deser_len);
49 GNUNET_free (ser_data);
50 GNUNET_RECLAIM_attribute_list_destroy (al);
51}