aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim-attribute/reclaim_attribute.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-11 20:25:11 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 10:01:23 +0200
commit94f8e5437da8cc1c5ee38a333da2e1c68b3289f1 (patch)
tree8f56950954baccbc7e1867f9ac01144b419a4798 /src/reclaim-attribute/reclaim_attribute.c
parent61625d4834bc7a599446486c9d16f2451527f989 (diff)
downloadgnunet-94f8e5437da8cc1c5ee38a333da2e1c68b3289f1.tar.gz
gnunet-94f8e5437da8cc1c5ee38a333da2e1c68b3289f1.zip
RECLAIM: Start move to GNS encryption
Diffstat (limited to 'src/reclaim-attribute/reclaim_attribute.c')
-rw-r--r--src/reclaim-attribute/reclaim_attribute.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c
index a5520cbcf..3d260f15b 100644
--- a/src/reclaim-attribute/reclaim_attribute.c
+++ b/src/reclaim-attribute/reclaim_attribute.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -104,7 +104,7 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename)
104 unsigned int i; 104 unsigned int i;
105 struct Plugin *plugin; 105 struct Plugin *plugin;
106 uint32_t ret; 106 uint32_t ret;
107 107
108 init (); 108 init ();
109 for (i = 0; i < num_plugins; i++) 109 for (i = 0; i < num_plugins; i++)
110 { 110 {
@@ -152,9 +152,9 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type)
152 */ 152 */
153int 153int
154GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, 154GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
155 const char *s, 155 const char *s,
156 void **data, 156 void **data,
157 size_t *data_size) 157 size_t *data_size)
158{ 158{
159 unsigned int i; 159 unsigned int i;
160 struct Plugin *plugin; 160 struct Plugin *plugin;
@@ -183,8 +183,8 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
183 */ 183 */
184char * 184char *
185GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, 185GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
186 const void* data, 186 const void* data,
187 size_t data_size) 187 size_t data_size)
188{ 188{
189 unsigned int i; 189 unsigned int i;
190 struct Plugin *plugin; 190 struct Plugin *plugin;
@@ -214,9 +214,9 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
214 */ 214 */
215struct GNUNET_RECLAIM_ATTRIBUTE_Claim * 215struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
216GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name, 216GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
217 uint32_t type, 217 uint32_t type,
218 const void* data, 218 const void* data,
219 size_t data_size) 219 size_t data_size)
220{ 220{
221 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; 221 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
222 char *write_ptr; 222 char *write_ptr;
@@ -256,20 +256,20 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
256 */ 256 */
257void 257void
258GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, 258GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list,
259 const char* attr_name, 259 const char* attr_name,
260 uint32_t type, 260 uint32_t type,
261 const void* data, 261 const void* data,
262 size_t data_size) 262 size_t data_size)
263{ 263{
264 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 264 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
265 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 265 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
266 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, 266 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name,
267 type, 267 type,
268 data, 268 data,
269 data_size); 269 data_size);
270 GNUNET_CONTAINER_DLL_insert (claim_list->list_head, 270 GNUNET_CONTAINER_DLL_insert (claim_list->list_head,
271 claim_list->list_tail, 271 claim_list->list_tail,
272 le); 272 le);
273} 273}
274 274
275size_t 275size_t
@@ -279,12 +279,12 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_AT
279 size_t len = 0; 279 size_t len = 0;
280 for (le = attrs->list_head; NULL != le; le = le->next) 280 for (le = attrs->list_head; NULL != le; le = le->next)
281 len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); 281 len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim);
282 return len; 282 return len;
283} 283}
284 284
285size_t 285size_t
286GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, 286GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
287 char *result) 287 char *result)
288{ 288{
289 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 289 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
290 size_t len; 290 size_t len;
@@ -296,7 +296,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_C
296 for (le = attrs->list_head; NULL != le; le = le->next) 296 for (le = attrs->list_head; NULL != le; le = le->next)
297 { 297 {
298 len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, 298 len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim,
299 write_ptr); 299 write_ptr);
300 total_len += len; 300 total_len += len;
301 write_ptr += len; 301 write_ptr += len;
302 } 302 }
@@ -305,7 +305,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_C
305 305
306struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * 306struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
307GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data, 307GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
308 size_t data_size) 308 size_t data_size)
309{ 309{
310 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; 310 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
311 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 311 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
@@ -314,7 +314,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
314 314
315 if (data_size < sizeof (struct Attribute)) 315 if (data_size < sizeof (struct Attribute))
316 return NULL; 316 return NULL;
317 317
318 attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); 318 attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
319 read_ptr = data; 319 read_ptr = data;
320 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) 320 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute))
@@ -322,7 +322,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data,
322 322
323 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 323 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
324 le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, 324 le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr,
325 data_size - (read_ptr - data)); 325 data_size - (read_ptr - data));
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Deserialized attribute %s\n", le->claim->name); 327 "Deserialized attribute %s\n", le->claim->name);
328 GNUNET_CONTAINER_DLL_insert (attrs->list_head, 328 GNUNET_CONTAINER_DLL_insert (attrs->list_head,
@@ -346,9 +346,9 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimLi
346 { 346 {
347 result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 347 result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
348 result_le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, 348 result_le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name,
349 le->claim->type, 349 le->claim->type,
350 le->claim->data, 350 le->claim->data,
351 le->claim->data_size); 351 le->claim->data_size);
352 GNUNET_CONTAINER_DLL_insert (result->list_head, 352 GNUNET_CONTAINER_DLL_insert (result->list_head,
353 result->list_tail, 353 result->list_tail,
354 result_le); 354 result_le);
@@ -377,14 +377,14 @@ GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList
377size_t 377size_t
378GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 378GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
379{ 379{
380 return sizeof (struct Attribute) 380 return sizeof (struct Attribute)
381 + strlen (attr->name) 381 + strlen (attr->name)
382 + attr->data_size; 382 + attr->data_size;
383} 383}
384 384
385size_t 385size_t
386GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, 386GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr,
387 char *result) 387 char *result)
388{ 388{
389 size_t data_len_ser; 389 size_t data_len_ser;
390 size_t name_len; 390 size_t name_len;
@@ -394,6 +394,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim
394 attr_ser = (struct Attribute*)result; 394 attr_ser = (struct Attribute*)result;
395 attr_ser->attribute_type = htons (attr->type); 395 attr_ser->attribute_type = htons (attr->type);
396 attr_ser->attribute_version = htonl (attr->version); 396 attr_ser->attribute_version = htonl (attr->version);
397 attr_ser->attribute_id = GNUNET_htonll (attr->id);
397 name_len = strlen (attr->name); 398 name_len = strlen (attr->name);
398 attr_ser->name_len = htons (name_len); 399 attr_ser->name_len = htons (name_len);
399 write_ptr = (char*)&attr_ser[1]; 400 write_ptr = (char*)&attr_ser[1];
@@ -411,7 +412,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim
411 412
412struct GNUNET_RECLAIM_ATTRIBUTE_Claim * 413struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
413GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data, 414GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
414 size_t data_size) 415 size_t data_size)
415{ 416{
416 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; 417 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
417 struct Attribute *attr_ser; 418 struct Attribute *attr_ser;
@@ -429,6 +430,7 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data,
429 + data_len + name_len + 1); 430 + data_len + name_len + 1);
430 attr->type = ntohs (attr_ser->attribute_type); 431 attr->type = ntohs (attr_ser->attribute_type);
431 attr->version = ntohl (attr_ser->attribute_version); 432 attr->version = ntohl (attr_ser->attribute_version);
433 attr->id = GNUNET_ntohll (attr_ser->attribute_id);
432 attr->data_size = ntohs (attr_ser->data_size); 434 attr->data_size = ntohs (attr_ser->data_size);
433 435
434 write_ptr = (char*)&attr[1]; 436 write_ptr = (char*)&attr[1];