diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-05-02 22:24:42 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-05-02 22:24:42 +0200 |
commit | 1eadd51205794a18e74f135672c96613d4f8734b (patch) | |
tree | 79dae4cf5ad1547e9e48aa87428e64c864af28f2 /src/include/gnunet_json_lib.h | |
parent | 5ef270d2a7fa5c32d874fc7da2f026998ff0ab8e (diff) | |
download | gnunet-1eadd51205794a18e74f135672c96613d4f8734b.tar.gz gnunet-1eadd51205794a18e74f135672c96613d4f8734b.zip |
preparatory change to GNUNET_JSON_post_parser() API for future compression support
Diffstat (limited to 'src/include/gnunet_json_lib.h')
-rw-r--r-- | src/include/gnunet_json_lib.h | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index c8f09d4e4..32de2208a 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_gnsrecord_lib.h" | 31 | #include "gnunet_gnsrecord_lib.h" |
32 | #include <jansson.h> | 32 | #include <jansson.h> |
33 | 33 | #include <microhttpd.h> | |
34 | 34 | ||
35 | /* ****************** Generic parser interface ******************* */ | 35 | /* ****************** Generic parser interface ******************* */ |
36 | 36 | ||
@@ -49,10 +49,9 @@ struct GNUNET_JSON_Specification; | |||
49 | * @return #GNUNET_SYSERR on error, | 49 | * @return #GNUNET_SYSERR on error, |
50 | * #GNUNET_OK on success | 50 | * #GNUNET_OK on success |
51 | */ | 51 | */ |
52 | typedef int | 52 | typedef int (*GNUNET_JSON_Parser) (void *cls, |
53 | (*GNUNET_JSON_Parser)(void *cls, | 53 | json_t *root, |
54 | json_t *root, | 54 | struct GNUNET_JSON_Specification *spec); |
55 | struct GNUNET_JSON_Specification *spec); | ||
56 | 55 | ||
57 | 56 | ||
58 | /** | 57 | /** |
@@ -61,9 +60,8 @@ typedef int | |||
61 | * @param cls closure | 60 | * @param cls closure |
62 | * @param spec our specification entry with data to clean. | 61 | * @param spec our specification entry with data to clean. |
63 | */ | 62 | */ |
64 | typedef void | 63 | typedef void (*GNUNET_JSON_Cleaner) (void *cls, |
65 | (*GNUNET_JSON_Cleaner)(void *cls, | 64 | struct GNUNET_JSON_Specification *spec); |
66 | struct GNUNET_JSON_Specification *spec); | ||
67 | 65 | ||
68 | 66 | ||
69 | /** | 67 | /** |
@@ -106,7 +104,6 @@ struct GNUNET_JSON_Specification | |||
106 | * Where should we store the final size of @e ptr. | 104 | * Where should we store the final size of @e ptr. |
107 | */ | 105 | */ |
108 | size_t *size_ptr; | 106 | size_t *size_ptr; |
109 | |||
110 | }; | 107 | }; |
111 | 108 | ||
112 | 109 | ||
@@ -140,7 +137,6 @@ void | |||
140 | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); | 137 | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); |
141 | 138 | ||
142 | 139 | ||
143 | |||
144 | /* ****************** Canonical parser specifications ******************* */ | 140 | /* ****************** Canonical parser specifications ******************* */ |
145 | 141 | ||
146 | 142 | ||
@@ -160,9 +156,7 @@ GNUNET_JSON_spec_end (void); | |||
160 | * @param size number of bytes expected in @a obj | 156 | * @param size number of bytes expected in @a obj |
161 | */ | 157 | */ |
162 | struct GNUNET_JSON_Specification | 158 | struct GNUNET_JSON_Specification |
163 | GNUNET_JSON_spec_fixed (const char *name, | 159 | GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); |
164 | void *obj, | ||
165 | size_t size); | ||
166 | 160 | ||
167 | 161 | ||
168 | /** | 162 | /** |
@@ -172,7 +166,8 @@ GNUNET_JSON_spec_fixed (const char *name, | |||
172 | * @param name name of the JSON field | 166 | * @param name name of the JSON field |
173 | * @param obj pointer where to write the data (type of `*obj` will determine size) | 167 | * @param obj pointer where to write the data (type of `*obj` will determine size) |
174 | */ | 168 | */ |
175 | #define GNUNET_JSON_spec_fixed_auto(name,obj) GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj)) | 169 | #define GNUNET_JSON_spec_fixed_auto(name, obj) \ |
170 | GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj)) | ||
176 | 171 | ||
177 | 172 | ||
178 | /** | 173 | /** |
@@ -184,9 +179,7 @@ GNUNET_JSON_spec_fixed (const char *name, | |||
184 | * @param[out] size where to store the number of bytes allocated for @a obj | 179 | * @param[out] size where to store the number of bytes allocated for @a obj |
185 | */ | 180 | */ |
186 | struct GNUNET_JSON_Specification | 181 | struct GNUNET_JSON_Specification |
187 | GNUNET_JSON_spec_varsize (const char *name, | 182 | GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size); |
188 | void **obj, | ||
189 | size_t *size); | ||
190 | 183 | ||
191 | 184 | ||
192 | /** | 185 | /** |
@@ -196,8 +189,7 @@ GNUNET_JSON_spec_varsize (const char *name, | |||
196 | * @param strptr where to store a pointer to the field | 189 | * @param strptr where to store a pointer to the field |
197 | */ | 190 | */ |
198 | struct GNUNET_JSON_Specification | 191 | struct GNUNET_JSON_Specification |
199 | GNUNET_JSON_spec_string (const char *name, | 192 | GNUNET_JSON_spec_string (const char *name, const char **strptr); |
200 | const char **strptr); | ||
201 | 193 | ||
202 | /** | 194 | /** |
203 | * JSON object. | 195 | * JSON object. |
@@ -206,8 +198,7 @@ GNUNET_JSON_spec_string (const char *name, | |||
206 | * @param[out] jsonp where to store the JSON found under @a name | 198 | * @param[out] jsonp where to store the JSON found under @a name |
207 | */ | 199 | */ |
208 | struct GNUNET_JSON_Specification | 200 | struct GNUNET_JSON_Specification |
209 | GNUNET_JSON_spec_json (const char *name, | 201 | GNUNET_JSON_spec_json (const char *name, json_t **jsonp); |
210 | json_t **jsonp); | ||
211 | 202 | ||
212 | 203 | ||
213 | /** | 204 | /** |
@@ -217,8 +208,7 @@ GNUNET_JSON_spec_json (const char *name, | |||
217 | * @param[out] u8 where to store the integer found under @a name | 208 | * @param[out] u8 where to store the integer found under @a name |
218 | */ | 209 | */ |
219 | struct GNUNET_JSON_Specification | 210 | struct GNUNET_JSON_Specification |
220 | GNUNET_JSON_spec_uint8 (const char *name, | 211 | GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); |
221 | uint8_t *u8); | ||
222 | 212 | ||
223 | 213 | ||
224 | /** | 214 | /** |
@@ -228,8 +218,7 @@ GNUNET_JSON_spec_uint8 (const char *name, | |||
228 | * @param[out] u16 where to store the integer found under @a name | 218 | * @param[out] u16 where to store the integer found under @a name |
229 | */ | 219 | */ |
230 | struct GNUNET_JSON_Specification | 220 | struct GNUNET_JSON_Specification |
231 | GNUNET_JSON_spec_uint16 (const char *name, | 221 | GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); |
232 | uint16_t *u16); | ||
233 | 222 | ||
234 | 223 | ||
235 | /** | 224 | /** |
@@ -239,8 +228,7 @@ GNUNET_JSON_spec_uint16 (const char *name, | |||
239 | * @param[out] u32 where to store the integer found under @a name | 228 | * @param[out] u32 where to store the integer found under @a name |
240 | */ | 229 | */ |
241 | struct GNUNET_JSON_Specification | 230 | struct GNUNET_JSON_Specification |
242 | GNUNET_JSON_spec_uint32 (const char *name, | 231 | GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); |
243 | uint32_t *u32); | ||
244 | 232 | ||
245 | 233 | ||
246 | /** | 234 | /** |
@@ -250,8 +238,7 @@ GNUNET_JSON_spec_uint32 (const char *name, | |||
250 | * @param[out] u64 where to store the integer found under @a name | 238 | * @param[out] u64 where to store the integer found under @a name |
251 | */ | 239 | */ |
252 | struct GNUNET_JSON_Specification | 240 | struct GNUNET_JSON_Specification |
253 | GNUNET_JSON_spec_uint64 (const char *name, | 241 | GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); |
254 | uint64_t *u64); | ||
255 | 242 | ||
256 | /** | 243 | /** |
257 | * Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). | 244 | * Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). |
@@ -260,8 +247,7 @@ GNUNET_JSON_spec_uint64 (const char *name, | |||
260 | * @param[out] boolean where to store the boolean found under @a name | 247 | * @param[out] boolean where to store the boolean found under @a name |
261 | */ | 248 | */ |
262 | struct GNUNET_JSON_Specification | 249 | struct GNUNET_JSON_Specification |
263 | GNUNET_JSON_spec_boolean (const char *name, | 250 | GNUNET_JSON_spec_boolean (const char *name, int *boolean); |
264 | int *boolean); | ||
265 | 251 | ||
266 | 252 | ||
267 | /* ************ GNUnet-specific parser specifications ******************* */ | 253 | /* ************ GNUnet-specific parser specifications ******************* */ |
@@ -285,7 +271,7 @@ GNUNET_JSON_spec_absolute_time (const char *name, | |||
285 | */ | 271 | */ |
286 | struct GNUNET_JSON_Specification | 272 | struct GNUNET_JSON_Specification |
287 | GNUNET_JSON_spec_absolute_time_nbo (const char *name, | 273 | GNUNET_JSON_spec_absolute_time_nbo (const char *name, |
288 | struct GNUNET_TIME_AbsoluteNBO *at); | 274 | struct GNUNET_TIME_AbsoluteNBO *at); |
289 | 275 | ||
290 | 276 | ||
291 | /** | 277 | /** |
@@ -321,7 +307,6 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
321 | struct GNUNET_CRYPTO_RsaSignature **sig); | 307 | struct GNUNET_CRYPTO_RsaSignature **sig); |
322 | 308 | ||
323 | 309 | ||
324 | |||
325 | /** | 310 | /** |
326 | * JSON Specification for GNS Records. | 311 | * JSON Specification for GNS Records. |
327 | * | 312 | * |
@@ -346,8 +331,7 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | |||
346 | * @return json string that encodes @a data | 331 | * @return json string that encodes @a data |
347 | */ | 332 | */ |
348 | json_t * | 333 | json_t * |
349 | GNUNET_JSON_from_data (const void *data, | 334 | GNUNET_JSON_from_data (const void *data, size_t size); |
350 | size_t size); | ||
351 | 335 | ||
352 | 336 | ||
353 | /** | 337 | /** |
@@ -357,7 +341,8 @@ GNUNET_JSON_from_data (const void *data, | |||
357 | * @param ptr binary data, sizeof (*ptr) must yield correct size | 341 | * @param ptr binary data, sizeof (*ptr) must yield correct size |
358 | * @return json string that encodes @a data | 342 | * @return json string that encodes @a data |
359 | */ | 343 | */ |
360 | #define GNUNET_JSON_from_data_auto(ptr) GNUNET_JSON_from_data(ptr, sizeof (*ptr)) | 344 | #define GNUNET_JSON_from_data_auto(ptr) \ |
345 | GNUNET_JSON_from_data (ptr, sizeof (*ptr)) | ||
361 | 346 | ||
362 | 347 | ||
363 | /** | 348 | /** |
@@ -417,7 +402,7 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); | |||
417 | * @return corresponding JSON encoding | 402 | * @return corresponding JSON encoding |
418 | */ | 403 | */ |
419 | json_t * | 404 | json_t * |
420 | GNUNET_JSON_from_gnsrecord (const char* rname, | 405 | GNUNET_JSON_from_gnsrecord (const char *rname, |
421 | const struct GNUNET_GNSRECORD_Data *rd, | 406 | const struct GNUNET_GNSRECORD_Data *rd, |
422 | unsigned int rd_count); | 407 | unsigned int rd_count); |
423 | 408 | ||
@@ -426,7 +411,8 @@ GNUNET_JSON_from_gnsrecord (const char* rname, | |||
426 | /** | 411 | /** |
427 | * Return codes from #GNUNET_JSON_post_parser(). | 412 | * Return codes from #GNUNET_JSON_post_parser(). |
428 | */ | 413 | */ |
429 | enum GNUNET_JSON_PostResult { | 414 | enum GNUNET_JSON_PostResult |
415 | { | ||
430 | /** | 416 | /** |
431 | * Parsing successful, JSON result is in `*json`. | 417 | * Parsing successful, JSON result is in `*json`. |
432 | */ | 418 | */ |
@@ -462,6 +448,7 @@ enum GNUNET_JSON_PostResult { | |||
462 | * #GNUNET_JSON_post_parser_callback(). | 448 | * #GNUNET_JSON_post_parser_callback(). |
463 | * | 449 | * |
464 | * @param buffer_max maximum allowed size for the buffer | 450 | * @param buffer_max maximum allowed size for the buffer |
451 | * @param connection MHD connection handle (for meta data about the upload) | ||
465 | * @param con_cls the closure (will point to a `struct Buffer *`) | 452 | * @param con_cls the closure (will point to a `struct Buffer *`) |
466 | * @param upload_data the POST data | 453 | * @param upload_data the POST data |
467 | * @param upload_data_size number of bytes in @a upload_data | 454 | * @param upload_data_size number of bytes in @a upload_data |
@@ -470,6 +457,7 @@ enum GNUNET_JSON_PostResult { | |||
470 | */ | 457 | */ |
471 | enum GNUNET_JSON_PostResult | 458 | enum GNUNET_JSON_PostResult |
472 | GNUNET_JSON_post_parser (size_t buffer_max, | 459 | GNUNET_JSON_post_parser (size_t buffer_max, |
460 | struct MHD_Connection *connection, | ||
473 | void **con_cls, | 461 | void **con_cls, |
474 | const char *upload_data, | 462 | const char *upload_data, |
475 | size_t *upload_data_size, | 463 | size_t *upload_data_size, |