aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-10-29 16:16:39 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-10-29 16:16:39 +0000
commit26e8eee69350d1d0159bbf0b29a1a5a82be744a6 (patch)
tree6b002beb84ddf9fbb9c0cb0f9da02bd4811d4d95
parent07cf21cb24446f7e5f71e9c464fc471600909bb5 (diff)
downloadgnunet-26e8eee69350d1d0159bbf0b29a1a5a82be744a6.tar.gz
gnunet-26e8eee69350d1d0159bbf0b29a1a5a82be744a6.zip
-fix build
-rw-r--r--src/identity/Makefile.am4
-rw-r--r--src/identity/plugin_gnsrecord_identity.c182
2 files changed, 184 insertions, 2 deletions
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index f793c2fc8..0a0f08fc3 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -41,8 +41,8 @@ libexec_PROGRAMS = \
41 41
42if HAVE_REST 42if HAVE_REST
43plugin_LTLIBRARIES = \ 43plugin_LTLIBRARIES = \
44 libgnunet_plugin_rest_identity.la 44 libgnunet_plugin_rest_identity.la \
45# libgnunet_plugin_gnsrecord_identity.la 45 libgnunet_plugin_gnsrecord_identity.la
46endif 46endif
47 47
48 48
diff --git a/src/identity/plugin_gnsrecord_identity.c b/src/identity/plugin_gnsrecord_identity.c
new file mode 100644
index 000000000..693167713
--- /dev/null
+++ b/src/identity/plugin_gnsrecord_identity.c
@@ -0,0 +1,182 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file gnsrecord/plugin_gnsrecord_identity.c
23 * @brief gnsrecord plugin to provide the API for identity records
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_gnsrecord_lib.h"
29#include "gnunet_gnsrecord_plugin.h"
30
31
32/**
33 * Convert the 'value' of a record to a string.
34 *
35 * @param cls closure, unused
36 * @param type type of the record
37 * @param data value in binary encoding
38 * @param data_size number of bytes in @a data
39 * @return NULL on error, otherwise human-readable representation of the value
40 */
41static char *
42value_to_string (void *cls,
43 uint32_t type,
44 const void *data,
45 size_t data_size)
46{
47 switch (type)
48 {
49 case GNUNET_GNSRECORD_TYPE_ID_ATTR:
50 case GNUNET_GNSRECORD_TYPE_ID_TOKEN:
51 return GNUNET_strndup (data, data_size);
52 default:
53 return NULL;
54 }
55}
56
57
58/**
59 * Convert human-readable version of a 'value' of a record to the binary
60 * representation.
61 *
62 * @param cls closure, unused
63 * @param type type of the record
64 * @param s human-readable string
65 * @param data set to value in binary encoding (will be allocated)
66 * @param data_size set to number of bytes in @a data
67 * @return #GNUNET_OK on success
68 */
69static int
70string_to_value (void *cls,
71 uint32_t type,
72 const char *s,
73 void **data,
74 size_t *data_size)
75{
76 if (NULL == s)
77 return GNUNET_SYSERR;
78 switch (type)
79 {
80 case GNUNET_GNSRECORD_TYPE_ID_ATTR:
81 case GNUNET_GNSRECORD_TYPE_ID_TOKEN:
82 *data = GNUNET_strdup (s);
83 *data_size = strlen (s);
84 return GNUNET_OK;
85 default:
86 return GNUNET_SYSERR;
87 }
88}
89
90
91/**
92 * Mapping of record type numbers to human-readable
93 * record type names.
94 */
95static struct {
96 const char *name;
97 uint32_t number;
98} name_map[] = {
99 { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR },
100 { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN },
101 { NULL, UINT32_MAX }
102};
103
104
105/**
106 * Convert a type name (i.e. "AAAA") to the corresponding number.
107 *
108 * @param cls closure, unused
109 * @param dns_typename name to convert
110 * @return corresponding number, UINT32_MAX on error
111 */
112static uint32_t
113typename_to_number (void *cls,
114 const char *dns_typename)
115{
116 unsigned int i;
117
118 i=0;
119 while ( (NULL != name_map[i].name) &&
120 (0 != strcasecmp (dns_typename, name_map[i].name)) )
121 i++;
122 return name_map[i].number;
123}
124
125
126/**
127 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
128 *
129 * @param cls closure, unused
130 * @param type number of a type to convert
131 * @return corresponding typestring, NULL on error
132 */
133static const char *
134number_to_typename (void *cls,
135 uint32_t type)
136{
137 unsigned int i;
138
139 i=0;
140 while ( (NULL != name_map[i].name) &&
141 (type != name_map[i].number) )
142 i++;
143 return name_map[i].name;
144}
145
146
147/**
148 * Entry point for the plugin.
149 *
150 * @param cls NULL
151 * @return the exported block API
152 */
153void *
154libgnunet_plugin_gnsrecord_identity_init (void *cls)
155{
156 struct GNUNET_GNSRECORD_PluginFunctions *api;
157
158 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
159 api->value_to_string = &value_to_string;
160 api->string_to_value = &string_to_value;
161 api->typename_to_number = &typename_to_number;
162 api->number_to_typename = &number_to_typename;
163 return api;
164}
165
166
167/**
168 * Exit point from the plugin.
169 *
170 * @param cls the return value from #libgnunet_plugin_block_test_init
171 * @return NULL
172 */
173void *
174libgnunet_plugin_gnsrecord_identity_done (void *cls)
175{
176 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
177
178 GNUNET_free (api);
179 return NULL;
180}
181
182/* end of plugin_gnsrecord_dns.c */