2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file reclaim/plugin_gnsrecord_reclaim.c
23 * @brief gnsrecord plugin to provide the API for identity records
24 * @author Martin Schanzenbach
28 #include "gnunet_util_lib.h"
30 #include "gnunet_gnsrecord_lib.h"
31 #include "gnunet_gnsrecord_plugin.h"
34 * Convert the 'value' of a record to a string.
36 * @param cls closure, unused
37 * @param type type of the record
38 * @param data value in binary encoding
39 * @param data_size number of bytes in @a data
40 * @return NULL on error, otherwise human-readable representation of the value
43 value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
47 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR:
48 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
50 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
51 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
52 return GNUNET_strndup (data, data_size);
54 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF:
55 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET:
56 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
57 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR:
58 case GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE:
59 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
68 * Convert human-readable version of a 'value' of a record to the binary
71 * @param cls closure, unused
72 * @param type type of the record
73 * @param s human-readable string
74 * @param data set to value in binary encoding (will be allocated)
75 * @param data_size set to number of bytes in @a data
76 * @return #GNUNET_OK on success
79 string_to_value (void *cls, uint32_t type, const char *s, void **data,
86 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR:
87 return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
89 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT:
90 case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT:
91 *data = GNUNET_strdup (s);
92 *data_size = strlen (s);
95 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF:
96 case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER:
97 case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET:
98 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR:
99 case GNUNET_GNSRECORD_TYPE_RECLAIM_REFERENCE:
100 return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size);
103 return GNUNET_SYSERR;
109 * Mapping of record type numbers to human-readable
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 },
130 * Convert a type name (i.e. "AAAA") to the corresponding number.
132 * @param cls closure, unused
133 * @param dns_typename name to convert
134 * @return corresponding number, UINT32_MAX on error
137 typename_to_number (void *cls, const char *dns_typename)
142 while ((NULL != name_map[i].name) &&
143 (0 != strcasecmp (dns_typename, name_map[i].name)))
145 return name_map[i].number;
150 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
152 * @param cls closure, unused
153 * @param type number of a type to convert
154 * @return corresponding typestring, NULL on error
157 number_to_typename (void *cls, uint32_t type)
162 while ((NULL != name_map[i].name) && (type != name_map[i].number))
164 return name_map[i].name;
169 * Entry point for the plugin.
172 * @return the exported block API
175 libgnunet_plugin_gnsrecord_reclaim_init (void *cls)
177 struct GNUNET_GNSRECORD_PluginFunctions *api;
179 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
180 api->value_to_string = &value_to_string;
181 api->string_to_value = &string_to_value;
182 api->typename_to_number = &typename_to_number;
183 api->number_to_typename = &number_to_typename;
189 * Exit point from the plugin.
191 * @param cls the return value from #libgnunet_plugin_block_test_init
195 libgnunet_plugin_gnsrecord_reclaim_done (void *cls)
197 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
204 /* end of plugin_gnsrecord_dns.c */