aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 16:40:11 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 16:40:11 +0200
commit79f1546aa9ad2eeead24324000130caeb26b0262 (patch)
tree5e32cdd17b0ca6067c0d73ece7dbc9989e370811
parent1eea290a7aaa845db727773bc7e9f2a0fdc5bebd (diff)
downloadgnunet-79f1546aa9ad2eeead24324000130caeb26b0262.tar.gz
gnunet-79f1546aa9ad2eeead24324000130caeb26b0262.zip
RECLAIM/REST: add attribute delete REST call
-rw-r--r--src/reclaim-attribute/reclaim_attribute.c199
-rw-r--r--src/reclaim/gnunet-service-reclaim.c4
-rw-r--r--src/reclaim/plugin_rest_reclaim.c77
3 files changed, 158 insertions, 122 deletions
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c
index 86f0f8f67..b434c386e 100644
--- a/src/reclaim-attribute/reclaim_attribute.c
+++ b/src/reclaim-attribute/reclaim_attribute.c
@@ -24,10 +24,11 @@
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
28#include "reclaim_attribute.h"
29#include "gnunet_reclaim_attribute_plugin.h"
30 29
30#include "gnunet_reclaim_attribute_plugin.h"
31#include "reclaim_attribute.h"
31/** 32/**
32 * Handle for a plugin 33 * Handle for a plugin
33 */ 34 */
@@ -63,15 +64,12 @@ static int initialized;
63 * Add a plugin 64 * Add a plugin
64 */ 65 */
65static void 66static void
66add_plugin (void* cls, 67add_plugin (void *cls, const char *library_name, void *lib_ret)
67 const char *library_name,
68 void *lib_ret)
69{ 68{
70 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; 69 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret;
71 struct Plugin *plugin; 70 struct Plugin *plugin;
72 71
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 72 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading attribute plugin `%s'\n",
74 "Loading attribute plugin `%s'\n",
75 library_name); 73 library_name);
76 plugin = GNUNET_new (struct Plugin); 74 plugin = GNUNET_new (struct Plugin);
77 plugin->api = api; 75 plugin->api = api;
@@ -83,7 +81,7 @@ add_plugin (void* cls,
83 * Load plugins 81 * Load plugins
84 */ 82 */
85static void 83static void
86init() 84init ()
87{ 85{
88 if (GNUNET_YES == initialized) 86 if (GNUNET_YES == initialized)
89 return; 87 return;
@@ -106,11 +104,10 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename)
106 uint32_t ret; 104 uint32_t ret;
107 105
108 init (); 106 init ();
109 for (i = 0; i < num_plugins; i++) 107 for (i = 0; i < num_plugins; i++) {
110 {
111 plugin = attr_plugins[i]; 108 plugin = attr_plugins[i];
112 if (UINT32_MAX != (ret = plugin->api->typename_to_number (plugin->api->cls, 109 if (UINT32_MAX !=
113 typename))) 110 (ret = plugin->api->typename_to_number (plugin->api->cls, typename)))
114 return ret; 111 return ret;
115 } 112 }
116 return UINT32_MAX; 113 return UINT32_MAX;
@@ -122,7 +119,7 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename)
122 * @param type number of a type 119 * @param type number of a type
123 * @return corresponding typestring, NULL on error 120 * @return corresponding typestring, NULL on error
124 */ 121 */
125const char* 122const char *
126GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) 123GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type)
127{ 124{
128 unsigned int i; 125 unsigned int i;
@@ -130,11 +127,10 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type)
130 const char *ret; 127 const char *ret;
131 128
132 init (); 129 init ();
133 for (i = 0; i < num_plugins; i++) 130 for (i = 0; i < num_plugins; i++) {
134 {
135 plugin = attr_plugins[i]; 131 plugin = attr_plugins[i];
136 if (NULL != (ret = plugin->api->number_to_typename (plugin->api->cls, 132 if (NULL !=
137 type))) 133 (ret = plugin->api->number_to_typename (plugin->api->cls, type)))
138 return ret; 134 return ret;
139 } 135 }
140 return NULL; 136 return NULL;
@@ -151,23 +147,17 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type)
151 * @return #GNUNET_OK on success 147 * @return #GNUNET_OK on success
152 */ 148 */
153int 149int
154GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, 150GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, const char *s,
155 const char *s, 151 void **data, size_t *data_size)
156 void **data,
157 size_t *data_size)
158{ 152{
159 unsigned int i; 153 unsigned int i;
160 struct Plugin *plugin; 154 struct Plugin *plugin;
161 155
162 init (); 156 init ();
163 for (i = 0; i < num_plugins; i++) 157 for (i = 0; i < num_plugins; i++) {
164 {
165 plugin = attr_plugins[i]; 158 plugin = attr_plugins[i];
166 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, 159 if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, type, s,
167 type, 160 data, data_size))
168 s,
169 data,
170 data_size))
171 return GNUNET_OK; 161 return GNUNET_OK;
172 } 162 }
173 return GNUNET_SYSERR; 163 return GNUNET_SYSERR;
@@ -182,22 +172,18 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type,
182 * @return NULL on error, otherwise human-readable representation of the claim 172 * @return NULL on error, otherwise human-readable representation of the claim
183 */ 173 */
184char * 174char *
185GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, 175GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, const void *data,
186 const void* data,
187 size_t data_size) 176 size_t data_size)
188{ 177{
189 unsigned int i; 178 unsigned int i;
190 struct Plugin *plugin; 179 struct Plugin *plugin;
191 char *ret; 180 char *ret;
192 181
193 init(); 182 init ();
194 for (i = 0; i < num_plugins; i++) 183 for (i = 0; i < num_plugins; i++) {
195 {
196 plugin = attr_plugins[i]; 184 plugin = attr_plugins[i];
197 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, 185 if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, type,
198 type, 186 data, data_size)))
199 data,
200 data_size)))
201 return ret; 187 return ret;
202 } 188 }
203 return NULL; 189 return NULL;
@@ -213,10 +199,8 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type,
213 * @return the new attribute 199 * @return the new attribute
214 */ 200 */
215struct GNUNET_RECLAIM_ATTRIBUTE_Claim * 201struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
216GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name, 202GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, uint32_t type,
217 uint32_t type, 203 const void *data, size_t data_size)
218 const void* data,
219 size_t data_size)
220{ 204{
221 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; 205 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
222 char *write_ptr; 206 char *write_ptr;
@@ -225,20 +209,15 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
225 GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); 209 GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp);
226 210
227 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + 211 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) +
228 strlen (attr_name_tmp) + 1 + 212 strlen (attr_name_tmp) + 1 + data_size);
229 data_size);
230 attr->type = type; 213 attr->type = type;
231 attr->data_size = data_size; 214 attr->data_size = data_size;
232 attr->version = 0; 215 attr->version = 0;
233 write_ptr = (char*)&attr[1]; 216 write_ptr = (char *)&attr[1];
234 GNUNET_memcpy (write_ptr, 217 GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1);
235 attr_name_tmp,
236 strlen (attr_name_tmp) + 1);
237 attr->name = write_ptr; 218 attr->name = write_ptr;
238 write_ptr += strlen (attr->name) + 1; 219 write_ptr += strlen (attr->name) + 1;
239 GNUNET_memcpy (write_ptr, 220 GNUNET_memcpy (write_ptr, data, data_size);
240 data,
241 data_size);
242 attr->data = write_ptr; 221 attr->data = write_ptr;
243 GNUNET_free (attr_name_tmp); 222 GNUNET_free (attr_name_tmp);
244 return attr; 223 return attr;
@@ -255,25 +234,21 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char* attr_name,
255 * @return 234 * @return
256 */ 235 */
257void 236void
258GNUNET_RECLAIM_ATTRIBUTE_list_add (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, 237GNUNET_RECLAIM_ATTRIBUTE_list_add (
259 const char* attr_name, 238 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list,
260 uint32_t type, 239 const char *attr_name, uint32_t type, const void *data, size_t data_size)
261 const void* data,
262 size_t data_size)
263{ 240{
264 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 241 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
265 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 242 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
266 le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, 243 le->claim =
267 type, 244 GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size);
268 data, 245 GNUNET_CONTAINER_DLL_insert (claim_list->list_head, claim_list->list_tail,
269 data_size);
270 GNUNET_CONTAINER_DLL_insert (claim_list->list_head,
271 claim_list->list_tail,
272 le); 246 le);
273} 247}
274 248
275size_t 249size_t
276GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) 250GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (
251 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
277{ 252{
278 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 253 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
279 size_t len = 0; 254 size_t len = 0;
@@ -283,20 +258,18 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (const struct GNUNET_RECLAIM_AT
283} 258}
284 259
285size_t 260size_t
286GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, 261GNUNET_RECLAIM_ATTRIBUTE_list_serialize (
287 char *result) 262 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, char *result)
288{ 263{
289 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 264 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
290 size_t len; 265 size_t len;
291 size_t total_len; 266 size_t total_len;
292 char* write_ptr; 267 char *write_ptr;
293 268
294 write_ptr = result; 269 write_ptr = result;
295 total_len = 0; 270 total_len = 0;
296 for (le = attrs->list_head; NULL != le; le = le->next) 271 for (le = attrs->list_head; NULL != le; le = le->next) {
297 { 272 len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr);
298 len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim,
299 write_ptr);
300 total_len += len; 273 total_len += len;
301 write_ptr += len; 274 write_ptr += len;
302 } 275 }
@@ -304,55 +277,49 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_C
304} 277}
305 278
306struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * 279struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
307GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char* data, 280GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size)
308 size_t data_size)
309{ 281{
310 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; 282 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
311 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 283 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
312 size_t attr_len; 284 size_t attr_len;
313 const char* read_ptr; 285 const char *read_ptr;
314 286
315 if (data_size < sizeof (struct Attribute)) 287 if (data_size < sizeof (struct Attribute))
316 return NULL; 288 return NULL;
317 289
318 attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); 290 attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
319 read_ptr = data; 291 read_ptr = data;
320 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) 292 while (((data + data_size) - read_ptr) >= sizeof (struct Attribute)) {
321 {
322 293
323 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 294 le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
324 le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, 295 le->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (
325 data_size - (read_ptr - data)); 296 read_ptr, data_size - (read_ptr - data));
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deserialized attribute %s\n",
327 "Deserialized attribute %s\n", le->claim->name); 298 le->claim->name);
328 GNUNET_CONTAINER_DLL_insert (attrs->list_head, 299 GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le);
329 attrs->list_tail,
330 le);
331 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); 300 attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim);
332 read_ptr += attr_len; 301 read_ptr += attr_len;
333 } 302 }
334 return attrs; 303 return attrs;
335} 304}
336 305
337struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList* 306struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *
338GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) 307GNUNET_RECLAIM_ATTRIBUTE_list_dup (
308 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
339{ 309{
340 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 310 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
341 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; 311 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le;
342 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; 312 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result;
343 313
344 result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); 314 result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList);
345 for (le = attrs->list_head; NULL != le; le = le->next) 315 for (le = attrs->list_head; NULL != le; le = le->next) {
346 {
347 result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); 316 result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry);
348 result_le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, 317 result_le->claim = GNUNET_RECLAIM_ATTRIBUTE_claim_new (
349 le->claim->type, 318 le->claim->name, le->claim->type, le->claim->data,
350 le->claim->data, 319 le->claim->data_size);
351 le->claim->data_size);
352 result_le->claim->version = le->claim->version; 320 result_le->claim->version = le->claim->version;
353 result_le->claim->id = le->claim->id; 321 result_le->claim->id = le->claim->id;
354 GNUNET_CONTAINER_DLL_insert (result->list_head, 322 GNUNET_CONTAINER_DLL_insert (result->list_head, result->list_tail,
355 result->list_tail,
356 result_le); 323 result_le);
357 } 324 }
358 return result; 325 return result;
@@ -360,50 +327,48 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup (const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimLi
360 327
361 328
362void 329void
363GNUNET_RECLAIM_ATTRIBUTE_list_destroy (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) 330GNUNET_RECLAIM_ATTRIBUTE_list_destroy (
331 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs)
364{ 332{
365 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; 333 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
366 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; 334 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le;
367 335
368 for (le = attrs->list_head; NULL != le;) 336 for (le = attrs->list_head; NULL != le;) {
369 {
370 GNUNET_free (le->claim); 337 GNUNET_free (le->claim);
371 tmp_le = le; 338 tmp_le = le;
372 le = le->next; 339 le = le->next;
373 GNUNET_free (tmp_le); 340 GNUNET_free (tmp_le);
374 } 341 }
375 GNUNET_free (attrs); 342 GNUNET_free (attrs);
376
377} 343}
378 344
379size_t 345size_t
380GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 346GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (
347 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
381{ 348{
382 return sizeof (struct Attribute) 349 return sizeof (struct Attribute) + strlen (attr->name) + attr->data_size;
383 + strlen (attr->name)
384 + attr->data_size;
385} 350}
386 351
387size_t 352size_t
388GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, 353GNUNET_RECLAIM_ATTRIBUTE_serialize (
389 char *result) 354 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, char *result)
390{ 355{
391 size_t data_len_ser; 356 size_t data_len_ser;
392 size_t name_len; 357 size_t name_len;
393 struct Attribute *attr_ser; 358 struct Attribute *attr_ser;
394 char* write_ptr; 359 char *write_ptr;
395 360
396 attr_ser = (struct Attribute*)result; 361 attr_ser = (struct Attribute *)result;
397 attr_ser->attribute_type = htons (attr->type); 362 attr_ser->attribute_type = htons (attr->type);
398 attr_ser->attribute_version = htonl (attr->version); 363 attr_ser->attribute_version = htonl (attr->version);
399 attr_ser->attribute_id = GNUNET_htonll (attr->id); 364 attr_ser->attribute_id = GNUNET_htonll (attr->id);
400 name_len = strlen (attr->name); 365 name_len = strlen (attr->name);
401 attr_ser->name_len = htons (name_len); 366 attr_ser->name_len = htons (name_len);
402 write_ptr = (char*)&attr_ser[1]; 367 write_ptr = (char *)&attr_ser[1];
403 GNUNET_memcpy (write_ptr, attr->name, name_len); 368 GNUNET_memcpy (write_ptr, attr->name, name_len);
404 write_ptr += name_len; 369 write_ptr += name_len;
405 //TODO plugin-ize 370 // TODO plugin-ize
406 //data_len_ser = plugin->serialize_attribute_value (attr, 371 // data_len_ser = plugin->serialize_attribute_value (attr,
407 // &attr_ser[1]); 372 // &attr_ser[1]);
408 data_len_ser = attr->data_size; 373 data_len_ser = attr->data_size;
409 GNUNET_memcpy (write_ptr, attr->data, attr->data_size); 374 GNUNET_memcpy (write_ptr, attr->data, attr->data_size);
@@ -413,42 +378,36 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize (const struct GNUNET_RECLAIM_ATTRIBUTE_Claim
413} 378}
414 379
415struct GNUNET_RECLAIM_ATTRIBUTE_Claim * 380struct GNUNET_RECLAIM_ATTRIBUTE_Claim *
416GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char* data, 381GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size)
417 size_t data_size)
418{ 382{
419 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; 383 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
420 struct Attribute *attr_ser; 384 struct Attribute *attr_ser;
421 size_t data_len; 385 size_t data_len;
422 size_t name_len; 386 size_t name_len;
423 char* write_ptr; 387 char *write_ptr;
424 388
425 if (data_size < sizeof (struct Attribute)) 389 if (data_size < sizeof (struct Attribute))
426 return NULL; 390 return NULL;
427 391
428 attr_ser = (struct Attribute*)data; 392 attr_ser = (struct Attribute *)data;
429 data_len = ntohs (attr_ser->data_size); 393 data_len = ntohs (attr_ser->data_size);
430 name_len = ntohs (attr_ser->name_len); 394 name_len = ntohs (attr_ser->name_len);
431 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) 395 attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) +
432 + data_len + name_len + 1); 396 data_len + name_len + 1);
433 attr->type = ntohs (attr_ser->attribute_type); 397 attr->type = ntohs (attr_ser->attribute_type);
434 attr->version = ntohl (attr_ser->attribute_version); 398 attr->version = ntohl (attr_ser->attribute_version);
435 attr->id = GNUNET_ntohll (attr_ser->attribute_id); 399 attr->id = GNUNET_ntohll (attr_ser->attribute_id);
436 attr->data_size = ntohs (attr_ser->data_size); 400 attr->data_size = ntohs (attr_ser->data_size);
437 401
438 write_ptr = (char*)&attr[1]; 402 write_ptr = (char *)&attr[1];
439 GNUNET_memcpy (write_ptr, 403 GNUNET_memcpy (write_ptr, &attr_ser[1], name_len);
440 &attr_ser[1],
441 name_len);
442 write_ptr[name_len] = '\0'; 404 write_ptr[name_len] = '\0';
443 attr->name = write_ptr; 405 attr->name = write_ptr;
444 406
445 write_ptr += name_len + 1; 407 write_ptr += name_len + 1;
446 GNUNET_memcpy (write_ptr, 408 GNUNET_memcpy (write_ptr, (char *)&attr_ser[1] + name_len, attr->data_size);
447 (char*)&attr_ser[1] + name_len,
448 attr->data_size);
449 attr->data = write_ptr; 409 attr->data = write_ptr;
450 return attr; 410 return attr;
451
452} 411}
453 412
454/* end of reclaim_attribute.c */ 413/* end of reclaim_attribute.c */
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 5deb482e9..a49962b4d 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -997,8 +997,8 @@ attr_delete_cont (void *cls, int32_t success, const char *emsg)
997 struct AttributeDeleteHandle *adh = cls; 997 struct AttributeDeleteHandle *adh = cls;
998 adh->ns_qe = NULL; 998 adh->ns_qe = NULL;
999 if (GNUNET_SYSERR == success) { 999 if (GNUNET_SYSERR == success) {
1000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s (%s)\n", 1000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s\n",
1001 adh->claim->name, adh->label); 1001 adh->label);
1002 send_delete_response (adh, GNUNET_SYSERR); 1002 send_delete_response (adh, GNUNET_SYSERR);
1003 cleanup_adh (adh); 1003 cleanup_adh (adh);
1004 return; 1004 return;
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index ae46211d5..74071d97b 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -634,6 +634,81 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
634 634
635 635
636static void 636static void
637delete_finished_cb (void *cls, int32_t success, const char *emsg)
638{
639 struct RequestHandle *handle = cls;
640 struct MHD_Response *resp;
641
642 resp = GNUNET_REST_create_response (emsg);
643 if (GNUNET_OK != success) {
644 GNUNET_SCHEDULER_add_now (&do_error, handle);
645 return;
646 }
647 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
648 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
649}
650
651
652/**
653 * List attributes for identity request
654 *
655 * @param con_handle the connection handle
656 * @param url the url
657 * @param cls the RequestHandle
658 */
659static void
660delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
661 const char *url, void *cls)
662{
663 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
664 struct RequestHandle *handle = cls;
665 struct GNUNET_RECLAIM_ATTRIBUTE_Claim attr;
666 struct EgoEntry *ego_entry;
667 char *identity_id_str;
668 char *identity;
669 char *id;
670
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
672 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) {
673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
674 GNUNET_SCHEDULER_add_now (&do_error, handle);
675 return;
676 }
677 identity_id_str =
678 strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
679 identity = strtok (identity_id_str, "/");
680 id = strtok (NULL, "/");
681 if ((NULL == identity) || (NULL == id)) {
682 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
683 GNUNET_free (identity_id_str);
684 GNUNET_SCHEDULER_add_now (&do_error, handle);
685 return;
686 }
687
688 for (ego_entry = handle->ego_head; NULL != ego_entry;
689 ego_entry = ego_entry->next)
690 if (0 == strcmp (identity, ego_entry->identifier))
691 break;
692 handle->resp_object = json_array ();
693 if (NULL == ego_entry) {
694 // Done
695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
696 GNUNET_free (identity_id_str);
697 GNUNET_SCHEDULER_add_now (&return_response, handle);
698 return;
699 }
700 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
701 handle->idp = GNUNET_RECLAIM_connect (cfg);
702 memset (&attr, 0, sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim));
703 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t));
704 attr.name = "";
705 handle->idp_op = GNUNET_RECLAIM_attribute_delete (
706 handle->idp, priv_key, &attr, &delete_finished_cb, handle);
707 GNUNET_free (identity_id_str);
708}
709
710
711static void
637revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, 712revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
638 const char *url, void *cls) 713 const char *url, void *cls)
639{ 714{
@@ -815,6 +890,8 @@ init_cont (struct RequestHandle *handle)
815 &list_attribute_cont}, 890 &list_attribute_cont},
816 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 891 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
817 &add_attribute_cont}, 892 &add_attribute_cont},
893 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
894 &delete_attribute_cont},
818 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, 895 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS,
819 &list_tickets_cont}, 896 &list_tickets_cont},
820 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, 897 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE,