libgnunetchat

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

commit be3816a6b353cb6487caf16a4aa97a1e2fb44f5f
parent 196a4ebac19eb5c673eb343ff1d48defe43ad68b
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun, 11 Feb 2024 21:58:08 +0100

Fix multiple memory leaks

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

Diffstat:
Msrc/gnunet_chat_contact.c | 6++++++
Msrc/gnunet_chat_contact_intern.c | 10++++++++++
Msrc/gnunet_chat_group.c | 6++++++
Msrc/gnunet_chat_group.h | 2++
Msrc/gnunet_chat_handle.c | 25+++++++++++++++++++++++++
Msrc/gnunet_chat_handle.h | 12++++++++++++
Msrc/gnunet_chat_handle_intern.c | 108+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/gnunet_chat_lib.c | 31+++++++++++--------------------
Msrc/gnunet_chat_lib_intern.c | 41+++++++++++++++++++++++++++++++++++++++++
Mtests/test_gnunet_chat_handle.c | 142++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mtests/test_gnunet_chat_message.c | 35++++++++++++++++++++---------------
11 files changed, 277 insertions(+), 141 deletions(-)

diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -352,7 +352,13 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact) GNUNET_free(contact->public_key); if (contact->joined) + { + GNUNET_CONTAINER_multihashmap_iterate( + contact->joined, it_free_join_hashes, NULL + ); + GNUNET_CONTAINER_multihashmap_destroy(contact->joined); + } if ((contact->context) && (!contact->context->room)) context_destroy(contact->context); diff --git a/src/gnunet_chat_contact_intern.c b/src/gnunet_chat_contact_intern.c @@ -86,4 +86,14 @@ it_contact_find_rejection (void *cls, return GNUNET_YES; } +enum GNUNET_GenericReturnValue +it_free_join_hashes (void *cls, + const struct GNUNET_HashCode *key, + void *value) +{ + GNUNET_assert((key) && (value)); + struct GNUNET_HashCode *hash = value; + GNUNET_free(hash); + return GNUNET_YES; +} diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c @@ -26,6 +26,7 @@ #include "gnunet_chat_util.h" #include "gnunet_chat_group_intern.c" +#include <gnunet/gnunet_scheduler_lib.h> static const unsigned int initial_map_size_of_context = 8; static const uint16_t group_regex_compression = 6; @@ -41,6 +42,8 @@ group_create_from_context (struct GNUNET_CHAT_Handle *handle, group->handle = handle; group->context = context; + group->destruction = NULL; + group->announcement = NULL; group->search = NULL; @@ -57,6 +60,9 @@ group_destroy (struct GNUNET_CHAT_Group* group) { GNUNET_assert(group); + if (group->destruction) + GNUNET_SCHEDULER_cancel(group->destruction); + if (group->registry) GNUNET_CONTAINER_multipeermap_destroy(group->registry); diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h @@ -36,6 +36,8 @@ struct GNUNET_CHAT_Group struct GNUNET_CHAT_Handle *handle; struct GNUNET_CHAT_Context *context; + struct GNUNET_SCHEDULER_Task *destruction; + struct GNUNET_REGEX_Announcement *announcement; struct GNUNET_REGEX_Search *search; diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -25,6 +25,8 @@ #include "gnunet_chat_handle.h" #include "gnunet_chat_handle_intern.c" +#include <gnunet/gnunet_arm_service.h> +#include <gnunet/gnunet_common.h> #include <gnunet/gnunet_reclaim_service.h> static const unsigned int initial_map_size_of_handle = 8; @@ -46,6 +48,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->destruction = NULL; + handle->services_head = NULL; + handle->services_tail = NULL; + handle->internal_head = NULL; handle->internal_tail = NULL; @@ -173,6 +178,9 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->destruction) GNUNET_SCHEDULER_cancel(handle->destruction); + if (handle->disconnection) + GNUNET_SCHEDULER_cancel(handle->disconnection); + if (handle->monitor) GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); @@ -232,6 +240,23 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->identity) GNUNET_IDENTITY_disconnect(handle->identity); + struct GNUNET_CHAT_InternalServices *services; + while (handle->services_head) + { + services = handle->services_head; + + if (services->op) + GNUNET_ARM_operation_cancel(services->op); + + GNUNET_CONTAINER_DLL_remove( + handle->services_head, + handle->services_tail, + services + ); + + GNUNET_free(services); + } + if (handle->arm) GNUNET_ARM_disconnect(handle->arm); diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -43,6 +43,14 @@ struct GNUNET_CHAT_Handle; +struct GNUNET_CHAT_InternalServices +{ + struct GNUNET_CHAT_Handle *chat; + struct GNUNET_ARM_Operation *op; + struct GNUNET_CHAT_InternalServices *next; + struct GNUNET_CHAT_InternalServices *prev; +}; + struct GNUNET_CHAT_InternalMessages { struct GNUNET_CHAT_Message *msg; @@ -116,6 +124,10 @@ struct GNUNET_CHAT_Handle const struct GNUNET_CONFIGURATION_Handle* cfg; struct GNUNET_SCHEDULER_Task *shutdown_hook; struct GNUNET_SCHEDULER_Task *destruction; + struct GNUNET_SCHEDULER_Task *disconnection; + + struct GNUNET_CHAT_InternalServices *services_head; + struct GNUNET_CHAT_InternalServices *services_tail; struct GNUNET_CHAT_InternalMessages *internal_head; struct GNUNET_CHAT_InternalMessages *internal_tail; diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -32,6 +32,7 @@ #include "gnunet_chat_ticket.h" #include "gnunet_chat_util.h" +#include <gnunet/gnunet_arm_service.h> #include <gnunet/gnunet_common.h> #include <gnunet/gnunet_identity_service.h> #include <gnunet/gnunet_messenger_service.h> @@ -64,55 +65,75 @@ on_handle_shutdown(void *cls) } void -on_handle_arm_connection(void *cls, - int connected) +on_handle_service_request(void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { - struct GNUNET_CHAT_Handle *chat = cls; + GNUNET_assert(cls); - GNUNET_assert((chat) && (chat->arm)); + struct GNUNET_CHAT_InternalServices *services = cls; + services->op = NULL; - if (GNUNET_YES == connected) { - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_identity, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + if (status != GNUNET_ARM_REQUEST_SENT_OK) + return; - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_messenger, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + struct GNUNET_CHAT_Handle *chat = services->chat; - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_fs, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + GNUNET_CONTAINER_DLL_remove( + chat->services_head, + chat->services_tail, + services + ); - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_gns, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + GNUNET_free(services); +} - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_namestore, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); +static void +_request_service_via_arm(struct GNUNET_CHAT_Handle *chat, + const char *service_name) +{ + GNUNET_assert((chat) && (chat->arm) && (service_name)); - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_reclaim, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + struct GNUNET_CHAT_InternalServices *services = GNUNET_new( + struct GNUNET_CHAT_InternalServices + ); + + if (! services) + return; + + services->chat = chat; + services->op = GNUNET_ARM_request_service_start( + chat->arm, + service_name, + GNUNET_OS_INHERIT_STD_NONE, + on_handle_service_request, + services + ); + + GNUNET_CONTAINER_DLL_insert( + chat->services_head, + chat->services_tail, + services + ); +} + +void +on_handle_arm_connection(void *cls, + int connected) +{ + struct GNUNET_CHAT_Handle *chat = cls; + + GNUNET_assert((chat) && (chat->arm)); + + if (GNUNET_YES == connected) { + _request_service_via_arm(chat, gnunet_service_name_identity); + _request_service_via_arm(chat, gnunet_service_name_messenger); + _request_service_via_arm(chat, gnunet_service_name_fs); + _request_service_via_arm(chat, gnunet_service_name_gns); + _request_service_via_arm(chat, gnunet_service_name_namestore); + _request_service_via_arm(chat, gnunet_service_name_reclaim); } else { - GNUNET_ARM_request_service_start( - chat->arm, gnunet_service_name_arm, - GNUNET_OS_INHERIT_STD_NONE, - NULL, NULL - ); + _request_service_via_arm(chat, gnunet_service_name_arm); } } @@ -266,12 +287,6 @@ cb_task_finish_ticket_update (void *cls) struct GNUNET_CHAT_Handle *handle = tickets->handle; - if (tickets->iter) - GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); - - if (tickets->op) - GNUNET_RECLAIM_cancel(tickets->op); - GNUNET_CONTAINER_DLL_remove( handle->tickets_head, handle->tickets_tail, @@ -327,6 +342,7 @@ cont_revoke_ticket_with_status (void *cls, if (tickets->iter) GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); + tickets->iter = NULL; return; } diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -28,6 +28,7 @@ #include <gnunet/gnunet_messenger_service.h> #include <gnunet/gnunet_reclaim_lib.h> #include <gnunet/gnunet_reclaim_service.h> +#include <gnunet/gnunet_scheduler_lib.h> #include <gnunet/gnunet_time_lib.h> #include <libgen.h> #include <limits.h> @@ -181,10 +182,14 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle) { GNUNET_CHAT_VERSION_ASSERT(); - if ((!handle) || (handle->destruction) || (!(handle->current))) + if ((!handle) || (handle->destruction) || + (!(handle->current)) || (handle->disconnection)) return; - handle_disconnect(handle); + handle->disconnection = GNUNET_SCHEDULER_add_now( + task_handle_disconnection, + handle + ); } @@ -1005,28 +1010,14 @@ GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) { GNUNET_CHAT_VERSION_ASSERT(); - if (!group) + if ((!group) || (group->destruction)) return GNUNET_SYSERR; - const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( - group->context->room - ); - - GNUNET_CONTAINER_multihashmap_remove( - group->handle->groups, key, group - ); - - GNUNET_CONTAINER_multihashmap_remove( - group->handle->contexts, key, group->context + group->destruction = GNUNET_SCHEDULER_add_now( + task_group_destruction, + group ); - GNUNET_MESSENGER_close_room(group->context->room); - - group->context->deleted = GNUNET_YES; - context_write_records(group->context); - - context_destroy(group->context); - group_destroy(group); return GNUNET_OK; } diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -66,6 +66,17 @@ task_handle_destruction (void *cls) } void +task_handle_disconnection (void *cls) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; + + handle_disconnect(handle); + handle->disconnection = NULL; +} + +void cb_lobby_lookup (void *cls, uint32_t count, const struct GNUNET_GNSRECORD_Data *data) @@ -209,6 +220,36 @@ it_room_find_contact (void *cls, return GNUNET_NO; } +void +task_group_destruction (void *cls) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_Group *group = (struct GNUNET_CHAT_Group*) cls; + + const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( + group->context->room + ); + + GNUNET_CONTAINER_multihashmap_remove( + group->handle->groups, key, group + ); + + GNUNET_CONTAINER_multihashmap_remove( + group->handle->contexts, key, group->context + ); + + GNUNET_MESSENGER_close_room(group->context->room); + + group->context->deleted = GNUNET_YES; + context_write_records(group->context); + + group->destruction = NULL; + + context_destroy(group->context); + group_destroy(group); +} + struct GNUNET_CHAT_GroupIterateContacts { const struct GNUNET_CHAT_Group *group; diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2023 GNUnet e.V. + Copyright (C) 2021--2024 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -23,6 +23,7 @@ */ #include "test_gnunet_chat.h" +#include <gnunet/gnunet_chat_lib.h> void call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg) @@ -59,8 +60,8 @@ on_gnunet_chat_handle_accounts_it(void *cls, int on_gnunet_chat_handle_accounts_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { static unsigned int accounts_stage = 0; @@ -75,17 +76,17 @@ on_gnunet_chat_handle_accounts_msg(void *cls, ck_assert_ptr_eq(context, NULL); GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_handle_accounts_it, - &accounts_stage + handle, + on_gnunet_chat_handle_accounts_it, + &accounts_stage ); if (2 & accounts_stage) { if (3 == accounts_stage) ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - "gnunet_chat_handle_accounts" + handle, + "gnunet_chat_handle_accounts" ), GNUNET_OK); accounts_stage = 4; @@ -95,8 +96,8 @@ on_gnunet_chat_handle_accounts_msg(void *cls, else if (0 == accounts_stage) { ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - "gnunet_chat_handle_accounts" + handle, + "gnunet_chat_handle_accounts" ), GNUNET_OK); accounts_stage = 1; @@ -118,8 +119,8 @@ CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_acc int on_gnunet_chat_handle_connection_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; @@ -143,8 +144,8 @@ on_gnunet_chat_handle_connection_it(void *cls, int on_gnunet_chat_handle_connection_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { struct GNUNET_CHAT_Handle *handle = *( (struct GNUNET_CHAT_Handle**) cls @@ -154,13 +155,24 @@ on_gnunet_chat_handle_connection_msg(void *cls, ck_assert_ptr_eq(context, NULL); ck_assert_ptr_ne(message, NULL); + if (GNUNET_CHAT_KIND_LOGOUT == GNUNET_CHAT_message_get_kind(message)) + { + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + "gnunet_chat_handle_connection" + ), GNUNET_OK); + + GNUNET_CHAT_stop(handle); + return GNUNET_YES; + } + if (GNUNET_CHAT_KIND_LOGIN == GNUNET_CHAT_message_get_kind(message)) goto skip_iteration; GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_handle_connection_it, - handle + handle, + on_gnunet_chat_handle_connection_it, + handle ); skip_iteration: @@ -168,13 +180,6 @@ skip_iteration: return GNUNET_YES; GNUNET_CHAT_disconnect(handle); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - "gnunet_chat_handle_connection" - ), GNUNET_OK); - - GNUNET_CHAT_stop(handle); return GNUNET_YES; } @@ -186,8 +191,8 @@ call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg ck_assert_ptr_ne(handle, NULL); ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - "gnunet_chat_handle_connection" + handle, + "gnunet_chat_handle_connection" ), GNUNET_OK); } @@ -195,8 +200,8 @@ CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_c int on_gnunet_chat_handle_update_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; @@ -220,11 +225,13 @@ on_gnunet_chat_handle_update_it(void *cls, int on_gnunet_chat_handle_update_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { + static unsigned int update_stage = 0; + struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls + (struct GNUNET_CHAT_Handle**) cls ); ck_assert_ptr_ne(handle, NULL); @@ -237,15 +244,29 @@ on_gnunet_chat_handle_update_msg(void *cls, goto skip_search_account; GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_handle_update_it, - handle + handle, + on_gnunet_chat_handle_update_it, + handle ); if (!GNUNET_CHAT_get_connected(handle)) return GNUNET_YES; skip_search_account: + if (GNUNET_CHAT_KIND_LOGOUT == kind) + { + if (update_stage < 2) + return GNUNET_YES; + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + "gnunet_chat_handle_update" + ), GNUNET_OK); + + GNUNET_CHAT_stop(handle); + return GNUNET_YES; + } + if (GNUNET_CHAT_KIND_LOGIN != kind) return GNUNET_YES; @@ -263,6 +284,8 @@ skip_search_account: GNUNET_CHAT_set_user_pointer(handle, (void*) dup); GNUNET_CHAT_update(handle); + + update_stage = 1; } else { @@ -273,12 +296,7 @@ skip_search_account: GNUNET_CHAT_disconnect(handle); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - "gnunet_chat_handle_update" - ), GNUNET_OK); - - GNUNET_CHAT_stop(handle); + update_stage = 2; } return GNUNET_YES; @@ -292,8 +310,8 @@ call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg) ck_assert_ptr_ne(handle, NULL); ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - "gnunet_chat_handle_update" + handle, + "gnunet_chat_handle_update" ), GNUNET_OK); } @@ -301,8 +319,8 @@ CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_updat int on_gnunet_chat_handle_rename_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; @@ -326,8 +344,8 @@ on_gnunet_chat_handle_rename_it(void *cls, int on_gnunet_chat_handle_rename_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { struct GNUNET_CHAT_Handle *handle = *( (struct GNUNET_CHAT_Handle**) cls @@ -343,15 +361,26 @@ on_gnunet_chat_handle_rename_msg(void *cls, goto skip_search_account; GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_handle_rename_it, - handle + handle, + on_gnunet_chat_handle_rename_it, + handle ); if (!GNUNET_CHAT_get_connected(handle)) return GNUNET_YES; skip_search_account: + if (GNUNET_CHAT_KIND_LOGOUT == kind) + { + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + "gnunet_chat_handle_rename_b" + ), GNUNET_OK); + + GNUNET_CHAT_stop(handle); + return GNUNET_YES; + } + if (GNUNET_CHAT_KIND_LOGIN != kind) return GNUNET_YES; @@ -370,8 +399,8 @@ skip_search_account: GNUNET_CHAT_set_user_pointer(handle, (void*) dup); ck_assert_int_eq(GNUNET_CHAT_set_name( - handle, - "gnunet_chat_handle_rename_b" + handle, + "gnunet_chat_handle_rename_b" ), GNUNET_YES); } else if (0 != strcmp(name, dup)) @@ -382,13 +411,6 @@ skip_search_account: GNUNET_free(dup); GNUNET_CHAT_disconnect(handle); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - "gnunet_chat_handle_rename_b" - ), GNUNET_OK); - - GNUNET_CHAT_stop(handle); } return GNUNET_YES; @@ -402,8 +424,8 @@ call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg) ck_assert_ptr_ne(handle, NULL); ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - "gnunet_chat_handle_rename_a" + handle, + "gnunet_chat_handle_rename_a" ), GNUNET_OK); } diff --git a/tests/test_gnunet_chat_message.c b/tests/test_gnunet_chat_message.c @@ -24,12 +24,13 @@ #include "test_gnunet_chat.h" #include <check.h> +#include <gnunet/gnunet_chat_lib.h> #include <stdio.h> int on_gnunet_chat_message_text_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; @@ -53,11 +54,11 @@ on_gnunet_chat_message_text_it(void *cls, int on_gnunet_chat_message_text_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) { struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls + (struct GNUNET_CHAT_Handle**) cls ); ck_assert_ptr_ne(handle, NULL); @@ -67,9 +68,9 @@ on_gnunet_chat_message_text_msg(void *cls, goto skip_search_account; GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_message_text_it, - handle + handle, + on_gnunet_chat_message_text_it, + handle ); if (!GNUNET_CHAT_get_connected(handle)) @@ -91,6 +92,14 @@ skip_search_account: GNUNET_CHAT_group_get_context(group), "test_text_message" ), GNUNET_OK); break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + "gnunet_chat_message_text" + ), GNUNET_OK); + + GNUNET_CHAT_stop(handle); + break; case GNUNET_CHAT_KIND_TEXT: ck_assert_ptr_ne(context, NULL); @@ -101,12 +110,8 @@ skip_search_account: ck_assert_int_eq(strcmp(text, "test_text_message"), 0); ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - "gnunet_chat_message_text" - ), GNUNET_OK); - GNUNET_CHAT_stop(handle); + GNUNET_CHAT_disconnect(handle); break; default: break; @@ -123,8 +128,8 @@ call_gnunet_chat_message_text(const struct GNUNET_CONFIGURATION_Handle *cfg) ck_assert_ptr_ne(handle, NULL); ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - "gnunet_chat_message_text" + handle, + "gnunet_chat_message_text" ), GNUNET_OK); }