a5bdae340c6498583a5f46b5cf11e7079384d16e
[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_URI_KSK_INFIX "ksk/"
63 #define GNUNET_FS_URI_SKS_INFIX "sks/"
64 #define GNUNET_FS_URI_CHK_INFIX "chk/"
65 #define GNUNET_FS_URI_LOC_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_CONTAINER_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 (struct 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 (struct 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  * Handle to one of our namespaces.
634  */
635 struct GNUNET_FS_Namespace;
636
637
638 /**
639  * Handle for controlling an upload.
640  */
641 struct GNUNET_FS_ShareContext;
642
643
644 /**
645  * Handle for controlling an unindexing operation.
646  */
647 struct GNUNET_FS_UnindexContext;
648
649
650 /**
651  * Handle for controlling a search.
652  */
653 struct GNUNET_FS_SearchContext;
654
655
656 /**
657  * Context for controlling a download.
658  */
659 struct GNUNET_FS_DownloadContext;
660
661
662 /**
663  * Handle for detail information about a file that is being shared.
664  * Specifies metadata, keywords, how to get the contents of the file
665  * (i.e. data-buffer in memory, filename on disk) and other options.
666  */
667 struct GNUNET_FS_FileInformation;
668
669
670 /**
671  * Argument given to the progress callback with
672  * information about what is going on.
673  */
674 struct GNUNET_FS_ProgressInfo
675 {  
676
677   /**
678    * Values that depend on the event type.
679    */
680   union {
681     
682     /**
683      * Values for all "GNUNET_FS_STATUS_SHARE_*" events.
684      */
685     struct {
686
687       /**
688        * Context for controlling the upload.
689        */
690       struct GNUNET_FS_ShareContext *sc;
691
692       /**
693        * Information about the file that is being shared.
694        */
695       const struct GNUNET_FS_FileInformation *fi;
696
697       /**
698        * Client context pointer (set the last time
699        * by the client for this operation; initially
700        * NULL on START/RESUME events).
701        */
702       void *cctx;
703
704       /**
705        * Client context pointer for the parent operation
706        * (if this is a file in a directory or a subdirectory).
707        */
708       void *pctx;
709       
710       /**
711        * How large is the file overall?  For directories,
712        * this is only the size of the directory itself,
713        * not of the other files contained within the 
714        * directory.
715        */
716       uint64_t size;
717
718       /**
719        * At what time do we expect to finish the upload?
720        * (will be a value in the past for completed
721        * uploads).
722        */ 
723       struct GNUNET_TIME_Absolute eta;
724
725       /**
726        * How long has this upload been actively running
727        * (excludes times where the upload was suspended).
728        */
729       struct GNUNET_TIME_Relative duration;
730
731       /**
732        * How many bytes have we completed?
733        */
734       uint64_t completed;
735
736       /**
737        * What anonymity level is used for this upload?
738        */
739       unsigned int anonymity;
740
741       /**
742        * Additional values for specific events.
743        */
744       union {
745
746         /**
747          * These values are only valid for
748          * GNUNET_FS_STATUS_SHARE_PROGRESS events.
749          */
750         struct {
751           
752           /**
753            * Data block we just published.
754            */
755           const void *data;
756           
757           /**
758            * At what offset in the file is "data"?
759            */
760           uint64_t offset;
761           
762           /**
763            * Length of the data block.
764            */
765           uint64_t data_len;
766
767         } progress;
768
769         /**
770          * These values are only valid for
771          * GNUNET_FS_STATUS_SHARE_RESUME events.
772          */
773         struct {
774           
775           /**
776            * Error message, NULL if no error was encountered so far.
777            */
778           const char *message;
779
780         } resume;
781
782         /**
783          * These values are only valid for
784          * GNUNET_FS_STATUS_SHARE_ERROR events.
785          */
786         struct {
787           
788           /**
789            * Error message, never NULL.
790            */
791           const char *message;
792
793         } error;
794
795       } specifics;
796
797     } share;
798
799     
800     /**
801      * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
802      */
803     struct {
804
805       /**
806        * Context for controlling the download.
807        */
808       struct GNUNET_FS_DownloadContext *dc;
809
810       /**
811        * Client context pointer (set the last time
812        * by the client for this operation; initially
813        * NULL on START/RESUME events).
814        */
815       void *cctx;
816
817       /**
818        * Client context pointer for the parent operation
819        * (if this is a file in a directory or a subdirectory).
820        */
821       void *pctx;
822       
823       /**
824        * URI used for this download.
825        */
826       const struct GNUNET_FS_Uri *uri;
827       
828       /**
829        * How large is the file overall?  For directories,
830        * this is only the size of the directory itself,
831        * not of the other files contained within the 
832        * directory.
833        */
834       uint64_t size;
835
836       /**
837        * At what time do we expect to finish the download?
838        * (will be a value in the past for completed
839        * uploads).
840        */ 
841       struct GNUNET_TIME_Absolute eta;
842
843       /**
844        * How long has this download been active?
845        */ 
846       struct GNUNET_TIME_Relative duration;
847
848       /**
849        * How many bytes have we completed?
850        */
851       uint64_t completed;
852
853       /**
854        * What anonymity level is used for this download?
855        */
856       unsigned int anonymity;
857
858       /**
859        * Additional values for specific events.
860        */
861       union {
862         
863         /**
864          * These values are only valid for
865          * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
866          */
867         struct {
868   
869           /**
870            * Data block we just obtained.
871            */
872           const void *data;
873           
874           /**
875            * At what offset in the file is "data"?
876            */
877           uint64_t offset;
878           
879           /**
880            * Length of the data block.
881            */
882           uint64_t data_len;
883
884           /**
885            * Amount of trust we offered to get the block.
886            */
887           unsigned int trust_offered;     
888
889         } progress;
890
891         /**
892          * These values are only valid for
893          * GNUNET_FS_STATUS_DOWNLOAD_START events.
894          */
895         struct {
896
897           /**
898            * Known metadata for the download.
899            */
900           const struct GNUNET_MetaData *meta;
901
902         } start;
903
904         /**
905          * These values are only valid for
906          * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
907          */
908         struct {
909
910           /**
911            * Known metadata for the download.
912            */
913           const struct GNUNET_MetaData *meta;
914
915           /**
916            * Error message, NULL if we have not encountered any error yet.
917            */
918           const char *message;
919
920         } resume;
921
922         /**
923          * These values are only valid for
924          * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
925          */
926         struct {
927
928           /**
929            * Error message.
930            */
931           const char *message;
932
933         } error;
934
935       } specifics;
936
937     } download;
938
939     /**
940      * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
941      */
942     struct {
943
944       /**
945        * Context for controlling the search, NULL for
946        * searches that were not explicitly triggered
947        * by the client (i.e., searches for updates in
948        * namespaces).
949        */
950       struct GNUNET_FS_SearchContext *sc;
951
952       /**
953        * Client context pointer (set the last time by the client for
954        * this operation; initially NULL on START/RESUME events).  Note
955        * that this value can only be set on START/RESUME; returning
956        * non-NULL on RESULT/RESUME_RESULT will actually update the
957        * private context for "UPDATE" events.
958        */
959       void *cctx;
960
961       /**
962        * Client parent-context pointer; NULL for top-level searches,
963        * non-NULL for automatically triggered searches for updates in
964        * namespaces.
965        */
966       void *pctx;
967
968       /**
969        * What query is used for this search
970        * (list of keywords or SKS identifier).
971        */
972       const struct GNUNET_FS_Uri *query;
973
974       /**
975        * How long has this search been actively running
976        * (excludes times where the search was paused or
977        * suspended).
978        */
979       struct GNUNET_TIME_Relative duration;
980
981       /**
982        * What anonymity level is used for this search?
983        */
984       unsigned int anonymity;
985
986       /**
987        * How much trust have we been offering for this search
988        * so far?
989        */
990       unsigned int trust_offered;
991
992       /**
993        * Additional values for specific events.
994        */
995       union {
996         
997         /**
998          * These values are only valid for
999          * GNUNET_FS_STATUS_SEARCH_RESULT events.
1000          */
1001         struct {
1002           
1003           /**
1004            * Metadata for the search result.
1005            */
1006           const struct GNUNET_MetaData *meta;
1007
1008           /**
1009            * URI for the search result.
1010            */
1011           const struct GNUNET_FS_Uri *uri;
1012
1013         } result;
1014         
1015         /**
1016          * These values are only valid for
1017          * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1018          */
1019         struct {
1020           
1021           /**
1022            * Metadata for the search result.
1023            */
1024           const struct GNUNET_MetaData *meta;
1025
1026           /**
1027            * URI for the search result.
1028            */
1029           const struct GNUNET_FS_Uri *uri;
1030
1031           /**
1032            * Current availability rank (negative:
1033            * unavailable, positive: available)
1034            */
1035           int availability_rank;
1036  
1037           /**
1038            * On how many total queries is the given
1039            * availability_rank based?
1040            */
1041           unsigned int availabiliy_certainty;
1042
1043           /**
1044            * Updated applicability rank (the larger,
1045            * the better the result fits the search
1046            * criteria).
1047            */
1048           unsigned int applicabiliy_rank;         
1049           
1050         } resume_result;
1051         
1052         /**
1053          * These values are only valid for
1054          * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1055          */
1056         struct {
1057
1058           /**
1059            * Private context set for for this result
1060            * during the "RESULT" event.
1061            */
1062           void *cctx;
1063           
1064           /**
1065            * Metadata for the search result.
1066            */
1067           const struct GNUNET_MetaData *meta;
1068
1069           /**
1070            * URI for the search result.
1071            */
1072           const struct GNUNET_FS_Uri *uri;
1073
1074           /**
1075            * Current availability rank (negative:
1076            * unavailable, positive: available)
1077            */
1078           int availability_rank;
1079  
1080           /**
1081            * On how many total queries is the given
1082            * availability_rank based?
1083            */
1084           unsigned int availabiliy_certainty;
1085
1086           /**
1087            * Updated applicability rank (the larger,
1088            * the better the result fits the search
1089            * criteria).
1090            */
1091           unsigned int applicabiliy_rank;
1092
1093         } update;
1094         
1095         /**
1096          * These values are only valid for
1097          * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1098          * These events are automatically triggered for
1099          * each search result before the 
1100          * GNUNET_FS_STATUS_SEARCH_SUSPEND event.  This
1101          * happens primarily to give the client a chance
1102          * to clean up the "cctx" (if needed).
1103          */
1104         struct {
1105
1106           /**
1107            * Private context set for for this result
1108            * during the "RESULT" event.
1109            */
1110           void *cctx;
1111           
1112           /**
1113            * Metadata for the search result.
1114            */
1115           const struct GNUNET_MetaData *meta;
1116
1117           /**
1118            * URI for the search result.
1119            */
1120           const struct GNUNET_FS_Uri *uri;
1121
1122         } result_suspend;
1123         
1124         /**
1125          * These values are only valid for
1126          * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1127          * These events are automatically triggered for
1128          * each search result before the 
1129          * GNUNET_FS_STATUS_SEARCH_STOPPED event.  This
1130          * happens primarily to give the client a chance
1131          * to clean up the "cctx" (if needed).
1132          */
1133         struct {
1134
1135           /**
1136            * Private context set for for this result
1137            * during the "RESULT" event.
1138            */
1139           void *cctx;
1140           
1141           /**
1142            * Metadata for the search result.
1143            */
1144           const struct GNUNET_MetaData *meta;
1145
1146           /**
1147            * URI for the search result.
1148            */
1149           const struct GNUNET_FS_Uri *uri;
1150
1151         } result_stopped;
1152
1153         /**
1154          * These values are only valid for
1155          * GNUNET_FS_STATUS_SEARCH_RESUME events.
1156          */
1157         struct {
1158
1159           /**
1160            * Error message, NULL if we have not encountered any error yet.
1161            */
1162           const char *message;
1163
1164           /**
1165            * Is this search currently paused?
1166            */
1167           int is_paused;
1168
1169         } resume;
1170
1171         /**
1172          * These values are only valid for
1173          * GNUNET_FS_STATUS_SEARCH_ERROR events.
1174          */
1175         struct {
1176
1177           /**
1178            * Error message.
1179            */
1180           const char *message;
1181
1182         } error;
1183     
1184         /**
1185          * Values for all "GNUNET_FS_STATUS_RESULT_NAMESPACE" events.
1186          */
1187         struct {
1188           
1189           /**
1190            * Handle to the namespace (NULL if it is not a local
1191            * namespace).
1192            */
1193           struct GNUNET_FS_Namespace *ns;
1194           
1195           /**
1196            * Short, human-readable name of the namespace.
1197            */
1198           const char *name;
1199           
1200           /**
1201            * Root identifier for the namespace, can be NULL.
1202            */
1203           const char *root;
1204           
1205           /**
1206            * Metadata for the namespace.
1207            */
1208           const struct GNUNET_CONTAINER_MetaData *meta;
1209           
1210           /**
1211            * Hash-identifier for the namespace.
1212            */
1213           GNUNET_HashCode id;      
1214           
1215         } namespace;
1216
1217       } specifics;
1218
1219     } search;
1220
1221     /**
1222      * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1223      */
1224     struct {
1225
1226       /**
1227        * Context for controlling the unindexing.
1228        */
1229       struct GNUNET_FS_UnindexContext *uc;
1230
1231       /**
1232        * Client context pointer (set the last time
1233        * by the client for this operation; initially
1234        * NULL on START/RESUME events).
1235        */
1236       void *cctx;
1237
1238       /**
1239        * Name of the file that is being unindexed.
1240        */
1241       const char *filename;
1242
1243       /**
1244        * How large is the file overall?
1245        */
1246       uint64_t size;
1247
1248       /**
1249        * At what time do we expect to finish unindexing?
1250        * (will be a value in the past for completed
1251        * unindexing opeations).
1252        */ 
1253       struct GNUNET_TIME_Absolute eta;
1254
1255       /**
1256        * How long has this upload been actively running
1257        * (excludes times where the upload was suspended).
1258        */
1259       struct GNUNET_TIME_Relative duration;
1260
1261       /**
1262        * How many bytes have we completed?
1263        */
1264       uint64_t completed;
1265
1266       /**
1267        * Additional values for specific events.
1268        */
1269       union {
1270
1271         /**
1272          * These values are only valid for
1273          * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1274          */
1275         struct {
1276   
1277           /**
1278            * Data block we just unindexed.
1279            */
1280           const void *data;
1281           
1282           /**
1283            * At what offset in the file is "data"?
1284            */
1285           uint64_t offset;
1286           
1287           /**
1288            * Length of the data block.
1289            */
1290           uint64_t data_len;
1291
1292         } progress;
1293
1294         /**
1295          * These values are only valid for
1296          * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1297          */
1298         struct {
1299
1300           /**
1301            * Error message, NULL if we have not encountered any error yet.
1302            */
1303           const char *message;
1304
1305         } resume;
1306
1307         /**
1308          * These values are only valid for
1309          * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1310          */
1311         struct {
1312
1313           /**
1314            * Error message.
1315            */
1316           const char *message;
1317
1318         } error;
1319
1320       } specifics;
1321
1322     } unindex;
1323
1324   } value;
1325
1326   /**
1327    * Specific status code (determines the event type).
1328    */  
1329   enum GNUNET_FS_Status status;
1330
1331 };
1332
1333
1334 /**
1335  * Notification of FS to a client about the progress of an 
1336  * operation.  Callbacks of this type will be used for uploads,
1337  * downloads and searches.  Some of the arguments depend a bit 
1338  * in their meaning on the context in which the callback is used.
1339  *
1340  * @param cls closure
1341  * @param info details about the event, specifying the event type
1342  *        and various bits about the event
1343  * @return client-context (for the next progress call
1344  *         for this operation; should be set to NULL for
1345  *         SUSPEND and STOPPED events).  The value returned
1346  *         will be passed to future callbacks in the respective
1347  *         field in the GNUNET_FS_ProgressInfo struct.
1348  */
1349 typedef int (*GNUNET_FS_ProgressCallback)
1350   (void *cls,
1351    const struct GNUNET_FS_ProgressInfo *info);
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_FileProcessor)(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                                     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_IndexedFileProcessor) (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_IndexedFileProcessor 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_NamespaceInfoProcessor 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_CONTAINER_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