GNUnet  0.11.x
Functions | Variables
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 (i.e. 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.

References GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, and GNUNET_strndup.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

49 {
50  switch (type)
51  {
53  return GNUNET_strndup (data, data_size);
54 
55  default:
56  return NULL;
57  }
58 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
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.

References GNUNET_OK, GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, GNUNET_strdup, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

78 {
79  if (NULL == s)
80  return GNUNET_SYSERR;
81  switch (type)
82  {
84  *data = GNUNET_strdup (s);
85  *data_size = strlen (s);
86  return GNUNET_OK;
87 
88  default:
89  return GNUNET_SYSERR;
90  }
91 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
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 113 of file plugin_reclaim_attribute_basic.c.

References basic_name_map, and name.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

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

1) to the corresponding type string

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

Definition at line 133 of file plugin_reclaim_attribute_basic.c.

References basic_name_map, name, and number.

Referenced by libgnunet_plugin_reclaim_attribute_basic_init().

134 {
135  unsigned int i;
136 
137  i = 0;
138  while ((NULL != basic_name_map[i].name) && (type != basic_name_map[i].number))
139  i++;
140  return basic_name_map[i].name;
141 }
static struct @66 basic_name_map[]
Mapping of attribute type numbers to human-readable attribute type names.
const char * name
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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 151 of file plugin_reclaim_attribute_basic.c.

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.

152 {
154 
160  return api;
161 }
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 &#39;value&#39; of an attribute to the binary representation.
static const char * basic_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
static char * basic_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; 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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_RECLAIM_AttributeTypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_RECLAIM_AttributeNumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_RECLAIM_AttributeStringToValueFunction string_to_value
Conversion to binary.
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.
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 171 of file plugin_reclaim_attribute_basic.c.

References GNUNET_RECLAIM_AttributePluginFunctions::cls, and GNUNET_free.

172 {
174 
175  GNUNET_free (api);
176  return NULL;
177 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 100 of file plugin_reclaim_attribute_basic.c.

Referenced by basic_number_to_typename().

◆ basic_name_map

struct { ... } basic_name_map[]
Initial value:
{ NULL, UINT32_MAX } }
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.

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

Referenced by basic_number_to_typename(), and basic_typename_to_number().