diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 16:44:02 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 16:44:02 +0200 |
commit | 62d9bd1120633b094b813b66c49f94db8f2f8abb (patch) | |
tree | ab14e08a5d674a2adac55daae82ef8007bf492d1 | |
parent | e19d4dedf548d6b16f95a97f6b67fd2a09a18643 (diff) | |
download | libgnunetchat-62d9bd1120633b094b813b66c49f94db8f2f8abb.tar.gz libgnunetchat-62d9bd1120633b094b813b66c49f94db8f2f8abb.zip |
Adjusted callbacks of file management
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 70 | ||||
-rw-r--r-- | src/gnunet_chat_context.c | 4 | ||||
-rw-r--r-- | src/gnunet_chat_file.c | 219 | ||||
-rw-r--r-- | src/gnunet_chat_file.h | 79 | ||||
-rw-r--r-- | src/gnunet_chat_group.c | 93 | ||||
-rw-r--r-- | src/gnunet_chat_group.h | 6 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 12 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 63 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 73 |
9 files changed, 539 insertions, 80 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 881938c..6214e1e 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -195,10 +195,11 @@ typedef int | |||
195 | * @param cls | 195 | * @param cls |
196 | * @param file | 196 | * @param file |
197 | * @param completed | 197 | * @param completed |
198 | * @param size | ||
198 | */ | 199 | */ |
199 | typedef int | 200 | typedef void |
200 | (*GNUNET_CHAT_MessageFileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file, | 201 | (*GNUNET_CHAT_FileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file, |
201 | uint64_t completed); | 202 | uint64_t completed, uint64_t size); |
202 | 203 | ||
203 | /** | 204 | /** |
204 | * TODO | 205 | * TODO |
@@ -206,10 +207,23 @@ typedef int | |||
206 | * @param cls | 207 | * @param cls |
207 | * @param file | 208 | * @param file |
208 | * @param completed | 209 | * @param completed |
210 | * @param size | ||
209 | */ | 211 | */ |
210 | typedef int | 212 | typedef void |
211 | (*GNUNET_CHAT_MessageFileDownloadCallback) (void *cls, struct GNUNET_CHAT_File *file, | 213 | (*GNUNET_CHAT_FileDownloadCallback) (void *cls, const struct GNUNET_CHAT_File *file, |
212 | uint64_t completed); | 214 | uint64_t completed, uint64_t size); |
215 | |||
216 | /** | ||
217 | * TODO | ||
218 | * | ||
219 | * @param cls | ||
220 | * @param file | ||
221 | * @param completed | ||
222 | * @param size | ||
223 | */ | ||
224 | typedef void | ||
225 | (*GNUNET_CHAT_FileUnindexCallback) (void *cls, struct GNUNET_CHAT_File *file, | ||
226 | uint64_t completed, uint64_t size); | ||
213 | 227 | ||
214 | /** | 228 | /** |
215 | * TODO | 229 | * TODO |
@@ -420,7 +434,7 @@ GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group, | |||
420 | * @param group | 434 | * @param group |
421 | */ | 435 | */ |
422 | void* | 436 | void* |
423 | GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group); | 437 | GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group); |
424 | 438 | ||
425 | /** | 439 | /** |
426 | * TODO | 440 | * TODO |
@@ -492,18 +506,9 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | |||
492 | */ | 506 | */ |
493 | int | 507 | int |
494 | GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | 508 | GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, |
495 | const char *path); | 509 | const char *path, |
496 | 510 | GNUNET_CHAT_FileUploadCallback callback, | |
497 | /** | 511 | void *cls); |
498 | * TODO | ||
499 | * | ||
500 | * @param context | ||
501 | * @param uri | ||
502 | * @return | ||
503 | */ | ||
504 | int | ||
505 | GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context, | ||
506 | const char *uri); | ||
507 | 512 | ||
508 | /** | 513 | /** |
509 | * TODO | 514 | * TODO |
@@ -657,11 +662,30 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); | |||
657 | * TODO | 662 | * TODO |
658 | * | 663 | * |
659 | * @param file | 664 | * @param file |
665 | * @param user_pointer | ||
666 | */ | ||
667 | void | ||
668 | GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file, | ||
669 | void *user_pointer); | ||
670 | |||
671 | /** | ||
672 | * TODO | ||
673 | * | ||
674 | * @param file | ||
675 | * @return | ||
676 | */ | ||
677 | void* | ||
678 | GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file); | ||
679 | |||
680 | /** | ||
681 | * TODO | ||
682 | * | ||
683 | * @param file | ||
660 | * @return | 684 | * @return |
661 | */ | 685 | */ |
662 | int | 686 | int |
663 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | 687 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, |
664 | GNUNET_CHAT_MessageFileDownloadCallback callback, | 688 | GNUNET_CHAT_FileDownloadCallback callback, |
665 | void *cls); | 689 | void *cls); |
666 | 690 | ||
667 | /** | 691 | /** |
@@ -695,10 +719,14 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); | |||
695 | * TODO | 719 | * TODO |
696 | * | 720 | * |
697 | * @param file | 721 | * @param file |
722 | * @param callback | ||
723 | * @param cls | ||
698 | * @return | 724 | * @return |
699 | */ | 725 | */ |
700 | int | 726 | int |
701 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file); | 727 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, |
728 | GNUNET_CHAT_FileUnindexCallback callback, | ||
729 | void *cls); | ||
702 | 730 | ||
703 | /** | 731 | /** |
704 | * TODO | 732 | * TODO |
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index caca1f0..06f9c88 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -138,7 +138,9 @@ context_save_config (const struct GNUNET_CHAT_Context *context) | |||
138 | char* filename; | 138 | char* filename; |
139 | util_get_filename(directory, "chats", hash, &filename); | 139 | util_get_filename(directory, "chats", hash, &filename); |
140 | 140 | ||
141 | GNUNET_CONFIGURATION_write(config, filename); | 141 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename)) |
142 | GNUNET_CONFIGURATION_write(config, filename); | ||
143 | |||
142 | GNUNET_CONFIGURATION_destroy(config); | 144 | GNUNET_CONFIGURATION_destroy(config); |
143 | 145 | ||
144 | GNUNET_free(filename); | 146 | GNUNET_free(filename); |
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c index fdfbe4c..063448e 100644 --- a/src/gnunet_chat_file.c +++ b/src/gnunet_chat_file.c | |||
@@ -39,10 +39,6 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle, | |||
39 | GNUNET_memcpy(&(file->key), &(message->key), sizeof(file->key)); | 39 | GNUNET_memcpy(&(file->key), &(message->key), sizeof(file->key)); |
40 | GNUNET_memcpy(&(file->hash), &(message->hash), sizeof(file->hash)); | 40 | GNUNET_memcpy(&(file->hash), &(message->hash), sizeof(file->hash)); |
41 | 41 | ||
42 | file->published = 0; | ||
43 | file->downloaded = 0; | ||
44 | file->unindexed = 0; | ||
45 | |||
46 | file->meta = GNUNET_CONTAINER_meta_data_create(); | 42 | file->meta = GNUNET_CONTAINER_meta_data_create(); |
47 | 43 | ||
48 | file->uri = GNUNET_FS_uri_parse(message->uri, NULL); | 44 | file->uri = GNUNET_FS_uri_parse(message->uri, NULL); |
@@ -50,6 +46,17 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle, | |||
50 | file->publish = NULL; | 46 | file->publish = NULL; |
51 | file->unindex = NULL; | 47 | file->unindex = NULL; |
52 | 48 | ||
49 | file->upload_head = NULL; | ||
50 | file->upload_tail = NULL; | ||
51 | |||
52 | file->download_head = NULL; | ||
53 | file->download_tail = NULL; | ||
54 | |||
55 | file->unindex_head = NULL; | ||
56 | file->unindex_tail = NULL; | ||
57 | |||
58 | file->user_pointer = NULL; | ||
59 | |||
53 | return file; | 60 | return file; |
54 | } | 61 | } |
55 | 62 | ||
@@ -67,10 +74,6 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, | |||
67 | GNUNET_memcpy(&(file->key), key, sizeof(file->key)); | 74 | GNUNET_memcpy(&(file->key), key, sizeof(file->key)); |
68 | GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash)); | 75 | GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash)); |
69 | 76 | ||
70 | file->published = 0; | ||
71 | file->downloaded = 0; | ||
72 | file->unindexed = 0; | ||
73 | |||
74 | file->meta = GNUNET_CONTAINER_meta_data_create(); | 77 | file->meta = GNUNET_CONTAINER_meta_data_create(); |
75 | 78 | ||
76 | file->uri = NULL; | 79 | file->uri = NULL; |
@@ -78,12 +81,65 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, | |||
78 | file->publish = NULL; | 81 | file->publish = NULL; |
79 | file->unindex = NULL; | 82 | file->unindex = NULL; |
80 | 83 | ||
84 | file->upload_head = NULL; | ||
85 | file->upload_tail = NULL; | ||
86 | |||
87 | file->download_head = NULL; | ||
88 | file->download_tail = NULL; | ||
89 | |||
90 | file->unindex_head = NULL; | ||
91 | file->unindex_tail = NULL; | ||
92 | |||
93 | file->user_pointer = NULL; | ||
94 | |||
81 | return file; | 95 | return file; |
82 | } | 96 | } |
83 | 97 | ||
84 | void | 98 | void |
85 | file_destroy (struct GNUNET_CHAT_File* file) | 99 | file_destroy (struct GNUNET_CHAT_File* file) |
86 | { | 100 | { |
101 | struct GNUNET_CHAT_FileUpload *upload; | ||
102 | while (file->upload_head) | ||
103 | { | ||
104 | upload = file->upload_head; | ||
105 | |||
106 | GNUNET_CONTAINER_DLL_remove( | ||
107 | file->upload_head, | ||
108 | file->upload_tail, | ||
109 | upload | ||
110 | ); | ||
111 | |||
112 | GNUNET_free(upload); | ||
113 | } | ||
114 | |||
115 | struct GNUNET_CHAT_FileDownload *download; | ||
116 | while (file->download_head) | ||
117 | { | ||
118 | download = file->download_head; | ||
119 | |||
120 | GNUNET_CONTAINER_DLL_remove( | ||
121 | file->download_head, | ||
122 | file->download_tail, | ||
123 | download | ||
124 | ); | ||
125 | |||
126 | GNUNET_free(download); | ||
127 | } | ||
128 | |||
129 | struct GNUNET_CHAT_FileUnindex *unindex; | ||
130 | while (file->unindex_head) | ||
131 | { | ||
132 | unindex = file->unindex_head; | ||
133 | |||
134 | GNUNET_CONTAINER_DLL_remove( | ||
135 | file->unindex_head, | ||
136 | file->unindex_tail, | ||
137 | unindex | ||
138 | ); | ||
139 | |||
140 | GNUNET_free(unindex); | ||
141 | } | ||
142 | |||
87 | if (file->uri) | 143 | if (file->uri) |
88 | GNUNET_FS_uri_destroy(file->uri); | 144 | GNUNET_FS_uri_destroy(file->uri); |
89 | 145 | ||
@@ -95,3 +151,150 @@ file_destroy (struct GNUNET_CHAT_File* file) | |||
95 | 151 | ||
96 | GNUNET_free(file); | 152 | GNUNET_free(file); |
97 | } | 153 | } |
154 | |||
155 | void | ||
156 | file_bind_upload (struct GNUNET_CHAT_File* file, | ||
157 | GNUNET_CHAT_FileUploadCallback cb, void *cls) | ||
158 | { | ||
159 | struct GNUNET_CHAT_FileUpload *upload = GNUNET_new( | ||
160 | struct GNUNET_CHAT_FileUpload | ||
161 | ); | ||
162 | |||
163 | upload->callback = cb; | ||
164 | upload->cls = cls; | ||
165 | |||
166 | GNUNET_CONTAINER_DLL_insert( | ||
167 | file->upload_head, | ||
168 | file->upload_tail, | ||
169 | upload | ||
170 | ); | ||
171 | } | ||
172 | |||
173 | void | ||
174 | file_bind_downlaod (struct GNUNET_CHAT_File* file, | ||
175 | GNUNET_CHAT_FileDownloadCallback cb, void *cls) | ||
176 | { | ||
177 | struct GNUNET_CHAT_FileDownload *download = GNUNET_new( | ||
178 | struct GNUNET_CHAT_FileDownload | ||
179 | ); | ||
180 | |||
181 | download->callback = cb; | ||
182 | download->cls = cls; | ||
183 | |||
184 | GNUNET_CONTAINER_DLL_insert( | ||
185 | file->download_head, | ||
186 | file->download_tail, | ||
187 | download | ||
188 | ); | ||
189 | } | ||
190 | |||
191 | void | ||
192 | file_bind_unindex (struct GNUNET_CHAT_File* file, | ||
193 | GNUNET_CHAT_FileUnindexCallback cb, void *cls) | ||
194 | { | ||
195 | struct GNUNET_CHAT_FileUnindex *unindex = GNUNET_new( | ||
196 | struct GNUNET_CHAT_FileUnindex | ||
197 | ); | ||
198 | |||
199 | unindex->callback = cb; | ||
200 | unindex->cls = cls; | ||
201 | |||
202 | GNUNET_CONTAINER_DLL_insert( | ||
203 | file->unindex_head, | ||
204 | file->unindex_tail, | ||
205 | unindex | ||
206 | ); | ||
207 | } | ||
208 | |||
209 | void | ||
210 | file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
211 | uint64_t size) | ||
212 | { | ||
213 | struct GNUNET_CHAT_FileUpload *upload = file->upload_head; | ||
214 | |||
215 | while (upload) | ||
216 | { | ||
217 | if (upload->callback) | ||
218 | upload->callback(upload->cls, file, completed, size); | ||
219 | |||
220 | upload = upload->next; | ||
221 | } | ||
222 | |||
223 | if (completed < size) | ||
224 | return; | ||
225 | |||
226 | while (file->upload_head) | ||
227 | { | ||
228 | upload = file->upload_head; | ||
229 | |||
230 | GNUNET_CONTAINER_DLL_remove( | ||
231 | file->upload_head, | ||
232 | file->upload_tail, | ||
233 | upload | ||
234 | ); | ||
235 | |||
236 | GNUNET_free(upload); | ||
237 | } | ||
238 | } | ||
239 | |||
240 | void | ||
241 | file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
242 | uint64_t size) | ||
243 | { | ||
244 | struct GNUNET_CHAT_FileDownload *download = file->download_head; | ||
245 | |||
246 | while (download) | ||
247 | { | ||
248 | if (download->callback) | ||
249 | download->callback(download->cls, file, completed, size); | ||
250 | |||
251 | download = download->next; | ||
252 | } | ||
253 | |||
254 | if (completed < size) | ||
255 | return; | ||
256 | |||
257 | while (file->download_head) | ||
258 | { | ||
259 | download = file->download_head; | ||
260 | |||
261 | GNUNET_CONTAINER_DLL_remove( | ||
262 | file->download_head, | ||
263 | file->download_tail, | ||
264 | download | ||
265 | ); | ||
266 | |||
267 | GNUNET_free(download); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | void | ||
272 | file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
273 | uint64_t size) | ||
274 | { | ||
275 | struct GNUNET_CHAT_FileUnindex *unindex = file->unindex_head; | ||
276 | |||
277 | while (unindex) | ||
278 | { | ||
279 | if (unindex->callback) | ||
280 | unindex->callback(unindex->cls, file, completed, size); | ||
281 | |||
282 | unindex = unindex->next; | ||
283 | } | ||
284 | |||
285 | if (completed < size) | ||
286 | return; | ||
287 | |||
288 | while (file->unindex_head) | ||
289 | { | ||
290 | unindex = file->unindex_head; | ||
291 | |||
292 | GNUNET_CONTAINER_DLL_remove( | ||
293 | file->unindex_head, | ||
294 | file->unindex_tail, | ||
295 | unindex | ||
296 | ); | ||
297 | |||
298 | GNUNET_free(unindex); | ||
299 | } | ||
300 | } | ||
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h index e4f4e12..3642896 100644 --- a/src/gnunet_chat_file.h +++ b/src/gnunet_chat_file.h | |||
@@ -32,6 +32,38 @@ | |||
32 | #include <gnunet/gnunet_messenger_service.h> | 32 | #include <gnunet/gnunet_messenger_service.h> |
33 | #include <gnunet/gnunet_util_lib.h> | 33 | #include <gnunet/gnunet_util_lib.h> |
34 | 34 | ||
35 | #include "gnunet_chat_lib.h" | ||
36 | |||
37 | struct GNUNET_CHAT_FileUpload | ||
38 | { | ||
39 | struct GNUNET_CHAT_FileUpload* prev; | ||
40 | struct GNUNET_CHAT_FileUpload* next; | ||
41 | |||
42 | GNUNET_CHAT_FileUploadCallback callback; | ||
43 | |||
44 | void *cls; | ||
45 | }; | ||
46 | |||
47 | struct GNUNET_CHAT_FileDownload | ||
48 | { | ||
49 | struct GNUNET_CHAT_FileDownload* prev; | ||
50 | struct GNUNET_CHAT_FileDownload* next; | ||
51 | |||
52 | GNUNET_CHAT_FileDownloadCallback callback; | ||
53 | |||
54 | void *cls; | ||
55 | }; | ||
56 | |||
57 | struct GNUNET_CHAT_FileUnindex | ||
58 | { | ||
59 | struct GNUNET_CHAT_FileUnindex* prev; | ||
60 | struct GNUNET_CHAT_FileUnindex* next; | ||
61 | |||
62 | GNUNET_CHAT_FileUnindexCallback callback; | ||
63 | |||
64 | void *cls; | ||
65 | }; | ||
66 | |||
35 | struct GNUNET_CHAT_Handle; | 67 | struct GNUNET_CHAT_Handle; |
36 | 68 | ||
37 | struct GNUNET_CHAT_File | 69 | struct GNUNET_CHAT_File |
@@ -43,16 +75,23 @@ struct GNUNET_CHAT_File | |||
43 | struct GNUNET_HashCode hash; | 75 | struct GNUNET_HashCode hash; |
44 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | 76 | struct GNUNET_CRYPTO_SymmetricSessionKey key; |
45 | 77 | ||
46 | uint64_t published; | ||
47 | uint64_t downloaded; | ||
48 | uint64_t unindexed; | ||
49 | |||
50 | struct GNUNET_CONTAINER_MetaData *meta; | 78 | struct GNUNET_CONTAINER_MetaData *meta; |
51 | 79 | ||
52 | struct GNUNET_FS_Uri* uri; | 80 | struct GNUNET_FS_Uri *uri; |
53 | struct GNUNET_FS_DownloadContext* download; | 81 | struct GNUNET_FS_DownloadContext *download; |
54 | struct GNUNET_FS_PublishContext* publish; | 82 | struct GNUNET_FS_PublishContext *publish; |
55 | struct GNUNET_FS_UnindexContext* unindex; | 83 | struct GNUNET_FS_UnindexContext *unindex; |
84 | |||
85 | struct GNUNET_CHAT_FileUpload *upload_head; | ||
86 | struct GNUNET_CHAT_FileUpload *upload_tail; | ||
87 | |||
88 | struct GNUNET_CHAT_FileDownload *download_head; | ||
89 | struct GNUNET_CHAT_FileDownload *download_tail; | ||
90 | |||
91 | struct GNUNET_CHAT_FileUnindex *unindex_head; | ||
92 | struct GNUNET_CHAT_FileUnindex *unindex_tail; | ||
93 | |||
94 | void *user_pointer; | ||
56 | }; | 95 | }; |
57 | 96 | ||
58 | struct GNUNET_CHAT_File* | 97 | struct GNUNET_CHAT_File* |
@@ -67,4 +106,28 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, | |||
67 | void | 106 | void |
68 | file_destroy (struct GNUNET_CHAT_File* file); | 107 | file_destroy (struct GNUNET_CHAT_File* file); |
69 | 108 | ||
109 | void | ||
110 | file_bind_upload (struct GNUNET_CHAT_File* file, | ||
111 | GNUNET_CHAT_FileUploadCallback cb, void *cls); | ||
112 | |||
113 | void | ||
114 | file_bind_downlaod (struct GNUNET_CHAT_File* file, | ||
115 | GNUNET_CHAT_FileDownloadCallback cb, void *cls); | ||
116 | |||
117 | void | ||
118 | file_bind_unindex (struct GNUNET_CHAT_File* file, | ||
119 | GNUNET_CHAT_FileUnindexCallback cb, void *cls); | ||
120 | |||
121 | void | ||
122 | file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
123 | uint64_t size); | ||
124 | |||
125 | void | ||
126 | file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
127 | uint64_t size); | ||
128 | |||
129 | void | ||
130 | file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed, | ||
131 | uint64_t size); | ||
132 | |||
70 | #endif /* GNUNET_CHAT_FILE_H_ */ | 133 | #endif /* GNUNET_CHAT_FILE_H_ */ |
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c index 0355dd5..a2aab29 100644 --- a/src/gnunet_chat_group.c +++ b/src/gnunet_chat_group.c | |||
@@ -23,6 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "gnunet_chat_group.h" | 25 | #include "gnunet_chat_group.h" |
26 | #include "gnunet_chat_util.h" | ||
26 | 27 | ||
27 | #include "gnunet_chat_group_intern.c" | 28 | #include "gnunet_chat_group_intern.c" |
28 | 29 | ||
@@ -63,14 +64,98 @@ group_destroy (struct GNUNET_CHAT_Group* group) | |||
63 | void | 64 | void |
64 | group_publish (struct GNUNET_CHAT_Group* group) | 65 | group_publish (struct GNUNET_CHAT_Group* group) |
65 | { | 66 | { |
67 | char* topic = NULL; | ||
68 | GNUNET_asprintf ( | ||
69 | &topic, | ||
70 | "GNUNET_CHAT_%s", | ||
71 | group->topic | ||
72 | ); | ||
73 | |||
66 | group->announcement = GNUNET_REGEX_announce( | 74 | group->announcement = GNUNET_REGEX_announce( |
67 | group->handle->cfg, group->topic, // TODO: raw topic? | 75 | group->handle->cfg, topic, |
68 | GNUNET_TIME_relative_get_minute_(), // TODO: configure delay? | 76 | GNUNET_TIME_relative_get_minute_(), |
69 | 1 // TODO: no compression? | 77 | 6 |
70 | ); | 78 | ); |
71 | 79 | ||
72 | group->search = GNUNET_REGEX_search( | 80 | group->search = GNUNET_REGEX_search( |
73 | group->handle->cfg, group->topic, // TODO: raw topic? | 81 | group->handle->cfg, topic, |
74 | search_group_by_topic, group | 82 | search_group_by_topic, group |
75 | ); | 83 | ); |
84 | |||
85 | GNUNET_free(topic); | ||
86 | } | ||
87 | |||
88 | void | ||
89 | group_load_config (struct GNUNET_CHAT_Group *group) | ||
90 | { | ||
91 | const char *directory = group->handle->directory; | ||
92 | |||
93 | if ((!directory) || (!(group->context))) | ||
94 | return; | ||
95 | |||
96 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
97 | group->context->room | ||
98 | ); | ||
99 | |||
100 | char* filename; | ||
101 | util_get_filename(directory, "groups", hash, &filename); | ||
102 | |||
103 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | ||
104 | goto free_filename; | ||
105 | |||
106 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
107 | |||
108 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, directory)) | ||
109 | goto destroy_config; | ||
110 | |||
111 | char* name = NULL; | ||
112 | |||
113 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | ||
114 | config, "group", "topic", &name)) | ||
115 | util_set_name_field(name, &(group->topic)); | ||
116 | |||
117 | if (name) | ||
118 | GNUNET_free(name); | ||
119 | |||
120 | destroy_config: | ||
121 | GNUNET_CONFIGURATION_destroy(config); | ||
122 | |||
123 | free_filename: | ||
124 | GNUNET_free(filename); | ||
125 | } | ||
126 | |||
127 | void | ||
128 | group_save_config (const struct GNUNET_CHAT_Group *group) | ||
129 | { | ||
130 | const char *directory = group->handle->directory; | ||
131 | |||
132 | if ((!directory) || (!(group->context))) | ||
133 | return; | ||
134 | |||
135 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
136 | group->context->room | ||
137 | ); | ||
138 | |||
139 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
140 | |||
141 | if (group->topic) | ||
142 | { | ||
143 | struct GNUNET_HashCode topic_hash; | ||
144 | GNUNET_CRYPTO_hash(group->topic, strlen(group->topic), &topic_hash); | ||
145 | |||
146 | if (0 == GNUNET_memcmp(hash, &topic_hash)) | ||
147 | GNUNET_CONFIGURATION_set_value_string( | ||
148 | config, "group", "topic", group->topic | ||
149 | ); | ||
150 | } | ||
151 | |||
152 | char* filename; | ||
153 | util_get_filename(directory, "groups", hash, &filename); | ||
154 | |||
155 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename)) | ||
156 | GNUNET_CONFIGURATION_write(config, filename); | ||
157 | |||
158 | GNUNET_CONFIGURATION_destroy(config); | ||
159 | |||
160 | GNUNET_free(filename); | ||
76 | } | 161 | } |
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h index a2fdfdc..13770d4 100644 --- a/src/gnunet_chat_group.h +++ b/src/gnunet_chat_group.h | |||
@@ -56,4 +56,10 @@ group_destroy (struct GNUNET_CHAT_Group* group); | |||
56 | void | 56 | void |
57 | group_publish (struct GNUNET_CHAT_Group* group); | 57 | group_publish (struct GNUNET_CHAT_Group* group); |
58 | 58 | ||
59 | void | ||
60 | group_load_config (struct GNUNET_CHAT_Group *group); | ||
61 | |||
62 | void | ||
63 | group_save_config (const struct GNUNET_CHAT_Group *group); | ||
64 | |||
59 | #endif /* GNUNET_CHAT_GROUP_H_ */ | 65 | #endif /* GNUNET_CHAT_GROUP_H_ */ |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index 8e664d0..7c9e578 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -64,13 +64,23 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
64 | if (handle->arm) | 64 | if (handle->arm) |
65 | on_handle_arm_connection(handle, GNUNET_NO); | 65 | on_handle_arm_connection(handle, GNUNET_NO); |
66 | 66 | ||
67 | char* fs_client_name = NULL; | ||
68 | GNUNET_asprintf ( | ||
69 | &fs_client_name, | ||
70 | "GNUNET_CHAT_%s%s", | ||
71 | name? "_" : "anonymous", | ||
72 | name? name : "" | ||
73 | ); | ||
74 | |||
67 | handle->fs = GNUNET_FS_start( | 75 | handle->fs = GNUNET_FS_start( |
68 | handle->cfg, name, // TODO: raw name? (NULL?) | 76 | handle->cfg, fs_client_name, |
69 | notify_handle_fs_progress, handle, | 77 | notify_handle_fs_progress, handle, |
70 | GNUNET_FS_FLAGS_NONE, | 78 | GNUNET_FS_FLAGS_NONE, |
71 | GNUNET_FS_OPTIONS_END | 79 | GNUNET_FS_OPTIONS_END |
72 | ); | 80 | ); |
73 | 81 | ||
82 | GNUNET_free(fs_client_name); | ||
83 | |||
74 | handle->messenger = GNUNET_MESSENGER_connect( | 84 | handle->messenger = GNUNET_MESSENGER_connect( |
75 | handle->cfg, name, | 85 | handle->cfg, name, |
76 | on_handle_identity, handle, | 86 | on_handle_identity, handle, |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index bcf0508..17bff20 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -71,13 +71,21 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
71 | case GNUNET_FS_STATUS_PUBLISH_START: { | 71 | case GNUNET_FS_STATUS_PUBLISH_START: { |
72 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; | 72 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; |
73 | 73 | ||
74 | file->published = 0; | 74 | file_update_upload( |
75 | file, | ||
76 | 0, | ||
77 | info->value.publish.size | ||
78 | ); | ||
75 | 79 | ||
76 | return file; | 80 | return file; |
77 | } case GNUNET_FS_STATUS_PUBLISH_PROGRESS: { | 81 | } case GNUNET_FS_STATUS_PUBLISH_PROGRESS: { |
78 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; | 82 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; |
79 | 83 | ||
80 | file->published = info->value.publish.completed; | 84 | file_update_upload( |
85 | file, | ||
86 | info->value.publish.completed, | ||
87 | info->value.publish.size | ||
88 | ); | ||
81 | 89 | ||
82 | return file; | 90 | return file; |
83 | } case GNUNET_FS_STATUS_PUBLISH_COMPLETED: { | 91 | } case GNUNET_FS_STATUS_PUBLISH_COMPLETED: { |
@@ -87,7 +95,12 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
87 | info->value.publish.specifics.completed.chk_uri | 95 | info->value.publish.specifics.completed.chk_uri |
88 | ); | 96 | ); |
89 | 97 | ||
90 | file->published = info->value.publish.size; | 98 | file_update_upload( |
99 | file, | ||
100 | info->value.publish.size, | ||
101 | info->value.publish.size | ||
102 | ); | ||
103 | |||
91 | file->publish = NULL; | 104 | file->publish = NULL; |
92 | break; | 105 | break; |
93 | } case GNUNET_FS_STATUS_PUBLISH_ERROR: { | 106 | } case GNUNET_FS_STATUS_PUBLISH_ERROR: { |
@@ -95,7 +108,11 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
95 | } case GNUNET_FS_STATUS_DOWNLOAD_START: { | 108 | } case GNUNET_FS_STATUS_DOWNLOAD_START: { |
96 | struct GNUNET_CHAT_File *file = info->value.download.cctx; | 109 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
97 | 110 | ||
98 | file->downloaded = 0; | 111 | file_update_download( |
112 | file, | ||
113 | 0, | ||
114 | info->value.download.size | ||
115 | ); | ||
99 | 116 | ||
100 | return file; | 117 | return file; |
101 | } case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: { | 118 | } case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: { |
@@ -105,13 +122,22 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
105 | } case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: { | 122 | } case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: { |
106 | struct GNUNET_CHAT_File *file = info->value.download.cctx; | 123 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
107 | 124 | ||
108 | file->downloaded = info->value.download.completed; | 125 | file_update_download( |
126 | file, | ||
127 | info->value.download.completed, | ||
128 | info->value.download.size | ||
129 | ); | ||
109 | 130 | ||
110 | return file; | 131 | return file; |
111 | } case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: { | 132 | } case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: { |
112 | struct GNUNET_CHAT_File *file = info->value.download.cctx; | 133 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
113 | 134 | ||
114 | file->downloaded = info->value.download.size; | 135 | file_update_download( |
136 | file, | ||
137 | info->value.download.size, | ||
138 | info->value.download.size | ||
139 | ); | ||
140 | |||
115 | file->download = NULL; | 141 | file->download = NULL; |
116 | break; | 142 | break; |
117 | } case GNUNET_FS_STATUS_DOWNLOAD_ERROR: { | 143 | } case GNUNET_FS_STATUS_DOWNLOAD_ERROR: { |
@@ -119,19 +145,32 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
119 | } case GNUNET_FS_STATUS_UNINDEX_START: { | 145 | } case GNUNET_FS_STATUS_UNINDEX_START: { |
120 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; | 146 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
121 | 147 | ||
122 | file->unindexed = 0; | 148 | file_update_unindex( |
149 | file, | ||
150 | 0, | ||
151 | info->value.unindex.size | ||
152 | ); | ||
123 | 153 | ||
124 | return file; | 154 | return file; |
125 | } case GNUNET_FS_STATUS_UNINDEX_PROGRESS: { | 155 | } case GNUNET_FS_STATUS_UNINDEX_PROGRESS: { |
126 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; | 156 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
127 | 157 | ||
128 | file->unindexed = info->value.unindex.completed; | 158 | file_update_unindex( |
159 | file, | ||
160 | info->value.unindex.completed, | ||
161 | info->value.unindex.size | ||
162 | ); | ||
129 | 163 | ||
130 | return file; | 164 | return file; |
131 | } case GNUNET_FS_STATUS_UNINDEX_COMPLETED: { | 165 | } case GNUNET_FS_STATUS_UNINDEX_COMPLETED: { |
132 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; | 166 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
133 | 167 | ||
134 | file->unindexed = info->value.unindex.size; | 168 | file_update_unindex( |
169 | file, | ||
170 | info->value.unindex.size, | ||
171 | info->value.unindex.size | ||
172 | ); | ||
173 | |||
135 | file->unindex = NULL; | 174 | file->unindex = NULL; |
136 | break; | 175 | break; |
137 | } default: { | 176 | } default: { |
@@ -225,6 +264,11 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
225 | handle, context | 264 | handle, context |
226 | ); | 265 | ); |
227 | 266 | ||
267 | group_load_config(group); | ||
268 | |||
269 | if (group->topic) | ||
270 | group_publish(group); | ||
271 | |||
228 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( | 272 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put( |
229 | handle->groups, key, group, | 273 | handle->groups, key, group, |
230 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 274 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
@@ -382,6 +426,7 @@ it_destroy_handle_groups (GNUNET_UNUSED void *cls, | |||
382 | void *value) | 426 | void *value) |
383 | { | 427 | { |
384 | struct GNUNET_CHAT_Group *group = value; | 428 | struct GNUNET_CHAT_Group *group = value; |
429 | group_save_config(group); | ||
385 | group_destroy(group); | 430 | group_destroy(group); |
386 | return GNUNET_YES; | 431 | return GNUNET_YES; |
387 | } | 432 | } |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index a835e48..cdce90c 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -374,7 +374,7 @@ GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group, | |||
374 | 374 | ||
375 | 375 | ||
376 | void* | 376 | void* |
377 | GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group) | 377 | GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group) |
378 | { | 378 | { |
379 | if (!group) | 379 | if (!group) |
380 | return NULL; | 380 | return NULL; |
@@ -475,7 +475,9 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | |||
475 | 475 | ||
476 | int | 476 | int |
477 | GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | 477 | GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, |
478 | const char *path) | 478 | const char *path, |
479 | GNUNET_CHAT_FileUploadCallback callback, | ||
480 | void *cls) | ||
479 | { | 481 | { |
480 | if ((!context) || (!path)) | 482 | if ((!context) || (!path)) |
481 | return GNUNET_SYSERR; | 483 | return GNUNET_SYSERR; |
@@ -516,6 +518,8 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
516 | 518 | ||
517 | GNUNET_free(p); | 519 | GNUNET_free(p); |
518 | 520 | ||
521 | file_bind_upload(file, callback, cls); | ||
522 | |||
519 | struct GNUNET_FS_BlockOptions bo; | 523 | struct GNUNET_FS_BlockOptions bo; |
520 | 524 | ||
521 | bo.anonymity_level = 1; | 525 | bo.anonymity_level = 1; |
@@ -543,32 +547,11 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
543 | ); | 547 | ); |
544 | 548 | ||
545 | GNUNET_free(filename); | 549 | GNUNET_free(filename); |
546 | |||
547 | // TODO: share file | ||
548 | |||
549 | return GNUNET_OK; | 550 | return GNUNET_OK; |
550 | } | 551 | } |
551 | 552 | ||
552 | 553 | ||
553 | int | 554 | int |
554 | GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context, | ||
555 | const char *uri) | ||
556 | { | ||
557 | if ((!context) || (!uri)) | ||
558 | return GNUNET_SYSERR; | ||
559 | |||
560 | struct GNUNET_FS_Uri *furi = GNUNET_FS_uri_parse(uri, NULL); | ||
561 | |||
562 | if (!furi) | ||
563 | return GNUNET_SYSERR; | ||
564 | |||
565 | // TODO: download file, hash file, share file | ||
566 | |||
567 | return GNUNET_SYSERR; | ||
568 | } | ||
569 | |||
570 | |||
571 | int | ||
572 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, | 555 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, |
573 | const struct GNUNET_CHAT_File *file) | 556 | const struct GNUNET_CHAT_File *file) |
574 | { | 557 | { |
@@ -833,9 +816,30 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) | |||
833 | } | 816 | } |
834 | 817 | ||
835 | 818 | ||
819 | void | ||
820 | GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file, | ||
821 | void *user_pointer) | ||
822 | { | ||
823 | if (!file) | ||
824 | return; | ||
825 | |||
826 | file->user_pointer = user_pointer; | ||
827 | } | ||
828 | |||
829 | |||
830 | void* | ||
831 | GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file) | ||
832 | { | ||
833 | if (!file) | ||
834 | return NULL; | ||
835 | |||
836 | return file->user_pointer; | ||
837 | } | ||
838 | |||
839 | |||
836 | int | 840 | int |
837 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | 841 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, |
838 | GNUNET_CHAT_MessageFileDownloadCallback callback, | 842 | GNUNET_CHAT_FileDownloadCallback callback, |
839 | void *cls) | 843 | void *cls) |
840 | { | 844 | { |
841 | if ((!file) || (!(file->uri))) | 845 | if ((!file) || (!(file->uri))) |
@@ -843,8 +847,10 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
843 | 847 | ||
844 | if (file->download) | 848 | if (file->download) |
845 | { | 849 | { |
850 | file_bind_downlaod(file, callback, cls); | ||
851 | |||
846 | GNUNET_FS_download_resume(file->download); | 852 | GNUNET_FS_download_resume(file->download); |
847 | return GNUNET_OK; | 853 | return GNUNET_NO; |
848 | } | 854 | } |
849 | 855 | ||
850 | const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); | 856 | const uint64_t size = GNUNET_FS_uri_chk_get_file_size(file->uri); |
@@ -859,7 +865,14 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
859 | offset = 0; | 865 | offset = 0; |
860 | 866 | ||
861 | if (offset >= size) | 867 | if (offset >= size) |
862 | return GNUNET_OK; | 868 | { |
869 | if (callback) | ||
870 | callback(cls, file, size, size); | ||
871 | |||
872 | return GNUNET_YES; | ||
873 | } | ||
874 | |||
875 | file_bind_downlaod(file, callback, cls); | ||
863 | 876 | ||
864 | const uint64_t remaining = (size - offset); | 877 | const uint64_t remaining = (size - offset); |
865 | 878 | ||
@@ -878,7 +891,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
878 | ); | 891 | ); |
879 | 892 | ||
880 | GNUNET_free(filename); | 893 | GNUNET_free(filename); |
881 | return GNUNET_OK; | 894 | return GNUNET_YES; |
882 | } | 895 | } |
883 | 896 | ||
884 | 897 | ||
@@ -917,7 +930,9 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | |||
917 | 930 | ||
918 | 931 | ||
919 | int | 932 | int |
920 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file) | 933 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, |
934 | GNUNET_CHAT_FileUnindexCallback callback, | ||
935 | void *cls) | ||
921 | { | 936 | { |
922 | if (!file) | 937 | if (!file) |
923 | return GNUNET_SYSERR; | 938 | return GNUNET_SYSERR; |
@@ -929,6 +944,8 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file) | |||
929 | return GNUNET_OK; | 944 | return GNUNET_OK; |
930 | } | 945 | } |
931 | 946 | ||
947 | file_bind_unindex(file, callback, cls); | ||
948 | |||
932 | if (file->unindex) | 949 | if (file->unindex) |
933 | return GNUNET_OK; | 950 | return GNUNET_OK; |
934 | 951 | ||