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