commit ae250a3b723b3fc56ee14be8f59019c49c66d35e
parent 48146d45effa20aba4d0bf1ec7517a33cfb5a37a
Author: Jacki <jacki@thejackimonster.de>
Date: Mon, 26 Aug 2024 02:35:17 +0200
Add function to find account by name
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -527,7 +527,7 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle);
*/
enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
- const char* name);
+ const char *name);
/**
* Deletes an existing chat account of a given chat <i>handle</i> under a
@@ -539,7 +539,7 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle,
*/
enum GNUNET_GenericReturnValue
GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle,
- const char* name);
+ const char *name);
/**
* Iterates through the accounts of a given chat <i>handle</i> with a selected
@@ -555,6 +555,18 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
GNUNET_CHAT_AccountCallback callback,
void *cls);
+/*
+ * Searches for an existing chat account of a given chat <i>handle</i> with
+ * a unique <i>name</i>.
+ *
+ * @param[in] handle Chat handle
+ * @param[in] name Account name
+ * @return Found account by the handle or NULL
+ */
+struct GNUNET_CHAT_Account*
+GNUNET_CHAT_find_account (const struct GNUNET_CHAT_Handle *handle,
+ const char *name);
+
/**
* Connects a chat <i>handle</i> to a selected chat <i>account</i>.
*
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -162,6 +162,32 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
}
+struct GNUNET_CHAT_Account*
+GNUNET_CHAT_find_account (const struct GNUNET_CHAT_Handle *handle,
+ const char *name)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if ((!handle) || (handle->destruction))
+ return NULL;
+
+ struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
+ while (accounts)
+ {
+ if ((!(accounts->account)) || (accounts->op))
+ goto skip_account;
+
+ if (0 == strcmp(accounts->account->name, name))
+ return accounts->account;
+
+ skip_account:
+ accounts = accounts->next;
+ }
+
+ return NULL;
+}
+
+
void
GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle,
const struct GNUNET_CHAT_Account *account)