aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-16 12:12:39 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-16 12:12:39 +0000
commit54d912e8c447f302172bf6dc3b3fe6769f4ac685 (patch)
treef6cfc4bf40d075509c7c8236be17a503cc3ab558 /src/conversation
parent10e14fa5739998d29fb8f47f54e45df52eff0d9d (diff)
downloadgnunet-54d912e8c447f302172bf6dc3b3fe6769f4ac685.tar.gz
gnunet-54d912e8c447f302172bf6dc3b3fe6769f4ac685.zip
-add gnsrecord plugin for conversation
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/Makefile.am15
-rw-r--r--src/conversation/plugin_gnsrecord_conversation.c224
2 files changed, 239 insertions, 0 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index 5e4ad0d67..92a649d10 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -1,5 +1,7 @@
1SUBDIRS = . 1SUBDIRS = .
2 2
3plugindir = $(libdir)/gnunet
4
3INCLUDES = \ 5INCLUDES = \
4 -I$(top_srcdir)/src/include \ 6 -I$(top_srcdir)/src/include \
5 -I$(top_srcdir) 7 -I$(top_srcdir)
@@ -16,6 +18,19 @@ pkgcfgdir= $(prefix)/share/gnunet/config.d/
16 18
17libexecdir= $(prefix)/lib/gnunet/libexec/ 19libexecdir= $(prefix)/lib/gnunet/libexec/
18 20
21plugin_LTLIBRARIES = \
22 libgnunet_plugin_gnsrecord_conversation.la
23
24
25libgnunet_plugin_gnsrecord_conversation_la_SOURCES = \
26 plugin_gnsrecord_conversation.c
27libgnunet_plugin_gnsrecord_conversation_la_LIBADD = \
28 $(top_builddir)/src/util/libgnunetutil.la \
29 $(LTLIBINTL)
30libgnunet_plugin_gnsrecord_conversation_la_LDFLAGS = \
31 $(GN_PLUGIN_LDFLAGS)
32
33
19libgnunetmicrophone_la_SOURCES = \ 34libgnunetmicrophone_la_SOURCES = \
20 microphone.c 35 microphone.c
21libgnunetmicrophone_la_LIBADD = \ 36libgnunetmicrophone_la_LIBADD = \
diff --git a/src/conversation/plugin_gnsrecord_conversation.c b/src/conversation/plugin_gnsrecord_conversation.c
new file mode 100644
index 000000000..d412d06fa
--- /dev/null
+++ b/src/conversation/plugin_gnsrecord_conversation.c
@@ -0,0 +1,224 @@
1/*
2 This file is part of GNUnet
3 (C) 2013 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
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
28 */
29
30#include "platform.h"
31#include "gnunet_util_lib.h"
32#include "gnunet_gnsrecord_lib.h"
33#include "gnunet_conversation_service.h"
34#include "gnunet_gnsrecord_plugin.h"
35
36
37/**
38 * Convert the 'value' of a record to a string.
39 *
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
45 */
46static char *
47conversation_value_to_string (void *cls,
48 uint32_t type,
49 const void *data,
50 size_t data_size)
51{
52 switch (type)
53 {
54 case GNUNET_GNSRECORD_TYPE_PHONE:
55 {
56 const struct GNUNET_CONVERSATION_PhoneRecord *pr;
57 char *ret;
58 char *pkey;
59
60 if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
61 return NULL;
62 pr = data;
63 if (0 != ntohl (pr->version))
64 return NULL;
65 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&pr->peer.public_key);
66 GNUNET_asprintf (&ret,
67 "%u-%s",
68 ntohl (pr->line),
69 pkey);
70 GNUNET_free (pkey);
71 return ret;
72 }
73 default:
74 return NULL;
75 }
76}
77
78
79/**
80 * Convert human-readable version of a 'value' of a record to the binary
81 * representation.
82 *
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
89 */
90static int
91conversation_string_to_value (void *cls,
92 uint32_t type,
93 const char *s,
94 void **data,
95 size_t *data_size)
96{
97 if (NULL == s)
98 return GNUNET_SYSERR;
99 switch (type)
100 {
101 case GNUNET_GNSRECORD_TYPE_PHONE:
102 {
103 struct GNUNET_CONVERSATION_PhoneRecord *pr;
104 unsigned int line;
105 const char *dash;
106 struct GNUNET_PeerIdentity peer;
107
108 if ( (NULL == (dash = strchr (s, '-'))) ||
109 (1 != sscanf (s, "%u-", &line)) ||
110 (GNUNET_OK !=
111 GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1,
112 strlen (dash + 1),
113 &peer.public_key)) )
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 _("Unable to parse PHONE record `%s'\n"),
117 s);
118 return GNUNET_SYSERR;
119 }
120 pr = GNUNET_new (struct GNUNET_CONVERSATION_PhoneRecord);
121 pr->version = htonl (0);
122 pr->line = htonl ((uint32_t) line);
123 pr->peer = peer;
124 *data = pr;
125 *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
126 return GNUNET_OK;
127 }
128 default:
129 return GNUNET_SYSERR;
130 }
131}
132
133
134/**
135 * Mapping of record type numbers to human-readable
136 * record type names.
137 */
138static struct {
139 const char *name;
140 uint32_t number;
141} name_map[] = {
142 { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE },
143 { NULL, UINT32_MAX }
144};
145
146
147/**
148 * Convert a type name (i.e. "AAAA") to the corresponding number.
149 *
150 * @param cls closure, unused
151 * @param gns_typename name to convert
152 * @return corresponding number, UINT32_MAX on error
153 */
154static uint32_t
155conversation_typename_to_number (void *cls,
156 const char *gns_typename)
157{
158 unsigned int i;
159
160 i=0;
161 while ( (name_map[i].name != NULL) &&
162 (0 != strcasecmp (gns_typename, name_map[i].name)) )
163 i++;
164 return name_map[i].number;
165}
166
167
168/**
169 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
170 *
171 * @param cls closure, unused
172 * @param type number of a type to convert
173 * @return corresponding typestring, NULL on error
174 */
175static const char *
176conversation_number_to_typename (void *cls,
177 uint32_t type)
178{
179 unsigned int i;
180
181 i=0;
182 while ( (name_map[i].name != NULL) &&
183 (type != name_map[i].number) )
184 i++;
185 return name_map[i].name;
186}
187
188
189/**
190 * Entry point for the plugin.
191 *
192 * @param cls NULL
193 * @return the exported block API
194 */
195void *
196libgnunet_plugin_gnsrecord_conversation_init (void *cls)
197{
198 struct GNUNET_GNSRECORD_PluginFunctions *api;
199
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;
205 return api;
206}
207
208
209/**
210 * Exit point from the plugin.
211 *
212 * @param cls the return value from #libgnunet_plugin_block_test_init
213 * @return NULL
214 */
215void *
216libgnunet_plugin_gnsrecord_conversation_done (void *cls)
217{
218 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
219
220 GNUNET_free (api);
221 return NULL;
222}
223
224/* end of plugin_gnsrecord_conversation.c */