6143f0630b531185e5b75d99d3edf65a17f23088
[oweals/gnunet.git] / src / include / gnunet_fs_service.h
1 /*
2      This file is part of GNUnet
3      (C) 2004--2013 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 3, 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 #include "gnunet_scheduler_lib.h"
30
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #if 0                           /* keep Emacsens' auto-indent happy */
35 }
36 #endif
37 #endif
38
39 /**
40  * Version number of the implementation.
41  * History:
42  *
43  * 1.x.x: initial version with triple GNUNET_hash and merkle tree
44  * 2.x.x: root node with mime-type, filename and version number
45  * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes
46  * 2.2.x: with directories
47  * 3.0.x: with namespaces
48  * 3.1.x: with namespace meta-data
49  * 3.2.x: with collections
50  * 4.0.x: with expiration, variable meta-data, kblocks
51  * 4.1.x: with new error and configuration handling
52  * 5.0.x: with location URIs
53  * 6.0.0: with support for OR in KSKs
54  * 6.1.x: with simplified namespace support
55  * 9.0.0: CPS-style integrated API
56  * 9.1.1: asynchronous directory scanning
57  * 9.2.0: unified K-Block and S-block format (#2564)
58  */
59 #define GNUNET_FS_VERSION 0x00090200
60
61
62 /* ******************** URI API *********************** */
63
64 #define GNUNET_FS_URI_PREFIX "gnunet://fs/"
65 #define GNUNET_FS_URI_KSK_INFIX "ksk/"
66 #define GNUNET_FS_URI_SKS_INFIX "sks/"
67 #define GNUNET_FS_URI_CHK_INFIX "chk/"
68 #define GNUNET_FS_URI_LOC_INFIX "loc/"
69
70
71 /**
72  * How often do we signal applications that a probe for a particular
73  * search result is running? (used to visualize probes).
74  */
75 #define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
76
77 /**
78  * A Universal Resource Identifier (URI), opaque.
79  */
80 struct GNUNET_FS_Uri;
81
82
83 /**
84  * Identifier for a GNUnet pseudonym (the public key).
85  * Q-point, Q=dp.
86  */
87 struct GNUNET_PseudonymIdentifier
88 {
89   /**
90    * Q consists of an x- and a y-value, each mod p (256 bits),
91    * given here in affine coordinates.
92    */
93   unsigned char q_x[256 / 8];
94
95   /**
96    * Q consists of an x- and a y-value, each mod p (256 bits),
97    * given here in affine coordinates.
98    */
99   unsigned char q_y[256 / 8];
100
101 };
102
103
104 /**
105  * Handle for a pseudonym (private key).
106  */
107 struct GNUNET_PseudonymHandle;
108
109
110 /**
111  * Signature made with a pseudonym (includes the full public key).
112  * The ECDSA signature is a pair (r,s) with r = x1 mod n where
113  * (x1,y1) = kG for "random" k and s = k^{-1}(z + rd) mod n,
114  * where z is derived from the hash of the message that is being
115  * signed.
116  */
117 struct GNUNET_PseudonymSignature
118 {
119   
120   /**
121    * Who created the signature? (public key of the signer), 'd' value in NIST P-256.
122    */
123   struct GNUNET_PseudonymIdentifier signer;
124
125   /**
126    * Binary ECDSA signature data, r-value.  Value is mod n, and n is 256 bits.
127    */
128   unsigned char sig_r[256 / 8];
129
130   /**
131    * Binary ECDSA signature data, s-value.  Value is mod n, and n is 256 bits.
132    */
133   unsigned char sig_s[256 / 8];
134 };
135
136
137 /**
138  * Purpose for signature made with a pseudonym.
139  */
140 struct GNUNET_PseudonymSignaturePurpose
141 {
142   /**
143    * How many bytes are being signed (including this header)?
144    */
145   uint32_t size;
146
147   /**
148    * What is the context/purpose of the signature?
149    */
150   uint32_t purpose;
151 };
152
153
154 /**
155  * Iterator over keywords
156  *
157  * @param cls closure
158  * @param keyword the keyword
159  * @param is_mandatory is the keyword mandatory (in a search)
160  * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
161  */
162 typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword,
163                                           int is_mandatory);
164
165
166
167
168 /**
169  * Create a pseudonym.
170  *
171  * @param filename name of the file to use for storage, NULL for in-memory only
172  * @return handle to the private key of the pseudonym
173  */
174 struct GNUNET_PseudonymHandle *
175 GNUNET_PSEUDONYM_create (const char *filename);
176
177
178 /**
179  * Create a pseudonym, from a file that must already exist.
180  *
181  * @param filename name of the file to use for storage, NULL for in-memory only
182  * @return handle to the private key of the pseudonym
183  */
184 struct GNUNET_PseudonymHandle *
185 GNUNET_PSEUDONYM_create_from_existing_file (const char *filename);
186
187
188 /**
189  * Get the handle for the 'anonymous' pseudonym shared by all users.
190  * That pseudonym uses a fixed 'secret' for the private key; this
191  * construction is useful to make anonymous and pseudonymous APIs
192  * (and packets) indistinguishable on the network.  See #2564.
193  *
194  * @return handle to the (non-secret) private key of the 'anonymous' pseudonym
195  */
196 struct GNUNET_PseudonymHandle *
197 GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle (void);
198
199
200 /**
201  * Destroy a pseudonym handle.  Does NOT remove the private key from
202  * the disk.
203  *
204  * @param ph pseudonym handle to destroy
205  */
206 void
207 GNUNET_PSEUDONYM_destroy (struct GNUNET_PseudonymHandle *ph);
208
209
210 /**
211  * Cryptographically sign some data with the pseudonym.
212  *
213  * @param ph private key used for signing (corresponds to 'x' in #2564)
214  * @param purpose data to sign
215  * @param seed hash of the plaintext of the data that we are signing, 
216  *             used for deterministic PRNG for anonymous signing;
217  *             corresponds to 'k' in section 2.7 of #2564
218  * @param signing_key modifier to apply to the private key for signing;
219  *                    corresponds to 'h' in section 2.3 of #2564.
220  * @param signature where to store the signature
221  * @return GNUNET_SYSERR on failure
222  */
223 int
224 GNUNET_PSEUDONYM_sign (struct GNUNET_PseudonymHandle *ph,
225                        const struct GNUNET_PseudonymSignaturePurpose *purpose,
226                        const struct GNUNET_HashCode *seed,
227                        const struct GNUNET_HashCode *signing_key,
228                        struct GNUNET_PseudonymSignature *signature);
229
230
231 /**
232  * Given a pseudonym and a signing key, derive the corresponding public
233  * key that would be used to verify the resulting signature.
234  *
235  * @param pseudonym the public key (g^x in DSA, dQ in ECDSA)
236  * @param signing_key input to derive 'h' (see section 2.4 of #2564)
237  * @param verification_key resulting public key to verify the signature
238  *        created from the 'ph' of 'pseudonym' and the 'signing_key';
239  *        the value stored here can then be given to GNUNET_PSEUDONYM_verify.
240  * @return GNUNET_OK on success, GNUNET_SYSERR on error
241  */
242 int
243 GNUNET_PSEUDONYM_derive_verification_key (struct GNUNET_PseudonymIdentifier *pseudonym,
244                                           const struct GNUNET_HashCode *signing_key,
245                                           struct GNUNET_PseudonymIdentifier *verification_key);
246
247
248 /**
249  * Verify a signature made with a pseudonym.
250  *
251  * @param purpose data that was signed
252  * @param signature signature to verify
253  * @param verification_key public key to use for checking the signature;
254  *                    corresponds to 'g^(x+h)' in section 2.4 of #2564.
255  * @return GNUNET_OK on success (signature valid, 'pseudonym' set),
256  *         GNUNET_SYSERR if the signature is invalid
257  */
258 int
259 GNUNET_PSEUDONYM_verify (const struct GNUNET_PseudonymSignaturePurpose *purpose,
260                          const struct GNUNET_PseudonymSignature *signature,
261                          const struct GNUNET_PseudonymIdentifier *verification_key);
262
263
264 /**
265  * Get the identifier (public key) of a pseudonym.
266  *
267  * @param ph pseudonym handle with the private key
268  * @param pseudonym pseudonym identifier (set based on 'ph')
269  */
270 void
271 GNUNET_PSEUDONYM_get_identifier (struct GNUNET_PseudonymHandle *ph,
272                                  struct GNUNET_PseudonymIdentifier *pseudonym);
273
274
275
276 /**
277  * Iterator over all known pseudonyms.
278  *
279  * @param cls closure
280  * @param pseudonym hash code of public key of pseudonym
281  * @param name name of the pseudonym (might be NULL)
282  * @param unique_name unique name of the pseudonym (might be NULL)
283  * @param md meta data known about the pseudonym
284  * @param rating the local rating of the pseudonym
285  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
286  */
287 typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls,
288                                           const struct GNUNET_PseudonymIdentifier *pseudonym,
289                                           const char *name,
290                                           const char *unique_name,
291                                           const struct GNUNET_CONTAINER_MetaData *md, 
292                                           int32_t rating);
293
294
295 /**
296  * Change the rank of a pseudonym.
297  *
298  * @param cfg overall configuration
299  * @param pseudonym identity of the pseudonym
300  * @param delta by how much should the rating be changed?
301  * @return new rating of the pseudonym
302  */
303 int
304 GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
305                        const struct GNUNET_PseudonymIdentifier *pseudonym, 
306                        int32_t delta);
307
308
309 /**
310  * Add a pseudonym to the set of known pseudonyms.
311  * For all pseudonym advertisements that we discover
312  * FS should automatically call this function.
313  *
314  * @param cfg overall configuration
315  * @param pseudonym the pseudonym identifier
316  * @param meta metadata for the pseudonym
317  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
318  */
319 int
320 GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
321                       const struct GNUNET_PseudonymIdentifier *pseudonym,
322                       const struct GNUNET_CONTAINER_MetaData *meta);
323
324
325 /**
326  * List all known pseudonyms.
327  *
328  * @param cfg overall configuration
329  * @param iterator function to call for each pseudonym
330  * @param iterator_cls closure for iterator
331  * @return number of pseudonyms found
332  */
333 int
334 GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
335                            GNUNET_PSEUDONYM_Iterator iterator, 
336                            void *iterator_cls);
337
338
339 /**
340  * Handle for a discovery callback registration.
341  */
342 struct GNUNET_PSEUDONYM_DiscoveryHandle;
343
344
345 /**
346  * Register callback to be invoked whenever we discover
347  * a new pseudonym.
348  *
349  * @param cfg our configuration
350  * @param iterator function to invoke on discovery
351  * @param iterator_cls closure for iterator
352  * @return registration handle
353  */
354 struct GNUNET_PSEUDONYM_DiscoveryHandle *
355 GNUNET_PSEUDONYM_discovery_callback_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
356                                               GNUNET_PSEUDONYM_Iterator iterator, 
357                                               void *iterator_cls);
358
359
360 /**
361  * Unregister pseudonym discovery callback.
362  *
363  * @param dh registration to unregister
364  */
365 void
366 GNUNET_PSEUDONYM_discovery_callback_unregister (struct GNUNET_PSEUDONYM_DiscoveryHandle *dh);
367
368
369 /**
370  * Return unique variant of the pseudonym name.  Use after
371  * GNUNET_PSEUDONYM_id_to_name() to make sure that name is unique.
372  *
373  * @param cfg configuration
374  * @param pseudonym cryptographic ID of the pseudonym
375  * @param name name to uniquify
376  * @param suffix if not NULL, filled with the suffix value
377  * @return NULL on failure (should never happen), name on success.
378  *         Free the name with GNUNET_free().
379  */
380 char *
381 GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg,
382                                 const struct GNUNET_PseudonymIdentifier *pseudonym, 
383                                 const char *name, 
384                                 unsigned int *suffix);
385
386
387 /**
388  * Get pseudonym name, metadata and rank. This is a wrapper around
389  * internal read_info() call, and ensures that returned data is not
390  * invalid (not NULL).  Writing back information returned by this
391  * function will give a name "no-name" to pseudonyms that have no
392  * name. This side-effect is unavoidable, but hardly harmful.
393  *
394  * @param cfg configuration
395  * @param pseudonym cryptographic ID of the pseudonym
396  * @param ret_meta a location to store metadata pointer. NULL, if metadata
397  *        is not needed. Destroy with GNUNET_CONTAINER_meta_data_destroy().
398  * @param ret_rank a location to store rank. NULL, if rank not needed.
399  * @param ret_name a location to store human-readable name. Name is not unique.
400  *        NULL, if name is not needed. Free with GNUNET_free().
401  * @param name_is_a_dup is set to GNUNET_YES, if ret_name was filled with
402  *        a duplicate of a "no-name" placeholder
403  * @return GNUNET_OK on success. GNUENT_SYSERR if the data was
404  *         unobtainable (in that case ret_* are filled with placeholders - 
405  *         empty metadata container, rank -1 and a "no-name" name).
406  */
407 int
408 GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
409                            const struct GNUNET_PseudonymIdentifier *pseudonym, 
410                            struct GNUNET_CONTAINER_MetaData **ret_meta,
411                            int32_t *ret_rank, 
412                            char **ret_name, 
413                            int *name_is_a_dup);
414
415
416 /**
417  * Get the pseudonym ID belonging to the given pseudonym name.
418  *
419  * @param cfg configuration to use
420  * @param ns_uname unique (!) human-readable name for the pseudonym
421  * @param pseudonym set to pseudonym ID based on 'ns_uname'
422  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
423  */
424 int
425 GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
426                              const char *ns_uname,
427                              struct GNUNET_PseudonymIdentifier *pseudonym);
428
429
430 /**
431  * Set the pseudonym metadata, rank and name.
432  *
433  * @param cfg overall configuration
434  * @param pseudonym id of the pseudonym
435  * @param name name to set. Must be the non-unique version of it.
436  *        May be NULL, in which case it erases pseudonym's name!
437  * @param md metadata to set
438  *        May be NULL, in which case it erases pseudonym's metadata!
439  * @param rank rank to assign
440  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
441  */
442 int
443 GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
444                            const struct GNUNET_PseudonymIdentifier *pseudonym, 
445                            const char *name,
446                            const struct GNUNET_CONTAINER_MetaData *md, 
447                            int32_t rank);
448
449
450 /**
451  * Remove pseudonym from the set of known pseudonyms.
452  *
453  * @param cfg overall configuration
454  * @param id the pseudonym identifier
455  * @return GNUNET_OK on success, GNUNET_SYSERR on failure
456  */
457 int
458 GNUNET_PSEUDONYM_remove (const struct GNUNET_CONFIGURATION_Handle *cfg,
459     const struct GNUNET_PseudonymIdentifier *id);
460
461
462 /**
463  * Get a unique key from a URI.  This is for putting URIs
464  * into HashMaps.  The key may change between FS implementations.
465  *
466  * @param uri uri to convert to a unique key
467  * @param key wherer to store the unique key
468  */
469 void
470 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode * key);
471
472
473 /**
474  * Convert a URI to a UTF-8 String.
475  *
476  * @param uri uri to convert to a string
477  * @return the UTF-8 string
478  */
479 char *
480 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri);
481
482
483 /**
484  * Convert keyword URI to a human readable format
485  * (i.e. the search query that was used in the first place)
486  *
487  * @param uri ksk uri to convert to a string
488  * @return string with the keywords
489  */
490 char *
491 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri);
492
493
494 /**
495  * Add the given keyword to the set of keywords represented by the URI.
496  * Does nothing if the keyword is already present.
497  *
498  * @param uri ksk uri to modify
499  * @param keyword keyword to add
500  * @param is_mandatory is this keyword mandatory?
501  */
502 void
503 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
504                                int is_mandatory);
505
506
507 /**
508  * Remove the given keyword from the set of keywords represented by the URI.
509  * Does nothing if the keyword is not present.
510  *
511  * @param uri ksk uri to modify
512  * @param keyword keyword to add
513  */
514 void
515 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
516                                   const char *keyword);
517
518
519 /**
520  * Convert a UTF-8 String to a URI.
521  *
522  * @param uri string to parse
523  * @param emsg where to store the parser error message (if any)
524  * @return NULL on error
525  */
526 struct GNUNET_FS_Uri *
527 GNUNET_FS_uri_parse (const char *uri, char **emsg);
528
529 /**
530  * Free URI.
531  *
532  * @param uri uri to free
533  */
534 void
535 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri);
536
537
538 /**
539  * How many keywords are ANDed in this keyword URI?
540  *
541  * @param uri ksk uri to get the number of keywords from
542  * @return 0 if this is not a keyword URI
543  */
544 unsigned int
545 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri);
546
547
548 /**
549  * Iterate over all keywords in this keyword URI.
550  *
551  * @param uri ksk uri to get the keywords from
552  * @param iterator function to call on each keyword
553  * @param iterator_cls closure for iterator
554  * @return -1 if this is not a keyword URI, otherwise number of
555  *   keywords iterated over until iterator aborted
556  */
557 int
558 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
559                                 GNUNET_FS_KeywordIterator iterator,
560                                 void *iterator_cls);
561
562
563 /**
564  * Obtain the identity of the peer offering the data
565  *
566  * @param uri the location URI to inspect
567  * @param peer where to store the identify of the peer (presumably) offering the content
568  * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
569  */
570 int
571 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
572                                      struct GNUNET_PeerIdentity *peer);
573
574
575 /**
576  * Obtain the URI of the content itself.
577  *
578  * @param uri location URI to get the content URI from
579  * @return NULL if argument is not a location URI
580  */
581 struct GNUNET_FS_Uri *
582 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri);
583
584
585 /**
586  * Obtain the expiration of the LOC URI.
587  *
588  * @param uri location URI to get the expiration from
589  * @return expiration time of the URI
590  */
591 struct GNUNET_TIME_Absolute
592 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri);
593
594
595 /**
596  * Construct a location URI (this peer will be used for the location).
597  *
598  * @param baseUri content offered by the sender
599  * @param cfg configuration information (used to find our hostkey)
600  * @param expiration_time how long will the content be offered?
601  * @return the location URI, NULL on error
602  */
603 struct GNUNET_FS_Uri *
604 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
605                           const struct GNUNET_CONFIGURATION_Handle *cfg,
606                           struct GNUNET_TIME_Absolute expiration_time);
607
608
609 /**
610  * Merge the sets of keywords from two KSK URIs.
611  *
612  * @param u1 first uri
613  * @param u2 second uri
614  * @return merged URI, NULL on error
615  */
616 struct GNUNET_FS_Uri *
617 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
618                          const struct GNUNET_FS_Uri *u2);
619
620
621 /**
622  * Duplicate URI.
623  *
624  * @param uri the URI to duplicate
625  * @return copy of the URI
626  */
627 struct GNUNET_FS_Uri *
628 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri);
629
630
631 /**
632  * Create an FS URI from a single user-supplied string of keywords.
633  * The string is broken up at spaces into individual keywords.
634  * Keywords that start with "+" are mandatory.  Double-quotes can
635  * be used to prevent breaking up strings at spaces (and also
636  * to specify non-mandatory keywords starting with "+").
637  *
638  * Keywords must contain a balanced number of double quotes and
639  * double quotes can not be used in the actual keywords (for
640  * example, the string '""foo bar""' will be turned into two
641  * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
642  *
643  * @param keywords the keyword string
644  * @param emsg where to store an error message
645  * @return an FS URI for the given keywords, NULL
646  *  if keywords is not legal (i.e. empty).
647  */
648 struct GNUNET_FS_Uri *
649 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg);
650
651
652 /**
653  * Create an FS URI from a user-supplied command line of keywords.
654  * Arguments should start with "+" to indicate mandatory
655  * keywords.
656  *
657  * @param argc number of keywords
658  * @param argv keywords (double quotes are not required for
659  *             keywords containing spaces; however, double
660  *             quotes are required for keywords starting with
661  *             "+"); there is no mechanism for having double
662  *             quotes in the actual keywords (if the user
663  *             did specifically specify double quotes, the
664  *             caller should convert each double quote
665  *             into two single quotes).
666  * @return an FS URI for the given keywords, NULL
667  *  if keywords is not legal (i.e. empty).
668  */
669 struct GNUNET_FS_Uri *
670 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv);
671
672
673 /**
674  * Test if two URIs are equal.
675  *
676  * @param u1 one of the URIs
677  * @param u2 the other URI
678  * @return GNUNET_YES if the URIs are equal
679  */
680 int
681 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
682                           const struct GNUNET_FS_Uri *u2);
683
684
685 /**
686  * Is this a namespace URI?
687  *
688  * @param uri the uri to check
689  * @return GNUNET_YES if this is an SKS uri
690  */
691 int
692 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri);
693
694
695 /**
696  * Handle to one of our namespaces.
697  */
698 struct GNUNET_FS_Namespace;
699
700
701 /**
702  * Create an SKS URI from a namespace and an identifier.
703  *
704  * @param ns namespace
705  * @param id identifier
706  * @param emsg where to store an error message
707  * @return an FS URI for the given namespace and identifier
708  */
709 struct GNUNET_FS_Uri *
710 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
711                           char **emsg);
712
713
714 /**
715  * Create an SKS URI from a namespace ID and an identifier.
716  *
717  * @param pseudonym pseudonym to use
718  * @param id identifier
719  * @return an FS URI for the given namespace and identifier
720  */
721 struct GNUNET_FS_Uri *
722 GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_PseudonymIdentifier *pseudonym, 
723                                     const char *id);
724
725
726 /**
727  * Get the public key of a namespace from the given
728  * namespace URI.
729  *
730  * @param uri the uri to get the namespace ID from
731  * @param pseudonym where to store the public key of the namespace
732  * @return GNUNET_OK on success
733  */
734 int
735 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
736                                  struct GNUNET_PseudonymIdentifier *pseudonym);
737
738
739 /**
740  * Get the content identifier of an SKS URI.
741  *
742  * @param uri the sks uri
743  * @return NULL on error (not a valid SKS URI)
744  */
745 char *
746 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri);
747
748
749 /**
750  * Convert namespace URI to a human readable format
751  * (using the namespace description, if available).
752  *
753  * @param cfg configuration to use
754  * @param uri SKS uri to convert
755  * @return NULL on error (not an SKS URI)
756  */
757 char *
758 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
759                                    const struct GNUNET_FS_Uri *uri);
760
761
762 /**
763  * Is this a keyword URI?
764  *
765  * @param uri the uri
766  * @return GNUNET_YES if this is a KSK uri
767  */
768 int
769 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri);
770
771
772 /**
773  * Is this a file (or directory) URI?
774  *
775  * @param uri the uri to check
776  * @return GNUNET_YES if this is a CHK uri
777  */
778 int
779 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri);
780
781
782 /**
783  * What is the size of the file that this URI
784  * refers to?
785  *
786  * @param uri the CHK (or LOC) URI to inspect
787  * @return size of the file as specified in the CHK URI
788  */
789 uint64_t
790 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
791
792
793 /**
794  * Is this a location URI?
795  *
796  * @param uri the uri to check
797  * @return GNUNET_YES if this is a LOC uri
798  */
799 int
800 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
801
802
803 /**
804  * Construct a keyword-URI from meta-data (take all entries
805  * in the meta-data and construct one large keyword URI
806  * that lists all keywords that can be found in the meta-data).
807  *
808  * @param md metadata to use
809  * @return NULL on error, otherwise a KSK URI
810  */
811 struct GNUNET_FS_Uri *
812 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
813                                          *md);
814
815
816 /* ******************** command-line option parsing API *********************** */
817
818 /**
819  * Command-line option parser function that allows the user
820  * to specify one or more '-k' options with keywords.  Each
821  * specified keyword will be added to the URI.  A pointer to
822  * the URI must be passed as the "scls" argument.
823  *
824  * @param ctx command line processor context
825  * @param scls must be of type "struct GNUNET_FS_Uri **"
826  * @param option name of the option (typically 'k')
827  * @param value command line argument given
828  * @return GNUNET_OK on success
829  */
830 int
831 GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext
832                                *ctx, void *scls, const char *option,
833                                const char *value);
834
835
836 /**
837  * Command-line option parser function that allows the user to specify
838  * one or more '-m' options with metadata.  Each specified entry of
839  * the form "type=value" will be added to the metadata.  A pointer to
840  * the metadata must be passed as the "scls" argument.
841  *
842  * @param ctx command line processor context
843  * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **"
844  * @param option name of the option (typically 'k')
845  * @param value command line argument given
846  * @return GNUNET_OK on success
847  */
848 int
849 GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext
850                                *ctx, void *scls, const char *option,
851                                const char *value);
852
853
854
855 /* ************************* sharing API ***************** */
856
857
858 /**
859  * Possible status codes used in the callback for the
860  * various file-sharing operations.  On each file (or search),
861  * the callback is guaranteed to be called once with "START"
862  * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED
863  * are optional and depend on the circumstances; parent operations
864  * will be STARTED before child-operations and STOPPED after
865  * their respective child-operations.  START and STOP signals
866  * are typically generated either due to explicit client requests
867  * or because of suspend/resume operations.
868  */
869 enum GNUNET_FS_Status
870 {
871   /**
872    * Notification that we have started to publish a file structure.
873    */
874   GNUNET_FS_STATUS_PUBLISH_START = 0,
875
876   /**
877    * Notification that we have resumed sharing a file structure.
878    */
879   GNUNET_FS_STATUS_PUBLISH_RESUME = 1,
880
881   /**
882    * Notification that we have suspended sharing a file structure.
883    */
884   GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2,
885
886   /**
887    * Notification that we are making progress sharing a file structure.
888    */
889   GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3,
890
891   /**
892    * Notification that an error was encountered  sharing a file structure.
893    * The application will continue to receive resume/suspend events for
894    * this structure until "GNUNET_FS_publish_stop" is called.
895    */
896   GNUNET_FS_STATUS_PUBLISH_ERROR = 4,
897
898   /**
899    * Notification that we completed sharing a file structure.
900    * The application will continue to receive resume/suspend events for
901    * this structure until "GNUNET_FS_publish_stop" is called.
902    */
903   GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5,
904
905   /**
906    * Notification that we have stopped
907    * the process of uploading a file structure; no
908    * futher events will be generated for this action.
909    */
910   GNUNET_FS_STATUS_PUBLISH_STOPPED = 6,
911
912   /**
913    * Notification that we have started this download.
914    */
915   GNUNET_FS_STATUS_DOWNLOAD_START = 7,
916
917   /**
918    * Notification that this download is being resumed.
919    */
920   GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8,
921
922   /**
923    * Notification that this download was suspended.
924    */
925   GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9,
926
927   /**
928    * Notification about progress with this download.
929    */
930   GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10,
931
932   /**
933    * Notification that this download encountered an error.
934    */
935   GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11,
936
937   /**
938    * Notification that this download completed.  Note that for
939    * directories, completion does not imply completion of all files in
940    * the directory.
941    */
942   GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12,
943
944   /**
945    * Notification that this download was stopped
946    * (final event with respect to this action).
947    */
948   GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13,
949
950   /**
951    * Notification that this download is now actively being
952    * pursued (as opposed to waiting in the queue).
953    */
954   GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14,
955
956   /**
957    * Notification that this download is no longer actively
958    * being pursued (back in the queue).
959    */
960   GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15,
961
962   /**
963    * Notification that this download is no longer part of a
964    * recursive download or search but now a 'stand-alone'
965    * download (and may thus need to be moved in the GUI
966    * into a different category).
967    */
968   GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16,
969
970   /**
971    * First event generated when a client requests
972    * a search to begin or when a namespace result
973    * automatically triggers the search for updates.
974    */
975   GNUNET_FS_STATUS_SEARCH_START = 17,
976
977   /**
978    * Last event when a search is being resumed;
979    * note that "GNUNET_FS_SEARCH_START" will not
980    * be generated in this case.
981    */
982   GNUNET_FS_STATUS_SEARCH_RESUME = 18,
983
984   /**
985    * Event generated for each search result
986    * when the respective search is resumed.
987    */
988   GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19,
989
990   /**
991    * Last event when a search is being suspended;
992    * note that "GNUNET_FS_SEARCH_STOPPED" will not
993    * be generated in this case.
994    */
995   GNUNET_FS_STATUS_SEARCH_SUSPEND = 20,
996
997   /**
998    * This search has yielded a result.
999    */
1000   GNUNET_FS_STATUS_SEARCH_RESULT = 21,
1001
1002   /**
1003    * We have discovered a new namespace.
1004    */
1005   GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22,
1006
1007   /**
1008    * We have additional data about the quality
1009    * or availability of a search result.
1010    */
1011   GNUNET_FS_STATUS_SEARCH_UPDATE = 23,
1012
1013   /**
1014    * Signals a problem with this search.
1015    */
1016   GNUNET_FS_STATUS_SEARCH_ERROR = 24,
1017
1018   /**
1019    * Signals that this search was paused.
1020    */
1021   GNUNET_FS_STATUS_SEARCH_PAUSED = 25,
1022
1023   /**
1024    * Signals that this search was continued (unpaused).
1025    */
1026   GNUNET_FS_STATUS_SEARCH_CONTINUED = 26,
1027
1028   /**
1029    * Event generated for each search result
1030    * when the respective search is stopped.
1031    */
1032   GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27,
1033
1034   /**
1035    * Event generated for each search result
1036    * when the respective search is suspended.
1037    */
1038   GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28,
1039
1040   /**
1041    * Last message from a search; this signals
1042    * that there will be no further events associated
1043    * with this search.
1044    */
1045   GNUNET_FS_STATUS_SEARCH_STOPPED = 29,
1046
1047   /**
1048    * Notification that we started to unindex a file.
1049    */
1050   GNUNET_FS_STATUS_UNINDEX_START = 30,
1051
1052   /**
1053    * Notification that we resumed unindexing of a file.
1054    */
1055   GNUNET_FS_STATUS_UNINDEX_RESUME = 31,
1056
1057   /**
1058    * Notification that we suspended unindexing a file.
1059    */
1060   GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32,
1061
1062   /**
1063    * Notification that we made progress unindexing a file.
1064    */
1065   GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33,
1066
1067   /**
1068    * Notification that we encountered an error unindexing
1069    * a file.
1070    */
1071   GNUNET_FS_STATUS_UNINDEX_ERROR = 34,
1072
1073   /**
1074    * Notification that the unindexing of this file
1075    * was completed.
1076    */
1077   GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35,
1078
1079   /**
1080    * Notification that the unindexing of this file
1081    * was stopped (final event for this action).
1082    */
1083   GNUNET_FS_STATUS_UNINDEX_STOPPED = 36
1084 };
1085
1086
1087 /**
1088  * Handle for controlling an upload.
1089  */
1090 struct GNUNET_FS_PublishContext;
1091
1092
1093 /**
1094  * Handle for controlling an unindexing operation.
1095  */
1096 struct GNUNET_FS_UnindexContext;
1097
1098
1099 /**
1100  * Handle for controlling a search.
1101  */
1102 struct GNUNET_FS_SearchContext;
1103
1104
1105 /**
1106  * Result from a search.  Opaque handle to refer to the search
1107  * (typically used when starting a download associated with the search
1108  * result).
1109  */
1110 struct GNUNET_FS_SearchResult;
1111
1112
1113 /**
1114  * Context for controlling a download.
1115  */
1116 struct GNUNET_FS_DownloadContext;
1117
1118
1119 /**
1120  * Handle for detail information about a file that is being publishd.
1121  * Specifies metadata, keywords, how to get the contents of the file
1122  * (i.e. data-buffer in memory, filename on disk) and other options.
1123  */
1124 struct GNUNET_FS_FileInformation;
1125
1126
1127 /**
1128  * Argument given to the progress callback with
1129  * information about what is going on.
1130  */
1131 struct GNUNET_FS_ProgressInfo
1132 {
1133
1134   /**
1135    * Values that depend on the event type.
1136    */
1137   union
1138   {
1139
1140     /**
1141      * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events.
1142      */
1143     struct
1144     {
1145
1146       /**
1147        * Context for controlling the upload.
1148        */
1149       struct GNUNET_FS_PublishContext *pc;
1150
1151       /**
1152        * Information about the file that is being publishd.
1153        */
1154       const struct GNUNET_FS_FileInformation *fi;
1155
1156       /**
1157        * Client context pointer (set the last time by the client for
1158        * this operation; initially NULL on START/RESUME events).
1159        */
1160       void *cctx;
1161
1162       /**
1163        * Client context pointer for the parent operation
1164        * (if this is a file in a directory or a subdirectory).
1165        */
1166       void *pctx;
1167
1168       /**
1169        * Name of the file being published; can be NULL.
1170        */
1171       const char *filename;
1172
1173       /**
1174        * How large is the file overall?  For directories,
1175        * this is only the size of the directory itself,
1176        * not of the other files contained within the
1177        * directory.
1178        */
1179       uint64_t size;
1180
1181       /**
1182        * At what time do we expect to finish the upload?
1183        * (will be a value in the past for completed
1184        * uploads).
1185        */
1186       struct GNUNET_TIME_Relative eta;
1187
1188       /**
1189        * How long has this upload been actively running
1190        * (excludes times where the upload was suspended).
1191        */
1192       struct GNUNET_TIME_Relative duration;
1193
1194       /**
1195        * How many bytes have we completed?
1196        */
1197       uint64_t completed;
1198
1199       /**
1200        * What anonymity level is used for this upload?
1201        */
1202       uint32_t anonymity;
1203
1204       /**
1205        * Additional values for specific events.
1206        */
1207       union
1208       {
1209
1210         /**
1211          * These values are only valid for
1212          * GNUNET_FS_STATUS_PUBLISH_PROGRESS events.
1213          */
1214         struct
1215         {
1216
1217           /**
1218            * Data block we just published.
1219            */
1220           const void *data;
1221
1222           /**
1223            * At what offset in the file is "data"?
1224            */
1225           uint64_t offset;
1226
1227           /**
1228            * Length of the data block.
1229            */
1230           uint64_t data_len;
1231
1232           /**
1233            * Depth of the given block in the tree;
1234            * 0 would be the lowest level (DBLOCKs).
1235            */
1236           unsigned int depth;
1237
1238         } progress;
1239
1240         /**
1241          * These values are only valid for
1242          * GNUNET_FS_STATUS_PUBLISH_RESUME events.
1243          */
1244         struct
1245         {
1246
1247           /**
1248            * Error message, NULL if no error was encountered so far.
1249            */
1250           const char *message;
1251
1252           /**
1253            * URI of the file (if the download had been completed)
1254            */
1255           const struct GNUNET_FS_Uri *chk_uri;
1256
1257         } resume;
1258
1259         /**
1260          * These values are only valid for
1261          * GNUNET_FS_STATUS_PUBLISH_COMPLETED events.
1262          */
1263         struct
1264         {
1265
1266           /**
1267            * URI of the file.
1268            */
1269           const struct GNUNET_FS_Uri *chk_uri;
1270
1271         } completed;
1272
1273         /**
1274          * These values are only valid for
1275          * GNUNET_FS_STATUS_PUBLISH_ERROR events.
1276          */
1277         struct
1278         {
1279
1280           /**
1281            * Error message, never NULL.
1282            */
1283           const char *message;
1284
1285         } error;
1286
1287       } specifics;
1288
1289     } publish;
1290
1291
1292     /**
1293      * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events.
1294      */
1295     struct
1296     {
1297
1298       /**
1299        * Context for controlling the download.
1300        */
1301       struct GNUNET_FS_DownloadContext *dc;
1302
1303       /**
1304        * Client context pointer (set the last time
1305        * by the client for this operation; initially
1306        * NULL on START/RESUME events).
1307        */
1308       void *cctx;
1309
1310       /**
1311        * Client context pointer for the parent operation
1312        * (if this is a file in a directory or a subdirectory).
1313        */
1314       void *pctx;
1315
1316       /**
1317        * Client context pointer for the associated search operation
1318        * (specifically, context pointer for the specific search
1319        * result, not the overall search); only set if this
1320        * download was started from a search result.
1321        */
1322       void *sctx;
1323
1324       /**
1325        * URI used for this download.
1326        */
1327       const struct GNUNET_FS_Uri *uri;
1328
1329       /**
1330        * Name of the file that we are downloading.
1331        */
1332       const char *filename;
1333
1334       /**
1335        * How large is the download overall?  This
1336        * is NOT necessarily the size from the
1337        * URI since we may be doing a partial download.
1338        */
1339       uint64_t size;
1340
1341       /**
1342        * At what time do we expect to finish the download?
1343        * (will be a value in the past for completed
1344        * uploads).
1345        */
1346       struct GNUNET_TIME_Relative eta;
1347
1348       /**
1349        * How long has this download been active?
1350        */
1351       struct GNUNET_TIME_Relative duration;
1352
1353       /**
1354        * How many bytes have we completed?
1355        */
1356       uint64_t completed;
1357
1358       /**
1359        * What anonymity level is used for this download?
1360        */
1361       uint32_t anonymity;
1362
1363       /**
1364        * Is the download currently active.
1365        */
1366       int is_active;
1367
1368       /**
1369        * Additional values for specific events.
1370        */
1371       union
1372       {
1373
1374         /**
1375          * These values are only valid for
1376          * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events.
1377          */
1378         struct
1379         {
1380
1381           /**
1382            * Data block we just obtained, can be NULL (even if
1383            * data_len > 0) if we found the entire block 'intact' on
1384            * disk.  In this case, it is also possible for 'data_len'
1385            * to be larger than an individual (32k) block.
1386            */
1387           const void *data;
1388
1389           /**
1390            * At what offset in the file is "data"?
1391            */
1392           uint64_t offset;
1393
1394           /**
1395            * Length of the data block.
1396            */
1397           uint64_t data_len;
1398
1399           /**
1400            * How much time passed between us asking for this block and
1401            * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown.
1402            */
1403           struct GNUNET_TIME_Relative block_download_duration;
1404
1405           /**
1406            * Depth of the given block in the tree;
1407            * 0 would be the lowest level (DBLOCKS).
1408            */
1409           unsigned int depth;
1410
1411           /**
1412            * How much respect did we offer for downloading this block? (estimate,
1413            * because we might have the same request pending for multiple clients,
1414            * and of course because a transmission may have failed at a lower
1415            * layer).
1416            */
1417           uint32_t respect_offered;
1418
1419           /**
1420            * How often did we transmit the request? (estimate,
1421            * because we might have the same request pending for multiple clients,
1422            * and of course because a transmission may have failed at a lower
1423            * layer).
1424            */
1425           uint32_t num_transmissions;
1426
1427         } progress;
1428
1429         /**
1430          * These values are only valid for
1431          * GNUNET_FS_STATUS_DOWNLOAD_START events.
1432          */
1433         struct
1434         {
1435
1436           /**
1437            * Known metadata for the download.
1438            */
1439           const struct GNUNET_CONTAINER_MetaData *meta;
1440
1441         } start;
1442
1443         /**
1444          * These values are only valid for
1445          * GNUNET_FS_STATUS_DOWNLOAD_RESUME events.
1446          */
1447         struct
1448         {
1449
1450           /**
1451            * Known metadata for the download.
1452            */
1453           const struct GNUNET_CONTAINER_MetaData *meta;
1454
1455           /**
1456            * Error message, NULL if we have not encountered any error yet.
1457            */
1458           const char *message;
1459
1460         } resume;
1461
1462         /**
1463          * These values are only valid for
1464          * GNUNET_FS_STATUS_DOWNLOAD_ERROR events.
1465          */
1466         struct
1467         {
1468
1469           /**
1470            * Error message.
1471            */
1472           const char *message;
1473
1474         } error;
1475
1476       } specifics;
1477
1478     } download;
1479
1480     /**
1481      * Values for all "GNUNET_FS_STATUS_SEARCH_*" events.
1482      */
1483     struct
1484     {
1485
1486       /**
1487        * Context for controlling the search, NULL for
1488        * searches that were not explicitly triggered
1489        * by the client (i.e., searches for updates in
1490        * namespaces).
1491        */
1492       struct GNUNET_FS_SearchContext *sc;
1493
1494       /**
1495        * Client context pointer (set the last time by the client for
1496        * this operation; initially NULL on START/RESUME events).  Note
1497        * that this value can only be set on START/RESUME; returning
1498        * non-NULL on RESULT/RESUME_RESULT will actually update the
1499        * private context for "UPDATE" events.
1500        */
1501       void *cctx;
1502
1503       /**
1504        * Client parent-context pointer; NULL for top-level searches,
1505        * refers to the client context of the associated search result
1506        * for automatically triggered searches for updates in
1507        * namespaces.  In this case, 'presult' refers to that search
1508        * result.
1509        */
1510       void *pctx;
1511
1512       /**
1513        * What query is used for this search
1514        * (list of keywords or SKS identifier).
1515        */
1516       const struct GNUNET_FS_Uri *query;
1517
1518       /**
1519        * How long has this search been actively running
1520        * (excludes times where the search was paused or
1521        * suspended).
1522        */
1523       struct GNUNET_TIME_Relative duration;
1524
1525       /**
1526        * What anonymity level is used for this search?
1527        */
1528       uint32_t anonymity;
1529
1530       /**
1531        * Additional values for specific events.
1532        */
1533       union
1534       {
1535
1536         /**
1537          * These values are only valid for
1538          * GNUNET_FS_STATUS_SEARCH_RESULT events.
1539          */
1540         struct
1541         {
1542
1543           /**
1544            * Metadata for the search result.
1545            */
1546           const struct GNUNET_CONTAINER_MetaData *meta;
1547
1548           /**
1549            * URI for the search result.
1550            */
1551           const struct GNUNET_FS_Uri *uri;
1552
1553           /**
1554            * Handle to the result (for starting downloads).
1555            */
1556           struct GNUNET_FS_SearchResult *result;
1557
1558           /**
1559            * Applicability rank (the larger, the better the result
1560            * fits the search criteria).
1561            */
1562           uint32_t applicability_rank;
1563
1564         } result;
1565
1566         /**
1567          * These values are only valid for
1568          * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events.
1569          */
1570         struct
1571         {
1572
1573           /**
1574            * Metadata for the search result.
1575            */
1576           const struct GNUNET_CONTAINER_MetaData *meta;
1577
1578           /**
1579            * URI for the search result.
1580            */
1581           const struct GNUNET_FS_Uri *uri;
1582
1583           /**
1584            * Handle to the result (for starting downloads).
1585            */
1586           struct GNUNET_FS_SearchResult *result;
1587
1588           /**
1589            * Current availability rank (negative:
1590            * unavailable, positive: available)
1591            */
1592           int32_t availability_rank;
1593
1594           /**
1595            * On how many total queries is the given
1596            * availability_rank based?
1597            */
1598           uint32_t availability_certainty;
1599
1600           /**
1601            * Updated applicability rank (the larger,
1602            * the better the result fits the search
1603            * criteria).
1604            */
1605           uint32_t applicability_rank;
1606
1607         } resume_result;
1608
1609         /**
1610          * These values are only valid for
1611          * GNUNET_FS_STATUS_SEARCH_UPDATE events.
1612          */
1613         struct
1614         {
1615
1616           /**
1617            * Private context set for for this result
1618            * during the "RESULT" event.
1619            */
1620           void *cctx;
1621
1622           /**
1623            * Metadata for the search result.
1624            */
1625           const struct GNUNET_CONTAINER_MetaData *meta;
1626
1627           /**
1628            * URI for the search result.
1629            */
1630           const struct GNUNET_FS_Uri *uri;
1631
1632           /**
1633            * Current availability rank (negative:
1634            * unavailable, positive: available)
1635            */
1636           int32_t availability_rank;
1637
1638           /**
1639            * On how many total queries is the given
1640            * availability_rank based?
1641            */
1642           uint32_t availability_certainty;
1643
1644           /**
1645            * Updated applicability rank (the larger,
1646            * the better the result fits the search
1647            * criteria).
1648            */
1649           uint32_t applicability_rank;
1650
1651           /**
1652            * How long has the current probe been active?
1653            */
1654           struct GNUNET_TIME_Relative current_probe_time;
1655
1656         } update;
1657
1658         /**
1659          * These values are only valid for
1660          * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events.
1661          * These events are automatically triggered for
1662          * each search result before the
1663          * GNUNET_FS_STATUS_SEARCH_SUSPEND event.  This
1664          * happens primarily to give the client a chance
1665          * to clean up the "cctx" (if needed).
1666          */
1667         struct
1668         {
1669
1670           /**
1671            * Private context set for for this result
1672            * during the "RESULT" event.
1673            */
1674           void *cctx;
1675
1676           /**
1677            * Metadata for the search result.
1678            */
1679           const struct GNUNET_CONTAINER_MetaData *meta;
1680
1681           /**
1682            * URI for the search result.
1683            */
1684           const struct GNUNET_FS_Uri *uri;
1685
1686         } result_suspend;
1687
1688         /**
1689          * These values are only valid for
1690          * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events.
1691          * These events are automatically triggered for
1692          * each search result before the
1693          * GNUNET_FS_STATUS_SEARCH_STOPPED event.  This
1694          * happens primarily to give the client a chance
1695          * to clean up the "cctx" (if needed).
1696          */
1697         struct
1698         {
1699
1700           /**
1701            * Private context set for for this result
1702            * during the "RESULT" event.
1703            */
1704           void *cctx;
1705
1706           /**
1707            * Metadata for the search result.
1708            */
1709           const struct GNUNET_CONTAINER_MetaData *meta;
1710
1711           /**
1712            * URI for the search result.
1713            */
1714           const struct GNUNET_FS_Uri *uri;
1715
1716         } result_stopped;
1717
1718         /**
1719          * These values are only valid for
1720          * GNUNET_FS_STATUS_SEARCH_RESUME events.
1721          */
1722         struct
1723         {
1724
1725           /**
1726            * Error message, NULL if we have not encountered any error yet.
1727            */
1728           const char *message;
1729
1730           /**
1731            * Is this search currently paused?
1732            */
1733           int is_paused;
1734
1735         } resume;
1736
1737         /**
1738          * These values are only valid for
1739          * GNUNET_FS_STATUS_SEARCH_ERROR events.
1740          */
1741         struct
1742         {
1743
1744           /**
1745            * Error message.
1746            */
1747           const char *message;
1748
1749         } error;
1750
1751         /**
1752          * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events.
1753          */
1754         struct
1755         {
1756
1757           /**
1758            * Handle to the namespace (NULL if it is not a local
1759            * namespace).
1760            */
1761           struct GNUNET_FS_Namespace *ns;
1762
1763           /**
1764            * Short, human-readable name of the namespace.
1765            */
1766           const char *name;
1767
1768           /**
1769            * Root identifier for the namespace, can be NULL.
1770            */
1771           const char *root;
1772
1773           /**
1774            * Metadata for the namespace.
1775            */
1776           const struct GNUNET_CONTAINER_MetaData *meta;
1777
1778           /**
1779            * Public key of the namespace.
1780            */
1781           struct GNUNET_PseudonymIdentifier pseudonym;
1782
1783         } ns;
1784
1785       } specifics;
1786
1787     } search;
1788
1789     /**
1790      * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
1791      */
1792     struct
1793     {
1794
1795       /**
1796        * Context for controlling the unindexing.
1797        */
1798       struct GNUNET_FS_UnindexContext *uc;
1799
1800       /**
1801        * Client context pointer (set the last time
1802        * by the client for this operation; initially
1803        * NULL on START/RESUME events).
1804        */
1805       void *cctx;
1806
1807       /**
1808        * Name of the file that is being unindexed.
1809        */
1810       const char *filename;
1811
1812       /**
1813        * How large is the file overall?
1814        */
1815       uint64_t size;
1816
1817       /**
1818        * At what time do we expect to finish unindexing?
1819        * (will be a value in the past for completed
1820        * unindexing opeations).
1821        */
1822       struct GNUNET_TIME_Relative eta;
1823
1824       /**
1825        * How long has this upload been actively running
1826        * (excludes times where the upload was suspended).
1827        */
1828       struct GNUNET_TIME_Relative duration;
1829
1830       /**
1831        * How many bytes have we completed?
1832        */
1833       uint64_t completed;
1834
1835       /**
1836        * Additional values for specific events.
1837        */
1838       union
1839       {
1840
1841         /**
1842          * These values are only valid for
1843          * GNUNET_FS_STATUS_UNINDEX_PROGRESS events.
1844          */
1845         struct
1846         {
1847
1848           /**
1849            * Data block we just unindexed.
1850            */
1851           const void *data;
1852
1853           /**
1854            * At what offset in the file is "data"?
1855            */
1856           uint64_t offset;
1857
1858           /**
1859            * Length of the data block.
1860            */
1861           uint64_t data_len;
1862
1863           /**
1864            * Depth of the given block in the tree;
1865            * 0 would be the lowest level (DBLOCKS).
1866            */
1867           unsigned int depth;
1868
1869         } progress;
1870
1871         /**
1872          * These values are only valid for
1873          * GNUNET_FS_STATUS_UNINDEX_RESUME events.
1874          */
1875         struct
1876         {
1877
1878           /**
1879            * Error message, NULL if we have not encountered any error yet.
1880            */
1881           const char *message;
1882
1883         } resume;
1884
1885         /**
1886          * These values are only valid for
1887          * GNUNET_FS_STATUS_UNINDEX_ERROR events.
1888          */
1889         struct
1890         {
1891
1892           /**
1893            * Error message.
1894            */
1895           const char *message;
1896
1897         } error;
1898
1899       } specifics;
1900
1901     } unindex;
1902
1903   } value;
1904
1905   /**
1906    * Specific status code (determines the event type).
1907    */
1908   enum GNUNET_FS_Status status;
1909
1910 };
1911
1912
1913 /**
1914  * Notification of FS to a client about the progress of an
1915  * operation.  Callbacks of this type will be used for uploads,
1916  * downloads and searches.  Some of the arguments depend a bit
1917  * in their meaning on the context in which the callback is used.
1918  *
1919  * @param cls closure
1920  * @param info details about the event, specifying the event type
1921  *        and various bits about the event
1922  * @return client-context (for the next progress call
1923  *         for this operation; should be set to NULL for
1924  *         SUSPEND and STOPPED events).  The value returned
1925  *         will be passed to future callbacks in the respective
1926  *         field in the GNUNET_FS_ProgressInfo struct.
1927  */
1928 typedef void *(*GNUNET_FS_ProgressCallback) (void *cls,
1929                                              const struct GNUNET_FS_ProgressInfo *info);
1930
1931
1932 /**
1933  * General (global) option flags for file-sharing.
1934  */
1935 enum GNUNET_FS_Flags
1936 {
1937     /**
1938      * No special flags set.
1939      */
1940   GNUNET_FS_FLAGS_NONE = 0,
1941
1942     /**
1943      * Is persistence of operations desired?
1944      * (will create SUSPEND/RESUME events).
1945      */
1946   GNUNET_FS_FLAGS_PERSISTENCE = 1,
1947
1948     /**
1949      * Should we automatically trigger probes for search results
1950      * to determine availability?
1951      * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events).
1952      */
1953   GNUNET_FS_FLAGS_DO_PROBES = 2
1954 };
1955
1956
1957 /**
1958  * Options specified in the VARARGs portion of GNUNET_FS_start.
1959  */
1960 enum GNUNET_FS_OPTIONS
1961 {
1962
1963   /**
1964    * Last option in the VARARG list.
1965    */
1966   GNUNET_FS_OPTIONS_END = 0,
1967
1968   /**
1969    * Select the desired amount of parallelism (this option should be
1970    * followed by an "unsigned int" giving the desired maximum number
1971    * of parallel downloads).
1972    */
1973   GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1,
1974
1975   /**
1976    * Maximum number of requests that should be pending at a given
1977    * point in time (invidivual downloads may go above this, but
1978    * if we are above this threshold, we should not activate any
1979    * additional downloads.
1980    */
1981   GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2
1982 };
1983
1984
1985 /**
1986  * Settings for publishing a block (which may of course also
1987  * apply to an entire directory or file).
1988  */
1989 struct GNUNET_FS_BlockOptions
1990 {
1991
1992   /**
1993    * At what time should the block expire?  Data blocks (DBLOCKS and
1994    * IBLOCKS) may still be used even if they are expired (however,
1995    * they'd be removed quickly from the datastore if we are short on
1996    * space), all other types of blocks will no longer be returned
1997    * after they expire.
1998    */
1999   struct GNUNET_TIME_Absolute expiration_time;
2000
2001   /**
2002    * At which anonymity level should the block be shared?
2003    * (0: no anonymity, 1: normal GAP, >1: with cover traffic).
2004    */
2005   uint32_t anonymity_level;
2006
2007   /**
2008    * How important is it for us to store the block?  If we run
2009    * out of space, the highest-priority, non-expired blocks will
2010    * be kept.
2011    */
2012   uint32_t content_priority;
2013
2014   /**
2015    * How often should we try to migrate the block to other peers?
2016    * Only used if "CONTENT_PUSHING" is set to YES, in which case we
2017    * first push each block to other peers according to their
2018    * replication levels.  Once each block has been pushed that many
2019    * times to other peers, blocks are chosen for migration at random.
2020    * Naturally, there is no guarantee that the other peers will keep
2021    * these blocks for any period of time (since they won't have any
2022    * priority or might be too busy to even store the block in the
2023    * first place).
2024    */
2025   uint32_t replication_level;
2026
2027 };
2028
2029
2030 /**
2031  * Return the current year (i.e. '2011').
2032  */
2033 unsigned int
2034 GNUNET_FS_get_current_year (void);
2035
2036
2037 /**
2038  * Convert a year to an expiration time of January 1st of that year.
2039  *
2040  * @param year a year (after 1970, please ;-)).
2041  * @return absolute time for January 1st of that year.
2042  */
2043 struct GNUNET_TIME_Absolute
2044 GNUNET_FS_year_to_time (unsigned int year);
2045
2046
2047 /**
2048  * Convert an expiration time to the respective year (rounds)
2049  *
2050  * @param at absolute time 
2051  * @return year a year (after 1970), 0 on error
2052  */
2053 unsigned int 
2054 GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at);
2055
2056
2057 /**
2058  * Handle to the file-sharing service.
2059  */
2060 struct GNUNET_FS_Handle;
2061
2062
2063 /**
2064  * Setup a connection to the file-sharing service.
2065  *
2066  * @param cfg configuration to use
2067  * @param client_name unique identifier for this client
2068  * @param upcb function to call to notify about FS actions
2069  * @param upcb_cls closure for upcb
2070  * @param flags specific attributes for fs-operations
2071  * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END
2072  * @return NULL on error
2073  */
2074 struct GNUNET_FS_Handle *
2075 GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
2076                  const char *client_name, GNUNET_FS_ProgressCallback upcb,
2077                  void *upcb_cls, enum GNUNET_FS_Flags flags, ...);
2078
2079
2080 /**
2081  * Close our connection with the file-sharing service.
2082  * The callback given to GNUNET_FS_start will no longer be
2083  * called after this function returns.
2084  *
2085  * @param h handle that was returned from GNUNET_FS_start
2086  */
2087 void
2088 GNUNET_FS_stop (struct GNUNET_FS_Handle *h);
2089
2090
2091 /**
2092  * Function called on entries in a GNUNET_FS_FileInformation publish-structure.
2093  *
2094  * @param cls closure
2095  * @param fi the entry in the publish-structure
2096  * @param length length of the file or directory
2097  * @param meta metadata for the file or directory (can be modified)
2098  * @param uri pointer to the keywords that will be used for this entry (can be modified)
2099  * @param bo block options (can be modified)
2100  * @param do_index should we index (can be modified)
2101  * @param client_info pointer to client context set upon creation (can be modified)
2102  * @return GNUNET_OK to continue, GNUNET_NO to remove
2103  *         this entry from the directory, GNUNET_SYSERR
2104  *         to abort the iteration
2105  */
2106 typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls,
2107                                                    struct
2108                                                    GNUNET_FS_FileInformation *
2109                                                    fi, uint64_t length,
2110                                                    struct
2111                                                    GNUNET_CONTAINER_MetaData *
2112                                                    meta,
2113                                                    struct GNUNET_FS_Uri ** uri,
2114                                                    struct GNUNET_FS_BlockOptions
2115                                                    * bo, int *do_index,
2116                                                    void **client_info);
2117
2118
2119 /**
2120  * Obtain the name under which this file information
2121  * structure is stored on disk.  Only works for top-level
2122  * file information structures.
2123  *
2124  * @param s structure to get the filename for
2125  * @return NULL on error, otherwise filename that
2126  *         can be passed to "GNUNET_FS_file_information_recover"
2127  *         to read this fi-struct from disk.
2128  */
2129 const char *
2130 GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
2131
2132
2133 /**
2134  * Obtain the filename from the file information structure.
2135  *
2136  * @param s structure to get the filename for
2137  * @return "filename" field of the structure (can be NULL)
2138  */
2139 const char *
2140 GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s);
2141
2142
2143 /**
2144  * Set the filename in the file information structure.
2145  * If filename was already set, frees it before setting the new one.
2146  * Makes a copy of the argument.
2147  *
2148  * @param s structure to get the filename for
2149  * @param filename filename to set
2150  */
2151 void
2152 GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s,
2153                                          const char *filename);
2154
2155
2156 /**
2157  * Create an entry for a file in a publish-structure.
2158  *
2159  * @param h handle to the file sharing subsystem
2160  * @param client_info initial client-info value for this entry
2161  * @param filename name of the file or directory to publish
2162  * @param keywords under which keywords should this file be available
2163  *         directly; can be NULL
2164  * @param meta metadata for the file
2165  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2166  *                GNUNET_SYSERR for simulation
2167  * @param bo block options
2168  * @return publish structure entry for the file
2169  */
2170 struct GNUNET_FS_FileInformation *
2171 GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
2172                                              void *client_info,
2173                                              const char *filename,
2174                                              const struct GNUNET_FS_Uri
2175                                              *keywords,
2176                                              const struct
2177                                              GNUNET_CONTAINER_MetaData *meta,
2178                                              int do_index,
2179                                              const struct GNUNET_FS_BlockOptions
2180                                              *bo);
2181
2182
2183 /**
2184  * Create an entry for a file in a publish-structure.
2185  *
2186  * @param h handle to the file sharing subsystem
2187  * @param client_info initial client-info value for this entry
2188  * @param length length of the file
2189  * @param data data for the file (should not be used afterwards by
2190  *        the caller; callee will "free")
2191  * @param keywords under which keywords should this file be available
2192  *         directly; can be NULL
2193  * @param meta metadata for the file
2194  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2195  *                GNUNET_SYSERR for simulation
2196  * @param bo block options
2197  * @return publish structure entry for the file
2198  */
2199 struct GNUNET_FS_FileInformation *
2200 GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
2201                                              void *client_info, uint64_t length,
2202                                              void *data,
2203                                              const struct GNUNET_FS_Uri
2204                                              *keywords,
2205                                              const struct
2206                                              GNUNET_CONTAINER_MetaData *meta,
2207                                              int do_index,
2208                                              const struct GNUNET_FS_BlockOptions
2209                                              *bo);
2210
2211
2212 /**
2213  * Function that provides data.
2214  *
2215  * @param cls closure
2216  * @param offset offset to read from; it is possible
2217  *            that the caller might need to go backwards
2218  *            a bit at times; set to UINT64_MAX to tell
2219  *            the reader that we won't be reading for a while
2220  *            (used to close the file descriptor but NOT fully
2221  *             clean up the reader's state); in this case,
2222  *            a value of '0' for max should be ignored
2223  * @param max maximum number of bytes that should be
2224  *            copied to buf; readers are not allowed
2225  *            to provide less data unless there is an error;
2226  *            a value of "0" will be used at the end to allow
2227  *            the reader to clean up its internal state
2228  * @param buf where the reader should write the data
2229  * @param emsg location for the reader to store an error message
2230  * @return number of bytes written, usually "max", 0 on error
2231  */
2232 typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max,
2233                                         void *buf, char **emsg);
2234
2235
2236 /**
2237  * Create an entry for a file in a publish-structure.
2238  *
2239  * @param h handle to the file sharing subsystem
2240  * @param client_info initial client-info value for this entry
2241  * @param length length of the file
2242  * @param reader function that can be used to obtain the data for the file
2243  * @param reader_cls closure for "reader"
2244  * @param keywords under which keywords should this file be available
2245  *         directly; can be NULL
2246  * @param meta metadata for the file
2247  * @param do_index GNUNET_YES for index, GNUNET_NO for insertion,
2248  *                GNUNET_SYSERR for simulation
2249  * @param bo block options
2250  * @return publish structure entry for the file
2251  */
2252 struct GNUNET_FS_FileInformation *
2253 GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
2254                                                void *client_info,
2255                                                uint64_t length,
2256                                                GNUNET_FS_DataReader reader,
2257                                                void *reader_cls,
2258                                                const struct GNUNET_FS_Uri
2259                                                *keywords,
2260                                                const struct
2261                                                GNUNET_CONTAINER_MetaData *meta,
2262                                                int do_index,
2263                                                const struct
2264                                                GNUNET_FS_BlockOptions *bo);
2265
2266
2267 /**
2268  * Create an entry for an empty directory in a publish-structure.
2269  * This function should be used by applications for which the
2270  * use of "GNUNET_FS_file_information_create_from_directory"
2271  * is not appropriate.
2272  *
2273  * @param h handle to the file sharing subsystem
2274  * @param client_info initial client-info value for this entry
2275  * @param keywords under which keywords should this directory be available
2276  *         directly; can be NULL
2277  * @param meta metadata for the directory
2278  * @param bo block options
2279  * @param filename name of the directory; can be NULL
2280  * @return publish structure entry for the directory , NULL on error
2281  */
2282 struct GNUNET_FS_FileInformation *
2283 GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
2284                                                    void *client_info,
2285                                                    const struct GNUNET_FS_Uri
2286                                                    *keywords,
2287                                                    const struct
2288                                                    GNUNET_CONTAINER_MetaData
2289                                                    *meta,
2290                                                    const struct
2291                                                    GNUNET_FS_BlockOptions *bo,
2292                                                    const char *filename);
2293
2294
2295 /**
2296  * Test if a given entry represents a directory.
2297  *
2298  * @param ent check if this FI represents a directory
2299  * @return GNUNET_YES if so, GNUNET_NO if not
2300  */
2301 int
2302 GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation
2303                                          *ent);
2304
2305
2306 /**
2307  * Add an entry to a directory in a publish-structure.  Clients
2308  * should never modify publish structures that were passed to
2309  * "GNUNET_FS_publish_start" already.
2310  *
2311  * @param dir the directory
2312  * @param ent the entry to add; the entry must not have been
2313  *            added to any other directory at this point and
2314  *            must not include "dir" in its structure
2315  * @return GNUNET_OK on success, GNUNET_SYSERR on error
2316  */
2317 int
2318 GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir,
2319                                 struct GNUNET_FS_FileInformation *ent);
2320
2321
2322 /**
2323  * Inspect a file or directory in a publish-structure.  Clients
2324  * should never modify publish structures that were passed to
2325  * "GNUNET_FS_publish_start" already.  When called on a directory,
2326  * this function will FIRST call "proc" with information about
2327  * the directory itself and then for each of the files in the
2328  * directory (but not for files in subdirectories).  When called
2329  * on a file, "proc" will be called exactly once (with information
2330  * about the specific file).
2331  *
2332  * @param dir the directory
2333  * @param proc function to call on each entry
2334  * @param proc_cls closure for proc
2335  */
2336 void
2337 GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir,
2338                                     GNUNET_FS_FileInformationProcessor proc,
2339                                     void *proc_cls);
2340
2341
2342 /**
2343  * Destroy publish-structure.  Clients should never destroy publish
2344  * structures that were passed to "GNUNET_FS_publish_start" already.
2345  *
2346  * @param fi structure to destroy
2347  * @param cleaner function to call on each entry in the structure
2348  *        (useful to clean up client_info); can be NULL; return
2349  *        values are ignored
2350  * @param cleaner_cls closure for cleaner
2351  */
2352 void
2353 GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi,
2354                                     GNUNET_FS_FileInformationProcessor cleaner,
2355                                     void *cleaner_cls);
2356
2357
2358 /**
2359  * Options for publishing.  Compatible options
2360  * can be OR'ed together.
2361  */
2362 enum GNUNET_FS_PublishOptions
2363 {
2364     /**
2365      * No options (use defaults for everything).
2366      */
2367   GNUNET_FS_PUBLISH_OPTION_NONE = 0,
2368
2369     /**
2370      * Simulate publishing.  With this option, no data will be stored
2371      * in the datastore.  Useful for computing URIs from files.
2372      */
2373   GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1
2374 };
2375
2376 /**
2377  * Publish a file or directory.
2378  *
2379  * @param h handle to the file sharing subsystem
2380  * @param fi information about the file or directory structure to publish
2381  * @param ns namespace to publish the file in, NULL for no namespace
2382  * @param nid identifier to use for the publishd content in the namespace
2383  *        (can be NULL, must be NULL if namespace is NULL)
2384  * @param nuid update-identifier that will be used for future updates
2385  *        (can be NULL, must be NULL if namespace or nid is NULL)
2386  * @param options options for the publication
2387  * @return context that can be used to control the publish operation
2388  */
2389 struct GNUNET_FS_PublishContext *
2390 GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
2391                          struct GNUNET_FS_FileInformation *fi,
2392                          struct GNUNET_FS_Namespace *ns, const char *nid,
2393                          const char *nuid,
2394                          enum GNUNET_FS_PublishOptions options);
2395
2396
2397 /**
2398  * Stop a publication.  Will abort incomplete publications (but
2399  * not remove blocks that have already been published) or
2400  * simply clean up the state for completed publications.
2401  * Must NOT be called from within the event callback!
2402  *
2403  * @param pc context for the publication to stop
2404  */
2405 void
2406 GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc);
2407
2408
2409 /**
2410  * Signature of a function called as the continuation of a KBlock or
2411  * SBlock publication.
2412  *
2413  * @param cls closure
2414  * @param uri URI under which the block is now available, NULL on error
2415  * @param emsg error message, NULL on success
2416  */
2417 typedef void (*GNUNET_FS_PublishContinuation) (void *cls,
2418                                                const struct GNUNET_FS_Uri * uri,
2419                                                const char *emsg);
2420
2421
2422 /**
2423  * Handle to cancel publish KSK operation.
2424  */
2425 struct GNUNET_FS_PublishKskContext;
2426
2427
2428 /**
2429  * Publish a KBlock on GNUnet.
2430  *
2431  * @param h handle to the file sharing subsystem
2432  * @param ksk_uri keywords to use
2433  * @param meta metadata to use
2434  * @param uri URI to refer to in the KBlock
2435  * @param bo block options
2436  * @param options publication options
2437  * @param cont continuation
2438  * @param cont_cls closure for cont
2439  * @return NULL on error ('cont' will still be called)
2440  */
2441 struct GNUNET_FS_PublishKskContext *
2442 GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2443                        const struct GNUNET_FS_Uri *ksk_uri,
2444                        const struct GNUNET_CONTAINER_MetaData *meta,
2445                        const struct GNUNET_FS_Uri *uri,
2446                        const struct GNUNET_FS_BlockOptions *bo,
2447                        enum GNUNET_FS_PublishOptions options,
2448                        GNUNET_FS_PublishContinuation cont, void *cont_cls);
2449
2450
2451 /**
2452  * Abort the KSK publishing operation.
2453  *
2454  * @param pkc context of the operation to abort.
2455  */
2456 void
2457 GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc);
2458
2459
2460 /**
2461  * Handle to cancel publish SKS operation.
2462  */
2463 struct GNUNET_FS_PublishSksContext;
2464
2465
2466 /**
2467  * Publish an SBlock on GNUnet.
2468  *
2469  * @param h handle to the file sharing subsystem
2470  * @param ns namespace to publish in
2471  * @param identifier identifier to use
2472  * @param update update identifier to use
2473  * @param meta metadata to use
2474  * @param uri URI to refer to in the SBlock
2475  * @param bo block options
2476  * @param options publication options
2477  * @param cont continuation
2478  * @param cont_cls closure for cont
2479  * @return NULL on error ('cont' will still be called)
2480  */
2481 struct GNUNET_FS_PublishSksContext *
2482 GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2483                        struct GNUNET_FS_Namespace *ns,
2484                        const char *identifier, const char *update,
2485                        const struct GNUNET_CONTAINER_MetaData *meta,
2486                        const struct GNUNET_FS_Uri *uri,
2487                        const struct GNUNET_FS_BlockOptions *bo,
2488                        enum GNUNET_FS_PublishOptions options,
2489                        GNUNET_FS_PublishContinuation cont, void *cont_cls);
2490
2491
2492 /**
2493  * Abort the SKS publishing operation.
2494  *
2495  * @param psc context of the operation to abort.
2496  */
2497 void
2498 GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc);
2499
2500
2501 /**
2502  * Type of a function called by "GNUNET_FS_get_indexed_files".
2503  *
2504  * @param cls closure
2505  * @param filename the name of the file, NULL for end of list
2506  * @param file_id hash of the contents of the indexed file
2507  * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
2508  */
2509 typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename,
2510                                                const struct GNUNET_HashCode * file_id);
2511
2512
2513 /**
2514  * Handle to cancel 'GNUNET_FS_get_indexed_files'.
2515  */
2516 struct GNUNET_FS_GetIndexedContext;
2517
2518
2519 /**
2520  * Iterate over all indexed files.
2521  *
2522  * @param h handle to the file sharing subsystem
2523  * @param iterator function to call on each indexed file
2524  * @param iterator_cls closure for iterator
2525  * @return NULL on error ('iter' is not called)
2526  */
2527 struct GNUNET_FS_GetIndexedContext *
2528 GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h,
2529                              GNUNET_FS_IndexedFileProcessor iterator,
2530                              void *iterator_cls);
2531
2532
2533 /**
2534  * Cancel iteration over all indexed files.
2535  *
2536  * @param gic operation to cancel
2537  */
2538 void
2539 GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic);
2540
2541
2542 /**
2543  * Unindex a file.
2544  *
2545  * @param h handle to the file sharing subsystem
2546  * @param filename file to unindex
2547  * @param cctx initial value for the client context
2548  * @return NULL on error, otherwise handle
2549  */
2550 struct GNUNET_FS_UnindexContext *
2551 GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename,
2552                          void *cctx);
2553
2554
2555 /**
2556  * Clean up after completion of an unindex operation.
2557  *
2558  * @param uc handle
2559  */
2560 void
2561 GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc);
2562
2563
2564 /**
2565  * Create a namespace with the given name; if one already
2566  * exists, return a handle to the existing namespace.
2567  *
2568  * @param h handle to the file sharing subsystem
2569  * @param name name to use for the namespace
2570  * @return handle to the namespace, NULL on error (i.e. invalid filename)
2571  */
2572 struct GNUNET_FS_Namespace *
2573 GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name);
2574
2575
2576 /**
2577  * Open the namespace with the given name; if it does not exist,
2578  * or the key file is corrupted, the function fails.
2579  *
2580  * @param h handle to the file sharing subsystem
2581  * @param name name of the namespace
2582  * @return handle to the namespace,
2583  *         NULL on error (i.e. invalid filename, non-existent filename)
2584  */
2585 struct GNUNET_FS_Namespace *
2586 GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name);
2587
2588
2589 /**
2590  * Rename a local namespace.
2591  *
2592  * @param h handle to the file sharing subsystem
2593  * @param old_name old name of the namespace
2594  * @param new_name new name of the namespace
2595  * @return GNUNET_OK on success, GNUNET_SYSERR on error (see errno for details)
2596  */
2597 int
2598 GNUNET_FS_namespace_rename (struct GNUNET_FS_Handle *h, const char *old_name,
2599     const char *new_name);
2600
2601
2602 /**
2603  * Duplicate a namespace handle.
2604  *
2605  * @param ns namespace handle
2606  * @return duplicated handle to the namespace
2607  */
2608 struct GNUNET_FS_Namespace *
2609 GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns);
2610
2611
2612 /**
2613  * Get hash of the public key of a namespace.
2614  *
2615  * @param ns namespace
2616  * @param id buffer to store the key in
2617  * @return GNUNET_OK on success
2618  *         GNUNET_SYSERR on failure (contents of id remain intact)
2619  */
2620 int
2621 GNUNET_FS_namespace_get_public_identifier (struct GNUNET_FS_Namespace *ns,
2622                                            struct GNUNET_PseudonymIdentifier *id);
2623
2624
2625 /**
2626  * Delete a namespace handle.  Can be used for a clean shutdown (free
2627  * memory) or also to freeze the namespace to prevent further
2628  * insertions by anyone.
2629  *
2630  * @param ns handle to the namespace that should be deleted / freed
2631  * @param freeze prevents future insertions; creating a namespace
2632  *        with the same name again will create a fresh namespace instead
2633  *
2634  * @return GNUNET_OK on success, GNUNET_SYSERR on error
2635  */
2636 int
2637 GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze);
2638
2639
2640 /**
2641  * Callback with information about local (!) namespaces.
2642  * Contains the names of the local namespace and the global
2643  * ID.
2644  *
2645  * @param cls closure
2646  * @param name human-readable identifier of the namespace
2647  * @param id identifier for the namespace
2648  */
2649 typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name,
2650                                                   const struct GNUNET_PseudonymIdentifier *id);
2651
2652
2653 /**
2654  * Build a list of all available local (!) namespaces The returned
2655  * names are only the nicknames since we only iterate over the local
2656  * namespaces.
2657  *
2658  * @param h handle to the file sharing subsystem
2659  * @param cb function to call on each known namespace
2660  * @param cb_cls closure for cb
2661  */
2662 void
2663 GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
2664                           GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls);
2665
2666
2667 /**
2668  * Function called on updateable identifiers.
2669  *
2670  * @param cls closure
2671  * @param last_id last identifier
2672  * @param last_uri uri used for the content published under the last_id
2673  * @param last_meta metadata associated with last_uri
2674  * @param next_id identifier that should be used for updates
2675  */
2676 typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id,
2677                                                const struct GNUNET_FS_Uri *
2678                                                last_uri,
2679                                                const struct
2680                                                GNUNET_CONTAINER_MetaData *
2681                                                last_meta, const char *next_id);
2682
2683
2684 /**
2685  * List all of the identifiers in the namespace for which we could
2686  * produce an update.  Namespace updates form a graph where each node
2687  * has a name.  Each node can have any number of URI/meta-data entries
2688  * which can each be linked to other nodes.  Cycles are possible.
2689  *
2690  * Calling this function with "next_id" NULL will cause the library to
2691  * call "ip" with a root for each strongly connected component of the
2692  * graph (a root being a node from which all other nodes in the Scc
2693  * are reachable).
2694  *
2695  * Calling this function with "next_id" being the name of a node will
2696  * cause the library to call "ip" with all children of the node.  Note
2697  * that cycles within an SCC are possible (including self-loops).
2698  *
2699  * @param ns namespace to inspect for updateable content
2700  * @param next_id ID to look for; use NULL to look for SCC roots
2701  * @param ip function to call on each updateable identifier
2702  * @param ip_cls closure for ip
2703  */
2704 void
2705 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *ns,
2706                                      const char *next_id,
2707                                      GNUNET_FS_IdentifierProcessor ip,
2708                                      void *ip_cls);
2709
2710
2711 /**
2712  * Options for searching.  Compatible options
2713  * can be OR'ed together.
2714  */
2715 enum GNUNET_FS_SearchOptions
2716 {
2717     /**
2718      * No options (use defaults for everything).
2719      */
2720   GNUNET_FS_SEARCH_OPTION_NONE = 0,
2721
2722     /**
2723      * Only search the local host, do not search remote systems (no P2P)
2724      */
2725   GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1
2726 };
2727
2728
2729 /**
2730  * Start search for content.
2731  *
2732  * @param h handle to the file sharing subsystem
2733  * @param uri specifies the search parameters; can be
2734  *        a KSK URI or an SKS URI.
2735  * @param anonymity desired level of anonymity
2736  * @param options options for the search
2737  * @param cctx initial value for the client context
2738  * @return context that can be used to control the search
2739  */
2740 struct GNUNET_FS_SearchContext *
2741 GNUNET_FS_search_start (struct GNUNET_FS_Handle *h,
2742                         const struct GNUNET_FS_Uri *uri, uint32_t anonymity,
2743                         enum GNUNET_FS_SearchOptions options, void *cctx);
2744
2745
2746 /**
2747  * Pause search.
2748  *
2749  * @param sc context for the search that should be paused
2750  */
2751 void
2752 GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc);
2753
2754
2755 /**
2756  * Continue paused search.
2757  *
2758  * @param sc context for the search that should be resumed
2759  */
2760 void
2761 GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc);
2762
2763
2764 /**
2765  * Stop search for content.
2766  *
2767  * @param sc context for the search that should be stopped
2768  */
2769 void
2770 GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2771
2772
2773
2774
2775 /**
2776  * Options for downloading.  Compatible options
2777  * can be OR'ed together.
2778  */
2779 enum GNUNET_FS_DownloadOptions
2780 {
2781     /**
2782      * No options (use defaults for everything).
2783      */
2784   GNUNET_FS_DOWNLOAD_OPTION_NONE = 0,
2785
2786     /**
2787      * Only download from the local host, do not access remote systems (no P2P)
2788      */
2789   GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1,
2790
2791     /**
2792      * Do a recursive download (that is, automatically trigger the
2793      * download of files in directories).
2794      */
2795   GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2,
2796
2797     /**
2798      * Do not append temporary data to
2799      * the target file (for the IBlocks).
2800      */
2801   GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4,
2802
2803     /**
2804      * Internal option used to flag this download as a 'probe' for a
2805      * search result.  Impacts the priority with which the download is
2806      * run and causes signalling callbacks to be done differently.
2807      * Also, probe downloads are not serialized on suspension.  Normal
2808      * clients should not use this!
2809      */
2810   GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31)
2811 };
2812
2813
2814
2815 /**
2816  * Download parts of a file.  Note that this will store
2817  * the blocks at the respective offset in the given file.  Also, the
2818  * download is still using the blocking of the underlying FS
2819  * encoding.  As a result, the download may *write* outside of the
2820  * given boundaries (if offset and length do not match the 32k FS
2821  * block boundaries). <p>
2822  *
2823  * The given range can be used to focus a download towards a
2824  * particular portion of the file (optimization), not to strictly
2825  * limit the download to exactly those bytes.
2826  *
2827  * @param h handle to the file sharing subsystem
2828  * @param uri the URI of the file (determines what to download); CHK or LOC URI
2829  * @param meta known metadata for the file (can be NULL)
2830  * @param filename where to store the file, maybe NULL (then no file is
2831  *        created on disk and data must be grabbed from the callbacks)
2832  * @param tempname where to store temporary file data, not used if filename is non-NULL;
2833  *        can be NULL (in which case we will pick a name if needed); the temporary file
2834  *        may already exist, in which case we will try to use the data that is there and
2835  *        if it is not what is desired, will overwrite it
2836  * @param offset at what offset should we start the download (typically 0)
2837  * @param length how many bytes should be downloaded starting at offset
2838  * @param anonymity anonymity level to use for the download
2839  * @param options various download options
2840  * @param cctx initial value for the client context for this download
2841  * @param parent parent download to associate this download with (use NULL
2842  *        for top-level downloads; useful for manually-triggered recursive downloads)
2843  * @return context that can be used to control this download
2844  */
2845 struct GNUNET_FS_DownloadContext *
2846 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2847                           const struct GNUNET_FS_Uri *uri,
2848                           const struct GNUNET_CONTAINER_MetaData *meta,
2849                           const char *filename, const char *tempname,
2850                           uint64_t offset, uint64_t length, uint32_t anonymity,
2851                           enum GNUNET_FS_DownloadOptions options, void *cctx,
2852                           struct GNUNET_FS_DownloadContext *parent);
2853
2854
2855 /**
2856  * Download parts of a file based on a search result.  The download
2857  * will be associated with the search result (and the association
2858  * will be preserved when serializing/deserializing the state).
2859  * If the search is stopped, the download will not be aborted but
2860  * be 'promoted' to a stand-alone download.
2861  *
2862  * As with the other download function, this will store
2863  * the blocks at the respective offset in the given file.  Also, the
2864  * download is still using the blocking of the underlying FS
2865  * encoding.  As a result, the download may *write* outside of the
2866  * given boundaries (if offset and length do not match the 32k FS
2867  * block boundaries). <p>
2868  *
2869  * The given range can be used to focus a download towards a
2870  * particular portion of the file (optimization), not to strictly
2871  * limit the download to exactly those bytes.
2872  *
2873  * @param h handle to the file sharing subsystem
2874  * @param sr the search result to use for the download (determines uri and
2875  *        meta data and associations)
2876  * @param filename where to store the file, maybe NULL (then no file is
2877  *        created on disk and data must be grabbed from the callbacks)
2878  * @param tempname where to store temporary file data, not used if filename is non-NULL;
2879  *        can be NULL (in which case we will pick a name if needed); the temporary file
2880  *        may already exist, in which case we will try to use the data that is there and
2881  *        if it is not what is desired, will overwrite it
2882  * @param offset at what offset should we start the download (typically 0)
2883  * @param length how many bytes should be downloaded starting at offset
2884  * @param anonymity anonymity level to use for the download
2885  * @param options various download options
2886  * @param cctx initial value for the client context for this download
2887  * @return context that can be used to control this download
2888  */
2889 struct GNUNET_FS_DownloadContext *
2890 GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
2891                                       struct GNUNET_FS_SearchResult *sr,
2892                                       const char *filename,
2893                                       const char *tempname, uint64_t offset,
2894                                       uint64_t length, uint32_t anonymity,
2895                                       enum GNUNET_FS_DownloadOptions options,
2896                                       void *cctx);
2897
2898
2899 /**
2900  * Stop a download (aborts if download is incomplete).
2901  *
2902  * @param dc handle for the download
2903  * @param do_delete delete files of incomplete downloads
2904  */
2905 void
2906 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete);
2907
2908
2909
2910 /* ******************** Directory API *********************** */
2911
2912
2913 #define GNUNET_FS_DIRECTORY_MIME  "application/gnunet-directory"
2914 #define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n"
2915 #define GNUNET_FS_DIRECTORY_EXT   ".gnd"
2916
2917 /**
2918  * Does the meta-data claim that this is a directory?
2919  * Checks if the mime-type is that of a GNUnet directory.
2920  *
2921  * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if
2922  *  we have no mime-type information (treat as 'GNUNET_NO')
2923  */
2924 int
2925 GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2926                                         *md);
2927
2928
2929 /**
2930  * Set the MIMETYPE information for the given
2931  * metadata to "application/gnunet-directory".
2932  *
2933  * @param md metadata to add mimetype to
2934  */
2935 void
2936 GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2937
2938
2939 /**
2940  * Suggest a filename based on given metadata.
2941  *
2942  * @param md given meta data
2943  * @return NULL if meta data is useless for suggesting a filename
2944  */
2945 char *
2946 GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
2947                                       *md);
2948
2949
2950 /**
2951  * Function used to process entries in a directory.
2952  *
2953  * @param cls closure
2954  * @param filename name of the file in the directory
2955  * @param uri URI of the file
2956  * @param metadata metadata for the file; metadata for
2957  *        the directory if everything else is NULL/zero
2958  * @param length length of the available data for the file
2959  *           (of type size_t since data must certainly fit
2960  *            into memory; if files are larger than size_t
2961  *            permits, then they will certainly not be
2962  *            embedded with the directory itself).
2963  * @param data data available for the file (length bytes)
2964  */
2965 typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2966                                                    const char *filename,
2967                                                    const struct GNUNET_FS_Uri *
2968                                                    uri,
2969                                                    const struct
2970                                                    GNUNET_CONTAINER_MetaData *
2971                                                    meta, size_t length,
2972                                                    const void *data);
2973
2974
2975 /**
2976  * Iterate over all entries in a directory.  Note that directories
2977  * are structured such that it is possible to iterate over the
2978  * individual blocks as well as over the entire directory.  Thus
2979  * a client can call this function on the buffer in the
2980  * GNUNET_FS_ProgressCallback.  Also, directories can optionally
2981  * include the contents of (small) files embedded in the directory
2982  * itself; for those files, the processor may be given the
2983  * contents of the file directly by this function.
2984  *
2985  * @param size number of bytes in data
2986  * @param data pointer to the beginning of the directory
2987  * @param offset offset of data in the directory
2988  * @param dep function to call on each entry
2989  * @param dep_cls closure for dep
2990  * @return GNUNET_OK if this could be a block in a directory,
2991  *         GNUNET_NO if this could be part of a directory (but not 100% OK)
2992  *         GNUNET_SYSERR if 'data' does not represent a directory
2993  */
2994 int
2995 GNUNET_FS_directory_list_contents (size_t size, const void *data,
2996                                    uint64_t offset,
2997                                    GNUNET_FS_DirectoryEntryProcessor dep,
2998                                    void *dep_cls);
2999
3000
3001 /**
3002  * Opaque handle to a directory builder.
3003  */
3004 struct GNUNET_FS_DirectoryBuilder;
3005
3006 /**
3007  * Create a directory builder.
3008  *
3009  * @param mdir metadata for the directory
3010  */
3011 struct GNUNET_FS_DirectoryBuilder *
3012 GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
3013                                     *mdir);
3014
3015
3016 /**
3017  * Add an entry to a directory.
3018  *
3019  * @param bld directory to extend
3020  * @param uri uri of the entry (must not be a KSK)
3021  * @param md metadata of the entry
3022  * @param data raw data of the entry, can be NULL, otherwise
3023  *        data must point to exactly the number of bytes specified
3024  *        by the uri
3025  */
3026 void
3027 GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
3028                                  const struct GNUNET_FS_Uri *uri,
3029                                  const struct GNUNET_CONTAINER_MetaData *md,
3030                                  const void *data);
3031
3032
3033 /**
3034  * Finish building the directory.  Frees the
3035  * builder context and returns the directory
3036  * in-memory.
3037  *
3038  * @param bld directory to finish
3039  * @param rsize set to the number of bytes needed
3040  * @param rdata set to the encoded directory
3041  * @return GNUNET_OK on success
3042  */
3043 int
3044 GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld,
3045                                     size_t * rsize, void **rdata);
3046
3047
3048 /* ******************** DirScanner API *********************** */
3049
3050 /**
3051  * Progress reasons of the directory scanner.
3052  */
3053 enum GNUNET_FS_DirScannerProgressUpdateReason
3054 {
3055
3056   /**
3057    * We've started processing a file or directory.
3058    */
3059   GNUNET_FS_DIRSCANNER_FILE_START = 0,
3060
3061   /**
3062    * We're having trouble accessing a file (soft-error); it will
3063    * be ignored.
3064    */
3065   GNUNET_FS_DIRSCANNER_FILE_IGNORED,
3066
3067   /**
3068    * We've found all files (in the pre-pass).
3069    */
3070   GNUNET_FS_DIRSCANNER_ALL_COUNTED,
3071
3072   /**
3073    * We've finished extracting meta data from a file.
3074    */
3075   GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED,
3076
3077   /**
3078    * Last call to the progress function: we have finished scanning
3079    * the directory.
3080    */
3081   GNUNET_FS_DIRSCANNER_FINISHED,
3082
3083   /**
3084    * There was an internal error.  Application should abort the scan.
3085    */
3086   GNUNET_FS_DIRSCANNER_INTERNAL_ERROR
3087
3088 };
3089
3090
3091 /**
3092  * Function called over time as the directory scanner makes
3093  * progress on the job at hand.
3094  *
3095  * @param cls closure
3096  * @param filename which file we are making progress on
3097  * @param is_directory GNUNET_YES if this is a directory,
3098  *                     GNUNET_NO if this is a file
3099  *                     GNUNET_SYSERR if it is neither (or unknown)
3100  * @param reason kind of progress we are making
3101  */
3102 typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls, 
3103                                                       const char *filename,
3104                                                       int is_directory, 
3105                                                       enum GNUNET_FS_DirScannerProgressUpdateReason reason);
3106
3107
3108 /**
3109  * A node of a directory tree (produced by dirscanner)
3110  */
3111 struct GNUNET_FS_ShareTreeItem
3112 {
3113   /**
3114    * This is a doubly-linked list
3115    */
3116   struct GNUNET_FS_ShareTreeItem *prev;
3117
3118   /**
3119    * This is a doubly-linked list
3120    */
3121   struct GNUNET_FS_ShareTreeItem *next;
3122
3123   /**
3124    * This is a doubly-linked tree
3125    * NULL for top-level entries.
3126    */
3127   struct GNUNET_FS_ShareTreeItem *parent;
3128
3129   /**
3130    * This is a doubly-linked tree
3131    * NULL for files and empty directories
3132    */
3133   struct GNUNET_FS_ShareTreeItem *children_head;
3134
3135   /**
3136    * This is a doubly-linked tree
3137    * NULL for files and empty directories
3138    */
3139   struct GNUNET_FS_ShareTreeItem *children_tail;
3140
3141   /**
3142    * Metadata for this file or directory
3143    */
3144   struct GNUNET_CONTAINER_MetaData *meta;
3145
3146   /**
3147    * Keywords for this file or directory (derived from metadata).
3148    */
3149   struct GNUNET_FS_Uri *ksk_uri;
3150
3151   /**
3152    * Name of the file/directory
3153    */
3154   char *filename;
3155
3156   /**
3157    * Base name of the file/directory.
3158    */
3159   char *short_filename;
3160
3161   /**
3162    * GNUNET_YES if this is a directory
3163    */
3164   int is_directory;
3165
3166 };
3167
3168
3169 /**
3170  * Opaqe handle to an asynchronous directory scanning activity.
3171  */
3172 struct GNUNET_FS_DirScanner;
3173
3174
3175 /**
3176  * Start a directory scanner.
3177  *
3178  * @param filename name of the directory to scan
3179  * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree)
3180  * @param ex if not NULL, must be a list of extra plugins for extractor
3181  * @param cb the callback to call when there are scanning progress messages
3182  * @param cb_cls closure for 'cb'
3183  * @return directory scanner object to be used for controlling the scanner
3184  */
3185 struct GNUNET_FS_DirScanner *
3186 GNUNET_FS_directory_scan_start (const char *filename,
3187                                 int disable_extractor, 
3188                                 const char *ex,
3189                                 GNUNET_FS_DirScannerProgressCallback cb, 
3190                                 void *cb_cls);
3191
3192
3193 /**
3194  * Abort the scan.    Must not be called from within the progress_callback
3195  * function.
3196  *
3197  * @param ds directory scanner structure
3198  */
3199 void
3200 GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds);
3201
3202
3203 /**
3204  * Obtain the result of the scan after the scan has signalled
3205  * completion.  Must not be called prior to completion.  The 'ds' is
3206  * freed as part of this call.
3207  *
3208  * @param ds directory scanner structure
3209  * @return the results of the scan (a directory tree)
3210  */
3211 struct GNUNET_FS_ShareTreeItem *
3212 GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds);
3213
3214
3215 /**
3216  * Process a share item tree, moving frequent keywords up and
3217  * copying frequent metadata up.
3218  *
3219  * @param toplevel toplevel directory in the tree, returned by the scanner
3220  */
3221 void
3222 GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
3223
3224
3225 /**
3226  * Release memory of a share item tree.
3227  *
3228  * @param toplevel toplevel of the tree to be freed
3229  */
3230 void
3231 GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
3232
3233
3234 #if 0                           /* keep Emacsens' auto-indent happy */
3235 {
3236 #endif
3237 #ifdef __cplusplus
3238 }
3239 #endif
3240
3241
3242 #endif