7c6fc0549a97eeacb8a7d2159452ed68a926f054
[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  * Recover file information structure from disk.
1419  *
1420  * @param name filename for the structure on disk
1421  * @return NULL on error 
1422  */
1423 struct GNUNET_FS_FileInformation *
1424 GNUNET_FS_file_information_recover (const char *name);
1425
1426
1427 /**
1428  * Obtain the name under which this file information
1429  * structure is stored on disk.  Only works for top-level
1430  * file information structures.
1431  *
1432  * @param s structure to get the filename for
1433  * @return NULL on error, otherwise filename that
1434  *         can be passed to "GNUNET_FS_file_information_recover"
1435  *         to read this fi-struct from disk.
1436  */
1437 const char *
1438 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1439
1440
1441 /**
1442  * Synchronize this file-information struct with its mirror
1443  * on disk.  Note that all internal FS-operations that change
1444  * file information data should already call "sync" internally,
1445  * so this function is likely not useful for clients.
1446  * 
1447  * @param s the struct to sync
1448  */
1449 void
1450 GNUNET_FS_file_information_sync (struct GNUNET_FS_FileInformation *s);
1451
1452
1453 /**
1454  * Create an entry for a file in a publish-structure.
1455  *
1456  * @param filename name of the file or directory to publish
1457  * @param keywords under which keywords should this file be available
1458  *         directly; can be NULL
1459  * @param meta metadata for the file
1460  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1461  *                GNUNET_SYSERR for simulation
1462  * @param anonymity what is the desired anonymity level for sharing?
1463  * @param priority what is the priority for OUR node to
1464  *   keep this file available?  Use 0 for maximum anonymity and
1465  *   minimum reliability...
1466  * @param expirationTime when should this content expire?
1467  * @return publish structure entry for the file
1468  */
1469 struct GNUNET_FS_FileInformation *
1470 GNUNET_FS_file_information_create_from_file (void *client_info,
1471                                              const char *filename,
1472                                              const struct GNUNET_FS_Uri *keywords,
1473                                              const struct GNUNET_CONTAINER_MetaData *meta,
1474                                              int do_index,
1475                                              unsigned int anonymity,
1476                                              unsigned int priority,
1477                                              struct GNUNET_TIME_Absolute expirationTime);
1478
1479
1480 /**
1481  * Create an entry for a file in a publish-structure.
1482  *
1483  * @param length length of the file
1484  * @param data data for the file (should not be used afterwards by
1485  *        the caller; caller will "free")
1486  * @param keywords under which keywords should this file be available
1487  *         directly; can be NULL
1488  * @param meta metadata for the file
1489  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1490  *                GNUNET_SYSERR for simulation
1491  * @param anonymity what is the desired anonymity level for sharing?
1492  * @param priority what is the priority for OUR node to
1493  *   keep this file available?  Use 0 for maximum anonymity and
1494  *   minimum reliability...
1495  * @param expirationTime when should this content expire?
1496  * @return publish structure entry for the file
1497  */
1498 struct GNUNET_FS_FileInformation *
1499 GNUNET_FS_file_information_create_from_data (void *client_info,
1500                                              uint64_t length,
1501                                              void *data,
1502                                              const struct GNUNET_FS_Uri *keywords,
1503                                              const struct GNUNET_CONTAINER_MetaData *meta,
1504                                              int do_index,
1505                                              unsigned int anonymity,
1506                                              unsigned int priority,
1507                                              struct GNUNET_TIME_Absolute expirationTime);
1508
1509
1510 /**
1511  * Function that provides data.
1512  *
1513  * @param cls closure
1514  * @param offset offset to read from; it is possible
1515  *            that the caller might need to go backwards
1516  *            a bit at times
1517  * @param max maximum number of bytes that should be 
1518  *            copied to buf; readers are not allowed
1519  *            to provide less data unless there is an error;
1520  *            a value of "0" will be used at the end to allow
1521  *            the reader to clean up its internal state
1522  * @param buf where the reader should write the data
1523  * @param emsg location for the reader to store an error message
1524  * @return number of bytes written, usually "max", 0 on error
1525  */
1526 typedef size_t (*GNUNET_FS_DataReader)(void *cls, 
1527                                        uint64_t offset,
1528                                        size_t max, 
1529                                        void *buf,
1530                                        char **emsg);
1531
1532
1533 /**
1534  * Create an entry for a file in a publish-structure.
1535  *
1536  * @param length length of the file
1537  * @param reader function that can be used to obtain the data for the file 
1538  * @param reader_cls closure for "reader"
1539  * @param keywords under which keywords should this file be available
1540  *         directly; can be NULL
1541  * @param meta metadata for the file
1542  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
1543  *                GNUNET_SYSERR for simulation
1544  * @param anonymity what is the desired anonymity level for sharing?
1545  * @param priority what is the priority for OUR node to
1546  *   keep this file available?  Use 0 for maximum anonymity and
1547  *   minimum reliability...
1548  * @param expirationTime when should this content expire?
1549  * @return publish structure entry for the file
1550  */
1551 struct GNUNET_FS_FileInformation *
1552 GNUNET_FS_file_information_create_from_reader (void *client_info,
1553                                                uint64_t length,
1554                                                GNUNET_FS_DataReader reader,
1555                                                void *reader_cls,
1556                                                const struct GNUNET_FS_Uri *keywords,
1557                                                const struct GNUNET_CONTAINER_MetaData *meta,
1558                                                int do_index,
1559                                                unsigned int anonymity,
1560                                                unsigned int priority,
1561                                                struct GNUNET_TIME_Absolute expirationTime);
1562
1563
1564 /**
1565  * Function that a "GNUNET_FS_DirectoryScanner" should call
1566  * for each entry in the directory.
1567  *
1568  * @param cls closure
1569  * @param filename name of the file (including path); must end 
1570  *          in a "/" (even on W32) if this is a directory
1571  * @param fi information about the file (should not be
1572  *        used henceforth by the caller)
1573  */
1574 typedef void (*GNUNET_FS_FileProcessor)(void *cls,
1575                                         const char *filename,
1576                                         struct GNUNET_FS_FileInformation *fi);
1577
1578
1579 /**
1580  * Type of a function that will be used to scan a directory.
1581  * 
1582  * @param cls closure
1583  * @param dirname name of the directory to scan
1584  * @param do_index should files be indexed or inserted
1585  * @param anonymity desired anonymity level
1586  * @param priority priority for publishing
1587  * @param expirationTime expiration for publication
1588  * @param proc function to call on each entry
1589  * @param proc_cls closure for proc
1590  * @param emsg where to store an error message (on errors)
1591  * @return GNUNET_OK on success
1592  */
1593 typedef int (*GNUNET_FS_DirectoryScanner)(void *cls,
1594                                           const char *dirname,
1595                                           int do_index,
1596                                           unsigned int anonymity,
1597                                           unsigned int priority,
1598                                           struct GNUNET_TIME_Absolute expirationTime,
1599                                           GNUNET_FS_FileProcessor proc,
1600                                           void *proc_cls,
1601                                           char **emsg);
1602
1603
1604
1605 /**
1606  * Simple, useful default implementation of a directory scanner
1607  * (GNUNET_FS_DirectoryScanner).  This implementation expects to get a
1608  * UNIX filename, will publish all files in the directory except hidden
1609  * files (those starting with a ".").  Metadata will be extracted
1610  * using GNU libextractor; the specific list of plugins should be
1611  * specified in "cls", passing NULL will disable (!)  metadata
1612  * extraction.  Keywords will be derived from the metadata and be
1613  * subject to default canonicalization.  This is strictly a
1614  * convenience function.
1615  *
1616  * @param cls must be of type "struct EXTRACTOR_Extractor*"
1617  * @param dirname name of the directory to scan
1618  * @param do_index should files be indexed or inserted
1619  * @param anonymity desired anonymity level
1620  * @param priority priority for publishing
1621  * @param expirationTime expiration for publication
1622  * @param proc function called on each entry
1623  * @param proc_cls closure for proc
1624  * @param emsg where to store an error message (on errors)
1625  * @return GNUNET_OK on success
1626  */
1627 int
1628 GNUNET_FS_directory_scanner_default (void *cls,
1629                                      const char *dirname,
1630                                      int do_index,
1631                                      unsigned int anonymity,
1632                                      unsigned int priority,
1633                                      struct GNUNET_TIME_Absolute expirationTime,
1634                                      GNUNET_FS_FileProcessor proc,
1635                                      void *proc_cls,
1636                                      char **emsg);
1637
1638
1639 /**
1640  * Create a publish-structure from an existing file hierarchy, inferring
1641  * and organizing keywords and metadata as much as possible.  This
1642  * function primarily performs the recursive build and re-organizes
1643  * keywords and metadata; for automatically getting metadata
1644  * extraction, scanning of directories and creation of the respective
1645  * GNUNET_FS_FileInformation entries the default scanner should be
1646  * passed (GNUNET_FS_directory_scanner_default).  This is strictly a
1647  * convenience function.
1648  *
1649  * @param filename name of the top-level file or directory
1650  * @param scanner function used to get a list of files in a directory
1651  * @param scanner_cls closure for scanner
1652  * @param do_index should files in the hierarchy be indexed?
1653  * @param anonymity what is the desired anonymity level for sharing?
1654  * @param priority what is the priority for OUR node to
1655  *   keep this file available?  Use 0 for maximum anonymity and
1656  *   minimum reliability...
1657  * @param expirationTime when should this content expire?
1658  * @param emsg where to store an error message
1659  * @return publish structure entry for the directory, NULL on error
1660  */
1661 struct GNUNET_FS_FileInformation *
1662 GNUNET_FS_file_information_create_from_directory (void *client_info,
1663                                                   const char *filename,
1664                                                   GNUNET_FS_DirectoryScanner scanner,
1665                                                   void *scanner_cls,
1666                                                   int do_index,
1667                                                   unsigned int anonymity,
1668                                                   unsigned int priority,
1669                                                   struct GNUNET_TIME_Absolute expirationTime,
1670                                                   char **emsg);
1671
1672
1673 /**
1674  * Create an entry for an empty directory in a publish-structure.
1675  * This function should be used by applications for which the
1676  * use of "GNUNET_FS_file_information_create_from_directory"
1677  * is not appropriate.
1678  *
1679  * @param meta metadata for the directory
1680  * @param keywords under which keywords should this directory be available
1681  *         directly; can be NULL
1682  * @param anonymity what is the desired anonymity level for sharing?
1683  * @param priority what is the priority for OUR node to
1684  *   keep this file available?  Use 0 for maximum anonymity and
1685  *   minimum reliability...
1686  * @param expirationTime when should this content expire?
1687  * @return publish structure entry for the directory , NULL on error
1688  */
1689 struct GNUNET_FS_FileInformation *
1690 GNUNET_FS_file_information_create_empty_directory (void *client_info,
1691                                                    const struct GNUNET_CONTAINER_MetaData *meta,
1692                                                    const struct GNUNET_FS_Uri *keywords,
1693                                                    unsigned int anonymity,
1694                                                    unsigned int priority,
1695                                                    struct GNUNET_TIME_Absolute expirationTime);
1696
1697
1698 /**
1699  * Add an entry to a directory in a publish-structure.  Clients
1700  * should never modify publish structures that were passed to
1701  * "GNUNET_FS_publish_start" already.
1702  *
1703  * @param dir the directory
1704  * @param end the entry to add; the entry must not have been
1705  *            added to any other directory at this point and 
1706  *            must not include "dir" in its structure
1707  * @return GNUNET_OK on success, GNUNET_SYSERR on error
1708  */
1709 int
1710 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
1711                                 struct GNUNET_FS_FileInformation *end);
1712
1713
1714 /**
1715  * Inspect a file or directory in a publish-structure.  Clients
1716  * should never modify publish structures that were passed to
1717  * "GNUNET_FS_publish_start" already.  When called on a directory,
1718  * this function will FIRST call "proc" with information about
1719  * the directory itself and then for each of the files in the
1720  * directory (but not for files in subdirectories).  When called
1721  * on a file, "proc" will be called exactly once (with information
1722  * about the specific file).
1723  *
1724  * @param dir the directory
1725  * @param proc function to call on each entry
1726  * @param proc_cls closure for proc
1727  */
1728 void
1729 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
1730                                     GNUNET_FS_FileInformationProcessor proc,
1731                                     void *proc_cls);
1732
1733
1734 /**
1735  * Destroy publish-structure.  Clients should never destroy publish
1736  * structures that were passed to "GNUNET_FS_publish_start" already.
1737  *
1738  * @param fi structure to destroy
1739  * @param cleaner function to call on each entry in the structure
1740  *        (useful to clean up client_info); can be NULL; return
1741  *        values are ignored
1742  * @param cleaner_cls closure for cleaner
1743  */
1744 void
1745 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
1746                                     GNUNET_FS_FileInformationProcessor cleaner,
1747                                     void *cleaner_cls);
1748
1749
1750 /**
1751  * Publish a file or directory.
1752  *
1753  * @param h handle to the file sharing subsystem
1754  * @param ctx initial value to use for the '*ctx'
1755  *        in the callback (for the GNUNET_FS_STATUS_PUBLISH_START event).
1756  * @param fi information about the file or directory structure to publish
1757  * @param namespace namespace to publish the file in, NULL for no namespace
1758  * @param nid identifier to use for the publishd content in the namespace
1759  *        (can be NULL, must be NULL if namespace is NULL)
1760  * @param nuid update-identifier that will be used for future updates 
1761  *        (can be NULL, must be NULL if namespace or nid is NULL)
1762  * @return context that can be used to control the publish operation
1763  */
1764 struct GNUNET_FS_PublishContext *
1765 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1766                        void *ctx,
1767                        const struct GNUNET_FS_FileInformation *fi,
1768                        struct GNUNET_FS_Namespace *namespace,
1769                        const char *nid,
1770                        const char *nuid);
1771
1772
1773 /**
1774  * Stop an upload.  Will abort incomplete uploads (but 
1775  * not remove blocks that have already been publishd) or
1776  * simply clean up the state for completed uploads.
1777  *
1778  * @param sc context for the upload to stop
1779  */
1780 void 
1781 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc);
1782
1783
1784 /**
1785  * Type of a function called by "GNUNET_FS_get_indexed_files".
1786  *
1787  * @param cls closure
1788  * @param filename the name of the file
1789  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
1790  */
1791 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls,
1792                                                const char *filename);
1793
1794
1795 /**
1796  * Iterate over all indexed files.
1797  *
1798  * @param h handle to the file sharing subsystem
1799  * @param iterator function to call on each indexed file
1800  * @param iterator_cls closure for iterator
1801  */
1802 void 
1803 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
1804                              GNUNET_FS_IndexedFileProcessor iterator,
1805                              void *iterator_cls);
1806
1807
1808 /**
1809  * Unindex a file.
1810  *
1811  * @param h handle to the file sharing subsystem
1812  * @param filename file to unindex
1813  * @return NULL on error, otherwise handle 
1814  */
1815 struct GNUNET_FS_UnindexContext *
1816 GNUNET_FS_unindex (struct GNUNET_FS_Handle *h,
1817                    const char *filename);
1818
1819
1820 /**
1821  * Clean up after completion of an unindex operation.
1822  *
1823  * @param uc handle
1824  */
1825 void
1826 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
1827
1828
1829 /**
1830  * Publish an advertismement for a namespace.  
1831  *
1832  * @param h handle to the file sharing subsystem
1833  * @param namespace handle for the namespace that should be advertised
1834  * @param meta meta-data for the namespace advertisement
1835  * @param anonymity for the namespace advertismement
1836  * @param priority for the namespace advertisement
1837  * @param expiration for the namespace advertisement
1838  * @param advertisementURI the keyword (!) URI to advertise the
1839  *        namespace under (we will create a GNUNET_EC_KNBlock)
1840  * @param rootEntry name of the root entry in the namespace (for
1841  *        the namespace advertisement)
1842  *
1843  * @return uri of the advertisement
1844  */
1845 struct GNUNET_FS_Uri *
1846 GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h,
1847                                struct GNUNET_FS_Namespace *namespace,
1848                                const struct GNUNET_MetaData *meta,
1849                                unsigned int anonymity,
1850                                unsigned int priority,
1851                                struct GNUNET_TIME_Absolute expiration,
1852                                const struct GNUNET_FS_Uri *advertisementURI,
1853                                const char *rootEntry);
1854
1855
1856 /**
1857  * Create a namespace with the given name; if one already
1858  * exists, return a handle to the existing namespace.
1859  *
1860  * @param h handle to the file sharing subsystem
1861  * @param name name to use for the namespace
1862  * @return handle to the namespace, NULL on error
1863  */
1864 struct GNUNET_FS_Namespace *
1865 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h,
1866                             const char *name);
1867
1868
1869 /**
1870  * Delete a namespace handle.  Can be used for a clean shutdown (free
1871  * memory) or also to freeze the namespace to prevent further
1872  * insertions by anyone.
1873  *
1874  * @param namespace handle to the namespace that should be deleted / freed
1875  * @param freeze prevents future insertions; creating a namespace
1876  *        with the same name again will create a fresh namespace instead
1877  *
1878  * @return GNUNET_OK on success, GNUNET_SYSERR on error
1879  */
1880 int 
1881 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace,
1882                             int freeze);
1883
1884
1885 /**
1886  * Callback with information about local (!) namespaces.
1887  * Contains the names of the local namespace and the global
1888  * ID.
1889  *
1890  * @param cls closure
1891  * @param name human-readable identifier of the namespace
1892  * @param id hash identifier for the namespace
1893  */
1894 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls,
1895                                                   const char *name,
1896                                                   const GNUNET_HashCode *id);
1897
1898
1899 /**
1900  * Build a list of all available local (!) namespaces The returned
1901  * names are only the nicknames since we only iterate over the local
1902  * namespaces.
1903  *
1904  * @param h handle to the file sharing subsystem
1905  * @param cb function to call on each known namespace
1906  * @param cb_cls closure for cb
1907  */
1908 void 
1909 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
1910                           GNUNET_FS_NamespaceInfoProcessor cb,
1911                           void *cb_cls);
1912
1913
1914 /**
1915  * Function called on updateable identifiers.
1916  *
1917  * @param cls closure
1918  * @param last_id last identifier 
1919  * @param last_uri uri used for the content published under the last_id
1920  * @param last_meta metadata associated with last_uri
1921  * @param next_id identifier that should be used for updates
1922  */
1923 typedef void 
1924 (*GNUNET_FS_IdentifierProcessor)(void *cls,
1925                                  const char *last_id, 
1926                                  const struct GNUNET_FS_Uri *last_uri,
1927                                  const struct GNUNET_CONTAINER_MetaData *last_meta,
1928                                  const char *next_id);
1929
1930
1931 /**
1932  * List all of the identifiers in the namespace for 
1933  * which we could produce an update.
1934  *
1935  * @param namespace namespace to inspect for updateable content
1936  * @param ip function to call on each updateable identifier
1937  * @param ip_cls closure for ip
1938  */
1939 void
1940 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
1941                                      GNUNET_FS_IdentifierProcessor ip, 
1942                                      void *ip_cls);
1943
1944
1945 /**
1946  * Start search for content.
1947  *
1948  * @param h handle to the file sharing subsystem
1949  * @param uri specifies the search parameters; can be
1950  *        a KSK URI or an SKS URI.
1951  * @param anonymity desired level of anonymity
1952  * @return context that can be used to control the search
1953  */
1954 struct GNUNET_FS_SearchContext *
1955 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
1956                         const struct GNUNET_FS_Uri *uri,
1957                         unsigned int anonymity);
1958
1959
1960 /**
1961  * Pause search.  
1962  *
1963  * @param sc context for the search that should be paused
1964  */
1965 void 
1966 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
1967
1968
1969 /**
1970  * Continue paused search.
1971  *
1972  * @param sc context for the search that should be resumed
1973  */
1974 void 
1975 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
1976
1977
1978 /**
1979  * Stop search for content.
1980  *
1981  * @param sc context for the search that should be stopped
1982  */
1983 void 
1984 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
1985
1986
1987 /**
1988  * Download parts of a file.  Note that this will store
1989  * the blocks at the respective offset in the given file.  Also, the
1990  * download is still using the blocking of the underlying FS
1991  * encoding.  As a result, the download may *write* outside of the
1992  * given boundaries (if offset and length do not match the 32k FS
1993  * block boundaries). <p>
1994  *
1995  * This function should be used to focus a download towards a
1996  * particular portion of the file (optimization), not to strictly
1997  * limit the download to exactly those bytes.
1998  *
1999  * @param h handle to the file sharing subsystem
2000  * @param uri the URI of the file (determines what to download); CHK or LOC URI
2001  * @param filename where to store the file, maybe NULL (then no file is
2002  *        created on disk and data must be grabbed from the callbacks)
2003  * @param offset at what offset should we start the download (typically 0)
2004  * @param length how many bytes should be downloaded starting at offset
2005  * @param anonymity anonymity level to use for the download
2006  * @param no_temporaries set to GNUNET_YES to disallow generation of temporary files
2007  * @param recursive should this be a recursive download (useful for directories
2008  *        to automatically trigger download of files in the directories)
2009  * @param parent parent download to associate this download with (use NULL
2010  *        for top-level downloads; useful for manually-triggered recursive downloads)
2011  * @return context that can be used to control this download
2012  */
2013 struct GNUNET_FS_DownloadContext *
2014 GNUNET_FS_file_download_start (struct GNUNET_FS_Handle *h,
2015                                const struct GNUNET_FS_Uri *uri,
2016                                const char *filename,
2017                                unsigned long long offset,
2018                                unsigned long long length,
2019                                unsigned int anonymity,
2020                                int no_temporaries,      
2021                                int recursive,
2022                                struct GNUNET_FS_DownloadContext *parent);
2023
2024
2025 /**
2026  * Stop a download (aborts if download is incomplete).
2027  *
2028  * @param rm handle for the download
2029  * @param do_delete delete files of incomplete downloads
2030  */
2031 void
2032 GNUNET_FS_file_download_stop (struct GNUNET_FS_DownloadContext *rm,
2033                               int do_delete);
2034
2035
2036 /**
2037  * Initialize collection.
2038  *
2039  * @param h handle to the file sharing subsystem
2040  * @param namespace namespace to use for the collection
2041  * @return GNUNET_OK on success, GNUNET_SYSERR if another
2042  *         namespace is already set for our collection
2043  */
2044 int 
2045 GNUNET_FS_collection_start (struct GNUNET_FS_Handle *h,
2046                             struct GNUNET_FS_Namespace *namespace);
2047
2048
2049 /**
2050  * Stop collection.
2051  *
2052  * @param h handle to the file sharing subsystem
2053  * @return GNUNET_OK on success, GNUNET_SYSERR if no collection is active
2054  */
2055 int 
2056 GNUNET_FS_collection_stop (struct GNUNET_FS_Handle *h);
2057
2058
2059 /**
2060  * Are we using a collection?
2061  *
2062  * @param h handle to the file sharing subsystem
2063  * @return NULL if there is no collection,
2064  */
2065 struct GNUNET_FS_Namespace *
2066 GNUNET_FS_collection_get(struct GNUNET_FS_Handle *h);
2067
2068
2069 /**
2070  * Publish an update of the current collection information to the
2071  * network now.  The function has no effect if the collection has not
2072  * changed since the last publication.  If we are currently not
2073  * collecting, this function does nothing.
2074  *
2075  * @param h handle to the file sharing subsystem
2076  */
2077 void GNUNET_FS_collection_publish (struct GNUNET_FS_Handle *h);
2078
2079
2080 /**
2081  * If we are currently building a collection, publish the given file
2082  * information in that collection.  If we are currently not
2083  * collecting, this function does nothing.
2084  *
2085  * @param h handle to the file sharing subsystem
2086  * @param uri uri to add to the collection
2087  * @param meta metadata for the uri
2088  */
2089 void GNUNET_FS_collection_add (const struct GNUNET_FS_Handle *h,
2090                                const struct GNUNET_FS_Uri *uri,
2091                                const struct GNUNET_CONTAINER_MetaData *meta);
2092
2093
2094
2095
2096
2097 /* ******************** Directory API *********************** */
2098
2099
2100 #define GNUNET_FS_DIRECTORY_MIME  "application/gnunet-directory"
2101 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2102 #define GNUNET_FS_DIRECTORY_EXT   ".gnd"
2103
2104 /**
2105  * Does the meta-data claim that this is a directory?
2106  * Checks if the mime-type is that of a GNUnet directory.
2107  *
2108  * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2109  *  we have no mime-type information (treat as 'GNUNET_NO')
2110  */
2111 int 
2112 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData *md);
2113
2114
2115 /**
2116  * Set the MIMETYPE information for the given
2117  * metadata to "application/gnunet-directory".
2118  * 
2119  * @param md metadata to add mimetype to
2120  */
2121 void
2122 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2123
2124
2125 /**
2126  * Function used to process entries in a directory.
2127  *
2128  * @param cls closure
2129  * @param filename name of the file in the directory
2130  * @param uri URI of the file
2131  * @param metadata metadata for the file; metadata for
2132  *        the directory if everything else is NULL/zero
2133  * @param length length of the available data for the file
2134  *           (of type size_t since data must certainly fit
2135  *            into memory; if files are larger than size_t
2136  *            permits, then they will certainly not be
2137  *            embedded with the directory itself).
2138  * @param data data available for the file (length bytes)
2139  */
2140 typedef void (*GNUNET_FS_DirectoryEntryProcessor)(void *cls,
2141                                                   const char *filename,
2142                                                   const struct GNUNET_FS_Uri *uri,
2143                                                   const struct GNUNET_CONTAINER_MetaData *meta,
2144                                                   size_t length,
2145                                                   const void *data);
2146
2147
2148 /**
2149  * Iterate over all entries in a directory.  Note that directories
2150  * are structured such that it is possible to iterate over the
2151  * individual blocks as well as over the entire directory.  Thus
2152  * a client can call this function on the buffer in the
2153  * GNUNET_FS_ProgressCallback.  Also, directories can optionally
2154  * include the contents of (small) files embedded in the directory
2155  * itself; for those files, the processor may be given the
2156  * contents of the file directly by this function.
2157  *
2158  * @param size number of bytes in data
2159  * @param data pointer to the beginning of the directory
2160  * @param offset offset of data in the directory
2161  * @param dep function to call on each entry
2162  * @param dep_cls closure for dep
2163  */
2164 void 
2165 GNUNET_FS_directory_list_contents (size_t size,
2166                                    const void *data,
2167                                    uint64_t offset,
2168                                    GNUNET_FS_DirectoryEntryProcessor dep, 
2169                                    void *dep_cls);
2170
2171
2172 #if 0                           /* keep Emacsens' auto-indent happy */
2173 {
2174 #endif
2175 #ifdef __cplusplus
2176 }
2177 #endif
2178
2179
2180 #endif