libgnunetchat

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

commit 56b4e95cd59010900c1bc92005b277123b37f69d
parent e6062f4a30a55053011e67c4ef1733f9ab650bec
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun, 28 Apr 2024 20:39:14 +0200

Fix automatic lobby deletion

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

Diffstat:
Msrc/gnunet_chat_handle.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Msrc/gnunet_chat_handle.h | 12++++++++++++
Msrc/gnunet_chat_handle_intern.c | 26++++++++++++++++++++++++++
Msrc/gnunet_chat_lobby.c | 16+---------------
4 files changed, 84 insertions(+), 15 deletions(-)

diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -645,6 +645,51 @@ handle_rename_account (struct GNUNET_CHAT_Handle *handle, return result; } +enum GNUNET_GenericReturnValue +handle_delete_lobby (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CHAT_Lobby *lobby) +{ + GNUNET_assert((handle) && (lobby)); + + if (!(lobby->context)) + return GNUNET_SYSERR; + + const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( + lobby->context->room + ); + + if (!key) + return GNUNET_SYSERR; + + struct GNUNET_CHAT_InternalAccounts *accounts = NULL; + enum GNUNET_GenericReturnValue result = update_accounts_operation( + &accounts, + handle, + NULL, + GNUNET_CHAT_ACCOUNT_DELETION + ); + + if (GNUNET_OK != result) + return result; + + char *name; + util_lobby_name(key, &name); + + accounts->op = GNUNET_IDENTITY_delete( + handle->identity, + name, + cb_lobby_deletion, + accounts + ); + + GNUNET_free(name); + + if (!accounts->op) + return GNUNET_SYSERR; + + return result; +} + const char* handle_get_directory (const struct GNUNET_CHAT_Handle *handle) { diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -228,6 +228,18 @@ handle_rename_account (struct GNUNET_CHAT_Handle *handle, const char *new_name); /** + * Enqueues a deletion for a chat <i>lobby</i> for a + * given chat <i>handle</i>. + * + * @param[in,out] handle Chat handle + * @param[in] lobby Chat lobby + * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR + */ +enum GNUNET_GenericReturnValue +handle_delete_lobby (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CHAT_Lobby *lobby); + +/** * Returns the main directory path to store information * of a given chat <i>handle</i>. * diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -450,6 +450,32 @@ cb_account_rename (void *cls, ); } +void +cb_lobby_deletion (void *cls, + enum GNUNET_ErrorCode ec) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_InternalAccounts *accounts = ( + (struct GNUNET_CHAT_InternalAccounts*) cls + ); + + accounts->op = NULL; + + internal_accounts_stop_method(accounts); + + if (GNUNET_EC_NONE != ec) + handle_send_internal_message( + accounts->handle, + accounts->account, + NULL, + GNUNET_CHAT_FLAG_WARNING, + GNUNET_ErrorCode_get_hint(ec) + ); + + internal_accounts_destroy(accounts); +} + static void cb_account_update_completion (void *cls, const struct GNUNET_CRYPTO_PrivateKey *key, diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c @@ -56,21 +56,7 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby) if ((!(lobby->op)) && (!(lobby->query))) goto skip_deletion; - if (lobby->context) - { - const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( - lobby->context->room - ); - - if (!key) - goto skip_deletion; - - char *name; - util_lobby_name(key, &name); - - handle_delete_account(lobby->handle, name); - GNUNET_free(name); - } + handle_delete_lobby(lobby->handle, lobby); skip_deletion: if (lobby->op)