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