diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-01-14 22:58:15 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-01-14 22:58:15 +0100 |
commit | ae5feca119e594767102ce7bcc17d1a3b7580a52 (patch) | |
tree | da00a4ea4e72f05de67d30a604b0d2ca2c0c54cb | |
parent | 4db9842adc64fe254a2e61ce214b2fabb2fc67f8 (diff) | |
download | libgnunetchat-ae5feca119e594767102ce7bcc17d1a3b7580a52.tar.gz libgnunetchat-ae5feca119e594767102ce7bcc17d1a3b7580a52.zip |
Adjusted API to get current status of file processing
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 45 | ||||
-rw-r--r-- | src/gnunet_chat_file.c | 20 | ||||
-rw-r--r-- | src/gnunet_chat_file.h | 6 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 64 |
4 files changed, 114 insertions, 21 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 8e8ec4e..7675ad1 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -797,7 +797,7 @@ const struct GNUNET_HashCode* | |||
797 | GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file); | 797 | GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file); |
798 | 798 | ||
799 | /** | 799 | /** |
800 | * Returns the file size of a given <i>file</i> handle. | 800 | * Returns the actual file size of a given <i>file</i> handle. |
801 | * | 801 | * |
802 | * @param[in] file File handle | 802 | * @param[in] file File handle |
803 | * @return The file size of file | 803 | * @return The file size of file |
@@ -806,19 +806,33 @@ uint64_t | |||
806 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file); | 806 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file); |
807 | 807 | ||
808 | /** | 808 | /** |
809 | * Checks whether a file locally exists of a given <i>file</i> handle and | 809 | * Returns the local file size of a given <i>file</i> handle. |
810 | * returns #GNUNET_YES in that case, otherwise #GNUNET_NO. | 810 | * |
811 | * This can be less than the actual size of the file once its download | ||
812 | * has been completed! | ||
811 | * | 813 | * |
812 | * @param[in] file File handle | 814 | * @param[in] file File handle |
813 | * @return #GNUNET_YES if the file exists locally, otherwise #GNUNET_NO | 815 | * @return The local file size of file |
816 | */ | ||
817 | uint64_t | ||
818 | GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file); | ||
819 | |||
820 | /** | ||
821 | * Returns if a given <i>file</i> handle is currently uploading. | ||
822 | * | ||
823 | * @param[in] file File handle | ||
824 | * @return #GNUNET_YES during active upload, #GNUNET_NO otherwise | ||
814 | */ | 825 | */ |
815 | int | 826 | int |
816 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); | 827 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file); |
817 | 828 | ||
818 | /** | 829 | /** |
819 | * Returns the temporary file name of the decrypted file preview | 830 | * Returns the temporary file name of the decrypted file preview |
820 | * of a given <i>file</i> handle. | 831 | * of a given <i>file</i> handle. |
821 | * | 832 | * |
833 | * This can only be used when the file handle is ready to preview! | ||
834 | * @see GNUNET_CHAT_file_is_ready() | ||
835 | * | ||
822 | * @param[in,out] file File handle | 836 | * @param[in,out] file File handle |
823 | * @return The temporary file name or NULL on error | 837 | * @return The temporary file name or NULL on error |
824 | */ | 838 | */ |
@@ -829,6 +843,9 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file); | |||
829 | * Deletes the temporary decrypted file preview of a given <i>file</i> | 843 | * Deletes the temporary decrypted file preview of a given <i>file</i> |
830 | * handle. | 844 | * handle. |
831 | * | 845 | * |
846 | * This can only be used when the file handle is ready to preview! | ||
847 | * @see GNUNET_CHAT_file_is_ready() | ||
848 | * | ||
832 | * @param[out] file File handle | 849 | * @param[out] file File handle |
833 | */ | 850 | */ |
834 | void | 851 | void |
@@ -856,6 +873,15 @@ void* | |||
856 | GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file); | 873 | GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file); |
857 | 874 | ||
858 | /** | 875 | /** |
876 | * Returns if a given <i>file</i> handle is currently downloading. | ||
877 | * | ||
878 | * @param[in] file File handle | ||
879 | * @return #GNUNET_YES during active download, #GNUNET_NO otherwise | ||
880 | */ | ||
881 | int | ||
882 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file); | ||
883 | |||
884 | /** | ||
859 | * Starts downloading a file from a given <i>file</i> handle and sets up a | 885 | * Starts downloading a file from a given <i>file</i> handle and sets up a |
860 | * selected callback and custom closure for its progress. | 886 | * selected callback and custom closure for its progress. |
861 | * | 887 | * |
@@ -897,6 +923,15 @@ int | |||
897 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); | 923 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); |
898 | 924 | ||
899 | /** | 925 | /** |
926 | * Returns if a given <i>file</i> handle is currently unindexing. | ||
927 | * | ||
928 | * @param[in] file File handle | ||
929 | * @return #GNUNET_YES during active unindexing, #GNUNET_NO otherwise | ||
930 | */ | ||
931 | int | ||
932 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file); | ||
933 | |||
934 | /** | ||
900 | * Unindexes an uploaded file from a given <i>file</i> handle with a selected | 935 | * Unindexes an uploaded file from a given <i>file</i> handle with a selected |
901 | * callback and a custom closure. | 936 | * callback and a custom closure. |
902 | * | 937 | * |
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c index 9e52ccf..e661d7e 100644 --- a/src/gnunet_chat_file.c +++ b/src/gnunet_chat_file.c | |||
@@ -61,6 +61,7 @@ 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->status = 0; | ||
64 | file->preview = NULL; | 65 | file->preview = NULL; |
65 | 66 | ||
66 | file->user_pointer = NULL; | 67 | file->user_pointer = NULL; |
@@ -104,6 +105,7 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, | |||
104 | file->unindex_head = NULL; | 105 | file->unindex_head = NULL; |
105 | file->unindex_tail = NULL; | 106 | file->unindex_tail = NULL; |
106 | 107 | ||
108 | file->status = 0; | ||
107 | file->preview = NULL; | 109 | file->preview = NULL; |
108 | 110 | ||
109 | file->user_pointer = NULL; | 111 | file->user_pointer = NULL; |
@@ -242,6 +244,8 @@ file_update_upload (struct GNUNET_CHAT_File *file, | |||
242 | { | 244 | { |
243 | GNUNET_assert(file); | 245 | GNUNET_assert(file); |
244 | 246 | ||
247 | file->status |= GNUNET_CHAT_FILE_STATUS_PUBLISH; | ||
248 | |||
245 | struct GNUNET_CHAT_FileUpload *upload = file->upload_head; | 249 | struct GNUNET_CHAT_FileUpload *upload = file->upload_head; |
246 | 250 | ||
247 | while (upload) | 251 | while (upload) |
@@ -278,6 +282,10 @@ file_update_upload (struct GNUNET_CHAT_File *file, | |||
278 | } | 282 | } |
279 | 283 | ||
280 | GNUNET_free(msg.body.file.uri); | 284 | GNUNET_free(msg.body.file.uri); |
285 | |||
286 | file->status &= ( | ||
287 | GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_PUBLISH | ||
288 | ); | ||
281 | } | 289 | } |
282 | 290 | ||
283 | void | 291 | void |
@@ -287,6 +295,8 @@ file_update_download (struct GNUNET_CHAT_File *file, | |||
287 | { | 295 | { |
288 | GNUNET_assert(file); | 296 | GNUNET_assert(file); |
289 | 297 | ||
298 | file->status |= GNUNET_CHAT_FILE_STATUS_DOWNLOAD; | ||
299 | |||
290 | struct GNUNET_CHAT_FileDownload *download = file->download_head; | 300 | struct GNUNET_CHAT_FileDownload *download = file->download_head; |
291 | 301 | ||
292 | while (download) | 302 | while (download) |
@@ -312,6 +322,10 @@ file_update_download (struct GNUNET_CHAT_File *file, | |||
312 | 322 | ||
313 | GNUNET_free(download); | 323 | GNUNET_free(download); |
314 | } | 324 | } |
325 | |||
326 | file->status &= ( | ||
327 | GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_DOWNLOAD | ||
328 | ); | ||
315 | } | 329 | } |
316 | 330 | ||
317 | void | 331 | void |
@@ -321,6 +335,8 @@ file_update_unindex (struct GNUNET_CHAT_File *file, | |||
321 | { | 335 | { |
322 | GNUNET_assert(file); | 336 | GNUNET_assert(file); |
323 | 337 | ||
338 | file->status |= GNUNET_CHAT_FILE_STATUS_UNINDEX; | ||
339 | |||
324 | struct GNUNET_CHAT_FileUnindex *unindex = file->unindex_head; | 340 | struct GNUNET_CHAT_FileUnindex *unindex = file->unindex_head; |
325 | 341 | ||
326 | while (unindex) | 342 | while (unindex) |
@@ -346,4 +362,8 @@ file_update_unindex (struct GNUNET_CHAT_File *file, | |||
346 | 362 | ||
347 | GNUNET_free(unindex); | 363 | GNUNET_free(unindex); |
348 | } | 364 | } |
365 | |||
366 | file->status &= ( | ||
367 | GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_UNINDEX | ||
368 | ); | ||
349 | } | 369 | } |
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h index 872b09a..8aa1465 100644 --- a/src/gnunet_chat_file.h +++ b/src/gnunet_chat_file.h | |||
@@ -67,6 +67,11 @@ struct GNUNET_CHAT_FileUnindex | |||
67 | 67 | ||
68 | struct GNUNET_CHAT_Handle; | 68 | struct GNUNET_CHAT_Handle; |
69 | 69 | ||
70 | #define GNUNET_CHAT_FILE_STATUS_DOWNLOAD 0x1 | ||
71 | #define GNUNET_CHAT_FILE_STATUS_PUBLISH 0x2 | ||
72 | #define GNUNET_CHAT_FILE_STATUS_UNINDEX 0x4 | ||
73 | #define GNUNET_CHAT_FILE_STATUS_MASK 0x7 | ||
74 | |||
70 | struct GNUNET_CHAT_File | 75 | struct GNUNET_CHAT_File |
71 | { | 76 | { |
72 | struct GNUNET_CHAT_Handle *handle; | 77 | struct GNUNET_CHAT_Handle *handle; |
@@ -92,6 +97,7 @@ struct GNUNET_CHAT_File | |||
92 | struct GNUNET_CHAT_FileUnindex *unindex_head; | 97 | struct GNUNET_CHAT_FileUnindex *unindex_head; |
93 | struct GNUNET_CHAT_FileUnindex *unindex_tail; | 98 | struct GNUNET_CHAT_FileUnindex *unindex_tail; |
94 | 99 | ||
100 | int status; | ||
95 | char *preview; | 101 | char *preview; |
96 | 102 | ||
97 | void *user_pointer; | 103 | void *user_pointer; |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 99d07cd..8332f1d 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -703,6 +703,9 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | |||
703 | GNUNET_FS_PUBLISH_OPTION_NONE | 703 | GNUNET_FS_PUBLISH_OPTION_NONE |
704 | ); | 704 | ); |
705 | 705 | ||
706 | if (file->publish) | ||
707 | file->status |= GNUNET_CHAT_FILE_STATUS_PUBLISH; | ||
708 | |||
706 | GNUNET_free(filename); | 709 | GNUNET_free(filename); |
707 | 710 | ||
708 | file_binding: | 711 | file_binding: |
@@ -978,11 +981,18 @@ GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file) | |||
978 | uint64_t | 981 | uint64_t |
979 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) | 982 | GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) |
980 | { | 983 | { |
981 | if (!file) | 984 | if ((!file) || (!(file->uri))) |
982 | return 0; | 985 | return 0; |
983 | 986 | ||
984 | if (file->uri) | 987 | return GNUNET_FS_uri_chk_get_file_size(file->uri); |
985 | return GNUNET_FS_uri_chk_get_file_size(file->uri); | 988 | } |
989 | |||
990 | |||
991 | uint64_t | ||
992 | GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file) | ||
993 | { | ||
994 | if (!file) | ||
995 | return 0; | ||
986 | 996 | ||
987 | char *filename; | 997 | char *filename; |
988 | util_get_filename ( | 998 | util_get_filename ( |
@@ -999,20 +1009,12 @@ GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) | |||
999 | 1009 | ||
1000 | 1010 | ||
1001 | int | 1011 | int |
1002 | GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) | 1012 | GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file) |
1003 | { | 1013 | { |
1004 | if (!file) | 1014 | if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_PUBLISH))) |
1005 | return GNUNET_SYSERR; | 1015 | return GNUNET_NO; |
1006 | 1016 | else | |
1007 | char *filename; | 1017 | return GNUNET_YES; |
1008 | util_get_filename ( | ||
1009 | file->handle->directory, "files", &(file->hash), &filename | ||
1010 | ); | ||
1011 | |||
1012 | int result = GNUNET_DISK_file_test(filename); | ||
1013 | |||
1014 | GNUNET_free(filename); | ||
1015 | return result; | ||
1016 | } | 1018 | } |
1017 | 1019 | ||
1018 | 1020 | ||
@@ -1088,6 +1090,16 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file) | |||
1088 | 1090 | ||
1089 | 1091 | ||
1090 | int | 1092 | int |
1093 | GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file) | ||
1094 | { | ||
1095 | if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_DOWNLOAD))) | ||
1096 | return GNUNET_NO; | ||
1097 | else | ||
1098 | return GNUNET_YES; | ||
1099 | } | ||
1100 | |||
1101 | |||
1102 | int | ||
1091 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | 1103 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, |
1092 | GNUNET_CHAT_FileDownloadCallback callback, | 1104 | GNUNET_CHAT_FileDownloadCallback callback, |
1093 | void *cls) | 1105 | void *cls) |
@@ -1140,6 +1152,9 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, | |||
1140 | NULL | 1152 | NULL |
1141 | ); | 1153 | ); |
1142 | 1154 | ||
1155 | if (file->download) | ||
1156 | file->status |= GNUNET_CHAT_FILE_STATUS_DOWNLOAD; | ||
1157 | |||
1143 | GNUNET_free(filename); | 1158 | GNUNET_free(filename); |
1144 | return GNUNET_OK; | 1159 | return GNUNET_OK; |
1145 | } | 1160 | } |
@@ -1180,6 +1195,18 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | |||
1180 | 1195 | ||
1181 | 1196 | ||
1182 | int | 1197 | int |
1198 | GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file) | ||
1199 | { | ||
1200 | if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_UNINDEX))) | ||
1201 | return GNUNET_NO; | ||
1202 | else | ||
1203 | return GNUNET_YES; | ||
1204 | } | ||
1205 | |||
1206 | |||
1207 | |||
1208 | |||
1209 | int | ||
1183 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, | 1210 | GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, |
1184 | GNUNET_CHAT_FileUnindexCallback callback, | 1211 | GNUNET_CHAT_FileUnindexCallback callback, |
1185 | void *cls) | 1212 | void *cls) |
@@ -1208,11 +1235,16 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, | |||
1208 | file->handle->fs, filename, file | 1235 | file->handle->fs, filename, file |
1209 | ); | 1236 | ); |
1210 | 1237 | ||
1238 | if (file->unindex) | ||
1239 | file->status |= GNUNET_CHAT_FILE_STATUS_UNINDEX; | ||
1240 | |||
1211 | GNUNET_free(filename); | 1241 | GNUNET_free(filename); |
1212 | return GNUNET_OK; | 1242 | return GNUNET_OK; |
1213 | } | 1243 | } |
1214 | 1244 | ||
1215 | 1245 | ||
1246 | |||
1247 | |||
1216 | void | 1248 | void |
1217 | GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) | 1249 | GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) |
1218 | { | 1250 | { |