From 0e770eb262e25bd2d2b268d2f72c4918280a4a2a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jan 2012 16:43:54 +0000 Subject: [PATCH] -LRN: make file filename alterable and initializable --- src/fs/fs_file_information.c | 42 +++++++++++++++++++++++++--- src/fs/test_fs_file_information.c | 2 +- src/fs/test_fs_list_indexed.c | 2 +- src/fs/test_fs_publish.c | 2 +- src/fs/test_fs_publish_persistence.c | 2 +- src/include/gnunet_fs_service.h | 24 +++++++++++++++- 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c index c2ab84ec2..cade94a79 100644 --- a/src/fs/fs_file_information.c +++ b/src/fs/fs_file_information.c @@ -107,6 +107,37 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s) return s->serialization; } +/** + * Obtain the filename from the file information structure. + * + * @param s structure to get the filename for + * @return "filename" field of the structure (can be NULL) + */ +const char * +GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s) +{ + return s->filename; +} + + +/** + * Set the filename in the file information structure. + * If filename was already set, frees it before setting the new one. + * Makes a copy of the argument. + * + * @param s structure to get the filename for + * @param filename filename to set + */ +void +GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, + const char *filename) +{ + GNUNET_free_non_null (s->filename); + if (filename) + s->filename = GNUNET_strdup (filename); + else + s->filename = NULL; +} /** * Create an entry for a file in a publish-structure. @@ -764,7 +795,7 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, GNUNET_FS_DIRECTORY_MIME, GNUNET_NO); ret = GNUNET_FS_file_information_create_empty_directory (h, client_info, cdmc.ksk, - cdmc.meta, bo); + cdmc.meta, bo, filename); GNUNET_CONTAINER_meta_data_destroy (cdmc.meta); GNUNET_FS_uri_destroy (cdmc.ksk); ret->data.dir.entries = dc.entries; @@ -789,8 +820,7 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, "text/plain", dn, strlen (dn) + 1); #endif GNUNET_free (dn); - ret->filename = GNUNET_strdup (filename); - return ret; + return ret; } @@ -820,6 +850,7 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation * @param keywords under which keywords should this directory be available * directly; can be NULL * @param bo block options + * @param filename name of the directory; can be NULL * @return publish structure entry for the directory , NULL on error */ struct GNUNET_FS_FileInformation * @@ -831,7 +862,8 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, GNUNET_CONTAINER_MetaData *meta, const struct - GNUNET_FS_BlockOptions *bo) + GNUNET_FS_BlockOptions *bo, + const char *filename) { struct GNUNET_FS_FileInformation *ret; @@ -842,6 +874,8 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, ret->keywords = GNUNET_FS_uri_dup (keywords); ret->bo = *bo; ret->is_directory = GNUNET_YES; + if (filename != NULL) + ret->filename = GNUNET_strdup (filename); return ret; } diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index 0a2969cd3..8d89312df 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c @@ -121,7 +121,7 @@ run (void *cls, char *const *args, const char *cfgfile, fidir = GNUNET_FS_file_information_create_empty_directory (fs, "file_information-context-dir", - kuri, meta, &bo); + kuri, meta, &bo, NULL); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); GNUNET_FS_uri_destroy (kuri); diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index 8a847ba2b..5d2ad5d78 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -281,7 +281,7 @@ run (void *cls, char *const *args, const char *cfgfile, fidir = GNUNET_FS_file_information_create_empty_directory (fs, "list_indexed-context-dir", - kuri, meta, &bo); + kuri, meta, &bo, NULL); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); GNUNET_FS_uri_destroy (kuri); diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index 051b84f68..65632cb08 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -266,7 +266,7 @@ run (void *cls, char *const *args, const char *cfgfile, fidir = GNUNET_FS_file_information_create_empty_directory (fs, "publish-context-dir", - kuri, meta, &bo); + kuri, meta, &bo, NULL); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); GNUNET_FS_uri_destroy (kuri); diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 4d569849f..cdd6d818f 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -328,7 +328,7 @@ run (void *cls, char *const *args, const char *cfgfile, fidir = GNUNET_FS_file_information_create_empty_directory (fs, "publish-context-dir", - kuri, meta, &bo); + kuri, meta, &bo, NULL); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); GNUNET_FS_uri_destroy (kuri); diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 34925d562..cd9093a8e 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -1749,6 +1749,26 @@ const char * GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s); +/** + * Obtain the filename from the file information structure. + * + * @param s structure to get the filename for + * @return "filename" field of the structure (can be NULL) + */ +const char * +GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s); + +/** + * Set the filename in the file information structure. + * If filename was already set, frees it before setting the new one. + * Makes a copy of the argument. + * + * @param s structure to get the filename for + * @param filename filename to set + */ +void +GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, + const char *filename); /** * Create an entry for a file in a publish-structure. @@ -1968,6 +1988,7 @@ GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h, * directly; can be NULL * @param meta metadata for the directory * @param bo block options + * @param filename name of the directory; can be NULL * @return publish structure entry for the directory , NULL on error */ struct GNUNET_FS_FileInformation * @@ -1979,7 +2000,8 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, GNUNET_CONTAINER_MetaData *meta, const struct - GNUNET_FS_BlockOptions *bo); + GNUNET_FS_BlockOptions *bo, + const char *filename); /** -- 2.25.1