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