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