libgnunetchat

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

commit 6dc2e8abf1f13d83d2645920859b581641233b75
parent 42569e3d32251be923bff7b8176215ec2bdbf69b
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu, 11 Apr 2024 01:11:59 +0200

Fix attributes to pass test case

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

Diffstat:
Msrc/gnunet_chat_handle.c | 55+++++++++++++++++++++++++++++--------------------------
Msrc/gnunet_chat_lib_intern.c | 13++++++++-----
Mtests/test_gnunet_chat_attribute.c | 8++++++--
3 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -174,10 +174,8 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->shutdown_hook) GNUNET_SCHEDULER_cancel(handle->shutdown_hook); - if (handle->destruction) GNUNET_SCHEDULER_cancel(handle->destruction); - if (handle->disconnection) GNUNET_SCHEDULER_cancel(handle->disconnection); @@ -190,14 +188,42 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->namestore) GNUNET_NAMESTORE_disconnect(handle->namestore); + struct GNUNET_CHAT_AttributeProcess *attributes; + while (handle->attributes_head) + { + attributes = handle->attributes_head; + + if (attributes->attribute) + GNUNET_free(attributes->attribute); + if (attributes->name) + GNUNET_free(attributes->name); + + if (attributes->iter) + GNUNET_RECLAIM_get_attributes_stop(attributes->iter); + if (attributes->op) + GNUNET_RECLAIM_cancel(attributes->op); + + GNUNET_CONTAINER_DLL_remove( + handle->attributes_head, + handle->attributes_tail, + attributes + ); + + GNUNET_free(attributes); + } + struct GNUNET_CHAT_TicketProcess *tickets; while (handle->tickets_head) { tickets = handle->tickets_head; + if (tickets->ticket) + GNUNET_free(tickets->ticket); + if (tickets->name) + GNUNET_free(tickets->name); + if (tickets->iter) GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); - if (tickets->op) GNUNET_RECLAIM_cancel(tickets->op); @@ -495,29 +521,6 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) GNUNET_free(lobbies); } - struct GNUNET_CHAT_AttributeProcess *attributes; - while (handle->attributes_head) - { - attributes = handle->attributes_head; - - if (attributes->attribute) - GNUNET_free(attributes->attribute); - - if (attributes->iter) - GNUNET_RECLAIM_get_attributes_stop(attributes->iter); - - if (attributes->op) - GNUNET_RECLAIM_cancel(attributes->op); - - GNUNET_CONTAINER_DLL_remove( - handle->attributes_head, - handle->attributes_tail, - attributes - ); - - GNUNET_free(attributes); - } - GNUNET_CONTAINER_multihashmap_destroy(handle->groups); GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -562,13 +562,16 @@ cb_iterate_attribute (void *cls, if (value) GNUNET_free (value); - if (attributes->iter) + if (! attributes->iter) + return; + + if (GNUNET_YES != result) { - if (GNUNET_YES == result) - GNUNET_RECLAIM_get_attributes_next(attributes->iter); - else - GNUNET_RECLAIM_get_attributes_stop(attributes->iter); + GNUNET_RECLAIM_get_attributes_stop(attributes->iter); + attributes->iter = NULL; } + else + GNUNET_RECLAIM_get_attributes_next(attributes->iter); } void diff --git a/tests/test_gnunet_chat_attribute.c b/tests/test_gnunet_chat_attribute.c @@ -30,8 +30,8 @@ enum GNUNET_GenericReturnValue on_gnunet_chat_attribute_check_it(void *cls, - const struct GNUNET_CHAT_Handle *handle, - struct GNUNET_CHAT_Account *account) + const struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Account *account) { struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; @@ -59,11 +59,15 @@ on_gnunet_chat_attribute_check_attr(void *cls, const char *name, const char *value) { + ck_assert_ptr_eq(cls, NULL); + ck_assert_ptr_ne(handle, NULL); ck_assert_ptr_ne(name, NULL); + if (0 == strcmp(name, "test_attribute_name")) { ck_assert_ptr_ne(value, NULL); ck_assert_int_eq(strcmp(value, "test_attribute_value"), 0); + GNUNET_CHAT_delete_attribute(handle, "test_attribute_name"); return GNUNET_NO; }