GNUnet  0.10.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...
 
struct  GNUNET_CONTAINER_MetaData
 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...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-container-meta-data", __VA_ARGS__)
 
#define HEADER_COMPRESSED   0x80000000
 Flag in 'version' that indicates compressed meta-data. More...
 
#define HEADER_VERSION_MASK   0x7FFFFFFF
 Bits in 'version' that give the version number. More...
 

Functions

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.

Author
Christian Grothoff

Definition in file container_meta_data.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 34 of file container_meta_data.c.

◆ HEADER_COMPRESSED

#define HEADER_COMPRESSED   0x80000000

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

Definition at line 691 of file container_meta_data.c.

Referenced by GNUNET_CONTAINER_meta_data_deserialize(), and GNUNET_CONTAINER_meta_data_serialize().

◆ HEADER_VERSION_MASK

#define HEADER_VERSION_MASK   0x7FFFFFFF

Bits in 'version' that give the version number.

Definition at line 697 of file container_meta_data.c.

Referenced by GNUNET_CONTAINER_meta_data_deserialize().

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().

Parameters
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
Returns
GNUNET_YES if compression reduce the size, GNUNET_NO if compression did not help

Definition at line 54 of file container_meta_data.c.

References GNUNET_free, GNUNET_malloc, GNUNET_NO, and GNUNET_YES.

Referenced by GNUNET_CONTAINER_meta_data_serialize(), and strata_estimator_write().

58 {
59  char *tmp;
60  uLongf dlen;
61 
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 }
#define GNUNET_NO
Definition: gnunet_common.h:81
static int result
Global testing status.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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.

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

Definition at line 101 of file container_meta_data.c.

References GNUNET_free, and GNUNET_malloc.

Referenced by GNUNET_CONTAINER_meta_data_deserialize(), and strata_estimator_read().

104 {
105  char *output;
106  uLongf olen;
107 
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 }
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ meta_item_free()

static void meta_item_free ( struct MetaItem mi)
static

Free meta data item.

Parameters
miitem to free

Definition at line 220 of file container_meta_data.c.

References MetaItem::data, GNUNET_free, GNUNET_free_non_null, 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().

221 {
225  GNUNET_free (mi);
226 }
char * data
The actual meta data.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * plugin_name
Name of the extracting plugin.
char * mime_type
Mime-type of data.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ invalidate_sbuf()

static void invalidate_sbuf ( struct GNUNET_CONTAINER_MetaData md)
static

The meta data has changed, invalidate its serialization buffer.

Parameters
mdmeta data that changed

Definition at line 236 of file container_meta_data.c.

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().

237 {
238  if (NULL == md->sbuf)
239  return;
240  GNUNET_free (md->sbuf);
241  md->sbuf = NULL;
242  md->sbuf_size = 0;
243 }
size_t sbuf_size
Number of bytes in &#39;sbuf&#39;.
char * sbuf
Complete serialized and compressed buffer of the items.
#define GNUNET_free(ptr)
Wrapper around free.
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 
)
static

Merge given meta data.

Parameters
clsthe struct GNUNET_CONTAINER_MetaData to merge into
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
0 (to continue)

Definition at line 444 of file container_meta_data.c.

References GNUNET_CONTAINER_meta_data_insert().

Referenced by GNUNET_CONTAINER_meta_data_merge().

447 {
448  struct GNUNET_CONTAINER_MetaData *md = cls;
449 
451  data_mime_type, data, data_size);
452  return 0;
453 }
Meta data to associate with a file, directory or namespace.
static char * plugin_name
Solver plugin name as string.
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the call graph for this function:
Here is the caller graph for this function: