2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file conversation/plugin_gnsrecord_conversation.c
23 * @brief gnsrecord plugin to provide the API for fundamental GNS records
24 * This includes the VPN record because GNS resolution
25 * is expected to understand VPN records and (if needed)
26 * map the result to A/AAAA.
27 * @author Christian Grothoff
31 #include "gnunet_util_lib.h"
32 #include "gnunet_gnsrecord_lib.h"
33 #include "gnunet_conversation_service.h"
34 #include "gnunet_gnsrecord_plugin.h"
38 * Convert the 'value' of a record to a string.
40 * @param cls closure, unused
41 * @param type type of the record
42 * @param data value in binary encoding
43 * @param data_size number of bytes in @a data
44 * @return NULL on error, otherwise human-readable representation of the value
47 conversation_value_to_string (void *cls,
54 case GNUNET_GNSRECORD_TYPE_PHONE:
56 const struct GNUNET_CONVERSATION_PhoneRecord *pr;
60 if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
63 if (0 != ntohl (pr->version))
65 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key);
66 GNUNET_asprintf (&ret,
80 * Convert human-readable version of a 'value' of a record to the binary
83 * @param cls closure, unused
84 * @param type type of the record
85 * @param s human-readable string
86 * @param data set to value in binary encoding (will be allocated)
87 * @param data_size set to number of bytes in @a data
88 * @return #GNUNET_OK on success
91 conversation_string_to_value (void *cls,
101 case GNUNET_GNSRECORD_TYPE_PHONE:
103 struct GNUNET_CONVERSATION_PhoneRecord *pr;
106 struct GNUNET_PeerIdentity peer;
108 if ( (NULL == (dash = strchr (s, '-'))) ||
109 (1 != sscanf (s, "%u-", &line)) ||
111 GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1,
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 _("Unable to parse PHONE record `%s'\n"),
118 return GNUNET_SYSERR;
120 pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord);
121 pr->version = htonl (0);
122 pr->line = htonl ((uint32_t) line);
125 *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
129 return GNUNET_SYSERR;
135 * Mapping of record type numbers to human-readable
142 { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE },
148 * Convert a type name (i.e. "AAAA") to the corresponding number.
150 * @param cls closure, unused
151 * @param gns_typename name to convert
152 * @return corresponding number, UINT32_MAX on error
155 conversation_typename_to_number (void *cls,
156 const char *gns_typename)
161 while ( (name_map[i].name != NULL) &&
162 (0 != strcasecmp (gns_typename, name_map[i].name)) )
164 return name_map[i].number;
169 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
171 * @param cls closure, unused
172 * @param type number of a type to convert
173 * @return corresponding typestring, NULL on error
176 conversation_number_to_typename (void *cls,
182 while ( (name_map[i].name != NULL) &&
183 (type != name_map[i].number) )
185 return name_map[i].name;
190 * Entry point for the plugin.
193 * @return the exported block API
196 libgnunet_plugin_gnsrecord_conversation_init (void *cls)
198 struct GNUNET_GNSRECORD_PluginFunctions *api;
200 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
201 api->value_to_string = &conversation_value_to_string;
202 api->string_to_value = &conversation_string_to_value;
203 api->typename_to_number = &conversation_typename_to_number;
204 api->number_to_typename = &conversation_number_to_typename;
210 * Exit point from the plugin.
212 * @param cls the return value from #libgnunet_plugin_block_test_init
216 libgnunet_plugin_gnsrecord_conversation_done (void *cls)
218 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
224 /* end of plugin_gnsrecord_conversation.c */