aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-11-08 00:25:45 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-11-08 00:25:45 +0100
commitf407a9417dfff9e6bf3363573e42e85bf2191790 (patch)
treed82bbcdc55d3d67420d4cab637c6fdeccf423daa
parent9ca0d5d5b870914e1c6a7b2912207f4ed3c7312f (diff)
downloadlibgnunetchat-f407a9417dfff9e6bf3363573e42e85bf2191790.tar.gz
libgnunetchat-f407a9417dfff9e6bf3363573e42e85bf2191790.zip
Added functions to get contact or group of a context
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--include/gnunet_chat_lib.h56
-rw-r--r--src/gnunet_chat_lib.c55
-rw-r--r--src/gnunet_chat_lib_intern.c17
3 files changed, 115 insertions, 13 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
index 06b7478..2023323 100644
--- a/include/gnunet_chat_lib.h
+++ b/include/gnunet_chat_lib.h
@@ -139,7 +139,8 @@ struct GNUNET_CHAT_Invitation;
139 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 139 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
140 */ 140 */
141typedef int 141typedef int
142(*GNUNET_CHAT_ContactCallback) (void *cls, struct GNUNET_CHAT_Handle *handle, 142(*GNUNET_CHAT_ContactCallback) (void *cls,
143 struct GNUNET_CHAT_Handle *handle,
143 struct GNUNET_CHAT_Contact *contact); 144 struct GNUNET_CHAT_Contact *contact);
144 145
145/** 146/**
@@ -151,7 +152,8 @@ typedef int
151 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 152 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
152 */ 153 */
153typedef int 154typedef int
154(*GNUNET_CHAT_GroupCallback) (void *cls, struct GNUNET_CHAT_Handle *handle, 155(*GNUNET_CHAT_GroupCallback) (void *cls,
156 struct GNUNET_CHAT_Handle *handle,
155 struct GNUNET_CHAT_Group *group); 157 struct GNUNET_CHAT_Group *group);
156 158
157/** 159/**
@@ -163,8 +165,9 @@ typedef int
163 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 165 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
164 */ 166 */
165typedef int 167typedef int
166(*GNUNET_CHAT_GroupContactCallback) (void *cls, struct GNUNET_CHAT_Group *group, 168(*GNUNET_CHAT_GroupContactCallback) (void *cls,
167 struct GNUNET_CHAT_Contact *contact); 169 struct GNUNET_CHAT_Group *group,
170 struct GNUNET_CHAT_Contact *contact);
168 171
169/** 172/**
170 * Iterator over chat messages in a specific chat context. 173 * Iterator over chat messages in a specific chat context.
@@ -175,7 +178,8 @@ typedef int
175 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 178 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
176 */ 179 */
177typedef int 180typedef int
178(*GNUNET_CHAT_ContextMessageCallback) (void *cls, struct GNUNET_CHAT_Context *context, 181(*GNUNET_CHAT_ContextMessageCallback) (void *cls,
182 struct GNUNET_CHAT_Context *context,
179 const struct GNUNET_CHAT_Message *message); 183 const struct GNUNET_CHAT_Message *message);
180 184
181/** 185/**
@@ -187,7 +191,8 @@ typedef int
187 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 191 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
188 */ 192 */
189typedef int 193typedef int
190(*GNUNET_CHAT_ContextFileCallback) (void *cls, struct GNUNET_CHAT_Context *context, 194(*GNUNET_CHAT_ContextFileCallback) (void *cls,
195 struct GNUNET_CHAT_Context *context,
191 struct GNUNET_CHAT_File *file); 196 struct GNUNET_CHAT_File *file);
192 197
193/** 198/**
@@ -202,7 +207,8 @@ typedef int
202 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise. 207 * @return #GNUNET_YES if we should continue to iterate, #GNUNET_NO otherwise.
203 */ 208 */
204typedef int 209typedef int
205(*GNUNET_CHAT_MessageReadReceiptCallback) (void *cls, const struct GNUNET_CHAT_Message *message, 210(*GNUNET_CHAT_MessageReadReceiptCallback) (void *cls,
211 const struct GNUNET_CHAT_Message *message,
206 const struct GNUNET_CHAT_Contact *contact, 212 const struct GNUNET_CHAT_Contact *contact,
207 int read_receipt); 213 int read_receipt);
208 214
@@ -215,8 +221,10 @@ typedef int
215 * @param[in] size Full size of the uploading file (in bytes) 221 * @param[in] size Full size of the uploading file (in bytes)
216 */ 222 */
217typedef void 223typedef void
218(*GNUNET_CHAT_FileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file, 224(*GNUNET_CHAT_FileUploadCallback) (void *cls,
219 uint64_t completed, uint64_t size); 225 const struct GNUNET_CHAT_File *file,
226 uint64_t completed,
227 uint64_t size);
220 228
221/** 229/**
222 * Method called during a download of a specific file in a chat which was shared. 230 * Method called during a download of a specific file in a chat which was shared.
@@ -227,8 +235,10 @@ typedef void
227 * @param[in] size Full size of the downloading file (in bytes) 235 * @param[in] size Full size of the downloading file (in bytes)
228 */ 236 */
229typedef void 237typedef void
230(*GNUNET_CHAT_FileDownloadCallback) (void *cls, const struct GNUNET_CHAT_File *file, 238(*GNUNET_CHAT_FileDownloadCallback) (void *cls,
231 uint64_t completed, uint64_t size); 239 const struct GNUNET_CHAT_File *file,
240 uint64_t completed,
241 uint64_t size);
232 242
233/** 243/**
234 * Method called during an unindexing of a specific file in a chat which was 244 * Method called during an unindexing of a specific file in a chat which was
@@ -240,8 +250,10 @@ typedef void
240 * @param[in] size Full size of the unindexing file (in bytes) 250 * @param[in] size Full size of the unindexing file (in bytes)
241 */ 251 */
242typedef void 252typedef void
243(*GNUNET_CHAT_FileUnindexCallback) (void *cls, struct GNUNET_CHAT_File *file, 253(*GNUNET_CHAT_FileUnindexCallback) (void *cls,
244 uint64_t completed, uint64_t size); 254 struct GNUNET_CHAT_File *file,
255 uint64_t completed,
256 uint64_t size);
245 257
246/** 258/**
247 * Start a chat handle with a certain configuration, an application <i>directory</i> 259 * Start a chat handle with a certain configuration, an application <i>directory</i>
@@ -516,6 +528,24 @@ struct GNUNET_CHAT_Context*
516GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group); 528GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group);
517 529
518/** 530/**
531 * Returns the chat contact which uses a given <i>context</i>.
532 *
533 * @param[in] context Context
534 * @return Chat contact
535 */
536const struct GNUNET_CHAT_Contact*
537GNUNET_CHAT_context_get_contact (const struct GNUNET_CHAT_Context *context);
538
539/**
540 * Returns the chat group which uses a given <i>context</i>.
541 *
542 * @param[in] context Context
543 * @return Chat group
544 */
545const struct GNUNET_CHAT_Group*
546GNUNET_CHAT_context_get_group (const struct GNUNET_CHAT_Context *context);
547
548/**
519 * Sets a custom <i>user pointer</i> to a given chat <i>context</i> so it can 549 * Sets a custom <i>user pointer</i> to a given chat <i>context</i> so it can
520 * be accessed in chat context related callbacks. 550 * be accessed in chat context related callbacks.
521 * 551 *
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index e002b89..57744fe 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -486,6 +486,61 @@ GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group)
486} 486}
487 487
488 488
489const struct GNUNET_CHAT_Contact*
490GNUNET_CHAT_context_get_contact (const struct GNUNET_CHAT_Context *context)
491{
492 if ((!context) || (GNUNET_CHAT_CONTEXT_TYPE_CONTACT != context->type))
493 return NULL;
494
495 struct GNUNET_MESSENGER_Room *room = context->room;
496 struct GNUNET_CHAT_RoomFindContact find;
497
498 find.contact = NULL;
499
500 GNUNET_MESSENGER_iterate_members(
501 room,
502 it_room_find_contact,
503 &find
504 );
505
506 if (!find.contact)
507 return NULL;
508
509 struct GNUNET_ShortHashCode shorthash;
510 util_shorthash_from_member(find.contact, &shorthash);
511
512 const struct GNUNET_CHAT_Contact *contact;
513 contact = GNUNET_CONTAINER_multishortmap_get(
514 context->handle->contacts, &shorthash
515 );
516
517 GNUNET_assert((contact == NULL) || (contact->context == context));
518 return contact;
519}
520
521
522const struct GNUNET_CHAT_Group*
523GNUNET_CHAT_context_get_group (const struct GNUNET_CHAT_Context *context)
524{
525 if ((!context) || (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type))
526 return NULL;
527
528 const struct GNUNET_MESSENGER_Room *room = context->room;
529 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room);
530
531 if (!key)
532 return NULL;
533
534 const struct GNUNET_CHAT_Group *group;
535 group = GNUNET_CONTAINER_multihashmap_get(
536 context->handle->groups, key
537 );
538
539 GNUNET_assert((group == NULL) || (group->context == context));
540 return group;
541}
542
543
489void 544void
490GNUNET_CHAT_context_set_user_pointer (struct GNUNET_CHAT_Context *context, 545GNUNET_CHAT_context_set_user_pointer (struct GNUNET_CHAT_Context *context,
491 void *user_pointer) 546 void *user_pointer)
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
index 6d72cbf..e87176d 100644
--- a/src/gnunet_chat_lib_intern.c
+++ b/src/gnunet_chat_lib_intern.c
@@ -89,6 +89,23 @@ it_contact_find_room (void *cls,
89 return GNUNET_NO; 89 return GNUNET_NO;
90} 90}
91 91
92struct GNUNET_CHAT_RoomFindContact
93{
94 const struct GNUNET_MESSENGER_Contact *contact;
95};
96
97int
98it_room_find_contact (void *cls,
99 GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room,
100 const struct GNUNET_MESSENGER_Contact *member)
101{
102 GNUNET_assert((cls) && (member));
103
104 struct GNUNET_CHAT_RoomFindContact *find = cls;
105 find->contact = member;
106 return GNUNET_NO;
107}
108
92struct GNUNET_CHAT_GroupIterateContacts 109struct GNUNET_CHAT_GroupIterateContacts
93{ 110{
94 struct GNUNET_CHAT_Group *group; 111 struct GNUNET_CHAT_Group *group;