libgnunetchat

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

commit 20fea02015ce7846fd96a256d13dfba1c393e4a2
parent 2db1df44bb874044c7b70f873d7eb8698f5644fd
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun, 21 Jul 2024 01:11:07 +0200

Fix some internal messages to be instant feedback for warnings and pre-destruction handling

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

Diffstat:
Msrc/gnunet_chat_account.c | 3++-
Msrc/gnunet_chat_context.c | 3++-
Msrc/gnunet_chat_context_intern.c | 3++-
Msrc/gnunet_chat_handle.c | 26+++++++++++++++++++-------
Msrc/gnunet_chat_handle.h | 8+++++++-
Msrc/gnunet_chat_handle_intern.c | 21++++++++++++++-------
Msrc/gnunet_chat_lib_intern.c | 18++++++++++++------
Msrc/gnunet_chat_lobby_intern.c | 6++++--
Mtests/test_gnunet_chat.h | 1+
Mtests/test_gnunet_chat_handle.c | 11+++++++----
10 files changed, 70 insertions(+), 30 deletions(-)

diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c @@ -137,7 +137,8 @@ account_update_ego (struct GNUNET_CHAT_Account *account, account, NULL, flag, - NULL + NULL, + GNUNET_YES ); } diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c @@ -276,7 +276,8 @@ context_update_nick (struct GNUNET_CHAT_Context *context, NULL, context, GNUNET_CHAT_FLAG_UPDATE_CONTEXT, - NULL + NULL, + GNUNET_NO ); } diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c @@ -145,6 +145,7 @@ cont_context_write_records (void *cls, NULL, context, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); } diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -302,7 +302,8 @@ handle_update_identity(struct GNUNET_CHAT_Handle *handle) handle->current, NULL, GNUNET_CHAT_FLAG_LOGIN, - NULL + NULL, + GNUNET_NO ); const struct GNUNET_CRYPTO_PrivateKey *zone = handle_get_key(handle); @@ -382,7 +383,8 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) handle->current, NULL, GNUNET_CHAT_FLAG_LOGOUT, - NULL + NULL, + GNUNET_YES ); while (handle->attributes_head) @@ -791,7 +793,8 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, const struct GNUNET_CHAT_Account *account, struct GNUNET_CHAT_Context *context, enum GNUNET_CHAT_MessageFlag flag, - const char *warning) + const char *warning, + enum GNUNET_GenericReturnValue feedback) { GNUNET_assert((handle) && (GNUNET_CHAT_FLAG_NONE != flag)); @@ -813,9 +816,17 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, return; } - internal->task = GNUNET_SCHEDULER_add_now( - on_handle_internal_message_callback, internal - ); + if (GNUNET_YES != feedback) + internal->task = GNUNET_SCHEDULER_add_now( + on_handle_internal_message_callback, + internal + ); + else + { + internal->task = NULL; + if (handle->msg_cb) + handle->msg_cb(handle->msg_cls, context, internal->msg); + } if (context) GNUNET_CONTAINER_DLL_insert( @@ -960,7 +971,8 @@ setup_group: NULL, context, GNUNET_CHAT_FLAG_UPDATE_CONTEXT, - NULL + NULL, + GNUNET_NO ); context_write_records(context); diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -292,18 +292,24 @@ handle_get_key (const struct GNUNET_CHAT_Handle *handle); * <i>context</i>, a custom <i>flag</i> and an optional * <i>warning</i> text. * + * You can select whether the callback for the internal + * message should be scheduled dynamically or be called + * as instant feedback. + * * @param[in,out] handle Chat handle * @param[in] account Chat account or NULL * @param[in,out] context Chat context or NULL * @param[in] flag Chat message flag * @param[in] warning Warning text + * @param[in] feedback Instant feedback */ void handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, const struct GNUNET_CHAT_Account *account, struct GNUNET_CHAT_Context *context, enum GNUNET_CHAT_MessageFlag flag, - const char *warning); + const char *warning, + enum GNUNET_GenericReturnValue feedback); /** * Sends a name message to a messenger <i>room</i> with diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -292,7 +292,8 @@ on_handle_refresh (void *cls) NULL, NULL, GNUNET_CHAT_FLAG_REFRESH, - NULL + NULL, + GNUNET_YES ); } @@ -331,7 +332,8 @@ on_handle_gnunet_identity (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_UPDATE_ACCOUNT, - NULL + NULL, + GNUNET_YES ); } else if (!(accounts->op)) @@ -407,7 +409,8 @@ cb_account_creation (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); } @@ -434,7 +437,8 @@ cb_account_deletion (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); else { @@ -443,7 +447,8 @@ cb_account_deletion (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_DELETE_ACCOUNT, - NULL + NULL, + GNUNET_YES ); account_delete(accounts->account); @@ -475,7 +480,8 @@ cb_account_rename (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); } @@ -499,7 +505,8 @@ cb_lobby_deletion (void *cls, accounts->account, NULL, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); internal_accounts_destroy(accounts); diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -549,7 +549,8 @@ cont_update_attribute_with_status (void *cls, account, NULL, GNUNET_CHAT_KIND_WARNING, - emsg + emsg, + GNUNET_YES ); else handle_send_internal_message( @@ -557,7 +558,8 @@ cont_update_attribute_with_status (void *cls, account, NULL, GNUNET_CHAT_FLAG_ATTRIBUTES, - attribute_name + attribute_name, + GNUNET_YES ); internal_attributes_destroy(attributes); @@ -624,7 +626,8 @@ cb_task_error_iterate_attribute (void *cls) attributes->account, NULL, GNUNET_CHAT_FLAG_WARNING, - "Attribute iteration failed!" + "Attribute iteration failed!", + GNUNET_YES ); cb_task_finish_iterate_attribute(cls); @@ -949,7 +952,8 @@ cb_task_error_iterate_ticket (void *cls) NULL, NULL, GNUNET_CHAT_FLAG_WARNING, - "Ticket iteration failed!" + "Ticket iteration failed!", + GNUNET_YES ); cb_task_finish_iterate_ticket(cls); @@ -976,7 +980,8 @@ cont_revoke_ticket (void *cls, NULL, NULL, GNUNET_CHAT_FLAG_WARNING, - emsg + emsg, + GNUNET_YES ); else handle_send_internal_message( @@ -984,7 +989,8 @@ cont_revoke_ticket (void *cls, NULL, NULL, GNUNET_CHAT_FLAG_SHARE_ATTRIBUTES, - NULL + NULL, + GNUNET_NO ); internal_tickets_destroy(tickets); diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c @@ -47,7 +47,8 @@ cont_lobby_write_records (void *cls, NULL, lobby->context, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); if (lobby->uri) @@ -78,7 +79,8 @@ cont_lobby_identity_create (void *cls, NULL, lobby->context, GNUNET_CHAT_FLAG_WARNING, - GNUNET_ErrorCode_get_hint(ec) + GNUNET_ErrorCode_get_hint(ec), + GNUNET_YES ); return; diff --git a/tests/test_gnunet_chat.h b/tests/test_gnunet_chat.h @@ -90,6 +90,7 @@ int main (void) \ SRunner *runner; \ \ runner = srunner_create(suite_name ()); \ + srunner_set_fork_status(runner, CK_NOFORK); \ srunner_run_all(runner, suite_check); \ \ tests_failed = srunner_ntests_failed(runner); \ diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c @@ -85,6 +85,9 @@ on_gnunet_chat_handle_accounts_msg(void *cls, const struct GNUNET_CHAT_Account *account; account = GNUNET_CHAT_message_get_account(message); + const char *name; + name = GNUNET_CHAT_account_get_name(account); + switch (GNUNET_CHAT_message_get_kind(message)) { case GNUNET_CHAT_KIND_WARNING: @@ -122,17 +125,17 @@ on_gnunet_chat_handle_accounts_msg(void *cls, break; case GNUNET_CHAT_KIND_CREATED_ACCOUNT: ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); - if (0 == strcmp(GNUNET_CHAT_account_get_name(account), - TEST_ACCOUNTS_ID)) + if (0 == strcmp(name, TEST_ACCOUNTS_ID)) accounts_stage = 2; break; case GNUNET_CHAT_KIND_DELETED_ACCOUNT: ck_assert_int_eq(accounts_stage, 4); + ck_assert_ptr_nonnull(name); - if (0 == strcmp(GNUNET_CHAT_account_get_name(account), - TEST_ACCOUNTS_ID)) + if (0 == strcmp(name, TEST_ACCOUNTS_ID)) GNUNET_CHAT_stop(handle); break;