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