-LRN: make file filename alterable and initializable
authorChristian Grothoff <christian@grothoff.org>
Mon, 9 Jan 2012 16:43:54 +0000 (16:43 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 9 Jan 2012 16:43:54 +0000 (16:43 +0000)
src/fs/fs_file_information.c
src/fs/test_fs_file_information.c
src/fs/test_fs_list_indexed.c
src/fs/test_fs_publish.c
src/fs/test_fs_publish_persistence.c
src/include/gnunet_fs_service.h

index c2ab84ec2e311cdf10f48f616d8dbc2446cb02b2..cade94a799baffc4c752f694d424d6da7ac903a3 100644 (file)
@@ -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;
 }
 
index 0a2969cd3872db8f5394512f53b29a5be497c5a5..8d89312df2438ab71ee6de2bd5817e324786dae7 100644 (file)
@@ -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);
index 8a847ba2b43153a2eebd873c06fc3eaa335c7220..5d2ad5d781e5de2d97a1e73e2e01f9228cd8d18a 100644 (file)
@@ -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);
index 051b84f6873722daf646b2eefdd63d8e2d7b2e4c..65632cb08cec36352bd8292e3b685c77e5434ecf 100644 (file)
@@ -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);
index 4d569849f0244bfce240455ddb2503a9b0183931..cdd6d818f796fb30559fdefbe969af2acab8f323 100644 (file)
@@ -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);
index 34925d562aaceb76de3571efaba3175a1aa29c2d..cd9093a8eed25f440aa5ef0735db60ab6589d719 100644 (file)
@@ -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);
 
 
 /**