gnunet

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

gnunet_fs_service.h (96004B)


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