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