diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-04 23:21:39 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-04 23:21:39 +0200 |
commit | e366e189791025f7fad5572bc786f4883152812e (patch) | |
tree | e949232919c4aeff7149975bb1e20e957489c5c4 | |
parent | 5200796f0fe43ba498eaa7ea5c81e46cdc2d8116 (diff) | |
download | libgnunetchat-e366e189791025f7fad5572bc786f4883152812e.tar.gz libgnunetchat-e366e189791025f7fad5572bc786f4883152812e.zip |
Additions to restructure generalized the messenger API for the purpose of chatting
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | include/gnunet_chat_lib.h | 123 | ||||
-rw-r--r-- | src/gnunet_chat_config.c | 27 | ||||
-rw-r--r-- | src/gnunet_chat_config.h | 30 | ||||
-rw-r--r-- | src/gnunet_chat_contact.c | 4 | ||||
-rw-r--r-- | src/gnunet_chat_context.c | 10 | ||||
-rw-r--r-- | src/gnunet_chat_file.c | 43 | ||||
-rw-r--r-- | src/gnunet_chat_file.h | 2 | ||||
-rw-r--r-- | src/gnunet_chat_group.c | 12 | ||||
-rw-r--r-- | src/gnunet_chat_group.h | 7 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 482 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 72 | ||||
-rw-r--r-- | src/gnunet_chat_invitation.c | 37 | ||||
-rw-r--r-- | src/gnunet_chat_invitation.h | 35 | ||||
-rw-r--r-- | src/gnunet_chat_message.c | 8 | ||||
-rw-r--r-- | src/gnunet_chat_message.h | 2 |
16 files changed, 810 insertions, 88 deletions
@@ -7,9 +7,11 @@ LIBRARY = libgnunetchat.so | |||
7 | SOURCES = gnunet_chat_handle.c\ | 7 | SOURCES = gnunet_chat_handle.c\ |
8 | gnunet_chat_contact.c\ | 8 | gnunet_chat_contact.c\ |
9 | gnunet_chat_file.c\ | 9 | gnunet_chat_file.c\ |
10 | gnunet_chat_invitation.c\ | ||
10 | gnunet_chat_group.c\ | 11 | gnunet_chat_group.c\ |
11 | gnunet_chat_context.c\ | 12 | gnunet_chat_context.c\ |
12 | gnunet_chat_message.c | 13 | gnunet_chat_message.c\ |
14 | gnunet_chat_config.c | ||
13 | HEADERS = gnunet_chat_lib.h | 15 | HEADERS = gnunet_chat_lib.h |
14 | 16 | ||
15 | LIBRARIES = gnunetarm\ | 17 | LIBRARIES = gnunetarm\ |
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index eca7a77..f2605b9 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -29,6 +29,8 @@ | |||
29 | #ifndef GNUNET_CHAT_LIB_H_ | 29 | #ifndef GNUNET_CHAT_LIB_H_ |
30 | #define GNUNET_CHAT_LIB_H_ | 30 | #define GNUNET_CHAT_LIB_H_ |
31 | 31 | ||
32 | #define GNUNET_UNUSED __attribute__ ((unused)) | ||
33 | |||
32 | #include <gnunet/platform.h> | 34 | #include <gnunet/platform.h> |
33 | #include <gnunet/gnunet_util_lib.h> | 35 | #include <gnunet/gnunet_util_lib.h> |
34 | 36 | ||
@@ -40,17 +42,22 @@ enum GNUNET_CHAT_MessageKind | |||
40 | /** | 42 | /** |
41 | * TODO | 43 | * TODO |
42 | */ | 44 | */ |
43 | GNUNET_CHAT_KIND_TEXT = 1, /**< GNUNET_CHAT_KIND_TEXT */ | 45 | GNUNET_CHAT_KIND_TEXT = 1, /**< GNUNET_CHAT_KIND_TEXT */ |
46 | |||
47 | /** | ||
48 | * TODO | ||
49 | */ | ||
50 | GNUNET_CHAT_KIND_FILE = 2, /**< GNUNET_CHAT_KIND_FILE */ | ||
44 | 51 | ||
45 | /** | 52 | /** |
46 | * TODO | 53 | * TODO |
47 | */ | 54 | */ |
48 | GNUNET_CHAT_KIND_FILE = 2, /**< GNUNET_CHAT_KIND_FILE */ | 55 | GNUNET_CHAT_KIND_INVITATION = 3, /**< GNUNET_CHAT_KIND_INVITATION */ |
49 | 56 | ||
50 | /** | 57 | /** |
51 | * TODO | 58 | * TODO |
52 | */ | 59 | */ |
53 | GNUNET_CHAT_KIND_UNKNOWN = 0/**< GNUNET_CHAT_KIND_UNKNOWN */ | 60 | GNUNET_CHAT_KIND_UNKNOWN = 0 /**< GNUNET_CHAT_KIND_UNKNOWN */ |
54 | }; | 61 | }; |
55 | 62 | ||
56 | /** | 63 | /** |
@@ -85,6 +92,11 @@ struct GNUNET_CHAT_File; | |||
85 | 92 | ||
86 | /** | 93 | /** |
87 | * TODO | 94 | * TODO |
95 | */ | ||
96 | struct GNUNET_CHAT_Invitation; | ||
97 | |||
98 | /** | ||
99 | * TODO | ||
88 | * | 100 | * |
89 | * @param cls | 101 | * @param cls |
90 | * @param handle | 102 | * @param handle |
@@ -157,8 +169,27 @@ typedef int | |||
157 | struct GNUNET_CHAT_Contact *contact, | 169 | struct GNUNET_CHAT_Contact *contact, |
158 | int read_receipt); | 170 | int read_receipt); |
159 | 171 | ||
160 | typedef void | 172 | /** |
161 | (*GNUNET_CHAT_MessageFileDownloadCallback) (void *cls, struct GNUNET_CHAT_File *file); | 173 | * TODO |
174 | * | ||
175 | * @param cls | ||
176 | * @param file | ||
177 | * @param completed | ||
178 | */ | ||
179 | typedef int | ||
180 | (*GNUNET_CHAT_MessageFileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file, | ||
181 | uint64_t completed); | ||
182 | |||
183 | /** | ||
184 | * TODO | ||
185 | * | ||
186 | * @param cls | ||
187 | * @param file | ||
188 | * @param completed | ||
189 | */ | ||
190 | typedef int | ||
191 | (*GNUNET_CHAT_MessageFileDownloadCallback) (void *cls, struct GNUNET_CHAT_File *file, | ||
192 | uint64_t completed); | ||
162 | 193 | ||
163 | /** | 194 | /** |
164 | * TODO | 195 | * TODO |
@@ -172,7 +203,8 @@ typedef void | |||
172 | struct GNUNET_CHAT_Handle* | 203 | struct GNUNET_CHAT_Handle* |
173 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 204 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
174 | const char *name, | 205 | const char *name, |
175 | GNUNET_CHAT_WarningCallback warn_cb, void *warn_cls); | 206 | GNUNET_CHAT_WarningCallback warn_cb, void *warn_cls, |
207 | GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls); | ||
176 | 208 | ||
177 | /** | 209 | /** |
178 | * TODO | 210 | * TODO |
@@ -306,8 +338,9 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact); | |||
306 | * TODO | 338 | * TODO |
307 | * | 339 | * |
308 | * @param group | 340 | * @param group |
341 | * @return | ||
309 | */ | 342 | */ |
310 | void | 343 | int |
311 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group); | 344 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group); |
312 | 345 | ||
313 | /** | 346 | /** |
@@ -418,11 +451,15 @@ GNUNET_CHAT_context_delete_message (struct GNUNET_CHAT_Context *context, | |||
418 | * | 451 | * |
419 | * @param context | 452 | * @param context |
420 | * @param hash | 453 | * @param hash |
454 | * @param callback | ||
455 | * @param cls | ||
421 | * @return | 456 | * @return |
422 | */ | 457 | */ |
423 | const struct GNUNET_CHAT_Message* | 458 | int |
424 | GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, | 459 | GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, |
425 | const struct GNUNET_HashCode *hash); | 460 | const struct GNUNET_HashCode *hash, |
461 | GNUNET_CHAT_ContextMessageCallback callback, | ||
462 | void *cls); | ||
426 | 463 | ||
427 | /** | 464 | /** |
428 | * TODO | 465 | * TODO |
@@ -499,33 +536,91 @@ GNUNET_CHAT_message_get_file (const struct GNUNET_CHAT_Message *message); | |||
499 | /** | 536 | /** |
500 | * TODO | 537 | * TODO |
501 | * | 538 | * |
539 | * @param message | ||
540 | * @return | ||
541 | */ | ||
542 | struct GNUNET_CHAT_Invitation* | ||
543 | GNUNET_CHAT_message_get_invitation (const struct GNUNET_CHAT_Message *message); | ||
544 | |||
545 | /** | ||
546 | * TODO | ||
547 | * | ||
502 | * @param file | 548 | * @param file |
549 | * @return | ||
503 | */ | 550 | */ |
504 | void | 551 | const struct GNUNET_HashCode* |
505 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file); | 552 | GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file); |
506 | 553 | ||
507 | /** | 554 | /** |
508 | * TODO | 555 | * TODO |
509 | * | 556 | * |
510 | * @param file | 557 | * @param file |
558 | * @return | ||
511 | */ | 559 | */ |
512 | void | 560 | uint64_t |
561 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file); | ||
562 | |||
563 | /** | ||
564 | * TODO | ||
565 | * | ||
566 | * @param file | ||
567 | * @return | ||
568 | */ | ||
569 | int | ||
570 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); | ||
571 | |||
572 | /** | ||
573 | * TODO | ||
574 | * | ||
575 | * @param file | ||
576 | * @return | ||
577 | */ | ||
578 | int | ||
579 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | ||
580 | GNUNET_CHAT_MessageFileDownloadCallback callback, | ||
581 | void *cls); | ||
582 | |||
583 | /** | ||
584 | * TODO | ||
585 | * | ||
586 | * @param file | ||
587 | * @return | ||
588 | */ | ||
589 | int | ||
513 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file); | 590 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file); |
514 | 591 | ||
515 | /** | 592 | /** |
516 | * TODO | 593 | * TODO |
517 | * | 594 | * |
518 | * @param file | 595 | * @param file |
596 | * @return | ||
519 | */ | 597 | */ |
520 | void | 598 | int |
521 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file); | 599 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file); |
522 | 600 | ||
523 | /** | 601 | /** |
524 | * TODO | 602 | * TODO |
525 | * | 603 | * |
526 | * @param file | 604 | * @param file |
605 | * @return | ||
527 | */ | 606 | */ |
528 | void | 607 | int |
529 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); | 608 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); |
530 | 609 | ||
610 | /** | ||
611 | * TODO | ||
612 | * | ||
613 | * @param invitation | ||
614 | */ | ||
615 | void | ||
616 | GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation); | ||
617 | |||
618 | /** | ||
619 | * TODO | ||
620 | * | ||
621 | * @param invitation | ||
622 | */ | ||
623 | void | ||
624 | GNUNET_CHAT_invitation_decline (struct GNUNET_CHAT_Invitation *invitation); | ||
625 | |||
531 | #endif /* GNUNET_CHAT_LIB_H_ */ | 626 | #endif /* GNUNET_CHAT_LIB_H_ */ |
diff --git a/src/gnunet_chat_config.c b/src/gnunet_chat_config.c new file mode 100644 index 0000000..08f0d50 --- /dev/null +++ b/src/gnunet_chat_config.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file gnunet_chat_config.c | ||
23 | */ | ||
24 | |||
25 | #include "gnunet_chat_config.h" | ||
26 | |||
27 | |||
diff --git a/src/gnunet_chat_config.h b/src/gnunet_chat_config.h new file mode 100644 index 0000000..64a16c7 --- /dev/null +++ b/src/gnunet_chat_config.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file gnunet_chat_config.h | ||
23 | */ | ||
24 | |||
25 | #ifndef GNUNET_CHAT_CONFIG_H_ | ||
26 | #define GNUNET_CHAT_CONFIG_H_ | ||
27 | |||
28 | |||
29 | |||
30 | #endif /* GNUNET_CHAT_CONFIG_H_ */ | ||
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c index 8e3bda9..d1d92ff 100644 --- a/src/gnunet_chat_contact.c +++ b/src/gnunet_chat_contact.c | |||
@@ -140,6 +140,10 @@ GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) | |||
140 | if (!contact) | 140 | if (!contact) |
141 | return GNUNET_SYSERR; | 141 | return GNUNET_SYSERR; |
142 | 142 | ||
143 | if (GNUNET_YES != handle_update_chat_contact(contact->handle, | ||
144 | contact, GNUNET_YES)) | ||
145 | return GNUNET_SYSERR; | ||
146 | |||
143 | if (contact->context) | 147 | if (contact->context) |
144 | GNUNET_MESSENGER_close_room(contact->context->room); | 148 | GNUNET_MESSENGER_close_room(contact->context->room); |
145 | 149 | ||
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index 3124ded..27e8f35 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -165,12 +165,14 @@ GNUNET_CHAT_context_delete_message (struct GNUNET_CHAT_Context *context, | |||
165 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); | 165 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); |
166 | } | 166 | } |
167 | 167 | ||
168 | const struct GNUNET_CHAT_Message* | 168 | int |
169 | GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, | 169 | GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, |
170 | const struct GNUNET_HashCode *hash) | 170 | const struct GNUNET_HashCode *hash, |
171 | GNUNET_CHAT_ContextMessageCallback callback, | ||
172 | void *cls) | ||
171 | { | 173 | { |
172 | if (!context) | 174 | if (!context) |
173 | return NULL; | 175 | return GNUNET_SYSERR; |
174 | 176 | ||
175 | struct GNUNET_MESSENGER_Message *message = GNUNET_MESSENGER_get_message( | 177 | struct GNUNET_MESSENGER_Message *message = GNUNET_MESSENGER_get_message( |
176 | context->room, hash | 178 | context->room, hash |
@@ -178,7 +180,7 @@ GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, | |||
178 | 180 | ||
179 | //TODO: convert messenger-message to chat-message | 181 | //TODO: convert messenger-message to chat-message |
180 | 182 | ||
181 | return NULL; | 183 | return GNUNET_OK; |
182 | } | 184 | } |
183 | 185 | ||
184 | int | 186 | int |
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c index 33add7b..b5f480c 100644 --- a/src/gnunet_chat_file.c +++ b/src/gnunet_chat_file.c | |||
@@ -25,11 +25,31 @@ | |||
25 | #include "gnunet_chat_lib.h" | 25 | #include "gnunet_chat_lib.h" |
26 | #include "gnunet_chat_file.h" | 26 | #include "gnunet_chat_file.h" |
27 | 27 | ||
28 | void | 28 | const struct GNUNET_HashCode* |
29 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file) | 29 | GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file) |
30 | { | ||
31 | return &(file->hash); | ||
32 | } | ||
33 | |||
34 | uint64_t | ||
35 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) | ||
36 | { | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | int | ||
41 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) | ||
42 | { | ||
43 | return GNUNET_NO; | ||
44 | } | ||
45 | |||
46 | int | ||
47 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | ||
48 | GNUNET_CHAT_MessageFileDownloadCallback callback, | ||
49 | void *cls) | ||
30 | { | 50 | { |
31 | if (!file) | 51 | if (!file) |
32 | return; | 52 | return GNUNET_SYSERR; |
33 | 53 | ||
34 | struct GNUNET_FS_Handle *handle; | 54 | struct GNUNET_FS_Handle *handle; |
35 | const char *path = ""; // TODO: path = download_directory + filename | 55 | const char *path = ""; // TODO: path = download_directory + filename |
@@ -47,31 +67,36 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file) | |||
47 | NULL, | 67 | NULL, |
48 | NULL | 68 | NULL |
49 | ); | 69 | ); |
70 | |||
71 | return GNUNET_OK; | ||
50 | } | 72 | } |
51 | 73 | ||
52 | void | 74 | int |
53 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) | 75 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) |
54 | { | 76 | { |
55 | if (!file) | 77 | if (!file) |
56 | return; | 78 | return GNUNET_SYSERR; |
57 | 79 | ||
58 | GNUNET_FS_download_suspend(file->context); | 80 | GNUNET_FS_download_suspend(file->context); |
81 | return GNUNET_OK; | ||
59 | } | 82 | } |
60 | 83 | ||
61 | void | 84 | int |
62 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) | 85 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) |
63 | { | 86 | { |
64 | if (!file) | 87 | if (!file) |
65 | return; | 88 | return GNUNET_SYSERR; |
66 | 89 | ||
67 | GNUNET_FS_download_resume(file->context); | 90 | GNUNET_FS_download_resume(file->context); |
91 | return GNUNET_OK; | ||
68 | } | 92 | } |
69 | 93 | ||
70 | void | 94 | int |
71 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | 95 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) |
72 | { | 96 | { |
73 | if (!file) | 97 | if (!file) |
74 | return; | 98 | return GNUNET_SYSERR; |
75 | 99 | ||
76 | GNUNET_FS_download_stop(file->context, GNUNET_YES); | 100 | GNUNET_FS_download_stop(file->context, GNUNET_YES); |
101 | return GNUNET_OK; | ||
77 | } | 102 | } |
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h index fc08d7d..ae45def 100644 --- a/src/gnunet_chat_file.h +++ b/src/gnunet_chat_file.h | |||
@@ -27,10 +27,12 @@ | |||
27 | 27 | ||
28 | #include <gnunet/platform.h> | 28 | #include <gnunet/platform.h> |
29 | #include <gnunet/gnunet_fs_service.h> | 29 | #include <gnunet/gnunet_fs_service.h> |
30 | #include <gnunet/gnunet_messenger_service.h> | ||
30 | #include <gnunet/gnunet_util_lib.h> | 31 | #include <gnunet/gnunet_util_lib.h> |
31 | 32 | ||
32 | struct GNUNET_CHAT_File | 33 | struct GNUNET_CHAT_File |
33 | { | 34 | { |
35 | struct GNUNET_HashCode hash; | ||
34 | struct GNUNET_FS_Uri* uri; | 36 | struct GNUNET_FS_Uri* uri; |
35 | struct GNUNET_FS_DownloadContext* context; | 37 | struct GNUNET_FS_DownloadContext* context; |
36 | }; | 38 | }; |
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c index da4430c..e027b19 100644 --- a/src/gnunet_chat_group.c +++ b/src/gnunet_chat_group.c | |||
@@ -46,6 +46,10 @@ group_create(struct GNUNET_CHAT_Handle *handle, | |||
46 | topic? &topic_key : NULL | 46 | topic? &topic_key : NULL |
47 | ); | 47 | ); |
48 | 48 | ||
49 | group->is_public = topic? GNUNET_YES : GNUNET_NO; | ||
50 | group->announcement = NULL; | ||
51 | group->search = NULL; | ||
52 | |||
49 | if (!group->context) | 53 | if (!group->context) |
50 | { | 54 | { |
51 | group_destroy (group); | 55 | group_destroy (group); |
@@ -90,16 +94,20 @@ skip_context: | |||
90 | GNUNET_free(group); | 94 | GNUNET_free(group); |
91 | } | 95 | } |
92 | 96 | ||
93 | void | 97 | int |
94 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) | 98 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) |
95 | { | 99 | { |
96 | if (!group) | 100 | if (!group) |
97 | return; | 101 | return GNUNET_SYSERR; |
102 | |||
103 | if (GNUNET_YES != handle_update_chat_group(group->handle, group, GNUNET_YES)) | ||
104 | return GNUNET_SYSERR; | ||
98 | 105 | ||
99 | if (group->context) | 106 | if (group->context) |
100 | GNUNET_MESSENGER_close_room(group->context->room); | 107 | GNUNET_MESSENGER_close_room(group->context->room); |
101 | 108 | ||
102 | group_destroy(group); | 109 | group_destroy(group); |
110 | return GNUNET_OK; | ||
103 | } | 111 | } |
104 | 112 | ||
105 | void | 113 | void |
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h index 35b7e40..c0127bc 100644 --- a/src/gnunet_chat_group.h +++ b/src/gnunet_chat_group.h | |||
@@ -25,12 +25,19 @@ | |||
25 | #ifndef GNUNET_CHAT_GROUP_H_ | 25 | #ifndef GNUNET_CHAT_GROUP_H_ |
26 | #define GNUNET_CHAT_GROUP_H_ | 26 | #define GNUNET_CHAT_GROUP_H_ |
27 | 27 | ||
28 | #include <gnunet/gnunet_regex_service.h> | ||
29 | |||
28 | #include "gnunet_chat_context.h" | 30 | #include "gnunet_chat_context.h" |
29 | 31 | ||
30 | struct GNUNET_CHAT_Group | 32 | struct GNUNET_CHAT_Group |
31 | { | 33 | { |
32 | struct GNUNET_CHAT_Handle *handle; | 34 | struct GNUNET_CHAT_Handle *handle; |
33 | struct GNUNET_CHAT_Context *context; | 35 | struct GNUNET_CHAT_Context *context; |
36 | |||
37 | int is_public; | ||
38 | |||
39 | struct GNUNET_REGEX_Announcement *announcement; | ||
40 | struct GNUNET_REGEX_Search *search; | ||
34 | }; | 41 | }; |
35 | 42 | ||
36 | struct GNUNET_CHAT_Group* | 43 | struct GNUNET_CHAT_Group* |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index 6e2f32e..84539c5 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -25,57 +25,285 @@ | |||
25 | #include "gnunet_chat_lib.h" | 25 | #include "gnunet_chat_lib.h" |
26 | #include "gnunet_chat_handle.h" | 26 | #include "gnunet_chat_handle.h" |
27 | #include "gnunet_chat_group.h" | 27 | #include "gnunet_chat_group.h" |
28 | #include "gnunet_chat_contact.h" | ||
29 | #include "gnunet_chat_message.h" | ||
30 | #include "gnunet_chat_file.h" | ||
28 | 31 | ||
29 | static void handle_arm_connection(void* cls, int connected) { | 32 | static void* |
30 | struct GNUNET_CHAT_Handle *handle = cls; | 33 | handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) |
34 | { | ||
35 | struct GNUNET_CHAT_Handle *chat = cls; | ||
36 | |||
37 | if (!chat) | ||
38 | return NULL; | ||
39 | |||
40 | switch (info->status) { | ||
41 | case GNUNET_FS_STATUS_PUBLISH_START: { | ||
42 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | ||
43 | publication->progress = 0.0f; | ||
44 | |||
45 | GNUNET_SCHEDULER_add_now(&CGTK_publication_progress, publication); | ||
46 | |||
47 | return publication;*/ | ||
48 | } case GNUNET_FS_STATUS_PUBLISH_PROGRESS: { | ||
49 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | ||
50 | publication->progress = 1.0f * info->value.publish.completed / info->value.publish.size; | ||
51 | |||
52 | GNUNET_SCHEDULER_add_now(&CGTK_publication_progress, publication); | ||
53 | |||
54 | return publication;*/ | ||
55 | } case GNUNET_FS_STATUS_PUBLISH_COMPLETED: { | ||
56 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | ||
57 | publication->uri = GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); | ||
58 | publication->progress = 1.0f; | ||
59 | |||
60 | GNUNET_SCHEDULER_add_now(&CGTK_publication_finish, publication);*/ | ||
61 | break; | ||
62 | } case GNUNET_FS_STATUS_PUBLISH_ERROR: { | ||
63 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | ||
64 | |||
65 | GNUNET_SCHEDULER_add_now(&CGTK_publication_error, publication);*/ | ||
66 | break; | ||
67 | } case GNUNET_FS_STATUS_DOWNLOAD_START: { | ||
68 | /*request_t* request = (request_t*) info->value.download.cctx; | ||
69 | request->progress = 0.0f; | ||
70 | |||
71 | return request;*/ | ||
72 | } case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: { | ||
73 | return info->value.download.cctx; | ||
74 | } case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: { | ||
75 | return info->value.download.cctx; | ||
76 | } case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: { | ||
77 | /*request_t* request = (request_t*) info->value.download.cctx; | ||
78 | request->progress = 1.0f * info->value.download.completed / info->value.download.size; | ||
79 | |||
80 | GNUNET_SCHEDULER_add_now(&CGTK_request_progress, request); | ||
81 | |||
82 | return request;*/ | ||
83 | } case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: { | ||
84 | /*request_t* request = (request_t*) info->value.download.cctx; | ||
85 | request->progress = 1.0f; | ||
86 | |||
87 | GNUNET_SCHEDULER_add_now(&CGTK_request_finish, request);*/ | ||
88 | break; | ||
89 | } case GNUNET_FS_STATUS_DOWNLOAD_ERROR: { | ||
90 | /*request_t *request = (request_t *) info->value.download.cctx; | ||
91 | |||
92 | GNUNET_SCHEDULER_add_now(&CGTK_request_error, request);*/ | ||
93 | break; | ||
94 | } case GNUNET_FS_STATUS_UNINDEX_START: { | ||
95 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | ||
96 | publication->progress = 0.0f; | ||
97 | |||
98 | return publication;*/ | ||
99 | } case GNUNET_FS_STATUS_UNINDEX_PROGRESS: { | ||
100 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | ||
101 | publication->progress = 1.0f * info->value.unindex.completed / info->value.unindex.size; | ||
102 | |||
103 | return publication;*/ | ||
104 | } case GNUNET_FS_STATUS_UNINDEX_COMPLETED: { | ||
105 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | ||
106 | publication->progress = 1.0f; | ||
107 | |||
108 | GNUNET_SCHEDULER_add_now(&CGTK_publication_unindex_finish, publication);*/ | ||
109 | break; | ||
110 | } default: { | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | return NULL; | ||
116 | } | ||
117 | |||
118 | static void | ||
119 | handle_on_message (void *cls, | ||
120 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | ||
121 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *sender, | ||
122 | const struct GNUNET_MESSENGER_Message *message, | ||
123 | const struct GNUNET_HashCode *hash, | ||
124 | GNUNET_UNUSED enum GNUNET_MESSENGER_MessageFlags flags) | ||
125 | { | ||
126 | struct GNUNET_CHAT_Handle *chat = cls; | ||
127 | |||
128 | //TODO | ||
129 | |||
130 | struct GNUNET_CHAT_Message msg; | ||
131 | GNUNET_memcpy(&(msg.hash), hash, sizeof(msg.hash)); | ||
132 | msg.message = message; | ||
133 | |||
134 | if ((GNUNET_CHAT_KIND_UNKNOWN == GNUNET_CHAT_message_get_kind(&msg)) || | ||
135 | (!chat->msg_cb)) | ||
136 | return; | ||
137 | |||
138 | chat->msg_cb(chat->msg_cls, NULL /* TODO */, &msg); | ||
139 | } | ||
140 | |||
141 | struct GNUNET_CHAT_CheckRoomMembers | ||
142 | { | ||
143 | const struct GNUNET_IDENTITY_PublicKey *ignore_key; | ||
144 | const struct GNUNET_MESSENGER_Contact *contact; | ||
145 | }; | ||
146 | |||
147 | static int | ||
148 | handle_check_room_members (void* cls, | ||
149 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | ||
150 | const struct GNUNET_MESSENGER_Contact *contact) | ||
151 | { | ||
152 | struct GNUNET_CHAT_CheckRoomMembers *check = cls; | ||
153 | const struct GNUNET_IDENTITY_PublicKey *contact_key = ( | ||
154 | GNUNET_MESSENGER_contact_get_key(contact) | ||
155 | ); | ||
156 | |||
157 | if (0 == GNUNET_memcmp(contact_key, check->ignore_key)) | ||
158 | return GNUNET_YES; | ||
159 | |||
160 | if (check->contact) | ||
161 | return GNUNET_NO; | ||
162 | |||
163 | check->contact = contact; | ||
164 | return GNUNET_YES; | ||
165 | } | ||
166 | |||
167 | static int | ||
168 | handle_initialize_context (void *cls, struct GNUNET_MESSENGER_Room *room, | ||
169 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *contact) | ||
170 | { | ||
171 | struct GNUNET_CHAT_Handle *chat = cls; | ||
172 | |||
173 | struct GNUNET_CHAT_CheckRoomMembers check; | ||
174 | check.ignore_key = GNUNET_CHAT_get_key(chat); | ||
175 | check.contact = NULL; | ||
176 | |||
177 | const int amount = GNUNET_MESSENGER_iterate_members( | ||
178 | room, handle_check_room_members, &check | ||
179 | ); | ||
180 | |||
181 | if (amount <= 1) | ||
182 | return GNUNET_YES; | ||
183 | |||
184 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
185 | struct GNUNET_CHAT_Context *context = handle_get_chat_context(chat, key); | ||
186 | enum GNUNET_CHAT_ContextType type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; | ||
187 | |||
188 | if (check.contact) | ||
189 | type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; | ||
190 | else | ||
191 | type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; | ||
192 | |||
193 | if (!context) | ||
194 | context = context_create(chat, type, key); | ||
195 | else | ||
196 | context->type = type; | ||
197 | |||
198 | if (GNUNET_YES != handle_update_chat_context(chat, context, GNUNET_NO)) | ||
199 | context_destroy(context); | ||
200 | |||
201 | return GNUNET_YES; | ||
202 | } | ||
203 | |||
204 | static void | ||
205 | handle_on_identity(void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
206 | { | ||
207 | struct GNUNET_CHAT_Handle *chat = cls; | ||
208 | |||
209 | //TODO | ||
210 | |||
211 | GNUNET_MESSENGER_find_rooms( | ||
212 | chat->handles.messenger, NULL, handle_initialize_context, handle | ||
213 | ); | ||
214 | } | ||
215 | |||
216 | static void | ||
217 | handle_arm_connection(void *cls, int connected) | ||
218 | { | ||
219 | struct GNUNET_CHAT_Handle *chat = cls; | ||
31 | 220 | ||
32 | if (GNUNET_YES == connected) { | 221 | if (GNUNET_YES == connected) { |
33 | GNUNET_ARM_request_service_start(handle->handles.arm, "messenger", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | 222 | GNUNET_ARM_request_service_start(chat->handles.arm, "messenger", |
34 | GNUNET_ARM_request_service_start(handle->handles.arm, "fs", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | 223 | GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); |
224 | GNUNET_ARM_request_service_start(chat->handles.arm, "fs", | ||
225 | GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | ||
35 | } else { | 226 | } else { |
36 | GNUNET_ARM_request_service_start(handle->handles.arm, "arm", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | 227 | GNUNET_ARM_request_service_start(chat->handles.arm, "arm", |
228 | GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | ||
37 | } | 229 | } |
38 | } | 230 | } |
39 | 231 | ||
40 | struct GNUNET_CHAT_Handle* | 232 | struct GNUNET_CHAT_Handle* |
41 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle* cfg, | 233 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle* cfg, |
42 | const char *name, | 234 | const char *name, |
43 | GNUNET_CHAT_WarningCallback warn_cb, | 235 | GNUNET_CHAT_WarningCallback warn_cb, |
44 | void *warn_cls) { | 236 | void *warn_cls, |
237 | GNUNET_CHAT_ContextMessageCallback msg_cb, | ||
238 | void *msg_cls) | ||
239 | { | ||
45 | if (!cfg) | 240 | if (!cfg) |
46 | return NULL; | 241 | return NULL; |
47 | 242 | ||
48 | struct GNUNET_CHAT_Handle *handle = GNUNET_new(struct GNUNET_CHAT_Handle); | 243 | struct GNUNET_CHAT_Handle *chat = GNUNET_new(struct GNUNET_CHAT_Handle); |
49 | memset(handle, 0, sizeof(*handle)); | 244 | memset(chat, 0, sizeof(*chat)); |
50 | handle->cfg = cfg; | 245 | chat->cfg = cfg; |
51 | 246 | ||
52 | handle->handles.arm = GNUNET_ARM_connect(cfg, &handle_arm_connection, handle); | 247 | chat->warn_cb = warn_cb; |
248 | chat->warn_cls = warn_cls; | ||
53 | 249 | ||
54 | if (handle->handles.arm) | 250 | chat->handles.arm = GNUNET_ARM_connect(cfg, &handle_arm_connection, chat); |
55 | handle_arm_connection(handle, GNUNET_NO); | 251 | |
252 | if (chat->handles.arm) | ||
253 | handle_arm_connection(chat, GNUNET_NO); | ||
56 | 254 | ||
57 | handle->handles.messenger = GNUNET_MESSENGER_connect( | 255 | chat->handles.messenger = GNUNET_MESSENGER_connect( |
58 | cfg, name, NULL, NULL, NULL, NULL //TODO | 256 | cfg, name, |
257 | handle_on_identity, chat, | ||
258 | handle_on_message, chat | ||
59 | ); | 259 | ); |
60 | 260 | ||
61 | if (!handle->handles.messenger) | 261 | if (!chat->handles.messenger) |
62 | { | 262 | { |
63 | GNUNET_CHAT_stop(handle); | 263 | GNUNET_CHAT_stop(chat); |
64 | return NULL; | 264 | return NULL; |
65 | } | 265 | } |
66 | 266 | ||
67 | handle->handles.fs = GNUNET_FS_start( | 267 | chat->handles.fs = GNUNET_FS_start( |
68 | cfg, | 268 | cfg, |
69 | NULL, //TODO | 269 | name, |
70 | NULL, | 270 | handle_fs_progress, |
271 | chat, | ||
71 | GNUNET_FS_FLAGS_NONE, | 272 | GNUNET_FS_FLAGS_NONE, |
72 | GNUNET_FS_OPTIONS_END | 273 | GNUNET_FS_OPTIONS_END |
73 | ); | 274 | ); |
74 | 275 | ||
75 | handle->contacts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 276 | chat->contacts.short_map = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); |
76 | handle->groups = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 277 | chat->contacts.hash_map = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); |
278 | |||
279 | chat->groups = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
280 | chat->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
281 | chat->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
282 | |||
283 | chat->msg_cb = msg_cb; | ||
284 | chat->msg_cls = msg_cls; | ||
285 | |||
286 | return chat; | ||
287 | } | ||
288 | |||
289 | static int | ||
290 | handle_iterate_destroy_contacts (GNUNET_UNUSED void *cls, | ||
291 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
292 | void *value) | ||
293 | { | ||
294 | struct GNUNET_CHAT_Contact *contact = value; | ||
295 | contact_destroy(contact); | ||
296 | return GNUNET_YES; | ||
297 | } | ||
77 | 298 | ||
78 | return handle; | 299 | static int |
300 | handle_iterate_destroy_groups (GNUNET_UNUSED void *cls, | ||
301 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
302 | void *value) | ||
303 | { | ||
304 | struct GNUNET_CHAT_Group *group = value; | ||
305 | group_destroy(group); | ||
306 | return GNUNET_YES; | ||
79 | } | 307 | } |
80 | 308 | ||
81 | void | 309 | void |
@@ -102,18 +330,28 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle) | |||
102 | 330 | ||
103 | if (handle->groups) | 331 | if (handle->groups) |
104 | { | 332 | { |
105 | // TODO: destroy each | 333 | GNUNET_CONTAINER_multihashmap_iterate( |
334 | handle->groups, handle_iterate_destroy_groups, NULL | ||
335 | ); | ||
106 | 336 | ||
107 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); | 337 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); |
108 | handle->groups = NULL; | 338 | handle->groups = NULL; |
109 | } | 339 | } |
110 | 340 | ||
111 | if (handle->contacts) | 341 | if (handle->contacts.hash_map) |
112 | { | 342 | { |
113 | // TODO: destroy each | 343 | GNUNET_CONTAINER_multihashmap_iterate( |
344 | handle->contacts.hash_map, handle_iterate_destroy_contacts, NULL | ||
345 | ); | ||
114 | 346 | ||
115 | GNUNET_CONTAINER_multihashmap_destroy(handle->contacts); | 347 | GNUNET_CONTAINER_multihashmap_destroy(handle->contacts.hash_map); |
116 | handle->contacts = NULL; | 348 | handle->contacts.hash_map = NULL; |
349 | } | ||
350 | |||
351 | if (handle->contacts.short_map) | ||
352 | { | ||
353 | GNUNET_CONTAINER_multishortmap_destroy(handle->contacts.short_map); | ||
354 | handle->contacts.short_map = NULL; | ||
117 | } | 355 | } |
118 | 356 | ||
119 | if (handle->handles.arm) | 357 | if (handle->handles.arm) |
@@ -172,7 +410,8 @@ struct GNUNET_CHAT_IterateContacts | |||
172 | }; | 410 | }; |
173 | 411 | ||
174 | static int | 412 | static int |
175 | handle_iterate_contacts(void *cls, const struct GNUNET_HashCode *key, | 413 | handle_iterate_contacts(void *cls, |
414 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
176 | void *value) | 415 | void *value) |
177 | { | 416 | { |
178 | struct GNUNET_CHAT_IterateContacts *iterate = cls; | 417 | struct GNUNET_CHAT_IterateContacts *iterate = cls; |
@@ -197,7 +436,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle, | |||
197 | iterate.callback = callback; | 436 | iterate.callback = callback; |
198 | iterate.cls = cls; | 437 | iterate.cls = cls; |
199 | 438 | ||
200 | return GNUNET_CONTAINER_multihashmap_iterate(handle->contacts, | 439 | return GNUNET_CONTAINER_multihashmap_iterate(handle->contacts.hash_map, |
201 | handle_iterate_contacts, | 440 | handle_iterate_contacts, |
202 | &iterate); | 441 | &iterate); |
203 | } | 442 | } |
@@ -209,7 +448,18 @@ GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, | |||
209 | if (!handle) | 448 | if (!handle) |
210 | return NULL; | 449 | return NULL; |
211 | 450 | ||
212 | return group_create(handle, topic); | 451 | struct GNUNET_CHAT_Group *group = group_create(handle, topic); |
452 | |||
453 | if (!group) | ||
454 | return NULL; | ||
455 | |||
456 | if (GNUNET_YES != handle_update_chat_group(handle, group, GNUNET_NO)) | ||
457 | { | ||
458 | group_destroy(group); | ||
459 | return NULL; | ||
460 | } | ||
461 | |||
462 | return group; | ||
213 | } | 463 | } |
214 | 464 | ||
215 | struct GNUNET_CHAT_IterateGroups | 465 | struct GNUNET_CHAT_IterateGroups |
@@ -220,8 +470,9 @@ struct GNUNET_CHAT_IterateGroups | |||
220 | }; | 470 | }; |
221 | 471 | ||
222 | static int | 472 | static int |
223 | handle_iterate_groups(void *cls, const struct GNUNET_HashCode *key, | 473 | handle_iterate_groups(void *cls, |
224 | void *value) | 474 | GNUNET_UNUSED const struct GNUNET_HashCode *key, |
475 | void *value) | ||
225 | { | 476 | { |
226 | struct GNUNET_CHAT_IterateGroups *iterate = cls; | 477 | struct GNUNET_CHAT_IterateGroups *iterate = cls; |
227 | struct GNUNET_CHAT_Group *group = value; | 478 | struct GNUNET_CHAT_Group *group = value; |
@@ -246,6 +497,167 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle, | |||
246 | iterate.cls = cls; | 497 | iterate.cls = cls; |
247 | 498 | ||
248 | return GNUNET_CONTAINER_multihashmap_iterate(handle->groups, | 499 | return GNUNET_CONTAINER_multihashmap_iterate(handle->groups, |
249 | handle_iterate_contacts, | 500 | handle_iterate_groups, |
250 | &iterate); | 501 | &iterate); |
251 | } | 502 | } |
503 | |||
504 | int | ||
505 | handle_update_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
506 | struct GNUNET_CHAT_Contact *chatContact, | ||
507 | int removeContact) | ||
508 | { | ||
509 | const struct GNUNET_HashCode *key = context_get_key(chatContact->context); | ||
510 | |||
511 | if (GNUNET_YES == removeContact) | ||
512 | { | ||
513 | const int result = GNUNET_CONTAINER_multihashmap_remove( | ||
514 | handle->contacts.hash_map, key, chatContact | ||
515 | ); | ||
516 | |||
517 | if (GNUNET_YES == result) | ||
518 | return handle_update_chat_context(handle, chatContact->context, | ||
519 | GNUNET_YES); | ||
520 | else | ||
521 | return GNUNET_NO; | ||
522 | } | ||
523 | else | ||
524 | { | ||
525 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
526 | handle->contacts.hash_map, key, chatContact, | ||
527 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY | ||
528 | ); | ||
529 | |||
530 | if (GNUNET_OK != result) | ||
531 | return GNUNET_NO; | ||
532 | else | ||
533 | return handle_update_chat_context(handle, chatContact->context, | ||
534 | GNUNET_NO); | ||
535 | } | ||
536 | } | ||
537 | |||
538 | int | ||
539 | handle_update_chat_group (struct GNUNET_CHAT_Handle *handle, | ||
540 | struct GNUNET_CHAT_Group *chatGroup, | ||
541 | int removeGroup) | ||
542 | { | ||
543 | const struct GNUNET_HashCode *key = context_get_key(chatGroup->context); | ||
544 | |||
545 | if (GNUNET_YES == removeGroup) | ||
546 | { | ||
547 | const int result = GNUNET_CONTAINER_multihashmap_remove( | ||
548 | handle->groups, key, chatGroup | ||
549 | ); | ||
550 | |||
551 | if (GNUNET_YES == result) | ||
552 | return handle_update_chat_context(handle, chatGroup->context, | ||
553 | GNUNET_YES); | ||
554 | else | ||
555 | return GNUNET_NO; | ||
556 | } | ||
557 | else | ||
558 | { | ||
559 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
560 | handle->groups, key, chatGroup, | ||
561 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY | ||
562 | ); | ||
563 | |||
564 | if (GNUNET_OK != result) | ||
565 | return GNUNET_NO; | ||
566 | else | ||
567 | return handle_update_chat_context(handle, chatGroup->context, | ||
568 | GNUNET_NO); | ||
569 | } | ||
570 | } | ||
571 | |||
572 | int | ||
573 | handle_update_chat_context (struct GNUNET_CHAT_Handle *handle, | ||
574 | struct GNUNET_CHAT_Context *context, | ||
575 | int removeContext) | ||
576 | { | ||
577 | const struct GNUNET_HashCode *key = context_get_key(context); | ||
578 | |||
579 | if (GNUNET_YES == removeContext) | ||
580 | return GNUNET_CONTAINER_multihashmap_remove( | ||
581 | handle->contexts, key, context | ||
582 | ); | ||
583 | else | ||
584 | { | ||
585 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
586 | handle->contexts, key, context, | ||
587 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY | ||
588 | ); | ||
589 | |||
590 | if (GNUNET_OK != result) | ||
591 | return GNUNET_NO; | ||
592 | else | ||
593 | return GNUNET_YES; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | int | ||
598 | handle_update_chat_file (struct GNUNET_CHAT_Handle *handle, | ||
599 | struct GNUNET_CHAT_File *file, | ||
600 | int removeFile) | ||
601 | { | ||
602 | const struct GNUNET_HashCode *hash = GNUNET_CHAT_file_get_hash(file); | ||
603 | |||
604 | if (GNUNET_YES == removeFile) | ||
605 | return GNUNET_CONTAINER_multihashmap_remove( | ||
606 | handle->files, hash, file | ||
607 | ); | ||
608 | else | ||
609 | { | ||
610 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
611 | handle->files, hash, file, | ||
612 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY | ||
613 | ); | ||
614 | |||
615 | if (GNUNET_OK != result) | ||
616 | return GNUNET_NO; | ||
617 | else | ||
618 | return GNUNET_YES; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | static void | ||
623 | handle_get_short_of_contact(struct GNUNET_ShortHashCode *shortHash, | ||
624 | const struct GNUNET_MESSENGER_Contact *contact) | ||
625 | { | ||
626 | memset(shortHash, 0, sizeof(*shortHash)); | ||
627 | GNUNET_memcpy(shortHash, &contact, sizeof(contact)); | ||
628 | } | ||
629 | |||
630 | struct GNUNET_CHAT_Contact* | ||
631 | handle_get_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
632 | const struct GNUNET_MESSENGER_Contact *contact) | ||
633 | { | ||
634 | struct GNUNET_ShortHashCode shortHash; | ||
635 | handle_get_short_of_contact (&shortHash, contact); | ||
636 | |||
637 | struct GNUNET_CHAT_Contact* chatContact = GNUNET_CONTAINER_multishortmap_get( | ||
638 | handle->contacts.short_map, &shortHash | ||
639 | ); | ||
640 | |||
641 | return chatContact; | ||
642 | } | ||
643 | |||
644 | void | ||
645 | handle_set_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
646 | const struct GNUNET_MESSENGER_Contact *contact, | ||
647 | struct GNUNET_CHAT_Contact *chatContact) | ||
648 | { | ||
649 | struct GNUNET_ShortHashCode shortHash; | ||
650 | handle_get_short_of_contact (&shortHash, contact); | ||
651 | |||
652 | if (chatContact) | ||
653 | { | ||
654 | GNUNET_CONTAINER_multishortmap_remove_all(handle->contacts.short_map, | ||
655 | &shortHash); | ||
656 | return; | ||
657 | } | ||
658 | |||
659 | GNUNET_CONTAINER_multishortmap_put( | ||
660 | handle->contacts.short_map, &shortHash, chatContact, | ||
661 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE | ||
662 | ); | ||
663 | } | ||
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index 837a16e..b287336 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -30,10 +30,7 @@ | |||
30 | #include <gnunet/gnunet_container_lib.h> | 30 | #include <gnunet/gnunet_container_lib.h> |
31 | #include <gnunet/gnunet_arm_service.h> | 31 | #include <gnunet/gnunet_arm_service.h> |
32 | #include <gnunet/gnunet_fs_service.h> | 32 | #include <gnunet/gnunet_fs_service.h> |
33 | #include <gnunet/gnunet_gns_service.h> | ||
34 | #include <gnunet/gnunet_identity_service.h> | ||
35 | #include <gnunet/gnunet_messenger_service.h> | 33 | #include <gnunet/gnunet_messenger_service.h> |
36 | #include <gnunet/gnunet_reclaim_service.h> | ||
37 | #include <gnunet/gnunet_regex_service.h> | 34 | #include <gnunet/gnunet_regex_service.h> |
38 | #include <gnunet/gnunet_util_lib.h> | 35 | #include <gnunet/gnunet_util_lib.h> |
39 | 36 | ||
@@ -53,31 +50,62 @@ struct GNUNET_CHAT_Handle | |||
53 | struct GNUNET_FS_Handle *fs; | 50 | struct GNUNET_FS_Handle *fs; |
54 | 51 | ||
55 | /* | 52 | /* |
56 | * required: (names can be resolved as well as zones and members) | ||
57 | */ | ||
58 | struct GNUNET_GNS_Handle *gns; | ||
59 | |||
60 | /* | ||
61 | * optional: (if not anonymous to receive private key) | ||
62 | * (has to be reset as soon as the private key changes) | ||
63 | */ | ||
64 | struct GNUNET_IDENTITY_Handle *identity; | ||
65 | |||
66 | /* | ||
67 | * required! | 53 | * required! |
68 | */ | 54 | */ |
69 | struct GNUNET_MESSENGER_Handle *messenger; | 55 | struct GNUNET_MESSENGER_Handle *messenger; |
70 | |||
71 | /* | ||
72 | * feature/optional: (maybe add new reclaim message kind?) | ||
73 | * (the message would automatically issue the ticket) | ||
74 | * (send the ticket and consume it) | ||
75 | */ | ||
76 | struct GNUNET_RECLAIM_Handle *reclaim; | ||
77 | } handles; | 56 | } handles; |
78 | 57 | ||
79 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | 58 | struct { |
59 | struct GNUNET_CONTAINER_MultiShortmap *short_map; | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *hash_map; | ||
61 | } contacts; | ||
62 | |||
80 | struct GNUNET_CONTAINER_MultiHashMap *groups; | 63 | struct GNUNET_CONTAINER_MultiHashMap *groups; |
64 | struct GNUNET_CONTAINER_MultiHashMap *contexts; | ||
65 | struct GNUNET_CONTAINER_MultiHashMap *files; | ||
66 | |||
67 | GNUNET_CHAT_ContextMessageCallback msg_cb; | ||
68 | void *msg_cls; | ||
69 | |||
70 | GNUNET_CHAT_WarningCallback warn_cb; | ||
71 | void *warn_cls; | ||
81 | }; | 72 | }; |
82 | 73 | ||
74 | int | ||
75 | handle_update_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
76 | struct GNUNET_CHAT_Contact *chatContact, | ||
77 | int removeContact); | ||
78 | |||
79 | int | ||
80 | handle_update_chat_group (struct GNUNET_CHAT_Handle *handle, | ||
81 | struct GNUNET_CHAT_Group *chatGroup, | ||
82 | int removeGroup); | ||
83 | |||
84 | int | ||
85 | handle_update_chat_context (struct GNUNET_CHAT_Handle *handle, | ||
86 | struct GNUNET_CHAT_Context *context, | ||
87 | int removeContext); | ||
88 | |||
89 | int | ||
90 | handle_update_chat_file (struct GNUNET_CHAT_Handle *handle, | ||
91 | struct GNUNET_CHAT_File *file, | ||
92 | int removeFile); | ||
93 | |||
94 | struct GNUNET_CHAT_Contact* | ||
95 | handle_get_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
96 | const struct GNUNET_MESSENGER_Contact *contact); | ||
97 | |||
98 | void | ||
99 | handle_set_chat_contact (struct GNUNET_CHAT_Handle *handle, | ||
100 | const struct GNUNET_MESSENGER_Contact *contact, | ||
101 | struct GNUNET_CHAT_Contact *chatContact); | ||
102 | |||
103 | struct GNUNET_CHAT_Context* | ||
104 | handle_get_chat_context (struct GNUNET_CHAT_Handle *handle, | ||
105 | const struct GNUNET_HashCode *key); | ||
106 | |||
107 | struct GNUNET_CHAT_File* | ||
108 | handle_get_chat_file (struct GNUNET_CHAT_Handle *handle, | ||
109 | const struct GNUNET_HashCode *hash); | ||
110 | |||
83 | #endif /* GNUNET_CHAT_HANDLE_H_ */ | 111 | #endif /* GNUNET_CHAT_HANDLE_H_ */ |
diff --git a/src/gnunet_chat_invitation.c b/src/gnunet_chat_invitation.c new file mode 100644 index 0000000..44f7787 --- /dev/null +++ b/src/gnunet_chat_invitation.c | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file gnunet_chat_invitation.c | ||
23 | */ | ||
24 | |||
25 | #include "gnunet_chat_invitation.h" | ||
26 | |||
27 | void | ||
28 | GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) | ||
29 | { | ||
30 | //TODO | ||
31 | } | ||
32 | |||
33 | void | ||
34 | GNUNET_CHAT_invitation_decline (struct GNUNET_CHAT_Invitation *invitation) | ||
35 | { | ||
36 | //TODO | ||
37 | } | ||
diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h new file mode 100644 index 0000000..dd2b8e8 --- /dev/null +++ b/src/gnunet_chat_invitation.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file gnunet_chat_invitation.h | ||
23 | */ | ||
24 | |||
25 | #ifndef GNUNET_CHAT_INVITATION_H_ | ||
26 | #define GNUNET_CHAT_INVITATION_H_ | ||
27 | |||
28 | #include "gnunet_chat_lib.h" | ||
29 | |||
30 | struct GNUNET_CHAT_Invitation | ||
31 | { | ||
32 | |||
33 | }; | ||
34 | |||
35 | #endif /* GNUNET_CHAT_INVITATION_H_ */ | ||
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c index 0179215..805453e 100644 --- a/src/gnunet_chat_message.c +++ b/src/gnunet_chat_message.c | |||
@@ -32,6 +32,8 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) | |||
32 | return GNUNET_CHAT_KIND_UNKNOWN; | 32 | return GNUNET_CHAT_KIND_UNKNOWN; |
33 | 33 | ||
34 | switch (message->message->header.kind) { | 34 | switch (message->message->header.kind) { |
35 | case GNUNET_MESSENGER_KIND_INVITE: | ||
36 | return GNUNET_CHAT_KIND_INVITATION; | ||
35 | case GNUNET_MESSENGER_KIND_TEXT: | 37 | case GNUNET_MESSENGER_KIND_TEXT: |
36 | return GNUNET_CHAT_KIND_TEXT; | 38 | return GNUNET_CHAT_KIND_TEXT; |
37 | case GNUNET_MESSENGER_KIND_FILE: | 39 | case GNUNET_MESSENGER_KIND_FILE: |
@@ -64,6 +66,12 @@ GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message, | |||
64 | return GNUNET_SYSERR; | 66 | return GNUNET_SYSERR; |
65 | } | 67 | } |
66 | 68 | ||
69 | struct GNUNET_CHAT_Invitation* | ||
70 | GNUNET_CHAT_message_get_invitation (const struct GNUNET_CHAT_Message *message) | ||
71 | { | ||
72 | return NULL; //TODO | ||
73 | } | ||
74 | |||
67 | const char* | 75 | const char* |
68 | GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message) | 76 | GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message) |
69 | { | 77 | { |
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h index 6436114..6de7fae 100644 --- a/src/gnunet_chat_message.h +++ b/src/gnunet_chat_message.h | |||
@@ -32,7 +32,7 @@ | |||
32 | struct GNUNET_CHAT_Message | 32 | struct GNUNET_CHAT_Message |
33 | { | 33 | { |
34 | struct GNUNET_HashCode hash; | 34 | struct GNUNET_HashCode hash; |
35 | struct GNUNET_MESSENGER_Message *message; | 35 | const struct GNUNET_MESSENGER_Message *message; |
36 | }; | 36 | }; |
37 | 37 | ||
38 | #endif /* GNUNET_CHAT_MESSAGE_H_ */ | 38 | #endif /* GNUNET_CHAT_MESSAGE_H_ */ |