GNUnet 0.22.2
json_gnsrecord.c File Reference
Include dependency graph for json_gnsrecord.c:

Go to the source code of this file.

Data Structures

struct  GnsRecordInfo
 

Macros

#define GNUNET_JSON_GNSRECORD_VALUE   "value"
 
#define GNUNET_JSON_GNSRECORD_RECORD_DATA   "data"
 
#define GNUNET_JSON_GNSRECORD_TYPE   "record_type"
 
#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME   "relative_expiration"
 
#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME   "absolute_expiration"
 
#define GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE   "is_maintenance"
 
#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE   "is_private"
 
#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL   "is_supplemental"
 
#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE   "is_relative_expiration"
 
#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW   "is_shadow"
 
#define GNUNET_JSON_GNSRECORD_RECORD_NAME   "record_name"
 

Functions

static void cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info)
 
static int parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
 Parse given JSON object to gns record. More...
 
static int parse_record_data (struct GnsRecordInfo *gnsrecord_info, json_t *data)
 Parse given JSON object to gns record. More...
 
static int parse_gnsrecordobject (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 
static void clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing the record. More...
 
struct GNUNET_JSON_Specification GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
 JSON Specification for GNS Records. More...
 
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord (const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Convert GNS record to JSON. More...
 

Macro Definition Documentation

◆ GNUNET_JSON_GNSRECORD_VALUE

#define GNUNET_JSON_GNSRECORD_VALUE   "value"

Definition at line 32 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_RECORD_DATA

#define GNUNET_JSON_GNSRECORD_RECORD_DATA   "data"

Definition at line 33 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_TYPE

#define GNUNET_JSON_GNSRECORD_TYPE   "record_type"

Definition at line 34 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME

#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME   "relative_expiration"

Definition at line 35 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME

#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME   "absolute_expiration"

Definition at line 36 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE

#define GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE   "is_maintenance"

Definition at line 37 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_FLAG_PRIVATE

#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE   "is_private"

Definition at line 38 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL

#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL   "is_supplemental"

Definition at line 39 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_FLAG_RELATIVE

#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE   "is_relative_expiration"

Definition at line 40 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_FLAG_SHADOW

#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW   "is_shadow"

Definition at line 41 of file json_gnsrecord.c.

◆ GNUNET_JSON_GNSRECORD_RECORD_NAME

#define GNUNET_JSON_GNSRECORD_RECORD_NAME   "record_name"

Definition at line 42 of file json_gnsrecord.c.

Function Documentation

◆ cleanup_recordinfo()

static void cleanup_recordinfo ( struct GnsRecordInfo gnsrecord_info)
static

Definition at line 55 of file json_gnsrecord.c.

56{
57 char *tmp;
58
59 if (NULL != *(gnsrecord_info->rd))
60 {
61 for (int i = 0; i < *(gnsrecord_info->rd_count); i++)
62 {
63 tmp = (char*) (*(gnsrecord_info->rd))[i].data;
64 if (NULL != tmp)
65 GNUNET_free (tmp);
66 }
67 GNUNET_free (*(gnsrecord_info->rd));
68 *(gnsrecord_info->rd) = NULL;
69 }
70 if (NULL != *(gnsrecord_info->name))
71 GNUNET_free (*(gnsrecord_info->name));
72 *(gnsrecord_info->name) = NULL;
73}
static char * data
The data to insert into the dht.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_GNSRECORD_Data ** rd
unsigned int * rd_count

References data, GNUNET_free, GnsRecordInfo::name, GnsRecordInfo::rd, and GnsRecordInfo::rd_count.

Referenced by parse_gnsrecordobject().

Here is the caller graph for this function:

◆ parse_record()

static int parse_record ( json_t *  data,
struct GNUNET_GNSRECORD_Data rd 
)
static

Parse given JSON object to gns record.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 85 of file json_gnsrecord.c.

86{
87 struct GNUNET_TIME_Absolute abs_exp;
88 struct GNUNET_TIME_Relative rel_exp;
89 const char *value;
90 const char *record_type;
91 int maintenance;
92 int private;
93 int supplemental;
94 int is_rel_exp;
95 int shadow;
96 int unpack_state = 0;
97 json_error_t err;
98
99 // interpret single gns record
100 unpack_state = json_unpack_ex (data,
101 &err,
102 0,
103 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b, s:b}",
105 &value,
107 &record_type,
109 &rel_exp.rel_value_us,
111 &maintenance,
113 &private,
115 &supplemental,
117 &is_rel_exp,
119 &shadow);
120 if (0 != unpack_state)
121 {
123 "Error gnsdata object has a wrong format: `%s'!\n",
124 err.text);
125 unpack_state = json_unpack_ex (data,
126 &err,
127 0,
128 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b, s:b}",
130 &value,
132 &record_type,
134 &abs_exp.abs_value_us,
136 &maintenance,
138 &private,
140 &supplemental,
142 &is_rel_exp,
144 &shadow);
145 if ((0 != unpack_state) || (is_rel_exp))
146 {
148 "Error gnsdata object has a wrong format: `%s'!\n",
149 (is_rel_exp) ? "No relative expiration given" : err.text);
150 return GNUNET_SYSERR;
151 }
152 rd->expiration_time = abs_exp.abs_value_us;
153 }
154 else
155 {
156 rd->expiration_time = rel_exp.rel_value_us;
157 }
159 if (UINT32_MAX == rd->record_type)
160 {
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unsupported type\n");
162 return GNUNET_SYSERR;
163 }
165 value,
166 (void **) &rd->data,
167 &rd->data_size))
168 {
169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Value invalid for record type\n");
170 return GNUNET_SYSERR;
171 }
172
173 if (is_rel_exp)
175 if (1 == maintenance)
177 if (1 == private)
179 if (1 == supplemental)
181 if (1 == shadow)
183 return GNUNET_OK;
184}
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static char * value
Value of the record to add/remove.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition: gnsrecord.c:192
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of the value s of a record of type type to the respective binary repre...
Definition: gnsrecord.c:169
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_MAINTENANCE
Maintenance records.
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW
#define GNUNET_JSON_GNSRECORD_VALUE
#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE
#define GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE
#define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL
#define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME
#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE
#define GNUNET_JSON_GNSRECORD_TYPE
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, data, GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_Data::data_size, GNUNET_GNSRECORD_Data::expiration_time, GNUNET_GNSRECORD_Data::flags, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_RF_MAINTENANCE, GNUNET_GNSRECORD_RF_PRIVATE, GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, GNUNET_GNSRECORD_RF_SHADOW, GNUNET_GNSRECORD_RF_SUPPLEMENTAL, GNUNET_GNSRECORD_string_to_value(), GNUNET_GNSRECORD_typename_to_number(), GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_FLAG_MAINTENANCE, GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, GNUNET_JSON_GNSRECORD_FLAG_SHADOW, GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME, GNUNET_JSON_GNSRECORD_TYPE, GNUNET_JSON_GNSRECORD_VALUE, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, rd, GNUNET_GNSRECORD_Data::record_type, GNUNET_TIME_Relative::rel_value_us, and value.

Referenced by parse_record_data().

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

◆ parse_record_data()

static int parse_record_data ( struct GnsRecordInfo gnsrecord_info,
json_t *  data 
)
static

Parse given JSON object to gns record.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 196 of file json_gnsrecord.c.

197{
198 GNUNET_assert (NULL != data);
199 if (! json_is_array (data))
200 {
202 "Error gns record data JSON is not an array!\n");
203 return GNUNET_SYSERR;
204 }
205 *(gnsrecord_info->rd_count) = json_array_size (data);
206 *(gnsrecord_info->rd) = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Data)
207 * json_array_size (data));
208 {
209 size_t index;
210 json_t *value;
211 json_array_foreach (data, index, value)
212 {
213 if (GNUNET_OK != parse_record (value, &(*(gnsrecord_info->rd))[index]))
214 return GNUNET_SYSERR;
215 }
216 }
217 return GNUNET_OK;
218}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
static int parse_record(json_t *data, struct GNUNET_GNSRECORD_Data *rd)
Parse given JSON object to gns record.

References data, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, parse_record(), GnsRecordInfo::rd, GnsRecordInfo::rd_count, and value.

Referenced by parse_gnsrecordobject().

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

◆ parse_gnsrecordobject()

static int parse_gnsrecordobject ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Definition at line 222 of file json_gnsrecord.c.

225{
226 struct GnsRecordInfo *gnsrecord_info;
227 int unpack_state = 0;
228 const char *name;
229 json_t *data;
230
231 GNUNET_assert (NULL != root);
232 if (! json_is_object (root))
233 {
235 "Error record JSON is not an object!\n");
236 return GNUNET_SYSERR;
237 }
238 // interpret single gns record
239 unpack_state = json_unpack (root,
240 "{s:s, s:o!}",
242 &name,
244 &data);
245 if (0 != unpack_state)
246 {
248 "Error namestore records object has a wrong format!\n");
249 return GNUNET_SYSERR;
250 }
251 gnsrecord_info = (struct GnsRecordInfo *) spec->ptr;
252 *(gnsrecord_info->name) = GNUNET_strdup (name);
253 if (GNUNET_OK != parse_record_data (gnsrecord_info, data))
254 {
255 cleanup_recordinfo (gnsrecord_info);
256 return GNUNET_SYSERR;
257 }
258 return GNUNET_OK;
259}
static char * name
Name (label) of the records to list.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static int parse_record_data(struct GnsRecordInfo *gnsrecord_info, json_t *data)
Parse given JSON object to gns record.
#define GNUNET_JSON_GNSRECORD_RECORD_NAME
static void cleanup_recordinfo(struct GnsRecordInfo *gnsrecord_info)
#define GNUNET_JSON_GNSRECORD_RECORD_DATA
void * ptr
Pointer, details specific to the parser.

References cleanup_recordinfo(), data, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_JSON_GNSRECORD_RECORD_DATA, GNUNET_JSON_GNSRECORD_RECORD_NAME, GNUNET_log, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, name, GnsRecordInfo::name, parse_record_data(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_GNSRECORD_JSON_spec_gnsrecord().

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

◆ clean_gnsrecordobject()

static void clean_gnsrecordobject ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing the record.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 269 of file json_gnsrecord.c.

270{
271 struct GnsRecordInfo *gnsrecord_info = (struct GnsRecordInfo *) spec->ptr;
272
273 GNUNET_free (gnsrecord_info);
274}

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_GNSRECORD_JSON_spec_gnsrecord().

Here is the caller graph for this function: