libgnunetchat

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

commit e9081a700fc49b6b53746e001000065519cc939c
parent 1ce8e8bddaab6363fdb700454f5ab56992b54a54
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 22 Apr 2024 22:51:14 +0200

Fix context requirements in internal functions

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

Diffstat:
Msrc/gnunet_chat_contact.c | 15+++++++++++----
Msrc/gnunet_chat_contact.h | 4+++-
Msrc/gnunet_chat_lib.c | 17+++++++++++++----
Msrc/gnunet_chat_lib_intern.c | 5+++--
Msrc/gnunet_chat_ticket_intern.c | 12+++++++++++-
5 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -148,11 +148,13 @@ contact_get_key (const struct GNUNET_CHAT_Contact *contact) } struct GNUNET_CHAT_Context* -contact_find_context (const struct GNUNET_CHAT_Contact *contact) +contact_find_context (const struct GNUNET_CHAT_Contact *contact, + enum GNUNET_GenericReturnValue room_required) { GNUNET_assert(contact); - if (contact->context) + if ((contact->context) && + ((GNUNET_YES != room_required) || (contact->context->room))) return contact->context; struct GNUNET_CHAT_ContactFindRoom find; @@ -169,10 +171,15 @@ contact_find_context (const struct GNUNET_CHAT_Contact *contact) if (!(find.room)) return NULL; - return GNUNET_CONTAINER_multihashmap_get( + struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( contact->handle->contexts, GNUNET_MESSENGER_room_get_key(find.room) ); + + if ((GNUNET_YES == room_required) && (!(context->room))) + return NULL; + + return context; } const struct GNUNET_HashCode* @@ -408,7 +415,7 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact) GNUNET_CONTAINER_multihashmap_destroy(contact->joined); } - if ((contact->context) && (!contact->context->room)) + if ((contact->context) && (!(contact->context->room))) context_destroy(contact->context); GNUNET_free(contact); diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h @@ -110,10 +110,12 @@ contact_get_key (const struct GNUNET_CHAT_Contact *contact); * <i>contact</i> and the least amount of other members. * * @param[in] contact Chat contact + * @param[in] room_required Flag to suggest a room is required * @return Chat context or NULL */ struct GNUNET_CHAT_Context* -contact_find_context (const struct GNUNET_CHAT_Contact *contact); +contact_find_context (const struct GNUNET_CHAT_Contact *contact, + enum GNUNET_GenericReturnValue room_required); /** * Returns whether a chat <i>contact</i> is tagged in diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -1185,7 +1185,10 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact) if (contact->context) return contact->context; - struct GNUNET_CHAT_Context *context = contact_find_context(contact); + struct GNUNET_CHAT_Context *context = contact_find_context( + contact, + GNUNET_NO + ); if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_CONTACT == context->type)) goto attach_return; @@ -1442,7 +1445,10 @@ GNUNET_CHAT_group_invite_contact (const struct GNUNET_CHAT_Group *group, if ((!group) || (!contact) || (!contact->member)) return; - struct GNUNET_CHAT_Context *context = contact_find_context(contact); + struct GNUNET_CHAT_Context *context = contact_find_context( + contact, + GNUNET_YES + ); if (!context) return; @@ -1576,9 +1582,12 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; - struct GNUNET_CHAT_Context *other = contact_find_context(contact); + struct GNUNET_CHAT_Context *other = contact_find_context( + contact, + GNUNET_YES + ); - if ((!other) || (!(other->room))) + if (!other) goto cleanup_contact; struct GNUNET_HashCode key; diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -711,10 +711,11 @@ cb_issue_ticket (void *cls, struct GNUNET_CHAT_Handle *handle = attributes->handle; struct GNUNET_CHAT_Context *context = contact_find_context( - attributes->contact + attributes->contact, + GNUNET_YES ); - if ((context) && (context->room) && (ticket)) + if ((context) && (ticket)) GNUNET_MESSENGER_send_ticket(context->room, ticket); GNUNET_CONTAINER_DLL_remove( diff --git a/src/gnunet_chat_ticket_intern.c b/src/gnunet_chat_ticket_intern.c @@ -22,6 +22,7 @@ * @file gnunet_chat_ticket_intern.c */ +#include <gnunet/gnunet_common.h> #include <gnunet/gnunet_reclaim_lib.h> #define GNUNET_UNUSED __attribute__ ((unused)) @@ -38,7 +39,13 @@ cb_ticket_consume_attribute (void *cls, (struct GNUNET_CHAT_Ticket*) cls ); - const char *value = GNUNET_RECLAIM_attribute_value_to_string( + if (!attribute) + { + ticket->op = NULL; + return; + } + + char *value = GNUNET_RECLAIM_attribute_value_to_string( attribute->type, attribute->data, attribute->data_size @@ -46,4 +53,7 @@ cb_ticket_consume_attribute (void *cls, if (ticket->callback) ticket->callback(ticket->closure, ticket->issuer, attribute->name, value); + + if (value) + GNUNET_free(value); }