GNUnet 0.22.2
plugin_gnsrecord_messenger.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021--2024 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 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnu_name_system_record_types.h"
32
33
43static char *
45 uint32_t type,
46 const void *data,
47 size_t data_size)
48{
49 (void) cls;
50 switch (type)
51 {
53 {
54 if (data_size != sizeof(struct GNUNET_MESSENGER_RoomEntryRecord))
55 {
57 return NULL;
58 }
59 {
61
63 &(record->door.public_key));
65 sizeof(struct
67 );
68
69 char *ret;
70 GNUNET_asprintf (&ret, "%s-%s", key, door);
73 return ret;
74 }
75 }
77 {
79 {
81 return NULL;
82 }
83 {
85
86 char *name = GNUNET_strndup (record->name, 256);
88 sizeof(uint32_t));
89
90 char *ret;
91 GNUNET_asprintf (&ret, "%s-%s", flags, name);
94 return ret;
95 }
96 }
97 default:
98 return NULL;
99 }
100}
101
102
114static int
116 uint32_t type,
117 const char *s,
118 void **data,
119 size_t *data_size)
120{
121 (void) cls;
122 if (NULL == s)
123 {
124 GNUNET_break (0);
125 return GNUNET_SYSERR;
126 }
127
128 switch (type)
129 {
131 {
132 char key[104];
133 const char *dash;
134 struct GNUNET_PeerIdentity door;
135
136 if ((NULL == (dash = strchr (s, '-'))) ||
137 (1 != sscanf (s, "%103s-", key)) ||
139 strlen (
140 dash + 1),
141 &(door.
142 public_key))))
143 {
145 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
146 s);
147 return GNUNET_SYSERR;
148 }
149 {
152 );
153
155 strlen (key),
156 &(record->key),
157 sizeof(struct
159 )
160 {
162 _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
163 s);
165 return GNUNET_SYSERR;
166 }
167
168 record->door = door;
169 *data = record;
171 return GNUNET_OK;
172 }
173 }
175 {
176 char flags[8];
177 const char *dash;
178
179 if ((NULL == (dash = strchr (s, '-'))) ||
180 (1 != sscanf (s, "%7s-", flags)) ||
181 (strlen (dash + 1) > 256))
182 {
184 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
185 s);
186 return GNUNET_SYSERR;
187 }
188 {
191 );
192
194 strlen (flags),
195 &(record->flags),
196 sizeof(uint32_t)))
197 {
199 _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n")
200 ,
201 s);
203 return GNUNET_SYSERR;
204 }
205
206 GNUNET_memcpy (record->name, dash + 1, strlen (dash + 1));
207
208 *data = record;
210 return GNUNET_OK;
211 }
212 }
213 default:
214 return GNUNET_SYSERR;
215 }
216}
217
218
223static struct
224{
225 const char *name;
226 uint32_t number;
227} name_map[] = {
228 { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
229 { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
230 { NULL, UINT32_MAX }
232
233
241static uint32_t
243 const char *gns_typename)
244{
245 unsigned int i;
246
247 (void) cls;
248 i = 0;
249 while ((name_map[i].name != NULL) &&
250 (0 != strcasecmp (gns_typename, name_map[i].name)))
251 i++;
252 return name_map[i].number;
253}
254
255
263static const char *
265 uint32_t type)
266{
267 unsigned int i;
268
269 (void) cls;
270 i = 0;
271 while ((name_map[i].name != NULL) &&
272 (type != name_map[i].number))
273 i++;
274 return name_map[i].name;
275}
276
277
278void *
280
287void *
289{
291
292 (void) cls;
298 return api;
299}
300
301
302void *
304
311void *
313{
315
316 GNUNET_free (api);
317 return NULL;
318}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
Plugin API for GNS record types.
#define GNUNET_log(kind,...)
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:255
enum GNUNET_GenericReturnValue 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:361
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:787
enum GNUNET_GenericReturnValue 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:812
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
void * libgnunet_plugin_gnsrecord_messenger_init(void *cls)
Entry point for the plugin.
void * libgnunet_plugin_gnsrecord_messenger_done(void *cls)
Exit point from the plugin.
static char * messenger_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
static struct @39 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
static const char * messenger_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static uint32_t messenger_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (e.g.
static int messenger_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of a record to the binary representation.
uint32_t number
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY
Record type to share an entry of a messenger room.
#define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS
Record type to store details about a messenger room.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
void * cls
Closure for all of the callbacks.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
A 512-bit hashcode.
A room details record specifies a custom name for a given room and some additional space for flags.
uint32_t flags
The flags of the room.
A room entry record specifies which peer is hosting a given room and may also specify the key to ente...
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key