libgnunetchat

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

commit 35e3ee46594914fd651d82120772d051a8f5535a
parent 3f81dbe736093e4e4842ab166cc0ed68a6791761
Author: Jacki <jacki@thejackimonster.de>
Date:   Sat, 17 Feb 2024 17:16:48 +0100

Adjust blocking code for generic tagging of contacts

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

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 34++++++++++++++++++++++++++++++++++
Msrc/gnunet_chat_contact.c | 32++++++++++++++++++++------------
Msrc/gnunet_chat_contact.h | 31++++++++++++++++++-------------
Msrc/gnunet_chat_handle_intern.c | 3---
Msrc/gnunet_chat_lib.c | 68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/gnunet_chat_lib_intern.c | 7+++++--
6 files changed, 140 insertions(+), 35 deletions(-)

diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h @@ -810,6 +810,40 @@ enum GNUNET_GenericReturnValue GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact); /** + * Tags a given <i>contact</i> by the current account with a specific + * <i>tag</i>. + * + * @param[in,out] contact Contact + * @param[in] tag Tag + */ +void +GNUNET_CHAT_contact_tag (struct GNUNET_CHAT_Contact *contact, + const char *tag); + +/** + * Untags a given <i>contact</i> by the current account with a specific + * <i>tag</i>. + * + * @param[in,out] contact Contact + * @param[in] tag Tag + */ +void +GNUNET_CHAT_contact_untag (struct GNUNET_CHAT_Contact *contact, + const char *tag); + +/** + * Returns if a given <i>contact</i> is tagged by the current account with + * a specific <i>tag</i>. + * + * @param[in] contact Contact + * @return #GNUNET_YES if the contact is tagged, #GNUNET_SYSERR on failure and + * #GNUNET_NO otherwise + */ +enum GNUNET_GenericReturnValue +GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, + const char *tag); + +/** * Iterates through the tickets of a given <i>contact</i> with a selected * callback and custom closure. * diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -77,8 +77,8 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, if (!(context->room)) return; - const enum GNUNET_GenericReturnValue blocked = contact_is_blocked( - contact, context + const enum GNUNET_GenericReturnValue blocked = contact_is_tagged( + contact, context, NULL ); const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( @@ -109,13 +109,13 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, return; if (GNUNET_YES == blocked) - contact_unblock(contact, context); + contact_untag(contact, context, NULL); GNUNET_memcpy(current, hash, sizeof(struct GNUNET_HashCode)); if (GNUNET_YES == blocked) - contact_block(contact, context); + contact_tag(contact, context, NULL); } void @@ -167,8 +167,9 @@ contact_find_context (const struct GNUNET_CHAT_Contact *contact) } enum GNUNET_GenericReturnValue -contact_is_blocked (const struct GNUNET_CHAT_Contact *contact, - const struct GNUNET_CHAT_Context *context) +contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, + const struct GNUNET_CHAT_Context *context, + const char *tag) { GNUNET_assert( (contact) && @@ -218,7 +219,7 @@ skip_context_search: if (! hash) return (general == GNUNET_YES? GNUNET_NO : - contact_is_blocked(contact, NULL) + contact_is_tagged(contact, NULL, tag) ); struct GNUNET_CHAT_ContactFindJoin find; @@ -238,8 +239,9 @@ skip_context_search: } void -contact_unblock (struct GNUNET_CHAT_Contact *contact, - struct GNUNET_CHAT_Context *context) +contact_untag (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context, + const char *tag) { GNUNET_assert( (contact) && @@ -280,8 +282,9 @@ contact_unblock (struct GNUNET_CHAT_Contact *contact, } void -contact_block (struct GNUNET_CHAT_Contact *contact, - struct GNUNET_CHAT_Context *context) +contact_tag (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context, + const char *tag) { GNUNET_assert( (contact) && @@ -314,17 +317,22 @@ contact_block (struct GNUNET_CHAT_Contact *contact, if ((find.hash) || (! context->room)) return; + char *tag_value = tag? GNUNET_strdup(tag) : NULL; + struct GNUNET_MESSENGER_Message msg; msg.header.kind = GNUNET_MESSENGER_KIND_TAG; GNUNET_memcpy(&(msg.body.tag.hash), hash, sizeof(struct GNUNET_HashCode)); - msg.body.tag.tag = NULL; + msg.body.tag.tag = tag_value; GNUNET_MESSENGER_send_message( context->room, &msg, contact->member ); + + if (tag_value) + GNUNET_free(tag_value); } void diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h @@ -104,38 +104,43 @@ struct GNUNET_CHAT_Context* contact_find_context (const struct GNUNET_CHAT_Contact *contact); /** - * Returns whether a chat <i>contact</i> is blocked in - * a given chat <i>context</i>. + * Returns whether a chat <i>contact</i> is tagged in + * a given chat <i>context</i> with a specific <i>tag</i>. * * @param[in] contact Chat contact * @param[in] context Chat context or NULL (optional) - * @return #GNUNET_YES if blocked, otherwise #GNUNET_NO + * @param[in] tag Tag or NULL + * @return #GNUNET_YES if tagged, otherwise #GNUNET_NO */ enum GNUNET_GenericReturnValue -contact_is_blocked (const struct GNUNET_CHAT_Contact *contact, - const struct GNUNET_CHAT_Context *context); +contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, + const struct GNUNET_CHAT_Context *context, + const char *tag); /** - * Unblocks a given chat <i>contact</i> in - * a given chat <i>context</i>. + * Untags a given chat <i>contact</i> in + * a given chat <i>context</i> from a specific <i>tag</i>. * * @param[in,out] contact Chat contact * @param[in,out] context Chat context */ void -contact_unblock (struct GNUNET_CHAT_Contact *contact, - struct GNUNET_CHAT_Context *context); +contact_untag (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context, + const char *tag); /** - * Blocks a given chat <i>contact</i> in - * a given chat <i>context</i>. + * Tags a given chat <i>contact</i> in + * a given chat <i>context</i> with a specific <i>tag</i>. * * @param[in,out] contact Chat contact * @param[in,out] context Chat context + * @param[in] tag Tag or NULL */ void -contact_block (struct GNUNET_CHAT_Contact *contact, - struct GNUNET_CHAT_Context *context); +contact_tag (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context, + const char *tag); /** * Destroys a chat <i>contact</i> and frees its memory. diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -955,9 +955,6 @@ on_handle_message_callback(void *cls) break; } - if (GNUNET_YES == contact_is_blocked(contact, context)) - goto clear_dependencies; - handle->msg_cb(handle->msg_cls, context, message); clear_dependencies: diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -948,11 +948,12 @@ GNUNET_CHAT_contact_set_blocked (struct GNUNET_CHAT_Contact *contact, struct GNUNET_CHAT_ContactIterateContexts it; it.contact = contact; + it.tag = NULL; if (GNUNET_NO == blocked) - it.cb = contact_unblock; + it.cb = contact_untag; else if (GNUNET_YES == blocked) - it.cb = contact_block; + it.cb = contact_tag; else return; @@ -972,7 +973,64 @@ GNUNET_CHAT_contact_is_blocked (const struct GNUNET_CHAT_Contact *contact) if (!contact) return GNUNET_SYSERR; - return contact_is_blocked(contact, NULL); + return contact_is_tagged(contact, NULL, NULL); +} + + +void +GNUNET_CHAT_contact_tag (struct GNUNET_CHAT_Contact *contact, + const char *tag) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if ((!contact) || (!tag) || (!tag[0])) + return; + + struct GNUNET_CHAT_ContactIterateContexts it; + it.contact = contact; + it.tag = tag; + it.cb = contact_tag; + + GNUNET_CONTAINER_multihashmap_iterate( + contact->joined, + it_contact_iterate_contexts, + &it + ); +} + + +void +GNUNET_CHAT_contact_untag (struct GNUNET_CHAT_Contact *contact, + const char *tag) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if ((!contact) || (!tag) || (!tag[0])) + return; + + struct GNUNET_CHAT_ContactIterateContexts it; + it.contact = contact; + it.tag = tag; + it.cb = contact_untag; + + GNUNET_CONTAINER_multihashmap_iterate( + contact->joined, + it_contact_iterate_contexts, + &it + ); +} + + +enum GNUNET_GenericReturnValue +GNUNET_CHAT_contact_is_tagged (const struct GNUNET_CHAT_Contact *contact, + const char *tag) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if ((!contact) || (!tag) || (!tag[0])) + return GNUNET_SYSERR; + + return contact_is_tagged(contact, NULL, tag); } @@ -1623,7 +1681,7 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) { GNUNET_CHAT_VERSION_ASSERT(); - if ((!message) || (GNUNET_CHAT_FLAG_NONE != message->flag) || + if ((!message) || (GNUNET_YES != message_has_msg(message)) || (!(message->context)) || (!(message->context->room))) return NULL; @@ -1643,7 +1701,7 @@ GNUNET_CHAT_message_get_recipient (const struct GNUNET_CHAT_Message *message) { GNUNET_CHAT_VERSION_ASSERT(); - if ((!message) || (GNUNET_CHAT_FLAG_NONE != message->flag) || + if ((!message) || (GNUNET_YES != message_has_msg(message)) || (!(message->context)) || (!(message->context->room))) return NULL; diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -162,11 +162,14 @@ it_handle_iterate_groups (void *cls, typedef void (*GNUNET_CHAT_ContactIterateContextCallback) (struct GNUNET_CHAT_Contact *contact, - struct GNUNET_CHAT_Context *context); + struct GNUNET_CHAT_Context *context, + const char *tag); struct GNUNET_CHAT_ContactIterateContexts { struct GNUNET_CHAT_Contact *contact; + const char *tag; + GNUNET_CHAT_ContactIterateContextCallback cb; }; @@ -189,7 +192,7 @@ it_contact_iterate_contexts (void *cls, if (! context) return GNUNET_YES; - it->cb(it->contact, context); + it->cb(it->contact, context, it->tag); return GNUNET_YES; }