GNUnet  0.10.x
Enumerations | Enumerator | Functions
Container library: Metadata

GNU libextractor key-value pairs. More...

Enumerations

enum  GNUNET_CONTAINER_MetaDataSerializationOptions { GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0, GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1, GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2 }
 Options for metadata serialization. More...
 

Functions

struct GNUNET_CONTAINER_MetaDataGNUNET_CONTAINER_meta_data_create (void)
 Create a fresh meta data container. More...
 
struct GNUNET_CONTAINER_MetaDataGNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData *md)
 Duplicate a MetaData token. More...
 
void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md)
 Free meta data. More...
 
int GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData *md1, const struct GNUNET_CONTAINER_MetaData *md2)
 Test if two MDs are equal. More...
 
int GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
 Extend metadata. More...
 
void GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, const struct GNUNET_CONTAINER_MetaData *in)
 Extend metadata. More...
 
int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type, const char *data, size_t data_size)
 Remove an item. More...
 
void GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
 Remove all items in the container. More...
 
void GNUNET_CONTAINER_meta_data_add_publication_date (struct GNUNET_CONTAINER_MetaData *md)
 Add the current time as the publication date to the meta-data. More...
 
int GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
 Iterate over MD entries. More...
 
char * GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type)
 Get the first MD entry of the given type. More...
 
char * GNUNET_CONTAINER_meta_data_get_first_by_types (const struct GNUNET_CONTAINER_MetaData *md,...)
 Get the first matching MD entry of the given types. More...
 
size_t GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData *md, unsigned char **thumb)
 Get a thumbnail from the meta-data (if present). More...
 
ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData *md, char **target, size_t max, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt)
 Serialize meta-data to target. More...
 
ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct GNUNET_CONTAINER_MetaData *md)
 Get the size of the full meta-data in serialized form. More...
 
struct GNUNET_CONTAINER_MetaDataGNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size)
 Deserialize meta-data. More...
 

Detailed Description

GNU libextractor key-value pairs.

Enumeration Type Documentation

◆ GNUNET_CONTAINER_MetaDataSerializationOptions

Options for metadata serialization.

Enumerator
GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL 

Serialize all of the data.

GNUNET_CONTAINER_META_DATA_SERIALIZE_PART 

If not enough space is available, it is acceptable to only serialize some of the metadata.

GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS 

Speed is of the essence, do not allow compression.

Definition at line 630 of file gnunet_container_lib.h.

630  {
636 
643 
649 };
If not enough space is available, it is acceptable to only serialize some of the metadata.
Speed is of the essence, do not allow compression.

Function Documentation

◆ GNUNET_CONTAINER_meta_data_create()

struct GNUNET_CONTAINER_MetaData* GNUNET_CONTAINER_meta_data_create ( void  )

Create a fresh meta data container.

Returns
empty meta-data container

Create a fresh meta data container.

Returns
empty meta-data container

Definition at line 204 of file container_meta_data.c.

References GNUNET_new.

Referenced by extract_files(), get_file_information(), getopt_set_metadata(), GNUNET_CONTAINER_meta_data_deserialize(), GNUNET_CONTAINER_meta_data_duplicate(), GNUNET_FS_directory_builder_create(), GNUNET_FS_file_information_create_from_reader(), migrate_and_drop_metadata(), process_kblock(), and share_tree_trim().

205 {
206  return GNUNET_new(struct GNUNET_CONTAINER_MetaData);
207 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Meta data to associate with a file, directory or namespace.
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_duplicate()

struct GNUNET_CONTAINER_MetaData* GNUNET_CONTAINER_meta_data_duplicate ( const struct GNUNET_CONTAINER_MetaData md)

Duplicate a MetaData token.

Parameters
mdwhat to duplicate
Returns
duplicate meta-data container

Duplicate a MetaData token.

Parameters
mdwhat to duplicate
Returns
duplicate meta-data container

Definition at line 667 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, MetaItem::format, GNUNET_CONTAINER_meta_data_create(), GNUNET_CONTAINER_meta_data_insert(), GNUNET_CONTAINER_MetaData::items_tail, MetaItem::mime_type, MetaItem::plugin_name, MetaItem::prev, ret, and MetaItem::type.

Referenced by create_download_context(), GNUNET_FS_directory_builder_add(), GNUNET_FS_directory_builder_create(), GNUNET_FS_file_information_create_empty_directory(), GNUNET_FS_file_information_create_from_reader(), GNUNET_FS_probe(), GNUNET_FS_publish_ksk(), GNUNET_FS_publish_sks(), process_ksk_result(), and process_sks_result().

669 {
671  struct MetaItem *pos;
672 
673  if (NULL == md)
674  return NULL;
676  for (pos = md->items_tail; NULL != pos; pos = pos->prev)
678  pos->format, pos->mime_type, pos->data,
679  pos->data_size);
680  return ret;
681 }
char * data
The actual meta data.
enum EXTRACTOR_MetaType type
Type of the meta data.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct MetaItem * prev
This is a doubly linked list.
size_t data_size
Number of bytes in 'data'.
char * plugin_name
Name of the extracting plugin.
Meta data to associate with a file, directory or namespace.
char * mime_type
Mime-type of data.
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_create()
Create a fresh struct CONTAINER_MetaData token.
int GNUNET_CONTAINER_meta_data_insert(struct GNUNET_CONTAINER_MetaData *md, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
Extend metadata.
Meta data item.
enum EXTRACTOR_MetaFormat format
Format of the meta data.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_destroy()

void GNUNET_CONTAINER_meta_data_destroy ( struct GNUNET_CONTAINER_MetaData md)

Free meta data.

Parameters
mdwhat to free

Definition at line 248 of file container_meta_data.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_free_non_null, GNUNET_CONTAINER_MetaData::items_head, GNUNET_CONTAINER_MetaData::items_tail, meta_item_free(), and GNUNET_CONTAINER_MetaData::sbuf.

Referenced by deserialize_search_result(), do_stop_task(), extract_files(), free_download_context(), free_result(), free_update_information_graph(), GNUNET_FS_directory_builder_add(), GNUNET_FS_directory_builder_finish(), GNUNET_FS_directory_list_contents(), GNUNET_FS_download_signal_suspend_(), GNUNET_FS_download_stop(), GNUNET_FS_file_information_destroy(), GNUNET_FS_probe_stop(), GNUNET_FS_publish_ksk_cancel(), GNUNET_FS_publish_sks_cancel(), GNUNET_FS_share_tree_free(), process_kblock(), process_sblock(), publish_inspector(), read_update_information_graph(), search_result_free(), and search_result_suspend().

249 {
250  struct MetaItem *pos;
251 
252  if (NULL == md)
253  return;
254  while (NULL != (pos = md->items_head))
255  {
257  meta_item_free(pos);
258  }
260  GNUNET_free(md);
261 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct MetaItem * items_head
Head of linked list of the meta data items.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * sbuf
Complete serialized and compressed buffer of the items.
Meta data item.
static void meta_item_free(struct MetaItem *mi)
Free meta data item.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_test_equal()

int GNUNET_CONTAINER_meta_data_test_equal ( const struct GNUNET_CONTAINER_MetaData md1,
const struct GNUNET_CONTAINER_MetaData md2 
)

Test if two MDs are equal.

We consider them equal if the meta types, formats and content match (we do not include the mime types and plugins names in this consideration).

Parameters
md1first value to check
md2other value to check
Returns
GNUNET_YES if they are equal

Definition at line 297 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, MetaItem::format, GNUNET_NO, GNUNET_YES, GNUNET_CONTAINER_MetaData::item_count, GNUNET_CONTAINER_MetaData::items_head, MetaItem::next, and MetaItem::type.

301 {
302  struct MetaItem *i;
303  struct MetaItem *j;
304  int found;
305 
306  if (md1 == md2)
307  return GNUNET_YES;
308  if (md1->item_count != md2->item_count)
309  return GNUNET_NO;
310  for (i = md1->items_head; NULL != i; i = i->next)
311  {
312  found = GNUNET_NO;
313  for (j = md2->items_head; NULL != j; j = j->next)
314  {
315  if ((i->type == j->type) && (i->format == j->format) &&
316  (i->data_size == j->data_size) &&
317  (0 == memcmp(i->data, j->data, i->data_size)))
318  {
319  found = GNUNET_YES;
320  break;
321  }
322  if (j->data_size < i->data_size)
323  break; /* elements are sorted by (decreasing) size... */
324  }
325  if (GNUNET_NO == found)
326  return GNUNET_NO;
327  }
328  return GNUNET_YES;
329 }
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
#define GNUNET_NO
Definition: gnunet_common.h:78
size_t data_size
Number of bytes in &#39;data&#39;.
struct MetaItem * next
This is a doubly linked list.
Meta data item.
unsigned int item_count
Number of items in the linked list.
#define GNUNET_YES
Definition: gnunet_common.h:77
enum EXTRACTOR_MetaFormat format
Format of the meta data.

◆ GNUNET_CONTAINER_meta_data_insert()

int GNUNET_CONTAINER_meta_data_insert ( struct GNUNET_CONTAINER_MetaData md,
const char *  plugin_name,
enum EXTRACTOR_MetaType  type,
enum EXTRACTOR_MetaFormat  format,
const char *  data_mime_type,
const char *  data,
size_t  data_size 
)

Extend metadata.

Parameters
mdmetadata to extend
plugin_namename of the plugin that produced this value; special values can be used (i.e. '<zlib>' for zlib being used in the main libextractor library and yielding meta data).
typelibextractor-type describing the meta data
formatbasic format information about data
data_mime_typemime-type of data (not of the original file); can be NULL (if mime-type is not known)
dataactual meta-data found
data_sizenumber of bytes in data
Returns
GNUNET_OK on success, GNUNET_SYSERR if this entry already exists data_mime_type and plugin_name are not considered for "exists" checks

Note that the list of meta data items is sorted by size (largest first).

Parameters
mdmetadata to extend
plugin_namename of the plugin that produced this value; special values can be used (i.e. '<zlib>' for zlib being used in the main libextractor library and yielding meta data).
typelibextractor-type describing the meta data
formatbasic format information about data
data_mime_typemime-type of data (not of the original file); can be NULL (if mime-type is not known)
dataactual meta-data found
data_sizenumber of bytes in data
Returns
GNUNET_OK on success, GNUNET_SYSERR if this entry already exists data_mime_type and plugin_name are not considered for "exists" checks

Definition at line 351 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, EXTRACTOR_METAFORMAT_C_STRING, EXTRACTOR_METAFORMAT_UTF8, EXTRACTOR_METATYPE_FILENAME, EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, MetaItem::format, GNUNET_break, GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, invalidate_sbuf(), GNUNET_CONTAINER_MetaData::item_count, GNUNET_CONTAINER_MetaData::items_head, GNUNET_CONTAINER_MetaData::items_tail, MetaItem::mime_type, MetaItem::next, p, MetaItem::plugin_name, MetaItem::prev, and MetaItem::type.

Referenced by getopt_set_metadata(), GNUNET_CONTAINER_meta_data_add_publication_date(), GNUNET_CONTAINER_meta_data_deserialize(), GNUNET_CONTAINER_meta_data_duplicate(), GNUNET_FS_directory_builder_add(), GNUNET_FS_file_information_create_from_file(), GNUNET_FS_meta_data_make_directory(), merge_helper(), migrate_and_drop_metadata(), process_helper_msgs(), and share_tree_trim().

357 {
358  struct MetaItem *pos;
359  struct MetaItem *mi;
360  char *p;
361 
364  GNUNET_break('\0' == data[data_size - 1]);
365 
366  for (pos = md->items_head; NULL != pos; pos = pos->next)
367  {
368  if (pos->data_size < data_size)
369  break; /* elements are sorted by size in the list */
370  if ((pos->type == type) && (pos->data_size == data_size) &&
371  (0 == memcmp(pos->data, data, data_size)))
372  {
373  if ((NULL == pos->mime_type) && (NULL != data_mime_type))
374  {
375  pos->mime_type = GNUNET_strdup(data_mime_type);
376  invalidate_sbuf(md);
377  }
378  if ((EXTRACTOR_METAFORMAT_C_STRING == pos->format) &&
380  {
382  invalidate_sbuf(md);
383  }
384  return GNUNET_SYSERR;
385  }
386  }
387  md->item_count++;
388  mi = GNUNET_new(struct MetaItem);
389  mi->type = type;
390  mi->format = format;
391  mi->data_size = data_size;
392  if (NULL == pos)
394  md->items_tail,
395  mi);
396  else
398  md->items_tail,
399  pos->prev,
400  mi);
401  mi->mime_type =
402  (NULL == data_mime_type) ? NULL : GNUNET_strdup(data_mime_type);
403  mi->plugin_name = (NULL == plugin_name) ? NULL : GNUNET_strdup(plugin_name);
406  /* change all dir separators to POSIX style ('/') */
409  {
410  p = mi->data;
411  while (('\0' != *p) && (p < mi->data + data_size))
412  {
413  if ('\\' == *p)
414  *p = '/';
415  p++;
416  }
417  }
418  invalidate_sbuf(md);
419  return GNUNET_OK;
420 }
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
0-terminated, UTF-8 encoded string.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MetaItem * prev
This is a doubly linked list.
size_t data_size
Number of bytes in &#39;data&#39;.
char * plugin_name
Name of the extracting plugin.
char * mime_type
Mime-type of data.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
static char * plugin_name
Solver plugin name as string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct MetaItem * next
This is a doubly linked list.
Meta data item.
unsigned int item_count
Number of items in the linked list.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static void invalidate_sbuf(struct GNUNET_CONTAINER_MetaData *md)
The meta data has changed, invalidate its serialization buffer.
enum EXTRACTOR_MetaFormat format
Format of the meta data.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_merge()

void GNUNET_CONTAINER_meta_data_merge ( struct GNUNET_CONTAINER_MetaData md,
const struct GNUNET_CONTAINER_MetaData in 
)

Extend metadata.

Merges the meta data from the second argument into the first, discarding duplicate key-value pairs.

Parameters
mdmetadata to extend
inmetadata to merge

Definition at line 460 of file container_meta_data.c.

References GNUNET_CONTAINER_meta_data_iterate(), and merge_helper().

Referenced by process_ksk_result(), and publish_inspector().

462 {
464 }
static int merge_helper(void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
Merge given meta data.
int GNUNET_CONTAINER_meta_data_iterate(const struct GNUNET_CONTAINER_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_delete()

int GNUNET_CONTAINER_meta_data_delete ( struct GNUNET_CONTAINER_MetaData md,
enum EXTRACTOR_MetaType  type,
const char *  data,
size_t  data_size 
)

Remove an item.

Parameters
mdmetadata to manipulate
typetype of the item to remove
dataspecific value to remove, NULL to remove all entries of the given type
data_sizenumber of bytes in data
Returns
GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md
Parameters
mdmetadata to manipulate
typetype of the item to remove
dataspecific value to remove, NULL to remove all entries of the given type
data_sizenumber of bytes in data
Returns
GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md

Definition at line 478 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, GNUNET_CONTAINER_DLL_remove, GNUNET_OK, GNUNET_SYSERR, invalidate_sbuf(), GNUNET_CONTAINER_MetaData::item_count, GNUNET_CONTAINER_MetaData::items_head, GNUNET_CONTAINER_MetaData::items_tail, meta_item_free(), MetaItem::next, and MetaItem::type.

Referenced by get_file_information(), GNUNET_CONTAINER_meta_data_add_publication_date(), and process_helper_msgs().

481 {
482  struct MetaItem *pos;
483 
484  for (pos = md->items_head; NULL != pos; pos = pos->next)
485  {
486  if (pos->data_size < data_size)
487  break; /* items are sorted by (decreasing) size */
488  if ((pos->type == type) &&
489  ((NULL == data) ||
490  ((pos->data_size == data_size) &&
491  (0 == memcmp(pos->data, data, data_size)))))
492  {
494  meta_item_free(pos);
495  md->item_count--;
496  invalidate_sbuf(md);
497  return GNUNET_OK;
498  }
499  }
500  return GNUNET_SYSERR;
501 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
size_t data_size
Number of bytes in &#39;data&#39;.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct MetaItem * next
This is a doubly linked list.
Meta data item.
static void meta_item_free(struct MetaItem *mi)
Free meta data item.
unsigned int item_count
Number of items in the linked list.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static void invalidate_sbuf(struct GNUNET_CONTAINER_MetaData *md)
The meta data has changed, invalidate its serialization buffer.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_clear()

void GNUNET_CONTAINER_meta_data_clear ( struct GNUNET_CONTAINER_MetaData md)

Remove all items in the container.

Parameters
mdmetadata to manipulate

Definition at line 270 of file container_meta_data.c.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free_non_null, GNUNET_CONTAINER_MetaData::items_head, GNUNET_CONTAINER_MetaData::items_tail, meta_item_free(), and GNUNET_CONTAINER_MetaData::sbuf.

271 {
272  struct MetaItem *mi;
273 
274  if (NULL == md)
275  return;
276  while (NULL != (mi = md->items_head))
277  {
279  meta_item_free(mi);
280  }
282  memset(md, 0, sizeof(struct GNUNET_CONTAINER_MetaData));
283 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct MetaItem * items_head
Head of linked list of the meta data items.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Meta data to associate with a file, directory or namespace.
char * sbuf
Complete serialized and compressed buffer of the items.
Meta data item.
static void meta_item_free(struct MetaItem *mi)
Free meta data item.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
Here is the call graph for this function:

◆ GNUNET_CONTAINER_meta_data_add_publication_date()

void GNUNET_CONTAINER_meta_data_add_publication_date ( struct GNUNET_CONTAINER_MetaData md)

Add the current time as the publication date to the meta-data.

Parameters
mdmetadata to modify

Definition at line 511 of file container_meta_data.c.

References EXTRACTOR_METAFORMAT_UTF8, EXTRACTOR_METATYPE_PUBLICATION_DATE, GNUNET_CONTAINER_meta_data_delete(), GNUNET_CONTAINER_meta_data_insert(), GNUNET_STRINGS_absolute_time_to_string(), and GNUNET_TIME_absolute_get().

Referenced by publish_inspector().

513 {
514  const char *dat;
515  struct GNUNET_TIME_Absolute t;
516 
520  NULL, 0);
522  GNUNET_CONTAINER_meta_data_insert(md, "<gnunet>",
524  EXTRACTOR_METAFORMAT_UTF8, "text/plain",
525  dat, strlen(dat) + 1);
526 }
0-terminated, UTF-8 encoded string.
static struct GNUNET_SCHEDULER_Task * t
Main task.
int GNUNET_CONTAINER_meta_data_insert(struct GNUNET_CONTAINER_MetaData *md, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
Extend metadata.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int GNUNET_CONTAINER_meta_data_delete(struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type, const char *data, size_t data_size)
Remove an item.
Time for absolute times used by GNUnet, in microseconds.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_iterate()

int GNUNET_CONTAINER_meta_data_iterate ( const struct GNUNET_CONTAINER_MetaData md,
EXTRACTOR_MetaDataProcessor  iter,
void *  iter_cls 
)

Iterate over MD entries.

Parameters
mdmetadata to inspect
iterfunction to call on each entry, return 0 to continue to iterate and 1 to abort iteration in this function (GNU libextractor API!)
iter_clsclosure for iter
Returns
number of entries
Parameters
mdmetadata to inspect
iterfunction to call on each entry
iter_clsclosure for iterator
Returns
number of entries

Definition at line 538 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, MetaItem::format, GNUNET_CONTAINER_MetaData::item_count, GNUNET_CONTAINER_MetaData::items_head, MetaItem::mime_type, MetaItem::next, MetaItem::plugin_name, and MetaItem::type.

Referenced by GNUNET_CONTAINER_meta_data_merge(), GNUNET_FS_directory_list_contents(), GNUNET_FS_download_start_task_(), GNUNET_FS_uri_ksk_create_from_meta_data(), print_entry(), progress_cb(), publish_inspector(), and share_tree_trim().

541 {
542  struct MetaItem *pos;
543 
544  if (NULL == md)
545  return 0;
546  if (NULL == iter)
547  return md->item_count;
548  for (pos = md->items_head; NULL != pos; pos = pos->next)
549  if (0 !=
550  iter(iter_cls, pos->plugin_name, pos->type, pos->format,
551  pos->mime_type, pos->data, pos->data_size))
552  return md->item_count;
553  return md->item_count;
554 }
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
size_t data_size
Number of bytes in &#39;data&#39;.
char * plugin_name
Name of the extracting plugin.
char * mime_type
Mime-type of data.
struct MetaItem * next
This is a doubly linked list.
Meta data item.
unsigned int item_count
Number of items in the linked list.
enum EXTRACTOR_MetaFormat format
Format of the meta data.
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_get_by_type()

char* GNUNET_CONTAINER_meta_data_get_by_type ( const struct GNUNET_CONTAINER_MetaData md,
enum EXTRACTOR_MetaType  type 
)

Get the first MD entry of the given type.

Caller is responsible for freeing the return value. Also, only meta data items that are strings (0-terminated) are returned by this function.

Parameters
mdmetadata to inspect
typetype to look for
Returns
NULL if no entry was found

Definition at line 568 of file container_meta_data.c.

References MetaItem::data, EXTRACTOR_METAFORMAT_C_STRING, EXTRACTOR_METAFORMAT_UTF8, MetaItem::format, GNUNET_strdup, GNUNET_CONTAINER_MetaData::items_head, MetaItem::next, and MetaItem::type.

Referenced by GNUNET_CONTAINER_meta_data_get_first_by_types(), GNUNET_FS_directory_list_contents(), GNUNET_FS_meta_data_make_directory(), GNUNET_FS_meta_data_suggest_filename(), GNUNET_FS_meta_data_test_for_directory(), GNUNET_FS_publish_main_(), print_entry(), progress_cb(), and publish_inspector().

570 {
571  struct MetaItem *pos;
572 
573  if (NULL == md)
574  return NULL;
575  for (pos = md->items_head; NULL != pos; pos = pos->next)
576  if ((type == pos->type) &&
577  ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
579  return GNUNET_strdup(pos->data);
580  return NULL;
581 }
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
0-terminated, UTF-8 encoded string.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct MetaItem * next
This is a doubly linked list.
Meta data item.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
enum EXTRACTOR_MetaFormat format
Format of the meta data.
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_get_first_by_types()

char* GNUNET_CONTAINER_meta_data_get_first_by_types ( const struct GNUNET_CONTAINER_MetaData md,
  ... 
)

Get the first matching MD entry of the given types.

Caller is responsible for freeing the return value. Also, only meta data items that are strings (0-terminated) are returned by this function.

Parameters
mdmetadata to inspect
...-1-terminated list of types
Returns
NULL if we do not have any such entry, otherwise client is responsible for freeing the value!

Definition at line 596 of file container_meta_data.c.

References gnunet-chk::args, GNUNET_CONTAINER_meta_data_get_by_type(), ret, and MetaItem::type.

Referenced by GNUNET_FS_meta_data_suggest_filename(), and GNUNET_FS_uri_ksk_create_from_meta_data().

599 {
600  char *ret;
601  va_list args;
602  int type;
603 
604  if (NULL == md)
605  return NULL;
606  ret = NULL;
607  va_start(args, md);
608  while (1)
609  {
610  type = va_arg(args, int);
611  if (-1 == type)
612  break;
613  if (NULL != (ret = GNUNET_CONTAINER_meta_data_get_by_type(md, type)))
614  break;
615  }
616  va_end(args);
617  return ret;
618 }
char * GNUNET_CONTAINER_meta_data_get_by_type(const struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_get_thumbnail()

size_t GNUNET_CONTAINER_meta_data_get_thumbnail ( const struct GNUNET_CONTAINER_MetaData md,
unsigned char **  thumb 
)

Get a thumbnail from the meta-data (if present).

Only matches meta data with mime type "image" and binary format.

Parameters
mdmetadata to inspect
thumbwill be set to the thumbnail data. Must be freed by the caller!
Returns
number of bytes in thumbnail, 0 if not available
Parameters
mdmetadata to get the thumbnail from
thumbwill be set to the thumbnail data. Must be freed by the caller!
Returns
number of bytes in thumbnail, 0 if not available

Definition at line 630 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, EXTRACTOR_METAFORMAT_BINARY, EXTRACTOR_METATYPE_THUMBNAIL, MetaItem::format, GNUNET_malloc, GNUNET_memcpy, GNUNET_CONTAINER_MetaData::items_head, MetaItem::mime_type, MetaItem::next, and MetaItem::type.

632 {
633  struct MetaItem *pos;
634  struct MetaItem *match;
635 
636  if (NULL == md)
637  return 0;
638  match = NULL;
639  for (pos = md->items_head; NULL != pos; pos = pos->next)
640  {
641  if ((NULL != pos->mime_type) &&
642  (0 == strncasecmp("image/", pos->mime_type, strlen("image/"))) &&
644  {
645  if (NULL == match)
646  match = pos;
647  else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
649  match = pos;
650  }
651  }
652  if ((NULL == match) || (0 == match->data_size))
653  return 0;
654  *thumb = GNUNET_malloc(match->data_size);
655  GNUNET_memcpy(*thumb, match->data, match->data_size);
656  return match->data_size;
657 }
Some kind of binary format, see given Mime type.
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
enum EXTRACTOR_MetaType type
Type of the meta data.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
size_t data_size
Number of bytes in &#39;data&#39;.
char * mime_type
Mime-type of data.
struct MetaItem * next
This is a doubly linked list.
Meta data item.
enum EXTRACTOR_MetaFormat format
Format of the meta data.
#define GNUNET_malloc(size)
Wrapper around malloc.

◆ GNUNET_CONTAINER_meta_data_serialize()

ssize_t GNUNET_CONTAINER_meta_data_serialize ( const struct GNUNET_CONTAINER_MetaData md,
char **  target,
size_t  max,
enum GNUNET_CONTAINER_MetaDataSerializationOptions  opt 
)

Serialize meta-data to target.

Parameters
mdmetadata to serialize
targetwhere to write the serialized metadata; *target can be NULL, in which case memory is allocated
maxmaximum number of bytes available
optis it ok to just write SOME of the meta-data to match the size constraint, possibly discarding some data?
Returns
number of bytes written on success, -1 on error (typically: not enough space)
Parameters
mdmetadata to serialize
targetwhere to write the serialized metadata; *target can be NULL, in which case memory is allocated
maxmaximum number of bytes available in target
optis it ok to just write SOME of the meta-data to match the size constraint, possibly discarding some data?
Returns
number of bytes written on success, GNUNET_SYSERR on error (typically: not enough space)

Definition at line 775 of file container_meta_data.c.

References MetaItem::data, MetaItem::data_size, MetaDataEntry::data_size, MetaDataHeader::entries, EXTRACTOR_METAFORMAT_C_STRING, EXTRACTOR_METAFORMAT_UTF8, MetaItem::format, MetaDataEntry::format, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS, GNUNET_CONTAINER_META_DATA_SERIALIZE_PART, GNUNET_free, GNUNET_free_non_null, GNUNET_malloc, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_SYSERR, GNUNET_try_compression(), GNUNET_YES, HEADER_COMPRESSED, GNUNET_CONTAINER_MetaData::item_count, GNUNET_CONTAINER_MetaData::items_head, GNUNET_CONTAINER_MetaData::items_tail, MetaItem::mime_type, MetaDataEntry::mime_type_len, MetaItem::next, MetaItem::plugin_name, MetaDataEntry::plugin_name_len, MetaItem::prev, GNUNET_CONTAINER_MetaData::sbuf, GNUNET_CONTAINER_MetaData::sbuf_size, size, MetaDataHeader::size, MetaItem::type, MetaDataEntry::type, and MetaDataHeader::version.

Referenced by extract_files(), GNUNET_BIO_write_meta_data(), GNUNET_CONTAINER_meta_data_get_serialized_size(), GNUNET_FS_directory_builder_add(), GNUNET_FS_directory_builder_finish(), and GNUNET_FS_publish_ublock_().

780 {
781  struct GNUNET_CONTAINER_MetaData *vmd;
782  struct MetaItem *pos;
783  struct MetaDataHeader ihdr;
784  struct MetaDataHeader *hdr;
785  struct MetaDataEntry *ent;
786  char *dst;
787  unsigned int i;
788  uint64_t msize;
789  size_t off;
790  char *mdata;
791  char *cdata;
792  size_t mlen;
793  size_t plen;
794  size_t size;
795  size_t left;
796  size_t clen;
797  size_t rlen;
798  int comp;
799 
800  if (max < sizeof(struct MetaDataHeader))
801  return GNUNET_SYSERR; /* far too small */
802  if (NULL == md)
803  return 0;
804 
805  if (NULL != md->sbuf)
806  {
807  /* try to use serialization cache */
808  if (md->sbuf_size <= max)
809  {
810  if (NULL == *target)
811  *target = GNUNET_malloc(md->sbuf_size);
812  GNUNET_memcpy(*target, md->sbuf, md->sbuf_size);
813  return md->sbuf_size;
814  }
816  return GNUNET_SYSERR; /* can say that this will fail */
817  /* need to compute a partial serialization, sbuf useless ... */
818  }
819  dst = NULL;
820  msize = 0;
821  for (pos = md->items_tail; NULL != pos; pos = pos->prev)
822  {
823  msize += sizeof(struct MetaDataEntry);
824  msize += pos->data_size;
825  if (NULL != pos->plugin_name)
826  msize += strlen(pos->plugin_name) + 1;
827  if (NULL != pos->mime_type)
828  msize += strlen(pos->mime_type) + 1;
829  }
830  size = (size_t)msize;
831  if (size != msize)
832  {
833  GNUNET_break(0); /* integer overflow */
834  return GNUNET_SYSERR;
835  }
836  if (size >= GNUNET_MAX_MALLOC_CHECKED)
837  {
838  /* too large to be processed */
839  return GNUNET_SYSERR;
840  }
841  ent = GNUNET_malloc(size);
842  mdata = (char *)&ent[md->item_count];
843  off = size - (md->item_count * sizeof(struct MetaDataEntry));
844  i = 0;
845  for (pos = md->items_head; NULL != pos; pos = pos->next)
846  {
847  ent[i].type = htonl((uint32_t)pos->type);
848  ent[i].format = htonl((uint32_t)pos->format);
849  ent[i].data_size = htonl((uint32_t)pos->data_size);
850  if (NULL == pos->plugin_name)
851  plen = 0;
852  else
853  plen = strlen(pos->plugin_name) + 1;
854  ent[i].plugin_name_len = htonl((uint32_t)plen);
855  if (NULL == pos->mime_type)
856  mlen = 0;
857  else
858  mlen = strlen(pos->mime_type) + 1;
859  ent[i].mime_type_len = htonl((uint32_t)mlen);
860  off -= pos->data_size;
861  if ((EXTRACTOR_METAFORMAT_UTF8 == pos->format) ||
863  GNUNET_break('\0' == pos->data[pos->data_size - 1]);
864  GNUNET_memcpy(&mdata[off], pos->data, pos->data_size);
865  off -= plen;
866  if (NULL != pos->plugin_name)
867  GNUNET_memcpy(&mdata[off], pos->plugin_name, plen);
868  off -= mlen;
869  if (NULL != pos->mime_type)
870  GNUNET_memcpy(&mdata[off], pos->mime_type, mlen);
871  i++;
872  }
873  GNUNET_assert(0 == off);
874 
875  clen = 0;
876  cdata = NULL;
877  left = size;
878  i = 0;
879  for (pos = md->items_head; NULL != pos; pos = pos->next)
880  {
881  comp = GNUNET_NO;
883  comp = GNUNET_try_compression((const char *)&ent[i],
884  left,
885  &cdata,
886  &clen);
887 
888  if ((NULL == md->sbuf) && (0 == i))
889  {
890  /* fill 'sbuf'; this "modifies" md, but since this is only
891  * an internal cache we will cast away the 'const' instead
892  * of making the API look strange. */
893  vmd = (struct GNUNET_CONTAINER_MetaData *)md;
894  hdr = GNUNET_malloc(left + sizeof(struct MetaDataHeader));
895  hdr->size = htonl(left);
896  hdr->entries = htonl(md->item_count);
897  if (GNUNET_YES == comp)
898  {
899  GNUNET_assert(clen < left);
900  hdr->version = htonl(2 | HEADER_COMPRESSED);
901  GNUNET_memcpy(&hdr[1], cdata, clen);
902  vmd->sbuf_size = clen + sizeof(struct MetaDataHeader);
903  }
904  else
905  {
906  hdr->version = htonl(2);
907  GNUNET_memcpy(&hdr[1], &ent[0], left);
908  vmd->sbuf_size = left + sizeof(struct MetaDataHeader);
909  }
910  vmd->sbuf = (char *)hdr;
911  }
912 
913  if (((left + sizeof(struct MetaDataHeader)) <= max) ||
914  ((GNUNET_YES == comp) && (clen <= max)))
915  {
916  /* success, this now fits! */
917  if (GNUNET_YES == comp)
918  {
919  if (NULL == dst)
920  dst = GNUNET_malloc(clen + sizeof(struct MetaDataHeader));
921  hdr = (struct MetaDataHeader *)dst;
922  hdr->version = htonl(2 | HEADER_COMPRESSED);
923  hdr->size = htonl(left);
924  hdr->entries = htonl(md->item_count - i);
925  GNUNET_memcpy(&dst[sizeof(struct MetaDataHeader)], cdata, clen);
926  GNUNET_free(cdata);
927  cdata = NULL;
928  GNUNET_free(ent);
929  rlen = clen + sizeof(struct MetaDataHeader);
930  }
931  else
932  {
933  if (NULL == dst)
934  dst = GNUNET_malloc(left + sizeof(struct MetaDataHeader));
935  hdr = (struct MetaDataHeader *)dst;
936  hdr->version = htonl(2);
937  hdr->entries = htonl(md->item_count - i);
938  hdr->size = htonl(left);
939  GNUNET_memcpy(&dst[sizeof(struct MetaDataHeader)], &ent[i], left);
940  GNUNET_free(ent);
941  rlen = left + sizeof(struct MetaDataHeader);
942  }
943  if (NULL != *target)
944  {
945  if (GNUNET_YES == comp)
946  GNUNET_memcpy(*target, dst, clen + sizeof(struct MetaDataHeader));
947  else
948  GNUNET_memcpy(*target, dst, left + sizeof(struct MetaDataHeader));
949  GNUNET_free(dst);
950  }
951  else
952  {
953  *target = dst;
954  }
955  return rlen;
956  }
957 
959  {
960  /* does not fit! */
961  GNUNET_free(ent);
962  return GNUNET_SYSERR;
963  }
964 
965  /* next iteration: ignore the corresponding meta data at the
966  * end and try again without it */
967  left -= sizeof(struct MetaDataEntry);
968  left -= pos->data_size;
969  if (NULL != pos->plugin_name)
970  left -= strlen(pos->plugin_name) + 1;
971  if (NULL != pos->mime_type)
972  left -= strlen(pos->mime_type) + 1;
973 
974  GNUNET_free_non_null(cdata);
975  cdata = NULL;
976 
977  i++;
978  }
979  GNUNET_free(ent);
980 
981  /* nothing fit, only write header! */
982  ihdr.version = htonl(2);
983  ihdr.entries = htonl(0);
984  ihdr.size = htonl(0);
985  if (NULL == *target)
986  *target = (char *)GNUNET_new(struct MetaDataHeader);
987  GNUNET_memcpy(*target, &ihdr, sizeof(struct MetaDataHeader));
988  return sizeof(struct MetaDataHeader);
989 }
If not enough space is available, it is acceptable to only serialize some of the metadata.
#define HEADER_COMPRESSED
Flag in &#39;version&#39; that indicates compressed meta-data.
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum EXTRACTOR_MetaType type
Type of the meta data.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
0-terminated, UTF-8 encoded string.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MetaItem * prev
This is a doubly linked list.
size_t data_size
Number of bytes in &#39;data&#39;.
uint32_t size
Size of the decompressed meta data.
char * plugin_name
Name of the extracting plugin.
Meta data to associate with a file, directory or namespace.
char * mime_type
Mime-type of data.
uint32_t version
The version of the MD serialization.
Speed is of the essence, do not allow compression.
size_t sbuf_size
Number of bytes in &#39;sbuf&#39;.
uint32_t mime_type_len
Number of bytes in the mime type including 0-terminator.
char * sbuf
Complete serialized and compressed buffer of the items.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct MetaItem * next
This is a doubly linked list.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
Meta data item.
Header for serialized meta data.
uint32_t plugin_name_len
Number of bytes in the plugin name including 0-terminator.
unsigned int item_count
Number of items in the linked list.
uint32_t format
Meta data format.
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t type
Meta data type.
uint32_t data_size
Number of bytes of meta data.
Entry of serialized meta data.
int GNUNET_try_compression(const char *data, size_t old_size, char **result, size_t *new_size)
Try to compress the given block of data using libz.
enum EXTRACTOR_MetaFormat format
Format of the meta data.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t entries
How many MD entries are there?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_get_serialized_size()

ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size ( const struct GNUNET_CONTAINER_MetaData md)

Get the size of the full meta-data in serialized form.

Parameters
mdmetadata to inspect
Returns
number of bytes needed for serialization, -1 on error

Definition at line 999 of file container_meta_data.c.

References GNUNET_CONTAINER_meta_data_serialize(), GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, ret, GNUNET_CONTAINER_MetaData::sbuf, and GNUNET_CONTAINER_MetaData::sbuf_size.

Referenced by extract_files(), GNUNET_FS_directory_builder_add(), GNUNET_FS_directory_builder_finish(), GNUNET_FS_download_start_task_(), GNUNET_FS_publish_ublock_(), and trigger_recursive_download().

1001 {
1002  ssize_t ret;
1003  char *ptr;
1004 
1005  if (NULL != md->sbuf)
1006  return md->sbuf_size;
1007  ptr = NULL;
1008  ret =
1011  if (-1 != ret)
1012  GNUNET_free(ptr);
1013  return ret;
1014 }
ssize_t GNUNET_CONTAINER_meta_data_serialize(const struct GNUNET_CONTAINER_MetaData *md, char **target, size_t max, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt)
Serialize meta-data to target.
static int ret
Final status code.
Definition: gnunet-arm.c:89
size_t sbuf_size
Number of bytes in &#39;sbuf&#39;.
char * sbuf
Complete serialized and compressed buffer of the items.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONTAINER_meta_data_deserialize()

struct GNUNET_CONTAINER_MetaData* GNUNET_CONTAINER_meta_data_deserialize ( const char *  input,
size_t  size 
)

Deserialize meta-data.

Initializes md.

Parameters
inputserialized meta-data.
sizenumber of bytes available
Returns
MD on success, NULL on error (i.e. bad format)

Initializes md.

Parameters
inputbuffer with the serialized metadata
sizenumber of bytes available in input
Returns
MD on success, NULL on error (i.e. bad format)

Definition at line 1026 of file container_meta_data.c.

References MetaItem::data, MetaDataEntry::data_size, MetaDataHeader::entries, EXTRACTOR_METAFORMAT_BINARY, EXTRACTOR_METAFORMAT_C_STRING, EXTRACTOR_METAFORMAT_UTF8, MetaItem::format, MetaDataEntry::format, GNUNET_break_op, GNUNET_CONTAINER_meta_data_create(), GNUNET_CONTAINER_meta_data_insert(), GNUNET_decompress(), GNUNET_free_non_null, GNUNET_MAX_MALLOC_CHECKED, GNUNET_memcpy, HEADER_COMPRESSED, HEADER_VERSION_MASK, MetaItem::mime_type, MetaDataEntry::mime_type_len, MetaItem::plugin_name, MetaDataEntry::plugin_name_len, MetaDataHeader::size, MetaDataEntry::type, and MetaDataHeader::version.

Referenced by GNUNET_BIO_read_meta_data(), GNUNET_FS_directory_list_contents(), process_helper_msgs(), process_kblock(), and process_sblock().

1027 {
1028  struct GNUNET_CONTAINER_MetaData *md;
1029  struct MetaDataHeader hdr;
1030  struct MetaDataEntry ent;
1031  uint32_t ic;
1032  uint32_t i;
1033  char *data;
1034  const char *cdata;
1035  uint32_t version;
1036  uint32_t dataSize;
1037  int compressed;
1038  size_t left;
1039  uint32_t mlen;
1040  uint32_t plen;
1041  uint32_t dlen;
1042  const char *mdata;
1043  const char *meta_data;
1044  const char *plugin_name;
1045  const char *mime_type;
1047 
1048  if (size < sizeof(struct MetaDataHeader))
1049  return NULL;
1050  GNUNET_memcpy(&hdr, input, sizeof(struct MetaDataHeader));
1051  version = ntohl(hdr.version) & HEADER_VERSION_MASK;
1052  compressed = (ntohl(hdr.version) & HEADER_COMPRESSED) != 0;
1053 
1054  if (1 == version)
1055  return NULL; /* null pointer */
1056  if (2 != version)
1057  {
1058  GNUNET_break_op(0); /* unsupported version */
1059  return NULL;
1060  }
1061 
1062  ic = ntohl(hdr.entries);
1063  dataSize = ntohl(hdr.size);
1064  if (((sizeof(struct MetaDataEntry) * ic) > dataSize) ||
1065  ((0 != ic) &&
1066  (dataSize / ic < sizeof(struct MetaDataEntry))))
1067  {
1068  GNUNET_break_op(0);
1069  return NULL;
1070  }
1071 
1072  if (compressed)
1073  {
1074  if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
1075  {
1076  /* make sure we don't blow our memory limit because of a mal-formed
1077  * message... */
1078  GNUNET_break_op(0);
1079  return NULL;
1080  }
1081  data =
1082  GNUNET_decompress((const char *)&input[sizeof(struct MetaDataHeader)],
1083  size - sizeof(struct MetaDataHeader),
1084  dataSize);
1085  if (NULL == data)
1086  {
1087  GNUNET_break_op(0);
1088  return NULL;
1089  }
1090  cdata = data;
1091  }
1092  else
1093  {
1094  data = NULL;
1095  cdata = (const char *)&input[sizeof(struct MetaDataHeader)];
1096  if (dataSize != size - sizeof(struct MetaDataHeader))
1097  {
1098  GNUNET_break_op(0);
1099  return NULL;
1100  }
1101  }
1102 
1104  left = dataSize - ic * sizeof(struct MetaDataEntry);
1105  mdata = &cdata[ic * sizeof(struct MetaDataEntry)];
1106  for (i = 0; i < ic; i++)
1107  {
1108  GNUNET_memcpy(&ent, &cdata[i * sizeof(struct MetaDataEntry)],
1109  sizeof(struct MetaDataEntry));
1110  format = (enum EXTRACTOR_MetaFormat)ntohl(ent.format);
1111  if ((EXTRACTOR_METAFORMAT_UTF8 != format) &&
1113  (EXTRACTOR_METAFORMAT_BINARY != format))
1114  {
1115  GNUNET_break_op(0);
1116  break;
1117  }
1118  dlen = ntohl(ent.data_size);
1119  plen = ntohl(ent.plugin_name_len);
1120  mlen = ntohl(ent.mime_type_len);
1121  if (dlen > left)
1122  {
1123  GNUNET_break_op(0);
1124  break;
1125  }
1126  left -= dlen;
1127  meta_data = &mdata[left];
1128  if ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
1129  (EXTRACTOR_METAFORMAT_C_STRING == format))
1130  {
1131  if (0 == dlen)
1132  {
1133  GNUNET_break_op(0);
1134  break;
1135  }
1136  if ('\0' != meta_data[dlen - 1])
1137  {
1138  GNUNET_break_op(0);
1139  break;
1140  }
1141  }
1142  if (plen > left)
1143  {
1144  GNUNET_break_op(0);
1145  break;
1146  }
1147  left -= plen;
1148  if ((plen > 0) && ('\0' != mdata[left + plen - 1]))
1149  {
1150  GNUNET_break_op(0);
1151  break;
1152  }
1153  if (0 == plen)
1154  plugin_name = NULL;
1155  else
1156  plugin_name = &mdata[left];
1157 
1158  if (mlen > left)
1159  {
1160  GNUNET_break_op(0);
1161  break;
1162  }
1163  left -= mlen;
1164  if ((mlen > 0) && ('\0' != mdata[left + mlen - 1]))
1165  {
1166  GNUNET_break_op(0);
1167  break;
1168  }
1169  if (0 == mlen)
1170  mime_type = NULL;
1171  else
1172  mime_type = &mdata[left];
1173  GNUNET_CONTAINER_meta_data_insert(md, plugin_name,
1174  (enum EXTRACTOR_MetaType)
1175  ntohl(ent.type), format, mime_type,
1176  meta_data, dlen);
1177  }
1178  GNUNET_free_non_null(data);
1179  return md;
1180 }
EXTRACTOR_MetaFormat
Format in which the extracted meta data is presented.
#define HEADER_COMPRESSED
Flag in &#39;version&#39; that indicates compressed meta-data.
Some kind of binary format, see given Mime type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
0-terminated, UTF-8 encoded string.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
EXTRACTOR_MetaType
Enumeration defining various sources of keywords.
Meta data to associate with a file, directory or namespace.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_create()
Create a fresh struct CONTAINER_MetaData token.
static char * plugin_name
Solver plugin name as string.
#define HEADER_VERSION_MASK
Bits in &#39;version&#39; that give the version number.
int GNUNET_CONTAINER_meta_data_insert(struct GNUNET_CONTAINER_MetaData *md, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
Extend metadata.
char * GNUNET_decompress(const char *input, size_t input_size, size_t output_size)
Decompress input, return the decompressed data as output.
static unsigned int size
Size of the "table".
Definition: peer.c:66
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
Header for serialized meta data.
uint32_t format
Meta data format.
Entry of serialized meta data.
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function: