GNUnet  0.11.x
Functions | Variables
plugin_gnsrecord_messenger.c File Reference

Plugin to provide the API for useful GNS records to improve the usability of the messenger service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_messenger_service.h"
#include "gnunet_gnsrecord_plugin.h"
Include dependency graph for plugin_gnsrecord_messenger.c:

Go to the source code of this file.

Functions

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. More...
 
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. More...
 
static uint32_t messenger_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (e.g. More...
 
static const char * messenger_number_to_typename (void *cls, uint32_t type)
 Convert a type number to the corresponding type string (e.g. More...
 
void * libgnunet_plugin_gnsrecord_messenger_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_messenger_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
name_map []
 Mapping of record type numbers to human-readable record type names. More...
 

Detailed Description

Plugin to provide the API for useful GNS records to improve the usability of the messenger service.

Author
Tobias Frisch

Definition in file plugin_gnsrecord_messenger.c.

Function Documentation

◆ messenger_value_to_string()

static char* messenger_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of a record to a string.

Parameters
clsclosure, unused
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 44 of file plugin_gnsrecord_messenger.c.

48 {
49  (void) cls;
50  switch (type)
51  {
53  {
54  if (data_size != sizeof(struct GNUNET_MESSENGER_RoomEntryRecord))
55  {
56  GNUNET_break_op (0);
57  return NULL;
58  }
59 
61 
62  char *door = GNUNET_CRYPTO_eddsa_public_key_to_string (&(record->door.public_key));
63  char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode));
64 
65  char *ret;
66  GNUNET_asprintf (&ret, "%s-%s", key, door);
67  GNUNET_free (key);
68  GNUNET_free (door);
69  return ret;
70  }
72  {
73  if (data_size != sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord))
74  {
75  GNUNET_break_op (0);
76  return NULL;
77  }
78 
80 
81  char *name = GNUNET_strndup(record->name, 256);
82  char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), sizeof(uint32_t));
83 
84  char *ret;
85  GNUNET_asprintf (&ret, "%s-%s", flags, name);
87  GNUNET_free (name);
88  return ret;
89  }
90  default:
91  return NULL;
92  }
93 }
#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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
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:251
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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_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:764
const char * name
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.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References data, data_size, GNUNET_MESSENGER_RoomEntryRecord::door, GNUNET_MESSENGER_RoomDetailsRecord::flags, GNUNET_asprintf(), GNUNET_break_op, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_free, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_strndup, key, name, record(), ret, and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messenger_string_to_value()

static int messenger_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 108 of file plugin_gnsrecord_messenger.c.

113 {
114  (void) cls;
115  if (NULL == s)
116  {
117  GNUNET_break (0);
118  return GNUNET_SYSERR;
119  }
120 
121  switch (type)
122  {
124  {
125  char key [103];
126  const char *dash;
127  struct GNUNET_PeerIdentity door;
128 
129  if ((NULL == (dash = strchr (s, '-'))) ||
130  (1 != sscanf (s, "%103s-", key)) ||
132  strlen (dash + 1),
133  &(door.public_key))))
134  {
136  _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
137  s);
138  return GNUNET_SYSERR;
139  }
140 
143  );
144 
146  strlen (key),
147  &(record->key),
148  sizeof(struct GNUNET_HashCode)))
149  {
151  _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"),
152  s);
154  return GNUNET_SYSERR;
155  }
156 
157  record->door = door;
158  *data = record;
160  return GNUNET_OK;
161  }
163  {
164  char flags [7];
165  const char *dash;
166 
167  if ((NULL == (dash = strchr (s, '-'))) ||
168  (1 != sscanf (s, "%7s-", flags)) ||
169  (strlen (dash + 1) > 256))
170  {
172  _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
173  s);
174  return GNUNET_SYSERR;
175  }
176 
179  );
180 
182  strlen (flags),
183  &(record->flags),
184  sizeof(uint32_t)))
185  {
187  _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
188  s);
190  return GNUNET_SYSERR;
191  }
192 
193  GNUNET_memcpy(record->name, dash + 1, strlen(dash + 1));
194 
195  *data = record;
197  return GNUNET_OK;
198  }
199  default:
200  return GNUNET_SYSERR;
201  }
202 }
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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:357
#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
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:789
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
The identity of the host (wraps the signing key of the peer).

References _, data, data_size, GNUNET_MESSENGER_RoomEntryRecord::door, GNUNET_MESSENGER_RoomDetailsRecord::flags, GNUNET_break, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS, GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, key, GNUNET_PeerIdentity::public_key, record(), and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messenger_typename_to_number()

static uint32_t messenger_typename_to_number ( void *  cls,
const char *  gns_typename 
)
static

Convert a type name (e.g.

"AAAA") to the corresponding number.

Parameters
clsclosure, unused
gns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 228 of file plugin_gnsrecord_messenger.c.

230 {
231  unsigned int i;
232 
233  (void) cls;
234  i = 0;
235  while ((name_map[i].name != NULL) &&
236  (0 != strcasecmp (gns_typename, name_map[i].name)))
237  i++;
238  return name_map[i].number;
239 }
static struct @52 name_map[]
Mapping of record type numbers to human-readable record type names.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the caller graph for this function:

◆ messenger_number_to_typename()

static const char* messenger_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number to the corresponding type string (e.g.

1 to "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 250 of file plugin_gnsrecord_messenger.c.

252 {
253  unsigned int i;
254 
255  (void) cls;
256  i = 0;
257  while ((name_map[i].name != NULL) &&
258  (type != name_map[i].number))
259  i++;
260  return name_map[i].name;
261 }

References name, name_map, and type.

Referenced by libgnunet_plugin_gnsrecord_messenger_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_messenger_init()

void* libgnunet_plugin_gnsrecord_messenger_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 271 of file plugin_gnsrecord_messenger.c.

272 {
274 
275  (void) cls;
281  return api;
282 }
static const char * messenger_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
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 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.
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.

References GNUNET_GNSRECORD_PluginFunctions::cls, GNUNET_new, messenger_number_to_typename(), messenger_string_to_value(), messenger_typename_to_number(), messenger_value_to_string(), GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_messenger_done()

void* libgnunet_plugin_gnsrecord_messenger_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 292 of file plugin_gnsrecord_messenger.c.

293 {
295 
296  GNUNET_free (api);
297  return NULL;
298 }

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 212 of file plugin_gnsrecord_messenger.c.

◆ 

struct { ... } name_map[]
Initial value:
= {
{ "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
{ "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
{ NULL, UINT32_MAX }
}

Mapping of record type numbers to human-readable record type names.

Referenced by messenger_number_to_typename(), and messenger_typename_to_number().