GNUnet  0.19.4
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  {
49  return GNUNET_strndup (data, data_size);
56 
57  default:
58  return NULL;
59  }
60 }
61 
62 
74 static int
75 string_to_value (void *cls, uint32_t type, const char *s, void **data,
76  size_t *data_size)
77 {
78  if (NULL == s)
79  return GNUNET_SYSERR;
80  switch (type)
81  {
84  *data = GNUNET_strdup (s);
85  *data_size = strlen (s);
86  return GNUNET_OK;
92  return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
93 
94  default:
95  return GNUNET_SYSERR;
96  }
97 }
98 
99 
104 static struct
105 {
106  const char *name;
107  uint32_t number;
108 } name_map[] = {
109  { "RECLAIM_ATTRIBUTE", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE },
110  { "RECLAIM_ATTRIBUTE_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF },
111  { "RECLAIM_CREDENTIAL", GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL },
112  { "RECLAIM_PRESENTATION", GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION },
113  { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT },
114  { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT },
115  { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET },
116  { NULL, UINT32_MAX }
117 };
118 
119 
127 static uint32_t
128 typename_to_number (void *cls, const char *dns_typename)
129 {
130  unsigned int i;
131 
132  i = 0;
133  while ((NULL != name_map[i].name) &&
134  (0 != strcasecmp (dns_typename, name_map[i].name)))
135  i++;
136  return name_map[i].number;
137 }
138 
139 
147 static const char *
148 number_to_typename (void *cls, uint32_t type)
149 {
150  unsigned int i;
151 
152  i = 0;
153  while ((NULL != name_map[i].name) && (type != name_map[i].number))
154  i++;
155  return name_map[i].name;
156 }
157 
158 
165 void *
167 {
169 
175  return api;
176 }
177 
178 
185 void *
187 {
189 
190  GNUNET_free (api);
191  return NULL;
192 }
193 
194 
195 /* end of plugin_gnsrecord_dns.c */
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE
identity attribute
#define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION
Record type for a presentation of a credential.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF
for reclaim records
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT
For reclaim OIDC client names.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL
Record type for an attribute attestation (e.g.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT
Used reclaimID OIDC client redirect URIs.
#define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET
local ticket reference
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
API that can be used to manipulate GNS record data.
Plugin API for GNS record 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.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:763
enum GNUNET_GenericReturnValue 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:788
static uint32_t typename_to_number(void *cls, const char *dns_typename)
Convert a type name (e.g.
static const char * number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static struct @53 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
void * libgnunet_plugin_gnsrecord_reclaim_done(void *cls)
Exit point from the plugin.
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 'value' of a record to the binary representation.
uint32_t number
static char * value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
void * libgnunet_plugin_gnsrecord_reclaim_init(void *cls)
Entry point for the plugin.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
void * cls
Closure for all of the callbacks.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model