diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-01-10 21:50:43 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-01-10 21:50:43 +0100 |
commit | 4db9842adc64fe254a2e61ce214b2fabb2fc67f8 (patch) | |
tree | 81e81bca056019843266b299d7c8e231ee3d028f | |
parent | ba8fe8ba1afa40046b209b1ae8ba290a09c90050 (diff) | |
download | libgnunetchat-4db9842adc64fe254a2e61ce214b2fabb2fc67f8.tar.gz libgnunetchat-4db9842adc64fe254a2e61ce214b2fabb2fc67f8.zip |
Implemented using temporary file previews
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 19 | ||||
-rw-r--r-- | src/gnunet_chat_file.c | 23 | ||||
-rw-r--r-- | src/gnunet_chat_file.h | 2 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 58 |
4 files changed, 87 insertions, 15 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index d15af55..8e8ec4e 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -816,6 +816,25 @@ int | |||
816 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); | 816 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); |
817 | 817 | ||
818 | /** | 818 | /** |
819 | * Returns the temporary file name of the decrypted file preview | ||
820 | * of a given <i>file</i> handle. | ||
821 | * | ||
822 | * @param[in,out] file File handle | ||
823 | * @return The temporary file name or NULL on error | ||
824 | */ | ||
825 | const char* | ||
826 | GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file); | ||
827 | |||
828 | /** | ||
829 | * Deletes the temporary decrypted file preview of a given <i>file</i> | ||
830 | * handle. | ||
831 | * | ||
832 | * @param[out] file File handle | ||
833 | */ | ||
834 | void | ||
835 | GNUNET_CHAT_file_close_preview (struct GNUNET_CHAT_File *file); | ||
836 | |||
837 | /** | ||
819 | * Sets a custom <i>user pointer</i> to a given <i>file</i> handle so it can | 838 | * Sets a custom <i>user pointer</i> to a given <i>file</i> handle so it can |
820 | * be accessed in file related callbacks. | 839 | * be accessed in file related callbacks. |
821 | * | 840 | * |
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c index cecee3a..9e52ccf 100644 --- a/src/gnunet_chat_file.c +++ b/src/gnunet_chat_file.c | |||
@@ -61,6 +61,8 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle, | |||
61 | file->unindex_head = NULL; | 61 | file->unindex_head = NULL; |
62 | file->unindex_tail = NULL; | 62 | file->unindex_tail = NULL; |
63 | 63 | ||
64 | file->preview = NULL; | ||
65 | |||
64 | file->user_pointer = NULL; | 66 | file->user_pointer = NULL; |
65 | 67 | ||
66 | return file; | 68 | return file; |
@@ -102,6 +104,8 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, | |||
102 | file->unindex_head = NULL; | 104 | file->unindex_head = NULL; |
103 | file->unindex_tail = NULL; | 105 | file->unindex_tail = NULL; |
104 | 106 | ||
107 | file->preview = NULL; | ||
108 | |||
105 | file->user_pointer = NULL; | 109 | file->user_pointer = NULL; |
106 | 110 | ||
107 | return file; | 111 | return file; |
@@ -251,21 +255,18 @@ file_update_upload (struct GNUNET_CHAT_File *file, | |||
251 | if (!(file->uri)) | 255 | if (!(file->uri)) |
252 | return; | 256 | return; |
253 | 257 | ||
254 | struct GNUNET_MESSENGER_Message message; | 258 | struct GNUNET_MESSENGER_Message msg; |
255 | message.header.kind = GNUNET_MESSENGER_KIND_FILE; | 259 | msg.header.kind = GNUNET_MESSENGER_KIND_FILE; |
256 | 260 | GNUNET_memcpy(&(msg.body.file.key), &(file->key), sizeof(file->key)); | |
257 | memcpy(&(message.body.file.key), &(file->key), sizeof(file->key)); | 261 | GNUNET_memcpy(&(msg.body.file.hash), &(file->hash), sizeof(file->hash)); |
258 | memcpy(&(message.body.file.hash), &(file->hash), sizeof(file->hash)); | 262 | GNUNET_strlcpy(msg.body.file.name, file->name, NAME_MAX); |
259 | 263 | msg.body.file.uri = GNUNET_FS_uri_to_string(file->uri); | |
260 | strncpy(message.body.file.name, file->name, NAME_MAX); | ||
261 | |||
262 | message.body.file.uri = GNUNET_FS_uri_to_string(file->uri); | ||
263 | 264 | ||
264 | while (file->upload_head) | 265 | while (file->upload_head) |
265 | { | 266 | { |
266 | upload = file->upload_head; | 267 | upload = file->upload_head; |
267 | 268 | ||
268 | GNUNET_MESSENGER_send_message(upload->context->room, &message, NULL); | 269 | GNUNET_MESSENGER_send_message(upload->context->room, &msg, NULL); |
269 | 270 | ||
270 | GNUNET_CONTAINER_DLL_remove( | 271 | GNUNET_CONTAINER_DLL_remove( |
271 | file->upload_head, | 272 | file->upload_head, |
@@ -276,7 +277,7 @@ file_update_upload (struct GNUNET_CHAT_File *file, | |||
276 | GNUNET_free(upload); | 277 | GNUNET_free(upload); |
277 | } | 278 | } |
278 | 279 | ||
279 | GNUNET_free(message.body.file.uri); | 280 | GNUNET_free(msg.body.file.uri); |
280 | } | 281 | } |
281 | 282 | ||
282 | void | 283 | void |
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h index d436f0b..872b09a 100644 --- a/src/gnunet_chat_file.h +++ b/src/gnunet_chat_file.h | |||
@@ -92,6 +92,8 @@ struct GNUNET_CHAT_File | |||
92 | struct GNUNET_CHAT_FileUnindex *unindex_head; | 92 | struct GNUNET_CHAT_FileUnindex *unindex_head; |
93 | struct GNUNET_CHAT_FileUnindex *unindex_tail; | 93 | struct GNUNET_CHAT_FileUnindex *unindex_tail; |
94 | 94 | ||
95 | char *preview; | ||
96 | |||
95 | void *user_pointer; | 97 | void *user_pointer; |
96 | }; | 98 | }; |
97 | 99 | ||
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index adf0eff..99d07cd 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -638,7 +638,7 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
638 | ); | 638 | ); |
639 | 639 | ||
640 | if (file) | 640 | if (file) |
641 | goto file_upload; | 641 | goto file_binding; |
642 | 642 | ||
643 | if ((GNUNET_YES == GNUNET_DISK_file_test(filename)) || | 643 | if ((GNUNET_YES == GNUNET_DISK_file_test(filename)) || |
644 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) || | 644 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(filename)) || |
@@ -677,9 +677,6 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
677 | return NULL; | 677 | return NULL; |
678 | } | 678 | } |
679 | 679 | ||
680 | file_upload: | ||
681 | file_bind_upload(file, context, callback, cls); | ||
682 | |||
683 | struct GNUNET_FS_BlockOptions bo; | 680 | struct GNUNET_FS_BlockOptions bo; |
684 | 681 | ||
685 | bo.anonymity_level = 1; | 682 | bo.anonymity_level = 1; |
@@ -707,6 +704,9 @@ file_upload: | |||
707 | ); | 704 | ); |
708 | 705 | ||
709 | GNUNET_free(filename); | 706 | GNUNET_free(filename); |
707 | |||
708 | file_binding: | ||
709 | file_bind_upload(file, context, callback, cls); | ||
710 | return file; | 710 | return file; |
711 | } | 711 | } |
712 | 712 | ||
@@ -1016,6 +1016,56 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) | |||
1016 | } | 1016 | } |
1017 | 1017 | ||
1018 | 1018 | ||
1019 | const char* | ||
1020 | GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file) | ||
1021 | { | ||
1022 | if (!file) | ||
1023 | return NULL; | ||
1024 | |||
1025 | if (file->preview) | ||
1026 | return file->preview; | ||
1027 | |||
1028 | char *filename; | ||
1029 | util_get_filename ( | ||
1030 | file->handle->directory, "files", &(file->hash), &filename | ||
1031 | ); | ||
1032 | |||
1033 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | ||
1034 | goto free_filename; | ||
1035 | |||
1036 | file->preview = GNUNET_DISK_mktemp(file->name); | ||
1037 | |||
1038 | if (!(file->preview)) | ||
1039 | goto free_filename; | ||
1040 | |||
1041 | remove(file->preview); | ||
1042 | |||
1043 | if ((GNUNET_OK != GNUNET_DISK_file_copy(filename, file->preview)) || | ||
1044 | (GNUNET_OK != util_decrypt_file(file->preview, &(file->key)))) | ||
1045 | { | ||
1046 | GNUNET_free(file->preview); | ||
1047 | file->preview = NULL; | ||
1048 | } | ||
1049 | |||
1050 | free_filename: | ||
1051 | GNUNET_free(filename); | ||
1052 | return file->preview; | ||
1053 | } | ||
1054 | |||
1055 | |||
1056 | void | ||
1057 | GNUNET_CHAT_file_close_preview (struct GNUNET_CHAT_File *file) | ||
1058 | { | ||
1059 | if ((!file) || (!(file->preview))) | ||
1060 | return; | ||
1061 | |||
1062 | remove(file->preview); | ||
1063 | |||
1064 | GNUNET_free(file->preview); | ||
1065 | file->preview = NULL; | ||
1066 | } | ||
1067 | |||
1068 | |||
1019 | void | 1069 | void |
1020 | GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file, | 1070 | GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file, |
1021 | void *user_pointer) | 1071 | void *user_pointer) |