libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 3e4a59cd79774ac210dbf968463daf5aec37d9f2
parent 668788871bf903fd8d487a2f63e7adc0b16b371e
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun, 14 Apr 2024 06:11:28 +0200

Fix issues with attribute test cases

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_handle.c | 43-------------------------------------------
Msrc/gnunet_chat_handle.h | 11-----------
Msrc/gnunet_chat_handle_intern.c | 111-------------------------------------------------------------------------------
Msrc/gnunet_chat_lib.c | 7+++++--
Msrc/gnunet_chat_lib_intern.c | 157++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
5 files changed, 117 insertions(+), 212 deletions(-)

diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -241,7 +241,6 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) GNUNET_RECLAIM_disconnect(handle->reclaim); struct GNUNET_CHAT_InternalAccounts *accounts; - while (handle->accounts_head) { accounts = handle->accounts_head; @@ -1056,45 +1055,3 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, return context; } - -void -handle_update_tickets (struct GNUNET_CHAT_Handle *handle, - const struct GNUNET_CRYPTO_PrivateKey *identity) -{ - GNUNET_assert((handle) && (identity)); - - if (!handle->reclaim) - return; - - struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new( - struct GNUNET_CHAT_TicketProcess - ); - - if (!tickets) - return; - - memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess)); - tickets->handle = handle; - GNUNET_memcpy( - &(tickets->identity), - identity, - sizeof(tickets->identity) - ); - - tickets->iter = GNUNET_RECLAIM_ticket_iteration_start( - handle->reclaim, - identity, - cb_task_error_ticket_update, - tickets, - cb_iterate_ticket_update, - tickets, - cb_task_finish_ticket_update, - tickets - ); - - GNUNET_CONTAINER_DLL_insert_tail( - handle->tickets_head, - handle->tickets_tail, - tickets - ); -} diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -387,15 +387,4 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, unsigned int count, const struct GNUNET_GNSRECORD_Data *data); -/** - * Updates the tickets of a given chat <i>handle</i>, revoking - * all tickets of an <i>identity</i>. - * - * @param[in,out] handle Chat handle - * @param[in] identity Identity private key - */ -void -handle_update_tickets (struct GNUNET_CHAT_Handle *handle, - const struct GNUNET_CRYPTO_PrivateKey *identity); - #endif /* GNUNET_CHAT_HANDLE_H_ */ diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -278,104 +278,6 @@ notify_handle_fs_progress(void* cls, } void -cb_task_finish_ticket_update (void *cls) -{ - GNUNET_assert(cls); - - struct GNUNET_CHAT_TicketProcess *tickets = ( - (struct GNUNET_CHAT_TicketProcess*) cls - ); - - struct GNUNET_CHAT_Handle *handle = tickets->handle; - - GNUNET_CONTAINER_DLL_remove( - handle->tickets_head, - handle->tickets_tail, - tickets - ); - - GNUNET_free(tickets); -} - -void -cb_task_error_ticket_update (void *cls) -{ - GNUNET_assert(cls); - - struct GNUNET_CHAT_TicketProcess *tickets = ( - (struct GNUNET_CHAT_TicketProcess*) cls - ); - - handle_send_internal_message( - tickets->handle, - NULL, - GNUNET_CHAT_FLAG_WARNING, - "Ticket update failed!" - ); - - cb_task_finish_ticket_update(cls); -} - -static void -cont_revoke_ticket_with_status (void *cls, - int32_t success, - const char *emsg) -{ - GNUNET_assert(cls); - - struct GNUNET_CHAT_TicketProcess *tickets = ( - (struct GNUNET_CHAT_TicketProcess*) cls - ); - - tickets->op = NULL; - - struct GNUNET_CHAT_Handle *handle = tickets->handle; - - if (GNUNET_SYSERR == success) - { - handle_send_internal_message( - handle, - NULL, - GNUNET_CHAT_KIND_WARNING, - emsg - ); - - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); - - tickets->iter = NULL; - return; - } - - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_next(tickets->iter); -} - -void -cb_iterate_ticket_update (void *cls, - const struct GNUNET_RECLAIM_Ticket *ticket) -{ - GNUNET_assert(cls); - - struct GNUNET_CHAT_TicketProcess *tickets = ( - (struct GNUNET_CHAT_TicketProcess*) cls - ); - - struct GNUNET_CHAT_Handle *handle = tickets->handle; - - if (tickets->op) - GNUNET_RECLAIM_cancel(tickets->op); - - tickets->op = GNUNET_RECLAIM_ticket_revoke( - handle->reclaim, - &(tickets->identity), - ticket, - cont_revoke_ticket_with_status, - tickets - ); -} - -void on_handle_gnunet_identity (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, @@ -415,12 +317,6 @@ on_handle_gnunet_identity (void *cls, } else { - const struct GNUNET_CRYPTO_PrivateKey *key; - key = GNUNET_IDENTITY_ego_get_private_key(ego); - - if (key) - handle_update_tickets(handle, key); - if (handle->current == accounts->account) handle_disconnect(handle); @@ -607,14 +503,7 @@ cb_account_update_completion (void *cls, struct GNUNET_CHAT_Handle *handle = accounts->handle; if ((GNUNET_EC_NONE == ec) && (key)) - { - const struct GNUNET_CRYPTO_PrivateKey *prev= handle_get_key(handle); - - if (prev) - handle_update_tickets(handle, prev); - GNUNET_MESSENGER_set_key(handle->messenger, key); - } cb_account_creation(cls, key, ec); } diff --git 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, return; } + void *data = NULL; + if (value) { - void *data = NULL; - enum GNUNET_GenericReturnValue result; result = GNUNET_RECLAIM_attribute_string_to_value( GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, @@ -351,6 +351,9 @@ GNUNET_CHAT_set_attribute (struct GNUNET_CHAT_Handle *handle, handle->attributes_tail, attributes ); + + if (data) + GNUNET_free(data); } diff --git 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) struct GNUNET_CHAT_Handle *handle = attributes->handle; - if (attributes->iter) - GNUNET_RECLAIM_get_attributes_stop(attributes->iter); - attributes->iter = NULL; if (attributes->op) @@ -523,6 +520,7 @@ cb_delete_attribute (void *cls, if (0 == strcmp(attribute->name, attributes->name)) { + if (attributes->iter) GNUNET_RECLAIM_get_attributes_stop(attributes->iter); @@ -610,6 +608,45 @@ cb_issue_ticket (void *cls, GNUNET_free(attributes); } +static struct GNUNET_RECLAIM_AttributeList* +attribute_list_from_attribute (const struct GNUNET_RECLAIM_Attribute *attribute) +{ + struct GNUNET_RECLAIM_AttributeList *attrs; + struct GNUNET_RECLAIM_AttributeListEntry *le; + + attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); + + if (!attrs) + return NULL; + + le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); + + if (!le) + { + GNUNET_free (attrs); + return NULL; + } + + le->attribute = GNUNET_RECLAIM_attribute_new ( + attribute->name, + &(attribute->credential), + attribute->type, + attribute->data, + attribute->data_size + ); + + le->attribute->flag = attribute->flag; + le->attribute->id = attribute->id; + + GNUNET_CONTAINER_DLL_insert ( + attrs->list_head, + attrs->list_tail, + le + ); + + return attrs; +} + void cb_share_attribute (void *cls, const struct GNUNET_CRYPTO_PublicKey *identity, @@ -646,22 +683,13 @@ cb_share_attribute (void *cls, ); if (attributes->iter) + { GNUNET_RECLAIM_get_attributes_stop(attributes->iter); - - attributes->iter = NULL; + attributes->iter = NULL; + } struct GNUNET_RECLAIM_AttributeList *attrs; - attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); - - if (attrs) - GNUNET_RECLAIM_attribute_list_add( - attrs, - attribute->name, - &(attribute->credential), - attribute->type, - attribute->data, - attribute->data_size - ); + attrs = attribute_list_from_attribute(attribute); if ((key) && (pubkey) && (attrs)) attributes->op = GNUNET_RECLAIM_ticket_issue( @@ -683,6 +711,25 @@ cb_share_attribute (void *cls, GNUNET_RECLAIM_get_attributes_next(attributes->iter); } +static void +ticket_process_next (struct GNUNET_CHAT_TicketProcess *tickets) +{ + if (! tickets->iter) + return; + + GNUNET_RECLAIM_ticket_iteration_next (tickets->iter); +} + +static void +ticket_process_stop (struct GNUNET_CHAT_TicketProcess *tickets) +{ + if (! tickets->iter) + return; + + GNUNET_RECLAIM_ticket_iteration_stop (tickets->iter); + tickets->iter = NULL; +} + void cb_task_finish_iterate_ticket (void *cls) { @@ -692,10 +739,9 @@ cb_task_finish_iterate_ticket (void *cls) (struct GNUNET_CHAT_TicketProcess*) cls ); - struct GNUNET_CHAT_Handle *handle = tickets->handle; + tickets->iter = NULL; - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_stop (tickets->iter); + struct GNUNET_CHAT_Handle *handle = tickets->handle; if (tickets->name) GNUNET_free(tickets->name); @@ -802,9 +848,10 @@ cb_consume_ticket_check (void *cls, ); if (tickets->ticket) + { GNUNET_free(tickets->ticket); - - tickets->ticket = NULL; + tickets->ticket = NULL; + } if (tickets->op) return; @@ -816,6 +863,7 @@ cb_consume_ticket_check (void *cls, ); GNUNET_free(tickets); + return; } if ((!attribute) || (! tickets->name) || @@ -823,9 +871,10 @@ cb_consume_ticket_check (void *cls, return; if (tickets->name) + { GNUNET_free(tickets->name); - - tickets->name = NULL; + tickets->name = NULL; + } } void @@ -839,27 +888,38 @@ cb_iterate_ticket_check (void *cls, ); struct GNUNET_CHAT_Handle *handle = tickets->handle; + const struct GNUNET_CRYPTO_PublicKey *pubkey; + + if (tickets->contact) + pubkey = contact_get_key(tickets->contact); + else + pubkey = NULL; + + if ((!pubkey) || (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))) + { + ticket_process_next (tickets); + return; + } const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( handle ); - const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key( - tickets->contact - ); - - if ((!key) || (!pubkey)) + if (!key) + { + ticket_process_stop (tickets); return; - - if (0 != GNUNET_memcmp(pubkey, &(ticket->audience))) - goto skip_ticket; + } struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new( struct GNUNET_CHAT_TicketProcess ); if (!tick) + { + ticket_process_stop (tickets); return; + } memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess)); @@ -895,9 +955,7 @@ cb_iterate_ticket_check (void *cls, tick ); -skip_ticket: - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_next (tickets->iter); + ticket_process_next (tickets); } void @@ -953,27 +1011,38 @@ cb_iterate_ticket (void *cls, ); struct GNUNET_CHAT_Handle *handle = tickets->handle; + const struct GNUNET_CRYPTO_PublicKey *pubkey; + + if (tickets->contact) + pubkey = contact_get_key(tickets->contact); + else + pubkey = NULL; + + if ((!pubkey) || (0 != GNUNET_memcmp(pubkey, &(ticket->audience)))) + { + ticket_process_next (tickets); + return; + } const struct GNUNET_CRYPTO_PrivateKey *key = handle_get_key( handle ); - const struct GNUNET_CRYPTO_PublicKey *pubkey = contact_get_key( - tickets->contact - ); - - if ((!key) || (!pubkey)) + if (!key) + { + ticket_process_stop (tickets); return; - - if (0 != GNUNET_memcmp(pubkey, &(ticket->audience))) - goto skip_ticket; + } struct GNUNET_CHAT_TicketProcess *tick = GNUNET_new( struct GNUNET_CHAT_TicketProcess ); if (!tick) + { + ticket_process_stop (tickets); return; + } memset(tick, 0, sizeof (struct GNUNET_CHAT_TicketProcess)); @@ -1003,7 +1072,5 @@ cb_iterate_ticket (void *cls, tick ); -skip_ticket: - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_next (tickets->iter); + ticket_process_next (tickets); }