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

gnsrecord plugin to provide the API for ABD records More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "delegate_misc.h"
#include "abd_serialization.h"
#include "gnunet_abd_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gnsrecord_plugin.h"
#include "gnunet_signatures.h"
Include dependency graph for plugin_gnsrecord_abd.c:

Go to the source code of this file.

Functions

static char * abd_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 abd_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 abd_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (i.e. More...
 
static const char * abd_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
void * libgnunet_plugin_gnsrecord_abd_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_abd_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

gnsrecord plugin to provide the API for ABD records

Author
Martin Schanzenbach

Definition in file plugin_gnsrecord_abd.c.

Function Documentation

◆ abd_value_to_string()

static char* abd_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 46 of file plugin_gnsrecord_abd.c.

References data, GNUNET_ABD_delegate_deserialize(), GNUNET_ABD_delegate_to_string(), GNUNET_ABD_delegation_set_deserialize(), GNUNET_asprintf(), GNUNET_CRYPTO_ecdsa_public_key_to_string(), GNUNET_free, GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNSRECORD_TYPE_DELEGATE, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_ABD_DelegationSet::subject_attribute, GNUNET_ABD_DelegationSet::subject_attribute_len, GNUNET_ABD_DelegationSet::subject_key, and subject_pkey.

Referenced by libgnunet_plugin_gnsrecord_abd_init().

50 {
51  const char *cdata;
52 
53  switch (type)
54  {
56  {
57  struct GNUNET_ABD_DelegationRecord sets;
58  char *attr_str;
59  char *subject_pkey;
60  char *tmp_str;
61  int i;
62  if (data_size < sizeof (struct GNUNET_ABD_DelegationRecord))
63  return NULL; /* malformed */
64 
65  GNUNET_memcpy (&sets, data, sizeof (sets));
66  cdata = data;
67 
68  struct GNUNET_ABD_DelegationSet set[ntohl (sets.set_count)];
69  if (GNUNET_OK !=
71  sets.data_size),
72  &cdata[sizeof (sets)],
73  ntohl (sets.set_count),
74  set))
75  return NULL;
76 
77  for (i = 0; i < ntohl (sets.set_count); i++)
78  {
79  subject_pkey =
81 
82  if (0 == set[i].subject_attribute_len)
83  {
84  if (0 == i)
85  {
86  GNUNET_asprintf (&attr_str, "%s", subject_pkey);
87  }
88  else
89  {
90  GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey);
91  GNUNET_free (attr_str);
92  attr_str = tmp_str;
93  }
94  }
95  else
96  {
97  if (0 == i)
98  {
99  GNUNET_asprintf (&attr_str,
100  "%s %s",
101  subject_pkey,
102  set[i].subject_attribute);
103  }
104  else
105  {
106  GNUNET_asprintf (&tmp_str,
107  "%s,%s %s",
108  attr_str,
109  subject_pkey,
110  set[i].subject_attribute);
111  GNUNET_free (attr_str);
112  attr_str = tmp_str;
113  }
114  }
115  GNUNET_free (subject_pkey);
116  }
117  return attr_str;
118  }
120  {
121  struct GNUNET_ABD_Delegate *cred;
122  char *cred_str;
123 
125  cred_str = GNUNET_ABD_delegate_to_string (cred);
126  GNUNET_free (cred);
127  return cred_str;
128  }
129  default:
130  return NULL;
131  }
132 }
char * GNUNET_ABD_delegate_to_string(const struct GNUNET_ABD_Delegate *cred)
Definition: delegate_misc.c:37
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
The attribute delegation record.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_GNSRECORD_TYPE_DELEGATE
65546 reserved
struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_deserialize(const char *data, size_t data_size)
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:101
const char * subject_attribute
The subject attribute.
char * GNUNET_CRYPTO_ecdsa_public_key_to_string(const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:237
int GNUNET_ABD_delegation_set_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_DelegationSet *dsr)
Deserialize the given destination.
The attribute delegation record.
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ abd_string_to_value()

static int abd_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 147 of file plugin_gnsrecord_abd.c.

References _, entries, GNUNET_ABD_delegate_from_string(), GNUNET_ABD_delegate_serialize(), GNUNET_ABD_delegation_set_get_size(), GNUNET_ABD_delegation_set_serialize(), GNUNET_CRYPTO_ecdsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNSRECORD_TYPE_DELEGATE, GNUNET_htonll(), GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, GNUNET_ABD_DelegationSet::subject_attribute, GNUNET_ABD_DelegationSet::subject_attribute_len, GNUNET_ABD_DelegationSet::subject_key, and subject_pkey.

Referenced by libgnunet_plugin_gnsrecord_abd_init().

152 {
153  if (NULL == s)
154  return GNUNET_SYSERR;
155  switch (type)
156  {
158  {
159  struct GNUNET_ABD_DelegationRecord *sets;
160  char attr_str[253 + 1];
161  char subject_pkey[52 + 1];
162  char *token;
163  char *tmp_str;
164  int matches = 0;
165  int entries;
166  size_t tmp_data_size;
167  int i;
168 
169  tmp_str = GNUNET_strdup (s);
170  token = strtok (tmp_str, ",");
171  entries = 0;
172  tmp_data_size = 0;
173  *data_size = sizeof (struct GNUNET_ABD_DelegationRecord);
174  while (NULL != token)
175  {
176  // also fills the variables subject_pley and attr_str if "regex"-like match
177  matches = sscanf (token, "%s %s", subject_pkey, attr_str);
178 
179  if (0 == matches)
180  {
182  _ ("Unable to parse ATTR record string `%s'\n"),
183  s);
184  GNUNET_free (tmp_str);
185  return GNUNET_SYSERR;
186  }
187 
188  entries++;
189  token = strtok (NULL, ",");
190  }
191  GNUNET_free (tmp_str);
192 
193  tmp_str = GNUNET_strdup (s);
194  token = strtok (tmp_str, ",");
195  if (NULL == token)
196  {
197  GNUNET_free (tmp_str);
198  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
199  return GNUNET_SYSERR;
200  }
201 
202  struct GNUNET_ABD_DelegationSet set[entries];
203  // sets memory to be 0, starting at *set for the size of struct * entries
204  memset (set, 0, sizeof (struct GNUNET_ABD_DelegationSet) * entries);
205  for (i = 0; i < entries; i++)
206  {
207  matches = sscanf (token, "%s %s", subject_pkey, attr_str);
208 
209  // sets the public key for the set entry
211  strlen (subject_pkey),
212  &set[i].subject_key);
213 
214  // If not just key, also set subject attribute (Not A.a <- B but A.a <- B.b)
215  if (2 == matches)
216  {
217  set[i].subject_attribute_len = strlen (attr_str) + 1;
218  set[i].subject_attribute = GNUNET_strdup (attr_str);
219  }
220  // If more entries, then token string can take the next entry (separated by ',') by calling strtok again
221  token = strtok (NULL, ",");
222  }
223  tmp_data_size = GNUNET_ABD_delegation_set_get_size (entries, set);
224 
225  if (-1 == tmp_data_size)
226  {
227  GNUNET_free (tmp_str);
228  return GNUNET_SYSERR;
229  }
230  *data_size += tmp_data_size;
231  *data = sets = GNUNET_malloc (*data_size);
233  set,
234  tmp_data_size,
235  (char *) &sets[1]);
236  for (i = 0; i < entries; i++)
237  {
238  if (0 != set[i].subject_attribute_len)
239  GNUNET_free ((char *) set[i].subject_attribute);
240  }
241  sets->set_count = htonl (entries);
242  sets->data_size = GNUNET_htonll (tmp_data_size);
243 
244  GNUNET_free (tmp_str);
245  return GNUNET_OK;
246  }
248  {
249  struct GNUNET_ABD_Delegate *cred;
251 
252  *data_size = GNUNET_ABD_delegate_serialize (cred, (char **) data);
253 
254  return GNUNET_OK;
255  }
256  default:
257  return GNUNET_SYSERR;
258  }
259 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
The attribute delegation record.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:180
int GNUNET_ABD_delegate_serialize(struct GNUNET_ABD_Delegate *dele, char **data)
#define GNUNET_GNSRECORD_TYPE_DELEGATE
65546 reserved
struct GNUNET_ABD_Delegate * GNUNET_ABD_delegate_from_string(const char *s)
Definition: delegate_misc.c:80
struct ListEntry * entries
List of peers in the list.
ssize_t GNUNET_ABD_delegation_set_serialize(unsigned int d_count, const struct GNUNET_ABD_DelegationSet *dsr, size_t dest_size, char *dest)
Serizalize the given delegation chain entries and abd.
uint64_t data_size
Length of delegation sets.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey
Subject key.
Definition: gnunet-abd.c:101
const char * subject_attribute
The subject attribute.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:371
The attribute delegation record.
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t set_count
Number of delegation sets in this record.
size_t GNUNET_ABD_delegation_set_get_size(unsigned int ds_count, const struct GNUNET_ABD_DelegationSet *dsr)
Calculate how many bytes we will need to serialize the given delegation chain.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ abd_typename_to_number()

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

Convert a type name (i.e.

"AAAA") to the corresponding number.

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

Definition at line 283 of file plugin_gnsrecord_abd.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_abd_init().

284 {
285  unsigned int i;
286 
287  i = 0;
288  while ((name_map[i].name != NULL) &&
289  (0 != strcasecmp (gns_typename, name_map[i].name)))
290  i++;
291  return name_map[i].number;
292 }
static struct @0 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
Here is the caller graph for this function:

◆ abd_number_to_typename()

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

Convert a type number (i.e.

1) to the corresponding type string (i.e. "A")

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

Definition at line 303 of file plugin_gnsrecord_abd.c.

References name, name_map, and number.

Referenced by libgnunet_plugin_gnsrecord_abd_init().

304 {
305  unsigned int i;
306 
307  i = 0;
308  while ((name_map[i].name != NULL) && (type != name_map[i].number))
309  i++;
310  return name_map[i].name;
311 }
static struct @0 name_map[]
Mapping of record type numbers to human-readable record type names.
uint32_t number
const char * name
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_abd_init()

void* libgnunet_plugin_gnsrecord_abd_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 321 of file plugin_gnsrecord_abd.c.

References abd_number_to_typename(), abd_string_to_value(), abd_typename_to_number(), abd_value_to_string(), GNUNET_new, 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.

322 {
324 
330  return api;
331 }
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
static uint32_t abd_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (i.e.
static int abd_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.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
static char * abd_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.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static const char * abd_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_abd_done()

void* libgnunet_plugin_gnsrecord_abd_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 341 of file plugin_gnsrecord_abd.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

342 {
344 
345  GNUNET_free (api);
346  return NULL;
347 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

Definition at line 268 of file plugin_gnsrecord_abd.c.

Referenced by abd_number_to_typename(), abd_typename_to_number(), check_barrier_status(), check_delete_message(), check_get(), check_get_default_message(), check_lookup_result(), check_monitor_notify(), check_record_result(), check_set(), check_ssl_certificate(), check_watch(), format_help(), GNS_get_tld(), gns_resolve_name(), GNUNET_DATACACHE_create(), GNUNET_DISK_directory_scan(), GNUNET_DNSPARSER_parse_query(), GNUNET_DNSPARSER_parse_record(), GNUNET_FS_GETOPT_KEYWORDS(), GNUNET_FS_GETOPT_METADATA(), GNUNET_GETOPT_option_absolute_time(), GNUNET_GETOPT_option_base32_fixed_size(), GNUNET_GETOPT_option_filename(), GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_increment_uint(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_GETOPT_option_uint16(), GNUNET_GETOPT_option_ulong(), GNUNET_JSON_getopt(), GNUNET_JSON_spec_absolute_time(), GNUNET_JSON_spec_absolute_time_nbo(), GNUNET_JSON_spec_boolean(), GNUNET_JSON_spec_fixed(), GNUNET_JSON_spec_json(), GNUNET_JSON_spec_relative_time(), GNUNET_JSON_spec_rsa_public_key(), GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_JSON_spec_uint16(), GNUNET_JSON_spec_uint32(), GNUNET_JSON_spec_uint64(), GNUNET_JSON_spec_uint8(), GNUNET_JSON_spec_varsize(), GNUNET_NETWORK_socket_accept(), GNUNET_PQ_connect(), GNUNET_PQ_make_prepare(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_uint16(), GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_PQ_result_spec_variable_size(), GNUNET_PROGRAM_run2(), handle_arm_list_result(), handle_barrier_cancel(), handle_barrier_init(), handle_barrier_status(), handle_barrier_wait(), handle_delete_message(), handle_get(), handle_get_default_message(), handle_lookup(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_lookup_result(), handle_record_result(), handle_set(), handle_watch(), handle_zone_to_name_it(), list_callback(), plugin_session_info_cb(), print_entry(), process_lookup_result(), REGEX_TEST_automaton_save_graph_step(), run(), send_ibf(), stun_attr2str(), stun_msg2str(), and translate_dot_plus().

◆ number

uint32_t number

Definition at line 269 of file plugin_gnsrecord_abd.c.

Referenced by abd_number_to_typename(), event_cb(), and GNUNET_TESTBED_run().

◆ name_map

struct { ... } name_map[]
Initial value:
{NULL, UINT32_MAX}}
#define GNUNET_GNSRECORD_TYPE_DELEGATE
65546 reserved
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.

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

Referenced by abd_number_to_typename(), and abd_typename_to_number().