aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gnunet/gnunet_chat_lib.h49
-rw-r--r--src/gnunet_chat_handle.h11
-rw-r--r--src/gnunet_chat_lib.c177
-rw-r--r--src/gnunet_chat_lib_intern.c476
4 files changed, 694 insertions, 19 deletions
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
index 574f661..3958dba 100644
--- a/include/gnunet/gnunet_chat_lib.h
+++ b/include/gnunet/gnunet_chat_lib.h
@@ -195,7 +195,7 @@ typedef enum GNUNET_GenericReturnValue
195 * Iterator over attributes of a specific chat handle. 195 * Iterator over attributes of a specific chat handle.
196 * 196 *
197 * @param[in,out] cls Closure from #GNUNET_CHAT_get_attributes 197 * @param[in,out] cls Closure from #GNUNET_CHAT_get_attributes
198 * @param[in] handle Chat handle 198 * @param[in,out] handle Chat handle
199 * @param[in] name Attribute name 199 * @param[in] name Attribute name
200 * @param[in] value Attribute value 200 * @param[in] value Attribute value
201 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 201 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
@@ -516,11 +516,11 @@ void
516GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, 516GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
517 const char *name, 517 const char *name,
518 const char *value, 518 const char *value,
519 const struct GNUNET_TIME_Relative *expires); 519 struct GNUNET_TIME_Relative expires);
520 520
521/** 521/**
522 * Deletes an attribute of a chat handle for related communication under a given 522 * Deletes an attribute of a chat <i>handle</i> for related communication
523 * <i>name</i>. 523 * under a given <i>name</i>.
524 * 524 *
525 * @param[in,out] handle Chat handle 525 * @param[in,out] handle Chat handle
526 * @param[in] name Attribute name 526 * @param[in] name Attribute name
@@ -543,6 +543,47 @@ GNUNET_CHAT_get_attributes (struct GNUNET_CHAT_Handle *handle,
543 void *cls); 543 void *cls);
544 544
545/** 545/**
546 * Share an attribute of a chat <i>handle</i> under a given <i>name</i>
547 * with a specific chat <i>contact</i>.
548 *
549 * @param[in,out] handle Chat handle
550 * @param[in,out] contact Chat contact
551 * @param[in] name Attribute name
552 */
553void
554GNUNET_CHAT_share_attribute_with (struct GNUNET_CHAT_Handle *handle,
555 struct GNUNET_CHAT_Contact *contact,
556 const char *name);
557
558/**
559 * Unshare an attribute of a chat <i>handle</i> under a given <i>name</i>
560 * from a specific chat <i>contact</i>.
561 *
562 * @param[in,out] handle Chat handle
563 * @param[in,out] contact Chat contact
564 * @param[in] name Attribute name
565 */
566void
567GNUNET_CHAT_unshare_attribute_from (struct GNUNET_CHAT_Handle *handle,
568 struct GNUNET_CHAT_Contact *contact,
569 const char *name);
570
571/**
572 * Calls an optional <i>callback</i> for each attribute of a given chat
573 * <i>handle</i> shared with a specific chat <i>contact</i>.
574 *
575 * @param[in,out] handle Chat handle
576 * @param[in] contact Chat contact
577 * @param[in] callback Callback for attribute iteration (optional)
578 * @param[in,out] cls Closure for attribute iteration (optional)
579 */
580void
581GNUNET_CHAT_get_shared_attributes (struct GNUNET_CHAT_Handle *handle,
582 const struct GNUNET_CHAT_Contact *contact,
583 GNUNET_CHAT_ContactAttributeCallback callback,
584 void *cls);
585
586/**
546 * Convert an UTF-8 String to a chat URI which will be newly allocated. 587 * Convert an UTF-8 String to a chat URI which will be newly allocated.
547 * 588 *
548 * @param[in] uri UTF-8 string to parse 589 * @param[in] uri UTF-8 string to parse
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 677c153..30c14ad 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -94,8 +94,10 @@ struct GNUNET_CHAT_UriLookups
94struct GNUNET_CHAT_AttributeProcess 94struct GNUNET_CHAT_AttributeProcess
95{ 95{
96 struct GNUNET_CHAT_Handle *handle; 96 struct GNUNET_CHAT_Handle *handle;
97 const struct GNUNET_CHAT_Contact *contact;
97 98
98 struct GNUNET_RECLAIM_Attribute *attribute; 99 struct GNUNET_RECLAIM_Attribute *attribute;
100 char *name;
99 101
100 GNUNET_CHAT_AttributeCallback callback; 102 GNUNET_CHAT_AttributeCallback callback;
101 void *closure; 103 void *closure;
@@ -110,6 +112,13 @@ struct GNUNET_CHAT_AttributeProcess
110struct GNUNET_CHAT_TicketProcess 112struct GNUNET_CHAT_TicketProcess
111{ 113{
112 struct GNUNET_CHAT_Handle *handle; 114 struct GNUNET_CHAT_Handle *handle;
115 const struct GNUNET_CHAT_Contact *contact;
116
117 struct GNUNET_RECLAIM_Ticket *ticket;
118 char *name;
119
120 GNUNET_CHAT_ContactAttributeCallback callback;
121 void *closure;
113 122
114 struct GNUNET_CRYPTO_PrivateKey identity; 123 struct GNUNET_CRYPTO_PrivateKey identity;
115 124
@@ -379,7 +388,7 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
379 388
380/** 389/**
381 * Updates the tickets of a given chat <i>handle</i>, revoking 390 * Updates the tickets of a given chat <i>handle</i>, revoking
382 * all tickets of a <i>identity</i>. 391 * all tickets of an <i>identity</i>.
383 * 392 *
384 * @param[in,out] handle Chat handle 393 * @param[in,out] handle Chat handle
385 * @param[in] identity Identity private key 394 * @param[in] identity Identity private key
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index ca17b62..3c7bb14 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -275,7 +275,7 @@ void
275GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, 275GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
276 const char *name, 276 const char *name,
277 const char *value, 277 const char *value,
278 const struct GNUNET_TIME_Relative *expires) 278 struct GNUNET_TIME_Relative expires)
279{ 279{
280 GNUNET_CHAT_VERSION_ASSERT(); 280 GNUNET_CHAT_VERSION_ASSERT();
281 281
@@ -336,7 +336,7 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
336 handle->reclaim, 336 handle->reclaim,
337 key, 337 key,
338 attributes->attribute, 338 attributes->attribute,
339 expires, 339 &expires,
340 cont_update_attribute_with_status, 340 cont_update_attribute_with_status,
341 attributes 341 attributes
342 ); 342 );
@@ -375,25 +375,22 @@ GNUNET_CHAT_delete_attribute (struct GNUNET_CHAT_Handle *handle,
375 memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess)); 375 memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
376 376
377 attributes->handle = handle; 377 attributes->handle = handle;
378 attributes->attribute = GNUNET_RECLAIM_attribute_new( 378 attributes->name = GNUNET_strdup(name);
379 name,
380 NULL,
381 GNUNET_RECLAIM_ATTRIBUTE_TYPE_NONE,
382 NULL,
383 0
384 );
385 379
386 if (!attributes->attribute) 380 if (!attributes->name)
387 { 381 {
388 GNUNET_free(attributes); 382 GNUNET_free(attributes);
389 return; 383 return;
390 } 384 }
391 385
392 attributes->op = GNUNET_RECLAIM_attribute_delete( 386 attributes->iter = GNUNET_RECLAIM_get_attributes_start(
393 handle->reclaim, 387 handle->reclaim,
394 key, 388 key,
395 attributes->attribute, 389 cb_task_error_iterate_attribute,
396 cont_update_attribute_with_status, 390 attributes,
391 cb_delete_attribute,
392 attributes,
393 cb_task_finish_iterate_attribute,
397 attributes 394 attributes
398 ); 395 );
399 396
@@ -455,6 +452,160 @@ GNUNET_CHAT_get_attributes (struct GNUNET_CHAT_Handle *handle,
455} 452}
456 453
457 454
455void
456GNUNET_CHAT_share_attribute_with (struct GNUNET_CHAT_Handle *handle,
457 struct GNUNET_CHAT_Contact *contact,
458 const char *name)
459{
460 GNUNET_CHAT_VERSION_ASSERT();
461
462 if ((!handle) || (handle->destruction) || (!contact))
463 return;
464
465 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
466 handle
467 );
468
469 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key(
470 contact
471 );
472
473 if ((!key) || (!pubkey) || (!name))
474 return;
475
476 struct GNUNET_CHAT_AttributeProcess *attributes = GNUNET_new(
477 struct GNUNET_CHAT_AttributeProcess
478 );
479
480 if (!attributes)
481 return;
482
483 memset(attributes, 0, sizeof(struct GNUNET_CHAT_AttributeProcess));
484
485 attributes->handle = handle;
486 attributes->contact = contact;
487 attributes->name = GNUNET_strdup(name);
488
489 attributes->iter = GNUNET_RECLAIM_get_attributes_start(
490 handle->reclaim,
491 key,
492 cb_task_error_iterate_attribute,
493 attributes,
494 cb_share_attribute,
495 attributes,
496 cb_task_finish_iterate_attribute,
497 attributes
498 );
499
500 GNUNET_CONTAINER_DLL_insert_tail(
501 handle->attributes_head,
502 handle->attributes_tail,
503 attributes
504 );
505}
506
507
508void
509GNUNET_CHAT_unshare_attribute_from (struct GNUNET_CHAT_Handle *handle,
510 struct GNUNET_CHAT_Contact *contact,
511 const char *name)
512{
513 GNUNET_CHAT_VERSION_ASSERT();
514
515 if ((!handle) || (handle->destruction) || (!contact))
516 return;
517
518 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
519 handle
520 );
521
522 if ((!key) || (!name))
523 return;
524
525 struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new(
526 struct GNUNET_CHAT_TicketProcess
527 );
528
529 if (!tickets)
530 return;
531
532 memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess));
533
534 tickets->handle = handle;
535 tickets->contact = contact;
536 tickets->name = GNUNET_strdup(name);
537
538 tickets->iter = GNUNET_RECLAIM_ticket_iteration_start(
539 handle->reclaim,
540 key,
541 cb_task_error_iterate_ticket,
542 tickets,
543 cb_iterate_ticket_check,
544 tickets,
545 cb_task_finish_iterate_ticket,
546 tickets
547 );
548
549 GNUNET_CONTAINER_DLL_insert_tail(
550 handle->tickets_head,
551 handle->tickets_tail,
552 tickets
553 );
554}
555
556
557void
558GNUNET_CHAT_get_shared_attributes (struct GNUNET_CHAT_Handle *handle,
559 const struct GNUNET_CHAT_Contact *contact,
560 GNUNET_CHAT_ContactAttributeCallback callback,
561 void *cls)
562{
563 GNUNET_CHAT_VERSION_ASSERT();
564
565 if ((!handle) || (handle->destruction) || (!contact))
566 return;
567
568 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
569 handle
570 );
571
572 if (!key)
573 return;
574
575 struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new(
576 struct GNUNET_CHAT_TicketProcess
577 );
578
579 if (!tickets)
580 return;
581
582 memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess));
583
584 tickets->handle = handle;
585 tickets->contact = contact;
586
587 tickets->callback = callback;
588 tickets->closure = cls;
589
590 tickets->iter = GNUNET_RECLAIM_ticket_iteration_start(
591 handle->reclaim,
592 key,
593 cb_task_error_iterate_ticket,
594 tickets,
595 cb_iterate_ticket,
596 tickets,
597 cb_task_finish_iterate_ticket,
598 tickets
599 );
600
601 GNUNET_CONTAINER_DLL_insert_tail(
602 handle->tickets_head,
603 handle->tickets_tail,
604 tickets
605 );
606}
607
608
458struct GNUNET_CHAT_Uri* 609struct GNUNET_CHAT_Uri*
459GNUNET_CHAT_uri_parse (const char *uri, 610GNUNET_CHAT_uri_parse (const char *uri,
460 char **emsg) 611 char **emsg)
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index 9bf5788..61c0e94 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -26,7 +26,11 @@
26#include "gnunet_chat_handle.h" 26#include "gnunet_chat_handle.h"
27 27
28#include <gnunet/gnunet_common.h> 28#include <gnunet/gnunet_common.h>
29#include <gnunet/gnunet_messenger_service.h>
30#include <gnunet/gnunet_reclaim_lib.h>
31#include <gnunet/gnunet_reclaim_service.h>
29#include <stdlib.h> 32#include <stdlib.h>
33#include <string.h>
30 34
31#define GNUNET_UNUSED __attribute__ ((unused)) 35#define GNUNET_UNUSED __attribute__ ((unused))
32 36
@@ -438,6 +442,11 @@ cb_task_finish_iterate_attribute (void *cls)
438 if (attributes->iter) 442 if (attributes->iter)
439 GNUNET_RECLAIM_get_attributes_stop(attributes->iter); 443 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
440 444
445 attributes->iter = NULL;
446
447 if (attributes->op)
448 return;
449
441 GNUNET_CONTAINER_DLL_remove( 450 GNUNET_CONTAINER_DLL_remove(
442 handle->attributes_head, 451 handle->attributes_head,
443 handle->attributes_tail, 452 handle->attributes_tail,
@@ -467,6 +476,55 @@ cb_task_error_iterate_attribute (void *cls)
467} 476}
468 477
469void 478void
479cb_delete_attribute (void *cls,
480 const struct GNUNET_CRYPTO_PublicKey *identity,
481 const struct GNUNET_RECLAIM_Attribute *attribute)
482{
483 GNUNET_assert(cls);
484
485 struct GNUNET_CHAT_AttributeProcess *attributes = (
486 (struct GNUNET_CHAT_AttributeProcess*) cls
487 );
488
489 if (! attributes->name)
490 {
491 if (attributes->iter)
492 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
493
494 attributes->iter = NULL;
495 return;
496 }
497
498 struct GNUNET_CHAT_Handle *handle = attributes->handle;
499
500 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
501 handle
502 );
503
504 if (0 == strcmp(attribute->name, attributes->name))
505 {
506 if (attributes->iter)
507 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
508
509 attributes->iter = NULL;
510 attributes->op = GNUNET_RECLAIM_attribute_delete(
511 handle->reclaim,
512 key,
513 attribute,
514 cont_update_attribute_with_status,
515 attributes
516 );
517
518 GNUNET_free(attributes->name);
519 attributes->name = NULL;
520 return;
521 }
522
523 if (attributes->iter)
524 GNUNET_RECLAIM_get_attributes_next(attributes->iter);
525}
526
527void
470cb_iterate_attribute (void *cls, 528cb_iterate_attribute (void *cls,
471 const struct GNUNET_CRYPTO_PublicKey *identity, 529 const struct GNUNET_CRYPTO_PublicKey *identity,
472 const struct GNUNET_RECLAIM_Attribute *attribute) 530 const struct GNUNET_RECLAIM_Attribute *attribute)
@@ -479,7 +537,7 @@ cb_iterate_attribute (void *cls,
479 537
480 struct GNUNET_CHAT_Handle *handle = attributes->handle; 538 struct GNUNET_CHAT_Handle *handle = attributes->handle;
481 539
482 const char *value = GNUNET_RECLAIM_attribute_value_to_string( 540 char *value = GNUNET_RECLAIM_attribute_value_to_string(
483 attribute->type, 541 attribute->type,
484 attribute->data, 542 attribute->data,
485 attribute->data_size 543 attribute->data_size
@@ -488,6 +546,422 @@ cb_iterate_attribute (void *cls,
488 if (attributes->callback) 546 if (attributes->callback)
489 attributes->callback(attributes->closure, handle, attribute->name, value); 547 attributes->callback(attributes->closure, handle, attribute->name, value);
490 548
549 if (value)
550 GNUNET_free (value);
551
552 if (attributes->iter)
553 GNUNET_RECLAIM_get_attributes_next(attributes->iter);
554}
555
556void
557cb_issue_ticket (void *cls,
558 const struct GNUNET_RECLAIM_Ticket *ticket,
559 const struct GNUNET_RECLAIM_PresentationList *presentations)
560{
561 GNUNET_assert(cls);
562
563 struct GNUNET_CHAT_AttributeProcess *attributes = (
564 (struct GNUNET_CHAT_AttributeProcess*) cls
565 );
566
567 struct GNUNET_CHAT_Handle *handle = attributes->handle;
568 struct GNUNET_CHAT_Context *context = contact_find_context(
569 attributes->contact
570 );
571
572 if ((context) && (context->room) && (ticket))
573 GNUNET_MESSENGER_send_ticket(context->room, ticket);
574
575 GNUNET_CONTAINER_DLL_remove(
576 handle->attributes_head,
577 handle->attributes_tail,
578 attributes
579 );
580
581 GNUNET_free(attributes);
582}
583
584void
585cb_share_attribute (void *cls,
586 const struct GNUNET_CRYPTO_PublicKey *identity,
587 const struct GNUNET_RECLAIM_Attribute *attribute)
588{
589 GNUNET_assert(cls);
590
591 struct GNUNET_CHAT_AttributeProcess *attributes = (
592 (struct GNUNET_CHAT_AttributeProcess*) cls
593 );
594
595 if (! attributes->name)
596 {
597 if (attributes->iter)
598 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
599
600 attributes->iter = NULL;
601 return;
602 }
603
604 struct GNUNET_CHAT_Handle *handle = attributes->handle;
605
606 if (0 == strcmp(attribute->name, attributes->name))
607 {
608 GNUNET_free(attributes->name);
609 attributes->name = NULL;
610
611 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
612 handle
613 );
614
615 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key(
616 attributes->contact
617 );
618
619 if (attributes->iter)
620 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
621
622 attributes->iter = NULL;
623
624 struct GNUNET_RECLAIM_AttributeList *attrs;
625 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
626
627 if (attrs)
628 GNUNET_RECLAIM_attribute_list_add(
629 attrs,
630 attribute->name,
631 &(attribute->credential),
632 attribute->type,
633 attribute->data,
634 attribute->data_size
635 );
636
637 if ((key) && (pubkey) && (attrs))
638 attributes->op = GNUNET_RECLAIM_ticket_issue(
639 handle->reclaim,
640 key,
641 pubkey,
642 attrs,
643 cb_issue_ticket,
644 attributes
645 );
646
647 if (attrs)
648 GNUNET_RECLAIM_attribute_list_destroy(attrs);
649
650 return;
651 }
652
491 if (attributes->iter) 653 if (attributes->iter)
492 GNUNET_RECLAIM_get_attributes_next(attributes->iter); 654 GNUNET_RECLAIM_get_attributes_next(attributes->iter);
493} 655}
656
657void
658cb_task_finish_iterate_ticket (void *cls)
659{
660 GNUNET_assert(cls);
661
662 struct GNUNET_CHAT_TicketProcess *tickets = (
663 (struct GNUNET_CHAT_TicketProcess*) cls
664 );
665
666 struct GNUNET_CHAT_Handle *handle = tickets->handle;
667
668 if (tickets->iter)
669 GNUNET_RECLAIM_ticket_iteration_stop (tickets->iter);
670
671 if (tickets->name)
672 GNUNET_free(tickets->name);
673
674 GNUNET_CONTAINER_DLL_remove(
675 handle->tickets_head,
676 handle->tickets_tail,
677 tickets
678 );
679
680 GNUNET_free(tickets);
681}
682
683void
684cb_task_error_iterate_ticket (void *cls)
685{
686 GNUNET_assert(cls);
687
688 struct GNUNET_CHAT_TicketProcess *tickets = (
689 (struct GNUNET_CHAT_TicketProcess*) cls
690 );
691
692 handle_send_internal_message(
693 tickets->handle,
694 NULL,
695 GNUNET_CHAT_FLAG_WARNING,
696 "Ticket iteration failed!"
697 );
698
699 cb_task_finish_iterate_ticket(cls);
700}
701
702void
703cont_revoke_ticket (void *cls,
704 int32_t success,
705 const char *emsg)
706{
707 GNUNET_assert(cls);
708
709 struct GNUNET_CHAT_TicketProcess *tickets = (
710 (struct GNUNET_CHAT_TicketProcess*) cls
711 );
712
713 struct GNUNET_CHAT_Handle *handle = tickets->handle;
714
715 if (success == GNUNET_SYSERR)
716 handle_send_internal_message(
717 handle,
718 NULL,
719 GNUNET_CHAT_FLAG_WARNING,
720 emsg
721 );
722
723 GNUNET_CONTAINER_DLL_remove(
724 handle->tickets_head,
725 handle->tickets_tail,
726 tickets
727 );
728
729 GNUNET_free(tickets);
730}
731
732void
733cb_consume_ticket_check (void *cls,
734 const struct GNUNET_CRYPTO_PublicKey *identity,
735 const struct GNUNET_RECLAIM_Attribute *attribute,
736 const struct GNUNET_RECLAIM_Presentation *presentation)
737{
738 GNUNET_assert(cls);
739
740 struct GNUNET_CHAT_TicketProcess *tickets = (
741 (struct GNUNET_CHAT_TicketProcess*) cls
742 );
743
744 if ((!identity) && (!attribute) && (!presentation))
745 {
746 tickets->op = NULL;
747
748 struct GNUNET_CHAT_Handle *handle = tickets->handle;
749
750 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
751 handle
752 );
753
754 if (tickets->name)
755 {
756 GNUNET_free(tickets->name);
757 tickets->name = NULL;
758 }
759 else if (!key)
760 tickets->op = GNUNET_RECLAIM_ticket_revoke(
761 handle->reclaim,
762 key,
763 tickets->ticket,
764 cont_revoke_ticket,
765 tickets
766 );
767
768 if (tickets->ticket)
769 GNUNET_free(tickets->ticket);
770
771 tickets->ticket = NULL;
772
773 if (tickets->op)
774 return;
775
776 GNUNET_CONTAINER_DLL_remove(
777 handle->tickets_head,
778 handle->tickets_tail,
779 tickets
780 );
781
782 GNUNET_free(tickets);
783 }
784
785 if ((!attribute) || (! tickets->name) ||
786 (0 != strcmp(tickets->name, attribute->name)))
787 return;
788
789 if (tickets->name)
790 GNUNET_free(tickets->name);
791
792 tickets->name = NULL;
793}
794
795void
796cb_iterate_ticket_check (void *cls,
797 const struct GNUNET_RECLAIM_Ticket *ticket)
798{
799 GNUNET_assert(cls);
800
801 struct GNUNET_CHAT_TicketProcess *tickets = (
802 (struct GNUNET_CHAT_TicketProcess*) cls
803 );
804
805 struct GNUNET_CHAT_Handle *handle = tickets->handle;
806
807 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
808 handle
809 );
810
811 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key(
812 tickets->contact
813 );
814
815 if ((!key) || (!pubkey))
816 return;
817
818 if (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))
819 goto skip_ticket;
820
821 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new(
822 struct GNUNET_CHAT_TicketProcess
823 );
824
825 if (!tick)
826 return;
827
828 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess));
829
830 tick->handle = handle;
831 tick->contact = tickets->contact;
832
833 if (tickets->name)
834 tick->name = GNUNET_strdup (tickets->name);
835
836 tick->ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
837
838 if (tick->ticket)
839 GNUNET_memcpy (
840 tick->ticket,
841 ticket,
842 sizeof (struct GNUNET_RECLAIM_Ticket)
843 );
844
845 tick->callback = tickets->callback;
846 tick->closure = tickets->closure;
847
848 tick->op = GNUNET_RECLAIM_ticket_consume(
849 handle->reclaim,
850 key,
851 ticket,
852 cb_consume_ticket_check,
853 tick
854 );
855
856 GNUNET_CONTAINER_DLL_insert_tail(
857 handle->tickets_head,
858 handle->tickets_tail,
859 tick
860 );
861
862skip_ticket:
863 if (tickets->iter)
864 GNUNET_RECLAIM_ticket_iteration_next (tickets->iter);
865}
866
867void
868cb_consume_ticket (void *cls,
869 const struct GNUNET_CRYPTO_PublicKey *identity,
870 const struct GNUNET_RECLAIM_Attribute *attribute,
871 const struct GNUNET_RECLAIM_Presentation *presentation)
872{
873 GNUNET_assert(cls);
874
875 struct GNUNET_CHAT_TicketProcess *tickets = (
876 (struct GNUNET_CHAT_TicketProcess*) cls
877 );
878
879 if ((!identity) && (!attribute) && (!presentation))
880 {
881 struct GNUNET_CHAT_Handle *handle = tickets->handle;
882
883 GNUNET_CONTAINER_DLL_remove(
884 handle->tickets_head,
885 handle->tickets_tail,
886 tickets
887 );
888
889 GNUNET_free(tickets);
890 return;
891 }
892
893 if (!attribute)
894 return;
895
896 char *value = GNUNET_RECLAIM_attribute_value_to_string(
897 attribute->type,
898 attribute->data,
899 attribute->data_size
900 );
901
902 if (tickets->callback)
903 tickets->callback(tickets->closure, tickets->contact, attribute->name, value);
904
905 if (value)
906 GNUNET_free (value);
907}
908
909void
910cb_iterate_ticket (void *cls,
911 const struct GNUNET_RECLAIM_Ticket *ticket)
912{
913 GNUNET_assert(cls);
914
915 struct GNUNET_CHAT_TicketProcess *tickets = (
916 (struct GNUNET_CHAT_TicketProcess*) cls
917 );
918
919 struct GNUNET_CHAT_Handle *handle = tickets->handle;
920
921 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
922 handle
923 );
924
925 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key(
926 tickets->contact
927 );
928
929 if ((!key) || (!pubkey))
930 return;
931
932 if (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))
933 goto skip_ticket;
934
935 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new(
936 struct GNUNET_CHAT_TicketProcess
937 );
938
939 if (!tick)
940 return;
941
942 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess));
943
944 tick->handle = handle;
945 tick->contact = tickets->contact;
946
947 tick->callback = tickets->callback;
948 tick->closure = tickets->closure;
949
950 tick->op = GNUNET_RECLAIM_ticket_consume(
951 handle->reclaim,
952 key,
953 ticket,
954 cb_consume_ticket,
955 tick
956 );
957
958 GNUNET_CONTAINER_DLL_insert_tail(
959 handle->tickets_head,
960 handle->tickets_tail,
961 tick
962 );
963
964skip_ticket:
965 if (tickets->iter)
966 GNUNET_RECLAIM_ticket_iteration_next (tickets->iter);
967}