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