aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gnunet_chat_handle.c43
-rw-r--r--src/gnunet_chat_handle.h11
-rw-r--r--src/gnunet_chat_handle_intern.c111
-rw-r--r--src/gnunet_chat_lib.c7
-rw-r--r--src/gnunet_chat_lib_intern.c157
5 files changed, 117 insertions, 212 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index 6e7ed8b..1ce4233 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -241,7 +241,6 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
241 GNUNET_RECLAIM_disconnect(handle->reclaim); 241 GNUNET_RECLAIM_disconnect(handle->reclaim);
242 242
243 struct GNUNET_CHAT_InternalAccounts *accounts; 243 struct GNUNET_CHAT_InternalAccounts *accounts;
244
245 while (handle->accounts_head) 244 while (handle->accounts_head)
246 { 245 {
247 accounts = handle->accounts_head; 246 accounts = handle->accounts_head;
@@ -1056,45 +1055,3 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
1056 1055
1057 return context; 1056 return context;
1058} 1057}
1059
1060void
1061handle_update_tickets (struct GNUNET_CHAT_Handle *handle,
1062 const struct GNUNET_CRYPTO_PrivateKey *identity)
1063{
1064 GNUNET_assert((handle) && (identity));
1065
1066 if (!handle->reclaim)
1067 return;
1068
1069 struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new(
1070 struct GNUNET_CHAT_TicketProcess
1071 );
1072
1073 if (!tickets)
1074 return;
1075
1076 memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess));
1077 tickets->handle = handle;
1078 GNUNET_memcpy(
1079 &(tickets->identity),
1080 identity,
1081 sizeof(tickets->identity)
1082 );
1083
1084 tickets->iter = GNUNET_RECLAIM_ticket_iteration_start(
1085 handle->reclaim,
1086 identity,
1087 cb_task_error_ticket_update,
1088 tickets,
1089 cb_iterate_ticket_update,
1090 tickets,
1091 cb_task_finish_ticket_update,
1092 tickets
1093 );
1094
1095 GNUNET_CONTAINER_DLL_insert_tail(
1096 handle->tickets_head,
1097 handle->tickets_tail,
1098 tickets
1099 );
1100}
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index da0ecc5..485cfeb 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -387,15 +387,4 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle,
387 unsigned int count, 387 unsigned int count,
388 const struct GNUNET_GNSRECORD_Data *data); 388 const struct GNUNET_GNSRECORD_Data *data);
389 389
390/**
391 * Updates the tickets of a given chat <i>handle</i>, revoking
392 * all tickets of an <i>identity</i>.
393 *
394 * @param[in,out] handle Chat handle
395 * @param[in] identity Identity private key
396 */
397void
398handle_update_tickets (struct GNUNET_CHAT_Handle *handle,
399 const struct GNUNET_CRYPTO_PrivateKey *identity);
400
401#endif /* GNUNET_CHAT_HANDLE_H_ */ 390#endif /* GNUNET_CHAT_HANDLE_H_ */
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 65f99bb..0eff7ae 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -278,104 +278,6 @@ notify_handle_fs_progress(void* cls,
278} 278}
279 279
280void 280void
281cb_task_finish_ticket_update (void *cls)
282{
283 GNUNET_assert(cls);
284
285 struct GNUNET_CHAT_TicketProcess *tickets = (
286 (struct GNUNET_CHAT_TicketProcess*) cls
287 );
288
289 struct GNUNET_CHAT_Handle *handle = tickets->handle;
290
291 GNUNET_CONTAINER_DLL_remove(
292 handle->tickets_head,
293 handle->tickets_tail,
294 tickets
295 );
296
297 GNUNET_free(tickets);
298}
299
300void
301cb_task_error_ticket_update (void *cls)
302{
303 GNUNET_assert(cls);
304
305 struct GNUNET_CHAT_TicketProcess *tickets = (
306 (struct GNUNET_CHAT_TicketProcess*) cls
307 );
308
309 handle_send_internal_message(
310 tickets->handle,
311 NULL,
312 GNUNET_CHAT_FLAG_WARNING,
313 "Ticket update failed!"
314 );
315
316 cb_task_finish_ticket_update(cls);
317}
318
319static void
320cont_revoke_ticket_with_status (void *cls,
321 int32_t success,
322 const char *emsg)
323{
324 GNUNET_assert(cls);
325
326 struct GNUNET_CHAT_TicketProcess *tickets = (
327 (struct GNUNET_CHAT_TicketProcess*) cls
328 );
329
330 tickets->op = NULL;
331
332 struct GNUNET_CHAT_Handle *handle = tickets->handle;
333
334 if (GNUNET_SYSERR == success)
335 {
336 handle_send_internal_message(
337 handle,
338 NULL,
339 GNUNET_CHAT_KIND_WARNING,
340 emsg
341 );
342
343 if (tickets->iter)
344 GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter);
345
346 tickets->iter = NULL;
347 return;
348 }
349
350 if (tickets->iter)
351 GNUNET_RECLAIM_ticket_iteration_next(tickets->iter);
352}
353
354void
355cb_iterate_ticket_update (void *cls,
356 const struct GNUNET_RECLAIM_Ticket *ticket)
357{
358 GNUNET_assert(cls);
359
360 struct GNUNET_CHAT_TicketProcess *tickets = (
361 (struct GNUNET_CHAT_TicketProcess*) cls
362 );
363
364 struct GNUNET_CHAT_Handle *handle = tickets->handle;
365
366 if (tickets->op)
367 GNUNET_RECLAIM_cancel(tickets->op);
368
369 tickets->op = GNUNET_RECLAIM_ticket_revoke(
370 handle->reclaim,
371 &(tickets->identity),
372 ticket,
373 cont_revoke_ticket_with_status,
374 tickets
375 );
376}
377
378void
379on_handle_gnunet_identity (void *cls, 281on_handle_gnunet_identity (void *cls,
380 struct GNUNET_IDENTITY_Ego *ego, 282 struct GNUNET_IDENTITY_Ego *ego,
381 void **ctx, 283 void **ctx,
@@ -415,12 +317,6 @@ on_handle_gnunet_identity (void *cls,
415 } 317 }
416 else 318 else
417 { 319 {
418 const struct GNUNET_CRYPTO_PrivateKey *key;
419 key = GNUNET_IDENTITY_ego_get_private_key(ego);
420
421 if (key)
422 handle_update_tickets(handle, key);
423
424 if (handle->current == accounts->account) 320 if (handle->current == accounts->account)
425 handle_disconnect(handle); 321 handle_disconnect(handle);
426 322
@@ -607,14 +503,7 @@ cb_account_update_completion (void *cls,
607 struct GNUNET_CHAT_Handle *handle = accounts->handle; 503 struct GNUNET_CHAT_Handle *handle = accounts->handle;
608 504
609 if ((GNUNET_EC_NONE == ec) && (key)) 505 if ((GNUNET_EC_NONE == ec) && (key))
610 {
611 const struct GNUNET_CRYPTO_PrivateKey *prev= handle_get_key(handle);
612
613 if (prev)
614 handle_update_tickets(handle, prev);
615
616 GNUNET_MESSENGER_set_key(handle->messenger, key); 506 GNUNET_MESSENGER_set_key(handle->messenger, key);
617 }
618 507
619 cb_account_creation(cls, key, ec); 508 cb_account_creation(cls, key, ec);
620} 509}
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index 5bac17d..b276fe4 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -314,10 +314,10 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
314 return; 314 return;
315 } 315 }
316 316
317 void *data = NULL;
318
317 if (value) 319 if (value)
318 { 320 {
319 void *data = NULL;
320
321 enum GNUNET_GenericReturnValue result; 321 enum GNUNET_GenericReturnValue result;
322 result = GNUNET_RECLAIM_attribute_string_to_value( 322 result = GNUNET_RECLAIM_attribute_string_to_value(
323 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, 323 GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
@@ -351,6 +351,9 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle,
351 handle->attributes_tail, 351 handle->attributes_tail,
352 attributes 352 attributes
353 ); 353 );
354
355 if (data)
356 GNUNET_free(data);
354} 357}
355 358
356 359
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index 4dd633b..e13da4f 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -459,9 +459,6 @@ cb_task_finish_iterate_attribute (void *cls)
459 459
460 struct GNUNET_CHAT_Handle *handle = attributes->handle; 460 struct GNUNET_CHAT_Handle *handle = attributes->handle;
461 461
462 if (attributes->iter)
463 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
464
465 attributes->iter = NULL; 462 attributes->iter = NULL;
466 463
467 if (attributes->op) 464 if (attributes->op)
@@ -523,6 +520,7 @@ cb_delete_attribute (void *cls,
523 520
524 if (0 == strcmp(attribute->name, attributes->name)) 521 if (0 == strcmp(attribute->name, attributes->name))
525 { 522 {
523
526 if (attributes->iter) 524 if (attributes->iter)
527 GNUNET_RECLAIM_get_attributes_stop(attributes->iter); 525 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
528 526
@@ -610,6 +608,45 @@ cb_issue_ticket (void *cls,
610 GNUNET_free(attributes); 608 GNUNET_free(attributes);
611} 609}
612 610
611static struct GNUNET_RECLAIM_AttributeList*
612attribute_list_from_attribute (const struct GNUNET_RECLAIM_Attribute *attribute)
613{
614 struct GNUNET_RECLAIM_AttributeList *attrs;
615 struct GNUNET_RECLAIM_AttributeListEntry *le;
616
617 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
618
619 if (!attrs)
620 return NULL;
621
622 le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
623
624 if (!le)
625 {
626 GNUNET_free (attrs);
627 return NULL;
628 }
629
630 le->attribute = GNUNET_RECLAIM_attribute_new (
631 attribute->name,
632 &(attribute->credential),
633 attribute->type,
634 attribute->data,
635 attribute->data_size
636 );
637
638 le->attribute->flag = attribute->flag;
639 le->attribute->id = attribute->id;
640
641 GNUNET_CONTAINER_DLL_insert (
642 attrs->list_head,
643 attrs->list_tail,
644 le
645 );
646
647 return attrs;
648}
649
613void 650void
614cb_share_attribute (void *cls, 651cb_share_attribute (void *cls,
615 const struct GNUNET_CRYPTO_PublicKey *identity, 652 const struct GNUNET_CRYPTO_PublicKey *identity,
@@ -646,22 +683,13 @@ cb_share_attribute (void *cls,
646 ); 683 );
647 684
648 if (attributes->iter) 685 if (attributes->iter)
686 {
649 GNUNET_RECLAIM_get_attributes_stop(attributes->iter); 687 GNUNET_RECLAIM_get_attributes_stop(attributes->iter);
650 688 attributes->iter = NULL;
651 attributes->iter = NULL; 689 }
652 690
653 struct GNUNET_RECLAIM_AttributeList *attrs; 691 struct GNUNET_RECLAIM_AttributeList *attrs;
654 attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 692 attrs = attribute_list_from_attribute(attribute);
655
656 if (attrs)
657 GNUNET_RECLAIM_attribute_list_add(
658 attrs,
659 attribute->name,
660 &(attribute->credential),
661 attribute->type,
662 attribute->data,
663 attribute->data_size
664 );
665 693
666 if ((key) && (pubkey) && (attrs)) 694 if ((key) && (pubkey) && (attrs))
667 attributes->op = GNUNET_RECLAIM_ticket_issue( 695 attributes->op = GNUNET_RECLAIM_ticket_issue(
@@ -683,6 +711,25 @@ cb_share_attribute (void *cls,
683 GNUNET_RECLAIM_get_attributes_next(attributes->iter); 711 GNUNET_RECLAIM_get_attributes_next(attributes->iter);
684} 712}
685 713
714static void
715ticket_process_next (struct GNUNET_CHAT_TicketProcess *tickets)
716{
717 if (! tickets->iter)
718 return;
719
720 GNUNET_RECLAIM_ticket_iteration_next (tickets->iter);
721}
722
723static void
724ticket_process_stop (struct GNUNET_CHAT_TicketProcess *tickets)
725{
726 if (! tickets->iter)
727 return;
728
729 GNUNET_RECLAIM_ticket_iteration_stop (tickets->iter);
730 tickets->iter = NULL;
731}
732
686void 733void
687cb_task_finish_iterate_ticket (void *cls) 734cb_task_finish_iterate_ticket (void *cls)
688{ 735{
@@ -692,10 +739,9 @@ cb_task_finish_iterate_ticket (void *cls)
692 (struct GNUNET_CHAT_TicketProcess*) cls 739 (struct GNUNET_CHAT_TicketProcess*) cls
693 ); 740 );
694 741
695 struct GNUNET_CHAT_Handle *handle = tickets->handle; 742 tickets->iter = NULL;
696 743
697 if (tickets->iter) 744 struct GNUNET_CHAT_Handle *handle = tickets->handle;
698 GNUNET_RECLAIM_ticket_iteration_stop (tickets->iter);
699 745
700 if (tickets->name) 746 if (tickets->name)
701 GNUNET_free(tickets->name); 747 GNUNET_free(tickets->name);
@@ -802,9 +848,10 @@ cb_consume_ticket_check (void *cls,
802 ); 848 );
803 849
804 if (tickets->ticket) 850 if (tickets->ticket)
851 {
805 GNUNET_free(tickets->ticket); 852 GNUNET_free(tickets->ticket);
806 853 tickets->ticket = NULL;
807 tickets->ticket = NULL; 854 }
808 855
809 if (tickets->op) 856 if (tickets->op)
810 return; 857 return;
@@ -816,6 +863,7 @@ cb_consume_ticket_check (void *cls,
816 ); 863 );
817 864
818 GNUNET_free(tickets); 865 GNUNET_free(tickets);
866 return;
819 } 867 }
820 868
821 if ((!attribute) || (! tickets->name) || 869 if ((!attribute) || (! tickets->name) ||
@@ -823,9 +871,10 @@ cb_consume_ticket_check (void *cls,
823 return; 871 return;
824 872
825 if (tickets->name) 873 if (tickets->name)
874 {
826 GNUNET_free(tickets->name); 875 GNUNET_free(tickets->name);
827 876 tickets->name = NULL;
828 tickets->name = NULL; 877 }
829} 878}
830 879
831void 880void
@@ -839,27 +888,38 @@ cb_iterate_ticket_check (void *cls,
839 ); 888 );
840 889
841 struct GNUNET_CHAT_Handle *handle = tickets->handle; 890 struct GNUNET_CHAT_Handle *handle = tickets->handle;
891 const struct GNUNET_CRYPTO_PublicKey *pubkey;
892
893 if (tickets->contact)
894 pubkey = contact_get_key(tickets->contact);
895 else
896 pubkey = NULL;
897
898 if ((!pubkey) || (0 != GNUNET_memcmp(pubkey, &(ticket->audience))))
899 {
900 ticket_process_next (tickets);
901 return;
902 }
842 903
843 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( 904 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
844 handle 905 handle
845 ); 906 );
846 907
847 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key( 908 if (!key)
848 tickets->contact 909 {
849 ); 910 ticket_process_stop (tickets);
850
851 if ((!key) || (!pubkey))
852 return; 911 return;
853 912 }
854 if (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))
855 goto skip_ticket;
856 913
857 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new( 914 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new(
858 struct GNUNET_CHAT_TicketProcess 915 struct GNUNET_CHAT_TicketProcess
859 ); 916 );
860 917
861 if (!tick) 918 if (!tick)
919 {
920 ticket_process_stop (tickets);
862 return; 921 return;
922 }
863 923
864 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess)); 924 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess));
865 925
@@ -895,9 +955,7 @@ cb_iterate_ticket_check (void *cls,
895 tick 955 tick
896 ); 956 );
897 957
898skip_ticket: 958 ticket_process_next (tickets);
899 if (tickets->iter)
900 GNUNET_RECLAIM_ticket_iteration_next (tickets->iter);
901} 959}
902 960
903void 961void
@@ -953,27 +1011,38 @@ cb_iterate_ticket (void *cls,
953 ); 1011 );
954 1012
955 struct GNUNET_CHAT_Handle *handle = tickets->handle; 1013 struct GNUNET_CHAT_Handle *handle = tickets->handle;
1014 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1015
1016 if (tickets->contact)
1017 pubkey = contact_get_key(tickets->contact);
1018 else
1019 pubkey = NULL;
1020
1021 if ((!pubkey) || (0 != GNUNET_memcmp(pubkey, &(ticket->audience))))
1022 {
1023 ticket_process_next (tickets);
1024 return;
1025 }
956 1026
957 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( 1027 const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key(
958 handle 1028 handle
959 ); 1029 );
960 1030
961 const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key( 1031 if (!key)
962 tickets->contact 1032 {
963 ); 1033 ticket_process_stop (tickets);
964
965 if ((!key) || (!pubkey))
966 return; 1034 return;
967 1035 }
968 if (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))
969 goto skip_ticket;
970 1036
971 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new( 1037 struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new(
972 struct GNUNET_CHAT_TicketProcess 1038 struct GNUNET_CHAT_TicketProcess
973 ); 1039 );
974 1040
975 if (!tick) 1041 if (!tick)
1042 {
1043 ticket_process_stop (tickets);
976 return; 1044 return;
1045 }
977 1046
978 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess)); 1047 memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess));
979 1048
@@ -1003,7 +1072,5 @@ cb_iterate_ticket (void *cls,
1003 tick 1072 tick
1004 ); 1073 );
1005 1074
1006skip_ticket: 1075 ticket_process_next (tickets);
1007 if (tickets->iter)
1008 GNUNET_RECLAIM_ticket_iteration_next (tickets->iter);
1009} 1076}