aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_fs_service.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_fs_service.h')
-rw-r--r--src/include/gnunet_fs_service.h517
1 files changed, 486 insertions, 31 deletions
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 96936bad2..a05e07ac5 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -18,6 +18,9 @@
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20/** 20/**
21 * @addtogroup fs_l2 File sharing and support services/libraries
22 * @{
23 *
21 * @author Christian Grothoff 24 * @author Christian Grothoff
22 * 25 *
23 * @file 26 * @file
@@ -33,6 +36,8 @@
33#ifndef GNUNET_FS_LIB_H 36#ifndef GNUNET_FS_LIB_H
34#define GNUNET_FS_LIB_H 37#define GNUNET_FS_LIB_H
35 38
39
40#include "gnunet_common.h"
36#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
37 42
38#ifdef __cplusplus 43#ifdef __cplusplus
@@ -66,6 +71,106 @@ extern "C"
66 */ 71 */
67#define GNUNET_FS_VERSION 0x00090300 72#define GNUNET_FS_VERSION 0x00090300
68 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 */
86enum 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 */
116enum 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 */
159typedef 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
69 174
70/* ******************** URI API *********************** */ 175/* ******************** URI API *********************** */
71 176
@@ -88,6 +193,12 @@ extern "C"
88 */ 193 */
89struct GNUNET_FS_Uri; 194struct GNUNET_FS_Uri;
90 195
196/**
197 * @ingroup metadata
198 * Meta data to associate with a file, directory or namespace.
199 */
200struct GNUNET_FS_MetaData;
201
91 202
92/** 203/**
93 * Iterator over keywords 204 * Iterator over keywords
@@ -108,7 +219,7 @@ typedef int
108 * into HashMaps. The key may change between FS implementations. 219 * into HashMaps. The key may change between FS implementations.
109 * 220 *
110 * @param uri uri to convert to a unique key 221 * @param uri uri to convert to a unique key
111 * @param key wherer to store the unique key 222 * @param key where to store the unique key
112 * @return #GNUNET_OK on success 223 * @return #GNUNET_OK on success
113 */ 224 */
114int 225int
@@ -414,6 +525,17 @@ GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri);
414 525
415 526
416/** 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 */
534const struct GNUNET_HashCode*
535GNUNET_FS_uri_chk_get_file_hash (const struct GNUNET_FS_Uri *uri);
536
537
538/**
417 * Is this a location URI? 539 * Is this a location URI?
418 * 540 *
419 * @param uri the uri to check 541 * @param uri the uri to check
@@ -432,7 +554,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
432 * @return NULL on error, otherwise a KSK URI 554 * @return NULL on error, otherwise a KSK URI
433 */ 555 */
434struct GNUNET_FS_Uri * 556struct GNUNET_FS_Uri *
435GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData 557GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_FS_MetaData
436 *md); 558 *md);
437 559
438 560
@@ -461,14 +583,14 @@ GNUNET_FS_GETOPT_KEYWORDS (char shortName,
461 * @param name long name of the option 583 * @param name long name of the option
462 * @param argumentHelp help text for the option argument 584 * @param argumentHelp help text for the option argument
463 * @param description long help text for the option 585 * @param description long help text for the option
464 * @param[out] metadata set to the desired value 586 * @param[out] meta metadata set to the desired value
465 */ 587 */
466struct GNUNET_GETOPT_CommandLineOption 588struct GNUNET_GETOPT_CommandLineOption
467GNUNET_FS_GETOPT_METADATA (char shortName, 589GNUNET_FS_GETOPT_METADATA (char shortName,
468 const char *name, 590 const char *name,
469 const char *argumentHelp, 591 const char *argumentHelp,
470 const char *description, 592 const char *description,
471 struct GNUNET_CONTAINER_MetaData **meta); 593 struct GNUNET_FS_MetaData **meta);
472 594
473/** 595/**
474 * Command-line option parser function that allows the user to specify 596 * Command-line option parser function that allows the user to specify
@@ -477,7 +599,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
477 * the metadata must be passed as the "scls" argument. 599 * the metadata must be passed as the "scls" argument.
478 * 600 *
479 * @param ctx command line processor context 601 * @param ctx command line processor context
480 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **` 602 * @param scls must be of type `struct GNUNET_FS_MetaData **`
481 * @param option name of the option (typically 'k') 603 * @param option name of the option (typically 'k')
482 * @param value command line argument given 604 * @param value command line argument given
483 * @return #GNUNET_OK on success 605 * @return #GNUNET_OK on success
@@ -1095,7 +1217,7 @@ struct GNUNET_FS_ProgressInfo
1095 /** 1217 /**
1096 * Known metadata for the download. 1218 * Known metadata for the download.
1097 */ 1219 */
1098 const struct GNUNET_CONTAINER_MetaData *meta; 1220 const struct GNUNET_FS_MetaData *meta;
1099 } start; 1221 } start;
1100 1222
1101 /** 1223 /**
@@ -1107,7 +1229,7 @@ struct GNUNET_FS_ProgressInfo
1107 /** 1229 /**
1108 * Known metadata for the download. 1230 * Known metadata for the download.
1109 */ 1231 */
1110 const struct GNUNET_CONTAINER_MetaData *meta; 1232 const struct GNUNET_FS_MetaData *meta;
1111 1233
1112 /** 1234 /**
1113 * Error message, NULL if we have not encountered any error yet. 1235 * Error message, NULL if we have not encountered any error yet.
@@ -1192,7 +1314,7 @@ struct GNUNET_FS_ProgressInfo
1192 /** 1314 /**
1193 * Metadata for the search result. 1315 * Metadata for the search result.
1194 */ 1316 */
1195 const struct GNUNET_CONTAINER_MetaData *meta; 1317 const struct GNUNET_FS_MetaData *meta;
1196 1318
1197 /** 1319 /**
1198 * URI for the search result. 1320 * URI for the search result.
@@ -1220,7 +1342,7 @@ struct GNUNET_FS_ProgressInfo
1220 /** 1342 /**
1221 * Metadata for the search result. 1343 * Metadata for the search result.
1222 */ 1344 */
1223 const struct GNUNET_CONTAINER_MetaData *meta; 1345 const struct GNUNET_FS_MetaData *meta;
1224 1346
1225 /** 1347 /**
1226 * URI for the search result. 1348 * URI for the search result.
@@ -1267,7 +1389,7 @@ struct GNUNET_FS_ProgressInfo
1267 /** 1389 /**
1268 * Metadata for the search result. 1390 * Metadata for the search result.
1269 */ 1391 */
1270 const struct GNUNET_CONTAINER_MetaData *meta; 1392 const struct GNUNET_FS_MetaData *meta;
1271 1393
1272 /** 1394 /**
1273 * URI for the search result. 1395 * URI for the search result.
@@ -1319,7 +1441,7 @@ struct GNUNET_FS_ProgressInfo
1319 /** 1441 /**
1320 * Metadata for the search result. 1442 * Metadata for the search result.
1321 */ 1443 */
1322 const struct GNUNET_CONTAINER_MetaData *meta; 1444 const struct GNUNET_FS_MetaData *meta;
1323 1445
1324 /** 1446 /**
1325 * URI for the search result. 1447 * URI for the search result.
@@ -1347,7 +1469,7 @@ struct GNUNET_FS_ProgressInfo
1347 /** 1469 /**
1348 * Metadata for the search result. 1470 * Metadata for the search result.
1349 */ 1471 */
1350 const struct GNUNET_CONTAINER_MetaData *meta; 1472 const struct GNUNET_FS_MetaData *meta;
1351 1473
1352 /** 1474 /**
1353 * URI for the search result. 1475 * URI for the search result.
@@ -1402,7 +1524,7 @@ struct GNUNET_FS_ProgressInfo
1402 /** 1524 /**
1403 * Metadata for the namespace. 1525 * Metadata for the namespace.
1404 */ 1526 */
1405 const struct GNUNET_CONTAINER_MetaData *meta; 1527 const struct GNUNET_FS_MetaData *meta;
1406 1528
1407 /** 1529 /**
1408 * Public key of the namespace. 1530 * Public key of the namespace.
@@ -1702,7 +1824,7 @@ typedef int
1702(*GNUNET_FS_FileInformationProcessor) (void *cls, 1824(*GNUNET_FS_FileInformationProcessor) (void *cls,
1703 struct GNUNET_FS_FileInformation *fi, 1825 struct GNUNET_FS_FileInformation *fi,
1704 uint64_t length, 1826 uint64_t length,
1705 struct GNUNET_CONTAINER_MetaData *meta, 1827 struct GNUNET_FS_MetaData *meta,
1706 struct GNUNET_FS_Uri **uri, 1828 struct GNUNET_FS_Uri **uri,
1707 struct GNUNET_FS_BlockOptions *bo, 1829 struct GNUNET_FS_BlockOptions *bo,
1708 int *do_index, 1830 int *do_index,
@@ -1729,7 +1851,8 @@ GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s);
1729 * @return "filename" field of the structure (can be NULL) 1851 * @return "filename" field of the structure (can be NULL)
1730 */ 1852 */
1731const char * 1853const char *
1732GNUNET_FS_file_information_get_filename (const struct GNUNET_FS_FileInformation *s); 1854GNUNET_FS_file_information_get_filename (const struct
1855 GNUNET_FS_FileInformation *s);
1733 1856
1734 1857
1735/** 1858/**
@@ -1766,7 +1889,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1766 const struct 1889 const struct
1767 GNUNET_FS_Uri *keywords, 1890 GNUNET_FS_Uri *keywords,
1768 const struct 1891 const struct
1769 GNUNET_CONTAINER_MetaData *meta, 1892 GNUNET_FS_MetaData *meta,
1770 int do_index, 1893 int do_index,
1771 const struct 1894 const struct
1772 GNUNET_FS_BlockOptions *bo); 1895 GNUNET_FS_BlockOptions *bo);
@@ -1796,7 +1919,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1796 const struct 1919 const struct
1797 GNUNET_FS_Uri *keywords, 1920 GNUNET_FS_Uri *keywords,
1798 const struct 1921 const struct
1799 GNUNET_CONTAINER_MetaData *meta, 1922 GNUNET_FS_MetaData *meta,
1800 int do_index, 1923 int do_index,
1801 const struct 1924 const struct
1802 GNUNET_FS_BlockOptions *bo); 1925 GNUNET_FS_BlockOptions *bo);
@@ -1855,7 +1978,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1855 const struct GNUNET_FS_Uri 1978 const struct GNUNET_FS_Uri
1856 *keywords, 1979 *keywords,
1857 const struct 1980 const struct
1858 GNUNET_CONTAINER_MetaData *meta, 1981 GNUNET_FS_MetaData *meta,
1859 int do_index, 1982 int do_index,
1860 const struct 1983 const struct
1861 GNUNET_FS_BlockOptions *bo); 1984 GNUNET_FS_BlockOptions *bo);
@@ -1879,7 +2002,7 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1879 const struct GNUNET_FS_Uri 2002 const struct GNUNET_FS_Uri
1880 *keywords, 2003 *keywords,
1881 const struct 2004 const struct
1882 GNUNET_CONTAINER_MetaData 2005 GNUNET_FS_MetaData
1883 *meta, 2006 *meta,
1884 const struct 2007 const struct
1885 GNUNET_FS_BlockOptions *bo, 2008 GNUNET_FS_BlockOptions *bo,
@@ -2038,7 +2161,7 @@ struct GNUNET_FS_PublishKskContext;
2038struct GNUNET_FS_PublishKskContext * 2161struct GNUNET_FS_PublishKskContext *
2039GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 2162GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2040 const struct GNUNET_FS_Uri *ksk_uri, 2163 const struct GNUNET_FS_Uri *ksk_uri,
2041 const struct GNUNET_CONTAINER_MetaData *meta, 2164 const struct GNUNET_FS_MetaData *meta,
2042 const struct GNUNET_FS_Uri *uri, 2165 const struct GNUNET_FS_Uri *uri,
2043 const struct GNUNET_FS_BlockOptions *bo, 2166 const struct GNUNET_FS_BlockOptions *bo,
2044 enum GNUNET_FS_PublishOptions options, 2167 enum GNUNET_FS_PublishOptions options,
@@ -2080,7 +2203,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2080 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 2203 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2081 const char *identifier, 2204 const char *identifier,
2082 const char *update, 2205 const char *update,
2083 const struct GNUNET_CONTAINER_MetaData *meta, 2206 const struct GNUNET_FS_MetaData *meta,
2084 const struct GNUNET_FS_Uri *uri, 2207 const struct GNUNET_FS_Uri *uri,
2085 const struct GNUNET_FS_BlockOptions *bo, 2208 const struct GNUNET_FS_BlockOptions *bo,
2086 enum GNUNET_FS_PublishOptions options, 2209 enum GNUNET_FS_PublishOptions options,
@@ -2176,7 +2299,7 @@ typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2176 const struct 2299 const struct
2177 GNUNET_FS_Uri *last_uri, 2300 GNUNET_FS_Uri *last_uri,
2178 const struct 2301 const struct
2179 GNUNET_CONTAINER_MetaData * 2302 GNUNET_FS_MetaData *
2180 last_meta, 2303 last_meta,
2181 const char *next_id); 2304 const char *next_id);
2182 2305
@@ -2286,7 +2409,7 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2286struct GNUNET_FS_SearchResult * 2409struct GNUNET_FS_SearchResult *
2287GNUNET_FS_probe (struct GNUNET_FS_Handle *h, 2410GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2288 const struct GNUNET_FS_Uri *uri, 2411 const struct GNUNET_FS_Uri *uri,
2289 const struct GNUNET_CONTAINER_MetaData *meta, 2412 const struct GNUNET_FS_MetaData *meta,
2290 void *client_info, 2413 void *client_info,
2291 uint32_t anonymity); 2414 uint32_t anonymity);
2292 2415
@@ -2374,7 +2497,7 @@ enum GNUNET_FS_DownloadOptions
2374struct GNUNET_FS_DownloadContext * 2497struct GNUNET_FS_DownloadContext *
2375GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 2498GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2376 const struct GNUNET_FS_Uri *uri, 2499 const struct GNUNET_FS_Uri *uri,
2377 const struct GNUNET_CONTAINER_MetaData *meta, 2500 const struct GNUNET_FS_MetaData *meta,
2378 const char *filename, const char *tempname, 2501 const char *filename, const char *tempname,
2379 uint64_t offset, uint64_t length, uint32_t anonymity, 2502 uint64_t offset, uint64_t length, uint32_t anonymity,
2380 enum GNUNET_FS_DownloadOptions options, void *cctx, 2503 enum GNUNET_FS_DownloadOptions options, void *cctx,
@@ -2468,7 +2591,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2468 * we have no mime-type information (treat as #GNUNET_NO) 2591 * we have no mime-type information (treat as #GNUNET_NO)
2469 */ 2592 */
2470int 2593int
2471GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData 2594GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_FS_MetaData
2472 *md); 2595 *md);
2473 2596
2474 2597
@@ -2479,7 +2602,7 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2479 * @param md metadata to add mimetype to 2602 * @param md metadata to add mimetype to
2480 */ 2603 */
2481void 2604void
2482GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); 2605GNUNET_FS_meta_data_make_directory (struct GNUNET_FS_MetaData *md);
2483 2606
2484 2607
2485/** 2608/**
@@ -2490,7 +2613,7 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2490 */ 2613 */
2491char * 2614char *
2492GNUNET_FS_meta_data_suggest_filename (const struct 2615GNUNET_FS_meta_data_suggest_filename (const struct
2493 GNUNET_CONTAINER_MetaData *md); 2616 GNUNET_FS_MetaData *md);
2494 2617
2495 2618
2496/** 2619/**
@@ -2513,7 +2636,7 @@ typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2513 const struct GNUNET_FS_Uri * 2636 const struct GNUNET_FS_Uri *
2514 uri, 2637 uri,
2515 const struct 2638 const struct
2516 GNUNET_CONTAINER_MetaData * 2639 GNUNET_FS_MetaData *
2517 meta, size_t length, 2640 meta, size_t length,
2518 const void *data); 2641 const void *data);
2519 2642
@@ -2556,7 +2679,7 @@ struct GNUNET_FS_DirectoryBuilder;
2556 * @param mdir metadata for the directory 2679 * @param mdir metadata for the directory
2557 */ 2680 */
2558struct GNUNET_FS_DirectoryBuilder * 2681struct GNUNET_FS_DirectoryBuilder *
2559GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData 2682GNUNET_FS_directory_builder_create (const struct GNUNET_FS_MetaData
2560 *mdir); 2683 *mdir);
2561 2684
2562 2685
@@ -2573,7 +2696,7 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2573void 2696void
2574GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, 2697GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2575 const struct GNUNET_FS_Uri *uri, 2698 const struct GNUNET_FS_Uri *uri,
2576 const struct GNUNET_CONTAINER_MetaData *md, 2699 const struct GNUNET_FS_MetaData *md,
2577 const void *data); 2700 const void *data);
2578 2701
2579 2702
@@ -2688,7 +2811,7 @@ struct GNUNET_FS_ShareTreeItem
2688 /** 2811 /**
2689 * Metadata for this file or directory 2812 * Metadata for this file or directory
2690 */ 2813 */
2691 struct GNUNET_CONTAINER_MetaData *meta; 2814 struct GNUNET_FS_MetaData *meta;
2692 2815
2693 /** 2816 /**
2694 * Keywords for this file or directory (derived from metadata). 2817 * Keywords for this file or directory (derived from metadata).
@@ -2777,6 +2900,336 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2777void 2900void
2778GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel); 2901GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2779 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 */
2919struct GNUNET_FS_MetaData *
2920GNUNET_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 */
2930struct GNUNET_FS_MetaData *
2931GNUNET_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 */
2941void
2942GNUNET_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 */
2956int
2957GNUNET_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 */
2980int
2981GNUNET_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 */
2998void
2999GNUNET_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 */
3014int
3015GNUNET_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 */
3027void
3028GNUNET_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 */
3038void
3039GNUNET_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 */
3053int
3054GNUNET_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 */
3070char *
3071GNUNET_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 */
3088char *
3089GNUNET_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 */
3103size_t
3104GNUNET_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 */
3113enum 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 */
3151ssize_t
3152GNUNET_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 */
3166ssize_t
3167GNUNET_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 */
3180struct GNUNET_FS_MetaData *
3181GNUNET_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 */
3191enum GNUNET_GenericReturnValue
3192GNUNET_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 */
3203struct GNUNET_BIO_ReadSpec
3204GNUNET_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 */
3216struct GNUNET_BIO_WriteSpec
3217GNUNET_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 */
3228enum GNUNET_GenericReturnValue
3229GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
3230 const char *what,
3231 struct GNUNET_FS_MetaData **result);
3232
2780 3233
2781#if 0 /* keep Emacsens' auto-indent happy */ 3234#if 0 /* keep Emacsens' auto-indent happy */
2782{ 3235{
@@ -2788,3 +3241,5 @@ GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2788#endif 3241#endif
2789 3242
2790/** @} */ /* end of group */ 3243/** @} */ /* end of group */
3244
3245/** @} */ /* end of group addition */