bb323bbbc22c21696264176d92bff0de6c0e1193
[oweals/gnunet.git] / src / fs / fs_file_information.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file fs/fs_file_information.c
23  * @brief  Manage information for publishing directory hierarchies
24  * @author Christian Grothoff
25  *
26  * TODO:
27  * - metadata filename clean up code
28  * - metadata/ksk generation for directories from contained files
29  */
30 #include "platform.h"
31 #include <extractor.h>
32 #include "gnunet_fs_service.h"
33 #include "fs.h"
34 #include "fs_tree.h"
35
36
37 /**
38  * Add meta data that libextractor finds to our meta data
39  * container.
40  *
41  * @param cls closure, our meta data container
42  * @param plugin_name name of the plugin that produced this value;
43  *        special values can be used (i.e. '&lt;zlib&gt;' for zlib being
44  *        used in the main libextractor library and yielding
45  *        meta data).
46  * @param type libextractor-type describing the meta data
47  * @param format basic format information about data
48  * @param data_mime_type mime-type of data (not of the original file);
49  *        can be NULL (if mime-type is not known)
50  * @param data actual meta-data found
51  * @param data_len number of bytes in data
52  * @return always 0 to continue extracting
53  */
54 static int
55 add_to_md (void *cls,
56            const char *plugin_name,
57            enum EXTRACTOR_MetaType type,
58            enum EXTRACTOR_MetaFormat format,
59            const char *data_mime_type, const char *data, size_t data_len)
60 {
61   struct GNUNET_CONTAINER_MetaData *md = cls;
62
63   (void) GNUNET_CONTAINER_meta_data_insert (md,
64                                             plugin_name,
65                                             type,
66                                             format,
67                                             data_mime_type, data, data_len);
68   return 0;
69 }
70
71
72 /**
73  * Extract meta-data from a file.
74  *
75  * @return GNUNET_SYSERR on error, otherwise the number
76  *   of meta-data items obtained
77  */
78 int
79 GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData
80                                        *md, const char *filename,
81                                        struct EXTRACTOR_PluginList *extractors)
82 {
83   int old;
84
85   if (filename == NULL)
86     return GNUNET_SYSERR;
87   if (extractors == NULL)
88     return 0;
89   old = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
90   GNUNET_assert (old >= 0);
91   EXTRACTOR_extract (extractors, filename, NULL, 0, &add_to_md, md);
92   return (GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL) - old);
93 }
94
95
96
97 /**
98  * Obtain the name under which this file information
99  * structure is stored on disk.  Only works for top-level
100  * file information structures.
101  *
102  * @param s structure to get the filename for
103  * @return NULL on error, otherwise filename that
104  *         can be passed to "GNUNET_FS_file_information_recover"
105  *         to read this fi-struct from disk.
106  */
107 const char *
108 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
109 {
110   if (NULL != s->dir)
111     return NULL;
112   return s->serialization;
113 }
114
115
116 /**
117  * Create an entry for a file in a publish-structure.
118  *
119  * @param h handle to the file sharing subsystem
120  * @param client_info initial value for the client-info value for this entry
121  * @param filename name of the file or directory to publish
122  * @param keywords under which keywords should this file be available
123  *         directly; can be NULL
124  * @param meta metadata for the file
125  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
126  *                GNUNET_SYSERR for simulation
127  * @param bo block options
128  * @return publish structure entry for the file
129  */
130 struct GNUNET_FS_FileInformation *
131 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
132                                              void *client_info,
133                                              const char *filename,
134                                              const struct GNUNET_FS_Uri
135                                              *keywords,
136                                              const struct
137                                              GNUNET_CONTAINER_MetaData *meta,
138                                              int do_index,
139                                              const struct GNUNET_FS_BlockOptions
140                                              *bo)
141 {
142   struct FileInfo *fi;
143   struct stat sbuf;
144   struct GNUNET_FS_FileInformation *ret;
145   const char *fn;
146   const char *ss;
147
148 #if WINDOWS
149   char fn_conv[MAX_PATH];
150 #endif
151
152   if (0 != STAT (filename, &sbuf))
153   {
154     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
155     return NULL;
156   }
157   fi = GNUNET_FS_make_file_reader_context_ (filename);
158   if (fi == NULL)
159   {
160     GNUNET_break (0);
161     return NULL;
162   }
163   ret = GNUNET_FS_file_information_create_from_reader (h,
164                                                        client_info,
165                                                        sbuf.st_size,
166                                                        &GNUNET_FS_data_reader_file_,
167                                                        fi,
168                                                        keywords,
169                                                        meta, do_index, bo);
170   if (ret == NULL)
171     return NULL;
172   ret->h = h;
173   ret->filename = GNUNET_strdup (filename);
174 #if !WINDOWS
175   fn = filename;
176 #else
177   plibc_conv_to_win_path (filename, fn_conv);
178   fn = fn_conv;
179 #endif
180   while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
181     fn = ss + 1;
182   GNUNET_CONTAINER_meta_data_insert (ret->meta,
183                                      "<gnunet>",
184                                      EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
185                                      EXTRACTOR_METAFORMAT_C_STRING,
186                                      "text/plain", fn, strlen (fn) + 1);
187   return ret;
188 }
189
190
191 /**
192  * Create an entry for a file in a publish-structure.
193  *
194  * @param h handle to the file sharing subsystem
195  * @param client_info initial value for the client-info value for this entry
196  * @param length length of the file
197  * @param data data for the file (should not be used afterwards by
198  *        the caller; callee will "free")
199  * @param keywords under which keywords should this file be available
200  *         directly; can be NULL
201  * @param meta metadata for the file
202  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
203  *                GNUNET_SYSERR for simulation
204  * @param bo block options
205  * @return publish structure entry for the file
206  */
207 struct GNUNET_FS_FileInformation *
208 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
209                                              void *client_info,
210                                              uint64_t length,
211                                              void *data,
212                                              const struct GNUNET_FS_Uri
213                                              *keywords,
214                                              const struct
215                                              GNUNET_CONTAINER_MetaData *meta,
216                                              int do_index,
217                                              const struct GNUNET_FS_BlockOptions
218                                              *bo)
219 {
220   if (GNUNET_YES == do_index)
221   {
222     GNUNET_break (0);
223     return NULL;
224   }
225   return GNUNET_FS_file_information_create_from_reader (h,
226                                                         client_info,
227                                                         length,
228                                                         &GNUNET_FS_data_reader_copy_,
229                                                         data,
230                                                         keywords,
231                                                         meta, do_index, bo);
232 }
233
234
235 /**
236  * Create an entry for a file in a publish-structure.
237  *
238  * @param h handle to the file sharing subsystem
239  * @param client_info initial value for the client-info value for this entry
240  * @param length length of the file
241  * @param reader function that can be used to obtain the data for the file 
242  * @param reader_cls closure for "reader"
243  * @param keywords under which keywords should this file be available
244  *         directly; can be NULL
245  * @param meta metadata for the file
246  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
247  *                GNUNET_SYSERR for simulation
248  * @param bo block options
249  * @return publish structure entry for the file
250  */
251 struct GNUNET_FS_FileInformation *
252 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
253                                                void *client_info,
254                                                uint64_t length,
255                                                GNUNET_FS_DataReader reader,
256                                                void *reader_cls,
257                                                const struct GNUNET_FS_Uri
258                                                *keywords,
259                                                const struct
260                                                GNUNET_CONTAINER_MetaData *meta,
261                                                int do_index,
262                                                const struct
263                                                GNUNET_FS_BlockOptions *bo)
264 {
265   struct GNUNET_FS_FileInformation *ret;
266
267   if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
268   {
269     GNUNET_break (0);
270     return NULL;
271   }
272   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
273   ret->h = h;
274   ret->client_info = client_info;
275   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
276   if (ret->meta == NULL)
277     ret->meta = GNUNET_CONTAINER_meta_data_create ();
278   ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
279   ret->data.file.reader = reader;
280   ret->data.file.reader_cls = reader_cls;
281   ret->data.file.do_index = do_index;
282   ret->data.file.file_size = length;
283   ret->bo = *bo;
284   return ret;
285 }
286
287
288 /**
289  * Closure for "dir_scan_cb".
290  */
291 struct DirScanCls
292 {
293   /**
294    * Metadata extractors to use.
295    */
296   struct EXTRACTOR_PluginList *extractors;
297
298   /**
299    * Master context.
300    */
301   struct GNUNET_FS_Handle *h;
302
303   /**
304    * Function to call on each directory entry.
305    */
306   GNUNET_FS_FileProcessor proc;
307
308   /**
309    * Closure for proc.
310    */
311   void *proc_cls;
312
313   /**
314    * Scanner to use for subdirectories.
315    */
316   GNUNET_FS_DirectoryScanner scanner;
317
318   /**
319    * Closure for scanner.
320    */
321   void *scanner_cls;
322
323   /**
324    * Set to an error message (if any).
325    */
326   char *emsg;
327
328   /**
329    * Block options.
330    */
331   const struct GNUNET_FS_BlockOptions *bo;
332
333   /**
334    * Should files be indexed?
335    */
336   int do_index;
337
338 };
339
340
341 /**
342  * Function called on each entry in a file to
343  * cause default-publishing.
344  * @param cls closure (struct DirScanCls)
345  * @param filename name of the file to be published
346  * @return GNUNET_OK on success, GNUNET_SYSERR to abort
347  */
348 static int
349 dir_scan_cb (void *cls, const char *filename)
350 {
351   struct DirScanCls *dsc = cls;
352   struct stat sbuf;
353   struct GNUNET_FS_FileInformation *fi;
354   struct GNUNET_FS_Uri *ksk_uri;
355   struct GNUNET_FS_Uri *keywords;
356   struct GNUNET_CONTAINER_MetaData *meta;
357
358   if (0 != STAT (filename, &sbuf))
359   {
360     GNUNET_asprintf (&dsc->emsg,
361                      _("`%s' failed on file `%s': %s"),
362                      "stat", filename, STRERROR (errno));
363     return GNUNET_SYSERR;
364   }
365   if (S_ISDIR (sbuf.st_mode))
366   {
367     fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
368                                                            NULL,
369                                                            filename,
370                                                            dsc->scanner,
371                                                            dsc->scanner_cls,
372                                                            dsc->do_index,
373                                                            dsc->bo, &dsc->emsg);
374     if (NULL == fi)
375     {
376       GNUNET_assert (NULL != dsc->emsg);
377       return GNUNET_SYSERR;
378     }
379   }
380   else
381   {
382     meta = GNUNET_CONTAINER_meta_data_create ();
383     GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
384     keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
385     ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
386     fi = GNUNET_FS_file_information_create_from_file (dsc->h,
387                                                       NULL,
388                                                       filename,
389                                                       ksk_uri,
390                                                       meta,
391                                                       dsc->do_index, dsc->bo);
392     GNUNET_CONTAINER_meta_data_destroy (meta);
393     GNUNET_FS_uri_destroy (keywords);
394     GNUNET_FS_uri_destroy (ksk_uri);
395   }
396   dsc->proc (dsc->proc_cls, filename, fi);
397   return GNUNET_OK;
398 }
399
400
401 /**
402  * Simple, useful default implementation of a directory scanner
403  * (GNUNET_FS_DirectoryScanner).  This implementation expects to get a
404  * UNIX filename, will publish all files in the directory except hidden
405  * files (those starting with a ".").  Metadata will be extracted
406  * using GNU libextractor; the specific list of plugins should be
407  * specified in "cls", passing NULL will disable (!)  metadata
408  * extraction.  Keywords will be derived from the metadata and be
409  * subject to default canonicalization.  This is strictly a
410  * convenience function.
411  *
412  * @param cls must be of type "struct EXTRACTOR_Extractor*"
413  * @param h handle to the file sharing subsystem
414  * @param dirname name of the directory to scan
415  * @param do_index should files be indexed or inserted
416  * @param bo block options
417  * @param proc function called on each entry
418  * @param proc_cls closure for proc
419  * @param emsg where to store an error message (on errors)
420  * @return GNUNET_OK on success
421  */
422 int
423 GNUNET_FS_directory_scanner_default (void *cls,
424                                      struct GNUNET_FS_Handle *h,
425                                      const char *dirname,
426                                      int do_index,
427                                      const struct GNUNET_FS_BlockOptions *bo,
428                                      GNUNET_FS_FileProcessor proc,
429                                      void *proc_cls, char **emsg)
430 {
431   struct EXTRACTOR_PluginList *ex = cls;
432   struct DirScanCls dsc;
433
434   dsc.h = h;
435   dsc.extractors = ex;
436   dsc.proc = proc;
437   dsc.proc_cls = proc_cls;
438   dsc.scanner = &GNUNET_FS_directory_scanner_default;
439   dsc.scanner_cls = cls;
440   dsc.do_index = do_index;
441   dsc.bo = bo;
442   if (-1 == GNUNET_DISK_directory_scan (dirname, &dir_scan_cb, &dsc))
443   {
444     GNUNET_assert (NULL != dsc.emsg);
445     *emsg = dsc.emsg;
446     return GNUNET_SYSERR;
447   }
448   return GNUNET_OK;
449 }
450
451
452 /**
453  * Closure for dirproc function.
454  */
455 struct EntryProcCls
456 {
457   /**
458    * Linked list of directory entries that is being
459    * created.
460    */
461   struct GNUNET_FS_FileInformation *entries;
462
463 };
464
465
466 /**
467  * Function that processes a directory entry that
468  * was obtained from the scanner.
469  * @param cls our closure
470  * @param filename name of the file (unused, why there???)
471  * @param fi information for publishing the file
472  */
473 static void
474 dirproc (void *cls, const char *filename, struct GNUNET_FS_FileInformation *fi)
475 {
476   struct EntryProcCls *dc = cls;
477
478   GNUNET_assert (fi->next == NULL);
479   GNUNET_assert (fi->dir == NULL);
480   fi->next = dc->entries;
481   dc->entries = fi;
482 }
483
484
485 /**
486  * Create a publish-structure from an existing file hierarchy, inferring
487  * and organizing keywords and metadata as much as possible.  This
488  * function primarily performs the recursive build and re-organizes
489  * keywords and metadata; for automatically getting metadata
490  * extraction, scanning of directories and creation of the respective
491  * GNUNET_FS_FileInformation entries the default scanner should be
492  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
493  * convenience function.
494  *
495  * @param h handle to the file sharing subsystem
496  * @param client_info initial value for the client-info value for this entry
497  * @param filename name of the top-level file or directory
498  * @param scanner function used to get a list of files in a directory
499  * @param scanner_cls closure for scanner
500  * @param do_index should files in the hierarchy be indexed?
501  * @param bo block options
502  * @param emsg where to store an error message
503  * @return publish structure entry for the directory, NULL on error
504  */
505 struct GNUNET_FS_FileInformation *
506 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
507                                                   void *client_info,
508                                                   const char *filename,
509                                                   GNUNET_FS_DirectoryScanner
510                                                   scanner, void *scanner_cls,
511                                                   int do_index,
512                                                   const struct
513                                                   GNUNET_FS_BlockOptions *bo,
514                                                   char **emsg)
515 {
516   struct GNUNET_FS_FileInformation *ret;
517   struct EntryProcCls dc;
518   struct GNUNET_FS_Uri *ksk;
519   struct GNUNET_CONTAINER_MetaData *meta;
520   const char *fn;
521   const char *ss;
522   char *dn;
523
524   dc.entries = NULL;
525   meta = GNUNET_CONTAINER_meta_data_create ();
526   GNUNET_FS_meta_data_make_directory (meta);
527   scanner (scanner_cls, h, filename, do_index, bo, &dirproc, &dc, emsg);
528   ksk = NULL;                   // FIXME...
529   // FIXME: create meta!
530   ret = GNUNET_FS_file_information_create_empty_directory (h,
531                                                            client_info,
532                                                            ksk, meta, bo);
533   GNUNET_CONTAINER_meta_data_destroy (meta);
534   ret->data.dir.entries = dc.entries;
535   while (dc.entries != NULL)
536   {
537     dc.entries->dir = ret;
538     dc.entries = dc.entries->next;
539   }
540   fn = filename;
541   while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
542     fn = ss + 1;
543   GNUNET_asprintf (&dn, "%s/", fn);
544   GNUNET_CONTAINER_meta_data_insert (ret->meta,
545                                      "<gnunet>",
546                                      EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
547                                      EXTRACTOR_METAFORMAT_C_STRING,
548                                      "text/plain", dn, strlen (dn) + 1);
549   GNUNET_free (dn);
550   ret->filename = GNUNET_strdup (filename);
551   return ret;
552 }
553
554
555 /**
556  * Test if a given entry represents a directory.
557  *
558  * @param ent check if this FI represents a directory
559  * @return GNUNET_YES if so, GNUNET_NO if not
560  */
561 int
562 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
563                                          *ent)
564 {
565   return ent->is_directory;
566 }
567
568
569 /**
570  * Create an entry for an empty directory in a publish-structure.
571  * This function should be used by applications for which the
572  * use of "GNUNET_FS_file_information_create_from_directory"
573  * is not appropriate.
574  *
575  * @param h handle to the file sharing subsystem
576  * @param client_info initial value for the client-info value for this entry
577  * @param meta metadata for the directory
578  * @param keywords under which keywords should this directory be available
579  *         directly; can be NULL
580  * @param bo block options
581  * @return publish structure entry for the directory , NULL on error
582  */
583 struct GNUNET_FS_FileInformation *
584 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
585                                                    void *client_info,
586                                                    const struct GNUNET_FS_Uri
587                                                    *keywords,
588                                                    const struct
589                                                    GNUNET_CONTAINER_MetaData
590                                                    *meta,
591                                                    const struct
592                                                    GNUNET_FS_BlockOptions *bo)
593 {
594   struct GNUNET_FS_FileInformation *ret;
595
596   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
597   ret->h = h;
598   ret->client_info = client_info;
599   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
600   ret->keywords = GNUNET_FS_uri_dup (keywords);
601   ret->bo = *bo;
602   ret->is_directory = GNUNET_YES;
603   return ret;
604 }
605
606
607 /**
608  * Add an entry to a directory in a publish-structure.  Clients
609  * should never modify publish structures that were passed to
610  * "GNUNET_FS_publish_start" already.
611  *
612  * @param dir the directory
613  * @param ent the entry to add; the entry must not have been
614  *            added to any other directory at this point and 
615  *            must not include "dir" in its structure
616  * @return GNUNET_OK on success, GNUNET_SYSERR on error
617  */
618 int
619 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
620                                 struct GNUNET_FS_FileInformation *ent)
621 {
622   if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
623   {
624     GNUNET_break (0);
625     return GNUNET_SYSERR;
626   }
627   ent->dir = dir;
628   ent->next = dir->data.dir.entries;
629   dir->data.dir.entries = ent;
630   dir->data.dir.dir_size = 0;
631   return GNUNET_OK;
632 }
633
634
635 /**
636  * Inspect a file or directory in a publish-structure.  Clients
637  * should never modify publish structures that were passed to
638  * "GNUNET_FS_publish_start" already.  When called on a directory,
639  * this function will FIRST call "proc" with information about
640  * the directory itself and then for each of the files in the
641  * directory (but not for files in subdirectories).  When called
642  * on a file, "proc" will be called exactly once (with information
643  * about the specific file).
644  *
645  * @param dir the directory
646  * @param proc function to call on each entry
647  * @param proc_cls closure for proc
648  */
649 void
650 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
651                                     GNUNET_FS_FileInformationProcessor proc,
652                                     void *proc_cls)
653 {
654   struct GNUNET_FS_FileInformation *pos;
655   int no;
656
657   no = GNUNET_NO;
658   if (GNUNET_OK !=
659       proc (proc_cls,
660             dir,
661             (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
662             file.file_size, dir->meta, &dir->keywords, &dir->bo,
663             (dir->is_directory) ? &no : &dir->data.file.do_index,
664             &dir->client_info))
665     return;
666   if (!dir->is_directory)
667     return;
668   pos = dir->data.dir.entries;
669   while (pos != NULL)
670   {
671     no = GNUNET_NO;
672     if (GNUNET_OK !=
673         proc (proc_cls,
674               pos,
675               (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
676               file.file_size, pos->meta, &pos->keywords, &pos->bo,
677               (dir->is_directory) ? &no : &dir->data.file.do_index,
678               &pos->client_info))
679       break;
680     pos = pos->next;
681   }
682 }
683
684
685 /**
686  * Destroy publish-structure.  Clients should never destroy publish
687  * structures that were passed to "GNUNET_FS_publish_start" already.
688  *
689  * @param fi structure to destroy
690  * @param cleaner function to call on each entry in the structure
691  *        (useful to clean up client_info); can be NULL; return
692  *        values are ignored
693  * @param cleaner_cls closure for cleaner
694  */
695 void
696 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
697                                     GNUNET_FS_FileInformationProcessor cleaner,
698                                     void *cleaner_cls)
699 {
700   struct GNUNET_FS_FileInformation *pos;
701   int no;
702
703   no = GNUNET_NO;
704   if (fi->is_directory)
705   {
706     /* clean up directory */
707     while (NULL != (pos = fi->data.dir.entries))
708     {
709       fi->data.dir.entries = pos->next;
710       GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
711     }
712     /* clean up client-info */
713     if (NULL != cleaner)
714       cleaner (cleaner_cls,
715                fi,
716                fi->data.dir.dir_size,
717                fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info);
718     GNUNET_free_non_null (fi->data.dir.dir_data);
719   }
720   else
721   {
722     /* call clean-up function of the reader */
723     if (fi->data.file.reader != NULL)
724       fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
725     /* clean up client-info */
726     if (NULL != cleaner)
727       cleaner (cleaner_cls,
728                fi,
729                fi->data.file.file_size,
730                fi->meta,
731                &fi->keywords,
732                &fi->bo, &fi->data.file.do_index, &fi->client_info);
733   }
734   GNUNET_free_non_null (fi->filename);
735   GNUNET_free_non_null (fi->emsg);
736   GNUNET_free_non_null (fi->chk_uri);
737   /* clean up serialization */
738   if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
739     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
740                               "unlink", fi->serialization);
741   if (NULL != fi->keywords)
742     GNUNET_FS_uri_destroy (fi->keywords);
743   if (NULL != fi->meta)
744     GNUNET_CONTAINER_meta_data_destroy (fi->meta);
745   GNUNET_free_non_null (fi->serialization);
746   if (fi->te != NULL)
747   {
748     GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
749     fi->te = NULL;
750   }
751   GNUNET_free (fi);
752 }
753
754
755 /* end of fs_file_information.c */