commit 77e4525e6477ddda9b025261be2e1c73d86a1fe9
parent ccdeafaf88627aa274c2d6090e4231ed51b56c63
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Sun, 13 Feb 2022 18:15:43 +0100
Added user pointer and name access to accounts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
4 files changed, 76 insertions(+), 11 deletions(-)
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
@@ -150,13 +150,13 @@ struct GNUNET_CHAT_Invitation;
*
* @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts
* @param[in] handle Chat handle
- * @param[in] account Chat account
+ * @param[in,out] account Chat account
* @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
*/
typedef int
(*GNUNET_CHAT_AccountCallback) (void *cls,
const struct GNUNET_CHAT_Handle *handle,
- const struct GNUNET_CHAT_Account *account);
+ struct GNUNET_CHAT_Account *account);
/**
* Iterator over chat contacts of a specific chat handle.
@@ -320,9 +320,9 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle);
* @return Amount of accounts iterated or #GNUNET_SYSERR on failure
*/
int
-GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle,
- GNUNET_CHAT_AccountCallback callback,
- void *cls);
+GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
+ GNUNET_CHAT_AccountCallback callback,
+ void *cls);
/**
* Connects a chat <i>handle</i> to a selected chat <i>account</i>.
@@ -349,7 +349,7 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle);
* @return Account used by the handle or NULL
*/
const struct GNUNET_CHAT_Account*
-GNUNET_CHAT_get_connected(const struct GNUNET_CHAT_Handle *handle);
+GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle);
/**
* Updates a chat handle to renew the used ego to sign sent messages in active
@@ -409,6 +409,36 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
void *cls);
/**
+ * Returns the provided name of a given <i>account</i> or NULL on failure.
+ *
+ * @param account Chat account
+ * @return Name or NULL
+ */
+const char*
+GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account);
+
+/**
+ * Sets a custom <i>user pointer</i> to a given chat <i>account</i> so it can
+ * be accessed in account related callbacks.
+ *
+ * @param[in,out] account Chat account
+ * @param[in] user_pointer Custom user pointer
+ */
+void
+GNUNET_CHAT_account_set_user_pointer (struct GNUNET_CHAT_Account *account,
+ void *user_pointer);
+
+/**
+ * Returns the custom user pointer of a given <i>contact</i> or NULL if it was
+ * not set any.
+ *
+ * @param[in] account Chat account
+ * @return Custom user pointer or NULL
+ */
+void*
+GNUNET_CHAT_account_get_user_pointer (const struct GNUNET_CHAT_Account *account);
+
+/**
* Creates a new group chat to use with a given chat <i>handle</i> with an
* optional public <i>topic</i>.
*
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
@@ -35,6 +35,8 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego,
account->ego = ego;
account->name = GNUNET_strdup(name);
+ account->user_pointer = NULL;
+
return account;
}
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
@@ -33,6 +33,8 @@ struct GNUNET_CHAT_Account
{
struct GNUNET_IDENTITY_Ego *ego;
char *name;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_Account*
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -63,9 +63,9 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
int
-GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle,
- GNUNET_CHAT_AccountCallback callback,
- void *cls)
+GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
+ GNUNET_CHAT_AccountCallback callback,
+ void *cls)
{
if (!handle)
return GNUNET_SYSERR;
@@ -80,7 +80,7 @@ GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle,
result++;
- if ((!callback) && (GNUNET_YES != callback(cls, handle, accounts->account)))
+ if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account)))
break;
accounts = accounts->next;
@@ -118,7 +118,7 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle)
const struct GNUNET_CHAT_Account*
-GNUNET_CHAT_get_connected(const struct GNUNET_CHAT_Handle *handle)
+GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle)
{
if (!handle)
return NULL;
@@ -211,6 +211,37 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
}
+const char*
+GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account)
+{
+ if (!account)
+ return NULL;
+
+ return account->name;
+}
+
+
+void
+GNUNET_CHAT_account_set_user_pointer (struct GNUNET_CHAT_Account *account,
+ void *user_pointer)
+{
+ if (!account)
+ return;
+
+ account->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_account_get_user_pointer (const struct GNUNET_CHAT_Account *account)
+{
+ if (!account)
+ return NULL;
+
+ return account->user_pointer;
+}
+
+
struct GNUNET_CHAT_Group *
GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
const char* topic)