gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

gnunet_fs_service.h (96081B)


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