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