GNUnet  0.11.x
plugin_reclaim_attribute_gnuid.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"
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);
86  return GNUNET_OK;
87 
88  default:
89  return GNUNET_SYSERR;
90  }
91 }
92 
102 static char *
104  uint32_t type,
105  const void *data,
106  size_t data_size)
107 {
108  switch (type)
109  {
111  return GNUNET_strndup (data, data_size);
112 
113  default:
114  return NULL;
115  }
116 }
117 
118 
130 static int
132  uint32_t type,
133  const char *s,
134  void **data,
135  size_t *data_size)
136 {
137  if (NULL == s)
138  return GNUNET_SYSERR;
139  switch (type)
140  {
142  *data = GNUNET_strdup (s);
143  *data_size = strlen (s);
144  return GNUNET_OK;
145 
146  default:
147  return GNUNET_SYSERR;
148  }
149 }
150 
155 static struct
156 {
157  const char *name;
158  uint32_t number;
160  { NULL, UINT32_MAX } };
161 
166 static struct
167 {
168  const char *name;
169  uint32_t number;
171  { NULL, UINT32_MAX } };
172 
180 static uint32_t
181 gnuid_typename_to_number (void *cls, const char *gnuid_typename)
182 {
183  unsigned int i;
184 
185  i = 0;
186  while ((NULL != gnuid_name_map[i].name) &&
187  (0 != strcasecmp (gnuid_typename, gnuid_name_map[i].name)))
188  i++;
189  return gnuid_name_map[i].number;
190 }
191 
192 
200 static const char *
201 gnuid_number_to_typename (void *cls, uint32_t type)
202 {
203  unsigned int i;
204 
205  i = 0;
206  while ((NULL != gnuid_name_map[i].name) && (type != gnuid_name_map[i].number))
207  i++;
208  return gnuid_name_map[i].name;
209 }
210 
218 static uint32_t
219 gnuid_typename_to_number_attest (void *cls, const char *gnuid_typename)
220 {
221  unsigned int i;
222 
223  i = 0;
224  while ((NULL != gnuid_attest_name_map[i].name) &&
225  (0 != strcasecmp (gnuid_typename, gnuid_attest_name_map[i].name)))
226  i++;
227  return gnuid_attest_name_map[i].number;
228 }
229 
237 static const char *
239 {
240  unsigned int i;
241 
242  i = 0;
243  while ((NULL != gnuid_attest_name_map[i].name) && (type !=
245  number))
246  i++;
247  return gnuid_attest_name_map[i].name;
248 }
249 
256 void *
258 {
260 
270  return api;
271 }
272 
273 
280 void *
282 {
284 
285  GNUNET_free (api);
286  return NULL;
287 }
288 
289 
290 /* end of plugin_reclaim_attribute_type_gnuid.c */
static const char * gnuid_number_to_typename_attest(void *cls, uint32_t type)
Convert a type number (i.e.
static struct @65 gnuid_name_map[]
Mapping of attribute type numbers to human-readable attribute type names.
GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename_attest
Attestation Number to typename.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static uint32_t gnuid_typename_to_number_attest(void *cls, const char *gnuid_typename)
Convert a type name to the corresponding number.
void * libgnunet_plugin_reclaim_attribute_gnuid_done(void *cls)
Exit point from the plugin.
void * libgnunet_plugin_reclaim_attribute_gnuid_init(void *cls)
Entry point for the plugin.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_RECLAIM_ATTRIBUTE_ValueToStringFunction value_to_string_attest
FIXME: It is odd that attestation functions are withing the attribute plugin.
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...
#define GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING
String attribute.
static int gnuid_string_to_value_attest(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 attestation to the binary representation.
GNUNET_RECLAIM_ATTRIBUTE_TypenameToNumberFunction typename_to_number_attest
Attestation Typename to number.
#define GNUNET_RECLAIM_ATTESTATION_TYPE_JWT
A JSON Web Token attestation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
static struct @66 gnuid_attest_name_map[]
Mapping of attestation type numbers to human-readable attestation type names.
const char * name
GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value_attest
Attestation Conversion to binary.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
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.
void * cls
Closure for all of the callbacks.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static char * gnuid_value_to_string_attest(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of an attestation to a string.
uint32_t data
The data value.
static const char * gnuid_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_RECLAIM_ATTRIBUTE_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_RECLAIM_ATTRIBUTE_StringToValueFunction string_to_value
Conversion to binary.