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