diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 22:24:45 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 22:24:45 +0200 |
commit | ecccdbe89ad906f5d995e45ec1ff40117d642b18 (patch) | |
tree | cca01251849b7343413c6d24b153cf1dd9828c7e | |
parent | 62d9bd1120633b094b813b66c49f94db8f2f8abb (diff) | |
download | libgnunetchat-ecccdbe89ad906f5d995e45ec1ff40117d642b18.tar.gz libgnunetchat-ecccdbe89ad906f5d995e45ec1ff40117d642b18.zip |
Added creating chat contacts for each known messenger contact
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 27 | ||||
-rw-r--r-- | src/gnunet_chat_contact.c | 2 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 70 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 19 | ||||
-rw-r--r-- | src/gnunet_chat_lib_intern.c | 22 |
5 files changed, 132 insertions, 8 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 6214e1e..a920973 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -173,7 +173,19 @@ typedef int | |||
173 | */ | 173 | */ |
174 | typedef int | 174 | typedef int |
175 | (*GNUNET_CHAT_ContextMessageCallback) (void *cls, struct GNUNET_CHAT_Context *context, | 175 | (*GNUNET_CHAT_ContextMessageCallback) (void *cls, struct GNUNET_CHAT_Context *context, |
176 | struct GNUNET_CHAT_Message *message); | 176 | const struct GNUNET_CHAT_Message *message); |
177 | |||
178 | /** | ||
179 | * TODO | ||
180 | * | ||
181 | * @param cls | ||
182 | * @param context | ||
183 | * @param file | ||
184 | * @return | ||
185 | */ | ||
186 | typedef int | ||
187 | (*GNUNET_CHAT_ContextFileCallback) (void *cls, struct GNUNET_CHAT_Context *context, | ||
188 | struct GNUNET_CHAT_File *file); | ||
177 | 189 | ||
178 | /** | 190 | /** |
179 | * TODO | 191 | * TODO |
@@ -537,6 +549,19 @@ GNUNET_CHAT_context_iterate_messages (struct GNUNET_CHAT_Context *context, | |||
537 | /** | 549 | /** |
538 | * TODO | 550 | * TODO |
539 | * | 551 | * |
552 | * @param context | ||
553 | * @param callback | ||
554 | * @param cls | ||
555 | * @return | ||
556 | */ | ||
557 | int | ||
558 | GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context, | ||
559 | GNUNET_CHAT_ContextFileCallback callback, | ||
560 | void *cls); | ||
561 | |||
562 | /** | ||
563 | * TODO | ||
564 | * | ||
540 | * @param message | 565 | * @param message |
541 | * @return | 566 | * @return |
542 | */ | 567 | */ |
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c index c023258..e539245 100644 --- a/src/gnunet_chat_contact.c +++ b/src/gnunet_chat_contact.c | |||
@@ -33,8 +33,6 @@ contact_create_from_member (struct GNUNET_CHAT_Handle *handle, | |||
33 | contact->handle = handle; | 33 | contact->handle = handle; |
34 | contact->context = NULL; | 34 | contact->context = NULL; |
35 | 35 | ||
36 | // TODO: search for private context? create private context? | ||
37 | |||
38 | contact->member = member; | 36 | contact->member = member; |
39 | 37 | ||
40 | contact->user_pointer = NULL; | 38 | contact->user_pointer = NULL; |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index 17bff20..a6342a9 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -190,21 +190,24 @@ struct GNUNET_CHAT_CheckHandleRoomMembers | |||
190 | int | 190 | int |
191 | check_handle_room_members (void* cls, | 191 | check_handle_room_members (void* cls, |
192 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | 192 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, |
193 | const struct GNUNET_MESSENGER_Contact *contact) | 193 | const struct GNUNET_MESSENGER_Contact *member) |
194 | { | 194 | { |
195 | struct GNUNET_CHAT_CheckHandleRoomMembers *check = cls; | 195 | struct GNUNET_CHAT_CheckHandleRoomMembers *check = cls; |
196 | 196 | ||
197 | const struct GNUNET_IDENTITY_PublicKey *contact_key = ( | 197 | const struct GNUNET_IDENTITY_PublicKey *member_key = ( |
198 | GNUNET_MESSENGER_contact_get_key(contact) | 198 | GNUNET_MESSENGER_contact_get_key(member) |
199 | ); | 199 | ); |
200 | 200 | ||
201 | if (0 == GNUNET_memcmp(contact_key, check->ignore_key)) | 201 | if (0 == GNUNET_memcmp(member_key, check->ignore_key)) |
202 | return GNUNET_YES; | 202 | return GNUNET_YES; |
203 | 203 | ||
204 | if (check->contact) | 204 | if (check->contact) |
205 | { | ||
206 | check->contact = NULL; | ||
205 | return GNUNET_NO; | 207 | return GNUNET_NO; |
208 | } | ||
206 | 209 | ||
207 | check->contact = contact; | 210 | check->contact = member; |
208 | return GNUNET_YES; | 211 | return GNUNET_YES; |
209 | } | 212 | } |
210 | 213 | ||
@@ -246,6 +249,8 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
246 | handle, check.contact | 249 | handle, check.contact |
247 | ); | 250 | ); |
248 | 251 | ||
252 | contact->context = context; | ||
253 | |||
249 | struct GNUNET_ShortHashCode shorthash; | 254 | struct GNUNET_ShortHashCode shorthash; |
250 | util_shorthash_from_member(check.contact, &shorthash); | 255 | util_shorthash_from_member(check.contact, &shorthash); |
251 | 256 | ||
@@ -295,15 +300,70 @@ find_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, | |||
295 | return GNUNET_YES; | 300 | return GNUNET_YES; |
296 | } | 301 | } |
297 | 302 | ||
303 | int | ||
304 | scan_handle_room_members (void* cls, | ||
305 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | ||
306 | const struct GNUNET_MESSENGER_Contact *member) | ||
307 | { | ||
308 | struct GNUNET_CHAT_Handle *handle = cls; | ||
309 | |||
310 | struct GNUNET_ShortHashCode shorthash; | ||
311 | util_shorthash_from_member(member, &shorthash); | ||
312 | |||
313 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains( | ||
314 | handle->contacts, &shorthash)) | ||
315 | return GNUNET_YES; | ||
316 | |||
317 | struct GNUNET_CHAT_Contact *contact = contact_create_from_member( | ||
318 | handle, member | ||
319 | ); | ||
320 | |||
321 | if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( | ||
322 | handle->contacts, &shorthash, contact, | ||
323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
324 | return GNUNET_YES; | ||
325 | |||
326 | contact_destroy(contact); | ||
327 | return GNUNET_NO; | ||
328 | } | ||
329 | |||
330 | int | ||
331 | scan_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, | ||
332 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *member) | ||
333 | { | ||
334 | struct GNUNET_CHAT_Handle *handle = cls; | ||
335 | |||
336 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
337 | |||
338 | struct GNUNET_CHAT_Group *group = GNUNET_CONTAINER_multihashmap_get( | ||
339 | handle->groups, key | ||
340 | ); | ||
341 | |||
342 | if (!group) | ||
343 | return GNUNET_YES; | ||
344 | |||
345 | GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); | ||
346 | return GNUNET_YES; | ||
347 | } | ||
348 | |||
298 | void | 349 | void |
299 | on_handle_identity(void *cls, | 350 | on_handle_identity(void *cls, |
300 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) | 351 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) |
301 | { | 352 | { |
302 | struct GNUNET_CHAT_Handle *handle = cls; | 353 | struct GNUNET_CHAT_Handle *handle = cls; |
303 | 354 | ||
355 | if ((0 < GNUNET_CONTAINER_multihashmap_size(handle->contexts)) || | ||
356 | (0 < GNUNET_CONTAINER_multihashmap_size(handle->groups)) || | ||
357 | (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) | ||
358 | return; | ||
359 | |||
304 | GNUNET_MESSENGER_find_rooms( | 360 | GNUNET_MESSENGER_find_rooms( |
305 | handle->messenger, NULL, find_handle_rooms, handle | 361 | handle->messenger, NULL, find_handle_rooms, handle |
306 | ); | 362 | ); |
363 | |||
364 | GNUNET_MESSENGER_find_rooms( | ||
365 | handle->messenger, NULL, scan_handle_rooms, handle | ||
366 | ); | ||
307 | } | 367 | } |
308 | 368 | ||
309 | void | 369 | void |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index cdce90c..294a735 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -591,6 +591,25 @@ GNUNET_CHAT_context_iterate_messages (struct GNUNET_CHAT_Context *context, | |||
591 | } | 591 | } |
592 | 592 | ||
593 | 593 | ||
594 | int | ||
595 | GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context, | ||
596 | GNUNET_CHAT_ContextFileCallback callback, | ||
597 | void *cls) | ||
598 | { | ||
599 | if (!context) | ||
600 | return GNUNET_SYSERR; | ||
601 | |||
602 | struct GNUNET_CHAT_ContextIterateFiles it; | ||
603 | it.context = context; | ||
604 | it.cb = callback; | ||
605 | it.cls = cls; | ||
606 | |||
607 | return GNUNET_CONTAINER_multihashmap_iterate( | ||
608 | context->files, it_context_iterate_files, &it | ||
609 | ); | ||
610 | } | ||
611 | |||
612 | |||
594 | enum GNUNET_CHAT_MessageKind | 613 | enum GNUNET_CHAT_MessageKind |
595 | GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) | 614 | GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) |
596 | { | 615 | { |
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c index 584ebab..a2db98a 100644 --- a/src/gnunet_chat_lib_intern.c +++ b/src/gnunet_chat_lib_intern.c | |||
@@ -117,6 +117,28 @@ it_context_iterate_messages (void *cls, | |||
117 | return it->cb(it->cls, it->context, message); | 117 | return it->cb(it->cls, it->context, message); |
118 | } | 118 | } |
119 | 119 | ||
120 | struct GNUNET_CHAT_ContextIterateFiles | ||
121 | { | ||
122 | struct GNUNET_CHAT_Context *context; | ||
123 | GNUNET_CHAT_ContextFileCallback cb; | ||
124 | void *cls; | ||
125 | }; | ||
126 | |||
127 | int | ||
128 | it_context_iterate_files (void *cls, | ||
129 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
130 | void *value) | ||
131 | { | ||
132 | struct GNUNET_CHAT_ContextIterateFiles *it = cls; | ||
133 | |||
134 | if (!(it->cb)) | ||
135 | return GNUNET_YES; | ||
136 | |||
137 | struct GNUNET_CHAT_File *file = value; | ||
138 | |||
139 | return it->cb(it->cls, it->context, file); | ||
140 | } | ||
141 | |||
120 | struct GNUNET_CHAT_MessageIterateReadReceipts | 142 | struct GNUNET_CHAT_MessageIterateReadReceipts |
121 | { | 143 | { |
122 | const struct GNUNET_CHAT_Message *message; | 144 | const struct GNUNET_CHAT_Message *message; |