tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / fs / fs_file_information.c
index 3e6d53af6d5b9fbdf0c39a43898d48337d7de789..49cfc1a683e77ac2b2296fc8ad86505dff6e09ca 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2011 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -24,7 +24,9 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#if HAVE_EXTRACTOR_H
 #include <extractor.h>
+#endif
 #include "gnunet_fs_service.h"
 #include "fs_api.h"
 #include "fs_tree.h"
@@ -37,8 +39,7 @@
  *
  * @param s structure to get the filename for
  * @return NULL on error, otherwise filename that
- *         can be passed to "GNUNET_FS_file_information_recover"
- *         to read this fi-struct from disk.
+ *         can be used to read this fi-struct from disk.
  */
 const char *
 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
@@ -80,6 +81,7 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
     s->filename = NULL;
 }
 
+
 /**
  * Create an entry for a file in a publish-structure.
  *
@@ -89,8 +91,8 @@ GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
  * @param keywords under which keywords should this file be available
  *         directly; can be NULL
  * @param meta metadata for the file
- * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
- *                GNUNET_SYSERR for simulation
+ * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
+ *                #GNUNET_SYSERR for simulation
  * @param bo block options
  * @return publish structure entry for the file
  */
@@ -116,14 +118,14 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
   char fn_conv[MAX_PATH];
 #endif
 
-  /* FIXME: should includeSymLinks be GNUNET_NO or GNUNET_YES here? */
+  /* FIXME: should include_symbolic_links be GNUNET_NO or GNUNET_YES here? */
   if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES))
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
     return NULL;
   }
   fi = GNUNET_FS_make_file_reader_context_ (filename);
-  if (fi == NULL)
+  if (NULL == fi)
   {
     GNUNET_break (0);
     return NULL;
@@ -215,8 +217,8 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
  * @param keywords under which keywords should this file be available
  *         directly; can be NULL
  * @param meta metadata for the file
- * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
- *                GNUNET_SYSERR for simulation
+ * @param do_index #GNUNET_YES for index, #GNUNET_NO for insertion,
+ *                #GNUNET_SYSERR for simulation
  * @param bo block options
  * @return publish structure entry for the file
  */
@@ -241,7 +243,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
     GNUNET_break (0);
     return NULL;
   }
-  ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret = GNUNET_new (struct GNUNET_FS_FileInformation);
   ret->h = h;
   ret->client_info = client_info;
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
@@ -261,7 +263,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
  * Test if a given entry represents a directory.
  *
  * @param ent check if this FI represents a directory
- * @return GNUNET_YES if so, GNUNET_NO if not
+ * @return #GNUNET_YES if so, #GNUNET_NO if not
  */
 int
 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
@@ -273,9 +275,6 @@ GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
 
 /**
  * Create an entry for an empty directory in a publish-structure.
- * This function should be used by applications for which the
- * use of "GNUNET_FS_file_information_create_from_directory"
- * is not appropriate.
  *
  * @param h handle to the file sharing subsystem
  * @param client_info initial value for the client-info value for this entry
@@ -300,7 +299,7 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
 {
   struct GNUNET_FS_FileInformation *ret;
 
-  ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
+  ret = GNUNET_new (struct GNUNET_FS_FileInformation);
   ret->h = h;
   ret->client_info = client_info;
   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
@@ -316,13 +315,13 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
 /**
  * Add an entry to a directory in a publish-structure.  Clients
  * should never modify publish structures that were passed to
- * "GNUNET_FS_publish_start" already.
+ * #GNUNET_FS_publish_start already.
  *
  * @param dir the directory
  * @param ent the entry to add; the entry must not have been
  *            added to any other directory at this point and
- *            must not include "dir" in its structure
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ *            must not include @a dir in its structure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  */
 int
 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
@@ -344,16 +343,16 @@ GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
 /**
  * Inspect a file or directory in a publish-structure.  Clients
  * should never modify publish structures that were passed to
- * "GNUNET_FS_publish_start" already.  When called on a directory,
- * this function will FIRST call "proc" with information about
+ * #GNUNET_FS_publish_start already.  When called on a directory,
+ * this function will FIRST call @a proc with information about
  * the directory itself and then for each of the files in the
  * directory (but not for files in subdirectories).  When called
- * on a file, "proc" will be called exactly once (with information
+ * on a file, @a proc will be called exactly once (with information
  * about the specific file).
  *
  * @param dir the directory
  * @param proc function to call on each entry
- * @param proc_cls closure for proc
+ * @param proc_cls closure for @a proc
  */
 void
 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
@@ -392,13 +391,13 @@ GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
 
 /**
  * Destroy publish-structure.  Clients should never destroy publish
- * structures that were passed to "GNUNET_FS_publish_start" already.
+ * structures that were passed to #GNUNET_FS_publish_start already.
  *
  * @param fi structure to destroy
  * @param cleaner function to call on each entry in the structure
  *        (useful to clean up client_info); can be NULL; return
  *        values are ignored
- * @param cleaner_cls closure for cleaner
+ * @param cleaner_cls closure for @a cleaner
  */
 void
 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
@@ -409,7 +408,7 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
   int no;
 
   no = GNUNET_NO;
-  if (fi->is_directory == GNUNET_YES)
+  if (GNUNET_YES == fi->is_directory)
   {
     /* clean up directory */
     while (NULL != (pos = fi->data.dir.entries))
@@ -439,7 +438,10 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
   }
   GNUNET_free_non_null (fi->filename);
   GNUNET_free_non_null (fi->emsg);
-  GNUNET_free_non_null (fi->chk_uri);
+  if (NULL != fi->sks_uri)
+      GNUNET_FS_uri_destroy (fi->sks_uri);
+  if (NULL != fi->chk_uri)
+      GNUNET_FS_uri_destroy (fi->chk_uri);
   /* clean up serialization */
   if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
@@ -451,7 +453,7 @@ GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
   GNUNET_free_non_null (fi->serialization);
   if (NULL != fi->te)
   {
-    GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
+    GNUNET_FS_tree_encoder_finish (fi->te, NULL);
     fi->te = NULL;
   }
   GNUNET_free (fi);