GNUnet 0.22.1
meta_data.c File Reference

Storing of meta data. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_fs_service.h"
Include dependency graph for meta_data.c:

Go to the source code of this file.

Data Structures

struct  MetaItem
 Meta data item. More...
 
struct  GNUNET_FS_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 MAX_META_DATA   (1024 * 1024)
 Maximum size allowed for meta data written/read from disk. More...
 
#define LOG(kind, ...)
 
#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

struct GNUNET_FS_MetaDataGNUNET_FS_meta_data_create ()
 Create a fresh struct FS_MetaData token. More...
 
static void meta_item_free (struct MetaItem *mi)
 Free meta data item. More...
 
static void invalidate_sbuf (struct GNUNET_FS_MetaData *md)
 The meta data has changed, invalidate its serialization buffer. More...
 
void GNUNET_FS_meta_data_destroy (struct GNUNET_FS_MetaData *md)
 Free meta data. More...
 
void GNUNET_FS_meta_data_clear (struct GNUNET_FS_MetaData *md)
 Remove all items in the container. More...
 
int GNUNET_FS_meta_data_test_equal (const struct GNUNET_FS_MetaData *md1, const struct GNUNET_FS_MetaData *md2)
 Test if two MDs are equal. More...
 
int GNUNET_FS_meta_data_insert (struct GNUNET_FS_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_FS_meta_data_merge (struct GNUNET_FS_MetaData *md, const struct GNUNET_FS_MetaData *in)
 Extend metadata. More...
 
int GNUNET_FS_meta_data_delete (struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type, const char *data, size_t data_size)
 Remove an item. More...
 
void GNUNET_FS_meta_data_add_publication_date (struct GNUNET_FS_MetaData *md)
 Add the current time as the publication date to the meta-data. More...
 
int GNUNET_FS_meta_data_iterate (const struct GNUNET_FS_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
 Iterate over MD entries. More...
 
char * GNUNET_FS_meta_data_get_by_type (const struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type)
 Get the first MD entry of the given type. More...
 
char * GNUNET_FS_meta_data_get_first_by_types (const struct GNUNET_FS_MetaData *md,...)
 Get the first matching MD entry of the given types. More...
 
size_t GNUNET_FS_meta_data_get_thumbnail (const struct GNUNET_FS_MetaData *md, unsigned char **thumb)
 Get a thumbnail from the meta-data (if present). More...
 
struct GNUNET_FS_MetaDataGNUNET_FS_meta_data_duplicate (const struct GNUNET_FS_MetaData *md)
 Duplicate a struct GNUNET_FS_MetaData. More...
 
ssize_t GNUNET_FS_meta_data_serialize (const struct GNUNET_FS_MetaData *md, char **target, size_t max, enum GNUNET_FS_MetaDataSerializationOptions opt)
 Serialize meta-data to target. More...
 
ssize_t GNUNET_FS_meta_data_get_serialized_size (const struct GNUNET_FS_MetaData *md)
 Get the size of the full meta-data in serialized form. More...
 
struct GNUNET_FS_MetaDataGNUNET_FS_meta_data_deserialize (const char *input, size_t size)
 Deserialize meta-data. More...
 
enum GNUNET_GenericReturnValue GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_FS_MetaData **result)
 Read a metadata container. More...
 
enum GNUNET_GenericReturnValue GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle *h, const char *what, const struct GNUNET_FS_MetaData *m)
 Write a metadata container. More...
 
static int read_spec_handler_meta_data (void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
 Function used internally to read a metadata container from within a read spec. More...
 
struct GNUNET_BIO_ReadSpec GNUNET_FS_read_spec_meta_data (const char *what, struct GNUNET_FS_MetaData **result)
 Create the specification to read a metadata container. More...
 
static int write_spec_handler_meta_data (void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
 Function used internally to write a metadata container from within a write spec. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_FS_write_spec_meta_data (const char *what, const struct GNUNET_FS_MetaData *m)
 Create the specification to write a metadata container. More...
 

Detailed Description

Storing of meta data.

Author
Christian Grothoff
Martin Schanzenbach

Definition in file meta_data.c.

Macro Definition Documentation

◆ MAX_META_DATA

#define MAX_META_DATA   (1024 * 1024)

Maximum size allowed for meta data written/read from disk.

File-sharing limits to 64k, so this should be rather generous.

Definition at line 35 of file meta_data.c.

◆ LOG

#define LOG (   kind,
  ... 
)
Value:
GNUNET_log_from (kind, "fs-meta-data", \
__VA_ARGS__)
#define GNUNET_log_from(kind, comp,...)

Definition at line 38 of file meta_data.c.

◆ HEADER_COMPRESSED

#define HEADER_COMPRESSED   0x80000000

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

Definition at line 547 of file meta_data.c.

◆ HEADER_VERSION_MASK

#define HEADER_VERSION_MASK   0x7FFFFFFF

Bits in 'version' that give the version number.

Definition at line 553 of file meta_data.c.

Function Documentation

◆ meta_item_free()

static void meta_item_free ( struct MetaItem mi)
static

Free meta data item.

Parameters
miitem to free

Definition at line 139 of file meta_data.c.

140{
143 GNUNET_free (mi->data);
144 GNUNET_free (mi);
145}
#define GNUNET_free(ptr)
Wrapper around free.
char * mime_type
Mime-type of data.
Definition: meta_data.c:65
char * data
The actual meta data.
Definition: meta_data.c:70
char * plugin_name
Name of the extracting plugin.
Definition: meta_data.c:60

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

Referenced by GNUNET_FS_meta_data_clear(), GNUNET_FS_meta_data_delete(), and GNUNET_FS_meta_data_destroy().

Here is the caller graph for this function:

◆ invalidate_sbuf()

static void invalidate_sbuf ( struct GNUNET_FS_MetaData md)
static

The meta data has changed, invalidate its serialization buffer.

Parameters
mdmeta data that changed

Definition at line 155 of file meta_data.c.

156{
157 if (NULL == md->sbuf)
158 return;
159 GNUNET_free (md->sbuf);
160 md->sbuf = NULL;
161 md->sbuf_size = 0;
162}
size_t sbuf_size
Number of bytes in 'sbuf'.
Definition: meta_data.c:112
char * sbuf
Complete serialized and compressed buffer of the items.
Definition: meta_data.c:107

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

Referenced by GNUNET_FS_meta_data_delete(), and GNUNET_FS_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 
)
static

Merge given meta data.

Parameters
clsthe struct GNUNET_FS_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
Returns
0 (to continue)

Definition at line 343 of file meta_data.c.

346{
347 struct GNUNET_FS_MetaData *md = cls;
348
349 (void) GNUNET_FS_meta_data_insert (md, plugin_name, type, format,
350 data_mime_type, data, data_size);
351 return 0;
352}
static char * plugin_name
Name of our plugin.
static char * data
The data to insert into the dht.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
int GNUNET_FS_meta_data_insert(struct GNUNET_FS_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.
Definition: meta_data.c:254
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:92

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

Referenced by GNUNET_FS_meta_data_merge().

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

◆ read_spec_handler_meta_data()

static int read_spec_handler_meta_data ( void *  cls,
struct GNUNET_BIO_ReadHandle h,
const char *  what,
void *  target,
size_t  target_size 
)
static

Function used internally to read a metadata container from within a read spec.

Parameters
clsignored, always NULL
hthe IO handle to read from
whatwhat is being read (for error message creation)
targetwhere to store the data
target_sizeignored
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 1166 of file meta_data.c.

1171{
1172 struct GNUNET_FS_MetaData **result = target;
1173 return GNUNET_FS_read_meta_data (h, what, result);
1174}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static int result
Global testing status.
enum GNUNET_GenericReturnValue GNUNET_FS_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_FS_MetaData **result)
Read a metadata container.
Definition: meta_data.c:1051

References GNUNET_FS_read_meta_data(), h, and result.

Referenced by GNUNET_FS_read_spec_meta_data().

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

◆ write_spec_handler_meta_data()

static int write_spec_handler_meta_data ( void *  cls,
struct GNUNET_BIO_WriteHandle h,
const char *  what,
void *  source,
size_t  source_size 
)
static

Function used internally to write a metadata container from within a write spec.

Parameters
clsignored, always NULL
hthe IO handle to write to
whatwhat is being written (for error message creation)
sourcethe data to write
source_sizeignored
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1211 of file meta_data.c.

1216{
1217 const struct GNUNET_FS_MetaData *m = source;
1218 return GNUNET_FS_write_meta_data (h, what, m);
1219}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static GstElement * source
Appsrc instance into which we write data for the pipeline.
enum GNUNET_GenericReturnValue GNUNET_FS_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const char *what, const struct GNUNET_FS_MetaData *m)
Write a metadata container.
Definition: meta_data.c:1110

References GNUNET_FS_write_meta_data(), h, m, and source.

Referenced by GNUNET_FS_write_spec_meta_data().

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