GNUnet  0.11.x
Functions | Variables
plugin_reclaim_attribute_gnuid.c File Reference

reclaim-attribute-plugin-gnuid attribute plugin to provide the API for fundamental attribute types. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_reclaim_attribute_plugin.h"
#include <inttypes.h>
Include dependency graph for plugin_reclaim_attribute_gnuid.c:

Go to the source code of this file.

Functions

static char * gnuid_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 gnuid_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 gnuid_typename_to_number (void *cls, const char *gnuid_typename)
 Convert a type name to the corresponding number. More...
 
static const char * gnuid_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
void * libgnunet_plugin_reclaim_attribute_gnuid_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_reclaim_attribute_gnuid_done (void *cls)
 Exit point from the plugin. More...
 

Variables

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

Detailed Description

reclaim-attribute-plugin-gnuid attribute plugin to provide the API for fundamental attribute types.

Author
Martin Schanzenbach

Definition in file plugin_reclaim_attribute_gnuid.c.

Function Documentation

◆ gnuid_value_to_string()

static char* gnuid_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_gnuid.c.

References GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, and GNUNET_strndup.

Referenced by libgnunet_plugin_reclaim_attribute_gnuid_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:

◆ gnuid_string_to_value()

static int gnuid_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_gnuid.c.

References GNUNET_OK, GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING, GNUNET_strdup, and GNUNET_SYSERR.

Referenced by libgnunet_plugin_reclaim_attribute_gnuid_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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
Here is the caller graph for this function:

◆ gnuid_typename_to_number()

static uint32_t gnuid_typename_to_number ( void *  cls,
const char *  gnuid_typename 
)
static

Convert a type name to the corresponding number.

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

Definition at line 114 of file plugin_reclaim_attribute_gnuid.c.

References gnuid_name_map, and name.

Referenced by libgnunet_plugin_reclaim_attribute_gnuid_init().

115 {
116  unsigned int i;
117 
118  i = 0;
119  while ((NULL != gnuid_name_map[i].name) &&
120  (0 != strcasecmp (gnuid_typename, gnuid_name_map[i].name)))
121  i++;
122  return gnuid_name_map[i].number;
123 }
static struct @65 gnuid_name_map[]
Mapping of attribute type numbers to human-readable attribute type names.
const char * name
Here is the caller graph for this function:

◆ gnuid_number_to_typename()

static const char* gnuid_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 134 of file plugin_reclaim_attribute_gnuid.c.

References gnuid_name_map, name, and number.

Referenced by libgnunet_plugin_reclaim_attribute_gnuid_init().

135 {
136  unsigned int i;
137 
138  i = 0;
139  while ((NULL != gnuid_name_map[i].name) && (type != gnuid_name_map[i].number))
140  i++;
141  return gnuid_name_map[i].name;
142 }
static struct @65 gnuid_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_gnuid_init()

void* libgnunet_plugin_reclaim_attribute_gnuid_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 152 of file plugin_reclaim_attribute_gnuid.c.

References gnuid_number_to_typename(), gnuid_string_to_value(), gnuid_typename_to_number(), gnuid_value_to_string(), GNUNET_new, GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions::number_to_typename, GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions::string_to_value, GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions::typename_to_number, and GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions::value_to_string.

153 {
155 
161  return api;
162 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction value_to_string
Conversion to string.
static int gnuid_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.
GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number
Typename to number.
static uint32_t gnuid_typename_to_number(void *cls, const char *gnuid_typename)
Convert a type name to the corresponding number.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
static char * gnuid_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 const char * gnuid_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value
Conversion to binary.
Here is the call graph for this function:

◆ libgnunet_plugin_reclaim_attribute_gnuid_done()

void* libgnunet_plugin_reclaim_attribute_gnuid_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init()
Returns
NULL

Definition at line 172 of file plugin_reclaim_attribute_gnuid.c.

References GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions::cls, and GNUNET_free.

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

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 101 of file plugin_reclaim_attribute_gnuid.c.

Referenced by gnuid_number_to_typename().

◆ gnuid_name_map

struct { ... } gnuid_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 gnuid_number_to_typename(), and gnuid_typename_to_number().