libgnunetchat

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

commit 5e91c20728b8c8fbad9df2f56338acce1325aa3f
parent 07dfa4175378db8b25d9d9024b5bf4391bf45561
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun,  6 Oct 2024 21:27:20 +0200

Adjust API to be more consistent

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

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 15+++++++++------
Msrc/gnunet_chat_contact.c | 16+++++++++-------
Msrc/gnunet_chat_contact.h | 3++-
Msrc/gnunet_chat_lib.c | 34+++++++++++++++++++---------------
Msrc/internal/gnunet_chat_tagging.h | 1+
5 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h @@ -1116,11 +1116,12 @@ GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, * @param[in] contact Chat contact * @param[in] callback Callback for tag iteration (optional) * @param[in,out] cls Closure for tag iteration (optional) + * @return Amount of tags iterated or #GNUNET_SYSERR on failure */ -void -GNUNET_CHAT_contact_get_tags (struct GNUNET_CHAT_Contact *contact, - GNUNET_CHAT_ContactTagCallback callback, - void *cls); +int +GNUNET_CHAT_contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, + GNUNET_CHAT_ContactTagCallback callback, + void *cls); /** * Calls an optional <i>callback</i> for each attribute of a given chat @@ -1192,8 +1193,9 @@ GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group); * * @param[in,out] group Group * @param[in,out] contact Contact + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ -void +enum GNUNET_GenericReturnValue GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, struct GNUNET_CHAT_Contact *contact); @@ -1263,8 +1265,9 @@ GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context); * receivement of new messages. * * @param[in,out] context Context + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ -void +enum GNUNET_GenericReturnValue GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context); /** diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -389,7 +389,7 @@ skip_tag_search: GNUNET_free(tag_value); } -void +int contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, struct GNUNET_CHAT_Context *context, GNUNET_CHAT_ContactTagCallback callback, @@ -406,7 +406,9 @@ contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, it.cls = cls; if (! (it.tags)) - return; + return GNUNET_SYSERR; + + int result = GNUNET_SYSERR; struct GNUNET_CONTAINER_MultiHashMapIterator *iter; iter = GNUNET_CONTAINER_multihashmap_iterator_create( @@ -429,7 +431,7 @@ contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, contact->handle->contexts, &key); if (context) - contact_iterate_tags( + result = contact_iterate_tags( contact, context, it_contact_iterate_unique_tag, @@ -441,14 +443,14 @@ contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, free_tags_iteration: GNUNET_CONTAINER_multihashmap_destroy(it.tags); - return; + return result; } const struct GNUNET_HashCode *hash = get_contact_join_hash( contact, context); if (! hash) - return; + return GNUNET_SYSERR; const struct GNUNET_CHAT_InternalTagging *tagging = GNUNET_CONTAINER_multihashmap_get( context->taggings, @@ -456,14 +458,14 @@ free_tags_iteration: ); if (! tagging) - return; + return 0; struct GNUNET_CHAT_ContactIterateTag it; it.contact = contact; it.callback = callback; it.cls = cls; - internal_tagging_iterate( + return internal_tagging_iterate( tagging, GNUNET_YES, NULL, diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h @@ -167,8 +167,9 @@ contact_tag (struct GNUNET_CHAT_Contact *contact, * @param[in,out] context Chat context or NULL * @param[in] callback Callback for tag iteration or NULL * @param[in,out] cls Closure for tag iteration or NULL + * @return Amount of tags iterated or #GNUNET_SYSERR on error */ -void +int contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, struct GNUNET_CHAT_Context *context, GNUNET_CHAT_ContactTagCallback callback, diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -1332,17 +1332,17 @@ GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, } -void -GNUNET_CHAT_contact_get_tags (struct GNUNET_CHAT_Contact *contact, - GNUNET_CHAT_ContactTagCallback callback, - void *cls) +int +GNUNET_CHAT_contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, + GNUNET_CHAT_ContactTagCallback callback, + void *cls) { GNUNET_CHAT_VERSION_ASSERT(); if (!contact) - return; + return GNUNET_SYSERR; - contact_iterate_tags( + return contact_iterate_tags( contact, NULL, callback, @@ -1451,14 +1451,14 @@ GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group) } -void +enum GNUNET_GenericReturnValue GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, struct GNUNET_CHAT_Contact *contact) { GNUNET_CHAT_VERSION_ASSERT(); if ((!group) || (!contact) || (!contact->member)) - return; + return GNUNET_SYSERR; struct GNUNET_CHAT_Context *context = contact_find_context( contact, @@ -1466,7 +1466,7 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, ); if (!context) - return; + return GNUNET_SYSERR; const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( group->context->room @@ -1484,6 +1484,7 @@ GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, GNUNET_memcpy(&(msg.body.invite.key), key, sizeof(msg.body.invite.key)); GNUNET_MESSENGER_send_message(context->room, &msg, contact->member); + return GNUNET_OK; } @@ -1577,25 +1578,27 @@ GNUNET_CHAT_context_get_status (const struct GNUNET_CHAT_Context *context) } -void +enum GNUNET_GenericReturnValue GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) { GNUNET_CHAT_VERSION_ASSERT(); - if ((!context) || (context->room)) - return; + if (!context) + return GNUNET_SYSERR; + else if (context->room) + return GNUNET_OK; struct GNUNET_CHAT_Handle *handle = context->handle; if ((!handle) || (!(context->contact))) - return; + return GNUNET_SYSERR; struct GNUNET_CHAT_Contact *contact = contact_create_from_member( handle, context->contact ); if (!contact) - return; + return GNUNET_SYSERR; context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; @@ -1638,13 +1641,14 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); GNUNET_MESSENGER_send_message(other->room, &msg, context->contact); - return; + return GNUNET_OK; cleanup_room: GNUNET_MESSENGER_close_room(room); cleanup_contact: contact_destroy(contact); + return GNUNET_SYSERR; } diff --git a/src/internal/gnunet_chat_tagging.h b/src/internal/gnunet_chat_tagging.h @@ -96,6 +96,7 @@ internal_tagging_remove (struct GNUNET_CHAT_InternalTagging *tagging, * @param[in] tag Tag value for filtering the iteration * @param[in] cb Callback for iteration * @param[in,out] cls Closure for iteration + * @return Amount of tags iterated or #GNUNET_SYSERR on error */ int internal_tagging_iterate (const struct GNUNET_CHAT_InternalTagging *tagging,