GNUnet  0.11.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 632 of file gnunet_container_lib.h.

633 {
639 
646 
652 };
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 206 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().

207 {
208  return GNUNET_new (struct GNUNET_CONTAINER_MetaData);
209 }
#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 670 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().

672 {
674  struct MetaItem *pos;
675 
676  if (NULL == md)
677  return NULL;
679  for (pos = md->items_tail; NULL != pos; pos = pos->prev)
681  pos->format, pos->mime_type, pos->data,
682  pos->data_size);
683  return ret;
684 }
char * data
The actual meta data.
enum EXTRACTOR_MetaType type
Type of the meta data.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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 250 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().

251 {
252  struct MetaItem *pos;
253 
254  if (NULL == md)
255  return;
256  while (NULL != (pos = md->items_head))
257  {
259  meta_item_free (pos);
260  }
262  GNUNET_free (md);
263 }
#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 299 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.

303 {
304  struct MetaItem *i;
305  struct MetaItem *j;
306  int found;
307 
308  if (md1 == md2)
309  return GNUNET_YES;
310  if (md1->item_count != md2->item_count)
311  return GNUNET_NO;
312  for (i = md1->items_head; NULL != i; i = i->next)
313  {
314  found = GNUNET_NO;
315  for (j = md2->items_head; NULL != j; j = j->next)
316  {
317  if ((i->type == j->type) && (i->format == j->format) &&
318  (i->data_size == j->data_size) &&
319  (0 == memcmp (i->data, j->data, i->data_size)))
320  {
321  found = GNUNET_YES;
322  break;
323  }
324  if (j->data_size < i->data_size)
325  break; /* elements are sorted by (decreasing) size... */
326  }
327  if (GNUNET_NO == found)
328  return GNUNET_NO;
329  }
330  return GNUNET_YES;
331 }
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 353 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().

359 {
360  struct MetaItem *pos;
361  struct MetaItem *mi;
362  char *p;
363 
366  GNUNET_break ('\0' == data[data_size - 1]);
367 
368  for (pos = md->items_head; NULL != pos; pos = pos->next)
369  {
370  if (pos->data_size < data_size)
371  break; /* elements are sorted by size in the list */
372  if ((pos->type == type) && (pos->data_size == data_size) &&
373  (0 == memcmp (pos->data, data, data_size)))
374  {
375  if ((NULL == pos->mime_type) && (NULL != data_mime_type))
376  {
377  pos->mime_type = GNUNET_strdup (data_mime_type);
378  invalidate_sbuf (md);
379  }
380  if ((EXTRACTOR_METAFORMAT_C_STRING == pos->format) &&
382  {
384  invalidate_sbuf (md);
385  }
386  return GNUNET_SYSERR;
387  }
388  }
389  md->item_count++;
390  mi = GNUNET_new (struct MetaItem);
391  mi->type = type;
392  mi->format = format;
393  mi->data_size = data_size;
394  if (NULL == pos)
396  md->items_tail,
397  mi);
398  else
400  md->items_tail,
401  pos->prev,
402  mi);
403  mi->mime_type =
404  (NULL == data_mime_type) ? NULL : GNUNET_strdup (data_mime_type);
405  mi->plugin_name = (NULL == plugin_name) ? NULL : GNUNET_strdup (plugin_name);
406  mi->data = GNUNET_malloc (data_size);
408  /* change all dir separators to POSIX style ('/') */
411  {
412  p = mi->data;
413  while (('\0' != *p) && (p < mi->data + data_size))
414  {
415  if ('\\' == *p)
416  *p = '/';
417  p++;
418  }
419  }
420  invalidate_sbuf (md);
421  return GNUNET_OK;
422 }
char * data
The actual meta data.
struct MetaItem * items_head
Head of linked list of the meta data items.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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.
#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.
struct MetaItem * items_tail
Tail of linked list of the meta data items.
static char * plugin_name
Name of our plugin.
#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 462 of file container_meta_data.c.

References GNUNET_CONTAINER_meta_data_iterate(), and merge_helper().

Referenced by process_ksk_result(), and publish_inspector().

464 {
466 }
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 480 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().

483 {
484  struct MetaItem *pos;
485 
486  for (pos = md->items_head; NULL != pos; pos = pos->next)
487  {
488  if (pos->data_size < data_size)
489  break; /* items are sorted by (decreasing) size */
490  if ((pos->type == type) &&
491  ((NULL == data) ||
492  ((pos->data_size == data_size) &&
493  (0 == memcmp (pos->data, data, data_size)))))
494  {
496  meta_item_free (pos);
497  md->item_count--;
498  invalidate_sbuf (md);
499  return GNUNET_OK;
500  }
501  }
502  return GNUNET_SYSERR;
503 }
#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.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
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.
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 272 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.

273 {
274  struct MetaItem *mi;
275 
276  if (NULL == md)
277  return;
278  while (NULL != (mi = md->items_head))
279  {
281  meta_item_free (mi);
282  }
284  memset (md, 0, sizeof(struct GNUNET_CONTAINER_MetaData));
285 }
#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 513 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().

515 {
516  const char *dat;
517  struct GNUNET_TIME_Absolute t;
518 
522  NULL, 0);
524  GNUNET_CONTAINER_meta_data_insert (md, "<gnunet>",
526  EXTRACTOR_METAFORMAT_UTF8, "text/plain",
527  dat, strlen (dat) + 1);
528 }
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:742
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 540 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().

543 {
544  struct MetaItem *pos;
545 
546  if (NULL == md)
547  return 0;
548  if (NULL == iter)
549  return md->item_count;
550  for (pos = md->items_head; NULL != pos; pos = pos->next)
551  if (0 !=
552  iter (iter_cls, pos->plugin_name, pos->type, pos->format,
553  pos->mime_type, pos->data, pos->data_size))
554  return md->item_count;
555  return md->item_count;
556 }
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 570 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().

573 {
574  struct MetaItem *pos;
575 
576  if (NULL == md)
577  return NULL;
578  for (pos = md->items_head; NULL != pos; pos = pos->next)
579  if ((type == pos->type) &&
580  ((pos->format == EXTRACTOR_METAFORMAT_UTF8) ||
582  return GNUNET_strdup (pos->data);
583  return NULL;
584 }
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 599 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().

602 {
603  char *ret;
604  va_list args;
605  int type;
606 
607  if (NULL == md)
608  return NULL;
609  ret = NULL;
610  va_start (args, md);
611  while (1)
612  {
613  type = va_arg (args, int);
614  if (-1 == type)
615  break;
616  if (NULL != (ret = GNUNET_CONTAINER_meta_data_get_by_type (md, type)))
617  break;
618  }
619  va_end (args);
620  return ret;
621 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
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 633 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.

635 {
636  struct MetaItem *pos;
637  struct MetaItem *match;
638 
639  if (NULL == md)
640  return 0;
641  match = NULL;
642  for (pos = md->items_head; NULL != pos; pos = pos->next)
643  {
644  if ((NULL != pos->mime_type) &&
645  (0 == strncasecmp ("image/", pos->mime_type, strlen ("image/"))) &&
647  {
648  if (NULL == match)
649  match = pos;
650  else if ((match->type != EXTRACTOR_METATYPE_THUMBNAIL) &&
652  match = pos;
653  }
654  }
655  if ((NULL == match) || (0 == match->data_size))
656  return 0;
657  *thumb = GNUNET_malloc (match->data_size);
658  GNUNET_memcpy (*thumb, match->data, match->data_size);
659  return match->data_size;
660 }
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 780 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_().

785 {
786  struct GNUNET_CONTAINER_MetaData *vmd;
787  struct MetaItem *pos;
788  struct MetaDataHeader ihdr;
789  struct MetaDataHeader *hdr;
790  struct MetaDataEntry *ent;
791  char *dst;
792  unsigned int i;
793  uint64_t msize;
794  size_t off;
795  char *mdata;
796  char *cdata;
797  size_t mlen;
798  size_t plen;
799  size_t size;
800  size_t left;
801  size_t clen;
802  size_t rlen;
803  int comp;
804 
805  if (max < sizeof(struct MetaDataHeader))
806  return GNUNET_SYSERR; /* far too small */
807  if (NULL == md)
808  return 0;
809 
810  if (NULL != md->sbuf)
811  {
812  /* try to use serialization cache */
813  if (md->sbuf_size <= max)
814  {
815  if (NULL == *target)
816  *target = GNUNET_malloc (md->sbuf_size);
817  GNUNET_memcpy (*target, md->sbuf, md->sbuf_size);
818  return md->sbuf_size;
819  }
821  return GNUNET_SYSERR; /* can say that this will fail */
822  /* need to compute a partial serialization, sbuf useless ... */
823  }
824  dst = NULL;
825  msize = 0;
826  for (pos = md->items_tail; NULL != pos; pos = pos->prev)
827  {
828  msize += sizeof(struct MetaDataEntry);
829  msize += pos->data_size;
830  if (NULL != pos->plugin_name)
831  msize += strlen (pos->plugin_name) + 1;
832  if (NULL != pos->mime_type)
833  msize += strlen (pos->mime_type) + 1;
834  }
835  size = (size_t) msize;
836  if (size != msize)
837  {
838  GNUNET_break (0); /* integer overflow */
839  return GNUNET_SYSERR;
840  }
841  if (size >= GNUNET_MAX_MALLOC_CHECKED)
842  {
843  /* too large to be processed */
844  return GNUNET_SYSERR;
845  }
846  ent = GNUNET_malloc (size);
847  mdata = (char *) &ent[md->item_count];
848  off = size - (md->item_count * sizeof(struct MetaDataEntry));
849  i = 0;
850  for (pos = md->items_head; NULL != pos; pos = pos->next)
851  {
852  ent[i].type = htonl ((uint32_t) pos->type);
853  ent[i].format = htonl ((uint32_t) pos->format);
854  ent[i].data_size = htonl ((uint32_t) pos->data_size);
855  if (NULL == pos->plugin_name)
856  plen = 0;
857  else
858  plen = strlen (pos->plugin_name) + 1;
859  ent[i].plugin_name_len = htonl ((uint32_t) plen);
860  if (NULL == pos->mime_type)
861  mlen = 0;
862  else
863  mlen = strlen (pos->mime_type) + 1;
864  ent[i].mime_type_len = htonl ((uint32_t) mlen);
865  off -= pos->data_size;
866  if ((EXTRACTOR_METAFORMAT_UTF8 == pos->format) ||
868  GNUNET_break ('\0' == pos->data[pos->data_size - 1]);
869  GNUNET_memcpy (&mdata[off], pos->data, pos->data_size);
870  off -= plen;
871  if (NULL != pos->plugin_name)
872  GNUNET_memcpy (&mdata[off], pos->plugin_name, plen);
873  off -= mlen;
874  if (NULL != pos->mime_type)
875  GNUNET_memcpy (&mdata[off], pos->mime_type, mlen);
876  i++;
877  }
878  GNUNET_assert (0 == off);
879 
880  clen = 0;
881  cdata = NULL;
882  left = size;
883  i = 0;
884  for (pos = md->items_head; NULL != pos; pos = pos->next)
885  {
886  comp = GNUNET_NO;
888  comp = GNUNET_try_compression ((const char *) &ent[i],
889  left,
890  &cdata,
891  &clen);
892 
893  if ((NULL == md->sbuf) && (0 == i))
894  {
895  /* fill 'sbuf'; this "modifies" md, but since this is only
896  * an internal cache we will cast away the 'const' instead
897  * of making the API look strange. */
898  vmd = (struct GNUNET_CONTAINER_MetaData *) md;
899  hdr = GNUNET_malloc (left + sizeof(struct MetaDataHeader));
900  hdr->size = htonl (left);
901  hdr->entries = htonl (md->item_count);
902  if (GNUNET_YES == comp)
903  {
904  GNUNET_assert (clen < left);
905  hdr->version = htonl (2 | HEADER_COMPRESSED);
906  GNUNET_memcpy (&hdr[1], cdata, clen);
907  vmd->sbuf_size = clen + sizeof(struct MetaDataHeader);
908  }
909  else
910  {
911  hdr->version = htonl (2);
912  GNUNET_memcpy (&hdr[1], &ent[0], left);
913  vmd->sbuf_size = left + sizeof(struct MetaDataHeader);
914  }
915  vmd->sbuf = (char *) hdr;
916  }
917 
918  if (((left + sizeof(struct MetaDataHeader)) <= max) ||
919  ((GNUNET_YES == comp) && (clen <= max)))
920  {
921  /* success, this now fits! */
922  if (GNUNET_YES == comp)
923  {
924  if (NULL == dst)
925  dst = GNUNET_malloc (clen + sizeof(struct MetaDataHeader));
926  hdr = (struct MetaDataHeader *) dst;
927  hdr->version = htonl (2 | HEADER_COMPRESSED);
928  hdr->size = htonl (left);
929  hdr->entries = htonl (md->item_count - i);
930  GNUNET_memcpy (&dst[sizeof(struct MetaDataHeader)], cdata, clen);
931  GNUNET_free (cdata);
932  cdata = NULL;
933  GNUNET_free (ent);
934  rlen = clen + sizeof(struct MetaDataHeader);
935  }
936  else
937  {
938  if (NULL == dst)
939  dst = GNUNET_malloc (left + sizeof(struct MetaDataHeader));
940  hdr = (struct MetaDataHeader *) dst;
941  hdr->version = htonl (2);
942  hdr->entries = htonl (md->item_count - i);
943  hdr->size = htonl (left);
944  GNUNET_memcpy (&dst[sizeof(struct MetaDataHeader)], &ent[i], left);
945  GNUNET_free (ent);
946  rlen = left + sizeof(struct MetaDataHeader);
947  }
948  if (NULL != *target)
949  {
950  if (GNUNET_YES == comp)
951  GNUNET_memcpy (*target, dst, clen + sizeof(struct MetaDataHeader));
952  else
953  GNUNET_memcpy (*target, dst, left + sizeof(struct MetaDataHeader));
954  GNUNET_free (dst);
955  }
956  else
957  {
958  *target = dst;
959  }
960  return rlen;
961  }
962 
964  {
965  /* does not fit! */
966  GNUNET_free (ent);
967  return GNUNET_SYSERR;
968  }
969 
970  /* next iteration: ignore the corresponding meta data at the
971  * end and try again without it */
972  left -= sizeof(struct MetaDataEntry);
973  left -= pos->data_size;
974  if (NULL != pos->plugin_name)
975  left -= strlen (pos->plugin_name) + 1;
976  if (NULL != pos->mime_type)
977  left -= strlen (pos->mime_type) + 1;
978 
979  GNUNET_free_non_null (cdata);
980  cdata = NULL;
981 
982  i++;
983  }
984  GNUNET_free (ent);
985 
986  /* nothing fit, only write header! */
987  ihdr.version = htonl (2);
988  ihdr.entries = htonl (0);
989  ihdr.size = htonl (0);
990  if (NULL == *target)
991  *target = (char *) GNUNET_new (struct MetaDataHeader);
992  GNUNET_memcpy (*target, &ihdr, sizeof(struct MetaDataHeader));
993  return sizeof(struct MetaDataHeader);
994 }
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:67
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 1004 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().

1006 {
1007  ssize_t ret;
1008  char *ptr;
1009 
1010  if (NULL != md->sbuf)
1011  return md->sbuf_size;
1012  ptr = NULL;
1013  ret =
1016  if (-1 != ret)
1017  GNUNET_free (ptr);
1018  return ret;
1019 }
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
Return value of the commandline.
Definition: gnunet-abd.c:81
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 1031 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().

1032 {
1033  struct GNUNET_CONTAINER_MetaData *md;
1034  struct MetaDataHeader hdr;
1035  struct MetaDataEntry ent;
1036  uint32_t ic;
1037  uint32_t i;
1038  char *data;
1039  const char *cdata;
1040  uint32_t version;
1041  uint32_t dataSize;
1042  int compressed;
1043  size_t left;
1044  uint32_t mlen;
1045  uint32_t plen;
1046  uint32_t dlen;
1047  const char *mdata;
1048  const char *meta_data;
1049  const char *plugin_name;
1050  const char *mime_type;
1052 
1053  if (size < sizeof(struct MetaDataHeader))
1054  return NULL;
1055  GNUNET_memcpy (&hdr, input, sizeof(struct MetaDataHeader));
1056  version = ntohl (hdr.version) & HEADER_VERSION_MASK;
1057  compressed = (ntohl (hdr.version) & HEADER_COMPRESSED) != 0;
1058 
1059  if (1 == version)
1060  return NULL; /* null pointer */
1061  if (2 != version)
1062  {
1063  GNUNET_break_op (0); /* unsupported version */
1064  return NULL;
1065  }
1066 
1067  ic = ntohl (hdr.entries);
1068  dataSize = ntohl (hdr.size);
1069  if (((sizeof(struct MetaDataEntry) * ic) > dataSize) ||
1070  ((0 != ic) &&
1071  (dataSize / ic < sizeof(struct MetaDataEntry))))
1072  {
1073  GNUNET_break_op (0);
1074  return NULL;
1075  }
1076 
1077  if (compressed)
1078  {
1079  if (dataSize >= GNUNET_MAX_MALLOC_CHECKED)
1080  {
1081  /* make sure we don't blow our memory limit because of a mal-formed
1082  * message... */
1083  GNUNET_break_op (0);
1084  return NULL;
1085  }
1086  data =
1087  GNUNET_decompress ((const char *) &input[sizeof(struct MetaDataHeader)],
1088  size - sizeof(struct MetaDataHeader),
1089  dataSize);
1090  if (NULL == data)
1091  {
1092  GNUNET_break_op (0);
1093  return NULL;
1094  }
1095  cdata = data;
1096  }
1097  else
1098  {
1099  data = NULL;
1100  cdata = (const char *) &input[sizeof(struct MetaDataHeader)];
1101  if (dataSize != size - sizeof(struct MetaDataHeader))
1102  {
1103  GNUNET_break_op (0);
1104  return NULL;
1105  }
1106  }
1107 
1109  left = dataSize - ic * sizeof(struct MetaDataEntry);
1110  mdata = &cdata[ic * sizeof(struct MetaDataEntry)];
1111  for (i = 0; i < ic; i++)
1112  {
1113  GNUNET_memcpy (&ent, &cdata[i * sizeof(struct MetaDataEntry)],
1114  sizeof(struct MetaDataEntry));
1115  format = (enum EXTRACTOR_MetaFormat) ntohl (ent.format);
1116  if ((EXTRACTOR_METAFORMAT_UTF8 != format) &&
1118  (EXTRACTOR_METAFORMAT_BINARY != format))
1119  {
1120  GNUNET_break_op (0);
1121  break;
1122  }
1123  dlen = ntohl (ent.data_size);
1124  plen = ntohl (ent.plugin_name_len);
1125  mlen = ntohl (ent.mime_type_len);
1126  if (dlen > left)
1127  {
1128  GNUNET_break_op (0);
1129  break;
1130  }
1131  left -= dlen;
1132  meta_data = &mdata[left];
1133  if ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
1134  (EXTRACTOR_METAFORMAT_C_STRING == format))
1135  {
1136  if (0 == dlen)
1137  {
1138  GNUNET_break_op (0);
1139  break;
1140  }
1141  if ('\0' != meta_data[dlen - 1])
1142  {
1143  GNUNET_break_op (0);
1144  break;
1145  }
1146  }
1147  if (plen > left)
1148  {
1149  GNUNET_break_op (0);
1150  break;
1151  }
1152  left -= plen;
1153  if ((plen > 0) && ('\0' != mdata[left + plen - 1]))
1154  {
1155  GNUNET_break_op (0);
1156  break;
1157  }
1158  if (0 == plen)
1159  plugin_name = NULL;
1160  else
1161  plugin_name = &mdata[left];
1162 
1163  if (mlen > left)
1164  {
1165  GNUNET_break_op (0);
1166  break;
1167  }
1168  left -= mlen;
1169  if ((mlen > 0) && ('\0' != mdata[left + mlen - 1]))
1170  {
1171  GNUNET_break_op (0);
1172  break;
1173  }
1174  if (0 == mlen)
1175  mime_type = NULL;
1176  else
1177  mime_type = &mdata[left];
1178  GNUNET_CONTAINER_meta_data_insert (md, plugin_name,
1179  (enum EXTRACTOR_MetaType)
1180  ntohl (ent.type), format, mime_type,
1181  meta_data, dlen);
1182  }
1183  GNUNET_free_non_null (data);
1184  return md;
1185 }
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.
#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:67
#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.
static char * plugin_name
Name of our plugin.
Here is the call graph for this function:
Here is the caller graph for this function: