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