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