commit 196a4ebac19eb5c673eb343ff1d48defe43ad68b
parent 1359cceb2003ad96a57a1e8ecac99ed00da80bb9
Author: Jacki <jacki@thejackimonster.de>
Date: Sun, 11 Feb 2024 09:03:51 +0100
Fix selection of context for blocked state
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
3 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -172,11 +172,41 @@ contact_is_blocked (const struct GNUNET_CHAT_Contact *contact,
{
GNUNET_assert(
(contact) &&
- (contact->joined) &&
- (context)
+ (contact->joined)
);
- if (!(context->room))
+ const enum GNUNET_GenericReturnValue general = (
+ context ? GNUNET_NO : GNUNET_YES
+ );
+
+ if (context)
+ goto skip_context_search;
+
+ struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
+ iter = GNUNET_CONTAINER_multihashmap_iterator_create(
+ contact->handle->contexts
+ );
+
+ if (iter)
+ {
+ struct GNUNET_HashCode key;
+ const void *value;
+
+ while (! context)
+ {
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_iterator_next(
+ iter, &key, &value))
+ break;
+
+ context = GNUNET_CONTAINER_multihashmap_get(
+ contact->handle->contexts, &key);
+ }
+
+ GNUNET_CONTAINER_multihashmap_iterator_destroy(iter);
+ }
+
+skip_context_search:
+ if ((! context) || (!(context->room)))
return GNUNET_NO;
const struct GNUNET_HashCode *hash;
@@ -186,7 +216,10 @@ contact_is_blocked (const struct GNUNET_CHAT_Contact *contact,
);
if (! hash)
- return GNUNET_YES;
+ return (general == GNUNET_YES?
+ GNUNET_NO :
+ contact_is_blocked(contact, NULL)
+ );
struct GNUNET_CHAT_ContactFindJoin find;
find.hash = NULL;
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h
@@ -108,7 +108,7 @@ contact_find_context (const struct GNUNET_CHAT_Contact *contact);
* a given chat <i>context</i>.
*
* @param[in] contact Chat contact
- * @param[in] context Chat context
+ * @param[in] context Chat context or NULL (optional)
* @return #GNUNET_YES if blocked, otherwise #GNUNET_NO
*/
enum GNUNET_GenericReturnValue
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -967,12 +967,7 @@ GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact)
if (!contact)
return GNUNET_SYSERR;
- struct GNUNET_CHAT_Context *context = contact_find_context(contact);
-
- if (!context)
- return GNUNET_SYSERR;
-
- return contact_is_blocked(contact, context);
+ return contact_is_blocked(contact, NULL);
}