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