GNUnet  0.11.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 
89  default:
90  return NULL;
91  }
92 }
93 
94 
106 static int
108  uint32_t type,
109  const char *s,
110  void **data,
111  size_t *data_size)
112 {
113  (void) cls;
114  if (NULL == s)
115  {
116  GNUNET_break (0);
117  return GNUNET_SYSERR;
118  }
119  switch (type)
120  {
122  {
124  char line_port[103];
125  const char *dash;
126  struct GNUNET_PeerIdentity peer;
127 
128  if ((NULL == (dash = strchr (s, '-'))) ||
129  (1 != sscanf (s, "%103s-", line_port)) ||
130  (GNUNET_OK !=
132  strlen (dash + 1),
133  &peer.public_key)))
134  {
136  _ ("Unable to parse PHONE record `%s'\n"),
137  s);
138  return GNUNET_SYSERR;
139  }
141  pr->version = htonl (1);
142  pr->reserved = htonl (0);
143  if (GNUNET_OK !=
145  strlen (line_port),
146  &pr->line_port,
147  sizeof(struct GNUNET_HashCode)))
148  {
150  _ ("Unable to parse PHONE record `%s'\n"),
151  s);
152  GNUNET_free (pr);
153  return GNUNET_SYSERR;
154  }
155  pr->peer = peer;
156  *data = pr;
157  *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord);
158  return GNUNET_OK;
159  }
160 
161  default:
162  return GNUNET_SYSERR;
163  }
164 }
165 
166 
171 static struct
172 {
173  const char *name;
174  uint32_t number;
175 } name_map[] = {
176  { "PHONE", GNUNET_GNSRECORD_TYPE_PHONE },
177  { NULL, UINT32_MAX }
178 };
179 
180 
188 static uint32_t
190  const char *gns_typename)
191 {
192  unsigned int i;
193 
194  (void) cls;
195  i = 0;
196  while ((name_map[i].name != NULL) &&
197  (0 != strcasecmp (gns_typename, name_map[i].name)))
198  i++;
199  return name_map[i].number;
200 }
201 
202 
210 static const char *
212  uint32_t type)
213 {
214  unsigned int i;
215 
216  (void) cls;
217  i = 0;
218  while ((name_map[i].name != NULL) &&
219  (type != name_map[i].number))
220  i++;
221  return name_map[i].name;
222 }
223 
224 
231 void *
233 {
235 
236  (void) cls;
242  return api;
243 }
244 
245 
252 void *
254 {
256 
257  GNUNET_free (api);
258  return NULL;
259 }
260 
261 
262 /* 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 struct @7 name_map[]
Mapping of record type numbers to human-readable record type names.
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.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
void * libgnunet_plugin_gnsrecord_conversation_init(void *cls)
Entry point for the plugin.
void * cls
Closure for all of the callbacks.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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.
#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:181
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:365
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:76
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:499
The identity of the host (wraps the signing key of the peer).
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:920
uint32_t data
The data value.
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:952
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key