commit f6eaddbabe79b5ccb857850b0f7ff625ccf9f87e
parent bd8aa616a2b2a90fdd90c5ab18f9e4006f51e07c
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 12 Jun 2025 17:42:40 +0200
Add function to lookup own contact of handle
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
5 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -897,6 +897,16 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
void *cls);
/**
+ * Returns the chat contact matching a given chat <i>handle</i>'s current
+ * account.
+ *
+ * @param[in,out] handle Chat handle
+ * @return Chat contact or NULL
+ */
+struct GNUNET_CHAT_Contact*
+GNUNET_CHAT_get_own_contact (struct GNUNET_CHAT_Handle *handle);
+
+/**
* Returns the provided name of a given <i>account</i> or NULL on failure.
*
* @param[in] account Chat account
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -94,6 +94,7 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
handle->accounts_tail = NULL;
handle->refreshing = GNUNET_NO;
+ handle->own_contact = NULL;
handle->next = NULL;
handle->current = NULL;
@@ -165,6 +166,7 @@ handle_update_key (struct GNUNET_CHAT_Handle *handle)
GNUNET_free(handle->public_key);
handle->public_key = NULL;
+ handle->own_contact = NULL;
if (!(handle->messenger))
return;
@@ -390,6 +392,8 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
GNUNET_YES
);
+ handle->own_contact = NULL;
+
while (handle->attributes_head)
internal_attributes_destroy(handle->attributes_head);
@@ -481,6 +485,8 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
GNUNET_free(lobbies);
}
+ handle->own_contact = NULL;
+
GNUNET_CONTAINER_multihashmap_destroy(handle->groups);
GNUNET_CONTAINER_multishortmap_destroy(handle->contacts);
GNUNET_CONTAINER_multihashmap_destroy(handle->contexts);
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2024 GNUnet e.V.
+ Copyright (C) 2021--2025 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -27,6 +27,7 @@
#include "gnunet_chat_lib.h"
#include "gnunet_chat_account.h"
+#include "gnunet_chat_contact.h"
#include "gnunet_chat_lobby.h"
#include "gnunet_chat_message.h"
#include "gnunet_chat_uri.h"
@@ -107,6 +108,7 @@ struct GNUNET_CHAT_Handle
struct GNUNET_CHAT_InternalAccounts *accounts_tail;
enum GNUNET_GenericReturnValue refreshing;
+ struct GNUNET_CHAT_Contact *own_contact;
struct GNUNET_CHAT_Account *next;
struct GNUNET_CHAT_Account *current;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -933,6 +933,18 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
}
+struct GNUNET_CHAT_Contact*
+GNUNET_CHAT_get_own_contact (struct GNUNET_CHAT_Handle *handle)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!(handle->own_contact))
+ GNUNET_CHAT_iterate_contacts (handle, it_handle_find_own_contact, NULL);
+
+ return handle->own_contact;
+}
+
+
const char*
GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account)
{
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021--2024 GNUnet e.V.
+ Copyright (C) 2021--2025 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -193,6 +193,27 @@ it_handle_iterate_contacts (void *cls,
return it->cb(it->cls, it->handle, contact);
}
+enum GNUNET_GenericReturnValue
+it_handle_find_own_contact (GNUNET_UNUSED void *cls,
+ struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Contact *contact)
+{
+ GNUNET_assert((handle) && (contact));
+
+ if (GNUNET_YES != GNUNET_CHAT_contact_is_owned(contact))
+ return GNUNET_YES;
+
+ const char *contact_key = GNUNET_CHAT_contact_get_key(contact);
+ const char *handle_key = GNUNET_CHAT_get_key(handle);
+
+ if ((!contact_key) || (!handle_key) ||
+ (0 != strcmp(contact_key, handle_key)))
+ return GNUNET_YES;
+
+ handle->own_contact = contact;
+ return GNUNET_NO;
+}
+
struct GNUNET_CHAT_HandleIterateGroups
{
struct GNUNET_CHAT_Handle *handle;