commit 62d9bd1120633b094b813b66c49f94db8f2f8abb
parent e19d4dedf548d6b16f95a97f6b67fd2a09a18643
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Thu, 29 Jul 2021 16:44:02 +0200
Adjusted callbacks of file management
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
9 files changed, 539 insertions(+), 80 deletions(-)
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h
@@ -195,10 +195,11 @@ typedef int
* @param cls
* @param file
* @param completed
+ * @param size
*/
-typedef int
-(*GNUNET_CHAT_MessageFileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file,
- uint64_t completed);
+typedef void
+(*GNUNET_CHAT_FileUploadCallback) (void *cls, const struct GNUNET_CHAT_File *file,
+ uint64_t completed, uint64_t size);
/**
* TODO
@@ -206,10 +207,23 @@ typedef int
* @param cls
* @param file
* @param completed
+ * @param size
*/
-typedef int
-(*GNUNET_CHAT_MessageFileDownloadCallback) (void *cls, struct GNUNET_CHAT_File *file,
- uint64_t completed);
+typedef void
+(*GNUNET_CHAT_FileDownloadCallback) (void *cls, const struct GNUNET_CHAT_File *file,
+ uint64_t completed, uint64_t size);
+
+/**
+ * TODO
+ *
+ * @param cls
+ * @param file
+ * @param completed
+ * @param size
+ */
+typedef void
+(*GNUNET_CHAT_FileUnindexCallback) (void *cls, struct GNUNET_CHAT_File *file,
+ uint64_t completed, uint64_t size);
/**
* TODO
@@ -420,7 +434,7 @@ GNUNET_CHAT_group_set_user_pointer (struct GNUNET_CHAT_Group *group,
* @param group
*/
void*
-GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group);
+GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group);
/**
* TODO
@@ -492,18 +506,9 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
*/
int
GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
- const char *path);
-
-/**
- * TODO
- *
- * @param context
- * @param uri
- * @return
- */
-int
-GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context,
- const char *uri);
+ const char *path,
+ GNUNET_CHAT_FileUploadCallback callback,
+ void *cls);
/**
* TODO
@@ -657,11 +662,30 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file);
* TODO
*
* @param file
+ * @param user_pointer
+ */
+void
+GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file,
+ void *user_pointer);
+
+/**
+ * TODO
+ *
+ * @param file
+ * @return
+ */
+void*
+GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file);
+
+/**
+ * TODO
+ *
+ * @param file
* @return
*/
int
GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
- GNUNET_CHAT_MessageFileDownloadCallback callback,
+ GNUNET_CHAT_FileDownloadCallback callback,
void *cls);
/**
@@ -695,10 +719,14 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file);
* TODO
*
* @param file
+ * @param callback
+ * @param cls
* @return
*/
int
-GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file);
+GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
+ GNUNET_CHAT_FileUnindexCallback callback,
+ void *cls);
/**
* TODO
diff --git 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)
char* filename;
util_get_filename(directory, "chats", hash, &filename);
- GNUNET_CONFIGURATION_write(config, filename);
+ if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename))
+ GNUNET_CONFIGURATION_write(config, filename);
+
GNUNET_CONFIGURATION_destroy(config);
GNUNET_free(filename);
diff --git 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,
GNUNET_memcpy(&(file->key), &(message->key), sizeof(file->key));
GNUNET_memcpy(&(file->hash), &(message->hash), sizeof(file->hash));
- file->published = 0;
- file->downloaded = 0;
- file->unindexed = 0;
-
file->meta = GNUNET_CONTAINER_meta_data_create();
file->uri = GNUNET_FS_uri_parse(message->uri, NULL);
@@ -50,6 +46,17 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle,
file->publish = NULL;
file->unindex = NULL;
+ file->upload_head = NULL;
+ file->upload_tail = NULL;
+
+ file->download_head = NULL;
+ file->download_tail = NULL;
+
+ file->unindex_head = NULL;
+ file->unindex_tail = NULL;
+
+ file->user_pointer = NULL;
+
return file;
}
@@ -67,10 +74,6 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
GNUNET_memcpy(&(file->key), key, sizeof(file->key));
GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash));
- file->published = 0;
- file->downloaded = 0;
- file->unindexed = 0;
-
file->meta = GNUNET_CONTAINER_meta_data_create();
file->uri = NULL;
@@ -78,12 +81,65 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
file->publish = NULL;
file->unindex = NULL;
+ file->upload_head = NULL;
+ file->upload_tail = NULL;
+
+ file->download_head = NULL;
+ file->download_tail = NULL;
+
+ file->unindex_head = NULL;
+ file->unindex_tail = NULL;
+
+ file->user_pointer = NULL;
+
return file;
}
void
file_destroy (struct GNUNET_CHAT_File* file)
{
+ struct GNUNET_CHAT_FileUpload *upload;
+ while (file->upload_head)
+ {
+ upload = file->upload_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->upload_head,
+ file->upload_tail,
+ upload
+ );
+
+ GNUNET_free(upload);
+ }
+
+ struct GNUNET_CHAT_FileDownload *download;
+ while (file->download_head)
+ {
+ download = file->download_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->download_head,
+ file->download_tail,
+ download
+ );
+
+ GNUNET_free(download);
+ }
+
+ struct GNUNET_CHAT_FileUnindex *unindex;
+ while (file->unindex_head)
+ {
+ unindex = file->unindex_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->unindex_head,
+ file->unindex_tail,
+ unindex
+ );
+
+ GNUNET_free(unindex);
+ }
+
if (file->uri)
GNUNET_FS_uri_destroy(file->uri);
@@ -95,3 +151,150 @@ file_destroy (struct GNUNET_CHAT_File* file)
GNUNET_free(file);
}
+
+void
+file_bind_upload (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileUploadCallback cb, void *cls)
+{
+ struct GNUNET_CHAT_FileUpload *upload = GNUNET_new(
+ struct GNUNET_CHAT_FileUpload
+ );
+
+ upload->callback = cb;
+ upload->cls = cls;
+
+ GNUNET_CONTAINER_DLL_insert(
+ file->upload_head,
+ file->upload_tail,
+ upload
+ );
+}
+
+void
+file_bind_downlaod (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileDownloadCallback cb, void *cls)
+{
+ struct GNUNET_CHAT_FileDownload *download = GNUNET_new(
+ struct GNUNET_CHAT_FileDownload
+ );
+
+ download->callback = cb;
+ download->cls = cls;
+
+ GNUNET_CONTAINER_DLL_insert(
+ file->download_head,
+ file->download_tail,
+ download
+ );
+}
+
+void
+file_bind_unindex (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileUnindexCallback cb, void *cls)
+{
+ struct GNUNET_CHAT_FileUnindex *unindex = GNUNET_new(
+ struct GNUNET_CHAT_FileUnindex
+ );
+
+ unindex->callback = cb;
+ unindex->cls = cls;
+
+ GNUNET_CONTAINER_DLL_insert(
+ file->unindex_head,
+ file->unindex_tail,
+ unindex
+ );
+}
+
+void
+file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size)
+{
+ struct GNUNET_CHAT_FileUpload *upload = file->upload_head;
+
+ while (upload)
+ {
+ if (upload->callback)
+ upload->callback(upload->cls, file, completed, size);
+
+ upload = upload->next;
+ }
+
+ if (completed < size)
+ return;
+
+ while (file->upload_head)
+ {
+ upload = file->upload_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->upload_head,
+ file->upload_tail,
+ upload
+ );
+
+ GNUNET_free(upload);
+ }
+}
+
+void
+file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size)
+{
+ struct GNUNET_CHAT_FileDownload *download = file->download_head;
+
+ while (download)
+ {
+ if (download->callback)
+ download->callback(download->cls, file, completed, size);
+
+ download = download->next;
+ }
+
+ if (completed < size)
+ return;
+
+ while (file->download_head)
+ {
+ download = file->download_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->download_head,
+ file->download_tail,
+ download
+ );
+
+ GNUNET_free(download);
+ }
+}
+
+void
+file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size)
+{
+ struct GNUNET_CHAT_FileUnindex *unindex = file->unindex_head;
+
+ while (unindex)
+ {
+ if (unindex->callback)
+ unindex->callback(unindex->cls, file, completed, size);
+
+ unindex = unindex->next;
+ }
+
+ if (completed < size)
+ return;
+
+ while (file->unindex_head)
+ {
+ unindex = file->unindex_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ file->unindex_head,
+ file->unindex_tail,
+ unindex
+ );
+
+ GNUNET_free(unindex);
+ }
+}
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h
@@ -32,6 +32,38 @@
#include <gnunet/gnunet_messenger_service.h>
#include <gnunet/gnunet_util_lib.h>
+#include "gnunet_chat_lib.h"
+
+struct GNUNET_CHAT_FileUpload
+{
+ struct GNUNET_CHAT_FileUpload* prev;
+ struct GNUNET_CHAT_FileUpload* next;
+
+ GNUNET_CHAT_FileUploadCallback callback;
+
+ void *cls;
+};
+
+struct GNUNET_CHAT_FileDownload
+{
+ struct GNUNET_CHAT_FileDownload* prev;
+ struct GNUNET_CHAT_FileDownload* next;
+
+ GNUNET_CHAT_FileDownloadCallback callback;
+
+ void *cls;
+};
+
+struct GNUNET_CHAT_FileUnindex
+{
+ struct GNUNET_CHAT_FileUnindex* prev;
+ struct GNUNET_CHAT_FileUnindex* next;
+
+ GNUNET_CHAT_FileUnindexCallback callback;
+
+ void *cls;
+};
+
struct GNUNET_CHAT_Handle;
struct GNUNET_CHAT_File
@@ -43,16 +75,23 @@ struct GNUNET_CHAT_File
struct GNUNET_HashCode hash;
struct GNUNET_CRYPTO_SymmetricSessionKey key;
- uint64_t published;
- uint64_t downloaded;
- uint64_t unindexed;
-
struct GNUNET_CONTAINER_MetaData *meta;
- struct GNUNET_FS_Uri* uri;
- struct GNUNET_FS_DownloadContext* download;
- struct GNUNET_FS_PublishContext* publish;
- struct GNUNET_FS_UnindexContext* unindex;
+ struct GNUNET_FS_Uri *uri;
+ struct GNUNET_FS_DownloadContext *download;
+ struct GNUNET_FS_PublishContext *publish;
+ struct GNUNET_FS_UnindexContext *unindex;
+
+ struct GNUNET_CHAT_FileUpload *upload_head;
+ struct GNUNET_CHAT_FileUpload *upload_tail;
+
+ struct GNUNET_CHAT_FileDownload *download_head;
+ struct GNUNET_CHAT_FileDownload *download_tail;
+
+ struct GNUNET_CHAT_FileUnindex *unindex_head;
+ struct GNUNET_CHAT_FileUnindex *unindex_tail;
+
+ void *user_pointer;
};
struct GNUNET_CHAT_File*
@@ -67,4 +106,28 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
void
file_destroy (struct GNUNET_CHAT_File* file);
+void
+file_bind_upload (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileUploadCallback cb, void *cls);
+
+void
+file_bind_downlaod (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileDownloadCallback cb, void *cls);
+
+void
+file_bind_unindex (struct GNUNET_CHAT_File* file,
+ GNUNET_CHAT_FileUnindexCallback cb, void *cls);
+
+void
+file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size);
+
+void
+file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size);
+
+void
+file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed,
+ uint64_t size);
+
#endif /* GNUNET_CHAT_FILE_H_ */
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c
@@ -23,6 +23,7 @@
*/
#include "gnunet_chat_group.h"
+#include "gnunet_chat_util.h"
#include "gnunet_chat_group_intern.c"
@@ -63,14 +64,98 @@ group_destroy (struct GNUNET_CHAT_Group* group)
void
group_publish (struct GNUNET_CHAT_Group* group)
{
+ char* topic = NULL;
+ GNUNET_asprintf (
+ &topic,
+ "GNUNET_CHAT_%s",
+ group->topic
+ );
+
group->announcement = GNUNET_REGEX_announce(
- group->handle->cfg, group->topic, // TODO: raw topic?
- GNUNET_TIME_relative_get_minute_(), // TODO: configure delay?
- 1 // TODO: no compression?
+ group->handle->cfg, topic,
+ GNUNET_TIME_relative_get_minute_(),
+ 6
);
group->search = GNUNET_REGEX_search(
- group->handle->cfg, group->topic, // TODO: raw topic?
+ group->handle->cfg, topic,
search_group_by_topic, group
);
+
+ GNUNET_free(topic);
+}
+
+void
+group_load_config (struct GNUNET_CHAT_Group *group)
+{
+ const char *directory = group->handle->directory;
+
+ if ((!directory) || (!(group->context)))
+ return;
+
+ const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
+ group->context->room
+ );
+
+ char* filename;
+ util_get_filename(directory, "groups", hash, &filename);
+
+ if (GNUNET_YES != GNUNET_DISK_file_test(filename))
+ goto free_filename;
+
+ struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, directory))
+ goto destroy_config;
+
+ char* name = NULL;
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(
+ config, "group", "topic", &name))
+ util_set_name_field(name, &(group->topic));
+
+ if (name)
+ GNUNET_free(name);
+
+destroy_config:
+ GNUNET_CONFIGURATION_destroy(config);
+
+free_filename:
+ GNUNET_free(filename);
+}
+
+void
+group_save_config (const struct GNUNET_CHAT_Group *group)
+{
+ const char *directory = group->handle->directory;
+
+ if ((!directory) || (!(group->context)))
+ return;
+
+ const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
+ group->context->room
+ );
+
+ struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
+
+ if (group->topic)
+ {
+ struct GNUNET_HashCode topic_hash;
+ GNUNET_CRYPTO_hash(group->topic, strlen(group->topic), &topic_hash);
+
+ if (0 == GNUNET_memcmp(hash, &topic_hash))
+ GNUNET_CONFIGURATION_set_value_string(
+ config, "group", "topic", group->topic
+ );
+ }
+
+ char* filename;
+ util_get_filename(directory, "groups", hash, &filename);
+
+ if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename))
+ GNUNET_CONFIGURATION_write(config, filename);
+
+ GNUNET_CONFIGURATION_destroy(config);
+
+ GNUNET_free(filename);
}
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h
@@ -56,4 +56,10 @@ group_destroy (struct GNUNET_CHAT_Group* group);
void
group_publish (struct GNUNET_CHAT_Group* group);
+void
+group_load_config (struct GNUNET_CHAT_Group *group);
+
+void
+group_save_config (const struct GNUNET_CHAT_Group *group);
+
#endif /* GNUNET_CHAT_GROUP_H_ */
diff --git 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,
if (handle->arm)
on_handle_arm_connection(handle, GNUNET_NO);
+ char* fs_client_name = NULL;
+ GNUNET_asprintf (
+ &fs_client_name,
+ "GNUNET_CHAT_%s%s",
+ name? "_" : "anonymous",
+ name? name : ""
+ );
+
handle->fs = GNUNET_FS_start(
- handle->cfg, name, // TODO: raw name? (NULL?)
+ handle->cfg, fs_client_name,
notify_handle_fs_progress, handle,
GNUNET_FS_FLAGS_NONE,
GNUNET_FS_OPTIONS_END
);
+ GNUNET_free(fs_client_name);
+
handle->messenger = GNUNET_MESSENGER_connect(
handle->cfg, name,
on_handle_identity, handle,
diff --git 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)
case GNUNET_FS_STATUS_PUBLISH_START: {
struct GNUNET_CHAT_File *file = info->value.publish.cctx;
- file->published = 0;
+ file_update_upload(
+ file,
+ 0,
+ info->value.publish.size
+ );
return file;
} case GNUNET_FS_STATUS_PUBLISH_PROGRESS: {
struct GNUNET_CHAT_File *file = info->value.publish.cctx;
- file->published = info->value.publish.completed;
+ file_update_upload(
+ file,
+ info->value.publish.completed,
+ info->value.publish.size
+ );
return file;
} case GNUNET_FS_STATUS_PUBLISH_COMPLETED: {
@@ -87,7 +95,12 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
info->value.publish.specifics.completed.chk_uri
);
- file->published = info->value.publish.size;
+ file_update_upload(
+ file,
+ info->value.publish.size,
+ info->value.publish.size
+ );
+
file->publish = NULL;
break;
} case GNUNET_FS_STATUS_PUBLISH_ERROR: {
@@ -95,7 +108,11 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
} case GNUNET_FS_STATUS_DOWNLOAD_START: {
struct GNUNET_CHAT_File *file = info->value.download.cctx;
- file->downloaded = 0;
+ file_update_download(
+ file,
+ 0,
+ info->value.download.size
+ );
return file;
} case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: {
@@ -105,13 +122,22 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
} case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: {
struct GNUNET_CHAT_File *file = info->value.download.cctx;
- file->downloaded = info->value.download.completed;
+ file_update_download(
+ file,
+ info->value.download.completed,
+ info->value.download.size
+ );
return file;
} case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: {
struct GNUNET_CHAT_File *file = info->value.download.cctx;
- file->downloaded = info->value.download.size;
+ file_update_download(
+ file,
+ info->value.download.size,
+ info->value.download.size
+ );
+
file->download = NULL;
break;
} case GNUNET_FS_STATUS_DOWNLOAD_ERROR: {
@@ -119,19 +145,32 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info)
} case GNUNET_FS_STATUS_UNINDEX_START: {
struct GNUNET_CHAT_File *file = info->value.unindex.cctx;
- file->unindexed = 0;
+ file_update_unindex(
+ file,
+ 0,
+ info->value.unindex.size
+ );
return file;
} case GNUNET_FS_STATUS_UNINDEX_PROGRESS: {
struct GNUNET_CHAT_File *file = info->value.unindex.cctx;
- file->unindexed = info->value.unindex.completed;
+ file_update_unindex(
+ file,
+ info->value.unindex.completed,
+ info->value.unindex.size
+ );
return file;
} case GNUNET_FS_STATUS_UNINDEX_COMPLETED: {
struct GNUNET_CHAT_File *file = info->value.unindex.cctx;
- file->unindexed = info->value.unindex.size;
+ file_update_unindex(
+ file,
+ info->value.unindex.size,
+ info->value.unindex.size
+ );
+
file->unindex = NULL;
break;
} default: {
@@ -225,6 +264,11 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle,
handle, context
);
+ group_load_config(group);
+
+ if (group->topic)
+ group_publish(group);
+
if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(
handle->groups, key, group,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
@@ -382,6 +426,7 @@ it_destroy_handle_groups (GNUNET_UNUSED void *cls,
void *value)
{
struct GNUNET_CHAT_Group *group = value;
+ group_save_config(group);
group_destroy(group);
return GNUNET_YES;
}
diff --git 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,
void*
-GNUNET_CHAT_group_get_user_pointer (struct GNUNET_CHAT_Group *group)
+GNUNET_CHAT_group_get_user_pointer (const struct GNUNET_CHAT_Group *group)
{
if (!group)
return NULL;
@@ -475,7 +475,9 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
int
GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
- const char *path)
+ const char *path,
+ GNUNET_CHAT_FileUploadCallback callback,
+ void *cls)
{
if ((!context) || (!path))
return GNUNET_SYSERR;
@@ -516,6 +518,8 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
GNUNET_free(p);
+ file_bind_upload(file, callback, cls);
+
struct GNUNET_FS_BlockOptions bo;
bo.anonymity_level = 1;
@@ -543,32 +547,11 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
);
GNUNET_free(filename);
-
- // TODO: share file
-
return GNUNET_OK;
}
int
-GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context,
- const char *uri)
-{
- if ((!context) || (!uri))
- return GNUNET_SYSERR;
-
- struct GNUNET_FS_Uri *furi = GNUNET_FS_uri_parse(uri, NULL);
-
- if (!furi)
- return GNUNET_SYSERR;
-
- // TODO: download file, hash file, share file
-
- return GNUNET_SYSERR;
-}
-
-
-int
GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
const struct GNUNET_CHAT_File *file)
{
@@ -833,9 +816,30 @@ GNUNET_CHAT_file_is_local (const struct GNUNET_CHAT_File *file)
}
+void
+GNUNET_CHAT_file_set_user_pointer (struct GNUNET_CHAT_File *file,
+ void *user_pointer)
+{
+ if (!file)
+ return;
+
+ file->user_pointer = user_pointer;
+}
+
+
+void*
+GNUNET_CHAT_file_get_user_pointer (const struct GNUNET_CHAT_File *file)
+{
+ if (!file)
+ return NULL;
+
+ return file->user_pointer;
+}
+
+
int
GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
- GNUNET_CHAT_MessageFileDownloadCallback callback,
+ GNUNET_CHAT_FileDownloadCallback callback,
void *cls)
{
if ((!file) || (!(file->uri)))
@@ -843,8 +847,10 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
if (file->download)
{
+ file_bind_downlaod(file, callback, cls);
+
GNUNET_FS_download_resume(file->download);
- return GNUNET_OK;
+ return GNUNET_NO;
}
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,
offset = 0;
if (offset >= size)
- return GNUNET_OK;
+ {
+ if (callback)
+ callback(cls, file, size, size);
+
+ return GNUNET_YES;
+ }
+
+ file_bind_downlaod(file, callback, cls);
const uint64_t remaining = (size - offset);
@@ -878,7 +891,7 @@ GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file,
);
GNUNET_free(filename);
- return GNUNET_OK;
+ return GNUNET_YES;
}
@@ -917,7 +930,9 @@ GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file)
int
-GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file)
+GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file,
+ GNUNET_CHAT_FileUnindexCallback callback,
+ void *cls)
{
if (!file)
return GNUNET_SYSERR;
@@ -929,6 +944,8 @@ GNUNET_CHAT_file_unindex (struct GNUNET_CHAT_File *file)
return GNUNET_OK;
}
+ file_bind_unindex(file, callback, cls);
+
if (file->unindex)
return GNUNET_OK;