236bdd08329727d066b5bdf0d6ee94eeae4ef650
[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 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file include/gnunet_fs_service.h
22  * @brief API for file-sharing via GNUnet 
23  * @author Christian Grothoff
24  */
25 #ifndef GNUNET_FS_LIB_H
26 #define GNUNET_FS_LIB_H
27
28 #include "gnunet_util_lib.h"
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 /**
39  * Version number of the implementation.
40  * History:
41  *
42  * 1.x.x: initial version with triple GNUNET_hash and merkle tree
43  * 2.x.x: root node with mime-type, filename and version number
44  * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
45  * 2.2.x: with directories
46  * 3.0.x: with namespaces
47  * 3.1.x: with namespace meta-data
48  * 3.2.x: with collections
49  * 4.0.x: with expiration, variable meta-data, kblocks
50  * 4.1.x: with new error and configuration handling
51  * 5.0.x: with location URIs
52  * 6.0.0: with support for OR in KSKs
53  * 6.1.x: with simplified namespace support
54  * 9.0.0: CPS-style integrated API
55  */
56 #define GNUNET_FS_VERSION 0x00090000
57
58
59 /* ******************** URI API *********************** */
60
61 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
62 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
63 #define GNUNET_FS_URI_SKS_INFIX "sks/"
64 #define GNUNET_FS_URI_CHK_INFIX "chk/"
65 #define GNUNET_FS_URI_LOC_INFIX "loc/"
66
67
68 /**
69  * A Universal Resource Identifier (URI), opaque.
70  */
71 struct GNUNET_FS_Uri;
72
73
74 /**
75  * Iterator over keywords
76  *
77  * @param cls closure
78  * @param keyword the keyword
79  * @param is_mandatory is the keyword mandatory (in a search)
80  * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
81  */
82 typedef int (*GNUNET_FS_KeywordIterator) (void *cls,
83                                           const char *keyword,
84                                           int is_mandatory);
85
86 /**
87  * Get a unique key from a URI.  This is for putting URIs
88  * into HashMaps.  The key may change between FS implementations.
89  *
90  * @param uri uri to convert to a unique key
91  * @param key wherer to store the unique key
92  */
93 void 
94 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
95                       GNUNET_HashCode * key);
96
97 /**
98  * Convert a URI to a UTF-8 String.
99  *
100  * @param uri uri to convert to a string
101  * @return the UTF-8 string
102  */
103 char *
104 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
105
106 /**
107  * Convert keyword URI to a human readable format
108  * (i.e. the search query that was used in the first place)
109  *
110  * @param uri ksk uri to convert to a string 
111  * @return string with the keywords
112  */
113 char *
114 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
115
116 /**
117  * Convert a UTF-8 String to a URI.
118  *
119  * @param uri string to parse
120  * @param emsg where to store the parser error message (if any)
121  * @return NULL on error
122  */
123 struct GNUNET_FS_Uri *
124 GNUNET_FS_uri_parse (const char *uri,
125                      char **emsg);
126
127 /**
128  * Free URI.
129  *
130  * @param uri uri to free
131  */
132 void 
133 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
134
135
136 /**
137  * How many keywords are ANDed in this keyword URI?
138  *
139  * @param uri ksk uri to get the number of keywords from
140  * @return 0 if this is not a keyword URI
141  */
142 unsigned int 
143 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
144
145
146 /**
147  * Iterate over all keywords in this keyword URI.
148  *
149  * @param uri ksk uri to get the keywords from
150  * @param iterator function to call on each keyword
151  * @param iterator_cls closure for iterator
152  * @return -1 if this is not a keyword URI, otherwise number of
153  *   keywords iterated over until iterator aborted
154  */
155 int 
156 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
157                                 GNUNET_FS_KeywordIterator iterator, 
158                                 void *iterator_cls);
159
160
161 /**
162  * Obtain the identity of the peer offering the data
163  *
164  * @param uri the location URI to inspect
165  * @param peer where to store the identify of the peer (presumably) offering the content
166  * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
167  */
168 int
169 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
170                                      struct GNUNET_PeerIdentity * peer);
171
172
173 /**
174  * Obtain the URI of the content itself.
175  *
176  * @param uri location URI to get the content URI from
177  * @return NULL if argument is not a location URI
178  */
179 struct GNUNET_FS_Uri *
180 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
181
182
183 /**
184  * Construct a location URI (this peer will be used for the location).
185  *
186  * @param baseURI content offered by the sender
187  * @param cfg configuration information (used to find our hostkey)
188  * @param expiration_time how long will the content be offered?
189  * @return the location URI, NULL on error
190  */
191 struct GNUNET_FS_Uri *
192 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
193                           struct GNUNET_CONFIGURATION_Handle *cfg,
194                           struct GNUNET_TIME_Absolute expiration_time);
195
196
197 /**
198  * Canonicalize keyword URI.  Performs operations such
199  * as decapitalization and removal of certain characters.
200  * (useful for search).
201  *
202  * @param uri the URI to canonicalize 
203  * @return canonicalized version of the URI, NULL on error
204  */
205 struct GNUNET_FS_Uri *
206 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri);
207
208
209 /**
210  * Merge the sets of keywords from two KSK URIs.
211  * (useful for merging the canonicalized keywords with
212  * the original keywords for sharing).
213  *
214  * @param u1 first uri
215  * @param u2 second uri
216  * @return merged URI, NULL on error
217  */
218 struct GNUNET_FS_Uri *
219 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
220                          const struct GNUNET_FS_Uri *u2);
221
222
223 /**
224  * Duplicate URI.
225  *
226  * @param uri the URI to duplicate
227  * @return copy of the URI
228  */
229 struct GNUNET_FS_Uri *
230 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
231
232
233 /**
234  * Create an FS URI from a single user-supplied string of keywords.
235  * The string is broken up at spaces into individual keywords.
236  * Keywords that start with "+" are mandatory.  Double-quotes can
237  * be used to prevent breaking up strings at spaces (and also
238  * to specify non-mandatory keywords starting with "+").
239  *
240  * Keywords must contain a balanced number of double quotes and
241  * double quotes can not be used in the actual keywords (for
242  * example, the string '""foo bar""' will be turned into two
243  * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
244  *
245  * @param keywords the keyword string
246  * @param emsg where to store an error message
247  * @return an FS URI for the given keywords, NULL
248  *  if keywords is not legal (i.e. empty).
249  */
250 struct GNUNET_FS_Uri *
251 GNUNET_FS_uri_ksk_create (const char *keywords,
252                           char **emsg);
253
254
255 /**
256  * Create an FS URI from a user-supplied command line of keywords.
257  * Arguments should start with "+" to indicate mandatory
258  * keywords.
259  *
260  * @param argc number of keywords
261  * @param argv keywords (double quotes are not required for
262  *             keywords containing spaces; however, double
263  *             quotes are required for keywords starting with
264  *             "+"); there is no mechanism for having double
265  *             quotes in the actual keywords (if the user
266  *             did specifically specify double quotes, the
267  *             caller should convert each double quote
268  *             into two single quotes).
269  * @return an FS URI for the given keywords, NULL
270  *  if keywords is not legal (i.e. empty).
271  */
272 struct GNUNET_FS_Uri *
273 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc,
274                                     const char **argv);
275
276
277 /**
278  * Test if two URIs are equal.
279  *
280  * @param u1 one of the URIs
281  * @param u2 the other URI
282  * @return GNUNET_YES if the URIs are equal
283  */
284 int 
285 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
286                           const struct GNUNET_FS_Uri *u2);
287
288
289 /**
290  * Is this a namespace URI?
291  *
292  * @param uri the uri to check
293  * @return GNUNET_YES if this is an SKS uri
294  */
295 int
296 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
297
298
299 /**
300  * Get the ID of a namespace from the given
301  * namespace URI.
302  *
303  * @param uri the uri to get the namespace ID from
304  * @param nsid where to store the ID of the namespace
305  * @return GNUNET_OK on success
306  */
307 int 
308 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
309                                  GNUNET_HashCode * nsid);
310
311
312 /**
313  * Get the content identifier of an SKS URI.
314  *
315  * @param uri the sks uri
316  * @return NULL on error (not a valid SKS URI)
317  */
318 char *
319 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
320
321
322 /**
323  * Convert namespace URI to a human readable format
324  * (using the namespace description, if available).
325  *
326  * @param cfg configuration to use
327  * @param uri SKS uri to convert
328  * @return NULL on error (not an SKS URI)
329  */
330 char *
331 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
332                                    const struct GNUNET_FS_Uri *uri);
333
334
335 /**
336  * Is this a keyword URI?
337  *
338  * @param uri the uri
339  * @return GNUNET_YES if this is a KSK uri
340  */
341 int 
342 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
343
344
345 /**
346  * Is this a file (or directory) URI?
347  *
348  * @param uri the uri to check
349  * @return GNUNET_YES if this is a CHK uri
350  */
351 int 
352 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
353
354
355 /**
356  * What is the size of the file that this URI
357  * refers to?
358  *
359  * @param uri the CHK URI to inspect
360  * @return size of the file as specified in the CHK URI
361  */
362 uint64_t 
363 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
364
365
366 /**
367  * Is this a location URI?
368  *
369  * @param uri the uri to check
370  * @return GNUNET_YES if this is a LOC uri
371  */
372 int 
373 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
374
375
376 /**
377  * Construct a keyword-URI from meta-data (take all entries
378  * in the meta-data and construct one large keyword URI
379  * that lists all keywords that can be found in the meta-data).
380  * @deprecated
381  */
382 struct GNUNET_FS_Uri *
383 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData *md);
384
385
386 /* ******************** command-line option parsing API *********************** */
387
388 /**
389  * Command-line option parser function that allows the user
390  * to specify one or more '-k' options with keywords.  Each
391  * specified keyword will be added to the URI.  A pointer to
392  * the URI must be passed as the "scls" argument.
393  *
394  * @param ctx command line processor context
395  * @param scls must be of type "struct GNUNET_FS_Uri **"
396  * @param option name of the option (typically 'k')
397  * @param value command line argument given
398  * @return GNUNET_OK on success
399  */
400 int
401 GNUNET_FS_getopt_configure_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 
402                                          void *scls,
403                                          const char *option,
404                                          const char *value);
405
406
407 /**
408  * Command-line option parser function that allows the user to specify
409  * one or more '-m' options with metadata.  Each specified entry of
410  * the form "type=value" will be added to the metadata.  A pointer to
411  * the metadata must be passed as the "scls" argument.
412  *
413  * @param ctx command line processor context
414  * @param scls must be of type "struct GNUNET_MetaData **"
415  * @param option name of the option (typically 'k')
416  * @param value command line argument given
417  * @return GNUNET_OK on success
418  */
419 int
420 GNUNET_FS_getopt_configure_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext* ctx, 
421                                          void *scls,
422                                          const char *option,
423                                          const char *value);
424
425
426
427 /* ************************* sharing API ***************** */
428
429
430 /**
431  * Possible status codes used in the callback for the 
432  * various file-sharing operations.  On each file (or search),
433  * the callback is guaranteed to be called once with "START"
434  * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
435  * are optional and depend on the circumstances; parent operations
436  * will be STARTED before child-operations and STOPPED after
437  * their respective child-operations.  START and STOP signals 
438  * are typically generated either due to explicit client requests
439  * or because of suspend/resume operations.
440  */
441 enum GNUNET_FS_Status
442 {
443   /**
444    * Notification that we have started to publish a file structure.
445    */
446   GNUNET_FS_STATUS_PUBLISH_START,
447
448   /**
449    * Notification that we have resumed sharing a file structure.
450    */
451   GNUNET_FS_STATUS_PUBLISH_RESUME,
452
453   /**
454    * Notification that we have suspended sharing a file structure.
455    */
456   GNUNET_FS_STATUS_PUBLISH_SUSPEND,
457
458   /**
459    * Notification that we are making progress sharing a file structure.
460    */
461   GNUNET_FS_STATUS_PUBLISH_PROGRESS,
462
463   /**
464    * Notification that an error was encountered  sharing a file structure.
465    * The application will continue to receive resume/suspend events for
466    * this structure until "GNUNET_FS_publish_stop" is called.
467    */
468   GNUNET_FS_STATUS_PUBLISH_ERROR,
469
470   /**
471    * Notification that we completed sharing a file structure.
472    * The application will continue to receive resume/suspend events for
473    * this structure until "GNUNET_FS_publish_stop" is called.
474    */
475   GNUNET_FS_STATUS_PUBLISH_COMPLETED,
476
477   /**
478    * Notification that we have stopped
479    * the process of uploading a file structure; no
480    * futher events will be generated for this action.
481    */
482   GNUNET_FS_STATUS_PUBLISH_STOPPED,
483
484   /**
485    * Notification that we have started this download.
486    */
487   GNUNET_FS_STATUS_DOWNLOAD_START,
488
489   /**
490    * Notification that this download is being resumed.
491    */
492   GNUNET_FS_STATUS_DOWNLOAD_RESUME,
493
494   /**
495    * Notification that this download was suspended.
496    */
497   GNUNET_FS_STATUS_DOWNLOAD_SUSPEND,
498
499   /**
500    * Notification about progress with this download.
501    */
502   GNUNET_FS_STATUS_DOWNLOAD_PROGRESS,
503
504   /**
505    * Notification that this download encountered an error.
506    */
507   GNUNET_FS_STATUS_DOWNLOAD_ERROR,
508
509   /**
510    * Notification that this download completed.  Note that for
511    * directories, completion does not imply completion of all files in
512    * the directory.
513    */
514   GNUNET_FS_STATUS_DOWNLOAD_COMPLETED,
515
516   /**
517    * Notification that this download was stopped
518    * (final event with respect to this action).
519    */
520   GNUNET_FS_STATUS_DOWNLOAD_STOPPED,
521
522   /**
523    * First event generated when a client requests 
524    * a search to begin or when a namespace result
525    * automatically triggers the search for updates.
526    */
527   GNUNET_FS_STATUS_SEARCH_START,
528
529   /**
530    * Last event when a search is being resumed;
531    * note that "GNUNET_FS_SEARCH_START" will not
532    * be generated in this case.
533    */
534   GNUNET_FS_STATUS_SEARCH_RESUME,
535
536   /**
537    * Event generated for each search result
538    * when the respective search is resumed.
539    */
540   GNUNET_FS_STATUS_SEARCH_RESUME_RESULT,
541
542   /**
543    * Last event when a search is being suspended;
544    * note that "GNUNET_FS_SEARCH_STOPPED" will not
545    * be generated in this case.
546    */
547   GNUNET_FS_STATUS_SEARCH_SUSPEND,
548   
549   /**
550    * Event generated for each search result
551    * when the respective search is suspended.
552    */
553   GNUNET_FS_STATUS_SEARCH_SUSPEND_RESULT,
554
555   /**
556    * This search has yielded a result.
557    */
558   GNUNET_FS_STATUS_SEARCH_RESULT,
559
560   /**
561    * We have discovered a new namespace.
562    */
563   GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE,
564
565   /**
566    * We have additional data about the quality
567    * or availability of a search result.
568    */
569   GNUNET_FS_STATUS_SEARCH_UPDATE,
570
571   /**
572    * Signals a problem with this search.
573    */
574   GNUNET_FS_STATUS_SEARCH_ERROR,
575
576   /**
577    * Signals that this search was paused.
578    */
579   GNUNET_FS_STATUS_SEARCH_PAUSED,
580
581   /**
582    * Signals that this search was continued (unpaused).
583    */
584   GNUNET_FS_STATUS_SEARCH_CONTINUED,
585
586   /**
587    * Event generated for each search result
588    * when the respective search is stopped.
589    */
590   GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED,
591
592   /**
593    * Last message from a search; this signals
594    * that there will be no further events associated
595    * with this search.
596    */
597   GNUNET_FS_STATUS_SEARCH_STOPPED,
598
599   /**
600    * Notification that we started to unindex a file.
601    */ 
602   GNUNET_FS_STATUS_UNINDEX_START,
603
604   /**
605    * Notification that we resumed unindexing of a file.
606    */
607   GNUNET_FS_STATUS_UNINDEX_RESUME,
608
609   /**
610    * Notification that we suspended unindexing a file.
611    */
612   GNUNET_FS_STATUS_UNINDEX_SUSPEND,
613
614   /**
615    * Notification that we made progress unindexing a file.
616    */
617   GNUNET_FS_STATUS_UNINDEX_PROGRESS,
618
619   /**
620    * Notification that we encountered an error unindexing
621    * a file.
622    */
623   GNUNET_FS_STATUS_UNINDEX_ERROR,
624
625   /**
626    * Notification that the unindexing of this file
627    * was stopped (final event for this action).
628    */
629   GNUNET_FS_STATUS_UNINDEX_STOPPED
630
631 };
632
633
634 /**
635  * Handle to one of our namespaces.
636  */
637 struct GNUNET_FS_Namespace;
638
639
640 /**
641  * Handle for controlling an upload.
642  */
643 struct GNUNET_FS_PublishContext;
644
645
646 /**
647  * Handle for controlling an unindexing operation.
648  */
649 struct GNUNET_FS_UnindexContext;
650
651
652 /**
653  * Handle for controlling a search.
654  */
655 struct GNUNET_FS_SearchContext;
656
657
658 /**
659  * Context for controlling a download.
660  */
661 struct GNUNET_FS_DownloadContext;
662
663
664 /**
665  * Handle for detail information about a file that is being publishd.
666  * Specifies metadata, keywords, how to get the contents of the file
667  * (i.e. data-buffer in memory, filename on disk) and other options.
668  */
669 struct GNUNET_FS_FileInformation;
670
671
672 /**
673  * Argument given to the progress callback with
674  * information about what is going on.
675  */
676 struct GNUNET_FS_ProgressInfo
677 {  
678
679   /**
680    * Values that depend on the event type.
681    */
682   union {
683     
684     /**
685      * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
686      */
687     struct {
688
689       /**
690        * Context for controlling the upload.
691        */
692       struct GNUNET_FS_PublishContext *sc;
693
694       /**
695        * Information about the file that is being publishd.
696        */
697       const struct GNUNET_FS_FileInformation *fi;
698
699       /**
700        * Client context pointer (set the last time
701        * by the client for this operation; initially
702        * NULL on START/RESUME events).
703        */
704       void *cctx;
705
706       /**
707        * Client context pointer for the parent operation
708        * (if this is a file in a directory or a subdirectory).
709        */
710       void *pctx;
711       
712       /**
713        * How large is the file overall?  For directories,
714        * this is only the size of the directory itself,
715        * not of the other files contained within the 
716        * directory.
717        */
718       uint64_t size;
719
720       /**
721        * At what time do we expect to finish the upload?
722        * (will be a value in the past for completed
723        * uploads).
724        */ 
725       struct GNUNET_TIME_Absolute eta;
726
727       /**
728        * How long has this upload been actively running
729        * (excludes times where the upload was suspended).
730        */
731       struct GNUNET_TIME_Relative duration;
732
733       /**
734        * How many bytes have we completed?
735        */
736       uint64_t completed;
737
738       /**
739        * What anonymity level is used for this upload?
740        */
741       unsigned int anonymity;
742
743       /**
744        * Additional values for specific events.
745        */
746       union {
747
748         /**
749          * These values are only valid for
750          * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
751          */
752         struct {
753           
754           /**
755            * Data block we just published.
756            */
757           const void *data;
758           
759           /**
760            * At what offset in the file is "data"?
761            */
762           uint64_t offset;
763           
764           /**
765            * Length of the data block.
766            */
767           uint64_t data_len;
768
769         } progress;
770
771         /**
772          * These values are only valid for
773          * GNUNET_FS_STATUS_PUBLISH_RESUME events.
774          */
775         struct {
776           
777           /**
778            * Error message, NULL if no error was encountered so far.
779            */
780           const char *message;
781
782         } resume;
783
784         /**
785          * These values are only valid for
786          * GNUNET_FS_STATUS_PUBLISH_ERROR events.
787          */
788         struct {
789           
790           /**
791            * Error message, never NULL.
792            */
793           const char *message;
794
795         } error;
796
797       } specifics;
798
799     } publish;
800
801     
802     /**
803      * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
804      */
805     struct {
806
807       /**
808        * Context for controlling the download.
809        */
810       struct GNUNET_FS_DownloadContext *dc;
811
812       /**
813        * Client context pointer (set the last time
814        * by the client for this operation; initially
815        * NULL on START/RESUME events).
816        */
817       void *cctx;
818
819       /**
820        * Client context pointer for the parent operation
821        * (if this is a file in a directory or a subdirectory).
822        */
823       void *pctx;
824       
825       /**
826        * URI used for this download.
827        */
828       const struct GNUNET_FS_Uri *uri;
829       
830       /**
831        * How large is the file overall?  For directories,
832        * this is only the size of the directory itself,
833        * not of the other files contained within the 
834        * directory.
835        */
836       uint64_t size;
837
838       /**
839        * At what time do we expect to finish the download?
840        * (will be a value in the past for completed
841        * uploads).
842        */ 
843       struct GNUNET_TIME_Absolute eta;
844
845       /**
846        * How long has this download been active?
847        */ 
848       struct GNUNET_TIME_Relative duration;
849
850       /**
851        * How many bytes have we completed?
852        */
853       uint64_t completed;
854
855       /**
856        * What anonymity level is used for this download?
857        */
858       unsigned int anonymity;
859
860       /**
861        * Additional values for specific events.
862        */
863       union {
864         
865         /**
866          * These values are only valid for
867          * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
868          */
869         struct {
870   
871           /**
872            * Data block we just obtained.
873            */
874           const void *data;
875           
876           /**
877            * At what offset in the file is "data"?
878            */
879           uint64_t offset;
880           
881           /**
882            * Length of the data block.
883            */
884           uint64_t data_len;
885
886           /**
887            * Amount of trust we offered to get the block.
888            */
889           unsigned int trust_offered;     
890
891         } progress;
892
893         /**
894          * These values are only valid for
895          * GNUNET_FS_STATUS_DOWNLOAD_START events.
896          */
897         struct {
898
899           /**
900            * Known metadata for the download.
901            */
902           const struct GNUNET_MetaData *meta;
903
904         } start;
905
906         /**
907          * These values are only valid for
908          * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
909          */
910         struct {
911
912           /**
913            * Known metadata for the download.
914            */
915           const struct GNUNET_MetaData *meta;
916
917           /**
918            * Error message, NULL if we have not encountered any error yet.
919            */
920           const char *message;
921
922         } resume;
923
924         /**
925          * These values are only valid for
926          * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
927          */
928         struct {
929
930           /**
931            * Error message.
932            */
933           const char *message;
934
935         } error;
936
937       } specifics;
938
939     } download;
940
941     /**
942      * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
943      */
944     struct {
945
946       /**
947        * Context for controlling the search, NULL for
948        * searches that were not explicitly triggered
949        * by the client (i.e., searches for updates in
950        * namespaces).
951        */
952       struct GNUNET_FS_SearchContext *sc;
953
954       /**
955        * Client context pointer (set the last time by the client for
956        * this operation; initially NULL on START/RESUME events).  Note
957        * that this value can only be set on START/RESUME; returning
958        * non-NULL on RESULT/RESUME_RESULT will actually update the
959        * private context for "UPDATE" events.
960        */
961       void *cctx;
962
963       /**
964        * Client parent-context pointer; NULL for top-level searches,
965        * non-NULL for automatically triggered searches for updates in
966        * namespaces.
967        */
968       void *pctx;
969
970       /**
971        * What query is used for this search
972        * (list of keywords or SKS identifier).
973        */
974       const struct GNUNET_FS_Uri *query;
975
976       /**
977        * How long has this search been actively running
978        * (excludes times where the search was paused or
979        * suspended).
980        */
981       struct GNUNET_TIME_Relative duration;
982
983       /**
984        * What anonymity level is used for this search?
985        */
986       unsigned int anonymity;
987
988       /**
989        * How much trust have we been offering for this search
990        * so far?
991        */
992       unsigned int trust_offered;
993
994       /**
995        * Additional values for specific events.
996        */
997       union {
998         
999         /**
1000          * These values are only valid for
1001          * GNUNET_FS_STATUS_SEARCH_RESULT events.
1002          */
1003         struct {
1004           
1005           /**
1006            * Metadata for the search result.
1007            */
1008           const struct GNUNET_MetaData *meta;
1009
1010           /**
1011            * URI for the search result.
1012            */
1013           const struct GNUNET_FS_Uri *uri;
1014
1015         } result;
1016         
1017         /**
1018          * These values are only valid for
1019          * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1020          */
1021         struct {
1022           
1023           /**
1024            * Metadata for the search result.
1025            */
1026           const struct GNUNET_MetaData *meta;
1027
1028           /**
1029            * URI for the search result.
1030            */
1031           const struct GNUNET_FS_Uri *uri;
1032
1033           /**
1034            * Current availability rank (negative:
1035            * unavailable, positive: available)
1036            */
1037           int availability_rank;
1038  
1039           /**
1040            * On how many total queries is the given
1041            * availability_rank based?
1042            */
1043           unsigned int availabiliy_certainty;
1044
1045           /**
1046            * Updated applicability rank (the larger,
1047            * the better the result fits the search
1048            * criteria).
1049            */
1050           unsigned int applicabiliy_rank;         
1051           
1052         } resume_result;
1053         
1054         /**
1055          * These values are only valid for
1056          * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1057          */
1058         struct {
1059
1060           /**
1061            * Private context set for for this result
1062            * during the "RESULT" event.
1063            */
1064           void *cctx;
1065           
1066           /**
1067            * Metadata for the search result.
1068            */
1069           const struct GNUNET_MetaData *meta;
1070
1071           /**
1072            * URI for the search result.
1073            */
1074           const struct GNUNET_FS_Uri *uri;
1075
1076           /**
1077            * Current availability rank (negative:
1078            * unavailable, positive: available)
1079            */
1080           int availability_rank;
1081  
1082           /**
1083            * On how many total queries is the given
1084            * availability_rank based?
1085            */
1086           unsigned int availabiliy_certainty;
1087
1088           /**
1089            * Updated applicability rank (the larger,
1090            * the better the result fits the search
1091            * criteria).
1092            */
1093           unsigned int applicabiliy_rank;
1094
1095         } update;
1096         
1097         /**
1098          * These values are only valid for
1099          * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1100          * These events are automatically triggered for
1101          * each search result before the 
1102          * GNUNET_FS_STATUS_SEARCH_SUSPEND event.  This
1103          * happens primarily to give the client a chance
1104          * to clean up the "cctx" (if needed).
1105          */
1106         struct {
1107
1108           /**
1109            * Private context set for for this result
1110            * during the "RESULT" event.
1111            */
1112           void *cctx;
1113           
1114           /**
1115            * Metadata for the search result.
1116            */
1117           const struct GNUNET_MetaData *meta;
1118
1119           /**
1120            * URI for the search result.
1121            */
1122           const struct GNUNET_FS_Uri *uri;
1123
1124         } result_suspend;
1125         
1126         /**
1127          * These values are only valid for
1128          * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1129          * These events are automatically triggered for
1130          * each search result before the 
1131          * GNUNET_FS_STATUS_SEARCH_STOPPED event.  This
1132          * happens primarily to give the client a chance
1133          * to clean up the "cctx" (if needed).
1134          */
1135         struct {
1136
1137           /**
1138            * Private context set for for this result
1139            * during the "RESULT" event.
1140            */
1141           void *cctx;
1142           
1143           /**
1144            * Metadata for the search result.
1145            */
1146           const struct GNUNET_MetaData *meta;
1147
1148           /**
1149            * URI for the search result.
1150            */
1151           const struct GNUNET_FS_Uri *uri;
1152
1153         } result_stopped;
1154
1155         /**
1156          * These values are only valid for
1157          * GNUNET_FS_STATUS_SEARCH_RESUME events.
1158          */
1159         struct {
1160
1161           /**
1162            * Error message, NULL if we have not encountered any error yet.
1163            */
1164           const char *message;
1165
1166           /**
1167            * Is this search currently paused?
1168            */
1169           int is_paused;
1170
1171         } resume;
1172
1173         /**
1174          * These values are only valid for
1175          * GNUNET_FS_STATUS_SEARCH_ERROR events.
1176          */
1177         struct {
1178
1179           /**
1180            * Error message.
1181            */
1182           const char *message;
1183
1184         } error;
1185     
1186         /**
1187          * Values for all "GNUNET_FS_STATUS_RESULT_NAMESPACE" events.
1188          */
1189         struct {
1190           
1191           /**
1192            * Handle to the namespace (NULL if it is not a local
1193            * namespace).
1194            */
1195           struct GNUNET_FS_Namespace *ns;
1196           
1197           /**
1198            * Short, human-readable name of the namespace.
1199            */
1200           const char *name;
1201           
1202           /**
1203            * Root identifier for the namespace, can be NULL.
1204            */
1205           const char *root;
1206           
1207           /**
1208            * Metadata for the namespace.
1209            */
1210           const struct GNUNET_CONTAINER_MetaData *meta;
1211           
1212           /**
1213            * Hash-identifier for the namespace.
1214            */
1215           GNUNET_HashCode id;      
1216           
1217         } namespace;
1218
1219       } specifics;
1220
1221     } search;
1222
1223     /**
1224      * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1225      */
1226     struct {
1227
1228       /**
1229        * Context for controlling the unindexing.
1230        */
1231       struct GNUNET_FS_UnindexContext *uc;
1232
1233       /**
1234        * Client context pointer (set the last time
1235        * by the client for this operation; initially
1236        * NULL on START/RESUME events).
1237        */
1238       void *cctx;
1239
1240       /**
1241        * Name of the file that is being unindexed.
1242        */
1243       const char *filename;
1244
1245       /**
1246        * How large is the file overall?
1247        */
1248       uint64_t size;
1249
1250       /**
1251        * At what time do we expect to finish unindexing?
1252        * (will be a value in the past for completed
1253        * unindexing opeations).
1254        */ 
1255       struct GNUNET_TIME_Absolute eta;
1256
1257       /**
1258        * How long has this upload been actively running
1259        * (excludes times where the upload was suspended).
1260        */
1261       struct GNUNET_TIME_Relative duration;
1262
1263       /**
1264        * How many bytes have we completed?
1265        */
1266       uint64_t completed;
1267
1268       /**
1269        * Additional values for specific events.
1270        */
1271       union {
1272
1273         /**
1274          * These values are only valid for
1275          * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1276          */
1277         struct {
1278   
1279           /**
1280            * Data block we just unindexed.
1281            */
1282           const void *data;
1283           
1284           /**
1285            * At what offset in the file is "data"?
1286            */
1287           uint64_t offset;
1288           
1289           /**
1290            * Length of the data block.
1291            */
1292           uint64_t data_len;
1293
1294         } progress;
1295
1296         /**
1297          * These values are only valid for
1298          * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1299          */
1300         struct {
1301
1302           /**
1303            * Error message, NULL if we have not encountered any error yet.
1304            */
1305           const char *message;
1306
1307         } resume;
1308
1309         /**
1310          * These values are only valid for
1311          * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1312          */
1313         struct {
1314
1315           /**
1316            * Error message.
1317            */
1318           const char *message;
1319
1320         } error;
1321
1322       } specifics;
1323
1324     } unindex;
1325
1326   } value;
1327
1328   /**
1329    * Specific status code (determines the event type).
1330    */  
1331   enum GNUNET_FS_Status status;
1332
1333 };
1334
1335
1336 /**
1337  * Notification of FS to a client about the progress of an 
1338  * operation.  Callbacks of this type will be used for uploads,
1339  * downloads and searches.  Some of the arguments depend a bit 
1340  * in their meaning on the context in which the callback is used.
1341  *
1342  * @param cls closure
1343  * @param info details about the event, specifying the event type
1344  *        and various bits about the event
1345  * @return client-context (for the next progress call
1346  *         for this operation; should be set to NULL for
1347  *         SUSPEND and STOPPED events).  The value returned
1348  *         will be passed to future callbacks in the respective
1349  *         field in the GNUNET_FS_ProgressInfo struct.
1350  */
1351 typedef void* (*GNUNET_FS_ProgressCallback)
1352   (void *cls,
1353    const struct GNUNET_FS_ProgressInfo *info);
1354
1355
1356 /**
1357  * Handle to the file-sharing service.
1358  */
1359 struct GNUNET_FS_Handle;
1360
1361
1362 /**
1363  * Setup a connection to the file-sharing service.
1364  *
1365  * @param sched scheduler to use
1366  * @param cfg configuration to use
1367  * @param client_name unique identifier for this client 
1368  * @param upcb function to call to notify about FS actions
1369  * @param upcb_cls closure for upcb
1370  */
1371 struct GNUNET_FS_Handle *
1372 GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched,
1373                  const struct GNUNET_CONFIGURATION_Handle *cfg,
1374                  const char *client_name,
1375                  GNUNET_FS_ProgressCallback upcb,
1376                  void *upcb_cls);
1377
1378
1379 /**
1380  * Close our connection with the file-sharing service.
1381  * The callback given to GNUNET_FS_start will no longer be
1382  * called after this function returns.
1383  *
1384  * @param h handle that was returned from GNUNET_FS_start
1385  */                    
1386 void 
1387 GNUNET_FS_stop (struct GNUNET_FS_Handle *h); 
1388
1389
1390 /**
1391  * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
1392  *
1393  * @param cls closure
1394  * @param fi the entry in the publish-structure
1395  * @param length length of the file or directory
1396  * @param meta metadata for the file or directory (can be modified)
1397  * @param uri pointer to the keywords that will be used for this entry (can be modified)
1398  * @param anonymity pointer to selected anonymity level (can be modified)
1399  * @param priority pointer to selected priority (can be modified)
1400  * @param expirationTime pointer to selected expiration time (can be modified)
1401  * @param client_info pointer to client context set upon creation (can be modified)
1402  * @return GNUNET_OK to continue, GNUNET_NO to remove
1403  *         this entry from the directory, GNUNET_SYSERR
1404  *         to abort the iteration
1405  */
1406 typedef int (*GNUNET_FS_FileInformationProcessor)(void *cls,
1407                                                   struct GNUNET_FS_FileInformation *fi,
1408                                                   uint64_t length,
1409                                                   struct GNUNET_CONTAINER_MetaData *meta,
1410                                                   struct GNUNET_FS_Uri **uri,
1411                                                   unsigned int *anonymity,
1412                                                   unsigned int *priority,
1413                                                   struct GNUNET_TIME_Absolute *expirationTime,
1414                                                   void **client_info);
1415
1416
1417 /**
1418  * Create an entry for a file in a publish-structure.
1419  *
1420  * @param filename name of the file or directory to publish
1421  * @param meta metadata for the file
1422  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1423  *                GNUNET_SYSERR for simulation
1424  * @param anonymity what is the desired anonymity level for sharing?
1425  * @param priority what is the priority for OUR node to
1426  *   keep this file available?  Use 0 for maximum anonymity and
1427  *   minimum reliability...
1428  * @param expirationTime when should this content expire?
1429  * @return publish structure entry for the file
1430  */
1431 struct GNUNET_FS_FileInformation *
1432 GNUNET_FS_file_information_create_from_file (void *client_info,
1433                                              const char *filename,
1434                                              const struct GNUNET_CONTAINER_MetaData *meta,
1435                                              int do_index,
1436                                              unsigned int anonymity,
1437                                              unsigned int priority,
1438                                              struct GNUNET_TIME_Absolute expirationTime);
1439
1440
1441 /**
1442  * Create an entry for a file in a publish-structure.
1443  *
1444  * @param length length of the file
1445  * @param data data for the file (should not be used afterwards by
1446  *        the caller; caller will "free")
1447  * @param meta metadata for the file
1448  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1449  *                GNUNET_SYSERR for simulation
1450  * @param anonymity what is the desired anonymity level for sharing?
1451  * @param priority what is the priority for OUR node to
1452  *   keep this file available?  Use 0 for maximum anonymity and
1453  *   minimum reliability...
1454  * @param expirationTime when should this content expire?
1455  * @return publish structure entry for the file
1456  */
1457 struct GNUNET_FS_FileInformation *
1458 GNUNET_FS_file_information_create_from_data (void *client_info,
1459                                              uint64_t length,
1460                                              void *data,
1461                                              const struct GNUNET_CONTAINER_MetaData *meta,
1462                                              int do_index,
1463                                              unsigned int anonymity,
1464                                              unsigned int priority,
1465                                              struct GNUNET_TIME_Absolute expirationTime);
1466
1467
1468 /**
1469  * Function that provides data.
1470  *
1471  * @param cls closure
1472  * @param offset offset to read from; it is possible
1473  *            that the caller might need to go backwards
1474  *            a bit at times
1475  * @param max maximum number of bytes that should be 
1476  *            copied to buf; readers are not allowed
1477  *            to provide less data unless there is an error;
1478  *            a value of "0" will be used at the end to allow
1479  *            the reader to clean up its internal state
1480  * @param buf where the reader should write the data
1481  * @param emsg location for the reader to store an error message
1482  * @return number of bytes written, usually "max", 0 on error
1483  */
1484 typedef size_t (*GNUNET_FS_DataReader)(void *cls, 
1485                                        uint64_t offset,
1486                                        size_t max, 
1487                                        void *buf,
1488                                        char **emsg);
1489
1490
1491 /**
1492  * Create an entry for a file in a publish-structure.
1493  *
1494  * @param length length of the file
1495  * @param reader function that can be used to obtain the data for the file 
1496  * @param reader_cls closure for "reader"
1497  * @param keywords under which keywords should this file be available
1498  *         directly; can be NULL
1499  * @param meta metadata for the file
1500  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1501  *                GNUNET_SYSERR for simulation
1502  * @param anonymity what is the desired anonymity level for sharing?
1503  * @param priority what is the priority for OUR node to
1504  *   keep this file available?  Use 0 for maximum anonymity and
1505  *   minimum reliability...
1506  * @param expirationTime when should this content expire?
1507  * @return publish structure entry for the file
1508  */
1509 struct GNUNET_FS_FileInformation *
1510 GNUNET_FS_file_information_create_from_reader (void *client_info,
1511                                                uint64_t length,
1512                                                GNUNET_FS_DataReader reader,
1513                                                void *reader_cls,
1514                                                const struct GNUNET_FS_Uri *keywords,
1515                                                const struct GNUNET_CONTAINER_MetaData *meta,
1516                                                int do_index,
1517                                                unsigned int anonymity,
1518                                                unsigned int priority,
1519                                                struct GNUNET_TIME_Absolute expirationTime);
1520
1521
1522 /**
1523  * Function that a "GNUNET_FS_DirectoryScanner" should call
1524  * for each entry in the directory.
1525  *
1526  * @param cls closure
1527  * @param filename name of the file (including path); must end 
1528  *          in a "/" (even on W32) if this is a directory
1529  * @param fi information about the file (should not be
1530  *        used henceforth by the caller)
1531  */
1532 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1533                                         const char *filename,
1534                                         struct GNUNET_FS_FileInformation *fi);
1535
1536
1537 /**
1538  * Type of a function that will be used to scan a directory.
1539  * 
1540  * @param cls closure
1541  * @param dirname name of the directory to scan
1542  * @param proc function to call on each entry
1543  * @param proc_cls closure for proc
1544  * @param emsg where to store an error message (on errors)
1545  * @return GNUNET_OK on success
1546  */
1547 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1548                                           const char *dirname,
1549                                           GNUNET_FS_FileProcessor proc,
1550                                           void *proc_cls,
1551                                           char **emsg);
1552
1553
1554
1555 /**
1556  * Simple, useful default implementation of a directory scanner
1557  * (GNUNET_FS_DirectoryScanner).  This implementation expects to get a
1558  * UNIX filename, will publish all files in the directory except hidden
1559  * files (those starting with a ".").  Metadata will be extracted
1560  * using GNU libextractor; the specific list of plugins should be
1561  * specified in "cls", passing NULL will disable (!)  metadata
1562  * extraction.  Keywords will be derived from the metadata and be
1563  * subject to default canonicalization.  This is strictly a
1564  * convenience function.
1565  *
1566  * @param cls must be of type "struct EXTRACTOR_Extractor*"
1567  * @param dirname name of the directory to scan
1568  * @param proc function called on each entry
1569  * @param proc_cls closure for proc
1570  * @param emsg where to store an error message (on errors)
1571  * @return GNUNET_OK on success
1572  */
1573 int
1574 GNUNET_FS_directory_scanner_default (void *cls,
1575                                      const char *dirname,
1576                                      GNUNET_FS_FileProcessor proc,
1577                                      void *proc_cls);
1578
1579
1580 /**
1581  * Create a publish-structure from an existing file hierarchy, inferring
1582  * and organizing keywords and metadata as much as possible.  This
1583  * function primarily performs the recursive build and re-organizes
1584  * keywords and metadata; for automatically getting metadata
1585  * extraction, scanning of directories and creation of the respective
1586  * GNUNET_FS_FileInformation entries the default scanner should be
1587  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
1588  * convenience function.
1589  *
1590  * @param filename name of the top-level file or directory
1591  * @param scanner function used to get a list of files in a directory
1592  * @param scanner_cls closure for scanner
1593  * @param anonymity what is the desired anonymity level for sharing?
1594  * @param priority what is the priority for OUR node to
1595  *   keep this file available?  Use 0 for maximum anonymity and
1596  *   minimum reliability...
1597  * @param expirationTime when should this content expire?
1598  * @return publish structure entry for the directory, NULL on error
1599  */
1600 struct GNUNET_FS_FileInformation *
1601 GNUNET_FS_file_information_create_from_directory (void *client_info,
1602                                                   GNUNET_FS_DirectoryScanner scanner,
1603                                                   void *scanner_cls,
1604                                                   unsigned int anonymity,
1605                                                   unsigned int priority,
1606                                                   struct GNUNET_TIME_Absolute expirationTime);
1607
1608
1609 /**
1610  * Create an entry for an empty directory in a publish-structure.
1611  * This function should be used by applications for which the
1612  * use of "GNUNET_FS_file_information_create_from_directory"
1613  * is not appropriate.
1614  *
1615  * @param meta metadata for the directory
1616  * @param keywords under which keywords should this directory be available
1617  *         directly; can be NULL
1618  * @param anonymity what is the desired anonymity level for sharing?
1619  * @param priority what is the priority for OUR node to
1620  *   keep this file available?  Use 0 for maximum anonymity and
1621  *   minimum reliability...
1622  * @param expirationTime when should this content expire?
1623  * @return publish structure entry for the directory , NULL on error
1624  */
1625 struct GNUNET_FS_FileInformation *
1626 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1627                                                    const struct GNUNET_CONTAINER_MetaData *meta,
1628                                                    const struct GNUNET_FS_Uri *keywords,
1629                                                    unsigned int anonymity,
1630                                                    unsigned int priority,
1631                                                    struct GNUNET_TIME_Absolute expirationTime);
1632
1633
1634 /**
1635  * Add an entry to a directory in a publish-structure.  Clients
1636  * should never modify publish structures that were passed to
1637  * "GNUNET_FS_publish_start" already.
1638  *
1639  * @param dir the directory
1640  * @param end the entry to add; the entry must not have been
1641  *            added to any other directory at this point and 
1642  *            must not include "dir" in its structure
1643  * @return GNUNET_OK on success, GNUNET_SYSERR on error
1644  */
1645 int
1646 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1647                                 struct GNUNET_FS_FileInformation *end);
1648
1649
1650 /**
1651  * Inspect a file or directory in a publish-structure.  Clients
1652  * should never modify publish structures that were passed to
1653  * "GNUNET_FS_publish_start" already.  When called on a directory,
1654  * this function will FIRST call "proc" with information about
1655  * the directory itself and then for each of the files in the
1656  * directory (but not for files in subdirectories).  When called
1657  * on a file, "proc" will be called exactly once (with information
1658  * about the specific file).
1659  *
1660  * @param dir the directory
1661  * @param proc function to call on each entry
1662  * @param proc_cls closure for proc
1663  */
1664 void
1665 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1666                                     GNUNET_FS_FileInformationProcessor proc,
1667                                     void *proc_cls);
1668
1669
1670 /**
1671  * Destroy publish-structure.  Clients should never destroy publish
1672  * structures that were passed to "GNUNET_FS_publish_start" already.
1673  *
1674  * @param fi structure to destroy
1675  * @param cleaner function to call on each entry in the structure
1676  *        (useful to clean up client_info); can be NULL; return
1677  *        values are ignored
1678  * @param cleaner_cls closure for cleaner
1679  */
1680 void
1681 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1682                                     GNUNET_FS_FileInformationProcessor cleaner,
1683                                     void *cleaner_cls);
1684
1685
1686 /**
1687  * Publish a file or directory.
1688  *
1689  * @param h handle to the file sharing subsystem
1690  * @param ctx initial value to use for the '*ctx'
1691  *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1692  * @param fi information about the file or directory structure to publish
1693  * @param namespace namespace to publish the file in, NULL for no namespace
1694  * @param nid identifier to use for the publishd content in the namespace
1695  *        (can be NULL, must be NULL if namespace is NULL)
1696  * @param nuid update-identifier that will be used for future updates 
1697  *        (can be NULL, must be NULL if namespace or nid is NULL)
1698  * @return context that can be used to control the publish operation
1699  */
1700 struct GNUNET_FS_PublishContext *
1701 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1702                        void *ctx,
1703                        const struct GNUNET_FS_FileInformation *fi,
1704                        struct GNUNET_FS_Namespace *namespace,
1705                        const char *nid,
1706                        const char *nuid);
1707
1708
1709 /**
1710  * Stop an upload.  Will abort incomplete uploads (but 
1711  * not remove blocks that have already been publishd) or
1712  * simply clean up the state for completed uploads.
1713  *
1714  * @param sc context for the upload to stop
1715  */
1716 void 
1717 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1718
1719
1720 /**
1721  * Type of a function called by "GNUNET_FS_get_indexed_files".
1722  *
1723  * @param cls closure
1724  * @param filename the name of the file
1725  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1726  */
1727 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1728                                                const char *filename);
1729
1730
1731 /**
1732  * Iterate over all indexed files.
1733  *
1734  * @param h handle to the file sharing subsystem
1735  * @param iterator function to call on each indexed file
1736  * @param iterator_cls closure for iterator
1737  */
1738 void 
1739 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1740                              GNUNET_FS_IndexedFileProcessor iterator,
1741                              void *iterator_cls);
1742
1743
1744 /**
1745  * Unindex a file.
1746  *
1747  * @param h handle to the file sharing subsystem
1748  * @param filename file to unindex
1749  * @return NULL on error, otherwise handle 
1750  */
1751 struct GNUNET_FS_UnindexContext *
1752 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
1753                    const char *filename);
1754
1755
1756 /**
1757  * Clean up after completion of an unindex operation.
1758  *
1759  * @param uc handle
1760  */
1761 void
1762 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
1763
1764
1765 /**
1766  * Publish an advertismement for a namespace.  
1767  *
1768  * @param h handle to the file sharing subsystem
1769  * @param namespace handle for the namespace that should be advertised
1770  * @param meta meta-data for the namespace advertisement
1771  * @param anonymity for the namespace advertismement
1772  * @param priority for the namespace advertisement
1773  * @param expiration for the namespace advertisement
1774  * @param advertisementURI the keyword (!) URI to advertise the
1775  *        namespace under (we will create a GNUNET_EC_KNBlock)
1776  * @param rootEntry name of the root entry in the namespace (for
1777  *        the namespace advertisement)
1778  *
1779  * @return uri of the advertisement
1780  */
1781 struct GNUNET_FS_Uri *
1782 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
1783                                struct GNUNET_FS_Namespace *namespace,
1784                                const struct GNUNET_MetaData *meta,
1785                                unsigned int anonymity,
1786                                unsigned int priority,
1787                                struct GNUNET_TIME_Absolute expiration,
1788                                const struct GNUNET_FS_Uri *advertisementURI,
1789                                const char *rootEntry);
1790
1791
1792 /**
1793  * Create a namespace with the given name; if one already
1794  * exists, return a handle to the existing namespace.
1795  *
1796  * @param h handle to the file sharing subsystem
1797  * @param name name to use for the namespace
1798  * @return handle to the namespace, NULL on error
1799  */
1800 struct GNUNET_FS_Namespace *
1801 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
1802                             const char *name);
1803
1804
1805 /**
1806  * Delete a namespace handle.  Can be used for a clean shutdown (free
1807  * memory) or also to freeze the namespace to prevent further
1808  * insertions by anyone.
1809  *
1810  * @param namespace handle to the namespace that should be deleted / freed
1811  * @param freeze prevents future insertions; creating a namespace
1812  *        with the same name again will create a fresh namespace instead
1813  *
1814  * @return GNUNET_OK on success, GNUNET_SYSERR on error
1815  */
1816 int 
1817 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
1818                             int freeze);
1819
1820
1821 /**
1822  * Callback with information about local (!) namespaces.
1823  * Contains the names of the local namespace and the global
1824  * ID.
1825  *
1826  * @param cls closure
1827  * @param name human-readable identifier of the namespace
1828  * @param id hash identifier for the namespace
1829  */
1830 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
1831                                                   const char *name,
1832                                                   const GNUNET_HashCode *id);
1833
1834
1835 /**
1836  * Build a list of all available local (!) namespaces The returned
1837  * names are only the nicknames since we only iterate over the local
1838  * namespaces.
1839  *
1840  * @param h handle to the file sharing subsystem
1841  * @param cb function to call on each known namespace
1842  * @param cb_cls closure for cb
1843  */
1844 void 
1845 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
1846                           GNUNET_FS_NamespaceInfoProcessor cb,
1847                           void *cb_cls);
1848
1849
1850 /**
1851  * Function called on updateable identifiers.
1852  *
1853  * @param cls closure
1854  * @param last_id last identifier 
1855  * @param last_uri uri used for the content published under the last_id
1856  * @param last_meta metadata associated with last_uri
1857  * @param next_id identifier that should be used for updates
1858  */
1859 typedef void 
1860 (*GNUNET_FS_IdentifierProcessor)(void *cls,
1861                                  const char *last_id, 
1862                                  const struct GNUNET_FS_Uri *last_uri,
1863                                  const struct GNUNET_CONTAINER_MetaData *last_meta,
1864                                  const char *next_id);
1865
1866
1867 /**
1868  * List all of the identifiers in the namespace for 
1869  * which we could produce an update.
1870  *
1871  * @param namespace namespace to inspect for updateable content
1872  * @param ip function to call on each updateable identifier
1873  * @param ip_cls closure for ip
1874  */
1875 void
1876 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1877                                      GNUNET_FS_IdentifierProcessor ip, 
1878                                      void *ip_cls);
1879
1880
1881 /**
1882  * Start search for content.
1883  *
1884  * @param h handle to the file sharing subsystem
1885  * @param uri specifies the search parameters; can be
1886  *        a KSK URI or an SKS URI.
1887  * @param anonymity desired level of anonymity
1888  * @return context that can be used to control the search
1889  */
1890 struct GNUNET_FS_SearchContext *
1891 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1892                         const struct GNUNET_FS_Uri *uri,
1893                         unsigned int anonymity);
1894
1895
1896 /**
1897  * Pause search.  
1898  *
1899  * @param sc context for the search that should be paused
1900  */
1901 void 
1902 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
1903
1904
1905 /**
1906  * Continue paused search.
1907  *
1908  * @param sc context for the search that should be resumed
1909  */
1910 void 
1911 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
1912
1913
1914 /**
1915  * Stop search for content.
1916  *
1917  * @param sc context for the search that should be stopped
1918  */
1919 void 
1920 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
1921
1922
1923 /**
1924  * Download parts of a file.  Note that this will store
1925  * the blocks at the respective offset in the given file.  Also, the
1926  * download is still using the blocking of the underlying FS
1927  * encoding.  As a result, the download may *write* outside of the
1928  * given boundaries (if offset and length do not match the 32k FS
1929  * block boundaries). <p>
1930  *
1931  * This function should be used to focus a download towards a
1932  * particular portion of the file (optimization), not to strictly
1933  * limit the download to exactly those bytes.
1934  *
1935  * @param h handle to the file sharing subsystem
1936  * @param uri the URI of the file (determines what to download); CHK or LOC URI
1937  * @param filename where to store the file, maybe NULL (then no file is
1938  *        created on disk and data must be grabbed from the callbacks)
1939  * @param offset at what offset should we start the download (typically 0)
1940  * @param length how many bytes should be downloaded starting at offset
1941  * @param anonymity anonymity level to use for the download
1942  * @param no_temporaries set to GNUNET_YES to disallow generation of temporary files
1943  * @param recursive should this be a recursive download (useful for directories
1944  *        to automatically trigger download of files in the directories)
1945  * @param parent parent download to associate this download with (use NULL
1946  *        for top-level downloads; useful for manually-triggered recursive downloads)
1947  * @return context that can be used to control this download
1948  */
1949 struct GNUNET_FS_DownloadContext *
1950 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
1951                                const struct GNUNET_FS_Uri *uri,
1952                                const char *filename,
1953                                unsigned long long offset,
1954                                unsigned long long length,
1955                                unsigned int anonymity,
1956                                int no_temporaries,      
1957                                int recursive,
1958                                struct GNUNET_FS_DownloadContext *parent);
1959
1960
1961 /**
1962  * Stop a download (aborts if download is incomplete).
1963  *
1964  * @param rm handle for the download
1965  * @param do_delete delete files of incomplete downloads
1966  */
1967 void
1968 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
1969                               int do_delete);
1970
1971
1972 /**
1973  * Initialize collection.
1974  *
1975  * @param h handle to the file sharing subsystem
1976  * @param namespace namespace to use for the collection
1977  * @return GNUNET_OK on success, GNUNET_SYSERR if another
1978  *         namespace is already set for our collection
1979  */
1980 int 
1981 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
1982                             struct GNUNET_FS_Namespace *namespace);
1983
1984
1985 /**
1986  * Stop collection.
1987  *
1988  * @param h handle to the file sharing subsystem
1989  * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
1990  */
1991 int 
1992 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
1993
1994
1995 /**
1996  * Are we using a collection?
1997  *
1998  * @param h handle to the file sharing subsystem
1999  * @return NULL if there is no collection,
2000  */
2001 struct GNUNET_FS_Namespace *
2002 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2003
2004
2005 /**
2006  * Publish an update of the current collection information to the
2007  * network now.  The function has no effect if the collection has not
2008  * changed since the last publication.  If we are currently not
2009  * collecting, this function does nothing.
2010  *
2011  * @param h handle to the file sharing subsystem
2012  */
2013 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2014
2015
2016 /**
2017  * If we are currently building a collection, publish the given file
2018  * information in that collection.  If we are currently not
2019  * collecting, this function does nothing.
2020  *
2021  * @param h handle to the file sharing subsystem
2022  * @param uri uri to add to the collection
2023  * @param meta metadata for the uri
2024  */
2025 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2026                                const struct GNUNET_FS_Uri *uri,
2027                                const struct GNUNET_CONTAINER_MetaData *meta);
2028
2029
2030
2031
2032
2033 /* ******************** Directory API *********************** */
2034
2035
2036 #define GNUNET_FS_DIRECTORY_MIME  "application/gnunet-directory"
2037 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2038 #define GNUNET_FS_DIRECTORY_EXT   ".gnd"
2039
2040 /**
2041  * Does the meta-data claim that this is a directory?
2042  * Checks if the mime-type is that of a GNUnet directory.
2043  *
2044  * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2045  *  we have no mime-type information (treat as 'GNUNET_NO')
2046  */
2047 int 
2048 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2049
2050
2051 /**
2052  * Set the MIMETYPE information for the given
2053  * metadata to "application/gnunet-directory".
2054  * 
2055  * @param md metadata to add mimetype to
2056  */
2057 void
2058 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2059
2060
2061 /**
2062  * Function used to process entries in a directory.
2063  *
2064  * @param cls closure
2065  * @param filename name of the file in the directory
2066  * @param uri URI of the file
2067  * @param metadata metadata for the file; metadata for
2068  *        the directory if everything else is NULL/zero
2069  * @param length length of the available data for the file
2070  *           (of type size_t since data must certainly fit
2071  *            into memory; if files are larger than size_t
2072  *            permits, then they will certainly not be
2073  *            embedded with the directory itself).
2074  * @param data data available for the file (length bytes)
2075  */
2076 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2077                                                   const char *filename,
2078                                                   const struct GNUNET_FS_Uri *uri,
2079                                                   const struct GNUNET_CONTAINER_MetaData *meta,
2080                                                   size_t length,
2081                                                   const void *data);
2082
2083
2084 /**
2085  * Iterate over all entries in a directory.  Note that directories
2086  * are structured such that it is possible to iterate over the
2087  * individual blocks as well as over the entire directory.  Thus
2088  * a client can call this function on the buffer in the
2089  * GNUNET_FS_ProgressCallback.  Also, directories can optionally
2090  * include the contents of (small) files embedded in the directory
2091  * itself; for those files, the processor may be given the
2092  * contents of the file directly by this function.
2093  *
2094  * @param size number of bytes in data
2095  * @param data pointer to the beginning of the directory
2096  * @param offset offset of data in the directory
2097  * @param dep function to call on each entry
2098  * @param dep_cls closure for dep
2099  */
2100 void 
2101 GNUNET_FS_directory_list_contents (size_t size,
2102                                    const void *data,
2103                                    uint64_t offset,
2104                                    GNUNET_FS_DirectoryEntryProcessor dep, 
2105                                    void *dep_cls);
2106
2107
2108 #if 0                           /* keep Emacsens' auto-indent happy */
2109 {
2110 #endif
2111 #ifdef __cplusplus
2112 }
2113 #endif
2114
2115
2116 #endif