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