summaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c1273
1 files changed, 656 insertions, 617 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 57bff8ed4..23a5db1ed 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-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 * @file src/reclaim/gnunet-service-reclaim.c 22 * @file src/reclaim/gnunet-service-reclaim.c
@@ -58,8 +58,7 @@ struct IdpClient;
58/** 58/**
59 * A ticket iteration operation. 59 * A ticket iteration operation.
60 */ 60 */
61struct TicketIteration 61struct TicketIteration {
62{
63 /** 62 /**
64 * DLL 63 * DLL
65 */ 64 */
@@ -90,8 +89,7 @@ struct TicketIteration
90/** 89/**
91 * An attribute iteration operation. 90 * An attribute iteration operation.
92 */ 91 */
93struct AttributeIterator 92struct AttributeIterator {
94{
95 /** 93 /**
96 * Next element in the DLL 94 * Next element in the DLL
97 */ 95 */
@@ -127,8 +125,7 @@ struct AttributeIterator
127/** 125/**
128 * An idp client 126 * An idp client
129 */ 127 */
130struct IdpClient 128struct IdpClient {
131{
132 /** 129 /**
133 * DLL 130 * DLL
134 */ 131 */
@@ -227,8 +224,7 @@ struct IdpClient
227/** 224/**
228 * Handle for attribute deletion request 225 * Handle for attribute deletion request
229 */ 226 */
230struct AttributeDeleteHandle 227struct AttributeDeleteHandle {
231{
232 /** 228 /**
233 * DLL 229 * DLL
234 */ 230 */
@@ -290,8 +286,7 @@ struct AttributeDeleteHandle
290/** 286/**
291 * Handle for attribute store request 287 * Handle for attribute store request
292 */ 288 */
293struct AttributeStoreHandle 289struct AttributeStoreHandle {
294{
295 /** 290 /**
296 * DLL 291 * DLL
297 */ 292 */
@@ -342,8 +337,7 @@ struct AttributeStoreHandle
342/** 337/**
343 * Handle for ticket consume request 338 * Handle for ticket consume request
344 */ 339 */
345struct ConsumeTicketOperation 340struct ConsumeTicketOperation {
346{
347 /** 341 /**
348 * DLL 342 * DLL
349 */ 343 */
@@ -374,8 +368,7 @@ struct ConsumeTicketOperation
374/** 368/**
375 * Ticket revocation request handle 369 * Ticket revocation request handle
376 */ 370 */
377struct TicketRevocationOperation 371struct TicketRevocationOperation {
378{
379 /** 372 /**
380 * DLL 373 * DLL
381 */ 374 */
@@ -406,8 +399,7 @@ struct TicketRevocationOperation
406/** 399/**
407 * Ticket issue operation handle 400 * Ticket issue operation handle
408 */ 401 */
409struct TicketIssueOperation 402struct TicketIssueOperation {
410{
411 /** 403 /**
412 * DLL 404 * DLL
413 */ 405 */
@@ -447,28 +439,30 @@ static struct IdpClient *client_list_tail = NULL;
447 * @param adh the attribute to cleanup 439 * @param adh the attribute to cleanup
448 */ 440 */
449static void 441static void
450cleanup_adh (struct AttributeDeleteHandle *adh) 442cleanup_adh(struct AttributeDeleteHandle *adh)
451{ 443{
452 struct TicketRecordsEntry *le; 444 struct TicketRecordsEntry *le;
445
453 if (NULL != adh->ns_it) 446 if (NULL != adh->ns_it)
454 GNUNET_NAMESTORE_zone_iteration_stop (adh->ns_it); 447 GNUNET_NAMESTORE_zone_iteration_stop(adh->ns_it);
455 if (NULL != adh->ns_qe) 448 if (NULL != adh->ns_qe)
456 GNUNET_NAMESTORE_cancel (adh->ns_qe); 449 GNUNET_NAMESTORE_cancel(adh->ns_qe);
457 if (NULL != adh->label) 450 if (NULL != adh->label)
458 GNUNET_free (adh->label); 451 GNUNET_free(adh->label);
459 if (NULL != adh->claim) 452 if (NULL != adh->claim)
460 GNUNET_free (adh->claim); 453 GNUNET_free(adh->claim);
461 while (NULL != (le = adh->tickets_to_update_head)) { 454 while (NULL != (le = adh->tickets_to_update_head))
462 GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, 455 {
463 adh->tickets_to_update_tail, 456 GNUNET_CONTAINER_DLL_remove(adh->tickets_to_update_head,
464 le); 457 adh->tickets_to_update_tail,
465 if (NULL != le->label) 458 le);
466 GNUNET_free (le->label); 459 if (NULL != le->label)
467 if (NULL != le->data) 460 GNUNET_free(le->label);
468 GNUNET_free (le->data); 461 if (NULL != le->data)
469 GNUNET_free (le); 462 GNUNET_free(le->data);
470 } 463 GNUNET_free(le);
471 GNUNET_free (adh); 464 }
465 GNUNET_free(adh);
472} 466}
473 467
474 468
@@ -478,13 +472,13 @@ cleanup_adh (struct AttributeDeleteHandle *adh)
478 * @param handle handle to clean up 472 * @param handle handle to clean up
479 */ 473 */
480static void 474static void
481cleanup_as_handle (struct AttributeStoreHandle *ash) 475cleanup_as_handle(struct AttributeStoreHandle *ash)
482{ 476{
483 if (NULL != ash->ns_qe) 477 if (NULL != ash->ns_qe)
484 GNUNET_NAMESTORE_cancel (ash->ns_qe); 478 GNUNET_NAMESTORE_cancel(ash->ns_qe);
485 if (NULL != ash->claim) 479 if (NULL != ash->claim)
486 GNUNET_free (ash->claim); 480 GNUNET_free(ash->claim);
487 GNUNET_free (ash); 481 GNUNET_free(ash);
488} 482}
489 483
490 484
@@ -494,7 +488,7 @@ cleanup_as_handle (struct AttributeStoreHandle *ash)
494 * @param idp the client to clean up 488 * @param idp the client to clean up
495 */ 489 */
496static void 490static void
497cleanup_client (struct IdpClient *idp) 491cleanup_client(struct IdpClient *idp)
498{ 492{
499 struct AttributeIterator *ai; 493 struct AttributeIterator *ai;
500 struct TicketIteration *ti; 494 struct TicketIteration *ti;
@@ -504,46 +498,53 @@ cleanup_client (struct IdpClient *idp)
504 struct AttributeStoreHandle *as; 498 struct AttributeStoreHandle *as;
505 struct AttributeDeleteHandle *adh; 499 struct AttributeDeleteHandle *adh;
506 500
507 while (NULL != (iss = idp->issue_op_head)) { 501 while (NULL != (iss = idp->issue_op_head))
508 GNUNET_CONTAINER_DLL_remove (idp->issue_op_head, idp->issue_op_tail, iss); 502 {
509 GNUNET_free (iss); 503 GNUNET_CONTAINER_DLL_remove(idp->issue_op_head, idp->issue_op_tail, iss);
510 } 504 GNUNET_free(iss);
511 while (NULL != (ct = idp->consume_op_head)) { 505 }
512 GNUNET_CONTAINER_DLL_remove (idp->consume_op_head, 506 while (NULL != (ct = idp->consume_op_head))
513 idp->consume_op_tail, 507 {
514 ct); 508 GNUNET_CONTAINER_DLL_remove(idp->consume_op_head,
515 if (NULL != ct->ch) 509 idp->consume_op_tail,
516 RECLAIM_TICKETS_consume_cancel (ct->ch); 510 ct);
517 GNUNET_free (ct); 511 if (NULL != ct->ch)
518 } 512 RECLAIM_TICKETS_consume_cancel(ct->ch);
519 while (NULL != (as = idp->store_op_head)) { 513 GNUNET_free(ct);
520 GNUNET_CONTAINER_DLL_remove (idp->store_op_head, idp->store_op_tail, as); 514 }
521 cleanup_as_handle (as); 515 while (NULL != (as = idp->store_op_head))
522 } 516 {
523 while (NULL != (adh = idp->delete_op_head)) { 517 GNUNET_CONTAINER_DLL_remove(idp->store_op_head, idp->store_op_tail, as);
524 GNUNET_CONTAINER_DLL_remove (idp->delete_op_head, idp->delete_op_tail, adh); 518 cleanup_as_handle(as);
525 cleanup_adh (adh); 519 }
526 } 520 while (NULL != (adh = idp->delete_op_head))
527 521 {
528 while (NULL != (ai = idp->attr_iter_head)) { 522 GNUNET_CONTAINER_DLL_remove(idp->delete_op_head, idp->delete_op_tail, adh);
529 GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); 523 cleanup_adh(adh);
530 GNUNET_free (ai); 524 }
531 } 525
532 while (NULL != (rop = idp->revoke_op_head)) { 526 while (NULL != (ai = idp->attr_iter_head))
533 GNUNET_CONTAINER_DLL_remove (idp->revoke_op_head, idp->revoke_op_tail, rop); 527 {
534 if (NULL != rop->rh) 528 GNUNET_CONTAINER_DLL_remove(idp->attr_iter_head, idp->attr_iter_tail, ai);
535 RECLAIM_TICKETS_revoke_cancel (rop->rh); 529 GNUNET_free(ai);
536 GNUNET_free (rop); 530 }
537 } 531 while (NULL != (rop = idp->revoke_op_head))
538 while (NULL != (ti = idp->ticket_iter_head)) { 532 {
539 GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head, 533 GNUNET_CONTAINER_DLL_remove(idp->revoke_op_head, idp->revoke_op_tail, rop);
540 idp->ticket_iter_tail, 534 if (NULL != rop->rh)
541 ti); 535 RECLAIM_TICKETS_revoke_cancel(rop->rh);
542 if (NULL != ti->iter) 536 GNUNET_free(rop);
543 RECLAIM_TICKETS_iteration_stop (ti->iter); 537 }
544 GNUNET_free (ti); 538 while (NULL != (ti = idp->ticket_iter_head))
545 } 539 {
546 GNUNET_free (idp); 540 GNUNET_CONTAINER_DLL_remove(idp->ticket_iter_head,
541 idp->ticket_iter_tail,
542 ti);
543 if (NULL != ti->iter)
544 RECLAIM_TICKETS_iteration_stop(ti->iter);
545 GNUNET_free(ti);
546 }
547 GNUNET_free(idp);
547} 548}
548 549
549 550
@@ -551,23 +552,24 @@ cleanup_client (struct IdpClient *idp)
551 * Cleanup task 552 * Cleanup task
552 */ 553 */
553static void 554static void
554cleanup () 555cleanup()
555{ 556{
556 struct IdpClient *cl; 557 struct IdpClient *cl;
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 558
559 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
558 560
559 while (NULL != (cl = client_list_head)) 561 while (NULL != (cl = client_list_head))
560 { 562 {
561 GNUNET_CONTAINER_DLL_remove (client_list_head, 563 GNUNET_CONTAINER_DLL_remove(client_list_head,
562 client_list_tail, 564 client_list_tail,
563 cl); 565 cl);
564 cleanup_client (cl); 566 cleanup_client(cl);
565 } 567 }
566 RECLAIM_TICKETS_deinit (); 568 RECLAIM_TICKETS_deinit();
567 if (NULL != timeout_task) 569 if (NULL != timeout_task)
568 GNUNET_SCHEDULER_cancel (timeout_task); 570 GNUNET_SCHEDULER_cancel(timeout_task);
569 if (NULL != nsh) 571 if (NULL != nsh)
570 GNUNET_NAMESTORE_disconnect (nsh); 572 GNUNET_NAMESTORE_disconnect(nsh);
571} 573}
572 574
573 575
@@ -577,10 +579,10 @@ cleanup ()
577 * @param cls NULL 579 * @param cls NULL
578 */ 580 */
579static void 581static void
580do_shutdown (void *cls) 582do_shutdown(void *cls)
581{ 583{
582 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down...\n"); 584 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Shutting down...\n");
583 cleanup (); 585 cleanup();
584} 586}
585 587
586 588
@@ -593,23 +595,24 @@ do_shutdown (void *cls)
593 * @param success the success status of the request 595 * @param success the success status of the request
594 */ 596 */
595static void 597static void
596send_ticket_result (const struct IdpClient *client, 598send_ticket_result(const struct IdpClient *client,
597 uint32_t r_id, 599 uint32_t r_id,
598 const struct GNUNET_RECLAIM_Ticket *ticket, 600 const struct GNUNET_RECLAIM_Ticket *ticket,
599 uint32_t success) 601 uint32_t success)
600{ 602{
601 struct TicketResultMessage *irm; 603 struct TicketResultMessage *irm;
602 struct GNUNET_MQ_Envelope *env; 604 struct GNUNET_MQ_Envelope *env;
603 605
604 env = GNUNET_MQ_msg (irm, 606 env = GNUNET_MQ_msg(irm,
605 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); 607 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
606 if (NULL != ticket) { 608 if (NULL != ticket)
607 irm->ticket = *ticket; 609 {
608 } 610 irm->ticket = *ticket;
611 }
609 // TODO add success member 612 // TODO add success member
610 irm->id = htonl (r_id); 613 irm->id = htonl(r_id);
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n"); 614 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
612 GNUNET_MQ_send (client->mq, env); 615 GNUNET_MQ_send(client->mq, env);
613} 616}
614 617
615 618
@@ -622,26 +625,28 @@ send_ticket_result (const struct IdpClient *client,
622 * @param emsg error message (NULL of success is GNUNET_OK) 625 * @param emsg error message (NULL of success is GNUNET_OK)
623 */ 626 */
624static void 627static void
625issue_ticket_result_cb (void *cls, 628issue_ticket_result_cb(void *cls,
626 struct GNUNET_RECLAIM_Ticket *ticket, 629 struct GNUNET_RECLAIM_Ticket *ticket,
627 int32_t success, 630 int32_t success,
628 const char *emsg) 631 const char *emsg)
629{ 632{
630 struct TicketIssueOperation *tio = cls; 633 struct TicketIssueOperation *tio = cls;
631 if (GNUNET_OK != success) { 634
632 send_ticket_result (tio->client, tio->r_id, NULL, GNUNET_SYSERR); 635 if (GNUNET_OK != success)
633 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, 636 {
634 tio->client->issue_op_tail, 637 send_ticket_result(tio->client, tio->r_id, NULL, GNUNET_SYSERR);
635 tio); 638 GNUNET_CONTAINER_DLL_remove(tio->client->issue_op_head,
636 GNUNET_free (tio); 639 tio->client->issue_op_tail,
637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg); 640 tio);
638 return; 641 GNUNET_free(tio);
639 } 642 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error issuing ticket: %s\n", emsg);
640 send_ticket_result (tio->client, tio->r_id, ticket, GNUNET_SYSERR); 643 return;
641 GNUNET_CONTAINER_DLL_remove (tio->client->issue_op_head, 644 }
642 tio->client->issue_op_tail, 645 send_ticket_result(tio->client, tio->r_id, ticket, GNUNET_SYSERR);
643 tio); 646 GNUNET_CONTAINER_DLL_remove(tio->client->issue_op_head,
644 GNUNET_free (tio); 647 tio->client->issue_op_tail,
648 tio);
649 GNUNET_free(tio);
645} 650}
646 651
647 652
@@ -653,15 +658,16 @@ issue_ticket_result_cb (void *cls,
653 * @return GNUNET_OK if message is ok 658 * @return GNUNET_OK if message is ok
654 */ 659 */
655static int 660static int
656check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) 661check_issue_ticket_message(void *cls, const struct IssueTicketMessage *im)
657{ 662{
658 uint16_t size; 663 uint16_t size;
659 664
660 size = ntohs (im->header.size); 665 size = ntohs(im->header.size);
661 if (size <= sizeof (struct IssueTicketMessage)) { 666 if (size <= sizeof(struct IssueTicketMessage))
662 GNUNET_break (0); 667 {
663 return GNUNET_SYSERR; 668 GNUNET_break(0);
664 } 669 return GNUNET_SYSERR;
670 }
665 return GNUNET_OK; 671 return GNUNET_OK;
666} 672}
667 673
@@ -673,34 +679,34 @@ check_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
673 * @param im the message 679 * @param im the message
674 */ 680 */
675static void 681static void
676handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im) 682handle_issue_ticket_message(void *cls, const struct IssueTicketMessage *im)
677{ 683{
678 struct TicketIssueOperation *tio; 684 struct TicketIssueOperation *tio;
679 struct IdpClient *idp = cls; 685 struct IdpClient *idp = cls;
680 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; 686 struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs;
681 size_t attrs_len; 687 size_t attrs_len;
682 688
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n"); 689 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n");
684 tio = GNUNET_new (struct TicketIssueOperation); 690 tio = GNUNET_new(struct TicketIssueOperation);
685 attrs_len = ntohs (im->attr_len); 691 attrs_len = ntohs(im->attr_len);
686 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize ((char *)&im[1], attrs_len); 692 attrs = GNUNET_RECLAIM_ATTRIBUTE_list_deserialize((char *)&im[1], attrs_len);
687 tio->r_id = ntohl (im->id); 693 tio->r_id = ntohl(im->id);
688 tio->client = idp; 694 tio->client = idp;
689 GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio); 695 GNUNET_CONTAINER_DLL_insert(idp->issue_op_head, idp->issue_op_tail, tio);
690 RECLAIM_TICKETS_issue (&im->identity, 696 RECLAIM_TICKETS_issue(&im->identity,
691 attrs, 697 attrs,
692 &im->rp, 698 &im->rp,
693 &issue_ticket_result_cb, 699 &issue_ticket_result_cb,
694 tio); 700 tio);
695 GNUNET_SERVICE_client_continue (idp->client); 701 GNUNET_SERVICE_client_continue(idp->client);
696 GNUNET_RECLAIM_ATTRIBUTE_list_destroy (attrs); 702 GNUNET_RECLAIM_ATTRIBUTE_list_destroy(attrs);
697} 703}
698 704
699 705
700 706
701/********************************************************** 707/**********************************************************
702 * Revocation 708* Revocation
703 **********************************************************/ 709**********************************************************/
704 710
705/** 711/**
706 * Handles revocation result 712 * Handles revocation result
@@ -709,22 +715,22 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
709 * @param success revocation result (GNUNET_OK if successful) 715 * @param success revocation result (GNUNET_OK if successful)
710 */ 716 */
711static void 717static void
712revoke_result_cb (void *cls, int32_t success) 718revoke_result_cb(void *cls, int32_t success)
713{ 719{
714 struct TicketRevocationOperation *rop = cls; 720 struct TicketRevocationOperation *rop = cls;
715 struct GNUNET_MQ_Envelope *env; 721 struct GNUNET_MQ_Envelope *env;
716 struct RevokeTicketResultMessage *trm; 722 struct RevokeTicketResultMessage *trm;
717 723
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending REVOKE_TICKET_RESULT message\n"); 724 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending REVOKE_TICKET_RESULT message\n");
719 rop->rh = NULL; 725 rop->rh = NULL;
720 env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT); 726 env = GNUNET_MQ_msg(trm, GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET_RESULT);
721 trm->id = htonl (rop->r_id); 727 trm->id = htonl(rop->r_id);
722 trm->success = htonl (success); 728 trm->success = htonl(success);
723 GNUNET_MQ_send (rop->client->mq, env); 729 GNUNET_MQ_send(rop->client->mq, env);
724 GNUNET_CONTAINER_DLL_remove (rop->client->revoke_op_head, 730 GNUNET_CONTAINER_DLL_remove(rop->client->revoke_op_head,
725 rop->client->revoke_op_tail, 731 rop->client->revoke_op_tail,
726 rop); 732 rop);
727 GNUNET_free (rop); 733 GNUNET_free(rop);
728} 734}
729 735
730 736
@@ -736,15 +742,16 @@ revoke_result_cb (void *cls, int32_t success)
736 * @return GNUNET_OK if message is ok 742 * @return GNUNET_OK if message is ok
737 */ 743 */
738static int 744static int
739check_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *im) 745check_revoke_ticket_message(void *cls, const struct RevokeTicketMessage *im)
740{ 746{
741 uint16_t size; 747 uint16_t size;
742 748
743 size = ntohs (im->header.size); 749 size = ntohs(im->header.size);
744 if (size != sizeof (struct RevokeTicketMessage)) { 750 if (size != sizeof(struct RevokeTicketMessage))
745 GNUNET_break (0); 751 {
746 return GNUNET_SYSERR; 752 GNUNET_break(0);
747 } 753 return GNUNET_SYSERR;
754 }
748 return GNUNET_OK; 755 return GNUNET_OK;
749} 756}
750 757
@@ -756,19 +763,19 @@ check_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *im)
756 * @param rm the message to handle 763 * @param rm the message to handle
757 */ 764 */
758static void 765static void
759handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) 766handle_revoke_ticket_message(void *cls, const struct RevokeTicketMessage *rm)
760{ 767{
761 struct TicketRevocationOperation *rop; 768 struct TicketRevocationOperation *rop;
762 struct IdpClient *idp = cls; 769 struct IdpClient *idp = cls;
763 770
764 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n"); 771 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received REVOKE_TICKET message\n");
765 rop = GNUNET_new (struct TicketRevocationOperation); 772 rop = GNUNET_new(struct TicketRevocationOperation);
766 rop->r_id = ntohl (rm->id); 773 rop->r_id = ntohl(rm->id);
767 rop->client = idp; 774 rop->client = idp;
768 GNUNET_CONTAINER_DLL_insert (idp->revoke_op_head, idp->revoke_op_tail, rop); 775 GNUNET_CONTAINER_DLL_insert(idp->revoke_op_head, idp->revoke_op_tail, rop);
769 rop->rh 776 rop->rh
770 = RECLAIM_TICKETS_revoke (&rm->ticket, &rm->identity, &revoke_result_cb, rop); 777 = RECLAIM_TICKETS_revoke(&rm->ticket, &rm->identity, &revoke_result_cb, rop);
771 GNUNET_SERVICE_client_continue (idp->client); 778 GNUNET_SERVICE_client_continue(idp->client);
772} 779}
773 780
774 781
@@ -782,36 +789,38 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm)
782 * @param emsg error message (NULL if success=GNUNET_OK) 789 * @param emsg error message (NULL if success=GNUNET_OK)
783 */ 790 */
784static void 791static void
785consume_result_cb (void *cls, 792consume_result_cb(void *cls,
786 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, 793 const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
787 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, 794 const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs,
788 int32_t success, 795 int32_t success,
789 const char *emsg) 796 const char *emsg)
790{ 797{
791 struct ConsumeTicketOperation *cop = cls; 798 struct ConsumeTicketOperation *cop = cls;
792 struct ConsumeTicketResultMessage *crm; 799 struct ConsumeTicketResultMessage *crm;
793 struct GNUNET_MQ_Envelope *env; 800 struct GNUNET_MQ_Envelope *env;
794 char *data_tmp; 801 char *data_tmp;
795 size_t attrs_len; 802 size_t attrs_len;
796 if (GNUNET_OK != success) { 803
797 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg); 804 if (GNUNET_OK != success)
798 } 805 {
799 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size (attrs); 806 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error consuming ticket: %s\n", emsg);
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending CONSUME_TICKET_RESULT message\n"); 807 }
801 env = GNUNET_MQ_msg_extra (crm, 808 attrs_len = GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size(attrs);
802 attrs_len, 809 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending CONSUME_TICKET_RESULT message\n");
803 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT); 810 env = GNUNET_MQ_msg_extra(crm,
804 crm->id = htonl (cop->r_id); 811 attrs_len,
805 crm->attrs_len = htons (attrs_len); 812 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET_RESULT);
813 crm->id = htonl(cop->r_id);
814 crm->attrs_len = htons(attrs_len);
806 crm->identity = *identity; 815 crm->identity = *identity;
807 crm->result = htonl (success); 816 crm->result = htonl(success);
808 data_tmp = (char *)&crm[1]; 817 data_tmp = (char *)&crm[1];
809 GNUNET_RECLAIM_ATTRIBUTE_list_serialize (attrs, data_tmp); 818 GNUNET_RECLAIM_ATTRIBUTE_list_serialize(attrs, data_tmp);
810 GNUNET_MQ_send (cop->client->mq, env); 819 GNUNET_MQ_send(cop->client->mq, env);
811 GNUNET_CONTAINER_DLL_remove (cop->client->consume_op_head, 820 GNUNET_CONTAINER_DLL_remove(cop->client->consume_op_head,
812 cop->client->consume_op_tail, 821 cop->client->consume_op_tail,
813 cop); 822 cop);
814 GNUNET_free (cop); 823 GNUNET_free(cop);
815} 824}
816 825
817 826
@@ -822,15 +831,16 @@ consume_result_cb (void *cls,
822 * @param cm the message to handle 831 * @param cm the message to handle
823 */ 832 */
824static int 833static int
825check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) 834check_consume_ticket_message(void *cls, const struct ConsumeTicketMessage *cm)
826{ 835{
827 uint16_t size; 836 uint16_t size;
828 837
829 size = ntohs (cm->header.size); 838 size = ntohs(cm->header.size);
830 if (size != sizeof (struct ConsumeTicketMessage)) { 839 if (size != sizeof(struct ConsumeTicketMessage))
831 GNUNET_break (0); 840 {
832 return GNUNET_SYSERR; 841 GNUNET_break(0);
833 } 842 return GNUNET_SYSERR;
843 }
834 return GNUNET_OK; 844 return GNUNET_OK;
835} 845}
836 846
@@ -842,24 +852,24 @@ check_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm)
842 * @cm the message to handle 852 * @cm the message to handle
843 */ 853 */
844static void 854static void
845handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm) 855handle_consume_ticket_message(void *cls, const struct ConsumeTicketMessage *cm)
846{ 856{
847 struct ConsumeTicketOperation *cop; 857 struct ConsumeTicketOperation *cop;
848 struct IdpClient *idp = cls; 858 struct IdpClient *idp = cls;
849 859
850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n"); 860 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received CONSUME_TICKET message\n");
851 cop = GNUNET_new (struct ConsumeTicketOperation); 861 cop = GNUNET_new(struct ConsumeTicketOperation);
852 cop->r_id = ntohl (cm->id); 862 cop->r_id = ntohl(cm->id);
853 cop->client = idp; 863 cop->client = idp;
854 cop->ch 864 cop->ch
855 = RECLAIM_TICKETS_consume (&cm->identity, &cm->ticket, &consume_result_cb, cop); 865 = RECLAIM_TICKETS_consume(&cm->identity, &cm->ticket, &consume_result_cb, cop);
856 GNUNET_CONTAINER_DLL_insert (idp->consume_op_head, idp->consume_op_tail, cop); 866 GNUNET_CONTAINER_DLL_insert(idp->consume_op_head, idp->consume_op_tail, cop);
857 GNUNET_SERVICE_client_continue (idp->client); 867 GNUNET_SERVICE_client_continue(idp->client);
858} 868}
859 869
860/***************************************** 870/*****************************************
861 * Attribute store 871* Attribute store
862 *****************************************/ 872*****************************************/
863 873
864 874
865/** 875/**
@@ -870,32 +880,33 @@ handle_consume_ticket_message (void *cls, const struct ConsumeTicketMessage *cm)
870 * @param emsg error message (NULL if success=GNUNET_OK) 880 * @param emsg error message (NULL if success=GNUNET_OK)
871 */ 881 */
872static void 882static void
873attr_store_cont (void *cls, int32_t success, const char *emsg) 883attr_store_cont(void *cls, int32_t success, const char *emsg)
874{ 884{
875 struct AttributeStoreHandle *ash = cls; 885 struct AttributeStoreHandle *ash = cls;
876 struct GNUNET_MQ_Envelope *env; 886 struct GNUNET_MQ_Envelope *env;
877 struct SuccessResultMessage *acr_msg; 887 struct SuccessResultMessage *acr_msg;
878 888
879 ash->ns_qe = NULL; 889 ash->ns_qe = NULL;
880 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, 890 GNUNET_CONTAINER_DLL_remove(ash->client->store_op_head,
881 ash->client->store_op_tail, 891 ash->client->store_op_tail,
882 ash); 892 ash);
883 893
884 if (GNUNET_SYSERR == success) { 894 if (GNUNET_SYSERR == success)
885 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 895 {
886 "Failed to store attribute %s\n", 896 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
887 emsg); 897 "Failed to store attribute %s\n",
888 cleanup_as_handle (ash); 898 emsg);
889 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 899 cleanup_as_handle(ash);
890 return; 900 GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
891 } 901 return;
892 902 }
893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); 903
894 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); 904 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
895 acr_msg->id = htonl (ash->r_id); 905 env = GNUNET_MQ_msg(acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
896 acr_msg->op_result = htonl (GNUNET_OK); 906 acr_msg->id = htonl(ash->r_id);
897 GNUNET_MQ_send (ash->client->mq, env); 907 acr_msg->op_result = htonl(GNUNET_OK);
898 cleanup_as_handle (ash); 908 GNUNET_MQ_send(ash->client->mq, env);
909 cleanup_as_handle(ash);
899} 910}
900 911
901 912
@@ -905,7 +916,7 @@ attr_store_cont (void *cls, int32_t success, const char *emsg)
905 * @param cls the AttributeStoreHandle 916 * @param cls the AttributeStoreHandle
906 */ 917 */
907static void 918static void
908attr_store_task (void *cls) 919attr_store_task(void *cls)
909{ 920{
910 struct AttributeStoreHandle *ash = cls; 921 struct AttributeStoreHandle *ash = cls;
911 struct GNUNET_GNSRECORD_Data rd[1]; 922 struct GNUNET_GNSRECORD_Data rd[1];
@@ -913,32 +924,32 @@ attr_store_task (void *cls)
913 char *label; 924 char *label;
914 size_t buf_size; 925 size_t buf_size;
915 926
916 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n"); 927 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Storing attribute\n");
917 buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (ash->claim); 928 buf_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(ash->claim);
918 buf = GNUNET_malloc (buf_size); 929 buf = GNUNET_malloc(buf_size);
919 // Give the ash a new id if unset 930 // Give the ash a new id if unset
920 if (0 == ash->claim->id) 931 if (0 == ash->claim->id)
921 ash->claim->id 932 ash->claim->id
922 = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); 933 = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
923 GNUNET_RECLAIM_ATTRIBUTE_serialize (ash->claim, buf); 934 GNUNET_RECLAIM_ATTRIBUTE_serialize(ash->claim, buf);
924 label 935 label
925 = GNUNET_STRINGS_data_to_string_alloc (&ash->claim->id, sizeof (uint64_t)); 936 = GNUNET_STRINGS_data_to_string_alloc(&ash->claim->id, sizeof(uint64_t));
926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); 937 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
927 938
928 rd[0].data_size = buf_size; 939 rd[0].data_size = buf_size;
929 rd[0].data = buf; 940 rd[0].data = buf;
930 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR; 941 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR;
931 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 942 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
932 rd[0].expiration_time = ash->exp.rel_value_us; 943 rd[0].expiration_time = ash->exp.rel_value_us;
933 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 944 ash->ns_qe = GNUNET_NAMESTORE_records_store(nsh,
934 &ash->identity, 945 &ash->identity,
935 label, 946 label,
936 1, 947 1,
937 rd, 948 rd,
938 &attr_store_cont, 949 &attr_store_cont,
939 ash); 950 ash);
940 GNUNET_free (buf); 951 GNUNET_free(buf);
941 GNUNET_free (label); 952 GNUNET_free(label);
942} 953}
943 954
944 955
@@ -949,16 +960,17 @@ attr_store_task (void *cls)
949 * @param sam the message to check 960 * @param sam the message to check
950 */ 961 */
951static int 962static int
952check_attribute_store_message (void *cls, 963check_attribute_store_message(void *cls,
953 const struct AttributeStoreMessage *sam) 964 const struct AttributeStoreMessage *sam)
954{ 965{
955 uint16_t size; 966 uint16_t size;
956 967
957 size = ntohs (sam->header.size); 968 size = ntohs(sam->header.size);
958 if (size <= sizeof (struct AttributeStoreMessage)) { 969 if (size <= sizeof(struct AttributeStoreMessage))
959 GNUNET_break (0); 970 {
960 return GNUNET_SYSERR; 971 GNUNET_break(0);
961 } 972 return GNUNET_SYSERR;
973 }
962 return GNUNET_OK; 974 return GNUNET_OK;
963} 975}
964 976
@@ -970,28 +982,29 @@ check_attribute_store_message (void *cls,
970 * @param sam the message to handle 982 * @param sam the message to handle
971 */ 983 */
972static void 984static void
973handle_attribute_store_message (void *cls, 985handle_attribute_store_message(void *cls,
974 const struct AttributeStoreMessage *sam) 986 const struct AttributeStoreMessage *sam)
975{ 987{
976 struct AttributeStoreHandle *ash; 988 struct AttributeStoreHandle *ash;
977 struct IdpClient *idp = cls; 989 struct IdpClient *idp = cls;
978 size_t data_len; 990 size_t data_len;
979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n");
980 991
981 data_len = ntohs (sam->attr_len); 992 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_STORE message\n");
993
994 data_len = ntohs(sam->attr_len);
982 995
983 ash = GNUNET_new (struct AttributeStoreHandle); 996 ash = GNUNET_new(struct AttributeStoreHandle);
984 ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&sam[1], data_len); 997 ash->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize((char *)&sam[1], data_len);
985 998
986 ash->r_id = ntohl (sam->id); 999 ash->r_id = ntohl(sam->id);
987 ash->identity = sam->identity; 1000 ash->identity = sam->identity;
988 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); 1001 ash->exp.rel_value_us = GNUNET_ntohll(sam->exp);
989 GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); 1002 GNUNET_CRYPTO_ecdsa_key_get_public(&sam->identity, &ash->identity_pkey);
990 1003
991 GNUNET_SERVICE_client_continue (idp->client); 1004 GNUNET_SERVICE_client_continue(idp->client);
992 ash->client = idp; 1005 ash->client = idp;
993 GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash); 1006 GNUNET_CONTAINER_DLL_insert(idp->store_op_head, idp->store_op_tail, ash);
994 GNUNET_SCHEDULER_add_now (&attr_store_task, ash); 1007 GNUNET_SCHEDULER_add_now(&attr_store_task, ash);
995} 1008}
996 1009
997 1010
@@ -1002,20 +1015,20 @@ handle_attribute_store_message (void *cls,
1002 * @param success the success status 1015 * @param success the success status
1003 */ 1016 */
1004static void 1017static void
1005send_delete_response (struct AttributeDeleteHandle *adh, int32_t success) 1018send_delete_response(struct AttributeDeleteHandle *adh, int32_t success)
1006{ 1019{
1007 struct GNUNET_MQ_Envelope *env; 1020 struct GNUNET_MQ_Envelope *env;
1008 struct SuccessResultMessage *acr_msg; 1021 struct SuccessResultMessage *acr_msg;
1009 1022
1010 GNUNET_CONTAINER_DLL_remove (adh->client->delete_op_head, 1023 GNUNET_CONTAINER_DLL_remove(adh->client->delete_op_head,
1011 adh->client->delete_op_tail, 1024 adh->client->delete_op_tail,
1012 adh); 1025 adh);
1013 1026
1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); 1027 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1015 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); 1028 env = GNUNET_MQ_msg(acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1016 acr_msg->id = htonl (adh->r_id); 1029 acr_msg->id = htonl(adh->r_id);
1017 acr_msg->op_result = htonl (success); 1030 acr_msg->op_result = htonl(success);
1018 GNUNET_MQ_send (adh->client->mq, env); 1031 GNUNET_MQ_send(adh->client->mq, env);
1019} 1032}
1020 1033
1021 1034
@@ -1030,39 +1043,41 @@ send_delete_response (struct AttributeDeleteHandle *adh, int32_t success)
1030 * @param rd record data 1043 * @param rd record data
1031 */ 1044 */
1032static void 1045static void
1033ticket_iter (void *cls, 1046ticket_iter(void *cls,
1034 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1047 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1035 const char *label, 1048 const char *label,
1036 unsigned int rd_count, 1049 unsigned int rd_count,
1037 const struct GNUNET_GNSRECORD_Data *rd) 1050 const struct GNUNET_GNSRECORD_Data *rd)
1038{ 1051{
1039 struct AttributeDeleteHandle *adh = cls; 1052 struct AttributeDeleteHandle *adh = cls;
1040 struct TicketRecordsEntry *le; 1053 struct TicketRecordsEntry *le;
1041 int has_changed = GNUNET_NO; 1054 int has_changed = GNUNET_NO;
1042 1055
1043 for (int i = 0; i < rd_count; i++) { 1056 for (int i = 0; i < rd_count; i++)
1044 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) 1057 {
1045 continue; 1058 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type)
1046 if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof (uint64_t))) 1059 continue;
1047 continue; 1060 if (0 != memcmp(rd[i].data, &adh->claim->id, sizeof(uint64_t)))
1048 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1061 continue;
1049 "Attribute to delete found (%s)\n", 1062 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1050 adh->label); 1063 "Attribute to delete found (%s)\n",
1051 has_changed = GNUNET_YES; 1064 adh->label);
1052 break; 1065 has_changed = GNUNET_YES;
1053 } 1066 break;
1054 if (GNUNET_YES == has_changed) { 1067 }
1055 le = GNUNET_new (struct TicketRecordsEntry); 1068 if (GNUNET_YES == has_changed)
1056 le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 1069 {
1057 le->data = GNUNET_malloc (le->data_size); 1070 le = GNUNET_new(struct TicketRecordsEntry);
1058 le->rd_count = rd_count; 1071 le->data_size = GNUNET_GNSRECORD_records_get_size(rd_count, rd);
1059 le->label = GNUNET_strdup (label); 1072 le->data = GNUNET_malloc(le->data_size);
1060 GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data); 1073 le->rd_count = rd_count;
1061 GNUNET_CONTAINER_DLL_insert (adh->tickets_to_update_head, 1074 le->label = GNUNET_strdup(label);
1062 adh->tickets_to_update_tail, 1075 GNUNET_GNSRECORD_records_serialize(rd_count, rd, le->data_size, le->data);
1063 le); 1076 GNUNET_CONTAINER_DLL_insert(adh->tickets_to_update_head,
1064 } 1077 adh->tickets_to_update_tail,
1065 GNUNET_NAMESTORE_zone_iterator_next (adh->ns_it, 1); 1078 le);
1079 }
1080 GNUNET_NAMESTORE_zone_iterator_next(adh->ns_it, 1);
1066} 1081}
1067 1082
1068 1083
@@ -1071,7 +1086,7 @@ ticket_iter (void *cls,
1071 * @param cls our deletion handle 1086 * @param cls our deletion handle
1072 */ 1087 */
1073static void 1088static void
1074update_tickets (void *cls); 1089update_tickets(void *cls);
1075 1090
1076 1091
1077/** 1092/**
@@ -1082,11 +1097,12 @@ update_tickets (void *cls);
1082 * @param emsg error message (NULL if success=GNUNET_OK) 1097 * @param emsg error message (NULL if success=GNUNET_OK)
1083 */ 1098 */
1084static void 1099static void
1085ticket_updated (void *cls, int32_t success, const char *emsg) 1100ticket_updated(void *cls, int32_t success, const char *emsg)
1086{ 1101{
1087 struct AttributeDeleteHandle *adh = cls; 1102 struct AttributeDeleteHandle *adh = cls;
1103
1088 adh->ns_qe = NULL; 1104 adh->ns_qe = NULL;
1089 GNUNET_SCHEDULER_add_now (&update_tickets, adh); 1105 GNUNET_SCHEDULER_add_now(&update_tickets, adh);
1090} 1106}
1091 1107
1092 1108
@@ -1098,55 +1114,58 @@ ticket_updated (void *cls, int32_t success, const char *emsg)
1098 * @param cls our attribute deletion handle 1114 * @param cls our attribute deletion handle
1099 */ 1115 */
1100static void 1116static void
1101update_tickets (void *cls) 1117update_tickets(void *cls)
1102{ 1118{
1103 struct AttributeDeleteHandle *adh = cls; 1119 struct AttributeDeleteHandle *adh = cls;
1104 struct TicketRecordsEntry *le; 1120 struct TicketRecordsEntry *le;
1105 if (NULL == adh->tickets_to_update_head) { 1121
1106 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1122 if (NULL == adh->tickets_to_update_head)
1107 "Finished updatding tickets, success\n"); 1123 {
1108 send_delete_response (adh, GNUNET_OK); 1124 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1109 cleanup_adh (adh); 1125 "Finished updatding tickets, success\n");
1110 return; 1126 send_delete_response(adh, GNUNET_OK);
1111 } 1127 cleanup_adh(adh);
1112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1128 return;
1113 "Updating %s\n", 1129 }
1114 adh->tickets_to_update_head->label); 1130 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1131 "Updating %s\n",
1132 adh->tickets_to_update_head->label);
1115 le = adh->tickets_to_update_head; 1133 le = adh->tickets_to_update_head;
1116 GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, 1134 GNUNET_CONTAINER_DLL_remove(adh->tickets_to_update_head,
1117 adh->tickets_to_update_tail, 1135 adh->tickets_to_update_tail,
1118 le); 1136 le);
1119 struct GNUNET_GNSRECORD_Data rd[le->rd_count]; 1137 struct GNUNET_GNSRECORD_Data rd[le->rd_count];
1120 struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1]; 1138 struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1];
1121 if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, 1139 if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize(le->data_size,
1122 le->data, 1140 le->data,
1123 le->rd_count, 1141 le->rd_count,
1124 rd)) 1142 rd))
1125 { 1143 {
1126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1144 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1127 "Unable to deserialize record data!\n"); 1145 "Unable to deserialize record data!\n");
1128 send_delete_response (adh, GNUNET_SYSERR); 1146 send_delete_response(adh, GNUNET_SYSERR);
1129 cleanup_adh (adh); 1147 cleanup_adh(adh);
1130 return; 1148 return;
1131 } 1149 }
1132 int j = 0; 1150 int j = 0;
1133 for (int i = 0; i < le->rd_count; i++) { 1151 for (int i = 0; i < le->rd_count; i++)
1134 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) 1152 {
1135 && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof (uint64_t)))) 1153 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type)
1136 continue; 1154 && (0 == memcmp(rd[i].data, &adh->claim->id, sizeof(uint64_t))))
1137 rd_new[j] = rd[i]; 1155 continue;
1138 j++; 1156 rd_new[j] = rd[i];
1139 } 1157 j++;
1140 adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 1158 }
1141 &adh->identity, 1159 adh->ns_qe = GNUNET_NAMESTORE_records_store(nsh,
1142 le->label, 1160 &adh->identity,
1143 j, 1161 le->label,
1144 rd_new, 1162 j,
1145 &ticket_updated, 1163 rd_new,
1146 adh); 1164 &ticket_updated,
1147 GNUNET_free (le->label); 1165 adh);
1148 GNUNET_free (le->data); 1166 GNUNET_free(le->label);
1149 GNUNET_free (le); 1167 GNUNET_free(le->data);
1168 GNUNET_free(le);
1150} 1169}
1151 1170
1152 1171
@@ -1156,11 +1175,12 @@ update_tickets (void *cls)
1156 * @param cls our attribute deletion handle 1175 * @param cls our attribute deletion handle
1157 */ 1176 */
1158static void 1177static void
1159ticket_iter_fin (void *cls) 1178ticket_iter_fin(void *cls)
1160{ 1179{
1161 struct AttributeDeleteHandle *adh = cls; 1180 struct AttributeDeleteHandle *adh = cls;
1181
1162 adh->ns_it = NULL; 1182 adh->ns_it = NULL;
1163 GNUNET_SCHEDULER_add_now (&update_tickets, adh); 1183 GNUNET_SCHEDULER_add_now(&update_tickets, adh);
1164} 1184}
1165 1185
1166 1186
@@ -1170,15 +1190,16 @@ ticket_iter_fin (void *cls)
1170 * @param cls our attribute deletion handle 1190 * @param cls our attribute deletion handle
1171 */ 1191 */
1172static void 1192static void
1173ticket_iter_err (void *cls) 1193ticket_iter_err(void *cls)
1174{ 1194{
1175 struct AttributeDeleteHandle *adh = cls; 1195 struct AttributeDeleteHandle *adh = cls;
1196
1176 adh->ns_it = NULL; 1197 adh->ns_it = NULL;
1177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1198 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1178 "Namestore error on delete %s\n", 1199 "Namestore error on delete %s\n",
1179 adh->label); 1200 adh->label);
1180 send_delete_response (adh, GNUNET_SYSERR); 1201 send_delete_response(adh, GNUNET_SYSERR);
1181 cleanup_adh (adh); 1202 cleanup_adh(adh);
1182} 1203}
1183 1204
1184 1205
@@ -1189,17 +1210,18 @@ ticket_iter_err (void *cls)
1189 * @param cls attribute deletion handle 1210 * @param cls attribute deletion handle
1190 */ 1211 */
1191static void 1212static void
1192start_ticket_update (void *cls) 1213start_ticket_update(void *cls)
1193{ 1214{
1194 struct AttributeDeleteHandle *adh = cls; 1215 struct AttributeDeleteHandle *adh = cls;
1195 adh->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, 1216
1196 &adh->identity, 1217 adh->ns_it = GNUNET_NAMESTORE_zone_iteration_start(nsh,
1197 &ticket_iter_err, 1218 &adh->identity,
1198 adh, 1219 &ticket_iter_err,
1199 &ticket_iter, 1220 adh,
1200 adh, 1221 &ticket_iter,
1201 &ticket_iter_fin, 1222 adh,
1202 adh); 1223 &ticket_iter_fin,
1224 adh);
1203} 1225}
1204 1226
1205 1227
@@ -1211,20 +1233,22 @@ start_ticket_update (void *cls)
1211 * @param emsg error message (NULL if success=GNUNET_OK) 1233 * @param emsg error message (NULL if success=GNUNET_OK)
1212 */ 1234 */
1213static void 1235static void
1214attr_delete_cont (void *cls, int32_t success, const char *emsg) 1236attr_delete_cont(void *cls, int32_t success, const char *emsg)
1215{ 1237{
1216 struct AttributeDeleteHandle *adh = cls; 1238 struct AttributeDeleteHandle *adh = cls;
1239
1217 adh->ns_qe = NULL; 1240 adh->ns_qe = NULL;
1218 if (GNUNET_SYSERR == success) { 1241 if (GNUNET_SYSERR == success)
1219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1242 {
1220 "Error deleting attribute %s\n", 1243 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1221 adh->label); 1244 "Error deleting attribute %s\n",
1222 send_delete_response (adh, GNUNET_SYSERR); 1245 adh->label);
1223 cleanup_adh (adh); 1246 send_delete_response(adh, GNUNET_SYSERR);
1224 return; 1247 cleanup_adh(adh);
1225 } 1248 return;
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); 1249 }
1227 GNUNET_SCHEDULER_add_now (&start_ticket_update, adh); 1250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n");
1251 GNUNET_SCHEDULER_add_now(&start_ticket_update, adh);
1228} 1252}
1229 1253
1230 1254
@@ -1235,16 +1259,17 @@ attr_delete_cont (void *cls, int32_t success, const char *emsg)
1235 * @dam message to check 1259 * @dam message to check
1236 */ 1260 */
1237static int 1261static int
1238check_attribute_delete_message (void *cls, 1262check_attribute_delete_message(void *cls,
1239 const struct AttributeDeleteMessage *dam) 1263 const struct AttributeDeleteMessage *dam)
1240{ 1264{
1241 uint16_t size; 1265 uint16_t size;
1242 1266
1243 size = ntohs (dam->header.size); 1267 size = ntohs(dam->header.size);
1244 if (size <= sizeof (struct AttributeDeleteMessage)) { 1268 if (size <= sizeof(struct AttributeDeleteMessage))
1245 GNUNET_break (0); 1269 {
1246 return GNUNET_SYSERR; 1270 GNUNET_break(0);
1247 } 1271 return GNUNET_SYSERR;
1272 }
1248 return GNUNET_OK; 1273 return GNUNET_OK;
1249} 1274}
1250 1275
@@ -1256,39 +1281,40 @@ check_attribute_delete_message (void *cls,
1256 * @param dam deletion message 1281 * @param dam deletion message
1257 */ 1282 */
1258static void 1283static void
1259handle_attribute_delete_message (void *cls, 1284handle_attribute_delete_message(void *cls,
1260 const struct AttributeDeleteMessage *dam) 1285 const struct AttributeDeleteMessage *dam)
1261{ 1286{
1262 struct AttributeDeleteHandle *adh; 1287 struct AttributeDeleteHandle *adh;
1263 struct IdpClient *idp = cls; 1288 struct IdpClient *idp = cls;
1264 size_t data_len; 1289 size_t data_len;
1265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n");
1266 1290
1267 data_len = ntohs (dam->attr_len); 1291 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received ATTRIBUTE_DELETE message\n");
1268 1292
1269 adh = GNUNET_new (struct AttributeDeleteHandle); 1293 data_len = ntohs(dam->attr_len);
1270 adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize ((char *)&dam[1], data_len);
1271 1294
1272 adh->r_id = ntohl (dam->id); 1295 adh = GNUNET_new(struct AttributeDeleteHandle);
1296 adh->claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize((char *)&dam[1], data_len);
1297
1298 adh->r_id = ntohl(dam->id);
1273 adh->identity = dam->identity; 1299 adh->identity = dam->identity;
1274 adh->label 1300 adh->label
1275 = GNUNET_STRINGS_data_to_string_alloc (&adh->claim->id, sizeof (uint64_t)); 1301 = GNUNET_STRINGS_data_to_string_alloc(&adh->claim->id, sizeof(uint64_t));
1276 GNUNET_SERVICE_client_continue (idp->client); 1302 GNUNET_SERVICE_client_continue(idp->client);
1277 adh->client = idp; 1303 adh->client = idp;
1278 GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh); 1304 GNUNET_CONTAINER_DLL_insert(idp->delete_op_head, idp->delete_op_tail, adh);
1279 adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 1305 adh->ns_qe = GNUNET_NAMESTORE_records_store(nsh,
1280 &adh->identity, 1306 &adh->identity,
1281 adh->label, 1307 adh->label,
1282 0, 1308 0,
1283 NULL, 1309 NULL,
1284 &attr_delete_cont, 1310 &attr_delete_cont,
1285 adh); 1311 adh);
1286} 1312}
1287 1313
1288 1314
1289/************************************************* 1315/*************************************************
1290 * Attrubute iteration 1316* Attrubute iteration
1291 *************************************************/ 1317*************************************************/
1292 1318
1293 1319
1294/** 1320/**
@@ -1297,21 +1323,21 @@ handle_attribute_delete_message (void *cls,
1297 * @param cls our iterator handle 1323 * @param cls our iterator handle
1298 */ 1324 */
1299static void 1325static void
1300attr_iter_finished (void *cls) 1326attr_iter_finished(void *cls)
1301{ 1327{
1302 struct AttributeIterator *ai = cls; 1328 struct AttributeIterator *ai = cls;
1303 struct GNUNET_MQ_Envelope *env; 1329 struct GNUNET_MQ_Envelope *env;
1304 struct AttributeResultMessage *arm; 1330 struct AttributeResultMessage *arm;
1305 1331
1306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); 1332 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n");
1307 env = GNUNET_MQ_msg (arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); 1333 env = GNUNET_MQ_msg(arm, GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1308 arm->id = htonl (ai->request_id); 1334 arm->id = htonl(ai->request_id);
1309 arm->attr_len = htons (0); 1335 arm->attr_len = htons(0);
1310 GNUNET_MQ_send (ai->client->mq, env); 1336 GNUNET_MQ_send(ai->client->mq, env);
1311 GNUNET_CONTAINER_DLL_remove (ai->client->attr_iter_head, 1337 GNUNET_CONTAINER_DLL_remove(ai->client->attr_iter_head,
1312 ai->client->attr_iter_tail, 1338 ai->client->attr_iter_tail,
1313 ai); 1339 ai);
1314 GNUNET_free (ai); 1340 GNUNET_free(ai);
1315} 1341}
1316 1342
1317/** 1343/**
@@ -1320,12 +1346,12 @@ attr_iter_finished (void *cls)
1320 * @param cls our attribute iteration handle 1346 * @param cls our attribute iteration handle
1321 */ 1347 */
1322static void 1348static void
1323attr_iter_error (void *cls) 1349attr_iter_error(void *cls)
1324{ 1350{
1325 struct AttributeIterator *ai = cls; 1351 struct AttributeIterator *ai = cls;
1326 1352
1327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n"); 1353 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n");
1328 attr_iter_finished (ai); 1354 attr_iter_finished(ai);
1329} 1355}
1330 1356
1331 1357
@@ -1339,37 +1365,39 @@ attr_iter_error (void *cls)
1339 * @param rd records 1365 * @param rd records
1340 */ 1366 */
1341static void 1367static void
1342attr_iter_cb (void *cls, 1368attr_iter_cb(void *cls,
1343 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1369 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1344 const char *label, 1370 const char *label,
1345 unsigned int rd_count, 1371 unsigned int rd_count,
1346 const struct GNUNET_GNSRECORD_Data *rd) 1372 const struct GNUNET_GNSRECORD_Data *rd)
1347{ 1373{
1348 struct AttributeIterator *ai = cls; 1374 struct AttributeIterator *ai = cls;
1349 struct AttributeResultMessage *arm; 1375 struct AttributeResultMessage *arm;
1350 struct GNUNET_MQ_Envelope *env; 1376 struct GNUNET_MQ_Envelope *env;
1351 char *data_tmp; 1377 char *data_tmp;
1352 1378
1353 if (rd_count != 1) { 1379 if (rd_count != 1)
1354 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1380 {
1355 return; 1381 GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1);
1356 } 1382 return;
1357 1383 }
1358 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type) { 1384
1359 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1385 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR != rd->record_type)
1360 return; 1386 {
1361 } 1387 GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1);
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label); 1388 return;
1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n"); 1389 }
1364 env = GNUNET_MQ_msg_extra (arm, 1390 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found attribute under: %s\n", label);
1365 rd->data_size, 1391 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ATTRIBUTE_RESULT message\n");
1366 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); 1392 env = GNUNET_MQ_msg_extra(arm,
1367 arm->id = htonl (ai->request_id); 1393 rd->data_size,
1368 arm->attr_len = htons (rd->data_size); 1394 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT);
1369 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); 1395 arm->id = htonl(ai->request_id);
1396 arm->attr_len = htons(rd->data_size);
1397 GNUNET_CRYPTO_ecdsa_key_get_public(zone, &arm->identity);
1370 data_tmp = (char *)&arm[1]; 1398 data_tmp = (char *)&arm[1];
1371 GNUNET_memcpy (data_tmp, rd->data, rd->data_size); 1399 GNUNET_memcpy(data_tmp, rd->data, rd->data_size);
1372 GNUNET_MQ_send (ai->client->mq, env); 1400 GNUNET_MQ_send(ai->client->mq, env);
1373} 1401}
1374 1402
1375 1403
@@ -1380,29 +1408,29 @@ attr_iter_cb (void *cls,
1380 * @param ais_msg the iteration message to start 1408 * @param ais_msg the iteration message to start
1381 */ 1409 */
1382static void 1410static void
1383handle_iteration_start (void *cls, 1411handle_iteration_start(void *cls,
1384 const struct AttributeIterationStartMessage *ais_msg) 1412 const struct AttributeIterationStartMessage *ais_msg)
1385{ 1413{
1386 struct IdpClient *idp = cls; 1414 struct IdpClient *idp = cls;
1387 struct AttributeIterator *ai; 1415 struct AttributeIterator *ai;
1388 1416
1389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1417 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1390 "Received ATTRIBUTE_ITERATION_START message\n"); 1418 "Received ATTRIBUTE_ITERATION_START message\n");
1391 ai = GNUNET_new (struct AttributeIterator); 1419 ai = GNUNET_new(struct AttributeIterator);
1392 ai->request_id = ntohl (ais_msg->id); 1420 ai->request_id = ntohl(ais_msg->id);
1393 ai->client = idp; 1421 ai->client = idp;
1394 ai->identity = ais_msg->identity; 1422 ai->identity = ais_msg->identity;
1395 1423
1396 GNUNET_CONTAINER_DLL_insert (idp->attr_iter_head, idp->attr_iter_tail, ai); 1424 GNUNET_CONTAINER_DLL_insert(idp->attr_iter_head, idp->attr_iter_tail, ai);
1397 ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start (nsh, 1425 ai->ns_it = GNUNET_NAMESTORE_zone_iteration_start(nsh,
1398 &ai->identity, 1426 &ai->identity,
1399 &attr_iter_error, 1427 &attr_iter_error,
1400 ai, 1428 ai,
1401 &attr_iter_cb, 1429 &attr_iter_cb,
1402 ai, 1430 ai,
1403 &attr_iter_finished, 1431 &attr_iter_finished,
1404 ai); 1432 ai);
1405 GNUNET_SERVICE_client_continue (idp->client); 1433 GNUNET_SERVICE_client_continue(idp->client);
1406} 1434}
1407 1435
1408 1436
@@ -1413,28 +1441,29 @@ handle_iteration_start (void *cls,
1413 * @param ais_msg the stop message 1441 * @param ais_msg the stop message
1414 */ 1442 */
1415static void 1443static void
1416handle_iteration_stop (void *cls, 1444handle_iteration_stop(void *cls,
1417 const struct AttributeIterationStopMessage *ais_msg) 1445 const struct AttributeIterationStopMessage *ais_msg)
1418{ 1446{
1419 struct IdpClient *idp = cls; 1447 struct IdpClient *idp = cls;
1420 struct AttributeIterator *ai; 1448 struct AttributeIterator *ai;
1421 uint32_t rid; 1449 uint32_t rid;
1422 1450
1423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1451 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1424 "Received `%s' message\n", 1452 "Received `%s' message\n",
1425 "ATTRIBUTE_ITERATION_STOP"); 1453 "ATTRIBUTE_ITERATION_STOP");
1426 rid = ntohl (ais_msg->id); 1454 rid = ntohl(ais_msg->id);
1427 for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) 1455 for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next)
1428 if (ai->request_id == rid) 1456 if (ai->request_id == rid)
1429 break; 1457 break;
1430 if (NULL == ai) { 1458 if (NULL == ai)
1431 GNUNET_break (0); 1459 {
1432 GNUNET_SERVICE_client_drop (idp->client); 1460 GNUNET_break(0);
1433 return; 1461 GNUNET_SERVICE_client_drop(idp->client);
1434 } 1462 return;
1435 GNUNET_CONTAINER_DLL_remove (idp->attr_iter_head, idp->attr_iter_tail, ai); 1463 }
1436 GNUNET_free (ai); 1464 GNUNET_CONTAINER_DLL_remove(idp->attr_iter_head, idp->attr_iter_tail, ai);
1437 GNUNET_SERVICE_client_continue (idp->client); 1465 GNUNET_free(ai);
1466 GNUNET_SERVICE_client_continue(idp->client);
1438} 1467}
1439 1468
1440 1469
@@ -1445,31 +1474,32 @@ handle_iteration_stop (void *cls,
1445 * @param ais_msg the message 1474 * @param ais_msg the message
1446 */ 1475 */
1447static void 1476static void
1448handle_iteration_next (void *cls, 1477handle_iteration_next(void *cls,
1449 const struct AttributeIterationNextMessage *ais_msg) 1478 const struct AttributeIterationNextMessage *ais_msg)
1450{ 1479{
1451 struct IdpClient *idp = cls; 1480 struct IdpClient *idp = cls;
1452 struct AttributeIterator *ai; 1481 struct AttributeIterator *ai;
1453 uint32_t rid; 1482 uint32_t rid;
1454 1483
1455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1484 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1456 "Received ATTRIBUTE_ITERATION_NEXT message\n"); 1485 "Received ATTRIBUTE_ITERATION_NEXT message\n");
1457 rid = ntohl (ais_msg->id); 1486 rid = ntohl(ais_msg->id);
1458 for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next) 1487 for (ai = idp->attr_iter_head; NULL != ai; ai = ai->next)
1459 if (ai->request_id == rid) 1488 if (ai->request_id == rid)
1460 break; 1489 break;
1461 if (NULL == ai) { 1490 if (NULL == ai)
1462 GNUNET_break (0); 1491 {
1463 GNUNET_SERVICE_client_drop (idp->client); 1492 GNUNET_break(0);
1464 return; 1493 GNUNET_SERVICE_client_drop(idp->client);
1465 } 1494 return;
1466 GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1); 1495 }
1467 GNUNET_SERVICE_client_continue (idp->client); 1496 GNUNET_NAMESTORE_zone_iterator_next(ai->ns_it, 1);
1497 GNUNET_SERVICE_client_continue(idp->client);
1468} 1498}
1469 1499
1470/****************************************************** 1500/******************************************************
1471 * Ticket iteration 1501* Ticket iteration
1472 ******************************************************/ 1502******************************************************/
1473 1503
1474/** 1504/**
1475 * Got a ticket. Return to client 1505 * Got a ticket. Return to client
@@ -1478,26 +1508,29 @@ handle_iteration_next (void *cls,
1478 * @param ticket the ticket 1508 * @param ticket the ticket
1479 */ 1509 */
1480static void 1510static void
1481ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket) 1511ticket_iter_cb(void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
1482{ 1512{
1483 struct TicketIteration *ti = cls; 1513 struct TicketIteration *ti = cls;
1484 struct GNUNET_MQ_Envelope *env; 1514 struct GNUNET_MQ_Envelope *env;
1485 struct TicketResultMessage *trm; 1515 struct TicketResultMessage *trm;
1486 1516
1487 env = GNUNET_MQ_msg (trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT); 1517 env = GNUNET_MQ_msg(trm, GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_RESULT);
1488 if (NULL == ticket) {
1489 /* send empty response to indicate end of list */
1490 GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head,
1491 ti->client->ticket_iter_tail,
1492 ti);
1493 } else {
1494 trm->ticket = *ticket;
1495 }
1496 trm->id = htonl (ti->r_id);
1497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
1498 GNUNET_MQ_send (ti->client->mq, env);
1499 if (NULL == ticket) 1518 if (NULL == ticket)
1500 GNUNET_free (ti); 1519 {
1520 /* send empty response to indicate end of list */
1521 GNUNET_CONTAINER_DLL_remove(ti->client->ticket_iter_head,
1522 ti->client->ticket_iter_tail,
1523 ti);
1524 }
1525 else
1526 {
1527 trm->ticket = *ticket;
1528 }
1529 trm->id = htonl(ti->r_id);
1530 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending TICKET_RESULT message\n");
1531 GNUNET_MQ_send(ti->client->mq, env);
1532 if (NULL == ticket)
1533 GNUNET_free(ti);
1501} 1534}
1502 1535
1503 1536
@@ -1508,25 +1541,25 @@ ticket_iter_cb (void *cls, struct GNUNET_RECLAIM_Ticket *ticket)
1508 * @param tis_msg the iteration request message 1541 * @param tis_msg the iteration request message
1509 */ 1542 */
1510static void 1543static void
1511handle_ticket_iteration_start ( 1544handle_ticket_iteration_start(
1512 void *cls, 1545 void *cls,
1513 const struct TicketIterationStartMessage *tis_msg) 1546 const struct TicketIterationStartMessage *tis_msg)
1514{ 1547{
1515 struct IdpClient *client = cls; 1548 struct IdpClient *client = cls;
1516 struct TicketIteration *ti; 1549 struct TicketIteration *ti;
1517 1550
1518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1551 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1519 "Received TICKET_ITERATION_START message\n"); 1552 "Received TICKET_ITERATION_START message\n");
1520 ti = GNUNET_new (struct TicketIteration); 1553 ti = GNUNET_new(struct TicketIteration);
1521 ti->r_id = ntohl (tis_msg->id); 1554 ti->r_id = ntohl(tis_msg->id);
1522 ti->client = client; 1555 ti->client = client;
1523 1556
1524 GNUNET_CONTAINER_DLL_insert (client->ticket_iter_head, 1557 GNUNET_CONTAINER_DLL_insert(client->ticket_iter_head,
1525 client->ticket_iter_tail, 1558 client->ticket_iter_tail,
1526 ti); 1559 ti);
1527 ti->iter 1560 ti->iter
1528 = RECLAIM_TICKETS_iteration_start (&tis_msg->identity, &ticket_iter_cb, ti); 1561 = RECLAIM_TICKETS_iteration_start(&tis_msg->identity, &ticket_iter_cb, ti);
1529 GNUNET_SERVICE_client_continue (client->client); 1562 GNUNET_SERVICE_client_continue(client->client);
1530} 1563}
1531 1564
1532 1565
@@ -1537,31 +1570,32 @@ handle_ticket_iteration_start (
1537 * @param tis_msg the stop message 1570 * @param tis_msg the stop message
1538 */ 1571 */
1539static void 1572static void
1540handle_ticket_iteration_stop (void *cls, 1573handle_ticket_iteration_stop(void *cls,
1541 const struct TicketIterationStopMessage *tis_msg) 1574 const struct TicketIterationStopMessage *tis_msg)
1542{ 1575{
1543 struct IdpClient *client = cls; 1576 struct IdpClient *client = cls;
1544 struct TicketIteration *ti; 1577 struct TicketIteration *ti;
1545 uint32_t rid; 1578 uint32_t rid;
1546 1579
1547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1548 "Received `%s' message\n", 1581 "Received `%s' message\n",
1549 "TICKET_ITERATION_STOP"); 1582 "TICKET_ITERATION_STOP");
1550 rid = ntohl (tis_msg->id); 1583 rid = ntohl(tis_msg->id);
1551 for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) 1584 for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next)
1552 if (ti->r_id == rid) 1585 if (ti->r_id == rid)
1553 break; 1586 break;
1554 if (NULL == ti) { 1587 if (NULL == ti)
1555 GNUNET_break (0); 1588 {
1556 GNUNET_SERVICE_client_drop (client->client); 1589 GNUNET_break(0);
1557 return; 1590 GNUNET_SERVICE_client_drop(client->client);
1558 } 1591 return;
1559 RECLAIM_TICKETS_iteration_stop (ti->iter); 1592 }
1560 GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, 1593 RECLAIM_TICKETS_iteration_stop(ti->iter);
1561 client->ticket_iter_tail, 1594 GNUNET_CONTAINER_DLL_remove(client->ticket_iter_head,
1562 ti); 1595 client->ticket_iter_tail,
1563 GNUNET_free (ti); 1596 ti);
1564 GNUNET_SERVICE_client_continue (client->client); 1597 GNUNET_free(ti);
1598 GNUNET_SERVICE_client_continue(client->client);
1565} 1599}
1566 1600
1567 1601
@@ -1572,26 +1606,27 @@ handle_ticket_iteration_stop (void *cls,
1572 * @param tis_msg the message 1606 * @param tis_msg the message
1573 */ 1607 */
1574static void 1608static void
1575handle_ticket_iteration_next (void *cls, 1609handle_ticket_iteration_next(void *cls,
1576 const struct TicketIterationNextMessage *tis_msg) 1610 const struct TicketIterationNextMessage *tis_msg)
1577{ 1611{
1578 struct IdpClient *client = cls; 1612 struct IdpClient *client = cls;
1579 struct TicketIteration *ti; 1613 struct TicketIteration *ti;
1580 uint32_t rid; 1614 uint32_t rid;
1581 1615
1582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1616 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1583 "Received TICKET_ITERATION_NEXT message\n"); 1617 "Received TICKET_ITERATION_NEXT message\n");
1584 rid = ntohl (tis_msg->id); 1618 rid = ntohl(tis_msg->id);
1585 for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next) 1619 for (ti = client->ticket_iter_head; NULL != ti; ti = ti->next)
1586 if (ti->r_id == rid) 1620 if (ti->r_id == rid)
1587 break; 1621 break;
1588 if (NULL == ti) { 1622 if (NULL == ti)
1589 GNUNET_break (0); 1623 {
1590 GNUNET_SERVICE_client_drop (client->client); 1624 GNUNET_break(0);
1591 return; 1625 GNUNET_SERVICE_client_drop(client->client);
1592 } 1626 return;
1593 RECLAIM_TICKETS_iteration_next (ti->iter); 1627 }
1594 GNUNET_SERVICE_client_continue (client->client); 1628 RECLAIM_TICKETS_iteration_next(ti->iter);
1629 GNUNET_SERVICE_client_continue(client->client);
1595} 1630}
1596 1631
1597 1632
@@ -1603,26 +1638,28 @@ handle_ticket_iteration_next (void *cls,
1603 * @param server the service handle 1638 * @param server the service handle
1604 */ 1639 */
1605static void 1640static void
1606run (void *cls, 1641run(void *cls,
1607 const struct GNUNET_CONFIGURATION_Handle *c, 1642 const struct GNUNET_CONFIGURATION_Handle *c,
1608 struct GNUNET_SERVICE_Handle *server) 1643 struct GNUNET_SERVICE_Handle *server)
1609{ 1644{
1610 cfg = c; 1645 cfg = c;
1611 1646
1612 if (GNUNET_OK != RECLAIM_TICKETS_init (cfg)) { 1647 if (GNUNET_OK != RECLAIM_TICKETS_init(cfg))
1613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1648 {
1614 "Unable to initialize TICKETS subsystem.\n"); 1649 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1615 GNUNET_SCHEDULER_shutdown (); 1650 "Unable to initialize TICKETS subsystem.\n");
1616 return; 1651 GNUNET_SCHEDULER_shutdown();
1617 } 1652 return;
1653 }
1618 // Connect to identity and namestore services 1654 // Connect to identity and namestore services
1619 nsh = GNUNET_NAMESTORE_connect (cfg); 1655 nsh = GNUNET_NAMESTORE_connect(cfg);
1620 if (NULL == nsh) { 1656 if (NULL == nsh)
1621 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 1657 {
1622 "error connecting to namestore"); 1658 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
1623 } 1659 "error connecting to namestore");
1624 1660 }
1625 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1661
1662 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
1626} 1663}
1627 1664
1628 1665
@@ -1634,16 +1671,17 @@ run (void *cls,
1634 * @param app_ctx @a client 1671 * @param app_ctx @a client
1635 */ 1672 */
1636static void 1673static void
1637client_disconnect_cb (void *cls, 1674client_disconnect_cb(void *cls,
1638 struct GNUNET_SERVICE_Client *client, 1675 struct GNUNET_SERVICE_Client *client,
1639 void *app_ctx) 1676 void *app_ctx)
1640{ 1677{
1641 struct IdpClient *idp = app_ctx; 1678 struct IdpClient *idp = app_ctx;
1642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 1679
1643 GNUNET_CONTAINER_DLL_remove (client_list_head, 1680 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1644 client_list_tail, 1681 GNUNET_CONTAINER_DLL_remove(client_list_head,
1645 idp); 1682 client_list_tail,
1646 cleanup_client (idp); 1683 idp);
1684 cleanup_client(idp);
1647} 1685}
1648 1686
1649 1687
@@ -1656,18 +1694,19 @@ client_disconnect_cb (void *cls,
1656 * @return internal namestore client structure for this client 1694 * @return internal namestore client structure for this client
1657 */ 1695 */
1658static void * 1696static void *
1659client_connect_cb (void *cls, 1697client_connect_cb(void *cls,
1660 struct GNUNET_SERVICE_Client *client, 1698 struct GNUNET_SERVICE_Client *client,
1661 struct GNUNET_MQ_Handle *mq) 1699 struct GNUNET_MQ_Handle *mq)
1662{ 1700{
1663 struct IdpClient *idp; 1701 struct IdpClient *idp;
1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client); 1702
1665 idp = GNUNET_new (struct IdpClient); 1703 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1704 idp = GNUNET_new(struct IdpClient);
1666 idp->client = client; 1705 idp->client = client;
1667 idp->mq = mq; 1706 idp->mq = mq;
1668 GNUNET_CONTAINER_DLL_insert (client_list_head, 1707 GNUNET_CONTAINER_DLL_insert(client_list_head,
1669 client_list_tail, 1708 client_list_tail,
1670 idp); 1709 idp);
1671 return idp; 1710 return idp;
1672} 1711}
1673 1712
@@ -1675,57 +1714,57 @@ client_connect_cb (void *cls,
1675/** 1714/**
1676 * Define "main" method using service macro. 1715 * Define "main" method using service macro.
1677 */ 1716 */
1678GNUNET_SERVICE_MAIN ( 1717GNUNET_SERVICE_MAIN(
1679 "reclaim", 1718 "reclaim",
1680 GNUNET_SERVICE_OPTION_NONE, 1719 GNUNET_SERVICE_OPTION_NONE,
1681 &run, 1720 &run,
1682 &client_connect_cb, 1721 &client_connect_cb,
1683 &client_disconnect_cb, 1722 &client_disconnect_cb,
1684 NULL, 1723 NULL,
1685 GNUNET_MQ_hd_var_size (attribute_store_message, 1724 GNUNET_MQ_hd_var_size(attribute_store_message,
1686 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, 1725 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE,
1687 struct AttributeStoreMessage, 1726 struct AttributeStoreMessage,
1688 NULL), 1727 NULL),
1689 GNUNET_MQ_hd_var_size (attribute_delete_message, 1728 GNUNET_MQ_hd_var_size(attribute_delete_message,
1690 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, 1729 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE,
1691 struct AttributeDeleteMessage, 1730 struct AttributeDeleteMessage,
1692 NULL), 1731 NULL),
1693 GNUNET_MQ_hd_fixed_size ( 1732 GNUNET_MQ_hd_fixed_size(
1694 iteration_start, 1733 iteration_start,
1695 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, 1734 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,
1696 struct AttributeIterationStartMessage, 1735 struct AttributeIterationStartMessage,
1697 NULL), 1736 NULL),
1698 GNUNET_MQ_hd_fixed_size (iteration_next, 1737 GNUNET_MQ_hd_fixed_size(iteration_next,
1699 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT, 1738 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_NEXT,
1700 struct AttributeIterationNextMessage, 1739 struct AttributeIterationNextMessage,
1701 NULL), 1740 NULL),
1702 GNUNET_MQ_hd_fixed_size (iteration_stop, 1741 GNUNET_MQ_hd_fixed_size(iteration_stop,
1703 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP, 1742 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_STOP,
1704 struct AttributeIterationStopMessage, 1743 struct AttributeIterationStopMessage,
1705 NULL), 1744 NULL),
1706 GNUNET_MQ_hd_var_size (issue_ticket_message, 1745 GNUNET_MQ_hd_var_size(issue_ticket_message,
1707 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET, 1746 GNUNET_MESSAGE_TYPE_RECLAIM_ISSUE_TICKET,
1708 struct IssueTicketMessage, 1747 struct IssueTicketMessage,
1709 NULL), 1748 NULL),
1710 GNUNET_MQ_hd_var_size (consume_ticket_message, 1749 GNUNET_MQ_hd_var_size(consume_ticket_message,
1711 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET, 1750 GNUNET_MESSAGE_TYPE_RECLAIM_CONSUME_TICKET,
1712 struct ConsumeTicketMessage, 1751 struct ConsumeTicketMessage,
1713 NULL), 1752 NULL),
1714 GNUNET_MQ_hd_fixed_size (ticket_iteration_start, 1753 GNUNET_MQ_hd_fixed_size(ticket_iteration_start,
1715 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START, 1754 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_START,
1716 struct TicketIterationStartMessage, 1755 struct TicketIterationStartMessage,
1717 NULL), 1756 NULL),
1718 GNUNET_MQ_hd_fixed_size (ticket_iteration_next, 1757 GNUNET_MQ_hd_fixed_size(ticket_iteration_next,
1719 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT, 1758 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_NEXT,
1720 struct TicketIterationNextMessage, 1759 struct TicketIterationNextMessage,
1721 NULL), 1760 NULL),
1722 GNUNET_MQ_hd_fixed_size (ticket_iteration_stop, 1761 GNUNET_MQ_hd_fixed_size(ticket_iteration_stop,
1723 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP, 1762 GNUNET_MESSAGE_TYPE_RECLAIM_TICKET_ITERATION_STOP,
1724 struct TicketIterationStopMessage, 1763 struct TicketIterationStopMessage,
1725 NULL), 1764 NULL),
1726 GNUNET_MQ_hd_var_size (revoke_ticket_message, 1765 GNUNET_MQ_hd_var_size(revoke_ticket_message,
1727 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET, 1766 GNUNET_MESSAGE_TYPE_RECLAIM_REVOKE_TICKET,
1728 struct RevokeTicketMessage, 1767 struct RevokeTicketMessage,
1729 NULL), 1768 NULL),
1730 GNUNET_MQ_handler_end ()); 1769 GNUNET_MQ_handler_end());
1731/* end of gnunet-service-reclaim.c */ 1770/* end of gnunet-service-reclaim.c */