aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/plugin_gnsrecord_zklaim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zklaim/plugin_gnsrecord_zklaim.c')
-rw-r--r--src/zklaim/plugin_gnsrecord_zklaim.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/src/zklaim/plugin_gnsrecord_zklaim.c b/src/zklaim/plugin_gnsrecord_zklaim.c
new file mode 100644
index 000000000..7e032d210
--- /dev/null
+++ b/src/zklaim/plugin_gnsrecord_zklaim.c
@@ -0,0 +1,178 @@
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
19/**
20 * @file zklaim/plugin_gnsrecord_zklaim.c
21 * @brief gnsrecord plugin to provide the API for identity records
22 * @author Martin Schanzenbach
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_gnsrecord_lib.h"
27#include "gnunet_gnsrecord_plugin.h"
28
29
30/**
31 * Convert the 'value' of a record to a string.
32 *
33 * @param cls closure, unused
34 * @param type type of the record
35 * @param data value in binary encoding
36 * @param data_size number of bytes in @a data
37 * @return NULL on error, otherwise human-readable representation of the value
38 */
39static char *
40value_to_string (void *cls,
41 uint32_t type,
42 const void *data,
43 size_t data_size)
44{
45 switch (type)
46 {
47 case GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX:
48 return GNUNET_STRINGS_data_to_string_alloc (data, data_size);
49 default:
50 return NULL;
51 }
52}
53
54
55/**
56 * Convert human-readable version of a 'value' of a record to the binary
57 * representation.
58 *
59 * @param cls closure, unused
60 * @param type type of the record
61 * @param s human-readable string
62 * @param data set to value in binary encoding (will be allocated)
63 * @param data_size set to number of bytes in @a data
64 * @return #GNUNET_OK on success
65 */
66static int
67string_to_value (void *cls,
68 uint32_t type,
69 const char *s,
70 void **data,
71 size_t *data_size)
72{
73 if (NULL == s)
74 return GNUNET_SYSERR;
75 switch (type)
76 {
77 case GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX:
78 return GNUNET_STRINGS_string_to_data (s,
79 strlen (s),
80 *data,
81 *data_size);
82 default:
83 return GNUNET_SYSERR;
84 }
85}
86
87
88/**
89 * Mapping of record type numbers to human-readable
90 * record type names.
91 */
92static struct {
93 const char *name;
94 uint32_t number;
95} name_map[] = {
96 { "ZKLAIM_CTX", GNUNET_GNSRECORD_TYPE_ZKLAIM_CTX },
97 { NULL, UINT32_MAX }
98};
99
100
101/**
102 * Convert a type name (i.e. "AAAA") to the corresponding number.
103 *
104 * @param cls closure, unused
105 * @param dns_typename name to convert
106 * @return corresponding number, UINT32_MAX on error
107 */
108static uint32_t
109typename_to_number (void *cls,
110 const char *dns_typename)
111{
112 unsigned int i;
113
114 i=0;
115 while ( (NULL != name_map[i].name) &&
116 (0 != strcasecmp (dns_typename, name_map[i].name)) )
117 i++;
118 return name_map[i].number;
119}
120
121
122/**
123 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
124 *
125 * @param cls closure, unused
126 * @param type number of a type to convert
127 * @return corresponding typestring, NULL on error
128 */
129static const char *
130number_to_typename (void *cls,
131 uint32_t type)
132{
133 unsigned int i;
134
135 i=0;
136 while ( (NULL != name_map[i].name) &&
137 (type != name_map[i].number) )
138 i++;
139 return name_map[i].name;
140}
141
142
143/**
144 * Entry point for the plugin.
145 *
146 * @param cls NULL
147 * @return the exported block API
148 */
149void *
150libgnunet_plugin_gnsrecord_zklaim_init (void *cls)
151{
152 struct GNUNET_GNSRECORD_PluginFunctions *api;
153
154 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
155 api->value_to_string = &value_to_string;
156 api->string_to_value = &string_to_value;
157 api->typename_to_number = &typename_to_number;
158 api->number_to_typename = &number_to_typename;
159 return api;
160}
161
162
163/**
164 * Exit point from the plugin.
165 *
166 * @param cls the return value from #libgnunet_plugin_block_test_init
167 * @return NULL
168 */
169void *
170libgnunet_plugin_gnsrecord_zklaim_done (void *cls)
171{
172 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
173
174 GNUNET_free (api);
175 return NULL;
176}
177
178/* end of plugin_gnsrecord_dns.c */