libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit ae5feca119e594767102ce7bcc17d1a3b7580a52
parent 4db9842adc64fe254a2e61ce214b2fabb2fc67f8
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Fri, 14 Jan 2022 22:58:15 +0100

Adjusted API to get current status of file processing

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Minclude/gnunet_chat_lib.h | 45++++++++++++++++++++++++++++++++++++++++-----
Msrc/gnunet_chat_file.c | 20++++++++++++++++++++
Msrc/gnunet_chat_file.h | 6++++++
Msrc/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 @@ -797,7 +797,7 @@ const struct GNUNET_HashCode* GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file); /** - * Returns the file size of a given <i>file</i> handle. + * Returns the actual file size of a given <i>file</i> handle. * * @param[in] file File handle * @return The file size of file @@ -806,19 +806,33 @@ uint64_t GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file); /** - * Checks whether a file locally exists of a given <i>file</i> handle and - * returns #GNUNET_YES in that case, otherwise #GNUNET_NO. + * Returns the local file size of a given <i>file</i> handle. + * + * This can be less than the actual size of the file once its download + * has been completed! * * @param[in] file File handle - * @return #GNUNET_YES if the file exists locally, otherwise #GNUNET_NO + * @return The local file size of file + */ +uint64_t +GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file); + +/** + * Returns if a given <i>file</i> handle is currently uploading. + * + * @param[in] file File handle + * @return #GNUNET_YES during active upload, #GNUNET_NO otherwise */ int -GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file); +GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file); /** * Returns the temporary file name of the decrypted file preview * of a given <i>file</i> handle. * + * This can only be used when the file handle is ready to preview! + * @see GNUNET_CHAT_file_is_ready() + * * @param[in,out] file File handle * @return The temporary file name or NULL on error */ @@ -829,6 +843,9 @@ GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file); * Deletes the temporary decrypted file preview of a given <i>file</i> * handle. * + * This can only be used when the file handle is ready to preview! + * @see GNUNET_CHAT_file_is_ready() + * * @param[out] file File handle */ void @@ -856,6 +873,15 @@ void* GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file); /** + * Returns if a given <i>file</i> handle is currently downloading. + * + * @param[in] file File handle + * @return #GNUNET_YES during active download, #GNUNET_NO otherwise + */ +int +GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file); + +/** * Starts downloading a file from a given <i>file</i> handle and sets up a * selected callback and custom closure for its progress. * @@ -897,6 +923,15 @@ int GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file); /** + * Returns if a given <i>file</i> handle is currently unindexing. + * + * @param[in] file File handle + * @return #GNUNET_YES during active unindexing, #GNUNET_NO otherwise + */ +int +GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file); + +/** * Unindexes an uploaded file from a given <i>file</i> handle with a selected * callback and a custom closure. * diff --git 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, file->unindex_head = NULL; file->unindex_tail = NULL; + file->status = 0; file->preview = NULL; file->user_pointer = NULL; @@ -104,6 +105,7 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle, file->unindex_head = NULL; file->unindex_tail = NULL; + file->status = 0; file->preview = NULL; file->user_pointer = NULL; @@ -242,6 +244,8 @@ file_update_upload (struct GNUNET_CHAT_File *file, { GNUNET_assert(file); + file->status |= GNUNET_CHAT_FILE_STATUS_PUBLISH; + struct GNUNET_CHAT_FileUpload *upload = file->upload_head; while (upload) @@ -278,6 +282,10 @@ file_update_upload (struct GNUNET_CHAT_File *file, } GNUNET_free(msg.body.file.uri); + + file->status &= ( + GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_PUBLISH + ); } void @@ -287,6 +295,8 @@ file_update_download (struct GNUNET_CHAT_File *file, { GNUNET_assert(file); + file->status |= GNUNET_CHAT_FILE_STATUS_DOWNLOAD; + struct GNUNET_CHAT_FileDownload *download = file->download_head; while (download) @@ -312,6 +322,10 @@ file_update_download (struct GNUNET_CHAT_File *file, GNUNET_free(download); } + + file->status &= ( + GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_DOWNLOAD + ); } void @@ -321,6 +335,8 @@ file_update_unindex (struct GNUNET_CHAT_File *file, { GNUNET_assert(file); + file->status |= GNUNET_CHAT_FILE_STATUS_UNINDEX; + struct GNUNET_CHAT_FileUnindex *unindex = file->unindex_head; while (unindex) @@ -346,4 +362,8 @@ file_update_unindex (struct GNUNET_CHAT_File *file, GNUNET_free(unindex); } + + file->status &= ( + GNUNET_CHAT_FILE_STATUS_MASK ^ GNUNET_CHAT_FILE_STATUS_UNINDEX + ); } diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h @@ -67,6 +67,11 @@ struct GNUNET_CHAT_FileUnindex struct GNUNET_CHAT_Handle; +#define GNUNET_CHAT_FILE_STATUS_DOWNLOAD 0x1 +#define GNUNET_CHAT_FILE_STATUS_PUBLISH 0x2 +#define GNUNET_CHAT_FILE_STATUS_UNINDEX 0x4 +#define GNUNET_CHAT_FILE_STATUS_MASK 0x7 + struct GNUNET_CHAT_File { struct GNUNET_CHAT_Handle *handle; @@ -92,6 +97,7 @@ struct GNUNET_CHAT_File struct GNUNET_CHAT_FileUnindex *unindex_head; struct GNUNET_CHAT_FileUnindex *unindex_tail; + int status; char *preview; void *user_pointer; diff --git 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, GNUNET_FS_PUBLISH_OPTION_NONE ); + if (file->publish) + file->status |= GNUNET_CHAT_FILE_STATUS_PUBLISH; + GNUNET_free(filename); file_binding: @@ -978,11 +981,18 @@ GNUNET_CHAT_file_get_hash (const struct GNUNET_CHAT_File *file) uint64_t GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) { - if (!file) + if ((!file) || (!(file->uri))) return 0; - if (file->uri) - return GNUNET_FS_uri_chk_get_file_size(file->uri); + return GNUNET_FS_uri_chk_get_file_size(file->uri); +} + + +uint64_t +GNUNET_CHAT_file_get_local_size (const struct GNUNET_CHAT_File *file) +{ + if (!file) + return 0; char *filename; util_get_filename ( @@ -999,20 +1009,12 @@ GNUNET_CHAT_file_get_size (const struct GNUNET_CHAT_File *file) int -GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file) +GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file) { - if (!file) - return GNUNET_SYSERR; - - char *filename; - util_get_filename ( - file->handle->directory, "files", &(file->hash), &filename - ); - - int result = GNUNET_DISK_file_test(filename); - - GNUNET_free(filename); - return result; + if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_PUBLISH))) + return GNUNET_NO; + else + return GNUNET_YES; } @@ -1088,6 +1090,16 @@ GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file) int +GNUNET_CHAT_file_is_downloading (const struct GNUNET_CHAT_File *file) +{ + if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_DOWNLOAD))) + return GNUNET_NO; + else + return GNUNET_YES; +} + + +int GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, GNUNET_CHAT_FileDownloadCallback callback, void *cls) @@ -1140,6 +1152,9 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file, NULL ); + if (file->download) + file->status |= GNUNET_CHAT_FILE_STATUS_DOWNLOAD; + GNUNET_free(filename); return GNUNET_OK; } @@ -1180,6 +1195,18 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) int +GNUNET_CHAT_file_is_unindexing (const struct GNUNET_CHAT_File *file) +{ + if ((!file) || (0 == (file->status & GNUNET_CHAT_FILE_STATUS_UNINDEX))) + return GNUNET_NO; + else + return GNUNET_YES; +} + + + + +int GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, GNUNET_CHAT_FileUnindexCallback callback, void *cls) @@ -1208,11 +1235,16 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file, file->handle->fs, filename, file ); + if (file->unindex) + file->status |= GNUNET_CHAT_FILE_STATUS_UNINDEX; + GNUNET_free(filename); return GNUNET_OK; } + + void GNUNET_CHAT_invitation_accept (struct GNUNET_CHAT_Invitation *invitation) {