more work on bugs and testing of fs service
[oweals/gnunet.git] / src / include / gnunet_fs_service.h
1 /*
2      This file is part of GNUnet
3      (C) 2004, 2005, 2006, 2007, 2008, 2009 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 2, 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  * @file include/gnunet_fs_service.h
22  * @brief API for file-sharing via GNUnet 
23  * @author Christian Grothoff
24  *
25  * TODO:
26  * - extend API with support for publish simulation (-s)
27  *   and URI-argument binding to keyword/namespace (-u)
28  */
29 #ifndef GNUNET_FS_LIB_H
30 #define GNUNET_FS_LIB_H
31
32 #include "gnunet_util_lib.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 /**
43  * Version number of the implementation.
44  * History:
45  *
46  * 1.x.x: initial version with triple GNUNET_hash and merkle tree
47  * 2.x.x: root node with mime-type, filename and version number
48  * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
49  * 2.2.x: with directories
50  * 3.0.x: with namespaces
51  * 3.1.x: with namespace meta-data
52  * 3.2.x: with collections
53  * 4.0.x: with expiration, variable meta-data, kblocks
54  * 4.1.x: with new error and configuration handling
55  * 5.0.x: with location URIs
56  * 6.0.0: with support for OR in KSKs
57  * 6.1.x: with simplified namespace support
58  * 9.0.0: CPS-style integrated API
59  */
60 #define GNUNET_FS_VERSION 0x00090000
61
62
63 /* ******************** URI API *********************** */
64
65 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
66 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
67 #define GNUNET_FS_URI_SKS_INFIX "sks/"
68 #define GNUNET_FS_URI_CHK_INFIX "chk/"
69 #define GNUNET_FS_URI_LOC_INFIX "loc/"
70
71
72 /**
73  * A Universal Resource Identifier (URI), opaque.
74  */
75 struct GNUNET_FS_Uri;
76
77
78 /**
79  * Iterator over keywords
80  *
81  * @param cls closure
82  * @param keyword the keyword
83  * @param is_mandatory is the keyword mandatory (in a search)
84  * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
85  */
86 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
87                                           const char *keyword,
88                                           int is_mandatory);
89
90 /**
91  * Get a unique key from a URI.  This is for putting URIs
92  * into HashMaps.  The key may change between FS implementations.
93  *
94  * @param uri uri to convert to a unique key
95  * @param key wherer to store the unique key
96  */
97 void 
98 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
99                       GNUNET_HashCode * key);
100
101 /**
102  * Convert a URI to a UTF-8 String.
103  *
104  * @param uri uri to convert to a string
105  * @return the UTF-8 string
106  */
107 char *
108 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
109
110 /**
111  * Convert keyword URI to a human readable format
112  * (i.e. the search query that was used in the first place)
113  *
114  * @param uri ksk uri to convert to a string 
115  * @return string with the keywords
116  */
117 char *
118 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
119
120
121 /**
122  * Convert a UTF-8 String to a URI.
123  *
124  * @param uri string to parse
125  * @param emsg where to store the parser error message (if any)
126  * @return NULL on error
127  */
128 struct GNUNET_FS_Uri *
129 GNUNET_FS_uri_parse (const char *uri,
130                      char **emsg);
131
132 /**
133  * Free URI.
134  *
135  * @param uri uri to free
136  */
137 void 
138 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
139
140
141 /**
142  * How many keywords are ANDed in this keyword URI?
143  *
144  * @param uri ksk uri to get the number of keywords from
145  * @return 0 if this is not a keyword URI
146  */
147 unsigned int 
148 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
149
150
151 /**
152  * Iterate over all keywords in this keyword URI.
153  *
154  * @param uri ksk uri to get the keywords from
155  * @param iterator function to call on each keyword
156  * @param iterator_cls closure for iterator
157  * @return -1 if this is not a keyword URI, otherwise number of
158  *   keywords iterated over until iterator aborted
159  */
160 int 
161 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
162                                 GNUNET_FS_KeywordIterator iterator, 
163                                 void *iterator_cls);
164
165
166 /**
167  * Obtain the identity of the peer offering the data
168  *
169  * @param uri the location URI to inspect
170  * @param peer where to store the identify of the peer (presumably) offering the content
171  * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
172  */
173 int
174 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
175                                      struct GNUNET_PeerIdentity * peer);
176
177
178 /**
179  * Obtain the URI of the content itself.
180  *
181  * @param uri location URI to get the content URI from
182  * @return NULL if argument is not a location URI
183  */
184 struct GNUNET_FS_Uri *
185 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
186
187
188 /**
189  * Obtain the expiration of the LOC URI.
190  *
191  * @param uri location URI to get the expiration from
192  * @return expiration time of the URI
193  */
194 struct GNUNET_TIME_Absolute
195 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
196
197
198 /**
199  * Construct a location URI (this peer will be used for the location).
200  *
201  * @param baseUri content offered by the sender
202  * @param cfg configuration information (used to find our hostkey)
203  * @param expiration_time how long will the content be offered?
204  * @return the location URI, NULL on error
205  */
206 struct GNUNET_FS_Uri *
207 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
208                           struct GNUNET_CONFIGURATION_Handle *cfg,
209                           struct GNUNET_TIME_Absolute expiration_time);
210
211
212 /**
213  * Canonicalize keyword URI.  Performs operations such
214  * as decapitalization and removal of certain characters.
215  * (useful for search).
216  *
217  * @param uri the URI to canonicalize 
218  * @return canonicalized version of the URI, NULL on error
219  */
220 struct GNUNET_FS_Uri *
221 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
222
223
224 /**
225  * Merge the sets of keywords from two KSK URIs.
226  * (useful for merging the canonicalized keywords with
227  * the original keywords for sharing).
228  *
229  * @param u1 first uri
230  * @param u2 second uri
231  * @return merged URI, NULL on error
232  */
233 struct GNUNET_FS_Uri *
234 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
235                          const struct GNUNET_FS_Uri *u2);
236
237
238 /**
239  * Duplicate URI.
240  *
241  * @param uri the URI to duplicate
242  * @return copy of the URI
243  */
244 struct GNUNET_FS_Uri *
245 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
246
247
248 /**
249  * Create an FS URI from a single user-supplied string of keywords.
250  * The string is broken up at spaces into individual keywords.
251  * Keywords that start with "+" are mandatory.  Double-quotes can
252  * be used to prevent breaking up strings at spaces (and also
253  * to specify non-mandatory keywords starting with "+").
254  *
255  * Keywords must contain a balanced number of double quotes and
256  * double quotes can not be used in the actual keywords (for
257  * example, the string '""foo bar""' will be turned into two
258  * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
259  *
260  * @param keywords the keyword string
261  * @param emsg where to store an error message
262  * @return an FS URI for the given keywords, NULL
263  *  if keywords is not legal (i.e. empty).
264  */
265 struct GNUNET_FS_Uri *
266 GNUNET_FS_uri_ksk_create (const char *keywords,
267                           char **emsg);
268
269
270 /**
271  * Create an FS URI from a user-supplied command line of keywords.
272  * Arguments should start with "+" to indicate mandatory
273  * keywords.
274  *
275  * @param argc number of keywords
276  * @param argv keywords (double quotes are not required for
277  *             keywords containing spaces; however, double
278  *             quotes are required for keywords starting with
279  *             "+"); there is no mechanism for having double
280  *             quotes in the actual keywords (if the user
281  *             did specifically specify double quotes, the
282  *             caller should convert each double quote
283  *             into two single quotes).
284  * @return an FS URI for the given keywords, NULL
285  *  if keywords is not legal (i.e. empty).
286  */
287 struct GNUNET_FS_Uri *
288 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
289                                     const char **argv);
290
291
292 /**
293  * Test if two URIs are equal.
294  *
295  * @param u1 one of the URIs
296  * @param u2 the other URI
297  * @return GNUNET_YES if the URIs are equal
298  */
299 int 
300 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
301                           const struct GNUNET_FS_Uri *u2);
302
303
304 /**
305  * Is this a namespace URI?
306  *
307  * @param uri the uri to check
308  * @return GNUNET_YES if this is an SKS uri
309  */
310 int
311 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
312
313
314 /**
315  * Get the ID of a namespace from the given
316  * namespace URI.
317  *
318  * @param uri the uri to get the namespace ID from
319  * @param nsid where to store the ID of the namespace
320  * @return GNUNET_OK on success
321  */
322 int 
323 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
324                                  GNUNET_HashCode * nsid);
325
326
327 /**
328  * Get the content identifier of an SKS URI.
329  *
330  * @param uri the sks uri
331  * @return NULL on error (not a valid SKS URI)
332  */
333 char *
334 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
335
336
337 /**
338  * Convert namespace URI to a human readable format
339  * (using the namespace description, if available).
340  *
341  * @param cfg configuration to use
342  * @param uri SKS uri to convert
343  * @return NULL on error (not an SKS URI)
344  */
345 char *
346 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
347                                    const struct GNUNET_FS_Uri *uri);
348
349
350 /**
351  * Is this a keyword URI?
352  *
353  * @param uri the uri
354  * @return GNUNET_YES if this is a KSK uri
355  */
356 int 
357 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
358
359
360 /**
361  * Is this a file (or directory) URI?
362  *
363  * @param uri the uri to check
364  * @return GNUNET_YES if this is a CHK uri
365  */
366 int 
367 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
368
369
370 /**
371  * What is the size of the file that this URI
372  * refers to?
373  *
374  * @param uri the CHK (or LOC) URI to inspect
375  * @return size of the file as specified in the CHK URI
376  */
377 uint64_t 
378 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
379
380
381 /**
382  * Is this a location URI?
383  *
384  * @param uri the uri to check
385  * @return GNUNET_YES if this is a LOC uri
386  */
387 int 
388 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
389
390
391 /**
392  * Construct a keyword-URI from meta-data (take all entries
393  * in the meta-data and construct one large keyword URI
394  * that lists all keywords that can be found in the meta-data).
395  *
396  * @param md metadata to use
397  * @return NULL on error, otherwise a KSK URI
398  */
399 struct GNUNET_FS_Uri *
400 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
401
402
403 /* ******************** command-line option parsing API *********************** */
404
405 /**
406  * Command-line option parser function that allows the user
407  * to specify one or more '-k' options with keywords.  Each
408  * specified keyword will be added to the URI.  A pointer to
409  * the URI must be passed as the "scls" argument.
410  *
411  * @param ctx command line processor context
412  * @param scls must be of type "struct GNUNET_FS_Uri **"
413  * @param option name of the option (typically 'k')
414  * @param value command line argument given
415  * @return GNUNET_OK on success
416  */
417 int
418 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 
419                                          void *scls,
420                                          const char *option,
421                                          const char *value);
422
423
424 /**
425  * Command-line option parser function that allows the user to specify
426  * one or more '-m' options with metadata.  Each specified entry of
427  * the form "type=value" will be added to the metadata.  A pointer to
428  * the metadata must be passed as the "scls" argument.
429  *
430  * @param ctx command line processor context
431  * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
432  * @param option name of the option (typically 'k')
433  * @param value command line argument given
434  * @return GNUNET_OK on success
435  */
436 int
437 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 
438                                          void *scls,
439                                          const char *option,
440                                          const char *value);
441
442
443
444 /* ************************* sharing API ***************** */
445
446
447 /**
448  * Possible status codes used in the callback for the 
449  * various file-sharing operations.  On each file (or search),
450  * the callback is guaranteed to be called once with "START"
451  * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
452  * are optional and depend on the circumstances; parent operations
453  * will be STARTED before child-operations and STOPPED after
454  * their respective child-operations.  START and STOP signals 
455  * are typically generated either due to explicit client requests
456  * or because of suspend/resume operations.
457  */
458 enum GNUNET_FS_Status
459 {
460   /**
461    * Notification that we have started to publish a file structure.
462    */
463   GNUNET_FS_STATUS_PUBLISH_START,
464
465   /**
466    * Notification that we have resumed sharing a file structure.
467    */
468   GNUNET_FS_STATUS_PUBLISH_RESUME,
469
470   /**
471    * Notification that we have suspended sharing a file structure.
472    */
473   GNUNET_FS_STATUS_PUBLISH_SUSPEND,
474
475   /**
476    * Notification that we are making progress sharing a file structure.
477    */
478   GNUNET_FS_STATUS_PUBLISH_PROGRESS,
479
480   /**
481    * Notification that an error was encountered  sharing a file structure.
482    * The application will continue to receive resume/suspend events for
483    * this structure until "GNUNET_FS_publish_stop" is called.
484    */
485   GNUNET_FS_STATUS_PUBLISH_ERROR,
486
487   /**
488    * Notification that we completed sharing a file structure.
489    * The application will continue to receive resume/suspend events for
490    * this structure until "GNUNET_FS_publish_stop" is called.
491    */
492   GNUNET_FS_STATUS_PUBLISH_COMPLETED,
493
494   /**
495    * Notification that we have stopped
496    * the process of uploading a file structure; no
497    * futher events will be generated for this action.
498    */
499   GNUNET_FS_STATUS_PUBLISH_STOPPED,
500
501   /**
502    * Notification that we have started this download.
503    */
504   GNUNET_FS_STATUS_DOWNLOAD_START,
505
506   /**
507    * Notification that this download is being resumed.
508    */
509   GNUNET_FS_STATUS_DOWNLOAD_RESUME,
510
511   /**
512    * Notification that this download was suspended.
513    */
514   GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
515
516   /**
517    * Notification about progress with this download.
518    */
519   GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
520
521   /**
522    * Notification that this download encountered an error.
523    */
524   GNUNET_FS_STATUS_DOWNLOAD_ERROR,
525
526   /**
527    * Notification that this download completed.  Note that for
528    * directories, completion does not imply completion of all files in
529    * the directory.
530    */
531   GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
532
533   /**
534    * Notification that this download was stopped
535    * (final event with respect to this action).
536    */
537   GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
538
539   /**
540    * First event generated when a client requests 
541    * a search to begin or when a namespace result
542    * automatically triggers the search for updates.
543    */
544   GNUNET_FS_STATUS_SEARCH_START,
545
546   /**
547    * Last event when a search is being resumed;
548    * note that "GNUNET_FS_SEARCH_START" will not
549    * be generated in this case.
550    */
551   GNUNET_FS_STATUS_SEARCH_RESUME,
552
553   /**
554    * Event generated for each search result
555    * when the respective search is resumed.
556    */
557   GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
558
559   /**
560    * Last event when a search is being suspended;
561    * note that "GNUNET_FS_SEARCH_STOPPED" will not
562    * be generated in this case.
563    */
564   GNUNET_FS_STATUS_SEARCH_SUSPEND,
565   
566   /**
567    * Event generated for each search result
568    * when the respective search is suspended.
569    */
570   GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
571
572   /**
573    * This search has yielded a result.
574    */
575   GNUNET_FS_STATUS_SEARCH_RESULT,
576
577   /**
578    * We have discovered a new namespace.
579    */
580   GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
581
582   /**
583    * We have additional data about the quality
584    * or availability of a search result.
585    */
586   GNUNET_FS_STATUS_SEARCH_UPDATE,
587
588   /**
589    * Signals a problem with this search.
590    */
591   GNUNET_FS_STATUS_SEARCH_ERROR,
592
593   /**
594    * Signals that this search was paused.
595    */
596   GNUNET_FS_STATUS_SEARCH_PAUSED,
597
598   /**
599    * Signals that this search was continued (unpaused).
600    */
601   GNUNET_FS_STATUS_SEARCH_CONTINUED,
602
603   /**
604    * Event generated for each search result
605    * when the respective search is stopped.
606    */
607   GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
608
609   /**
610    * Last message from a search; this signals
611    * that there will be no further events associated
612    * with this search.
613    */
614   GNUNET_FS_STATUS_SEARCH_STOPPED,
615
616   /**
617    * Notification that we started to unindex a file.
618    */ 
619   GNUNET_FS_STATUS_UNINDEX_START,
620
621   /**
622    * Notification that we resumed unindexing of a file.
623    */
624   GNUNET_FS_STATUS_UNINDEX_RESUME,
625
626   /**
627    * Notification that we suspended unindexing a file.
628    */
629   GNUNET_FS_STATUS_UNINDEX_SUSPEND,
630
631   /**
632    * Notification that we made progress unindexing a file.
633    */
634   GNUNET_FS_STATUS_UNINDEX_PROGRESS,
635
636   /**
637    * Notification that we encountered an error unindexing
638    * a file.
639    */
640   GNUNET_FS_STATUS_UNINDEX_ERROR,
641
642   /**
643    * Notification that the unindexing of this file
644    * was completed.
645    */
646   GNUNET_FS_STATUS_UNINDEX_COMPLETED,
647
648   /**
649    * Notification that the unindexing of this file
650    * was stopped (final event for this action).
651    */
652   GNUNET_FS_STATUS_UNINDEX_STOPPED
653
654 };
655
656
657 /**
658  * Handle to one of our namespaces.
659  */
660 struct GNUNET_FS_Namespace;
661
662
663 /**
664  * Handle for controlling an upload.
665  */
666 struct GNUNET_FS_PublishContext;
667
668
669 /**
670  * Handle for controlling an unindexing operation.
671  */
672 struct GNUNET_FS_UnindexContext;
673
674
675 /**
676  * Handle for controlling a search.
677  */
678 struct GNUNET_FS_SearchContext;
679
680
681 /**
682  * Context for controlling a download.
683  */
684 struct GNUNET_FS_DownloadContext;
685
686
687 /**
688  * Handle for detail information about a file that is being publishd.
689  * Specifies metadata, keywords, how to get the contents of the file
690  * (i.e. data-buffer in memory, filename on disk) and other options.
691  */
692 struct GNUNET_FS_FileInformation;
693
694
695 /**
696  * Argument given to the progress callback with
697  * information about what is going on.
698  */
699 struct GNUNET_FS_ProgressInfo
700 {  
701
702   /**
703    * Values that depend on the event type.
704    */
705   union {
706     
707     /**
708      * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
709      */
710     struct {
711
712       /**
713        * Context for controlling the upload.
714        */
715       struct GNUNET_FS_PublishContext *sc;
716
717       /**
718        * Information about the file that is being publishd.
719        */
720       const struct GNUNET_FS_FileInformation *fi;
721
722       /**
723        * Client context pointer (set the last time
724        * by the client for this operation; initially
725        * NULL on START/RESUME events).
726        */
727       void *cctx;
728
729       /**
730        * Client context pointer for the parent operation
731        * (if this is a file in a directory or a subdirectory).
732        */
733       void *pctx;
734
735       /**
736        * Name of the file being published; can be NULL.
737        */
738       const char *filename;
739       
740       /**
741        * How large is the file overall?  For directories,
742        * this is only the size of the directory itself,
743        * not of the other files contained within the 
744        * directory.
745        */
746       uint64_t size;
747
748       /**
749        * At what time do we expect to finish the upload?
750        * (will be a value in the past for completed
751        * uploads).
752        */ 
753       struct GNUNET_TIME_Relative eta;
754
755       /**
756        * How long has this upload been actively running
757        * (excludes times where the upload was suspended).
758        */
759       struct GNUNET_TIME_Relative duration;
760
761       /**
762        * How many bytes have we completed?
763        */
764       uint64_t completed;
765
766       /**
767        * What anonymity level is used for this upload?
768        */
769       uint32_t anonymity;
770
771       /**
772        * Additional values for specific events.
773        */
774       union {
775
776         /**
777          * These values are only valid for
778          * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
779          */
780         struct {
781           
782           /**
783            * Data block we just published.
784            */
785           const void *data;
786           
787           /**
788            * At what offset in the file is "data"?
789            */
790           uint64_t offset;
791           
792           /**
793            * Length of the data block.
794            */
795           uint64_t data_len;
796
797           /**
798            * Depth of the given block in the tree; 
799            * 0 would be the highest level (the first
800            * call is guaranteed to be for the lowest
801            * level).
802            */
803           unsigned int depth;
804
805         } progress;
806
807         /**
808          * These values are only valid for
809          * GNUNET_FS_STATUS_PUBLISH_RESUME events.
810          */
811         struct {
812           
813           /**
814            * Error message, NULL if no error was encountered so far.
815            */
816           const char *message;
817           
818           /**
819            * URI of the file (if the download had been completed)
820            */
821           const struct GNUNET_FS_Uri *chk_uri;
822
823         } resume;
824
825         /**
826          * These values are only valid for
827          * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
828          */
829         struct {
830           
831           /**
832            * URI of the file.
833            */
834           const struct GNUNET_FS_Uri *chk_uri;
835
836         } completed;
837
838         /**
839          * These values are only valid for
840          * GNUNET_FS_STATUS_PUBLISH_ERROR events.
841          */
842         struct {
843           
844           /**
845            * Error message, never NULL.
846            */
847           const char *message;
848
849         } error;
850
851       } specifics;
852
853     } publish;
854
855     
856     /**
857      * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
858      */
859     struct {
860
861       /**
862        * Context for controlling the download.
863        */
864       struct GNUNET_FS_DownloadContext *dc;
865
866       /**
867        * Client context pointer (set the last time
868        * by the client for this operation; initially
869        * NULL on START/RESUME events).
870        */
871       void *cctx;
872
873       /**
874        * Client context pointer for the parent operation
875        * (if this is a file in a directory or a subdirectory).
876        */
877       void *pctx;
878       
879       /**
880        * URI used for this download.
881        */
882       const struct GNUNET_FS_Uri *uri;
883
884       /**
885        * Name of the file that we are downloading.
886        */
887       const char *filename;
888       
889       /**
890        * How large is the download overall?  This
891        * is NOT necessarily the size from the
892        * URI since we may be doing a partial download.
893        */
894       uint64_t size;
895
896       /**
897        * At what time do we expect to finish the download?
898        * (will be a value in the past for completed
899        * uploads).
900        */ 
901       struct GNUNET_TIME_Relative eta;
902
903       /**
904        * How long has this download been active?
905        */ 
906       struct GNUNET_TIME_Relative duration;
907
908       /**
909        * How many bytes have we completed?
910        */
911       uint64_t completed;
912
913       /**
914        * What anonymity level is used for this download?
915        */
916       uint32_t anonymity;
917
918       /**
919        * Additional values for specific events.
920        */
921       union {
922         
923         /**
924          * These values are only valid for
925          * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
926          */
927         struct {
928   
929           /**
930            * Data block we just obtained.
931            */
932           const void *data;
933           
934           /**
935            * At what offset in the file is "data"?
936            */
937           uint64_t offset;
938           
939           /**
940            * Length of the data block.
941            */
942           uint64_t data_len;
943
944           /**
945            * Depth of the given block in the tree; 
946            * 0 would be the highest level (the first
947            * call is guaranteed to be for the lowest
948            * level).
949            */
950           unsigned int depth;
951
952         } progress;
953
954         /**
955          * These values are only valid for
956          * GNUNET_FS_STATUS_DOWNLOAD_START events.
957          */
958         struct {
959
960           /**
961            * Known metadata for the download.
962            */
963           const struct GNUNET_CONTAINER_MetaData *meta;
964           
965         } start;
966
967         /**
968          * These values are only valid for
969          * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
970          */
971         struct {
972
973           /**
974            * Known metadata for the download.
975            */
976           const struct GNUNET_CONTAINER_MetaData *meta;
977
978           /**
979            * Error message, NULL if we have not encountered any error yet.
980            */
981           const char *message;
982
983         } resume;
984
985         /**
986          * These values are only valid for
987          * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
988          */
989         struct {
990
991           /**
992            * Error message.
993            */
994           const char *message;
995
996         } error;
997
998       } specifics;
999
1000     } download;
1001
1002     /**
1003      * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1004      */
1005     struct {
1006
1007       /**
1008        * Context for controlling the search, NULL for
1009        * searches that were not explicitly triggered
1010        * by the client (i.e., searches for updates in
1011        * namespaces).
1012        */
1013       struct GNUNET_FS_SearchContext *sc;
1014
1015       /**
1016        * Client context pointer (set the last time by the client for
1017        * this operation; initially NULL on START/RESUME events).  Note
1018        * that this value can only be set on START/RESUME; returning
1019        * non-NULL on RESULT/RESUME_RESULT will actually update the
1020        * private context for "UPDATE" events.
1021        */
1022       void *cctx;
1023
1024       /**
1025        * Client parent-context pointer; NULL for top-level searches,
1026        * non-NULL for automatically triggered searches for updates in
1027        * namespaces.
1028        */
1029       void *pctx;
1030
1031       /**
1032        * What query is used for this search
1033        * (list of keywords or SKS identifier).
1034        */
1035       const struct GNUNET_FS_Uri *query;
1036
1037       /**
1038        * How long has this search been actively running
1039        * (excludes times where the search was paused or
1040        * suspended).
1041        */
1042       struct GNUNET_TIME_Relative duration;
1043
1044       /**
1045        * What anonymity level is used for this search?
1046        */
1047       uint32_t anonymity;
1048
1049       /**
1050        * Additional values for specific events.
1051        */
1052       union {
1053         
1054         /**
1055          * These values are only valid for
1056          * GNUNET_FS_STATUS_SEARCH_RESULT events.
1057          */
1058         struct {
1059           
1060           /**
1061            * Metadata for the search result.
1062            */
1063           const struct GNUNET_CONTAINER_MetaData *meta;
1064
1065           /**
1066            * URI for the search result.
1067            */
1068           const struct GNUNET_FS_Uri *uri;
1069
1070         } result;
1071         
1072         /**
1073          * These values are only valid for
1074          * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1075          */
1076         struct {
1077           
1078           /**
1079            * Metadata for the search result.
1080            */
1081           const struct GNUNET_CONTAINER_MetaData *meta;
1082
1083           /**
1084            * URI for the search result.
1085            */
1086           const struct GNUNET_FS_Uri *uri;
1087
1088           /**
1089            * Current availability rank (negative:
1090            * unavailable, positive: available)
1091            */
1092           int32_t availability_rank;
1093  
1094           /**
1095            * On how many total queries is the given
1096            * availability_rank based?
1097            */
1098           uint32_t availabiliy_certainty;
1099
1100           /**
1101            * Updated applicability rank (the larger,
1102            * the better the result fits the search
1103            * criteria).
1104            */
1105           uint32_t applicabiliy_rank;     
1106           
1107         } resume_result;
1108         
1109         /**
1110          * These values are only valid for
1111          * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1112          */
1113         struct {
1114
1115           /**
1116            * Private context set for for this result
1117            * during the "RESULT" event.
1118            */
1119           void *cctx;
1120           
1121           /**
1122            * Metadata for the search result.
1123            */
1124           const struct GNUNET_CONTAINER_MetaData *meta;
1125
1126           /**
1127            * URI for the search result.
1128            */
1129           const struct GNUNET_FS_Uri *uri;
1130
1131           /**
1132            * Current availability rank (negative:
1133            * unavailable, positive: available)
1134            */
1135           int32_t availability_rank;
1136  
1137           /**
1138            * On how many total queries is the given
1139            * availability_rank based?
1140            */
1141           uint32_t availability_certainty;
1142
1143           /**
1144            * Updated applicability rank (the larger,
1145            * the better the result fits the search
1146            * criteria).
1147            */
1148           uint32_t applicability_rank;
1149
1150         } update;
1151         
1152         /**
1153          * These values are only valid for
1154          * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1155          * These events are automatically triggered for
1156          * each search result before the 
1157          * GNUNET_FS_STATUS_SEARCH_SUSPEND event.  This
1158          * happens primarily to give the client a chance
1159          * to clean up the "cctx" (if needed).
1160          */
1161         struct {
1162
1163           /**
1164            * Private context set for for this result
1165            * during the "RESULT" event.
1166            */
1167           void *cctx;
1168           
1169           /**
1170            * Metadata for the search result.
1171            */
1172           const struct GNUNET_CONTAINER_MetaData *meta;
1173
1174           /**
1175            * URI for the search result.
1176            */
1177           const struct GNUNET_FS_Uri *uri;
1178
1179         } result_suspend;
1180         
1181         /**
1182          * These values are only valid for
1183          * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1184          * These events are automatically triggered for
1185          * each search result before the 
1186          * GNUNET_FS_STATUS_SEARCH_STOPPED event.  This
1187          * happens primarily to give the client a chance
1188          * to clean up the "cctx" (if needed).
1189          */
1190         struct {
1191
1192           /**
1193            * Private context set for for this result
1194            * during the "RESULT" event.
1195            */
1196           void *cctx;
1197           
1198           /**
1199            * Metadata for the search result.
1200            */
1201           const struct GNUNET_CONTAINER_MetaData *meta;
1202
1203           /**
1204            * URI for the search result.
1205            */
1206           const struct GNUNET_FS_Uri *uri;
1207
1208         } result_stopped;
1209
1210         /**
1211          * These values are only valid for
1212          * GNUNET_FS_STATUS_SEARCH_RESUME events.
1213          */
1214         struct {
1215
1216           /**
1217            * Error message, NULL if we have not encountered any error yet.
1218            */
1219           const char *message;
1220
1221           /**
1222            * Is this search currently paused?
1223            */
1224           int is_paused;
1225
1226         } resume;
1227
1228         /**
1229          * These values are only valid for
1230          * GNUNET_FS_STATUS_SEARCH_ERROR events.
1231          */
1232         struct {
1233
1234           /**
1235            * Error message.
1236            */
1237           const char *message;
1238
1239         } error;
1240     
1241         /**
1242          * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1243          */
1244         struct {
1245           
1246           /**
1247            * Handle to the namespace (NULL if it is not a local
1248            * namespace).
1249            */
1250           struct GNUNET_FS_Namespace *ns;
1251           
1252           /**
1253            * Short, human-readable name of the namespace.
1254            */
1255           const char *name;
1256           
1257           /**
1258            * Root identifier for the namespace, can be NULL.
1259            */
1260           const char *root;
1261           
1262           /**
1263            * Metadata for the namespace.
1264            */
1265           const struct GNUNET_CONTAINER_MetaData *meta;
1266           
1267           /**
1268            * Hash-identifier for the namespace.
1269            */
1270           GNUNET_HashCode id;      
1271           
1272         } namespace;
1273
1274       } specifics;
1275
1276     } search;
1277
1278     /**
1279      * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1280      */
1281     struct {
1282
1283       /**
1284        * Context for controlling the unindexing.
1285        */
1286       struct GNUNET_FS_UnindexContext *uc;
1287
1288       /**
1289        * Client context pointer (set the last time
1290        * by the client for this operation; initially
1291        * NULL on START/RESUME events).
1292        */
1293       void *cctx;
1294
1295       /**
1296        * Name of the file that is being unindexed.
1297        */
1298       const char *filename;
1299
1300       /**
1301        * How large is the file overall?
1302        */
1303       uint64_t size;
1304
1305       /**
1306        * At what time do we expect to finish unindexing?
1307        * (will be a value in the past for completed
1308        * unindexing opeations).
1309        */ 
1310       struct GNUNET_TIME_Relative eta;
1311
1312       /**
1313        * How long has this upload been actively running
1314        * (excludes times where the upload was suspended).
1315        */
1316       struct GNUNET_TIME_Relative duration;
1317
1318       /**
1319        * How many bytes have we completed?
1320        */
1321       uint64_t completed;
1322
1323       /**
1324        * Additional values for specific events.
1325        */
1326       union {
1327
1328         /**
1329          * These values are only valid for
1330          * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1331          */
1332         struct {
1333   
1334           /**
1335            * Data block we just unindexed.
1336            */
1337           const void *data;
1338           
1339           /**
1340            * At what offset in the file is "data"?
1341            */
1342           uint64_t offset;
1343           
1344           /**
1345            * Length of the data block.
1346            */
1347           uint64_t data_len;
1348
1349           /**
1350            * Depth of the given block in the tree; 
1351            * 0 would be the highest level (the first
1352            * call is guaranteed to be for the lowest
1353            * level).
1354            */
1355           unsigned int depth;
1356
1357         } progress;
1358
1359         /**
1360          * These values are only valid for
1361          * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1362          */
1363         struct {
1364
1365           /**
1366            * Error message, NULL if we have not encountered any error yet.
1367            */
1368           const char *message;
1369
1370         } resume;
1371
1372         /**
1373          * These values are only valid for
1374          * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1375          */
1376         struct {
1377
1378           /**
1379            * Error message.
1380            */
1381           const char *message;
1382
1383         } error;
1384
1385       } specifics;
1386
1387     } unindex;
1388
1389   } value;
1390
1391   /**
1392    * Specific status code (determines the event type).
1393    */  
1394   enum GNUNET_FS_Status status;
1395
1396 };
1397
1398
1399 /**
1400  * Notification of FS to a client about the progress of an 
1401  * operation.  Callbacks of this type will be used for uploads,
1402  * downloads and searches.  Some of the arguments depend a bit 
1403  * in their meaning on the context in which the callback is used.
1404  *
1405  * @param cls closure
1406  * @param info details about the event, specifying the event type
1407  *        and various bits about the event
1408  * @return client-context (for the next progress call
1409  *         for this operation; should be set to NULL for
1410  *         SUSPEND and STOPPED events).  The value returned
1411  *         will be passed to future callbacks in the respective
1412  *         field in the GNUNET_FS_ProgressInfo struct.
1413  */
1414 typedef void* (*GNUNET_FS_ProgressCallback)
1415   (void *cls,
1416    const struct GNUNET_FS_ProgressInfo *info);
1417
1418
1419 /**
1420  * General (global) option flags for file-sharing.
1421  */
1422 enum GNUNET_FS_Flags
1423   {
1424     /**
1425      * No special flags set.
1426      */
1427     GNUNET_FS_FLAGS_NONE = 0,
1428
1429     /**
1430      * Is persistence of operations desired?
1431      * (will create SUSPEND/RESUME events).
1432      */
1433     GNUNET_FS_FLAGS_PERSISTENCE = 1
1434
1435   };
1436
1437 /**
1438  * Options specified in the VARARGs
1439  * portion of GNUNET_FS_start.
1440  */
1441 enum GNUNET_FS_OPTIONS
1442   {
1443     
1444     /**
1445      * Last option in the VARARG list.
1446      */
1447     GNUNET_FS_OPTIONS_END = 0,
1448
1449     /**
1450      * Select the desired amount of parallelism (this option should be
1451      * followed by an "unsigned int" giving the desired maximum number
1452      * of parallel downloads).
1453      */
1454     GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1
1455
1456   };
1457
1458
1459 /**
1460  * Handle to the file-sharing service.
1461  */
1462 struct GNUNET_FS_Handle;
1463
1464
1465 /**
1466  * Setup a connection to the file-sharing service.
1467  *
1468  * @param sched scheduler to use
1469  * @param cfg configuration to use
1470  * @param client_name unique identifier for this client 
1471  * @param upcb function to call to notify about FS actions
1472  * @param upcb_cls closure for upcb
1473  * @param flags specific attributes for fs-operations
1474  * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
1475  * @return NULL on error
1476  */
1477 struct GNUNET_FS_Handle *
1478 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1479                  const struct GNUNET_CONFIGURATION_Handle *cfg,
1480                  const char *client_name,
1481                  GNUNET_FS_ProgressCallback upcb,
1482                  void *upcb_cls,
1483                  enum GNUNET_FS_Flags flags,
1484                  ...);
1485
1486
1487 /**
1488  * Close our connection with the file-sharing service.
1489  * The callback given to GNUNET_FS_start will no longer be
1490  * called after this function returns.
1491  *
1492  * @param h handle that was returned from GNUNET_FS_start
1493  */                    
1494 void 
1495 GNUNET_FS_stop (struct GNUNET_FS_Handle *h); 
1496
1497
1498 /**
1499  * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1500  *
1501  * @param cls closure
1502  * @param fi the entry in the publish-structure
1503  * @param length length of the file or directory
1504  * @param meta metadata for the file or directory (can be modified)
1505  * @param uri pointer to the keywords that will be used for this entry (can be modified)
1506  * @param anonymity pointer to selected anonymity level (can be modified)
1507  * @param priority pointer to selected priority (can be modified)
1508  * @param expirationTime pointer to selected expiration time (can be modified)
1509  * @param client_info pointer to client context set upon creation (can be modified)
1510  * @return GNUNET_OK to continue, GNUNET_NO to remove
1511  *         this entry from the directory, GNUNET_SYSERR
1512  *         to abort the iteration
1513  */
1514 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1515                                                   struct GNUNET_FS_FileInformation *fi,
1516                                                   uint64_t length,
1517                                                   struct GNUNET_CONTAINER_MetaData *meta,
1518                                                   struct GNUNET_FS_Uri **uri,
1519                                                   uint32_t *anonymity,
1520                                                   uint32_t *priority,
1521                                                   struct GNUNET_TIME_Absolute *expirationTime,
1522                                                   void **client_info);
1523
1524
1525 /**
1526  * Recover file information structure from disk.
1527  *
1528  * @param fn filename for the structure on disk
1529  * @return NULL on error 
1530  */
1531 struct GNUNET_FS_FileInformation *
1532 GNUNET_FS_file_information_recover (const char *fn);
1533
1534
1535 /**
1536  * Obtain the name under which this file information
1537  * structure is stored on disk.  Only works for top-level
1538  * file information structures.
1539  *
1540  * @param s structure to get the filename for
1541  * @return NULL on error, otherwise filename that
1542  *         can be passed to "GNUNET_FS_file_information_recover"
1543  *         to read this fi-struct from disk.
1544  */
1545 const char *
1546 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1547
1548
1549 /**
1550  * Synchronize this file-information struct with its mirror
1551  * on disk.  Note that all internal FS-operations that change
1552  * file information data should already call "sync" internally,
1553  * so this function is likely not useful for clients.
1554  * 
1555  * @param fi the struct to sync
1556  */
1557 void
1558 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *f);
1559
1560
1561 /**
1562  * Create an entry for a file in a publish-structure.
1563  *
1564  * @param filename name of the file or directory to publish
1565  * @param keywords under which keywords should this file be available
1566  *         directly; can be NULL
1567  * @param meta metadata for the file
1568  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1569  *                GNUNET_SYSERR for simulation
1570  * @param anonymity what is the desired anonymity level for sharing?
1571  * @param priority what is the priority for OUR node to
1572  *   keep this file available?  Use 0 for maximum anonymity and
1573  *   minimum reliability...
1574  * @param expirationTime when should this content expire?
1575  * @return publish structure entry for the file
1576  */
1577 struct GNUNET_FS_FileInformation *
1578 GNUNET_FS_file_information_create_from_file (void *client_info,
1579                                              const char *filename,
1580                                              const struct GNUNET_FS_Uri *keywords,
1581                                              const struct GNUNET_CONTAINER_MetaData *meta,
1582                                              int do_index,
1583                                              uint32_t anonymity,
1584                                              uint32_t priority,
1585                                              struct GNUNET_TIME_Absolute expirationTime);
1586
1587
1588 /**
1589  * Create an entry for a file in a publish-structure.
1590  *
1591  * @param length length of the file
1592  * @param data data for the file (should not be used afterwards by
1593  *        the caller; callee will "free")
1594  * @param keywords under which keywords should this file be available
1595  *         directly; can be NULL
1596  * @param meta metadata for the file
1597  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1598  *                GNUNET_SYSERR for simulation
1599  * @param anonymity what is the desired anonymity level for sharing?
1600  * @param priority what is the priority for OUR node to
1601  *   keep this file available?  Use 0 for maximum anonymity and
1602  *   minimum reliability...
1603  * @param expirationTime when should this content expire?
1604  * @return publish structure entry for the file
1605  */
1606 struct GNUNET_FS_FileInformation *
1607 GNUNET_FS_file_information_create_from_data (void *client_info,
1608                                              uint64_t length,
1609                                              void *data,
1610                                              const struct GNUNET_FS_Uri *keywords,
1611                                              const struct GNUNET_CONTAINER_MetaData *meta,
1612                                              int do_index,
1613                                              uint32_t anonymity,
1614                                              uint32_t priority,
1615                                              struct GNUNET_TIME_Absolute expirationTime);
1616
1617
1618 /**
1619  * Function that provides data.
1620  *
1621  * @param cls closure
1622  * @param offset offset to read from; it is possible
1623  *            that the caller might need to go backwards
1624  *            a bit at times
1625  * @param max maximum number of bytes that should be 
1626  *            copied to buf; readers are not allowed
1627  *            to provide less data unless there is an error;
1628  *            a value of "0" will be used at the end to allow
1629  *            the reader to clean up its internal state
1630  * @param buf where the reader should write the data
1631  * @param emsg location for the reader to store an error message
1632  * @return number of bytes written, usually "max", 0 on error
1633  */
1634 typedef size_t (*GNUNET_FS_DataReader)(void *cls, 
1635                                        uint64_t offset,
1636                                        size_t max, 
1637                                        void *buf,
1638                                        char **emsg);
1639
1640
1641 /**
1642  * Create an entry for a file in a publish-structure.
1643  *
1644  * @param length length of the file
1645  * @param reader function that can be used to obtain the data for the file 
1646  * @param reader_cls closure for "reader"
1647  * @param keywords under which keywords should this file be available
1648  *         directly; can be NULL
1649  * @param meta metadata for the file
1650  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1651  *                GNUNET_SYSERR for simulation
1652  * @param anonymity what is the desired anonymity level for sharing?
1653  * @param priority what is the priority for OUR node to
1654  *   keep this file available?  Use 0 for maximum anonymity and
1655  *   minimum reliability...
1656  * @param expirationTime when should this content expire?
1657  * @return publish structure entry for the file
1658  */
1659 struct GNUNET_FS_FileInformation *
1660 GNUNET_FS_file_information_create_from_reader (void *client_info,
1661                                                uint64_t length,
1662                                                GNUNET_FS_DataReader reader,
1663                                                void *reader_cls,
1664                                                const struct GNUNET_FS_Uri *keywords,
1665                                                const struct GNUNET_CONTAINER_MetaData *meta,
1666                                                int do_index,
1667                                                uint32_t anonymity,
1668                                                uint32_t priority,
1669                                                struct GNUNET_TIME_Absolute expirationTime);
1670
1671
1672 /**
1673  * Function that a "GNUNET_FS_DirectoryScanner" should call
1674  * for each entry in the directory.
1675  *
1676  * @param cls closure
1677  * @param filename name of the file (including path); must end 
1678  *          in a "/" (even on W32) if this is a directory
1679  * @param fi information about the file (should not be
1680  *        used henceforth by the caller)
1681  */
1682 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1683                                         const char *filename,
1684                                         struct GNUNET_FS_FileInformation *fi);
1685
1686
1687 /**
1688  * Type of a function that will be used to scan a directory.
1689  * 
1690  * @param cls closure
1691  * @param dirname name of the directory to scan
1692  * @param do_index should files be indexed or inserted
1693  * @param anonymity desired anonymity level
1694  * @param priority priority for publishing
1695  * @param expirationTime expiration for publication
1696  * @param proc function to call on each entry
1697  * @param proc_cls closure for proc
1698  * @param emsg where to store an error message (on errors)
1699  * @return GNUNET_OK on success
1700  */
1701 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1702                                           const char *dirname,
1703                                           int do_index,
1704                                           uint32_t anonymity,
1705                                           uint32_t priority,
1706                                           struct GNUNET_TIME_Absolute expirationTime,
1707                                           GNUNET_FS_FileProcessor proc,
1708                                           void *proc_cls,
1709                                           char **emsg);
1710
1711
1712
1713 /**
1714  * Simple, useful default implementation of a directory scanner
1715  * (GNUNET_FS_DirectoryScanner).  This implementation expects to get a
1716  * UNIX filename, will publish all files in the directory except hidden
1717  * files (those starting with a ".").  Metadata will be extracted
1718  * using GNU libextractor; the specific list of plugins should be
1719  * specified in "cls", passing NULL will disable (!)  metadata
1720  * extraction.  Keywords will be derived from the metadata and be
1721  * subject to default canonicalization.  This is strictly a
1722  * convenience function.
1723  *
1724  * @param cls must be of type "struct EXTRACTOR_Extractor*"
1725  * @param dirname name of the directory to scan
1726  * @param do_index should files be indexed or inserted
1727  * @param anonymity desired anonymity level
1728  * @param priority priority for publishing
1729  * @param expirationTime expiration for publication
1730  * @param proc function called on each entry
1731  * @param proc_cls closure for proc
1732  * @param emsg where to store an error message (on errors)
1733  * @return GNUNET_OK on success
1734  */
1735 int
1736 GNUNET_FS_directory_scanner_default (void *cls,
1737                                      const char *dirname,
1738                                      int do_index,
1739                                      uint32_t anonymity,
1740                                      uint32_t priority,
1741                                      struct GNUNET_TIME_Absolute expirationTime,
1742                                      GNUNET_FS_FileProcessor proc,
1743                                      void *proc_cls,
1744                                      char **emsg);
1745
1746
1747 /**
1748  * Create a publish-structure from an existing file hierarchy, inferring
1749  * and organizing keywords and metadata as much as possible.  This
1750  * function primarily performs the recursive build and re-organizes
1751  * keywords and metadata; for automatically getting metadata
1752  * extraction, scanning of directories and creation of the respective
1753  * GNUNET_FS_FileInformation entries the default scanner should be
1754  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
1755  * convenience function.
1756  *
1757  * @param filename name of the top-level file or directory
1758  * @param scanner function used to get a list of files in a directory
1759  * @param scanner_cls closure for scanner
1760  * @param do_index should files in the hierarchy be indexed?
1761  * @param anonymity what is the desired anonymity level for sharing?
1762  * @param priority what is the priority for OUR node to
1763  *   keep this file available?  Use 0 for maximum anonymity and
1764  *   minimum reliability...
1765  * @param expirationTime when should this content expire?
1766  * @param emsg where to store an error message
1767  * @return publish structure entry for the directory, NULL on error
1768  */
1769 struct GNUNET_FS_FileInformation *
1770 GNUNET_FS_file_information_create_from_directory (void *client_info,
1771                                                   const char *filename,
1772                                                   GNUNET_FS_DirectoryScanner scanner,
1773                                                   void *scanner_cls,
1774                                                   int do_index,
1775                                                   uint32_t anonymity,
1776                                                   uint32_t priority,
1777                                                   struct GNUNET_TIME_Absolute expirationTime,
1778                                                   char **emsg);
1779
1780
1781 /**
1782  * Create an entry for an empty directory in a publish-structure.
1783  * This function should be used by applications for which the
1784  * use of "GNUNET_FS_file_information_create_from_directory"
1785  * is not appropriate.
1786  *
1787  * @param meta metadata for the directory
1788  * @param keywords under which keywords should this directory be available
1789  *         directly; can be NULL
1790  * @param anonymity what is the desired anonymity level for sharing?
1791  * @param priority what is the priority for OUR node to
1792  *   keep this file available?  Use 0 for maximum anonymity and
1793  *   minimum reliability...
1794  * @param expirationTime when should this content expire?
1795  * @return publish structure entry for the directory , NULL on error
1796  */
1797 struct GNUNET_FS_FileInformation *
1798 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1799                                                    const struct GNUNET_CONTAINER_MetaData *meta,
1800                                                    const struct GNUNET_FS_Uri *keywords,
1801                                                    uint32_t anonymity,
1802                                                    uint32_t priority,
1803                                                    struct GNUNET_TIME_Absolute expirationTime);
1804
1805
1806 /**
1807  * Add an entry to a directory in a publish-structure.  Clients
1808  * should never modify publish structures that were passed to
1809  * "GNUNET_FS_publish_start" already.
1810  *
1811  * @param dir the directory
1812  * @param ent the entry to add; the entry must not have been
1813  *            added to any other directory at this point and 
1814  *            must not include "dir" in its structure
1815  * @return GNUNET_OK on success, GNUNET_SYSERR on error
1816  */
1817 int
1818 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1819                                 struct GNUNET_FS_FileInformation *ent);
1820
1821
1822 /**
1823  * Inspect a file or directory in a publish-structure.  Clients
1824  * should never modify publish structures that were passed to
1825  * "GNUNET_FS_publish_start" already.  When called on a directory,
1826  * this function will FIRST call "proc" with information about
1827  * the directory itself and then for each of the files in the
1828  * directory (but not for files in subdirectories).  When called
1829  * on a file, "proc" will be called exactly once (with information
1830  * about the specific file).
1831  *
1832  * @param dir the directory
1833  * @param proc function to call on each entry
1834  * @param proc_cls closure for proc
1835  */
1836 void
1837 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1838                                     GNUNET_FS_FileInformationProcessor proc,
1839                                     void *proc_cls);
1840
1841
1842 /**
1843  * Destroy publish-structure.  Clients should never destroy publish
1844  * structures that were passed to "GNUNET_FS_publish_start" already.
1845  *
1846  * @param fi structure to destroy
1847  * @param cleaner function to call on each entry in the structure
1848  *        (useful to clean up client_info); can be NULL; return
1849  *        values are ignored
1850  * @param cleaner_cls closure for cleaner
1851  */
1852 void
1853 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1854                                     GNUNET_FS_FileInformationProcessor cleaner,
1855                                     void *cleaner_cls);
1856
1857
1858 /**
1859  * Options for publishing.  Compatible options
1860  * can be OR'ed together.
1861  */
1862 enum GNUNET_FS_PublishOptions 
1863   {
1864     /**
1865      * No options (use defaults for everything).
1866      */
1867     GNUNET_FS_PUBLISH_OPTION_NONE = 0,
1868     
1869     /**
1870      * Simulate publishing.  With this option, no data will be stored
1871      * in the datastore.  Useful for computing URIs from files.
1872      */
1873     GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
1874   };
1875
1876 /**
1877  * Publish a file or directory.
1878  *
1879  * @param h handle to the file sharing subsystem
1880  * @param ctx initial value to use for the '*ctx'
1881  *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1882  * @param fi information about the file or directory structure to publish
1883  * @param namespace namespace to publish the file in, NULL for no namespace
1884  * @param nid identifier to use for the publishd content in the namespace
1885  *        (can be NULL, must be NULL if namespace is NULL)
1886  * @param nuid update-identifier that will be used for future updates 
1887  *        (can be NULL, must be NULL if namespace or nid is NULL)
1888  * @param options options for the publication 
1889  * @return context that can be used to control the publish operation
1890  */
1891 struct GNUNET_FS_PublishContext *
1892 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1893                          void *ctx,
1894                          struct GNUNET_FS_FileInformation *fi,
1895                          struct GNUNET_FS_Namespace *namespace,
1896                          const char *nid,
1897                          const char *nuid,
1898                          enum GNUNET_FS_PublishOptions options);
1899
1900
1901 /**
1902  * Stop an upload.  Will abort incomplete uploads (but 
1903  * not remove blocks that have already been publishd) or
1904  * simply clean up the state for completed uploads.
1905  * Must NOT be called from within the event callback!
1906  *
1907  * @param sc context for the upload to stop
1908  */
1909 void 
1910 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1911
1912
1913 /**
1914  * Signature of a function called as the continuation of a KBlock or
1915  * SBlock publication.
1916  *
1917  * @param cls closure
1918  * @param uri URI under which the block is now available, NULL on error
1919  * @param emsg error message, NULL on success
1920  */
1921 typedef void (*GNUNET_FS_PublishContinuation)(void *cls,
1922                                               const struct GNUNET_FS_Uri *uri,
1923                                               const char *emsg);
1924                                       
1925
1926 /**
1927  * Publish a KBlock on GNUnet.
1928  *
1929  * @param h handle to the file sharing subsystem
1930  * @param ksk_uri keywords to use
1931  * @param meta metadata to use
1932  * @param uri URI to refer to in the KBlock
1933  * @param expirationTime when the KBlock expires
1934  * @param anonymity anonymity level for the KBlock
1935  * @param priority priority for the KBlock
1936  * @param cont continuation
1937  * @param cont_cls closure for cont
1938  */
1939 void
1940 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
1941                        struct GNUNET_FS_Uri *ksk_uri,
1942                        struct GNUNET_CONTAINER_MetaData *meta,
1943                        struct GNUNET_FS_Uri *uri,
1944                        struct GNUNET_TIME_Absolute expirationTime,
1945                        uint32_t anonymity,
1946                        uint32_t priority,
1947                        enum GNUNET_FS_PublishOptions options,
1948                        GNUNET_FS_PublishContinuation cont,
1949                        void *cont_cls);
1950
1951
1952 /**
1953  * Publish an SBlock on GNUnet.
1954  *
1955  * @param h handle to the file sharing subsystem
1956  * @param namespace namespace to publish in
1957  * @param identifier identifier to use
1958  * @param update update identifier to use
1959  * @param meta metadata to use
1960  * @param uri URI to refer to in the SBlock
1961  * @param expirationTime when the SBlock expires
1962  * @param anonymity anonymity level for the SBlock
1963  * @param priority priority for the SBlock
1964  * @param cont continuation
1965  * @param cont_cls closure for cont
1966  */
1967 void
1968 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
1969                        struct GNUNET_FS_Namespace *namespace,
1970                        const char *identifier,
1971                        const char *update,
1972                        struct GNUNET_CONTAINER_MetaData *meta,
1973                        struct GNUNET_FS_Uri *uri,
1974                        struct GNUNET_TIME_Absolute expirationTime,
1975                        uint32_t anonymity,
1976                        uint32_t priority,
1977                        enum GNUNET_FS_PublishOptions options,
1978                        GNUNET_FS_PublishContinuation cont,
1979                        void *cont_cls);
1980
1981
1982 /**
1983  * Type of a function called by "GNUNET_FS_get_indexed_files".
1984  *
1985  * @param cls closure
1986  * @param filename the name of the file
1987  * @param file_id hash of the contents of the indexed file
1988  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1989  */
1990 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1991                                                const char *filename,
1992                                                const GNUNET_HashCode *file_id);
1993
1994
1995 /**
1996  * Iterate over all indexed files.
1997  *
1998  * @param h handle to the file sharing subsystem
1999  * @param iterator function to call on each indexed file
2000  * @param iterator_cls closure for iterator
2001  * @param cont continuation to call when done;
2002  *             reason should be "TIMEOUT" (on
2003  *             error) or  "PREREQ_DONE" (on success)
2004  * @param cont_cls closure for cont
2005  */
2006 void 
2007 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2008                              GNUNET_FS_IndexedFileProcessor iterator,
2009                              void *iterator_cls,
2010                              GNUNET_SCHEDULER_Task cont,
2011                              void *cont_cls);
2012
2013
2014 /**
2015  * Unindex a file.
2016  *
2017  * @param h handle to the file sharing subsystem
2018  * @param filename file to unindex
2019  * @return NULL on error, otherwise handle 
2020  */
2021 // FIXME: add a "void *" context for the client to arguments!?
2022 struct GNUNET_FS_UnindexContext *
2023 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h,
2024                          const char *filename);
2025
2026
2027 /**
2028  * Clean up after completion of an unindex operation.
2029  *
2030  * @param uc handle
2031  */
2032 void
2033 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2034
2035
2036 /**
2037  * Publish an advertismement for a namespace.  
2038  *
2039  * @param h handle to the file sharing subsystem
2040  * @param namespace handle for the namespace that should be advertised
2041  * @param meta meta-data for the namespace advertisement
2042  * @param anonymity for the namespace advertismement
2043  * @param priority for the namespace advertisement
2044  * @param expiration for the namespace advertisement
2045  * @param advertisementURI the keyword (!) URI to advertise the
2046  *        namespace under (we will create a GNUNET_EC_KNBlock)
2047  * @param rootEntry name of the root entry in the namespace (for
2048  *        the namespace advertisement)
2049  *
2050  * @return uri of the advertisement
2051  */
2052 struct GNUNET_FS_Uri *
2053 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
2054                                struct GNUNET_FS_Namespace *namespace,
2055                                const struct GNUNET_CONTAINER_MetaData *meta,
2056                                uint32_t anonymity,
2057                                uint32_t priority,
2058                                struct GNUNET_TIME_Absolute expiration,
2059                                const struct GNUNET_FS_Uri *advertisementURI,
2060                                const char *rootEntry);
2061
2062
2063 /**
2064  * Create a namespace with the given name; if one already
2065  * exists, return a handle to the existing namespace.
2066  *
2067  * @param h handle to the file sharing subsystem
2068  * @param name name to use for the namespace
2069  * @return handle to the namespace, NULL on error
2070  */
2071 struct GNUNET_FS_Namespace *
2072 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
2073                             const char *name);
2074
2075
2076 /**
2077  * Delete a namespace handle.  Can be used for a clean shutdown (free
2078  * memory) or also to freeze the namespace to prevent further
2079  * insertions by anyone.
2080  *
2081  * @param namespace handle to the namespace that should be deleted / freed
2082  * @param freeze prevents future insertions; creating a namespace
2083  *        with the same name again will create a fresh namespace instead
2084  *
2085  * @return GNUNET_OK on success, GNUNET_SYSERR on error
2086  */
2087 int 
2088 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
2089                             int freeze);
2090
2091
2092 /**
2093  * Callback with information about local (!) namespaces.
2094  * Contains the names of the local namespace and the global
2095  * ID.
2096  *
2097  * @param cls closure
2098  * @param name human-readable identifier of the namespace
2099  * @param id hash identifier for the namespace
2100  */
2101 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
2102                                                   const char *name,
2103                                                   const GNUNET_HashCode *id);
2104
2105
2106 /**
2107  * Build a list of all available local (!) namespaces The returned
2108  * names are only the nicknames since we only iterate over the local
2109  * namespaces.
2110  *
2111  * @param h handle to the file sharing subsystem
2112  * @param cb function to call on each known namespace
2113  * @param cb_cls closure for cb
2114  */
2115 void 
2116 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2117                           GNUNET_FS_NamespaceInfoProcessor cb,
2118                           void *cb_cls);
2119
2120
2121 /**
2122  * Function called on updateable identifiers.
2123  *
2124  * @param cls closure
2125  * @param last_id last identifier 
2126  * @param last_uri uri used for the content published under the last_id
2127  * @param last_meta metadata associated with last_uri
2128  * @param next_id identifier that should be used for updates
2129  */
2130 typedef void 
2131 (*GNUNET_FS_IdentifierProcessor)(void *cls,
2132                                  const char *last_id, 
2133                                  const struct GNUNET_FS_Uri *last_uri,
2134                                  const struct GNUNET_CONTAINER_MetaData *last_meta,
2135                                  const char *next_id);
2136
2137
2138 /**
2139  * List all of the identifiers in the namespace for 
2140  * which we could produce an update.
2141  *
2142  * @param namespace namespace to inspect for updateable content
2143  * @param ip function to call on each updateable identifier
2144  * @param ip_cls closure for ip
2145  */
2146 void
2147 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
2148                                      GNUNET_FS_IdentifierProcessor ip, 
2149                                      void *ip_cls);
2150
2151
2152 /**
2153  * Start search for content.
2154  *
2155  * @param h handle to the file sharing subsystem
2156  * @param uri specifies the search parameters; can be
2157  *        a KSK URI or an SKS URI.
2158  * @param anonymity desired level of anonymity
2159  * @return context that can be used to control the search
2160  */
2161 // FIXME: add a "void *" context for the client to arguments!?
2162 struct GNUNET_FS_SearchContext *
2163 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2164                         const struct GNUNET_FS_Uri *uri,
2165                         uint32_t anonymity);
2166
2167
2168 /**
2169  * Pause search.  
2170  *
2171  * @param sc context for the search that should be paused
2172  */
2173 void 
2174 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2175
2176
2177 /**
2178  * Continue paused search.
2179  *
2180  * @param sc context for the search that should be resumed
2181  */
2182 void 
2183 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2184
2185
2186 /**
2187  * Stop search for content.
2188  *
2189  * @param sc context for the search that should be stopped
2190  */
2191 void 
2192 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2193
2194
2195
2196
2197 /**
2198  * Options for downloading.  Compatible options
2199  * can be OR'ed together.
2200  */
2201 enum GNUNET_FS_DownloadOptions 
2202   {
2203     /**
2204      * No options (use defaults for everything).
2205      */
2206     GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2207     
2208     /**
2209      * Do a recursive download (that is, automatically trigger the
2210      * download of files in directories).
2211      */
2212     GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 1,
2213
2214     /**
2215      * Do not append temporary data to
2216      * the target file (for the IBlocks).
2217      */
2218     GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 2
2219
2220   };
2221
2222
2223
2224 /**
2225  * Download parts of a file.  Note that this will store
2226  * the blocks at the respective offset in the given file.  Also, the
2227  * download is still using the blocking of the underlying FS
2228  * encoding.  As a result, the download may *write* outside of the
2229  * given boundaries (if offset and length do not match the 32k FS
2230  * block boundaries). <p>
2231  *
2232  * The given range can be used to focus a download towards a
2233  * particular portion of the file (optimization), not to strictly
2234  * limit the download to exactly those bytes.
2235  *
2236  * @param h handle to the file sharing subsystem
2237  * @param uri the URI of the file (determines what to download); CHK or LOC URI
2238  * @param meta known metadata for the file (can be NULL)
2239  * @param filename where to store the file, maybe NULL (then no file is
2240  *        created on disk and data must be grabbed from the callbacks)
2241  * @param offset at what offset should we start the download (typically 0)
2242  * @param length how many bytes should be downloaded starting at offset
2243  * @param anonymity anonymity level to use for the download
2244  * @param options various download options
2245  * @param parent parent download to associate this download with (use NULL
2246  *        for top-level downloads; useful for manually-triggered recursive downloads)
2247  * @return context that can be used to control this download
2248  */
2249 // FIXME: add a "void *" context for the client to arguments!?
2250 struct GNUNET_FS_DownloadContext *
2251 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2252                           const struct GNUNET_FS_Uri *uri,
2253                           const struct GNUNET_CONTAINER_MetaData *meta,
2254                           const char *filename,
2255                           uint64_t offset,
2256                           uint64_t length,
2257                           uint32_t anonymity,
2258                           enum GNUNET_FS_DownloadOptions options,
2259                           struct GNUNET_FS_DownloadContext *parent);
2260
2261
2262 /**
2263  * Stop a download (aborts if download is incomplete).
2264  *
2265  * @param dc handle for the download
2266  * @param do_delete delete files of incomplete downloads
2267  */
2268 void
2269 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
2270                          int do_delete);
2271
2272
2273 /**
2274  * Initialize collection.
2275  *
2276  * @param h handle to the file sharing subsystem
2277  * @param namespace namespace to use for the collection
2278  * @return GNUNET_OK on success, GNUNET_SYSERR if another
2279  *         namespace is already set for our collection
2280  */
2281 int 
2282 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2283                             struct GNUNET_FS_Namespace *namespace);
2284
2285
2286 /**
2287  * Stop collection.
2288  *
2289  * @param h handle to the file sharing subsystem
2290  * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2291  */
2292 int 
2293 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2294
2295
2296 /**
2297  * Are we using a collection?
2298  *
2299  * @param h handle to the file sharing subsystem
2300  * @return NULL if there is no collection,
2301  */
2302 struct GNUNET_FS_Namespace *
2303 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2304
2305
2306 /**
2307  * Publish an update of the current collection information to the
2308  * network now.  The function has no effect if the collection has not
2309  * changed since the last publication.  If we are currently not
2310  * collecting, this function does nothing.
2311  *
2312  * @param h handle to the file sharing subsystem
2313  */
2314 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2315
2316
2317 /**
2318  * If we are currently building a collection, publish the given file
2319  * information in that collection.  If we are currently not
2320  * collecting, this function does nothing.
2321  *
2322  * @param h handle to the file sharing subsystem
2323  * @param uri uri to add to the collection
2324  * @param meta metadata for the uri
2325  */
2326 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2327                                const struct GNUNET_FS_Uri *uri,
2328                                const struct GNUNET_CONTAINER_MetaData *meta);
2329
2330
2331
2332
2333
2334 /* ******************** Directory API *********************** */
2335
2336
2337 #define GNUNET_FS_DIRECTORY_MIME  "application/gnunet-directory"
2338 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2339 #define GNUNET_FS_DIRECTORY_EXT   ".gnd"
2340
2341 /**
2342  * Does the meta-data claim that this is a directory?
2343  * Checks if the mime-type is that of a GNUnet directory.
2344  *
2345  * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2346  *  we have no mime-type information (treat as 'GNUNET_NO')
2347  */
2348 int 
2349 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2350
2351
2352 /**
2353  * Set the MIMETYPE information for the given
2354  * metadata to "application/gnunet-directory".
2355  * 
2356  * @param md metadata to add mimetype to
2357  */
2358 void
2359 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2360
2361
2362 /**
2363  * Function used to process entries in a directory.
2364  *
2365  * @param cls closure
2366  * @param filename name of the file in the directory
2367  * @param uri URI of the file
2368  * @param metadata metadata for the file; metadata for
2369  *        the directory if everything else is NULL/zero
2370  * @param length length of the available data for the file
2371  *           (of type size_t since data must certainly fit
2372  *            into memory; if files are larger than size_t
2373  *            permits, then they will certainly not be
2374  *            embedded with the directory itself).
2375  * @param data data available for the file (length bytes)
2376  */
2377 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2378                                                   const char *filename,
2379                                                   const struct GNUNET_FS_Uri *uri,
2380                                                   const struct GNUNET_CONTAINER_MetaData *meta,
2381                                                   size_t length,
2382                                                   const void *data);
2383
2384
2385 /**
2386  * Iterate over all entries in a directory.  Note that directories
2387  * are structured such that it is possible to iterate over the
2388  * individual blocks as well as over the entire directory.  Thus
2389  * a client can call this function on the buffer in the
2390  * GNUNET_FS_ProgressCallback.  Also, directories can optionally
2391  * include the contents of (small) files embedded in the directory
2392  * itself; for those files, the processor may be given the
2393  * contents of the file directly by this function.
2394  *
2395  * @param size number of bytes in data
2396  * @param data pointer to the beginning of the directory
2397  * @param offset offset of data in the directory
2398  * @param dep function to call on each entry
2399  * @param dep_cls closure for dep
2400  */
2401 void 
2402 GNUNET_FS_directory_list_contents (size_t size,
2403                                    const void *data,
2404                                    uint64_t offset,
2405                                    GNUNET_FS_DirectoryEntryProcessor dep, 
2406                                    void *dep_cls);
2407
2408
2409 /**
2410  * Opaque handle to a directory builder.
2411  */
2412 struct GNUNET_FS_DirectoryBuilder;
2413
2414 /**
2415  * Create a directory builder.
2416  * 
2417  * @param mdir metadata for the directory
2418  */
2419 struct GNUNET_FS_DirectoryBuilder *
2420 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData *mdir);
2421
2422
2423 /**
2424  * Add an entry to a directory.
2425  * 
2426  * @param bld directory to extend
2427  * @param uri uri of the entry (must not be a KSK)
2428  * @param md metadata of the entry
2429  * @param data raw data of the entry, can be NULL, otherwise
2430  *        data must point to exactly the number of bytes specified
2431  *        by the uri
2432  */
2433 void
2434 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2435                                  const struct GNUNET_FS_Uri *uri,
2436                                  const struct GNUNET_CONTAINER_MetaData *md,
2437                                  const void *data);
2438                  
2439
2440 /**
2441  * Finish building the directory.  Frees the
2442  * builder context and returns the directory
2443  * in-memory.
2444  *
2445  * @param bld directory to finish
2446  * @param rsize set to the number of bytes needed
2447  * @param rdata set to the encoded directory
2448  * @return GNUNET_OK on success
2449  */
2450 int
2451 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
2452                                     size_t *rsize,
2453                                     void **rdata);
2454
2455
2456 #if 0                           /* keep Emacsens' auto-indent happy */
2457 {
2458 #endif
2459 #ifdef __cplusplus
2460 }
2461 #endif
2462
2463
2464 #endif