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