aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-02-13 18:15:43 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-02-13 18:15:43 +0100
commit77e4525e6477ddda9b025261be2e1c73d86a1fe9 (patch)
tree801a3842070f4e5f6b055a9ba6cd625c086b5a16
parentccdeafaf88627aa274c2d6090e4231ed51b56c63 (diff)
downloadlibgnunetchat-77e4525e6477ddda9b025261be2e1c73d86a1fe9.tar.gz
libgnunetchat-77e4525e6477ddda9b025261be2e1c73d86a1fe9.zip
Added user pointer and name access to accounts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--include/gnunet_chat_lib.h42
-rw-r--r--src/gnunet_chat_account.c2
-rw-r--r--src/gnunet_chat_account.h2
-rw-r--r--src/gnunet_chat_lib.c41
4 files changed, 76 insertions, 11 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
index 0d2a848..a0d57d9 100644
--- a/include/gnunet_chat_lib.h
+++ b/include/gnunet_chat_lib.h
@@ -150,13 +150,13 @@ struct GNUNET_CHAT_Invitation;
150 * 150 *
151 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts 151 * @param[in,out] cls Closure from #GNUNET_CHAT_iterate_accounts
152 * @param[in] handle Chat handle 152 * @param[in] handle Chat handle
153 * @param[in] account Chat account 153 * @param[in,out] account Chat account
154 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 154 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
155 */ 155 */
156typedef int 156typedef int
157(*GNUNET_CHAT_AccountCallback) (void *cls, 157(*GNUNET_CHAT_AccountCallback) (void *cls,
158 const struct GNUNET_CHAT_Handle *handle, 158 const struct GNUNET_CHAT_Handle *handle,
159 const struct GNUNET_CHAT_Account *account); 159 struct GNUNET_CHAT_Account *account);
160 160
161/** 161/**
162 * Iterator over chat contacts of a specific chat handle. 162 * Iterator over chat contacts of a specific chat handle.
@@ -320,9 +320,9 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle);
320 * @return Amount of accounts iterated or #GNUNET_SYSERR on failure 320 * @return Amount of accounts iterated or #GNUNET_SYSERR on failure
321 */ 321 */
322int 322int
323GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle, 323GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
324 GNUNET_CHAT_AccountCallback callback, 324 GNUNET_CHAT_AccountCallback callback,
325 void *cls); 325 void *cls);
326 326
327/** 327/**
328 * Connects a chat <i>handle</i> to a selected chat <i>account</i>. 328 * 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);
349 * @return Account used by the handle or NULL 349 * @return Account used by the handle or NULL
350 */ 350 */
351const struct GNUNET_CHAT_Account* 351const struct GNUNET_CHAT_Account*
352GNUNET_CHAT_get_connected(const struct GNUNET_CHAT_Handle *handle); 352GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle);
353 353
354/** 354/**
355 * Updates a chat handle to renew the used ego to sign sent messages in active 355 * 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,
409 void *cls); 409 void *cls);
410 410
411/** 411/**
412 * Returns the provided name of a given <i>account</i> or NULL on failure.
413 *
414 * @param account Chat account
415 * @return Name or NULL
416 */
417const char*
418GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account);
419
420/**
421 * Sets a custom <i>user pointer</i> to a given chat <i>account</i> so it can
422 * be accessed in account related callbacks.
423 *
424 * @param[in,out] account Chat account
425 * @param[in] user_pointer Custom user pointer
426 */
427void
428GNUNET_CHAT_account_set_user_pointer (struct GNUNET_CHAT_Account *account,
429 void *user_pointer);
430
431/**
432 * Returns the custom user pointer of a given <i>contact</i> or NULL if it was
433 * not set any.
434 *
435 * @param[in] account Chat account
436 * @return Custom user pointer or NULL
437 */
438void*
439GNUNET_CHAT_account_get_user_pointer (const struct GNUNET_CHAT_Account *account);
440
441/**
412 * Creates a new group chat to use with a given chat <i>handle</i> with an 442 * Creates a new group chat to use with a given chat <i>handle</i> with an
413 * optional public <i>topic</i>. 443 * optional public <i>topic</i>.
414 * 444 *
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c
index 049536b..09e48f8 100644
--- 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,
35 account->ego = ego; 35 account->ego = ego;
36 account->name = GNUNET_strdup(name); 36 account->name = GNUNET_strdup(name);
37 37
38 account->user_pointer = NULL;
39
38 return account; 40 return account;
39} 41}
40 42
diff --git a/src/gnunet_chat_account.h b/src/gnunet_chat_account.h
index dc41f25..a00b8a5 100644
--- a/src/gnunet_chat_account.h
+++ b/src/gnunet_chat_account.h
@@ -33,6 +33,8 @@ struct GNUNET_CHAT_Account
33{ 33{
34 struct GNUNET_IDENTITY_Ego *ego; 34 struct GNUNET_IDENTITY_Ego *ego;
35 char *name; 35 char *name;
36
37 void *user_pointer;
36}; 38};
37 39
38struct GNUNET_CHAT_Account* 40struct GNUNET_CHAT_Account*
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index e40ef0c..0b36765 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -63,9 +63,9 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
63 63
64 64
65int 65int
66GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle, 66GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
67 GNUNET_CHAT_AccountCallback callback, 67 GNUNET_CHAT_AccountCallback callback,
68 void *cls) 68 void *cls)
69{ 69{
70 if (!handle) 70 if (!handle)
71 return GNUNET_SYSERR; 71 return GNUNET_SYSERR;
@@ -80,7 +80,7 @@ GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle,
80 80
81 result++; 81 result++;
82 82
83 if ((!callback) && (GNUNET_YES != callback(cls, handle, accounts->account))) 83 if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account)))
84 break; 84 break;
85 85
86 accounts = accounts->next; 86 accounts = accounts->next;
@@ -118,7 +118,7 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle)
118 118
119 119
120const struct GNUNET_CHAT_Account* 120const struct GNUNET_CHAT_Account*
121GNUNET_CHAT_get_connected(const struct GNUNET_CHAT_Handle *handle) 121GNUNET_CHAT_get_connected (const struct GNUNET_CHAT_Handle *handle)
122{ 122{
123 if (!handle) 123 if (!handle)
124 return NULL; 124 return NULL;
@@ -211,6 +211,37 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
211} 211}
212 212
213 213
214const char*
215GNUNET_CHAT_account_get_name (const struct GNUNET_CHAT_Account *account)
216{
217 if (!account)
218 return NULL;
219
220 return account->name;
221}
222
223
224void
225GNUNET_CHAT_account_set_user_pointer (struct GNUNET_CHAT_Account *account,
226 void *user_pointer)
227{
228 if (!account)
229 return;
230
231 account->user_pointer = user_pointer;
232}
233
234
235void*
236GNUNET_CHAT_account_get_user_pointer (const struct GNUNET_CHAT_Account *account)
237{
238 if (!account)
239 return NULL;
240
241 return account->user_pointer;
242}
243
244
214struct GNUNET_CHAT_Group * 245struct GNUNET_CHAT_Group *
215GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, 246GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
216 const char* topic) 247 const char* topic)