GNUnet  0.10.x
plugin_gnsrecord_conversation.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2013 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  SPDX-License-Identifier: AGPL3.0-or-later
19 */
20 
30 #include "platform.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_gnsrecord_lib.h"
35 
36 
46 static char *
48  uint32_t type,
49  const void *data,
50  size_t data_size)
51 {
52  char *s;
53 
54  (void) cls;
55  switch (type)
56  {
58  {
59  const struct GNUNET_CONVERSATION_PhoneRecord *pr;
60  char *ret;
61  char *pkey;
62 
63  if (data_size != sizeof (struct GNUNET_CONVERSATION_PhoneRecord))
64  {
65  GNUNET_break_op (0);
66  return NULL;
67  }
68  pr = data;
69  if (1 != ntohl (pr->version))
70  {
72  _("PHONE version %u not supported\n"),
73  ntohl (pr->version));
74  return NULL;
75  }
78  sizeof (struct GNUNET_HashCode));
79 
80  GNUNET_asprintf (&ret,
81  "%s-%s",
82  s,
83  pkey);
84  GNUNET_free (s);
85  GNUNET_free (pkey);
86  return ret;
87  }
88  default:
89  return NULL;
90  }
91 }
92 
93 
105 static int
107  uint32_t type,
108  const char *s,
109  void **data,
110  size_t *data_size)
111 {
112  (void) cls;
113  if (NULL == s)
114  {
115  GNUNET_break (0);
116  return GNUNET_SYSERR;
117  }
118  switch (type)
119  {
121  {
123  char line_port[103];
124  const char *dash;
125  struct GNUNET_PeerIdentity peer;
126 
127  if ( (NULL == (dash = strchr (s, '-'))) ||
128  (1 != sscanf (s, "%103s-", line_port)) ||
129  (GNUNET_OK !=
131  strlen (dash + 1),
132  &peer.public_key)) )
133  {
135  _("Unable to parse PHONE record `%s'\n"),
136  s);
137  return GNUNET_SYSERR;
138  }
140  pr->version = htonl (1);
141  pr->reserved = htonl (0);
142  if (GNUNET_OK !=
144  strlen (line_port),
145  &pr->line_port,
146  sizeof (struct GNUNET_HashCode)))
147  {
149  _("Unable to parse PHONE record `%s'\n"),
150  s);
151  GNUNET_free (pr);
152  return GNUNET_SYSERR;
153  }
154  pr->peer = peer;
155  *data = pr;
156  *data_size = sizeof (struct GNUNET_CONVERSATION_PhoneRecord);
157  return GNUNET_OK;
158  }
159  default:
160  return GNUNET_SYSERR;
161  }
162 }
163 
164 
169 static struct {
170  const char *name;
171  uint32_t number;
172 } name_map[] = {
173  { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE },
174  { NULL, UINT32_MAX }
175 };
176 
177 
185 static uint32_t
187  const char *gns_typename)
188 {
189  unsigned int i;
190 
191  (void) cls;
192  i=0;
193  while ( (name_map[i].name != NULL) &&
194  (0 != strcasecmp (gns_typename, name_map[i].name)) )
195  i++;
196  return name_map[i].number;
197 }
198 
199 
207 static const char *
209  uint32_t type)
210 {
211  unsigned int i;
212 
213  (void) cls;
214  i=0;
215  while ( (name_map[i].name != NULL) &&
216  (type != name_map[i].number) )
217  i++;
218  return name_map[i].name;
219 }
220 
221 
228 void *
230 {
232 
233  (void) cls;
239  return api;
240 }
241 
242 
249 void *
251 {
253 
254  GNUNET_free (api);
255  return NULL;
256 }
257 
258 /* end of plugin_gnsrecord_conversation.c */
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
struct GNUNET_PeerIdentity peer
Identity of the peer hosting the phone service.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
static const char * conversation_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
static char * pkey
Public key of the zone to look in, in ASCII.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
static uint32_t conversation_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (i.e.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
void * libgnunet_plugin_gnsrecord_conversation_init(void *cls)
Entry point for the plugin.
void * cls
Closure for all of the callbacks.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_GNSRECORD_TYPE_PHONE
Record type for a phone (of CONVERSATION).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int conversation_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a &#39;value&#39; of a record to the binary representation.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
A phone record specifies which peer is hosting a given user and may also specify the phone line that ...
static char * conversation_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:367
void * libgnunet_plugin_gnsrecord_conversation_done(void *cls)
Exit point from the plugin.
A 512-bit hashcode.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name
uint32_t version
Version of the phone record, for now always one.
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:501
The identity of the host (wraps the signing key of the peer).
static struct @9 name_map[]
Mapping of record type numbers to human-readable record type names.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_log(kind,...)
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:988
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:1021
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key