GNUnet 0.22.2
plugin_reclaim_attribute_basic.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_reclaim_plugin.h"
#include <inttypes.h>
Include dependency graph for plugin_reclaim_attribute_basic.c:

Go to the source code of this file.

Functions

static char * basic_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of an attribute to a string. More...
 
static int basic_string_to_value (void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'value' of an attribute to the binary representation. More...
 
static uint32_t basic_typename_to_number (void *cls, const char *basic_typename)
 Convert a type name to the corresponding number. More...
 
static const char * basic_number_to_typename (void *cls, uint32_t type)
 Convert a type number to the corresponding type string (e.g. More...
 
void * libgnunet_plugin_reclaim_attribute_basic_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_reclaim_attribute_basic_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
basic_name_map []
 Mapping of attribute type numbers to human-readable attribute type names. More...
 

Function Documentation

◆ basic_value_to_string()

static char * basic_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of an attribute to a string.

Parameters
clsclosure, unused
typetype of the attribute
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 45 of file plugin_reclaim_attribute_basic.c.

49{
50 switch (type)
51 {
54
55 default:
56 return NULL;
57 }
58}
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.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
@ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.

References data, data_size, GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, GNUNET_strndup, and type.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

Here is the caller graph for this function:

◆ basic_string_to_value()

static int basic_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of an attribute to the binary representation.

Parameters
clsclosure, unused
typetype of the attribute
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 73 of file plugin_reclaim_attribute_basic.c.

78{
79 if (NULL == s)
80 return GNUNET_SYSERR;
81 switch (type)
82 {
84 *data = GNUNET_strdup (s);
85 *data_size = strlen (s) + 1;
86 return GNUNET_OK;
87
88 default:
89 return GNUNET_SYSERR;
90 }
91}
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References data, data_size, GNUNET_OK, GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, GNUNET_strdup, GNUNET_SYSERR, and type.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

Here is the caller graph for this function:

◆ basic_typename_to_number()

static uint32_t basic_typename_to_number ( void *  cls,
const char *  basic_typename 
)
static

Convert a type name to the corresponding number.

Parameters
clsclosure, unused
basic_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 114 of file plugin_reclaim_attribute_basic.c.

115{
116 unsigned int i;
117
118 i = 0;
119 while ((NULL != basic_name_map[i].name) &&
120 (0 != strcasecmp (basic_typename, basic_name_map[i].name)))
121 i++;
122 return basic_name_map[i].number;
123}
const char * name
static struct @41 basic_name_map[]
Mapping of attribute type numbers to human-readable attribute type names.

References basic_name_map, and name.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

Here is the caller graph for this function:

◆ basic_number_to_typename()

static const char * basic_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 134 of file plugin_reclaim_attribute_basic.c.

135{
136 unsigned int i;
137
138 i = 0;
139 while ((NULL != basic_name_map[i].name) && (type != basic_name_map[i].number))
140 i++;
141 return basic_name_map[i].name;
142}

References basic_name_map, name, number, and type.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_reclaim_attribute_basic_init()

void * libgnunet_plugin_reclaim_attribute_basic_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 154 of file plugin_reclaim_attribute_basic.c.

155{
157
163 return api;
164}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int basic_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of an attribute to the binary representation.
static char * basic_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of an attribute to a string.
static uint32_t basic_typename_to_number(void *cls, const char *basic_typename)
Convert a type name to the corresponding number.
static const char * basic_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_RECLAIM_AttributeValueToStringFunction value_to_string
Conversion to string.
GNUNET_RECLAIM_AttributeTypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_RECLAIM_AttributeStringToValueFunction string_to_value
Conversion to binary.
GNUNET_RECLAIM_AttributeNumberToTypenameFunction number_to_typename
Number to typename.

References basic_number_to_typename(), basic_string_to_value(), basic_typename_to_number(), basic_value_to_string(), GNUNET_new, GNUNET_RECLAIM_AttributePluginFunctions::number_to_typename, GNUNET_RECLAIM_AttributePluginFunctions::string_to_value, GNUNET_RECLAIM_AttributePluginFunctions::typename_to_number, and GNUNET_RECLAIM_AttributePluginFunctions::value_to_string.

Here is the call graph for this function:

◆ libgnunet_plugin_reclaim_attribute_basic_done()

void * libgnunet_plugin_reclaim_attribute_basic_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init()
Returns
NULL

Definition at line 176 of file plugin_reclaim_attribute_basic.c.

177{
179
180 GNUNET_free (api);
181 return NULL;
182}
#define GNUNET_free(ptr)
Wrapper around free.
void * cls
Closure for all of the callbacks.

References GNUNET_RECLAIM_AttributePluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 101 of file plugin_reclaim_attribute_basic.c.

Referenced by basic_number_to_typename().

◆ 

struct { ... } basic_name_map[]
Initial value:
{ NULL, UINT32_MAX } }

Mapping of attribute type numbers to human-readable attribute type names.

Referenced by basic_number_to_typename(), and basic_typename_to_number().