comments
[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
153   if (0 != STAT (filename, &sbuf))
154     {
155       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
156                                 "stat",
157                                 filename);
158       return NULL;
159     }
160   fi = GNUNET_FS_make_file_reader_context_ (filename);
161   if (fi == NULL)
162     {
163       GNUNET_break (0);
164       return NULL;
165     }
166   ret = GNUNET_FS_file_information_create_from_reader (h,
167                                                        client_info,
168                                                        sbuf.st_size,
169                                                        &GNUNET_FS_data_reader_file_,
170                                                        fi,
171                                                        keywords,
172                                                        meta,
173                                                        do_index,
174                                                        bo);
175   if (ret == NULL)
176     return NULL;
177   ret->h = h;
178   ret->filename = GNUNET_strdup (filename);
179   fn = filename;
180   while (NULL != (ss = strstr (fn,
181                                DIR_SEPARATOR_STR)))
182     fn = ss + 1;
183   GNUNET_CONTAINER_meta_data_insert (ret->meta,
184                                      "<gnunet>",
185                                      EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
186                                      EXTRACTOR_METAFORMAT_C_STRING,
187                                      "text/plain",
188                                      fn,
189                                      strlen (fn) + 1);
190   return ret;
191 }
192
193
194 /**
195  * Create an entry for a file in a publish-structure.
196  *
197  * @param h handle to the file sharing subsystem
198  * @param client_info initial value for the client-info value for this entry
199  * @param length length of the file
200  * @param data data for the file (should not be used afterwards by
201  *        the caller; callee will "free")
202  * @param keywords under which keywords should this file be available
203  *         directly; can be NULL
204  * @param meta metadata for the file
205  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
206  *                GNUNET_SYSERR for simulation
207  * @param bo block options
208  * @return publish structure entry for the file
209  */
210 struct GNUNET_FS_FileInformation *
211 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
212                                              void *client_info,
213                                              uint64_t length,
214                                              void *data,
215                                              const struct GNUNET_FS_Uri *keywords,
216                                              const struct GNUNET_CONTAINER_MetaData *meta,
217                                              int do_index,
218                                              const struct GNUNET_FS_BlockOptions *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,
232                                                         do_index,
233                                                         bo);
234 }
235
236
237 /**
238  * Create an entry for a file in a publish-structure.
239  *
240  * @param h handle to the file sharing subsystem
241  * @param client_info initial value for the client-info value for this entry
242  * @param length length of the file
243  * @param reader function that can be used to obtain the data for the file 
244  * @param reader_cls closure for "reader"
245  * @param keywords under which keywords should this file be available
246  *         directly; can be NULL
247  * @param meta metadata for the file
248  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
249  *                GNUNET_SYSERR for simulation
250  * @param bo block options
251  * @return publish structure entry for the file
252  */
253 struct GNUNET_FS_FileInformation *
254 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
255                                                void *client_info,
256                                                uint64_t length,
257                                                GNUNET_FS_DataReader reader,
258                                                void *reader_cls,
259                                                const struct GNUNET_FS_Uri *keywords,
260                                                const struct GNUNET_CONTAINER_MetaData *meta,
261                                                int do_index,
262                                                const struct GNUNET_FS_BlockOptions *bo)
263 {
264   struct GNUNET_FS_FileInformation *ret;
265
266   if ( (GNUNET_YES == do_index) &&
267        (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,
350              const char *filename)
351 {
352   struct DirScanCls *dsc = cls;  
353   struct stat sbuf;
354   struct GNUNET_FS_FileInformation *fi;
355   struct GNUNET_FS_Uri *ksk_uri;
356   struct GNUNET_FS_Uri *keywords;
357   struct GNUNET_CONTAINER_MetaData *meta;
358
359   if (0 != STAT (filename, &sbuf))
360     {
361       GNUNET_asprintf (&dsc->emsg,
362                        _("`%s' failed on file `%s': %s"),
363                        "stat",
364                        filename,
365                        STRERROR (errno));
366       return GNUNET_SYSERR;
367     }
368   if (S_ISDIR (sbuf.st_mode))
369     {
370       fi = GNUNET_FS_file_information_create_from_directory (dsc->h,
371                                                              NULL,
372                                                              filename,
373                                                              dsc->scanner,
374                                                              dsc->scanner_cls,
375                                                              dsc->do_index,
376                                                              dsc->bo,
377                                                              &dsc->emsg);
378       if (NULL == fi)
379         {
380           GNUNET_assert (NULL != dsc->emsg);
381           return GNUNET_SYSERR;
382         }
383     }
384   else
385     {
386       meta = GNUNET_CONTAINER_meta_data_create ();
387       GNUNET_FS_meta_data_extract_from_file (meta,
388                                              filename,
389                                              dsc->extractors);
390       keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
391       ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
392       fi = GNUNET_FS_file_information_create_from_file (dsc->h,
393                                                         NULL,
394                                                         filename,
395                                                         ksk_uri,
396                                                         meta,
397                                                         dsc->do_index,
398                                                         dsc->bo);
399       GNUNET_CONTAINER_meta_data_destroy (meta);
400       GNUNET_FS_uri_destroy (keywords);
401       GNUNET_FS_uri_destroy (ksk_uri);
402     }
403   dsc->proc (dsc->proc_cls,
404              filename,
405              fi);
406   return GNUNET_OK;
407 }
408
409
410 /**
411  * Simple, useful default implementation of a directory scanner
412  * (GNUNET_FS_DirectoryScanner).  This implementation expects to get a
413  * UNIX filename, will publish all files in the directory except hidden
414  * files (those starting with a ".").  Metadata will be extracted
415  * using GNU libextractor; the specific list of plugins should be
416  * specified in "cls", passing NULL will disable (!)  metadata
417  * extraction.  Keywords will be derived from the metadata and be
418  * subject to default canonicalization.  This is strictly a
419  * convenience function.
420  *
421  * @param cls must be of type "struct EXTRACTOR_Extractor*"
422  * @param h handle to the file sharing subsystem
423  * @param dirname name of the directory to scan
424  * @param do_index should files be indexed or inserted
425  * @param bo block options
426  * @param proc function called on each entry
427  * @param proc_cls closure for proc
428  * @param emsg where to store an error message (on errors)
429  * @return GNUNET_OK on success
430  */
431 int
432 GNUNET_FS_directory_scanner_default (void *cls,
433                                      struct GNUNET_FS_Handle *h,
434                                      const char *dirname,
435                                      int do_index,
436                                      const struct GNUNET_FS_BlockOptions *bo,
437                                      GNUNET_FS_FileProcessor proc,
438                                      void *proc_cls,
439                                      char **emsg)
440 {
441   struct EXTRACTOR_PluginList *ex = cls;
442   struct DirScanCls dsc;
443
444   dsc.h = h;
445   dsc.extractors = ex;
446   dsc.proc = proc;
447   dsc.proc_cls = proc_cls;
448   dsc.scanner = &GNUNET_FS_directory_scanner_default;
449   dsc.scanner_cls = cls;
450   dsc.do_index = do_index;
451   dsc.bo = bo;
452   if (-1 == GNUNET_DISK_directory_scan (dirname,
453                                         &dir_scan_cb,
454                                         &dsc))
455     {
456       GNUNET_assert (NULL != dsc.emsg);
457       *emsg = dsc.emsg;
458       return GNUNET_SYSERR;
459     }
460   return GNUNET_OK;
461 }
462
463
464 /**
465  * Closure for dirproc function.
466  */
467 struct EntryProcCls
468 {
469   /**
470    * Linked list of directory entries that is being
471    * created.
472    */
473   struct GNUNET_FS_FileInformation *entries;
474
475 };
476
477
478 /**
479  * Function that processes a directory entry that
480  * was obtained from the scanner.
481  * @param cls our closure
482  * @param filename name of the file (unused, why there???)
483  * @param fi information for publishing the file
484  */
485 static void
486 dirproc (void *cls,
487          const char *filename,
488          struct GNUNET_FS_FileInformation *fi)
489 {
490   struct EntryProcCls *dc = cls;
491
492   GNUNET_assert (fi->next == NULL);
493   GNUNET_assert (fi->dir == NULL);
494   fi->next = dc->entries;
495   dc->entries = fi;
496 }
497
498
499 /**
500  * Create a publish-structure from an existing file hierarchy, inferring
501  * and organizing keywords and metadata as much as possible.  This
502  * function primarily performs the recursive build and re-organizes
503  * keywords and metadata; for automatically getting metadata
504  * extraction, scanning of directories and creation of the respective
505  * GNUNET_FS_FileInformation entries the default scanner should be
506  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
507  * convenience function.
508  *
509  * @param h handle to the file sharing subsystem
510  * @param client_info initial value for the client-info value for this entry
511  * @param filename name of the top-level file or directory
512  * @param scanner function used to get a list of files in a directory
513  * @param scanner_cls closure for scanner
514  * @param do_index should files in the hierarchy be indexed?
515  * @param bo block options
516  * @param emsg where to store an error message
517  * @return publish structure entry for the directory, NULL on error
518  */
519 struct GNUNET_FS_FileInformation *
520 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
521                                                   void *client_info,
522                                                   const char *filename,
523                                                   GNUNET_FS_DirectoryScanner scanner,
524                                                   void *scanner_cls,
525                                                   int do_index,
526                                                   const struct GNUNET_FS_BlockOptions *bo,
527                                                   char **emsg)
528 {
529   struct GNUNET_FS_FileInformation *ret;
530   struct EntryProcCls dc;
531   struct GNUNET_FS_Uri *ksk;
532   struct GNUNET_CONTAINER_MetaData *meta;
533   const char *fn;
534   const char *ss;
535   char *dn;
536
537   dc.entries = NULL;
538   meta = GNUNET_CONTAINER_meta_data_create ();
539   GNUNET_FS_meta_data_make_directory (meta);
540   scanner (scanner_cls,
541            h,
542            filename,
543            do_index,
544            bo,
545            &dirproc,
546            &dc,
547            emsg);
548   ksk = NULL; // FIXME...
549   // FIXME: create meta!
550   ret = GNUNET_FS_file_information_create_empty_directory (h,
551                                                            client_info,
552                                                            ksk,
553                                                            meta,
554                                                            bo);
555   GNUNET_CONTAINER_meta_data_destroy (meta);
556   ret->data.dir.entries = dc.entries;
557   while (dc.entries != NULL)
558     {
559       dc.entries->dir = ret;
560       dc.entries = dc.entries->next;
561     }
562   fn = filename;
563   while ( (NULL != (ss = strstr (fn,
564                                  DIR_SEPARATOR_STR))) &&
565           (strlen (ss) > 1) )
566     fn = ss + 1;
567   GNUNET_asprintf (&dn,
568                    "%s/", 
569                    fn);
570   GNUNET_CONTAINER_meta_data_insert (ret->meta,
571                                      "<gnunet>",
572                                      EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
573                                      EXTRACTOR_METAFORMAT_C_STRING,
574                                      "text/plain",
575                                      dn,
576                                      strlen (dn) + 1);
577   GNUNET_free (dn);
578   ret->filename = GNUNET_strdup (filename);
579   return ret;
580 }
581
582
583 /**
584  * Test if a given entry represents a directory.
585  *
586  * @param ent check if this FI represents a directory
587  * @return GNUNET_YES if so, GNUNET_NO if not
588  */
589 int
590 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation *ent)
591 {
592   return ent->is_directory;
593 }
594
595
596 /**
597  * Create an entry for an empty directory in a publish-structure.
598  * This function should be used by applications for which the
599  * use of "GNUNET_FS_file_information_create_from_directory"
600  * is not appropriate.
601  *
602  * @param h handle to the file sharing subsystem
603  * @param client_info initial value for the client-info value for this entry
604  * @param meta metadata for the directory
605  * @param keywords under which keywords should this directory be available
606  *         directly; can be NULL
607  * @param bo block options
608  * @return publish structure entry for the directory , NULL on error
609  */
610 struct GNUNET_FS_FileInformation *
611 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
612                                                    void *client_info,
613                                                    const struct GNUNET_FS_Uri *keywords,
614                                                    const struct GNUNET_CONTAINER_MetaData *meta,
615                                                    const struct GNUNET_FS_BlockOptions *bo)
616 {
617   struct GNUNET_FS_FileInformation *ret;
618
619   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
620   ret->h = h;
621   ret->client_info = client_info;
622   ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
623   ret->keywords = GNUNET_FS_uri_dup (keywords);
624   ret->bo = *bo;
625   ret->is_directory = GNUNET_YES;
626   return ret;
627 }
628
629
630 /**
631  * Add an entry to a directory in a publish-structure.  Clients
632  * should never modify publish structures that were passed to
633  * "GNUNET_FS_publish_start" already.
634  *
635  * @param dir the directory
636  * @param ent the entry to add; the entry must not have been
637  *            added to any other directory at this point and 
638  *            must not include "dir" in its structure
639  * @return GNUNET_OK on success, GNUNET_SYSERR on error
640  */
641 int
642 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
643                                 struct GNUNET_FS_FileInformation *ent)
644 {
645   if ( (ent->dir != NULL) ||
646        (ent->next != NULL) ||
647        (! dir->is_directory) )
648     {
649       GNUNET_break (0);
650       return GNUNET_SYSERR;
651     }
652   ent->dir = dir;
653   ent->next = dir->data.dir.entries;
654   dir->data.dir.entries = ent;
655   dir->data.dir.dir_size = 0;
656   return GNUNET_OK;
657 }
658
659
660 /**
661  * Inspect a file or directory in a publish-structure.  Clients
662  * should never modify publish structures that were passed to
663  * "GNUNET_FS_publish_start" already.  When called on a directory,
664  * this function will FIRST call "proc" with information about
665  * the directory itself and then for each of the files in the
666  * directory (but not for files in subdirectories).  When called
667  * on a file, "proc" will be called exactly once (with information
668  * about the specific file).
669  *
670  * @param dir the directory
671  * @param proc function to call on each entry
672  * @param proc_cls closure for proc
673  */
674 void
675 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
676                                     GNUNET_FS_FileInformationProcessor proc,
677                                     void *proc_cls)
678 {
679   struct GNUNET_FS_FileInformation *pos;
680   int no;
681
682   no = GNUNET_NO;
683   if (GNUNET_OK !=
684       proc (proc_cls, 
685             dir,
686             (dir->is_directory) ? dir->data.dir.dir_size : dir->data.file.file_size,
687             dir->meta,
688             &dir->keywords,
689             &dir->bo,
690             (dir->is_directory) ? &no : &dir->data.file.do_index,
691             &dir->client_info))
692     return;
693   if (! dir->is_directory)
694     return;
695   pos = dir->data.dir.entries;
696   while (pos != NULL)
697     {
698       no = GNUNET_NO;
699       if (GNUNET_OK != 
700           proc (proc_cls, 
701                 pos,
702                 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.file.file_size,
703                 pos->meta,
704                 &pos->keywords,
705                 &pos->bo,
706                 (dir->is_directory) ? &no : &dir->data.file.do_index,
707                 &pos->client_info))
708         break;
709       pos = pos->next;
710     }
711 }
712
713
714 /**
715  * Destroy publish-structure.  Clients should never destroy publish
716  * structures that were passed to "GNUNET_FS_publish_start" already.
717  *
718  * @param fi structure to destroy
719  * @param cleaner function to call on each entry in the structure
720  *        (useful to clean up client_info); can be NULL; return
721  *        values are ignored
722  * @param cleaner_cls closure for cleaner
723  */
724 void
725 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
726                                     GNUNET_FS_FileInformationProcessor cleaner,
727                                     void *cleaner_cls)
728 {
729   struct GNUNET_FS_FileInformation *pos;
730   int no;
731
732   no = GNUNET_NO;
733   if (fi->is_directory)
734     {
735       /* clean up directory */
736       while (NULL != (pos = fi->data.dir.entries))
737         {
738           fi->data.dir.entries = pos->next;
739           GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
740         }
741       /* clean up client-info */
742       if (NULL != cleaner)
743         cleaner (cleaner_cls, 
744                  fi,
745                  fi->data.dir.dir_size,
746                  fi->meta,
747                  &fi->keywords,
748                  &fi->bo,
749                  &no,
750                  &fi->client_info);
751       GNUNET_free_non_null (fi->data.dir.dir_data);
752     }
753   else
754     {
755       /* call clean-up function of the reader */
756       if (fi->data.file.reader != NULL)
757         fi->data.file.reader (fi->data.file.reader_cls, 0, 0, 
758                               NULL, NULL);
759       /* clean up client-info */
760       if (NULL != cleaner)
761         cleaner (cleaner_cls, 
762                  fi,
763                  fi->data.file.file_size,
764                  fi->meta,
765                  &fi->keywords,
766                  &fi->bo,
767                  &fi->data.file.do_index,
768                  &fi->client_info);
769     }
770   GNUNET_free_non_null (fi->filename);
771   GNUNET_free_non_null (fi->emsg);
772   GNUNET_free_non_null (fi->chk_uri);
773   /* clean up serialization */
774   if ( (NULL != fi->serialization) &&
775        (0 != UNLINK (fi->serialization)) )
776     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
777                               "unlink",
778                               fi->serialization);
779   if (NULL != fi->keywords)
780     GNUNET_FS_uri_destroy (fi->keywords);
781   if (NULL != fi->meta)
782     GNUNET_CONTAINER_meta_data_destroy (fi->meta);
783   GNUNET_free_non_null (fi->serialization);
784   if (fi->te != NULL)
785     {
786       GNUNET_FS_tree_encoder_finish (fi->te,
787                                      NULL, NULL);
788       fi->te = NULL;
789     }
790   GNUNET_free (fi);
791 }
792
793
794 /* end of fs_file_information.c */