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