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