aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/plugin_rest_reclaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r--src/reclaim/plugin_rest_reclaim.c941
1 files changed, 471 insertions, 470 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 3f2577802..176f46ffc 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -16,7 +16,7 @@
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
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @author Martin Schanzenbach 21 * @author Martin Schanzenbach
22 * @author Philippe Buschmann 22 * @author Philippe Buschmann
@@ -86,16 +86,14 @@ static char *allow_methods;
86/** 86/**
87 * @brief struct returned by the initialization function of the plugin 87 * @brief struct returned by the initialization function of the plugin
88 */ 88 */
89struct Plugin 89struct Plugin {
90{
91 const struct GNUNET_CONFIGURATION_Handle *cfg; 90 const struct GNUNET_CONFIGURATION_Handle *cfg;
92}; 91};
93 92
94/** 93/**
95 * The ego list 94 * The ego list
96 */ 95 */
97struct EgoEntry 96struct EgoEntry {
98{
99 /** 97 /**
100 * DLL 98 * DLL
101 */ 99 */
@@ -123,8 +121,7 @@ struct EgoEntry
123}; 121};
124 122
125 123
126struct RequestHandle 124struct RequestHandle {
127{
128 /** 125 /**
129 * Ego list 126 * Ego list
130 */ 127 */
@@ -241,55 +238,56 @@ struct RequestHandle
241 * @param handle Handle to clean up 238 * @param handle Handle to clean up
242 */ 239 */
243static void 240static void
244cleanup_handle (struct RequestHandle *handle) 241cleanup_handle(struct RequestHandle *handle)
245{ 242{
246 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry; 243 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_entry;
247 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp; 244 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *claim_tmp;
248 struct EgoEntry *ego_entry; 245 struct EgoEntry *ego_entry;
249 struct EgoEntry *ego_tmp; 246 struct EgoEntry *ego_tmp;
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 247
248 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
251 if (NULL != handle->resp_object) 249 if (NULL != handle->resp_object)
252 json_decref (handle->resp_object); 250 json_decref(handle->resp_object);
253 if (NULL != handle->timeout_task) 251 if (NULL != handle->timeout_task)
254 GNUNET_SCHEDULER_cancel (handle->timeout_task); 252 GNUNET_SCHEDULER_cancel(handle->timeout_task);
255 if (NULL != handle->identity_handle) 253 if (NULL != handle->identity_handle)
256 GNUNET_IDENTITY_disconnect (handle->identity_handle); 254 GNUNET_IDENTITY_disconnect(handle->identity_handle);
257 if (NULL != handle->attr_it) 255 if (NULL != handle->attr_it)
258 GNUNET_RECLAIM_get_attributes_stop (handle->attr_it); 256 GNUNET_RECLAIM_get_attributes_stop(handle->attr_it);
259 if (NULL != handle->ticket_it) 257 if (NULL != handle->ticket_it)
260 GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it); 258 GNUNET_RECLAIM_ticket_iteration_stop(handle->ticket_it);
261 if (NULL != handle->idp) 259 if (NULL != handle->idp)
262 GNUNET_RECLAIM_disconnect (handle->idp); 260 GNUNET_RECLAIM_disconnect(handle->idp);
263 if (NULL != handle->url) 261 if (NULL != handle->url)
264 GNUNET_free (handle->url); 262 GNUNET_free(handle->url);
265 if (NULL != handle->emsg) 263 if (NULL != handle->emsg)
266 GNUNET_free (handle->emsg); 264 GNUNET_free(handle->emsg);
267 if (NULL != handle->attr_list) 265 if (NULL != handle->attr_list)
268 {
269 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;)
270 { 266 {
271 claim_tmp = claim_entry; 267 for (claim_entry = handle->attr_list->list_head; NULL != claim_entry;)
272 claim_entry = claim_entry->next; 268 {
273 GNUNET_free (claim_tmp->claim); 269 claim_tmp = claim_entry;
274 GNUNET_free (claim_tmp); 270 claim_entry = claim_entry->next;
271 GNUNET_free(claim_tmp->claim);
272 GNUNET_free(claim_tmp);
273 }
274 GNUNET_free(handle->attr_list);
275 } 275 }
276 GNUNET_free (handle->attr_list);
277 }
278 for (ego_entry = handle->ego_head; NULL != ego_entry;) 276 for (ego_entry = handle->ego_head; NULL != ego_entry;)
279 { 277 {
280 ego_tmp = ego_entry; 278 ego_tmp = ego_entry;
281 ego_entry = ego_entry->next; 279 ego_entry = ego_entry->next;
282 GNUNET_free (ego_tmp->identifier); 280 GNUNET_free(ego_tmp->identifier);
283 GNUNET_free (ego_tmp->keystring); 281 GNUNET_free(ego_tmp->keystring);
284 GNUNET_free (ego_tmp); 282 GNUNET_free(ego_tmp);
285 } 283 }
286 GNUNET_free (handle); 284 GNUNET_free(handle);
287} 285}
288 286
289static void 287static void
290cleanup_handle_delayed (void *cls) 288cleanup_handle_delayed(void *cls)
291{ 289{
292 cleanup_handle (cls); 290 cleanup_handle(cls);
293} 291}
294 292
295 293
@@ -299,22 +297,22 @@ cleanup_handle_delayed (void *cls)
299 * @param cls the `struct RequestHandle` 297 * @param cls the `struct RequestHandle`
300 */ 298 */
301static void 299static void
302do_error (void *cls) 300do_error(void *cls)
303{ 301{
304 struct RequestHandle *handle = cls; 302 struct RequestHandle *handle = cls;
305 struct MHD_Response *resp; 303 struct MHD_Response *resp;
306 char *json_error; 304 char *json_error;
307 305
308 GNUNET_asprintf (&json_error, "{ \"error\" : \"%s\" }", handle->emsg); 306 GNUNET_asprintf(&json_error, "{ \"error\" : \"%s\" }", handle->emsg);
309 if (0 == handle->response_code) 307 if (0 == handle->response_code)
310 { 308 {
311 handle->response_code = MHD_HTTP_BAD_REQUEST; 309 handle->response_code = MHD_HTTP_BAD_REQUEST;
312 } 310 }
313 resp = GNUNET_REST_create_response (json_error); 311 resp = GNUNET_REST_create_response(json_error);
314 MHD_add_response_header (resp, "Content-Type", "application/json"); 312 MHD_add_response_header(resp, "Content-Type", "application/json");
315 handle->proc (handle->proc_cls, resp, handle->response_code); 313 handle->proc(handle->proc_cls, resp, handle->response_code);
316 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 314 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
317 GNUNET_free (json_error); 315 GNUNET_free(json_error);
318} 316}
319 317
320 318
@@ -324,37 +322,37 @@ do_error (void *cls)
324 * @param cls the `struct RequestHandle` 322 * @param cls the `struct RequestHandle`
325 */ 323 */
326static void 324static void
327do_timeout (void *cls) 325do_timeout(void *cls)
328{ 326{
329 struct RequestHandle *handle = cls; 327 struct RequestHandle *handle = cls;
330 328
331 handle->timeout_task = NULL; 329 handle->timeout_task = NULL;
332 do_error (handle); 330 do_error(handle);
333} 331}
334 332
335 333
336static void 334static void
337collect_error_cb (void *cls) 335collect_error_cb(void *cls)
338{ 336{
339 struct RequestHandle *handle = cls; 337 struct RequestHandle *handle = cls;
340 338
341 do_error (handle); 339 do_error(handle);
342} 340}
343 341
344static void 342static void
345finished_cont (void *cls, int32_t success, const char *emsg) 343finished_cont(void *cls, int32_t success, const char *emsg)
346{ 344{
347 struct RequestHandle *handle = cls; 345 struct RequestHandle *handle = cls;
348 struct MHD_Response *resp; 346 struct MHD_Response *resp;
349 347
350 resp = GNUNET_REST_create_response (emsg); 348 resp = GNUNET_REST_create_response(emsg);
351 if (GNUNET_OK != success) 349 if (GNUNET_OK != success)
352 { 350 {
353 GNUNET_SCHEDULER_add_now (&do_error, handle); 351 GNUNET_SCHEDULER_add_now(&do_error, handle);
354 return; 352 return;
355 } 353 }
356 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 354 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
357 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 355 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
358} 356}
359 357
360 358
@@ -364,28 +362,29 @@ finished_cont (void *cls, int32_t success, const char *emsg)
364 * @param cls the request handle 362 * @param cls the request handle
365 */ 363 */
366static void 364static void
367return_response (void *cls) 365return_response(void *cls)
368{ 366{
369 char *result_str; 367 char *result_str;
370 struct RequestHandle *handle = cls; 368 struct RequestHandle *handle = cls;
371 struct MHD_Response *resp; 369 struct MHD_Response *resp;
372 370
373 result_str = json_dumps (handle->resp_object, 0); 371 result_str = json_dumps(handle->resp_object, 0);
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 372 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
375 resp = GNUNET_REST_create_response (result_str); 373 resp = GNUNET_REST_create_response(result_str);
376 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 374 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
377 GNUNET_free (result_str); 375 GNUNET_free(result_str);
378 cleanup_handle (handle); 376 cleanup_handle(handle);
379} 377}
380 378
381static void 379static void
382collect_finished_cb (void *cls) 380collect_finished_cb(void *cls)
383{ 381{
384 struct RequestHandle *handle = cls; 382 struct RequestHandle *handle = cls;
383
385 // Done 384 // Done
386 handle->attr_it = NULL; 385 handle->attr_it = NULL;
387 handle->ticket_it = NULL; 386 handle->ticket_it = NULL;
388 GNUNET_SCHEDULER_add_now (&return_response, handle); 387 GNUNET_SCHEDULER_add_now(&return_response, handle);
389} 388}
390 389
391 390
@@ -394,38 +393,38 @@ collect_finished_cb (void *cls)
394 * 393 *
395 */ 394 */
396static void 395static void
397ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) 396ticket_collect(void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
398{ 397{
399 json_t *json_resource; 398 json_t *json_resource;
400 struct RequestHandle *handle = cls; 399 struct RequestHandle *handle = cls;
401 json_t *value; 400 json_t *value;
402 char *tmp; 401 char *tmp;
403 402
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n"); 403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding ticket\n");
405 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); 404 tmp = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t));
406 json_resource = json_object (); 405 json_resource = json_object();
407 GNUNET_free (tmp); 406 GNUNET_free(tmp);
408 json_array_append (handle->resp_object, json_resource); 407 json_array_append(handle->resp_object, json_resource);
409 408
410 tmp = 409 tmp =
411 GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, 410 GNUNET_STRINGS_data_to_string_alloc(&ticket->identity,
412 sizeof (struct 411 sizeof(struct
413 GNUNET_CRYPTO_EcdsaPublicKey)); 412 GNUNET_CRYPTO_EcdsaPublicKey));
414 value = json_string (tmp); 413 value = json_string(tmp);
415 json_object_set_new (json_resource, "issuer", value); 414 json_object_set_new(json_resource, "issuer", value);
416 GNUNET_free (tmp); 415 GNUNET_free(tmp);
417 tmp = 416 tmp =
418 GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, 417 GNUNET_STRINGS_data_to_string_alloc(&ticket->audience,
419 sizeof (struct 418 sizeof(struct
420 GNUNET_CRYPTO_EcdsaPublicKey)); 419 GNUNET_CRYPTO_EcdsaPublicKey));
421 value = json_string (tmp); 420 value = json_string(tmp);
422 json_object_set_new (json_resource, "audience", value); 421 json_object_set_new(json_resource, "audience", value);
423 GNUNET_free (tmp); 422 GNUNET_free(tmp);
424 tmp = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); 423 tmp = GNUNET_STRINGS_data_to_string_alloc(&ticket->rnd, sizeof(uint64_t));
425 value = json_string (tmp); 424 value = json_string(tmp);
426 json_object_set_new (json_resource, "rnd", value); 425 json_object_set_new(json_resource, "rnd", value);
427 GNUNET_free (tmp); 426 GNUNET_free(tmp);
428 GNUNET_RECLAIM_ticket_iteration_next (handle->ticket_it); 427 GNUNET_RECLAIM_ticket_iteration_next(handle->ticket_it);
429} 428}
430 429
431 430
@@ -437,57 +436,57 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
437 * @param cls the RequestHandle 436 * @param cls the RequestHandle
438 */ 437 */
439static void 438static void
440list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, 439list_tickets_cont(struct GNUNET_REST_RequestHandle *con_handle,
441 const char *url, 440 const char *url,
442 void *cls) 441 void *cls)
443{ 442{
444 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 443 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
445 struct RequestHandle *handle = cls; 444 struct RequestHandle *handle = cls;
446 struct EgoEntry *ego_entry; 445 struct EgoEntry *ego_entry;
447 char *identity; 446 char *identity;
448 447
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 448 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
450 "Getting tickets for %s.\n", 449 "Getting tickets for %s.\n",
451 handle->url); 450 handle->url);
452 if (strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen (handle->url)) 451 if (strlen(GNUNET_REST_API_NS_IDENTITY_TICKETS) >= strlen(handle->url))
453 { 452 {
454 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 453 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
455 GNUNET_SCHEDULER_add_now (&do_error, handle); 454 GNUNET_SCHEDULER_add_now(&do_error, handle);
456 return; 455 return;
457 } 456 }
458 identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1; 457 identity = handle->url + strlen(GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
459 458
460 for (ego_entry = handle->ego_head; NULL != ego_entry; 459 for (ego_entry = handle->ego_head; NULL != ego_entry;
461 ego_entry = ego_entry->next) 460 ego_entry = ego_entry->next)
462 if (0 == strcmp (identity, ego_entry->identifier)) 461 if (0 == strcmp(identity, ego_entry->identifier))
463 break; 462 break;
464 handle->resp_object = json_array (); 463 handle->resp_object = json_array();
465 464
466 if (NULL == ego_entry) 465 if (NULL == ego_entry)
467 { 466 {
468 // Done 467 // Done
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); 468 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
470 GNUNET_SCHEDULER_add_now (&return_response, handle); 469 GNUNET_SCHEDULER_add_now(&return_response, handle);
471 return; 470 return;
472 } 471 }
473 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 472 priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
474 handle->idp = GNUNET_RECLAIM_connect (cfg); 473 handle->idp = GNUNET_RECLAIM_connect(cfg);
475 handle->ticket_it = 474 handle->ticket_it =
476 GNUNET_RECLAIM_ticket_iteration_start (handle->idp, 475 GNUNET_RECLAIM_ticket_iteration_start(handle->idp,
477 priv_key, 476 priv_key,
478 &collect_error_cb, 477 &collect_error_cb,
479 handle, 478 handle,
480 &ticket_collect, 479 &ticket_collect,
481 handle, 480 handle,
482 &collect_finished_cb, 481 &collect_finished_cb,
483 handle); 482 handle);
484} 483}
485 484
486 485
487static void 486static void
488add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, 487add_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle,
489 const char *url, 488 const char *url,
490 void *cls) 489 void *cls)
491{ 490{
492 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 491 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
493 const char *identity; 492 const char *identity;
@@ -499,68 +498,68 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
499 json_t *data_json; 498 json_t *data_json;
500 json_error_t err; 499 json_error_t err;
501 struct GNUNET_JSON_Specification attrspec[] = 500 struct GNUNET_JSON_Specification attrspec[] =
502 {GNUNET_RECLAIM_JSON_spec_claim (&attribute), GNUNET_JSON_spec_end ()}; 501 { GNUNET_RECLAIM_JSON_spec_claim(&attribute), GNUNET_JSON_spec_end() };
503 502
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 503 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
505 "Adding an attribute for %s.\n", 504 "Adding an attribute for %s.\n",
506 handle->url); 505 handle->url);
507 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) 506 if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url))
508 { 507 {
509 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 508 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
510 GNUNET_SCHEDULER_add_now (&do_error, handle); 509 GNUNET_SCHEDULER_add_now(&do_error, handle);
511 return; 510 return;
512 } 511 }
513 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 512 identity = handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
514 513
515 for (ego_entry = handle->ego_head; NULL != ego_entry; 514 for (ego_entry = handle->ego_head; NULL != ego_entry;
516 ego_entry = ego_entry->next) 515 ego_entry = ego_entry->next)
517 if (0 == strcmp (identity, ego_entry->identifier)) 516 if (0 == strcmp(identity, ego_entry->identifier))
518 break; 517 break;
519 518
520 if (NULL == ego_entry) 519 if (NULL == ego_entry)
521 { 520 {
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); 521 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity);
523 return; 522 return;
524 } 523 }
525 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 524 identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
526 525
527 if (0 >= handle->rest_handle->data_size) 526 if (0 >= handle->rest_handle->data_size)
528 { 527 {
529 GNUNET_SCHEDULER_add_now (&do_error, handle); 528 GNUNET_SCHEDULER_add_now(&do_error, handle);
530 return; 529 return;
531 } 530 }
532 531
533 term_data[handle->rest_handle->data_size] = '\0'; 532 term_data[handle->rest_handle->data_size] = '\0';
534 GNUNET_memcpy (term_data, 533 GNUNET_memcpy(term_data,
535 handle->rest_handle->data, 534 handle->rest_handle->data,
536 handle->rest_handle->data_size); 535 handle->rest_handle->data_size);
537 data_json = json_loads (term_data, JSON_DECODE_ANY, &err); 536 data_json = json_loads(term_data, JSON_DECODE_ANY, &err);
538 GNUNET_assert (GNUNET_OK == 537 GNUNET_assert(GNUNET_OK ==
539 GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); 538 GNUNET_JSON_parse(data_json, attrspec, NULL, NULL));
540 json_decref (data_json); 539 json_decref(data_json);
541 if (NULL == attribute) 540 if (NULL == attribute)
542 { 541 {
543 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 542 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
544 "Unable to parse attribute from %s\n", 543 "Unable to parse attribute from %s\n",
545 term_data); 544 term_data);
546 GNUNET_SCHEDULER_add_now (&do_error, handle); 545 GNUNET_SCHEDULER_add_now(&do_error, handle);
547 return; 546 return;
548 } 547 }
549 /** 548 /**
550 * New ID for attribute 549 * New ID for attribute
551 */ 550 */
552 if (0 == attribute->id) 551 if (0 == attribute->id)
553 attribute->id = 552 attribute->id =
554 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); 553 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
555 handle->idp = GNUNET_RECLAIM_connect (cfg); 554 handle->idp = GNUNET_RECLAIM_connect(cfg);
556 exp = GNUNET_TIME_UNIT_HOURS; 555 exp = GNUNET_TIME_UNIT_HOURS;
557 handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp, 556 handle->idp_op = GNUNET_RECLAIM_attribute_store(handle->idp,
558 identity_priv, 557 identity_priv,
559 attribute, 558 attribute,
560 &exp, 559 &exp,
561 &finished_cont, 560 &finished_cont,
562 handle); 561 handle);
563 GNUNET_JSON_parse_free (attrspec); 562 GNUNET_JSON_parse_free(attrspec);
564} 563}
565 564
566 565
@@ -569,9 +568,9 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
569 * 568 *
570 */ 569 */
571static void 570static void
572attr_collect (void *cls, 571attr_collect(void *cls,
573 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 572 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
574 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 573 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
575{ 574{
576 struct RequestHandle *handle = cls; 575 struct RequestHandle *handle = cls;
577 json_t *attr_obj; 576 json_t *attr_obj;
@@ -580,28 +579,28 @@ attr_collect (void *cls,
580 char *id_str; 579 char *id_str;
581 580
582 if ((NULL == attr->name) || (NULL == attr->data)) 581 if ((NULL == attr->name) || (NULL == attr->data))
583 { 582 {
584 GNUNET_RECLAIM_get_attributes_next (handle->attr_it); 583 GNUNET_RECLAIM_get_attributes_next(handle->attr_it);
585 return; 584 return;
586 } 585 }
587 586
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); 587 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
589 588
590 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, 589 tmp_value = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type,
591 attr->data, 590 attr->data,
592 attr->data_size); 591 attr->data_size);
593 592
594 attr_obj = json_object (); 593 attr_obj = json_object();
595 json_object_set_new (attr_obj, "value", json_string (tmp_value)); 594 json_object_set_new(attr_obj, "value", json_string(tmp_value));
596 json_object_set_new (attr_obj, "name", json_string (attr->name)); 595 json_object_set_new(attr_obj, "name", json_string(attr->name));
597 type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type); 596 type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(attr->type);
598 json_object_set_new (attr_obj, "type", json_string (type)); 597 json_object_set_new(attr_obj, "type", json_string(type));
599 id_str = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t)); 598 id_str = GNUNET_STRINGS_data_to_string_alloc(&attr->id, sizeof(uint64_t));
600 json_object_set_new (attr_obj, "id", json_string (id_str)); 599 json_object_set_new(attr_obj, "id", json_string(id_str));
601 json_array_append (handle->resp_object, attr_obj); 600 json_array_append(handle->resp_object, attr_obj);
602 json_decref (attr_obj); 601 json_decref(attr_obj);
603 GNUNET_free (tmp_value); 602 GNUNET_free(tmp_value);
604 GNUNET_RECLAIM_get_attributes_next (handle->attr_it); 603 GNUNET_RECLAIM_get_attributes_next(handle->attr_it);
605} 604}
606 605
607 606
@@ -613,67 +612,67 @@ attr_collect (void *cls,
613 * @param cls the RequestHandle 612 * @param cls the RequestHandle
614 */ 613 */
615static void 614static void
616list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, 615list_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle,
617 const char *url, 616 const char *url,
618 void *cls) 617 void *cls)
619{ 618{
620 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 619 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
621 struct RequestHandle *handle = cls; 620 struct RequestHandle *handle = cls;
622 struct EgoEntry *ego_entry; 621 struct EgoEntry *ego_entry;
623 char *identity; 622 char *identity;
624 623
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 624 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
626 "Getting attributes for %s.\n", 625 "Getting attributes for %s.\n",
627 handle->url); 626 handle->url);
628 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) 627 if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url))
629 { 628 {
630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 629 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
631 GNUNET_SCHEDULER_add_now (&do_error, handle); 630 GNUNET_SCHEDULER_add_now(&do_error, handle);
632 return; 631 return;
633 } 632 }
634 identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1; 633 identity = handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
635 634
636 for (ego_entry = handle->ego_head; NULL != ego_entry; 635 for (ego_entry = handle->ego_head; NULL != ego_entry;
637 ego_entry = ego_entry->next) 636 ego_entry = ego_entry->next)
638 if (0 == strcmp (identity, ego_entry->identifier)) 637 if (0 == strcmp(identity, ego_entry->identifier))
639 break; 638 break;
640 handle->resp_object = json_array (); 639 handle->resp_object = json_array();
641 640
642 641
643 if (NULL == ego_entry) 642 if (NULL == ego_entry)
644 { 643 {
645 // Done 644 // Done
646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); 645 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
647 GNUNET_SCHEDULER_add_now (&return_response, handle); 646 GNUNET_SCHEDULER_add_now(&return_response, handle);
648 return; 647 return;
649 } 648 }
650 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 649 priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
651 handle->idp = GNUNET_RECLAIM_connect (cfg); 650 handle->idp = GNUNET_RECLAIM_connect(cfg);
652 handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, 651 handle->attr_it = GNUNET_RECLAIM_get_attributes_start(handle->idp,
653 priv_key, 652 priv_key,
654 &collect_error_cb, 653 &collect_error_cb,
655 handle, 654 handle,
656 &attr_collect, 655 &attr_collect,
657 handle, 656 handle,
658 &collect_finished_cb, 657 &collect_finished_cb,
659 handle); 658 handle);
660} 659}
661 660
662 661
663static void 662static void
664delete_finished_cb (void *cls, int32_t success, const char *emsg) 663delete_finished_cb(void *cls, int32_t success, const char *emsg)
665{ 664{
666 struct RequestHandle *handle = cls; 665 struct RequestHandle *handle = cls;
667 struct MHD_Response *resp; 666 struct MHD_Response *resp;
668 667
669 resp = GNUNET_REST_create_response (emsg); 668 resp = GNUNET_REST_create_response(emsg);
670 if (GNUNET_OK != success) 669 if (GNUNET_OK != success)
671 { 670 {
672 GNUNET_SCHEDULER_add_now (&do_error, handle); 671 GNUNET_SCHEDULER_add_now(&do_error, handle);
673 return; 672 return;
674 } 673 }
675 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 674 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
676 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); 675 GNUNET_SCHEDULER_add_now(&cleanup_handle_delayed, handle);
677} 676}
678 677
679 678
@@ -685,9 +684,9 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg)
685 * @param cls the RequestHandle 684 * @param cls the RequestHandle
686 */ 685 */
687static void 686static void
688delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, 687delete_attribute_cont(struct GNUNET_REST_RequestHandle *con_handle,
689 const char *url, 688 const char *url,
690 void *cls) 689 void *cls)
691{ 690{
692 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 691 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
693 struct RequestHandle *handle = cls; 692 struct RequestHandle *handle = cls;
@@ -697,56 +696,56 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
697 char *identity; 696 char *identity;
698 char *id; 697 char *id;
699 698
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n"); 699 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
701 if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) 700 if (strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen(handle->url))
702 { 701 {
703 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); 702 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
704 GNUNET_SCHEDULER_add_now (&do_error, handle); 703 GNUNET_SCHEDULER_add_now(&do_error, handle);
705 return; 704 return;
706 } 705 }
707 identity_id_str = 706 identity_id_str =
708 strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1); 707 strdup(handle->url + strlen(GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
709 identity = strtok (identity_id_str, "/"); 708 identity = strtok(identity_id_str, "/");
710 id = strtok (NULL, "/"); 709 id = strtok(NULL, "/");
711 if ((NULL == identity) || (NULL == id)) 710 if ((NULL == identity) || (NULL == id))
712 { 711 {
713 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); 712 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
714 GNUNET_free (identity_id_str); 713 GNUNET_free(identity_id_str);
715 GNUNET_SCHEDULER_add_now (&do_error, handle); 714 GNUNET_SCHEDULER_add_now(&do_error, handle);
716 return; 715 return;
717 } 716 }
718 717
719 for (ego_entry = handle->ego_head; NULL != ego_entry; 718 for (ego_entry = handle->ego_head; NULL != ego_entry;
720 ego_entry = ego_entry->next) 719 ego_entry = ego_entry->next)
721 if (0 == strcmp (identity, ego_entry->identifier)) 720 if (0 == strcmp(identity, ego_entry->identifier))
722 break; 721 break;
723 handle->resp_object = json_array (); 722 handle->resp_object = json_array();
724 if (NULL == ego_entry) 723 if (NULL == ego_entry)
725 { 724 {
726 // Done 725 // Done
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); 726 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
728 GNUNET_free (identity_id_str); 727 GNUNET_free(identity_id_str);
729 GNUNET_SCHEDULER_add_now (&return_response, handle); 728 GNUNET_SCHEDULER_add_now(&return_response, handle);
730 return; 729 return;
731 } 730 }
732 priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 731 priv_key = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
733 handle->idp = GNUNET_RECLAIM_connect (cfg); 732 handle->idp = GNUNET_RECLAIM_connect(cfg);
734 memset (&attr, 0, sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim)); 733 memset(&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim));
735 GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t)); 734 GNUNET_STRINGS_string_to_data(id, strlen(id), &attr.id, sizeof(uint64_t));
736 attr.name = ""; 735 attr.name = "";
737 handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp, 736 handle->idp_op = GNUNET_RECLAIM_attribute_delete(handle->idp,
738 priv_key, 737 priv_key,
739 &attr, 738 &attr,
740 &delete_finished_cb, 739 &delete_finished_cb,
741 handle); 740 handle);
742 GNUNET_free (identity_id_str); 741 GNUNET_free(identity_id_str);
743} 742}
744 743
745 744
746static void 745static void
747revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, 746revoke_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle,
748 const char *url, 747 const char *url,
749 void *cls) 748 void *cls)
750{ 749{
751 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 750 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
752 struct RequestHandle *handle = cls; 751 struct RequestHandle *handle = cls;
@@ -757,101 +756,101 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
757 json_t *data_json; 756 json_t *data_json;
758 json_error_t err; 757 json_error_t err;
759 struct GNUNET_JSON_Specification tktspec[] = 758 struct GNUNET_JSON_Specification tktspec[] =
760 {GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; 759 { GNUNET_RECLAIM_JSON_spec_ticket(&ticket), GNUNET_JSON_spec_end() };
761 760
762 if (0 >= handle->rest_handle->data_size) 761 if (0 >= handle->rest_handle->data_size)
763 { 762 {
764 GNUNET_SCHEDULER_add_now (&do_error, handle); 763 GNUNET_SCHEDULER_add_now(&do_error, handle);
765 return; 764 return;
766 } 765 }
767 766
768 term_data[handle->rest_handle->data_size] = '\0'; 767 term_data[handle->rest_handle->data_size] = '\0';
769 GNUNET_memcpy (term_data, 768 GNUNET_memcpy(term_data,
770 handle->rest_handle->data, 769 handle->rest_handle->data,
771 handle->rest_handle->data_size); 770 handle->rest_handle->data_size);
772 data_json = json_loads (term_data, JSON_DECODE_ANY, &err); 771 data_json = json_loads(term_data, JSON_DECODE_ANY, &err);
773 if ((NULL == data_json) || 772 if ((NULL == data_json) ||
774 (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL))) 773 (GNUNET_OK != GNUNET_JSON_parse(data_json, tktspec, NULL, NULL)))
775 { 774 {
776 handle->emsg = GNUNET_strdup ("Not a ticket!\n"); 775 handle->emsg = GNUNET_strdup("Not a ticket!\n");
777 GNUNET_SCHEDULER_add_now (&do_error, handle); 776 GNUNET_SCHEDULER_add_now(&do_error, handle);
778 GNUNET_JSON_parse_free (tktspec); 777 GNUNET_JSON_parse_free(tktspec);
779 if (NULL != data_json) 778 if (NULL != data_json)
780 json_decref (data_json); 779 json_decref(data_json);
781 return; 780 return;
782 } 781 }
783 json_decref (data_json); 782 json_decref(data_json);
784 if (NULL == ticket) 783 if (NULL == ticket)
785 { 784 {
786 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 785 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
787 "Unable to parse ticket from %s\n", 786 "Unable to parse ticket from %s\n",
788 term_data); 787 term_data);
789 GNUNET_SCHEDULER_add_now (&do_error, handle); 788 GNUNET_SCHEDULER_add_now(&do_error, handle);
790 return; 789 return;
791 } 790 }
792 791
793 for (ego_entry = handle->ego_head; NULL != ego_entry; 792 for (ego_entry = handle->ego_head; NULL != ego_entry;
794 ego_entry = ego_entry->next) 793 ego_entry = ego_entry->next)
795 { 794 {
796 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 795 GNUNET_IDENTITY_ego_get_public_key(ego_entry->ego, &tmp_pk);
797 if (0 == memcmp (&ticket->identity, 796 if (0 == memcmp(&ticket->identity,
798 &tmp_pk, 797 &tmp_pk,
799 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 798 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
800 break; 799 break;
801 } 800 }
802 if (NULL == ego_entry) 801 if (NULL == ego_entry)
803 { 802 {
804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); 803 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
805 GNUNET_JSON_parse_free (tktspec); 804 GNUNET_JSON_parse_free(tktspec);
806 return; 805 return;
807 } 806 }
808 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 807 identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
809 808
810 handle->idp = GNUNET_RECLAIM_connect (cfg); 809 handle->idp = GNUNET_RECLAIM_connect(cfg);
811 handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp, 810 handle->idp_op = GNUNET_RECLAIM_ticket_revoke(handle->idp,
812 identity_priv, 811 identity_priv,
813 ticket, 812 ticket,
814 &finished_cont, 813 &finished_cont,
815 handle); 814 handle);
816 GNUNET_JSON_parse_free (tktspec); 815 GNUNET_JSON_parse_free(tktspec);
817} 816}
818 817
819static void 818static void
820consume_cont (void *cls, 819consume_cont(void *cls,
821 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 820 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
822 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) 821 const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
823{ 822{
824 struct RequestHandle *handle = cls; 823 struct RequestHandle *handle = cls;
825 char *val_str; 824 char *val_str;
826 json_t *value; 825 json_t *value;
827 826
828 if (NULL == identity) 827 if (NULL == identity)
829 { 828 {
830 GNUNET_SCHEDULER_add_now (&return_response, handle); 829 GNUNET_SCHEDULER_add_now(&return_response, handle);
831 return; 830 return;
832 } 831 }
833 832
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name); 833 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", attr->name);
835 val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, 834 val_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string(attr->type,
836 attr->data, 835 attr->data,
837 attr->data_size); 836 attr->data_size);
838 if (NULL == val_str) 837 if (NULL == val_str)
839 { 838 {
840 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 839 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
841 "Failed to parse value for: %s\n", 840 "Failed to parse value for: %s\n",
842 attr->name); 841 attr->name);
843 return; 842 return;
844 } 843 }
845 value = json_string (val_str); 844 value = json_string(val_str);
846 json_object_set_new (handle->resp_object, attr->name, value); 845 json_object_set_new(handle->resp_object, attr->name, value);
847 json_decref (value); 846 json_decref(value);
848 GNUNET_free (val_str); 847 GNUNET_free(val_str);
849} 848}
850 849
851static void 850static void
852consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, 851consume_ticket_cont(struct GNUNET_REST_RequestHandle *con_handle,
853 const char *url, 852 const char *url,
854 void *cls) 853 void *cls)
855{ 854{
856 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; 855 const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv;
857 struct RequestHandle *handle = cls; 856 struct RequestHandle *handle = cls;
@@ -862,59 +861,59 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
862 json_t *data_json; 861 json_t *data_json;
863 json_error_t err; 862 json_error_t err;
864 struct GNUNET_JSON_Specification tktspec[] = 863 struct GNUNET_JSON_Specification tktspec[] =
865 {GNUNET_RECLAIM_JSON_spec_ticket (&ticket), GNUNET_JSON_spec_end ()}; 864 { GNUNET_RECLAIM_JSON_spec_ticket(&ticket), GNUNET_JSON_spec_end() };
866 865
867 if (0 >= handle->rest_handle->data_size) 866 if (0 >= handle->rest_handle->data_size)
868 { 867 {
869 GNUNET_SCHEDULER_add_now (&do_error, handle); 868 GNUNET_SCHEDULER_add_now(&do_error, handle);
870 return; 869 return;
871 } 870 }
872 871
873 term_data[handle->rest_handle->data_size] = '\0'; 872 term_data[handle->rest_handle->data_size] = '\0';
874 GNUNET_memcpy (term_data, 873 GNUNET_memcpy(term_data,
875 handle->rest_handle->data, 874 handle->rest_handle->data,
876 handle->rest_handle->data_size); 875 handle->rest_handle->data_size);
877 data_json = json_loads (term_data, JSON_DECODE_ANY, &err); 876 data_json = json_loads(term_data, JSON_DECODE_ANY, &err);
878 if (NULL == data_json) 877 if (NULL == data_json)
879 { 878 {
880 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 879 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
881 "Unable to parse JSON Object from %s\n", 880 "Unable to parse JSON Object from %s\n",
882 term_data); 881 term_data);
883 GNUNET_SCHEDULER_add_now (&do_error, handle); 882 GNUNET_SCHEDULER_add_now(&do_error, handle);
884 return; 883 return;
885 } 884 }
886 if (GNUNET_OK != GNUNET_JSON_parse (data_json, tktspec, NULL, NULL)) 885 if (GNUNET_OK != GNUNET_JSON_parse(data_json, tktspec, NULL, NULL))
887 { 886 {
888 handle->emsg = GNUNET_strdup ("Not a ticket!\n"); 887 handle->emsg = GNUNET_strdup("Not a ticket!\n");
889 GNUNET_SCHEDULER_add_now (&do_error, handle); 888 GNUNET_SCHEDULER_add_now(&do_error, handle);
890 GNUNET_JSON_parse_free (tktspec); 889 GNUNET_JSON_parse_free(tktspec);
891 json_decref (data_json); 890 json_decref(data_json);
892 return; 891 return;
893 } 892 }
894 for (ego_entry = handle->ego_head; NULL != ego_entry; 893 for (ego_entry = handle->ego_head; NULL != ego_entry;
895 ego_entry = ego_entry->next) 894 ego_entry = ego_entry->next)
896 { 895 {
897 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); 896 GNUNET_IDENTITY_ego_get_public_key(ego_entry->ego, &tmp_pk);
898 if (0 == memcmp (&ticket->audience, 897 if (0 == memcmp(&ticket->audience,
899 &tmp_pk, 898 &tmp_pk,
900 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 899 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
901 break; 900 break;
902 } 901 }
903 if (NULL == ego_entry) 902 if (NULL == ego_entry)
904 { 903 {
905 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n"); 904 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Identity unknown\n");
906 GNUNET_JSON_parse_free (tktspec); 905 GNUNET_JSON_parse_free(tktspec);
907 return; 906 return;
908 } 907 }
909 identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); 908 identity_priv = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego);
910 handle->resp_object = json_object (); 909 handle->resp_object = json_object();
911 handle->idp = GNUNET_RECLAIM_connect (cfg); 910 handle->idp = GNUNET_RECLAIM_connect(cfg);
912 handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp, 911 handle->idp_op = GNUNET_RECLAIM_ticket_consume(handle->idp,
913 identity_priv, 912 identity_priv,
914 ticket, 913 ticket,
915 &consume_cont, 914 &consume_cont,
916 handle); 915 handle);
917 GNUNET_JSON_parse_free (tktspec); 916 GNUNET_JSON_parse_free(tktspec);
918} 917}
919 918
920 919
@@ -926,18 +925,18 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
926 * @param cls the RequestHandle 925 * @param cls the RequestHandle
927 */ 926 */
928static void 927static void
929options_cont (struct GNUNET_REST_RequestHandle *con_handle, 928options_cont(struct GNUNET_REST_RequestHandle *con_handle,
930 const char *url, 929 const char *url,
931 void *cls) 930 void *cls)
932{ 931{
933 struct MHD_Response *resp; 932 struct MHD_Response *resp;
934 struct RequestHandle *handle = cls; 933 struct RequestHandle *handle = cls;
935 934
936 // For now, independent of path return all options 935 // For now, independent of path return all options
937 resp = GNUNET_REST_create_response (NULL); 936 resp = GNUNET_REST_create_response(NULL);
938 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); 937 MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods);
939 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 938 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK);
940 cleanup_handle (handle); 939 cleanup_handle(handle);
941 return; 940 return;
942} 941}
943 942
@@ -947,37 +946,37 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
947 * @param handle the request handle 946 * @param handle the request handle
948 */ 947 */
949static void 948static void
950init_cont (struct RequestHandle *handle) 949init_cont(struct RequestHandle *handle)
951{ 950{
952 struct GNUNET_REST_RequestHandlerError err; 951 struct GNUNET_REST_RequestHandlerError err;
953 static const struct GNUNET_REST_RequestHandler handlers[] = 952 static const struct GNUNET_REST_RequestHandler handlers[] =
954 {{MHD_HTTP_METHOD_GET, 953 { { MHD_HTTP_METHOD_GET,
955 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
956 &list_attribute_cont},
957 {MHD_HTTP_METHOD_POST,
958 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 954 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
959 &add_attribute_cont}, 955 &list_attribute_cont },
960 {MHD_HTTP_METHOD_DELETE, 956 { MHD_HTTP_METHOD_POST,
961 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, 957 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
962 &delete_attribute_cont}, 958 &add_attribute_cont },
963 {MHD_HTTP_METHOD_GET, 959 { MHD_HTTP_METHOD_DELETE,
964 GNUNET_REST_API_NS_IDENTITY_TICKETS, 960 GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
965 &list_tickets_cont}, 961 &delete_attribute_cont },
966 {MHD_HTTP_METHOD_POST, 962 { MHD_HTTP_METHOD_GET,
967 GNUNET_REST_API_NS_IDENTITY_REVOKE, 963 GNUNET_REST_API_NS_IDENTITY_TICKETS,
968 &revoke_ticket_cont}, 964 &list_tickets_cont },
969 {MHD_HTTP_METHOD_POST, 965 { MHD_HTTP_METHOD_POST,
970 GNUNET_REST_API_NS_IDENTITY_CONSUME, 966 GNUNET_REST_API_NS_IDENTITY_REVOKE,
971 &consume_ticket_cont}, 967 &revoke_ticket_cont },
972 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont}, 968 { MHD_HTTP_METHOD_POST,
973 GNUNET_REST_HANDLER_END}; 969 GNUNET_REST_API_NS_IDENTITY_CONSUME,
970 &consume_ticket_cont },
971 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
972 GNUNET_REST_HANDLER_END };
974 973
975 if (GNUNET_NO == 974 if (GNUNET_NO ==
976 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) 975 GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle))
977 { 976 {
978 handle->response_code = err.error_code; 977 handle->response_code = err.error_code;
979 GNUNET_SCHEDULER_add_now (&do_error, handle); 978 GNUNET_SCHEDULER_add_now(&do_error, handle);
980 } 979 }
981} 980}
982 981
983/** 982/**
@@ -1014,40 +1013,41 @@ init_cont (struct RequestHandle *handle)
1014 * must thus no longer be used 1013 * must thus no longer be used
1015 */ 1014 */
1016static void 1015static void
1017list_ego (void *cls, 1016list_ego(void *cls,
1018 struct GNUNET_IDENTITY_Ego *ego, 1017 struct GNUNET_IDENTITY_Ego *ego,
1019 void **ctx, 1018 void **ctx,
1020 const char *identifier) 1019 const char *identifier)
1021{ 1020{
1022 struct RequestHandle *handle = cls; 1021 struct RequestHandle *handle = cls;
1023 struct EgoEntry *ego_entry; 1022 struct EgoEntry *ego_entry;
1024 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 1023 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
1025 1024
1026 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 1025 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
1027 { 1026 {
1028 handle->state = ID_REST_STATE_POST_INIT; 1027 handle->state = ID_REST_STATE_POST_INIT;
1029 init_cont (handle); 1028 init_cont(handle);
1030 return; 1029 return;
1031 } 1030 }
1032 if (ID_REST_STATE_INIT == handle->state) 1031 if (ID_REST_STATE_INIT == handle->state)
1033 { 1032 {
1034 ego_entry = GNUNET_new (struct EgoEntry); 1033 ego_entry = GNUNET_new(struct EgoEntry);
1035 GNUNET_IDENTITY_ego_get_public_key (ego, &pk); 1034 GNUNET_IDENTITY_ego_get_public_key(ego, &pk);
1036 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 1035 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk);
1037 ego_entry->ego = ego; 1036 ego_entry->ego = ego;
1038 ego_entry->identifier = GNUNET_strdup (identifier); 1037 ego_entry->identifier = GNUNET_strdup(identifier);
1039 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, 1038 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,
1040 handle->ego_tail, 1039 handle->ego_tail,
1041 ego_entry); 1040 ego_entry);
1042 } 1041 }
1043} 1042}
1044 1043
1045static void 1044static void
1046rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle, 1045rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1047 GNUNET_REST_ResultProcessor proc, 1046 GNUNET_REST_ResultProcessor proc,
1048 void *proc_cls) 1047 void *proc_cls)
1049{ 1048{
1050 struct RequestHandle *handle = GNUNET_new (struct RequestHandle); 1049 struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
1050
1051 handle->response_code = 0; 1051 handle->response_code = 0;
1052 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1052 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1053 handle->proc_cls = proc_cls; 1053 handle->proc_cls = proc_cls;
@@ -1055,14 +1055,14 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1055 handle->state = ID_REST_STATE_INIT; 1055 handle->state = ID_REST_STATE_INIT;
1056 handle->rest_handle = rest_handle; 1056 handle->rest_handle = rest_handle;
1057 1057
1058 handle->url = GNUNET_strdup (rest_handle->url); 1058 handle->url = GNUNET_strdup(rest_handle->url);
1059 if (handle->url[strlen (handle->url) - 1] == '/') 1059 if (handle->url[strlen(handle->url) - 1] == '/')
1060 handle->url[strlen (handle->url) - 1] = '\0'; 1060 handle->url[strlen(handle->url) - 1] = '\0';
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 1061 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1062 handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle); 1062 handle->identity_handle = GNUNET_IDENTITY_connect(cfg, &list_ego, handle);
1063 handle->timeout_task = 1063 handle->timeout_task =
1064 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle); 1064 GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_timeout, handle);
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 1065 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1066} 1066}
1067 1067
1068/** 1068/**
@@ -1072,7 +1072,7 @@ rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
1072 * @return NULL on error, otherwise the plugin context 1072 * @return NULL on error, otherwise the plugin context
1073 */ 1073 */
1074void * 1074void *
1075libgnunet_plugin_rest_reclaim_init (void *cls) 1075libgnunet_plugin_rest_reclaim_init(void *cls)
1076{ 1076{
1077 static struct Plugin plugin; 1077 static struct Plugin plugin;
1078 struct GNUNET_REST_Plugin *api; 1078 struct GNUNET_REST_Plugin *api;
@@ -1080,22 +1080,22 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1080 cfg = cls; 1080 cfg = cls;
1081 if (NULL != plugin.cfg) 1081 if (NULL != plugin.cfg)
1082 return NULL; /* can only initialize once! */ 1082 return NULL; /* can only initialize once! */
1083 memset (&plugin, 0, sizeof (struct Plugin)); 1083 memset(&plugin, 0, sizeof(struct Plugin));
1084 plugin.cfg = cfg; 1084 plugin.cfg = cfg;
1085 api = GNUNET_new (struct GNUNET_REST_Plugin); 1085 api = GNUNET_new(struct GNUNET_REST_Plugin);
1086 api->cls = &plugin; 1086 api->cls = &plugin;
1087 api->name = GNUNET_REST_API_NS_RECLAIM; 1087 api->name = GNUNET_REST_API_NS_RECLAIM;
1088 api->process_request = &rest_identity_process_request; 1088 api->process_request = &rest_identity_process_request;
1089 GNUNET_asprintf (&allow_methods, 1089 GNUNET_asprintf(&allow_methods,
1090 "%s, %s, %s, %s, %s", 1090 "%s, %s, %s, %s, %s",
1091 MHD_HTTP_METHOD_GET, 1091 MHD_HTTP_METHOD_GET,
1092 MHD_HTTP_METHOD_POST, 1092 MHD_HTTP_METHOD_POST,
1093 MHD_HTTP_METHOD_PUT, 1093 MHD_HTTP_METHOD_PUT,
1094 MHD_HTTP_METHOD_DELETE, 1094 MHD_HTTP_METHOD_DELETE,
1095 MHD_HTTP_METHOD_OPTIONS); 1095 MHD_HTTP_METHOD_OPTIONS);
1096 1096
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1097 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1098 _ ("Identity Provider REST API initialized\n")); 1098 _("Identity Provider REST API initialized\n"));
1099 return api; 1099 return api;
1100} 1100}
1101 1101
@@ -1107,16 +1107,17 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
1107 * @return always NULL 1107 * @return always NULL
1108 */ 1108 */
1109void * 1109void *
1110libgnunet_plugin_rest_reclaim_done (void *cls) 1110libgnunet_plugin_rest_reclaim_done(void *cls)
1111{ 1111{
1112 struct GNUNET_REST_Plugin *api = cls; 1112 struct GNUNET_REST_Plugin *api = cls;
1113 struct Plugin *plugin = api->cls; 1113 struct Plugin *plugin = api->cls;
1114
1114 plugin->cfg = NULL; 1115 plugin->cfg = NULL;
1115 1116
1116 GNUNET_free_non_null (allow_methods); 1117 GNUNET_free_non_null(allow_methods);
1117 GNUNET_free (api); 1118 GNUNET_free(api);
1118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1119 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1119 "Identity Provider REST plugin is finished\n"); 1120 "Identity Provider REST plugin is finished\n");
1120 return NULL; 1121 return NULL;
1121} 1122}
1122 1123