GNUnet 0.27.0-9-g1409f30d5
 
Loading...
Searching...
No Matches
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.
 
static int parse_record_data (struct GnsRecordInfo *gnsrecord_info, json_t *data)
 Parse given JSON object to gns record.
 
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.
 
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.
 
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.
 

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 if (NULL != *(gnsrecord_info->rd))
58 {
59 for (int i = 0; i < *(gnsrecord_info->rd_count); i++)
60 {
61 char *tmp;
62
63 tmp = (char*) (*(gnsrecord_info->rd))[i].data;
64 GNUNET_free (tmp);
65 }
66 GNUNET_free (*(gnsrecord_info->rd));
67 }
68 GNUNET_free (*(gnsrecord_info->name));
69}
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 81 of file json_gnsrecord.c.

82{
83 struct GNUNET_TIME_Absolute abs_exp;
84 struct GNUNET_TIME_Relative rel_exp;
85 const char *value;
86 const char *record_type;
87 int maintenance;
88 int private;
89 int supplemental;
90 int is_rel_exp;
91 int shadow;
92 int unpack_state = 0;
93 json_error_t err;
94
95 // interpret single gns record
96 unpack_state = json_unpack_ex (data,
97 &err,
98 0,
99 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b, s:b}",
101 &value,
103 &record_type,
105 &rel_exp.rel_value_us,
107 &maintenance,
109 &private,
111 &supplemental,
113 &is_rel_exp,
115 &shadow);
116 if (0 != unpack_state)
117 {
119 "Error gnsdata object has a wrong format: `%s'!\n",
120 err.text);
121 unpack_state = json_unpack_ex (data,
122 &err,
123 0,
124 "{s:s, s:s, s:I, s:b, s:b, s:b, s:b, s:b}",
126 &value,
128 &record_type,
130 &abs_exp.abs_value_us,
132 &maintenance,
134 &private,
136 &supplemental,
138 &is_rel_exp,
140 &shadow);
141 if ((0 != unpack_state) || (is_rel_exp))
142 {
144 "Error gnsdata object has a wrong format: `%s'!\n",
145 (is_rel_exp) ? "No relative expiration given" : err.text);
146 return GNUNET_SYSERR;
147 }
148 rd->expiration_time = abs_exp.abs_value_us;
149 }
150 else
151 {
152 rd->expiration_time = rel_exp.rel_value_us;
153 }
155 if (UINT32_MAX == rd->record_type)
156 {
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unsupported type\n");
158 return GNUNET_SYSERR;
159 }
161 value,
162 (void **) &rd->data,
163 &rd->data_size))
164 {
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Value invalid for record type\n");
166 return GNUNET_SYSERR;
167 }
168
169 if (is_rel_exp)
171 if (1 == maintenance)
173 if (1 == private)
175 if (1 == supplemental)
177 if (1 == shadow)
179 return GNUNET_OK;
180}
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 192 of file json_gnsrecord.c.

193{
194 GNUNET_assert (NULL != data);
195 if (! json_is_array (data))
196 {
198 "Error gns record data JSON is not an array!\n");
199 return GNUNET_SYSERR;
200 }
201 *(gnsrecord_info->rd_count) = json_array_size (data);
202 *(gnsrecord_info->rd) = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Data)
203 * json_array_size (data));
204 {
205 size_t index;
206 json_t *value;
207 json_array_foreach (data, index, value)
208 {
209 if (GNUNET_OK != parse_record (value, &(*(gnsrecord_info->rd))[index]))
210 return GNUNET_SYSERR;
211 }
212 }
213 return GNUNET_OK;
214}
#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 218 of file json_gnsrecord.c.

221{
222 struct GnsRecordInfo *gnsrecord_info;
223 int unpack_state = 0;
224 const char *name;
225 json_t *data;
226
227 GNUNET_assert (NULL != root);
228 if (! json_is_object (root))
229 {
231 "Error record JSON is not an object!\n");
232 return GNUNET_SYSERR;
233 }
234 // interpret single gns record
235 unpack_state = json_unpack (root,
236 "{s:s, s:o!}",
238 &name,
240 &data);
241 if (0 != unpack_state)
242 {
244 "Error namestore records object has a wrong format!\n");
245 return GNUNET_SYSERR;
246 }
247 gnsrecord_info = (struct GnsRecordInfo *) spec->ptr;
248 *(gnsrecord_info->name) = GNUNET_strdup (name);
249 if (GNUNET_OK != parse_record_data (gnsrecord_info, data))
250 {
251 cleanup_recordinfo (gnsrecord_info);
252 return GNUNET_SYSERR;
253 }
254 return GNUNET_OK;
255}
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 265 of file json_gnsrecord.c.

266{
267 struct GnsRecordInfo *gnsrecord_info = (struct GnsRecordInfo *) spec->ptr;
268
269 GNUNET_free (gnsrecord_info);
270}

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_GNSRECORD_JSON_spec_gnsrecord().

Here is the caller graph for this function: