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