aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_container_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_container_lib.h')
-rw-r--r--src/include/gnunet_container_lib.h162
1 files changed, 90 insertions, 72 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index db9e10ef8..3df9dcfc0 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -196,23 +196,12 @@ void GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter
196struct GNUNET_CONTAINER_MetaData; 196struct GNUNET_CONTAINER_MetaData;
197 197
198/** 198/**
199 * Iterator over meta data.
200 *
201 * @param cls closure
202 * @param type type of the meta data
203 * @param data value of the meta data
204 * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort
205 */
206typedef int (*GNUNET_CONTAINER_MetaDataProcessor) (void *cls,
207 EXTRACTOR_KeywordType type,
208 const char *data);
209
210/**
211 * Create a fresh MetaData token. 199 * Create a fresh MetaData token.
212 * 200 *
213 * @return empty meta-data container 201 * @return empty meta-data container
214 */ 202 */
215struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void); 203struct GNUNET_CONTAINER_MetaData *
204GNUNET_CONTAINER_meta_data_create (void);
216 205
217/** 206/**
218 * Duplicate a MetaData token. 207 * Duplicate a MetaData token.
@@ -220,43 +209,61 @@ struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_create (void);
220 * @param md what to duplicate 209 * @param md what to duplicate
221 * @return duplicate meta-data container 210 * @return duplicate meta-data container
222 */ 211 */
223struct GNUNET_CONTAINER_MetaData *GNUNET_CONTAINER_meta_data_duplicate (const 212struct GNUNET_CONTAINER_MetaData *
224 struct 213GNUNET_CONTAINER_meta_data_duplicate (const struct
225 GNUNET_CONTAINER_MetaData 214 GNUNET_CONTAINER_MetaData *md);
226 *md);
227 215
228/** 216/**
229 * Free meta data. 217 * Free meta data.
230 * 218 *
231 * @param md what to free 219 * @param md what to free
232 */ 220 */
233void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData 221void
234 *md); 222GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
235 223
236/** 224/**
237 * Test if two MDs are equal. 225 * Test if two MDs are equal. We consider them equal if
226 * the meta types, formats and content match (we do not
227 * include the mime types and plugins names in this
228 * consideration).
238 * 229 *
239 * @param md1 first value to check 230 * @param md1 first value to check
240 * @param md2 other value to check 231 * @param md2 other value to check
241 * @return GNUNET_YES if they are equal 232 * @return GNUNET_YES if they are equal
242 */ 233 */
243int GNUNET_CONTAINER_meta_data_test_equal (const struct 234int
244 GNUNET_CONTAINER_MetaData *md1, 235GNUNET_CONTAINER_meta_data_test_equal (const struct
245 const struct 236 GNUNET_CONTAINER_MetaData *md1,
246 GNUNET_CONTAINER_MetaData *md2); 237 const struct
238 GNUNET_CONTAINER_MetaData *md2);
247 239
248 240
249/** 241/**
250 * Extend metadata. 242 * Extend metadata.
251 * 243 *
252 * @param md metadata to extend 244 * @param md metadata to extend
253 * @param type type of the new entry 245 * @param plugin_name name of the plugin that produced this value;
254 * @param data value for the entry 246 * special values can be used (i.e. '<zlib>' for zlib being
247 * used in the main libextractor library and yielding
248 * meta data).
249 * @param type libextractor-type describing the meta data
250 * @param format basic format information about data
251 * @param data_mime_type mime-type of data (not of the original file);
252 * can be NULL (if mime-type is not known)
253 * @param data actual meta-data found
254 * @param data_len number of bytes in data
255 * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists 255 * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists
256 * data_mime_type and plugin_name are not considered for "exists" checks
256 */ 257 */
257int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, 258int
258 EXTRACTOR_KeywordType type, 259GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
259 const char *data); 260 const char *plugin_name,
261 enum EXTRACTOR_MetaType type,
262 enum EXTRACTOR_MetaFormat format,
263 const char *data_mime_type,
264 const char *data,
265 size_t data_len);
266
260 267
261/** 268/**
262 * Remove an item. 269 * Remove an item.
@@ -265,11 +272,15 @@ int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
265 * @param type type of the item to remove 272 * @param type type of the item to remove
266 * @param data specific value to remove, NULL to remove all 273 * @param data specific value to remove, NULL to remove all
267 * entries of the given type 274 * entries of the given type
275 * @param data_len number of bytes in data
268 * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md 276 * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
269 */ 277 */
270int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, 278int
271 EXTRACTOR_KeywordType type, 279GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
272 const char *data); 280 enum EXTRACTOR_MetaType type,
281 const char *data,
282 size_t data_len);
283
273 284
274/** 285/**
275 * Add the current time as the publication date 286 * Add the current time as the publication date
@@ -277,58 +288,70 @@ int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
277 * 288 *
278 * @param md metadata to modify 289 * @param md metadata to modify
279 */ 290 */
280void GNUNET_CONTAINER_meta_data_add_publication_date (struct 291void
281 GNUNET_CONTAINER_MetaData 292GNUNET_CONTAINER_meta_data_add_publication_date (struct
282 *md); 293 GNUNET_CONTAINER_MetaData
294 *md);
295
283 296
284/** 297/**
285 * Iterate over MD entries, excluding thumbnails. 298 * Iterate over MD entries.
286 * 299 *
287 * @param md metadata to inspect 300 * @param md metadata to inspect
288 * @param iter function to call on each entry 301 * @param iter function to call on each entry
289 * @param iter_cls closure for iterator 302 * @param iter_cls closure for iterator
290 * @return number of entries 303 * @return number of entries
291 */ 304 */
292int GNUNET_CONTAINER_meta_data_get_contents (const struct 305int GNUNET_CONTAINER_meta_data_iterate (const struct
293 GNUNET_CONTAINER_MetaData *md, 306 GNUNET_CONTAINER_MetaData *md,
294 GNUNET_CONTAINER_MetaDataProcessor 307 EXTRACTOR_MetaDataProcessor
295 iter, void *iter_cls); 308 iter, void *iter_cls);
296 309
297/** 310/**
298 * Get the first MD entry of the given type. 311 * Get the first MD entry of the given type. Caller
312 * is responsible for freeing the return value.
313 * Also, only meta data items that are strings (0-terminated)
314 * are returned by this function.
299 * 315 *
300 * @param md metadata to inspect 316 * @param md metadata to inspect
301 * @param type type to look for 317 * @param type type to look for
302 * @return NULL if we do not have any such entry, 318 * @return NULL if no entry was found
303 * otherwise client is responsible for freeing the value!
304 */ 319 */
305char *GNUNET_CONTAINER_meta_data_get_by_type (const struct 320char *
306 GNUNET_CONTAINER_MetaData *md, 321GNUNET_CONTAINER_meta_data_get_by_type (const struct
307 EXTRACTOR_KeywordType type); 322 GNUNET_CONTAINER_MetaData *md,
323 enum EXTRACTOR_MetaType type);
324
308 325
309/** 326/**
310 * Get the first matching MD entry of the given types. 327 * Get the first matching MD entry of the given types. Caller is
328 * responsible for freeing the return value. Also, only meta data
329 * items that are strings (0-terminated) are returned by this
330 * function.
311 * 331 *
312 * @param md metadata to inspect 332 * @param md metadata to inspect
313 * @param ... -1-terminated list of types 333 * @param ... -1-terminated list of types
314 * @return NULL if we do not have any such entry, 334 * @return NULL if we do not have any such entry,
315 * otherwise client is responsible for freeing the value! 335 * otherwise client is responsible for freeing the value!
316 */ 336 */
317char *GNUNET_CONTAINER_meta_data_get_first_by_types (const struct 337char *
318 GNUNET_CONTAINER_MetaData 338GNUNET_CONTAINER_meta_data_get_first_by_types (const struct
319 *md, ...); 339 GNUNET_CONTAINER_MetaData
340 *md, ...);
320 341
321/** 342/**
322 * Get a thumbnail from the meta-data (if present). 343 * Get a thumbnail from the meta-data (if present). Only matches meta
344 * data with mime type "image" and binary format.
323 * 345 *
324 * @param md metadata to inspect 346 * @param md metadata to inspect
325 * @param thumb will be set to the thumbnail data. Must be 347 * @param thumb will be set to the thumbnail data. Must be
326 * freed by the caller! 348 * freed by the caller!
327 * @return number of bytes in thumbnail, 0 if not available 349 * @return number of bytes in thumbnail, 0 if not available
328 */ 350 */
329size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct 351size_t
330 GNUNET_CONTAINER_MetaData 352GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
331 *md, unsigned char **thumb); 353 GNUNET_CONTAINER_MetaData
354 *md, unsigned char **thumb);
332 355
333/** 356/**
334 * Extract meta-data from a file. 357 * Extract meta-data from a file.
@@ -339,11 +362,12 @@ size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
339 * @return GNUNET_SYSERR on error, otherwise the number 362 * @return GNUNET_SYSERR on error, otherwise the number
340 * of meta-data items obtained 363 * of meta-data items obtained
341 */ 364 */
342int GNUNET_CONTAINER_meta_data_extract_from_file (struct 365int
343 GNUNET_CONTAINER_MetaData 366GNUNET_CONTAINER_meta_data_extract_from_file (struct
344 *md, const char *filename, 367 GNUNET_CONTAINER_MetaData
345 EXTRACTOR_ExtractorList * 368 *md, const char *filename,
346 extractors); 369 struct EXTRACTOR_PluginList *
370 extractors);
347 371
348 372
349/** 373/**
@@ -373,7 +397,8 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
373 * Serialize meta-data to target. 397 * Serialize meta-data to target.
374 * 398 *
375 * @param md metadata to serialize 399 * @param md metadata to serialize
376 * @param target where to write the serialized metadata 400 * @param target where to write the serialized metadata;
401 * *target can be NULL, in which case memory is allocated
377 * @param max maximum number of bytes available 402 * @param max maximum number of bytes available
378 * @param opt is it ok to just write SOME of the 403 * @param opt is it ok to just write SOME of the
379 * meta-data to match the size constraint, 404 * meta-data to match the size constraint,
@@ -384,7 +409,7 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
384 */ 409 */
385ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct 410ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
386 GNUNET_CONTAINER_MetaData *md, 411 GNUNET_CONTAINER_MetaData *md,
387 char *target, 412 char **target,
388 size_t max, 413 size_t max,
389 enum 414 enum
390 GNUNET_CONTAINER_MetaDataSerializationOptions 415 GNUNET_CONTAINER_MetaDataSerializationOptions
@@ -392,22 +417,15 @@ ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
392 417
393 418
394/** 419/**
395 * Estimate (!) the size of the meta-data in 420 * Get the size of the full meta-data in serialized form.
396 * serialized form. The estimate MAY be higher
397 * than what is strictly needed.
398 * 421 *
399 * @param md metadata to inspect 422 * @param md metadata to inspect
400 * @param opt is it ok to just write SOME of the
401 * meta-data to match the size constraint,
402 * possibly discarding some data?
403 * @return number of bytes needed for serialization, -1 on error 423 * @return number of bytes needed for serialization, -1 on error
404 */ 424 */
405ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct 425ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
406 GNUNET_CONTAINER_MetaData 426 GNUNET_CONTAINER_MetaData
407 *md, 427 *md);
408 enum 428
409 GNUNET_CONTAINER_MetaDataSerializationOptions
410 opt);
411 429
412/** 430/**
413 * Deserialize meta-data. Initializes md. 431 * Deserialize meta-data. Initializes md.