GNUnet  0.20.0
plugin_reclaim_attribute_basic.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2013, 2014, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_reclaim_plugin.h"
32 #include <inttypes.h>
33 
34 
44 static char *
46  uint32_t type,
47  const void *data,
48  size_t data_size)
49 {
50  switch (type)
51  {
53  return GNUNET_strndup (data, data_size);
54 
55  default:
56  return NULL;
57  }
58 }
59 
60 
72 static int
74  uint32_t type,
75  const char *s,
76  void **data,
77  size_t *data_size)
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 }
92 
93 
98 static struct
99 {
100  const char *name;
101  uint32_t number;
103  { NULL, UINT32_MAX } };
104 
105 
113 static uint32_t
114 basic_typename_to_number (void *cls, const char *basic_typename)
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 }
124 
125 
133 static const char *
134 basic_number_to_typename (void *cls, uint32_t type)
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 }
143 
144 
151 void *
153 {
155 
161  return api;
162 }
163 
164 
171 void *
173 {
175 
176  GNUNET_free (api);
177  return NULL;
178 }
179 
180 
181 /* end of plugin_reclaim_attribute_type_gnuid.c */
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
Plugin API for reclaim attribute types.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
@ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
void * libgnunet_plugin_reclaim_attribute_basic_done(void *cls)
Exit point from the plugin.
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 const char * basic_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static uint32_t basic_typename_to_number(void *cls, const char *basic_typename)
Convert a type name to the corresponding number.
void * libgnunet_plugin_reclaim_attribute_basic_init(void *cls)
Entry point for the plugin.
const char * name
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 struct @55 basic_name_map[]
Mapping of attribute type numbers to human-readable attribute type names.
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.
void * cls
Closure for all of the callbacks.
GNUNET_RECLAIM_AttributeStringToValueFunction string_to_value
Conversion to binary.
GNUNET_RECLAIM_AttributeNumberToTypenameFunction number_to_typename
Number to typename.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model