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