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