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