libgnunetchat

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

commit 98852b955cacf792adc9a02682e3d23b5e6ee979
parent bf0bb934cc4c62c4aefedaab205ba0035747bdd4
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Thu, 16 Dec 2021 00:58:44 +0100

Added function to check if a contact is owned by the account

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Minclude/gnunet_chat_lib.h | 11+++++++++++
Msrc/gnunet_chat_contact.c | 2++
Msrc/gnunet_chat_contact.h | 2++
Msrc/gnunet_chat_contact_intern.c | 2++
Msrc/gnunet_chat_handle_intern.c | 11+++++++----
Msrc/gnunet_chat_lib.c | 10++++++++++
6 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h @@ -443,6 +443,17 @@ void* GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact); /** + * Returns if a given <i>contact</i> is owned as account and whether it has + * sent messages with. + * + * @param[in] contact Contact + * @return GNUNET_YES if the contact is owned, otherwise GNUNET_NO + * and GNUNET_SYSERR on failure + */ +int +GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact); + +/** * Leaves a specific <i>group</i> chat and frees its memory if it is not shared * with other groups or contacts. * diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -44,6 +44,8 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle, contact->public_key = NULL; contact->user_pointer = NULL; + contact->is_owned = GNUNET_NO; + contact_update_key (contact); return contact; } diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h @@ -42,6 +42,8 @@ struct GNUNET_CHAT_Contact char *public_key; void *user_pointer; + + int is_owned; }; struct GNUNET_CHAT_Contact* diff --git a/src/gnunet_chat_contact_intern.c b/src/gnunet_chat_contact_intern.c @@ -22,6 +22,8 @@ * @file gnunet_chat_contact_intern.c */ +#include <stdlib.h> + #define GNUNET_UNUSED __attribute__ ((unused)) struct GNUNET_CHAT_ContactFindRoom diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -464,6 +464,13 @@ on_handle_message (void *cls, struct GNUNET_ShortHashCode shorthash; util_shorthash_from_member(sender, &shorthash); + struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get( + handle->contacts, &shorthash + ); + + if (flags & GNUNET_MESSENGER_FLAG_SENT) + contact->is_owned = GNUNET_YES; + struct GNUNET_TIME_Absolute *time = GNUNET_CONTAINER_multishortmap_get( context->timestamps, &shorthash ); @@ -501,10 +508,6 @@ on_handle_message (void *cls, { case GNUNET_MESSENGER_KIND_KEY: { - struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get( - handle->contacts, &shorthash - ); - contact_update_key(contact); break; } diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -332,6 +332,16 @@ GNUNET_CHAT_contact_get_user_pointer (const struct GNUNET_CHAT_Contact *contact) int +GNUNET_CHAT_contact_is_owned (const struct GNUNET_CHAT_Contact *contact) +{ + if (!contact) + return GNUNET_SYSERR; + + return contact->is_owned; +} + + +int GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) { if (!group)