GNUnet  0.11.x
plugin_gnsrecord_reclaim.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2013, 2014 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 
26 #include "platform.h"
27 
28 #include "gnunet_util_lib.h"
29 
30 #include "gnunet_gnsrecord_lib.h"
32 
42 static char *
43 value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
44 {
45  switch (type)
46  {
48  return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
49 
52  return GNUNET_strndup (data, data_size);
53 
59  return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
60 
61  default:
62  return NULL;
63  }
64 }
65 
66 
78 static int
79 string_to_value (void *cls, uint32_t type, const char *s, void **data,
80  size_t *data_size)
81 {
82  if (NULL == s)
83  return GNUNET_SYSERR;
84  switch (type)
85  {
87  return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
88 
91  *data = GNUNET_strdup (s);
92  *data_size = strlen (s);
93  return GNUNET_OK;
94 
100  return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
101 
102  default:
103  return GNUNET_SYSERR;
104  }
105 }
106 
107 
112 static struct
113 {
114  const char *name;
115  uint32_t number;
116 } name_map[] = {
117  { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR },
118  { "RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF },
119  { "RECLAIM_ATTEST", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR },
120  { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER },
121  { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
122  { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
123  { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET },
124  { "RECLAIM_REFERENCE", GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE },
125  { NULL, UINT32_MAX }
126 };
127 
128 
136 static uint32_t
137 typename_to_number (void *cls, const char *dns_typename)
138 {
139  unsigned int i;
140 
141  i = 0;
142  while ((NULL != name_map[i].name) &&
143  (0 != strcasecmp (dns_typename, name_map[i].name)))
144  i++;
145  return name_map[i].number;
146 }
147 
148 
156 static const char *
157 number_to_typename (void *cls, uint32_t type)
158 {
159  unsigned int i;
160 
161  i = 0;
162  while ((NULL != name_map[i].name) && (type != name_map[i].number))
163  i++;
164  return name_map[i].name;
165 }
166 
167 
174 void *
176 {
178 
184  return api;
185 }
186 
187 
194 void *
196 {
198 
199  GNUNET_free (api);
200  return NULL;
201 }
202 
203 
204 /* end of plugin_gnsrecord_dns.c */
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
uint32_t number
#define GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER
Record type for RECLAIM master.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR
Record type for identity attributes (of RECLAIM).
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
void * cls
Closure for all of the callbacks.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF
Record type for reclaim records.
static int 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 a record to the binary representation.
void * libgnunet_plugin_gnsrecord_reclaim_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.
static const char * number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT
Record type for reclaim OIDC clients.
static struct @64 name_map[]
Mapping of record type numbers to human-readable record type names.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE
Record type for reclaim identity references.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR
Record type for reclaim identity attestation.
static char * value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
static uint32_t typename_to_number(void *cls, const char *dns_typename)
Convert a type name (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT
Record type for reclaim OIDC redirect URIs.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * libgnunet_plugin_gnsrecord_reclaim_done(void *cls)
Exit point from the plugin.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET
Record type for local ticket references.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:920
uint32_t data
The data value.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:952
const char * name
#define GNUNET_free(ptr)
Wrapper around free.