GNUnet  0.11.x
Data Structures | Macros | Functions
container_meta_data.c File Reference

Storing of meta data. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include <zlib.h>
Include dependency graph for container_meta_data.c:

Go to the source code of this file.

Data Structures

struct  MetaItem
 Meta data item. More...
 Meta data to associate with a file, directory or namespace. More...
struct  MetaDataHeader
 Header for serialized meta data. More...
struct  MetaDataEntry
 Entry of serialized meta data. More...


#define LOG(kind, ...)
#define HEADER_COMPRESSED   0x80000000
 Flag in 'version' that indicates compressed meta-data. More...
 Bits in 'version' that give the version number. More...


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. More...
char * GNUNET_decompress (const char *input, size_t input_size, size_t output_size)
 Decompress input, return the decompressed data as output. More...
struct GNUNET_CONTAINER_MetaDataGNUNET_CONTAINER_meta_data_create ()
 Create a fresh struct CONTAINER_MetaData token. More...
static void meta_item_free (struct MetaItem *mi)
 Free meta data item. More...
static void invalidate_sbuf (struct GNUNET_CONTAINER_MetaData *md)
 The meta data has changed, invalidate its serialization buffer. More...
void GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md)
 Free meta data. More...
void GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md)
 Remove all items in the container. 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...
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. 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_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...
struct GNUNET_CONTAINER_MetaDataGNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData *md)
 Duplicate a struct GNUNET_CONTAINER_MetaData. 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

Storing of meta data.

Christian Grothoff

Definition in file container_meta_data.c.

Macro Definition Documentation


#define LOG (   kind,
GNUNET_log_from (kind, "util-container-meta-data", \
#define GNUNET_log_from(kind, comp,...)

Definition at line 34 of file container_meta_data.c.


#define HEADER_COMPRESSED   0x80000000

Flag in 'version' that indicates compressed meta-data.

Definition at line 690 of file container_meta_data.c.



Bits in 'version' that give the version number.

Definition at line 696 of file container_meta_data.c.

Function Documentation

◆ GNUNET_try_compression()

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.

Only returns the compressed block if compression worked and the new block is actually smaller. Decompress using GNUNET_decompress().

datablock to compress; if compression resulted in a smaller block, the first bytes of data are updated to the compressed data
old_sizenumber of bytes in data
[out]resultset to the compressed data, if compression worked
[out]new_sizeset to size of result, if compression worked
GNUNET_YES if compression reduce the size, GNUNET_NO if compression did not help

Definition at line 54 of file container_meta_data.c.

58 {
59  char *tmp;
60  uLongf dlen;
62  *result = NULL;
63  *new_size = 0;
64 #ifdef compressBound
65  dlen = compressBound (old_size);
66 #else
67  dlen = old_size + (old_size / 100) + 20;
68  /* documentation says 100.1% oldSize + 12 bytes, but we
69  * should be able to overshoot by more to be safe */
70 #endif
71  tmp = GNUNET_malloc (dlen);
72  if (Z_OK ==
73  compress2 ((Bytef *) tmp,
74  &dlen,
75  (const Bytef *) data,
76  old_size, 9))
77  {
78  if (dlen < old_size)
79  {
80  *result = tmp;
81  *new_size = dlen;
82  return GNUNET_YES;
83  }
84  }
85  GNUNET_free (tmp);
86  return GNUNET_NO;
87 }
uint32_t data
The data value.
static int result
Global testing status.
Definition: gnunet_common.h:97
Definition: gnunet_common.h:94
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.

References data, GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_YES, and result.

Referenced by GNUNET_CONTAINER_meta_data_serialize(), and strata_estimator_write().

Here is the caller graph for this function:

◆ GNUNET_decompress()

char* GNUNET_decompress ( const char *  input,
size_t  input_size,
size_t  output_size 

Decompress input, return the decompressed data as output.

Dual to GNUNET_try_compression(). Caller must set output_size to the number of bytes that were originally compressed.

inputcompressed data
input_sizenumber of bytes in input
output_sizeexpected size of the output
NULL on error, buffer of output_size decompressed bytes otherwise

Definition at line 101 of file container_meta_data.c.

104 {
105  char *output;
106  uLongf olen;
108  olen = output_size;
109  output = GNUNET_malloc (olen);
110  if (Z_OK ==
111  uncompress ((Bytef *) output,
112  &olen,
113  (const Bytef *) input,
114  input_size))
115  return output;
116  GNUNET_free (output);
117  return NULL;
118 }

References GNUNET_free, and GNUNET_malloc.

Referenced by GNUNET_CONTAINER_meta_data_deserialize(), and strata_estimator_read().

Here is the caller graph for this function:

◆ meta_item_free()

static void meta_item_free ( struct MetaItem mi)

Free meta data item.

miitem to free

Definition at line 218 of file container_meta_data.c.

219 {
220  GNUNET_free (mi->plugin_name);
221  GNUNET_free (mi->mime_type);
222  GNUNET_free (mi->data);
223  GNUNET_free (mi);
224 }
char * mime_type
Mime-type of data.
char * data
The actual meta data.
char * plugin_name
Name of the extracting plugin.

References MetaItem::data, GNUNET_free, MetaItem::mime_type, and MetaItem::plugin_name.

Referenced by GNUNET_CONTAINER_meta_data_clear(), GNUNET_CONTAINER_meta_data_delete(), and GNUNET_CONTAINER_meta_data_destroy().

Here is the caller graph for this function:

◆ invalidate_sbuf()

static void invalidate_sbuf ( struct GNUNET_CONTAINER_MetaData md)

The meta data has changed, invalidate its serialization buffer.

mdmeta data that changed

Definition at line 234 of file container_meta_data.c.

235 {
236  if (NULL == md->sbuf)
237  return;
238  GNUNET_free (md->sbuf);
239  md->sbuf = NULL;
240  md->sbuf_size = 0;
241 }
char * sbuf
Complete serialized and compressed buffer of the items.
size_t sbuf_size
Number of bytes in 'sbuf'.

References GNUNET_free, GNUNET_CONTAINER_MetaData::sbuf, and GNUNET_CONTAINER_MetaData::sbuf_size.

Referenced by GNUNET_CONTAINER_meta_data_delete(), and GNUNET_CONTAINER_meta_data_insert().

Here is the caller graph for this function:

◆ merge_helper()

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.

clsthe struct GNUNET_CONTAINER_MetaData to merge into
plugin_namename of the plugin that produced this value; special values can be used (e.g. '<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
0 (to continue)

Definition at line 442 of file container_meta_data.c.

445 {
446  struct GNUNET_CONTAINER_MetaData *md = cls;
449  data_mime_type, data, data_size);
450  return 0;
451 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static char * plugin_name
Name of our plugin.
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 to associate with a file, directory or namespace.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References data, data_size, GNUNET_CONTAINER_meta_data_insert(), plugin_name, and type.

Referenced by GNUNET_CONTAINER_meta_data_merge().

Here is the call graph for this function:
Here is the caller graph for this function: