diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | include/gnunet_chat_lib.h | 18 | ||||
-rw-r--r-- | src/gnunet_chat_config.c | 27 | ||||
-rw-r--r-- | src/gnunet_chat_config.h | 30 | ||||
-rw-r--r-- | src/gnunet_chat_context.c | 69 | ||||
-rw-r--r-- | src/gnunet_chat_context.h | 7 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 6 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 47 | ||||
-rw-r--r-- | src/gnunet_chat_message.c | 11 | ||||
-rw-r--r-- | src/gnunet_chat_message.h | 14 | ||||
-rw-r--r-- | src/gnunet_chat_message_intern.c | 135 | ||||
-rw-r--r-- | src/gnunet_chat_util.c | 5 | ||||
-rw-r--r-- | src/gnunet_chat_util.h | 3 |
13 files changed, 304 insertions, 69 deletions
@@ -5,7 +5,6 @@ INSTALL_DIR = /usr/local/ | |||
5 | 5 | ||
6 | LIBRARY = libgnunetchat.so | 6 | LIBRARY = libgnunetchat.so |
7 | SOURCES = gnunet_chat_lib.c\ | 7 | SOURCES = gnunet_chat_lib.c\ |
8 | gnunet_chat_config.c\ | ||
9 | gnunet_chat_contact.c\ | 8 | gnunet_chat_contact.c\ |
10 | gnunet_chat_context.c\ | 9 | gnunet_chat_context.c\ |
11 | gnunet_chat_file.c\ | 10 | gnunet_chat_file.c\ |
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 3d2437a..9734644 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -559,6 +559,24 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message); | |||
559 | * TODO | 559 | * TODO |
560 | * | 560 | * |
561 | * @param message | 561 | * @param message |
562 | * @return | ||
563 | */ | ||
564 | int | ||
565 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message); | ||
566 | |||
567 | /** | ||
568 | * TODO | ||
569 | * | ||
570 | * @param message | ||
571 | * @return | ||
572 | */ | ||
573 | int | ||
574 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message); | ||
575 | |||
576 | /** | ||
577 | * TODO | ||
578 | * | ||
579 | * @param message | ||
562 | * @param callback | 580 | * @param callback |
563 | * @param cls | 581 | * @param cls |
564 | * @return | 582 | * @return |
diff --git a/src/gnunet_chat_config.c b/src/gnunet_chat_config.c deleted file mode 100644 index 08f0d50..0000000 --- a/src/gnunet_chat_config.c +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
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 deleted file mode 100644 index 64a16c7..0000000 --- a/src/gnunet_chat_config.h +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
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_context.c b/src/gnunet_chat_context.c index 33a65d0..1124fd2 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -23,6 +23,8 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "gnunet_chat_context.h" | 25 | #include "gnunet_chat_context.h" |
26 | #include "gnunet_chat_handle.h" | ||
27 | #include "gnunet_chat_util.h" | ||
26 | 28 | ||
27 | #include "gnunet_chat_context_intern.c" | 29 | #include "gnunet_chat_context_intern.c" |
28 | 30 | ||
@@ -68,3 +70,70 @@ context_destroy (struct GNUNET_CHAT_Context* context) | |||
68 | 70 | ||
69 | GNUNET_free(context); | 71 | GNUNET_free(context); |
70 | } | 72 | } |
73 | |||
74 | void | ||
75 | context_load_config (struct GNUNET_CHAT_Context *context) | ||
76 | { | ||
77 | const char *directory = context->handle->directory; | ||
78 | |||
79 | if (!directory) | ||
80 | return; | ||
81 | |||
82 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
83 | context->room | ||
84 | ); | ||
85 | |||
86 | char* filename; | ||
87 | util_get_filename(directory, "chats", hash, &filename); | ||
88 | |||
89 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | ||
90 | goto free_filename; | ||
91 | |||
92 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
93 | |||
94 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, directory)) | ||
95 | goto destroy_config; | ||
96 | |||
97 | char* name = NULL; | ||
98 | |||
99 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | ||
100 | config, "chat", "name", &name)) | ||
101 | util_set_name_field(name, &(context->nick)); | ||
102 | |||
103 | if (name) | ||
104 | GNUNET_free(name); | ||
105 | |||
106 | destroy_config: | ||
107 | GNUNET_CONFIGURATION_destroy(config); | ||
108 | |||
109 | free_filename: | ||
110 | GNUNET_free(filename); | ||
111 | } | ||
112 | |||
113 | void | ||
114 | context_save_config (const struct GNUNET_CHAT_Context *context) | ||
115 | { | ||
116 | const char *directory = context->handle->directory; | ||
117 | |||
118 | if (!directory) | ||
119 | return; | ||
120 | |||
121 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
122 | context->room | ||
123 | ); | ||
124 | |||
125 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
126 | |||
127 | if (context->nick) | ||
128 | GNUNET_CONFIGURATION_set_value_string( | ||
129 | config, "chat", "name", context->nick | ||
130 | ); | ||
131 | |||
132 | char* filename; | ||
133 | util_get_filename(directory, "chats", hash, &filename); | ||
134 | |||
135 | GNUNET_CONFIGURATION_write(config, filename); | ||
136 | GNUNET_CONFIGURATION_destroy(config); | ||
137 | |||
138 | GNUNET_free(filename); | ||
139 | } | ||
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h index 83e8d52..81e03c3 100644 --- a/src/gnunet_chat_context.h +++ b/src/gnunet_chat_context.h | |||
@@ -27,6 +27,7 @@ | |||
27 | 27 | ||
28 | #include <gnunet/platform.h> | 28 | #include <gnunet/platform.h> |
29 | #include <gnunet/gnunet_common.h> | 29 | #include <gnunet/gnunet_common.h> |
30 | #include <gnunet/gnunet_configuration_lib.h> | ||
30 | #include <gnunet/gnunet_container_lib.h> | 31 | #include <gnunet/gnunet_container_lib.h> |
31 | #include <gnunet/gnunet_messenger_service.h> | 32 | #include <gnunet/gnunet_messenger_service.h> |
32 | #include <gnunet/gnunet_util_lib.h> | 33 | #include <gnunet/gnunet_util_lib.h> |
@@ -63,4 +64,10 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, | |||
63 | void | 64 | void |
64 | context_destroy (struct GNUNET_CHAT_Context* context); | 65 | context_destroy (struct GNUNET_CHAT_Context* context); |
65 | 66 | ||
67 | void | ||
68 | context_load_config (struct GNUNET_CHAT_Context *context); | ||
69 | |||
70 | void | ||
71 | context_save_config (const struct GNUNET_CHAT_Context *context); | ||
72 | |||
66 | #endif /* GNUNET_CHAT_CONTEXT_H_ */ | 73 | #endif /* GNUNET_CHAT_CONTEXT_H_ */ |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index a34c63e..ede1eb7 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -183,6 +183,7 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
183 | return context; | 183 | return context; |
184 | 184 | ||
185 | context = context_create_from_room(handle, room); | 185 | context = context_create_from_room(handle, room); |
186 | context_load_config(context); | ||
186 | 187 | ||
187 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 188 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
188 | handle->contexts, key, context, | 189 | handle->contexts, key, context, |
@@ -267,7 +268,7 @@ on_handle_message (void *cls, | |||
267 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *sender, | 268 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *sender, |
268 | const struct GNUNET_MESSENGER_Message *msg, | 269 | const struct GNUNET_MESSENGER_Message *msg, |
269 | const struct GNUNET_HashCode *hash, | 270 | const struct GNUNET_HashCode *hash, |
270 | GNUNET_UNUSED enum GNUNET_MESSENGER_MessageFlags flags) | 271 | enum GNUNET_MESSENGER_MessageFlags flags) |
271 | { | 272 | { |
272 | struct GNUNET_CHAT_Handle *handle = cls; | 273 | struct GNUNET_CHAT_Handle *handle = cls; |
273 | 274 | ||
@@ -285,7 +286,7 @@ on_handle_message (void *cls, | |||
285 | if (message) | 286 | if (message) |
286 | return; | 287 | return; |
287 | 288 | ||
288 | message = message_create_from_msg(context, hash, msg); | 289 | message = message_create_from_msg(context, hash, flags, msg); |
289 | 290 | ||
290 | switch (msg->header.kind) | 291 | switch (msg->header.kind) |
291 | { | 292 | { |
@@ -360,6 +361,7 @@ it_destroy_handle_contexts (GNUNET_UNUSED void *cls, | |||
360 | void *value) | 361 | void *value) |
361 | { | 362 | { |
362 | struct GNUNET_CHAT_Context *context = value; | 363 | struct GNUNET_CHAT_Context *context = value; |
364 | context_save_config(context); | ||
363 | context_destroy(context); | 365 | context_destroy(context); |
364 | return GNUNET_YES; | 366 | return GNUNET_YES; |
365 | } | 367 | } |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index f455549..8be813b 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -26,7 +26,6 @@ | |||
26 | 26 | ||
27 | #include <limits.h> | 27 | #include <limits.h> |
28 | 28 | ||
29 | #include "gnunet_chat_config.h" | ||
30 | #include "gnunet_chat_contact.h" | 29 | #include "gnunet_chat_contact.h" |
31 | #include "gnunet_chat_context.h" | 30 | #include "gnunet_chat_context.h" |
32 | #include "gnunet_chat_file.h" | 31 | #include "gnunet_chat_file.h" |
@@ -489,7 +488,9 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
489 | return GNUNET_SYSERR; | 488 | return GNUNET_SYSERR; |
490 | 489 | ||
491 | char *filename; | 490 | char *filename; |
492 | util_get_filename (context->handle->directory, &hash, &filename); | 491 | util_get_filename ( |
492 | context->handle->directory, "files", &hash, &filename | ||
493 | ); | ||
493 | 494 | ||
494 | if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) || | 495 | if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) || |
495 | (GNUNET_OK != GNUNET_DISK_file_copy(path, filename))) | 496 | (GNUNET_OK != GNUNET_DISK_file_copy(path, filename))) |
@@ -670,6 +671,32 @@ GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) | |||
670 | 671 | ||
671 | 672 | ||
672 | int | 673 | int |
674 | GNUNET_CHAT_message_is_sent (const struct GNUNET_CHAT_Message *message) | ||
675 | { | ||
676 | if (!message) | ||
677 | return GNUNET_SYSERR; | ||
678 | |||
679 | if (message->flags & GNUNET_MESSENGER_FLAG_SENT) | ||
680 | return GNUNET_YES; | ||
681 | else | ||
682 | return GNUNET_NO; | ||
683 | } | ||
684 | |||
685 | |||
686 | int | ||
687 | GNUNET_CHAT_message_is_private (const struct GNUNET_CHAT_Message *message) | ||
688 | { | ||
689 | if (!message) | ||
690 | return GNUNET_SYSERR; | ||
691 | |||
692 | if (message->flags & GNUNET_MESSENGER_FLAG_PRIVATE) | ||
693 | return GNUNET_YES; | ||
694 | else | ||
695 | return GNUNET_NO; | ||
696 | } | ||
697 | |||
698 | |||
699 | int | ||
673 | GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message, | 700 | GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message, |
674 | GNUNET_CHAT_MessageReadReceiptCallback callback, | 701 | GNUNET_CHAT_MessageReadReceiptCallback callback, |
675 | void *cls) | 702 | void *cls) |
@@ -765,7 +792,9 @@ GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) | |||
765 | return GNUNET_FS_uri_chk_get_file_size(file->uri); | 792 | return GNUNET_FS_uri_chk_get_file_size(file->uri); |
766 | 793 | ||
767 | char *filename; | 794 | char *filename; |
768 | util_get_filename (file->handle->directory, &(file->hash), &filename); | 795 | util_get_filename ( |
796 | file->handle->directory, "files", &(file->hash), &filename | ||
797 | ); | ||
769 | 798 | ||
770 | uint64_t size; | 799 | uint64_t size; |
771 | if (GNUNET_OK != GNUNET_DISK_file_size(filename, &size, GNUNET_NO, GNUNET_YES)) | 800 | if (GNUNET_OK != GNUNET_DISK_file_size(filename, &size, GNUNET_NO, GNUNET_YES)) |
@@ -783,7 +812,9 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) | |||
783 | return GNUNET_SYSERR; | 812 | return GNUNET_SYSERR; |
784 | 813 | ||
785 | char *filename; | 814 | char *filename; |
786 | util_get_filename (file->handle->directory, &(file->hash), &filename); | 815 | util_get_filename ( |
816 | file->handle->directory, "files", &(file->hash), &filename | ||
817 | ); | ||
787 | 818 | ||
788 | int result = GNUNET_DISK_file_test(filename); | 819 | int result = GNUNET_DISK_file_test(filename); |
789 | 820 | ||
@@ -809,7 +840,9 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
809 | const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); | 840 | const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); |
810 | 841 | ||
811 | char *filename; | 842 | char *filename; |
812 | util_get_filename (file->handle->directory, &(file->hash), &filename); | 843 | util_get_filename ( |
844 | file->handle->directory, "files", &(file->hash), &filename | ||
845 | ); | ||
813 | 846 | ||
814 | uint64_t offset; | 847 | uint64_t offset; |
815 | if (GNUNET_OK != GNUNET_DISK_file_size(filename, &offset, GNUNET_NO, GNUNET_YES)) | 848 | if (GNUNET_OK != GNUNET_DISK_file_size(filename, &offset, GNUNET_NO, GNUNET_YES)) |
@@ -890,7 +923,9 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file) | |||
890 | return GNUNET_OK; | 923 | return GNUNET_OK; |
891 | 924 | ||
892 | char *filename; | 925 | char *filename; |
893 | util_get_filename (file->handle->directory, &(file->hash), &filename); | 926 | util_get_filename ( |
927 | file->handle->directory, "files", &(file->hash), &filename | ||
928 | ); | ||
894 | 929 | ||
895 | file->unindex = GNUNET_FS_unindex_start( | 930 | file->unindex = GNUNET_FS_unindex_start( |
896 | file->handle->fs, filename, file | 931 | file->handle->fs, filename, file |
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c index bff8a52..7e47291 100644 --- a/src/gnunet_chat_message.c +++ b/src/gnunet_chat_message.c | |||
@@ -24,9 +24,12 @@ | |||
24 | 24 | ||
25 | #include "gnunet_chat_message.h" | 25 | #include "gnunet_chat_message.h" |
26 | 26 | ||
27 | #include "gnunet_chat_message_intern.c" | ||
28 | |||
27 | struct GNUNET_CHAT_Message* | 29 | struct GNUNET_CHAT_Message* |
28 | message_create_from_msg (struct GNUNET_CHAT_Context *context, | 30 | message_create_from_msg (struct GNUNET_CHAT_Context *context, |
29 | const struct GNUNET_HashCode *hash, | 31 | const struct GNUNET_HashCode *hash, |
32 | enum GNUNET_MESSENGER_MessageFlags flags, | ||
30 | const struct GNUNET_MESSENGER_Message *msg) | 33 | const struct GNUNET_MESSENGER_Message *msg) |
31 | { | 34 | { |
32 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); | 35 | struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message); |
@@ -34,14 +37,22 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context, | |||
34 | message->context = context; | 37 | message->context = context; |
35 | 38 | ||
36 | GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash)); | 39 | GNUNET_memcpy(&(message->hash), hash, sizeof(message->hash)); |
40 | message->flags = flags; | ||
41 | |||
42 | message->head = NULL; | ||
43 | message->tail = NULL; | ||
37 | 44 | ||
38 | message->msg = msg; | 45 | message->msg = msg; |
39 | 46 | ||
47 | link_message_parent(message); | ||
48 | |||
40 | return message; | 49 | return message; |
41 | } | 50 | } |
42 | 51 | ||
43 | void | 52 | void |
44 | message_destroy (struct GNUNET_CHAT_Message* message) | 53 | message_destroy (struct GNUNET_CHAT_Message* message) |
45 | { | 54 | { |
55 | unlink_message_parent(message); | ||
56 | clear_message_children(message); | ||
46 | GNUNET_free(message); | 57 | GNUNET_free(message); |
47 | } | 58 | } |
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h index 7b3051c..ea5b355 100644 --- a/src/gnunet_chat_message.h +++ b/src/gnunet_chat_message.h | |||
@@ -31,12 +31,25 @@ | |||
31 | #include <gnunet/gnunet_util_lib.h> | 31 | #include <gnunet/gnunet_util_lib.h> |
32 | 32 | ||
33 | struct GNUNET_CHAT_Context; | 33 | struct GNUNET_CHAT_Context; |
34 | struct GNUNET_CHAT_Message; | ||
35 | |||
36 | struct GNUNET_CHAT_MessageList | ||
37 | { | ||
38 | struct GNUNET_CHAT_Message *message; | ||
39 | |||
40 | struct GNUNET_CHAT_MessageList *prev; | ||
41 | struct GNUNET_CHAT_MessageList *next; | ||
42 | }; | ||
34 | 43 | ||
35 | struct GNUNET_CHAT_Message | 44 | struct GNUNET_CHAT_Message |
36 | { | 45 | { |
37 | struct GNUNET_CHAT_Context *context; | 46 | struct GNUNET_CHAT_Context *context; |
38 | 47 | ||
39 | struct GNUNET_HashCode hash; | 48 | struct GNUNET_HashCode hash; |
49 | enum GNUNET_MESSENGER_MessageFlags flags; | ||
50 | |||
51 | struct GNUNET_CHAT_MessageList *head; | ||
52 | struct GNUNET_CHAT_MessageList *tail; | ||
40 | 53 | ||
41 | const struct GNUNET_MESSENGER_Message *msg; | 54 | const struct GNUNET_MESSENGER_Message *msg; |
42 | }; | 55 | }; |
@@ -44,6 +57,7 @@ struct GNUNET_CHAT_Message | |||
44 | struct GNUNET_CHAT_Message* | 57 | struct GNUNET_CHAT_Message* |
45 | message_create_from_msg (struct GNUNET_CHAT_Context *context, | 58 | message_create_from_msg (struct GNUNET_CHAT_Context *context, |
46 | const struct GNUNET_HashCode *hash, | 59 | const struct GNUNET_HashCode *hash, |
60 | enum GNUNET_MESSENGER_MessageFlags flags, | ||
47 | const struct GNUNET_MESSENGER_Message *msg); | 61 | const struct GNUNET_MESSENGER_Message *msg); |
48 | 62 | ||
49 | void | 63 | void |
diff --git a/src/gnunet_chat_message_intern.c b/src/gnunet_chat_message_intern.c new file mode 100644 index 0000000..97f3c18 --- /dev/null +++ b/src/gnunet_chat_message_intern.c | |||
@@ -0,0 +1,135 @@ | |||
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_message_intern.c | ||
23 | */ | ||
24 | |||
25 | #include <gnunet/gnunet_container_lib.h> | ||
26 | |||
27 | #include "gnunet_chat_context.h" | ||
28 | |||
29 | void | ||
30 | link_message_parent (struct GNUNET_CHAT_Message *message) | ||
31 | { | ||
32 | struct GNUNET_CHAT_Context *context = message->context; | ||
33 | |||
34 | struct GNUNET_CHAT_Message *prev = GNUNET_CONTAINER_multihashmap_get( | ||
35 | context->messages, &(message->msg->header.previous) | ||
36 | ); | ||
37 | |||
38 | if (prev) | ||
39 | { | ||
40 | struct GNUNET_CHAT_MessageList *list = GNUNET_new( | ||
41 | struct GNUNET_CHAT_MessageList | ||
42 | ); | ||
43 | |||
44 | list->message = message; | ||
45 | |||
46 | GNUNET_CONTAINER_DLL_insert(prev->head, prev->tail, list); | ||
47 | } | ||
48 | |||
49 | if (GNUNET_MESSENGER_KIND_MERGE != message->msg->header.kind) | ||
50 | return; | ||
51 | |||
52 | prev = GNUNET_CONTAINER_multihashmap_get( | ||
53 | context->messages, &(message->msg->body.merge.previous) | ||
54 | ); | ||
55 | |||
56 | if (prev) | ||
57 | { | ||
58 | struct GNUNET_CHAT_MessageList *list = GNUNET_new( | ||
59 | struct GNUNET_CHAT_MessageList | ||
60 | ); | ||
61 | |||
62 | list->message = message; | ||
63 | |||
64 | GNUNET_CONTAINER_DLL_insert(prev->head, prev->tail, list); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | void | ||
69 | unlink_message_parent (struct GNUNET_CHAT_Message *message) | ||
70 | { | ||
71 | struct GNUNET_CHAT_Context *context = message->context; | ||
72 | |||
73 | struct GNUNET_CHAT_Message *prev = GNUNET_CONTAINER_multihashmap_get( | ||
74 | context->messages, &(message->msg->header.previous) | ||
75 | ); | ||
76 | |||
77 | if (prev) | ||
78 | { | ||
79 | struct GNUNET_CHAT_MessageList *list = prev->head; | ||
80 | |||
81 | while (list) | ||
82 | { | ||
83 | if (list->message == message) | ||
84 | break; | ||
85 | |||
86 | list = list->next; | ||
87 | } | ||
88 | |||
89 | if (list) | ||
90 | { | ||
91 | GNUNET_CONTAINER_DLL_remove(prev->head, prev->tail, list); | ||
92 | GNUNET_free(list); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | if (GNUNET_MESSENGER_KIND_MERGE != message->msg->header.kind) | ||
97 | return; | ||
98 | |||
99 | prev = GNUNET_CONTAINER_multihashmap_get( | ||
100 | context->messages, &(message->msg->body.merge.previous) | ||
101 | ); | ||
102 | |||
103 | if (prev) | ||
104 | { | ||
105 | struct GNUNET_CHAT_MessageList *list = prev->head; | ||
106 | |||
107 | while (list) | ||
108 | { | ||
109 | if (list->message == message) | ||
110 | break; | ||
111 | |||
112 | list = list->next; | ||
113 | } | ||
114 | |||
115 | if (list) | ||
116 | { | ||
117 | GNUNET_CONTAINER_DLL_remove(prev->head, prev->tail, list); | ||
118 | GNUNET_free(list); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | void | ||
124 | clear_message_children (struct GNUNET_CHAT_Message *message) | ||
125 | { | ||
126 | struct GNUNET_CHAT_MessageList *list = message->tail; | ||
127 | |||
128 | while (list) | ||
129 | { | ||
130 | GNUNET_CONTAINER_DLL_remove(message->head, message->tail, list); | ||
131 | GNUNET_free(list); | ||
132 | |||
133 | list = message->tail; | ||
134 | } | ||
135 | } | ||
diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c index cdbd46c..836286f 100644 --- a/src/gnunet_chat_util.c +++ b/src/gnunet_chat_util.c | |||
@@ -175,14 +175,15 @@ util_decrypt_file (const char *filename, | |||
175 | } | 175 | } |
176 | 176 | ||
177 | int | 177 | int |
178 | util_get_filename (const char *directory, const struct GNUNET_HashCode *hash, | 178 | util_get_filename (const char *directory, const char *subdir, |
179 | const struct GNUNET_HashCode *hash, | ||
179 | char **filename) | 180 | char **filename) |
180 | { | 181 | { |
181 | return GNUNET_asprintf ( | 182 | return GNUNET_asprintf ( |
182 | filename, | 183 | filename, |
183 | "%s%s%c%s", | 184 | "%s%s%c%s", |
184 | directory, | 185 | directory, |
185 | "files", | 186 | subdir, |
186 | DIR_SEPARATOR, | 187 | DIR_SEPARATOR, |
187 | GNUNET_h2s_full(hash) | 188 | GNUNET_h2s_full(hash) |
188 | ); | 189 | ); |
diff --git a/src/gnunet_chat_util.h b/src/gnunet_chat_util.h index 1ffa01a..1a958d8 100644 --- a/src/gnunet_chat_util.h +++ b/src/gnunet_chat_util.h | |||
@@ -51,7 +51,8 @@ util_decrypt_file (const char *filename, | |||
51 | const struct GNUNET_CRYPTO_SymmetricSessionKey *key); | 51 | const struct GNUNET_CRYPTO_SymmetricSessionKey *key); |
52 | 52 | ||
53 | int | 53 | int |
54 | util_get_filename (const char *directory, const struct GNUNET_HashCode *hash, | 54 | util_get_filename (const char *directory, const char *subdir, |
55 | const struct GNUNET_HashCode *hash, | ||
55 | char **filename); | 56 | char **filename); |
56 | 57 | ||
57 | #endif /* GNUNET_CHAT_UTIL_H_ */ | 58 | #endif /* GNUNET_CHAT_UTIL_H_ */ |