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