2 This file is part of GNUnet.
3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file fs/fs_file_information.c
23 * @brief Manage information for publishing directory hierarchies
24 * @author Christian Grothoff
27 * - metadata filename clean up code
28 * - metadata/ksk generation for directories from contained files
31 #include <extractor.h>
32 #include "gnunet_fs_service.h"
38 * Add meta data that libextractor finds to our meta data
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. '<zlib>' for zlib being
44 * used in the main libextractor library and yielding
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
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)
59 struct GNUNET_CONTAINER_MetaData *md = cls;
61 (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
62 data_mime_type, data, data_len);
68 * Extract meta-data from a file.
70 * @return GNUNET_SYSERR on error, otherwise the number
71 * of meta-data items obtained
74 GNUNET_FS_meta_data_extract_from_file (struct GNUNET_CONTAINER_MetaData *md,
76 struct EXTRACTOR_PluginList *extractors)
82 if (extractors == NULL)
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);
93 * Obtain the name under which this file information
94 * structure is stored on disk. Only works for top-level
95 * file information structures.
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.
103 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s)
107 return s->serialization;
112 * Create an entry for a file in a publish-structure.
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
125 struct GNUNET_FS_FileInformation *
126 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
128 const char *filename,
129 const struct GNUNET_FS_Uri
132 GNUNET_CONTAINER_MetaData *meta,
134 const struct GNUNET_FS_BlockOptions
139 struct GNUNET_FS_FileInformation *ret;
144 char fn_conv[MAX_PATH];
147 if (0 != STAT (filename, &sbuf))
149 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
152 fi = GNUNET_FS_make_file_reader_context_ (filename);
159 GNUNET_FS_file_information_create_from_reader (h, client_info,
161 &GNUNET_FS_data_reader_file_,
167 ret->filename = GNUNET_strdup (filename);
171 plibc_conv_to_win_path (filename, fn_conv);
174 while (NULL != (ss = strstr (fn, DIR_SEPARATOR_STR)))
177 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
178 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
179 EXTRACTOR_METAFORMAT_C_STRING,
180 "text/plain", fn, strlen (fn) + 1);
182 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
183 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
184 EXTRACTOR_METAFORMAT_UTF8,
185 "text/plain", fn, strlen (fn) + 1);
192 * Create an entry for a file in a publish-structure.
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
207 struct GNUNET_FS_FileInformation *
208 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
209 void *client_info, uint64_t length,
211 const struct GNUNET_FS_Uri
214 GNUNET_CONTAINER_MetaData *meta,
216 const struct GNUNET_FS_BlockOptions
219 if (GNUNET_YES == do_index)
224 return GNUNET_FS_file_information_create_from_reader (h, client_info, length,
225 &GNUNET_FS_data_reader_copy_,
226 data, keywords, meta,
232 * Create an entry for a file in a publish-structure.
234 * @param h handle to the file sharing subsystem
235 * @param client_info initial value for the client-info value for this entry
236 * @param length length of the file
237 * @param reader function that can be used to obtain the data for the file
238 * @param reader_cls closure for "reader"
239 * @param keywords under which keywords should this file be available
240 * directly; can be NULL
241 * @param meta metadata for the file
242 * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
243 * GNUNET_SYSERR for simulation
244 * @param bo block options
245 * @return publish structure entry for the file
247 struct GNUNET_FS_FileInformation *
248 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
251 GNUNET_FS_DataReader reader,
253 const struct GNUNET_FS_Uri
256 GNUNET_CONTAINER_MetaData *meta,
259 GNUNET_FS_BlockOptions *bo)
261 struct GNUNET_FS_FileInformation *ret;
263 if ((GNUNET_YES == do_index) && (reader != &GNUNET_FS_data_reader_file_))
268 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
270 ret->client_info = client_info;
271 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
272 if (ret->meta == NULL)
273 ret->meta = GNUNET_CONTAINER_meta_data_create ();
274 ret->keywords = (keywords == NULL) ? NULL : GNUNET_FS_uri_dup (keywords);
275 ret->data.file.reader = reader;
276 ret->data.file.reader_cls = reader_cls;
277 ret->data.file.do_index = do_index;
278 ret->data.file.file_size = length;
285 * Closure for "dir_scan_cb".
290 * Metadata extractors to use.
292 struct EXTRACTOR_PluginList *extractors;
297 struct GNUNET_FS_Handle *h;
300 * Function to call on each directory entry.
302 GNUNET_FS_FileProcessor proc;
310 * Scanner to use for subdirectories.
312 GNUNET_FS_DirectoryScanner scanner;
315 * Closure for scanner.
320 * Set to an error message (if any).
327 const struct GNUNET_FS_BlockOptions *bo;
330 * Should files be indexed?
338 * Function called on each entry in a file to cause
339 * default-publishing.
341 * @param cls closure (struct DirScanCls)
342 * @param filename name of the file to be published
343 * @return GNUNET_OK on success, GNUNET_SYSERR to abort
346 dir_scan_cb (void *cls, const char *filename)
348 struct DirScanCls *dsc = cls;
350 struct GNUNET_FS_FileInformation *fi;
351 struct GNUNET_FS_Uri *keywords;
352 struct GNUNET_CONTAINER_MetaData *meta;
354 if (0 != STAT (filename, &sbuf))
356 GNUNET_asprintf (&dsc->emsg, _("`%s' failed on file `%s': %s"), "stat",
357 filename, STRERROR (errno));
358 return GNUNET_SYSERR;
360 if (S_ISDIR (sbuf.st_mode))
362 fi = GNUNET_FS_file_information_create_from_directory (dsc->h, NULL,
367 dsc->bo, &dsc->emsg);
370 GNUNET_assert (NULL != dsc->emsg);
371 return GNUNET_SYSERR;
376 meta = GNUNET_CONTAINER_meta_data_create ();
377 GNUNET_FS_meta_data_extract_from_file (meta, filename, dsc->extractors);
378 keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
379 fi = GNUNET_FS_file_information_create_from_file (dsc->h, NULL, filename,
381 dsc->do_index, dsc->bo);
382 GNUNET_CONTAINER_meta_data_destroy (meta);
383 GNUNET_FS_uri_destroy (keywords);
385 dsc->proc (dsc->proc_cls, filename, fi);
391 * Simple, useful default implementation of a directory scanner
392 * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
393 * UNIX filename, will publish all files in the directory except hidden
394 * files (those starting with a "."). Metadata will be extracted
395 * using GNU libextractor; the specific list of plugins should be
396 * specified in "cls", passing NULL will disable (!) metadata
397 * extraction. Keywords will be derived from the metadata and be
398 * subject to default canonicalization. This is strictly a
399 * convenience function.
401 * @param cls must be of type "struct EXTRACTOR_Extractor*"
402 * @param h handle to the file sharing subsystem
403 * @param dirname name of the directory to scan
404 * @param do_index should files be indexed or inserted
405 * @param bo block options
406 * @param proc function called on each entry
407 * @param proc_cls closure for proc
408 * @param emsg where to store an error message (on errors)
409 * @return GNUNET_OK on success
412 GNUNET_FS_directory_scanner_default (void *cls, struct GNUNET_FS_Handle *h,
413 const char *dirname, int do_index,
414 const struct GNUNET_FS_BlockOptions *bo,
415 GNUNET_FS_FileProcessor proc,
416 void *proc_cls, char **emsg)
418 struct EXTRACTOR_PluginList *ex = cls;
419 struct DirScanCls dsc;
424 dsc.proc_cls = proc_cls;
425 dsc.scanner = &GNUNET_FS_directory_scanner_default;
426 dsc.scanner_cls = cls;
427 dsc.do_index = do_index;
429 if (-1 == GNUNET_DISK_directory_scan (dirname, &dir_scan_cb, &dsc))
431 GNUNET_assert (NULL != dsc.emsg);
433 return GNUNET_SYSERR;
440 * Aggregate information we keep for meta data in each directory.
442 struct MetaValueInformation
448 const char *mime_type;
451 * The actual meta data.
456 * Number of bytes in 'data'.
461 * Type of the meta data.
463 enum EXTRACTOR_MetaType type;
466 * Format of the meta data.
468 enum EXTRACTOR_MetaFormat format;
471 * How often does this meta value occur in this directory?
473 unsigned int frequency;
479 * Type of a function that libextractor calls for each
480 * meta data item found.
482 * @param cls the container multihashmap to update
483 * @param plugin_name name of the plugin that produced this value;
484 * special values can be used (i.e. '<zlib>' for zlib being
485 * used in the main libextractor library and yielding
487 * @param type libextractor-type describing the meta data
488 * @param format basic format information about data
489 * @param data_mime_type mime-type of data (not of the original file);
490 * can be NULL (if mime-type is not known)
491 * @param data actual meta-data found
492 * @param data_len number of bytes in data
493 * @return 0 to continue extracting / iterating
496 update_metamap (void *cls, const char *plugin_name,
497 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
498 const char *data_mime_type, const char *data, size_t data_len)
500 struct GNUNET_CONTAINER_MultiHashMap *map = cls;
502 struct MetaValueInformation *mvi;
504 GNUNET_CRYPTO_hash (data, data_len, &key);
505 mvi = GNUNET_CONTAINER_multihashmap_get (map, &key);
508 mvi = GNUNET_malloc (sizeof (struct MetaValueInformation));
509 mvi->mime_type = data_mime_type;
511 mvi->data_size = data_len;
513 mvi->format = format;
514 GNUNET_CONTAINER_multihashmap_put (map, &key, mvi,
515 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
523 * Aggregate information we keep for keywords in each directory.
525 struct KeywordInformation
529 * Mime-type of keyword.
534 * How often does this meta value occur in this directory?
536 unsigned int frequency;
542 * Closure for dirproc function.
547 * Linked list of directory entries that is being
550 struct GNUNET_FS_FileInformation *entries;
553 * Map describing the meta data for all entries in the
554 * directory. Keys are the hash of the meta-value,
555 * values are of type 'struct MetaValueInformation'.
557 struct GNUNET_CONTAINER_MultiHashMap *metamap;
560 * Map describing the keywords for all entries in the
561 * directory. Keys are the hash of the keyword,
562 * values are of type 'struct KeywordInformation'.
564 struct GNUNET_CONTAINER_MultiHashMap *keywordmap;
567 * Number of entries in 'entries'.
575 * Function that processes a directory entry that
576 * was obtained from the scanner. Adds each entry to
577 * the directory and computes directroy meta map.
579 * @param cls our closure
580 * @param filename name of the file (unused, why there???)
581 * @param fi information for publishing the file
584 dirproc_add (void *cls, const char *filename,
585 struct GNUNET_FS_FileInformation *fi)
587 struct EntryProcCls *dc = cls;
590 struct KeywordInformation *ki;
593 GNUNET_assert (fi->next == NULL);
594 GNUNET_assert (fi->dir == NULL);
595 fi->next = dc->entries;
598 if (NULL != fi->meta)
599 GNUNET_CONTAINER_meta_data_iterate (fi->meta, &update_metamap, dc->metamap);
600 for (i = 0; i < fi->keywords->data.ksk.keywordCount; i++)
602 kw = fi->keywords->data.ksk.keywords[i];
603 GNUNET_CRYPTO_hash (kw, strlen (kw), &key);
604 ki = GNUNET_CONTAINER_multihashmap_get (dc->keywordmap, &key);
607 ki = GNUNET_malloc (sizeof (struct KeywordInformation));
608 ki->keyword = &kw[1];
609 GNUNET_CONTAINER_multihashmap_put (dc->keywordmap, &key, ki,
610 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
618 * Closure for 'compute_directory_metadata'.
620 struct ComputeDirectoryMetadataContext
623 * Where to store the extracted keywords.
625 struct GNUNET_FS_Uri *ksk;
628 * Where to store the extracted meta data.
630 struct GNUNET_CONTAINER_MetaData *meta;
633 * Threshold to apply for adding meta data.
635 unsigned int threshold;
640 * Add metadata that occurs in more than the threshold entries of the
641 * directory to the directory itself. For example, if most files in a
642 * directory are of the same mime-type, the directory should have that
643 * mime-type as a keyword.
645 * @param cls the 'struct ComputeDirectoryMetadataContext'
647 * @param value the 'struct MetaValueInformation' (to be freed as well)
651 compute_directory_metadata (void *cls, const GNUNET_HashCode * key, void *value)
653 struct ComputeDirectoryMetadataContext *cdmc = cls;
654 struct MetaValueInformation *mvi = value;
656 if (mvi->frequency > cdmc->threshold)
658 if (mvi->type != EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
659 (void) GNUNET_CONTAINER_meta_data_insert (cdmc->meta, "<children>",
660 mvi->type, mvi->format,
661 mvi->mime_type, mvi->data,
663 if ((mvi->format == EXTRACTOR_METAFORMAT_UTF8) ||
664 (mvi->format == EXTRACTOR_METAFORMAT_C_STRING))
665 GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, mvi->data, GNUNET_NO);
673 * Add keywords that occur in more than the threshold entries of the
674 * directory to the directory itself.
676 * @param cls the 'struct ComputeDirectoryMetadataContext'
678 * @param value the 'struct Keywordnformation' (to be freed as well)
682 compute_directory_keywords (void *cls, const GNUNET_HashCode * key, void *value)
684 struct ComputeDirectoryMetadataContext *cdmc = cls;
685 struct KeywordInformation *ki = value;
687 if (ki->frequency > cdmc->threshold)
688 (void) GNUNET_FS_uri_ksk_add_keyword (cdmc->ksk, ki->keyword, GNUNET_NO);
695 * Create a publish-structure from an existing file hierarchy, inferring
696 * and organizing keywords and metadata as much as possible. This
697 * function primarily performs the recursive build and re-organizes
698 * keywords and metadata; for automatically getting metadata
699 * extraction, scanning of directories and creation of the respective
700 * GNUNET_FS_FileInformation entries the default scanner should be
701 * passed (GNUNET_FS_directory_scanner_default). This is strictly a
702 * convenience function.
704 * @param h handle to the file sharing subsystem
705 * @param client_info initial value for the client-info value for this entry
706 * @param filename name of the top-level file or directory
707 * @param scanner function used to get a list of files in a directory
708 * @param scanner_cls closure for scanner
709 * @param do_index should files in the hierarchy be indexed?
710 * @param bo block options
711 * @param emsg where to store an error message
712 * @return publish structure entry for the directory, NULL on error
714 struct GNUNET_FS_FileInformation *
715 GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
717 const char *filename,
718 GNUNET_FS_DirectoryScanner
719 scanner, void *scanner_cls,
722 GNUNET_FS_BlockOptions *bo,
725 struct GNUNET_FS_FileInformation *ret;
726 struct ComputeDirectoryMetadataContext cdmc;
727 struct EntryProcCls dc;
731 struct GNUNET_FS_FileInformation *epos;
737 dc.metamap = GNUNET_CONTAINER_multihashmap_create (64);
738 dc.keywordmap = GNUNET_CONTAINER_multihashmap_create (64);
739 /* update children to point to directory and generate statistics
740 * on all meta data in children */
741 scanner (scanner_cls, h, filename, do_index, bo, &dirproc_add, &dc, emsg);
742 cdmc.meta = GNUNET_CONTAINER_meta_data_create ();
743 cdmc.ksk = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
744 cdmc.ksk->type = ksk;
745 cdmc.threshold = 1 + dc.count / 2; /* 50% threshold for now */
746 GNUNET_FS_meta_data_make_directory (cdmc.meta);
747 GNUNET_CONTAINER_multihashmap_iterate (dc.metamap,
748 &compute_directory_metadata, &cdmc);
749 GNUNET_CONTAINER_multihashmap_iterate (dc.keywordmap,
750 &compute_directory_keywords, &cdmc);
751 GNUNET_CONTAINER_multihashmap_destroy (dc.metamap);
752 GNUNET_CONTAINER_multihashmap_destroy (dc.keywordmap);
754 /* remove keywords in children that are already in the
756 for (epos = dc.entries; NULL != epos; epos = epos->next)
758 for (i = 0; i < cdmc.ksk->data.ksk.keywordCount; i++)
760 kw = cdmc.ksk->data.ksk.keywords[i];
761 GNUNET_FS_uri_ksk_remove_keyword (epos->keywords, &kw[1]);
764 GNUNET_FS_uri_ksk_add_keyword (cdmc.ksk, GNUNET_FS_DIRECTORY_MIME, GNUNET_NO);
766 GNUNET_FS_file_information_create_empty_directory (h, client_info, cdmc.ksk,
768 GNUNET_CONTAINER_meta_data_destroy (cdmc.meta);
769 GNUNET_FS_uri_destroy (cdmc.ksk);
770 ret->data.dir.entries = dc.entries;
771 while (dc.entries != NULL)
773 dc.entries->dir = ret;
774 dc.entries = dc.entries->next;
777 while ((NULL != (ss = strstr (fn, DIR_SEPARATOR_STR))) && (strlen (ss) > 1))
779 GNUNET_asprintf (&dn, "%s/", fn);
781 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
782 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
783 EXTRACTOR_METAFORMAT_C_STRING,
784 "text/plain", dn, strlen (dn) + 1);
786 GNUNET_CONTAINER_meta_data_insert (ret->meta, "<gnunet>",
787 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
788 EXTRACTOR_METAFORMAT_UTF8,
789 "text/plain", dn, strlen (dn) + 1);
792 ret->filename = GNUNET_strdup (filename);
798 * Test if a given entry represents a directory.
800 * @param ent check if this FI represents a directory
801 * @return GNUNET_YES if so, GNUNET_NO if not
804 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
807 return ent->is_directory;
812 * Create an entry for an empty directory in a publish-structure.
813 * This function should be used by applications for which the
814 * use of "GNUNET_FS_file_information_create_from_directory"
815 * is not appropriate.
817 * @param h handle to the file sharing subsystem
818 * @param client_info initial value for the client-info value for this entry
819 * @param meta metadata for the directory
820 * @param keywords under which keywords should this directory be available
821 * directly; can be NULL
822 * @param bo block options
823 * @return publish structure entry for the directory , NULL on error
825 struct GNUNET_FS_FileInformation *
826 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
828 const struct GNUNET_FS_Uri
831 GNUNET_CONTAINER_MetaData
834 GNUNET_FS_BlockOptions *bo)
836 struct GNUNET_FS_FileInformation *ret;
838 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_FileInformation));
840 ret->client_info = client_info;
841 ret->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
842 ret->keywords = GNUNET_FS_uri_dup (keywords);
844 ret->is_directory = GNUNET_YES;
850 * Add an entry to a directory in a publish-structure. Clients
851 * should never modify publish structures that were passed to
852 * "GNUNET_FS_publish_start" already.
854 * @param dir the directory
855 * @param ent the entry to add; the entry must not have been
856 * added to any other directory at this point and
857 * must not include "dir" in its structure
858 * @return GNUNET_OK on success, GNUNET_SYSERR on error
861 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
862 struct GNUNET_FS_FileInformation *ent)
864 if ((ent->dir != NULL) || (ent->next != NULL) || (!dir->is_directory))
867 return GNUNET_SYSERR;
870 ent->next = dir->data.dir.entries;
871 dir->data.dir.entries = ent;
872 dir->data.dir.dir_size = 0;
878 * Inspect a file or directory in a publish-structure. Clients
879 * should never modify publish structures that were passed to
880 * "GNUNET_FS_publish_start" already. When called on a directory,
881 * this function will FIRST call "proc" with information about
882 * the directory itself and then for each of the files in the
883 * directory (but not for files in subdirectories). When called
884 * on a file, "proc" will be called exactly once (with information
885 * about the specific file).
887 * @param dir the directory
888 * @param proc function to call on each entry
889 * @param proc_cls closure for proc
892 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
893 GNUNET_FS_FileInformationProcessor proc,
896 struct GNUNET_FS_FileInformation *pos;
902 (dir->is_directory) ? dir->data.dir.dir_size : dir->data.
903 file.file_size, dir->meta, &dir->keywords, &dir->bo,
904 (dir->is_directory) ? &no : &dir->data.file.do_index,
907 if (!dir->is_directory)
909 pos = dir->data.dir.entries;
915 (pos->is_directory) ? pos->data.dir.dir_size : pos->data.
916 file.file_size, pos->meta, &pos->keywords, &pos->bo,
917 (dir->is_directory) ? &no : &dir->data.file.do_index,
926 * Destroy publish-structure. Clients should never destroy publish
927 * structures that were passed to "GNUNET_FS_publish_start" already.
929 * @param fi structure to destroy
930 * @param cleaner function to call on each entry in the structure
931 * (useful to clean up client_info); can be NULL; return
933 * @param cleaner_cls closure for cleaner
936 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
937 GNUNET_FS_FileInformationProcessor cleaner,
940 struct GNUNET_FS_FileInformation *pos;
944 if (fi->is_directory)
946 /* clean up directory */
947 while (NULL != (pos = fi->data.dir.entries))
949 fi->data.dir.entries = pos->next;
950 GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls);
952 /* clean up client-info */
954 cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords,
955 &fi->bo, &no, &fi->client_info);
956 GNUNET_free_non_null (fi->data.dir.dir_data);
960 /* call clean-up function of the reader */
961 if (fi->data.file.reader != NULL)
962 fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL);
963 /* clean up client-info */
965 cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta,
966 &fi->keywords, &fi->bo, &fi->data.file.do_index,
969 GNUNET_free_non_null (fi->filename);
970 GNUNET_free_non_null (fi->emsg);
971 GNUNET_free_non_null (fi->chk_uri);
972 /* clean up serialization */
973 if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization)))
974 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
976 if (NULL != fi->keywords)
977 GNUNET_FS_uri_destroy (fi->keywords);
978 if (NULL != fi->meta)
979 GNUNET_CONTAINER_meta_data_destroy (fi->meta);
980 GNUNET_free_non_null (fi->serialization);
983 GNUNET_FS_tree_encoder_finish (fi->te, NULL, NULL);
990 /* end of fs_file_information.c */