diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-23 22:01:37 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-23 22:01:37 +0900 |
commit | 9c7255313368e04bff09d8dfb1aad537e7121359 (patch) | |
tree | 2b2a3a687abee43a71b1286b011ac2b1f942598a /src/gnsrecord | |
parent | ee99cbfa6a429854c632ee212815fc3fcac9f6f4 (diff) | |
download | gnunet-9c7255313368e04bff09d8dfb1aad537e7121359.tar.gz gnunet-9c7255313368e04bff09d8dfb1aad537e7121359.zip |
-more rest API fixes, test fix
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/json_gnsrecord.c | 114 |
1 files changed, 59 insertions, 55 deletions
diff --git a/src/gnsrecord/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c index 94916292f..707e88668 100644 --- a/src/gnsrecord/json_gnsrecord.c +++ b/src/gnsrecord/json_gnsrecord.c | |||
@@ -31,13 +31,13 @@ | |||
31 | #define GNUNET_JSON_GNSRECORD_VALUE "value" | 31 | #define GNUNET_JSON_GNSRECORD_VALUE "value" |
32 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" | 32 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" |
33 | #define GNUNET_JSON_GNSRECORD_TYPE "record_type" | 33 | #define GNUNET_JSON_GNSRECORD_TYPE "record_type" |
34 | #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" | 34 | #define GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME "relative_expiration" |
35 | #define GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME "absolute_expiration" | ||
35 | #define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "is_private" | 36 | #define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "is_private" |
36 | #define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "supplemental" | 37 | #define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "is_supplemental" |
37 | #define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "is_relative_expiration" | 38 | #define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "is_relative_expiration" |
38 | #define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "shadow" | 39 | #define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "is_shadow" |
39 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" | 40 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" |
40 | #define GNUNET_JSON_GNSRECORD_NEVER "never" | ||
41 | 41 | ||
42 | struct GnsRecordInfo | 42 | struct GnsRecordInfo |
43 | { | 43 | { |
@@ -82,39 +82,66 @@ cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info) | |||
82 | static int | 82 | static int |
83 | parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | 83 | parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) |
84 | { | 84 | { |
85 | struct GNUNET_TIME_Absolute abs_expiration_time; | 85 | struct GNUNET_TIME_Absolute abs_exp; |
86 | struct GNUNET_TIME_Relative rel_expiration_time; | 86 | struct GNUNET_TIME_Relative rel_exp; |
87 | const char *value; | 87 | const char *value; |
88 | const char *record_type; | 88 | const char *record_type; |
89 | const char *expiration_time; | ||
90 | int private; | 89 | int private; |
91 | int supplemental; | 90 | int supplemental; |
92 | int rel_exp; | 91 | int is_rel_exp; |
93 | int shadow; | 92 | int shadow; |
94 | int unpack_state = 0; | 93 | int unpack_state = 0; |
94 | json_error_t err; | ||
95 | 95 | ||
96 | // interpret single gns record | 96 | // interpret single gns record |
97 | unpack_state = json_unpack (data, | 97 | unpack_state = json_unpack_ex (data, |
98 | "{s:s, s:s, s:s, s:b, s:b, s:b, s:b}", | 98 | &err, |
99 | GNUNET_JSON_GNSRECORD_VALUE, | 99 | 0, |
100 | &value, | 100 | "{s:s, s:s, s:i, s:b, s:b, s:b, s:b}", |
101 | GNUNET_JSON_GNSRECORD_TYPE, | 101 | GNUNET_JSON_GNSRECORD_VALUE, |
102 | &record_type, | 102 | &value, |
103 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, | 103 | GNUNET_JSON_GNSRECORD_TYPE, |
104 | &expiration_time, | 104 | &record_type, |
105 | GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, | 105 | GNUNET_JSON_GNSRECORD_RELATIVE_EXPIRATION_TIME, |
106 | &private, | 106 | &rel_exp.rel_value_us, |
107 | GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, | 107 | GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, |
108 | &supplemental, | 108 | &private, |
109 | GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, | 109 | GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, |
110 | &rel_exp, | 110 | &supplemental, |
111 | GNUNET_JSON_GNSRECORD_FLAG_SHADOW, | 111 | GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, |
112 | &shadow); | 112 | &is_rel_exp, |
113 | GNUNET_JSON_GNSRECORD_FLAG_SHADOW, | ||
114 | &shadow); | ||
113 | if (0 != unpack_state) | 115 | if (0 != unpack_state) |
114 | { | 116 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
116 | "Error gnsdata object has a wrong format!\n"); | 118 | "Error gnsdata object has a wrong format: `%s'!\n", |
117 | return GNUNET_SYSERR; | 119 | err.text); |
120 | unpack_state = json_unpack_ex (data, | ||
121 | &err, | ||
122 | 0, | ||
123 | "{s:s, s:s, s:I, s:b, s:b, s:b, s:b}", | ||
124 | GNUNET_JSON_GNSRECORD_VALUE, | ||
125 | &value, | ||
126 | GNUNET_JSON_GNSRECORD_TYPE, | ||
127 | &record_type, | ||
128 | GNUNET_JSON_GNSRECORD_ABSOLUTE_EXPIRATION_TIME, | ||
129 | &abs_exp.abs_value_us, | ||
130 | GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, | ||
131 | &private, | ||
132 | GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, | ||
133 | &supplemental, | ||
134 | GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, | ||
135 | &is_rel_exp, | ||
136 | GNUNET_JSON_GNSRECORD_FLAG_SHADOW, | ||
137 | &shadow); | ||
138 | if ((0 != unpack_state) || (is_rel_exp)) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
141 | "Error gnsdata object has a wrong format: `%s'!\n", | ||
142 | (is_rel_exp) ? "No relative expiration given" : err.text); | ||
143 | return GNUNET_SYSERR; | ||
144 | } | ||
118 | } | 145 | } |
119 | rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type); | 146 | rd->record_type = GNUNET_GNSRECORD_typename_to_number (record_type); |
120 | if (UINT32_MAX == rd->record_type) | 147 | if (UINT32_MAX == rd->record_type) |
@@ -131,29 +158,8 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
131 | return GNUNET_SYSERR; | 158 | return GNUNET_SYSERR; |
132 | } | 159 | } |
133 | 160 | ||
134 | if (0 == strcmp (expiration_time, GNUNET_JSON_GNSRECORD_NEVER)) | 161 | if (is_rel_exp) |
135 | { | ||
136 | rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | ||
137 | } | ||
138 | else if ((1 != rel_exp) && | ||
139 | (GNUNET_OK == | ||
140 | GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, | ||
141 | &abs_expiration_time))) | ||
142 | { | ||
143 | rd->expiration_time = abs_expiration_time.abs_value_us; | ||
144 | } | ||
145 | else if (GNUNET_OK == | ||
146 | GNUNET_STRINGS_fancy_time_to_relative (expiration_time, | ||
147 | &rel_expiration_time)) | ||
148 | { | ||
149 | rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 162 | rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
150 | rd->expiration_time = rel_expiration_time.rel_value_us; | ||
151 | } | ||
152 | else | ||
153 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n"); | ||
155 | return GNUNET_SYSERR; | ||
156 | } | ||
157 | if (1 == private) | 163 | if (1 == private) |
158 | rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE; | 164 | rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE; |
159 | if (1 == supplemental) | 165 | if (1 == supplemental) |
@@ -260,8 +266,8 @@ clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec) | |||
260 | */ | 266 | */ |
261 | struct GNUNET_JSON_Specification | 267 | struct GNUNET_JSON_Specification |
262 | GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | 268 | GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, |
263 | unsigned int *rd_count, | 269 | unsigned int *rd_count, |
264 | char **name) | 270 | char **name) |
265 | { | 271 | { |
266 | struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo); | 272 | struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo); |
267 | 273 | ||
@@ -289,8 +295,8 @@ GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | |||
289 | */ | 295 | */ |
290 | json_t * | 296 | json_t * |
291 | GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, | 297 | GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, |
292 | const struct GNUNET_GNSRECORD_Data *rd, | 298 | const struct GNUNET_GNSRECORD_Data *rd, |
293 | unsigned int rd_count) | 299 | unsigned int rd_count) |
294 | { | 300 | { |
295 | struct GNUNET_TIME_Absolute abs_exp; | 301 | struct GNUNET_TIME_Absolute abs_exp; |
296 | struct GNUNET_TIME_Relative rel_exp; | 302 | struct GNUNET_TIME_Relative rel_exp; |
@@ -387,5 +393,3 @@ GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, | |||
387 | } | 393 | } |
388 | return data; | 394 | return data; |
389 | } | 395 | } |
390 | |||
391 | |||