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