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