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