GNUnet 0.21.0
json_helper.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2014-2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27#include "platform.h"
28#include "gnunet_json_lib.h"
29
30
33{
35 .parser = NULL,
36 .cleaner = NULL,
37 .cls = NULL
38 };
39
40 return ret;
41}
42
43
54 json_t *root,
55 struct GNUNET_JSON_Specification *spec)
56{
57 const char *enc;
58 size_t len;
59
60 if (NULL == (enc = json_string_value (root)))
61 {
63 return GNUNET_SYSERR;
64 }
65 len = strlen (enc);
66 if (len >= SIZE_MAX / 5)
67 {
69 return GNUNET_SYSERR;
70 }
71 if (((len * 5) / 8) != spec->ptr_size)
72 {
75 "Field `%s' has wrong length\n",
76 spec->field);
77 return GNUNET_SYSERR;
78 }
79 if (GNUNET_OK !=
81 len,
82 spec->ptr,
83 spec->ptr_size))
84 {
86 return GNUNET_SYSERR;
87 }
88 return GNUNET_OK;
89}
90
91
94 void *obj,
95 size_t size)
96{
98 .parser = &parse_fixed_data,
99 .cleaner = NULL,
100 .cls = NULL,
101 .field = name,
102 .ptr = obj,
103 .ptr_size = size,
104 .size_ptr = NULL
105 };
106
107 return ret;
108}
109
110
121 json_t *root,
122 struct GNUNET_JSON_Specification *spec)
123{
124 const char *enc;
125 unsigned int len;
126 void *output;
127 size_t olen;
128
129 if (NULL == (enc = json_string_value (root)))
130 {
131 GNUNET_break_op (0);
132 return GNUNET_SYSERR;
133 }
134 len = strlen (enc);
135 output = NULL;
137 len,
138 &output);
139 if (olen != spec->ptr_size)
140 {
141 GNUNET_break_op (0);
143 "Field `%s' has wrong length\n",
144 spec->field);
145 GNUNET_free (output);
146 return GNUNET_SYSERR;
147 }
148 memcpy (spec->ptr,
149 output,
150 olen);
151 GNUNET_free (output);
152 return GNUNET_OK;
153}
154
155
158 void *obj,
159 size_t size)
160{
162 .parser = &parse_fixed64_data,
163 .cleaner = NULL,
164 .cls = NULL,
165 .field = name,
166 .ptr = obj,
167 .ptr_size = size,
168 .size_ptr = NULL
169 };
170
171 return ret;
172}
173
174
185 json_t *root,
186 struct GNUNET_JSON_Specification *spec)
187{
188 const char *str;
189 size_t size;
190 void *data;
191
192 str = json_string_value (root);
193 if (NULL == str)
194 {
195 GNUNET_break_op (0);
196 return GNUNET_SYSERR;
197 }
198 if (GNUNET_OK !=
200 strlen (str),
201 &data,
202 &size))
203 {
204 GNUNET_break_op (0);
205 return GNUNET_SYSERR;
206 }
207 *(void **) spec->ptr = data;
208 *spec->size_ptr = size;
209 return GNUNET_OK;
210}
211
212
219static void
221 struct GNUNET_JSON_Specification *spec)
222{
223 (void) cls;
224 if (0 != *spec->size_ptr)
225 {
226 GNUNET_free (*(void **) spec->ptr);
227 *(void **) spec->ptr = NULL;
228 *spec->size_ptr = 0;
229 }
230}
231
232
235 void **obj,
236 size_t *size)
237{
239 .parser = &parse_variable_data,
240 .cleaner = &clean_variable_data,
241 .cls = NULL,
242 .field = name,
243 .ptr = obj,
244 .ptr_size = 0,
245 .size_ptr = size
246 };
247
248 *obj = NULL;
249 *size = 0;
250 return ret;
251}
252
253
264 json_t *root,
265 struct GNUNET_JSON_Specification *spec)
266{
267 const char *str;
268
269 (void) cls;
270 str = json_string_value (root);
271 if (NULL == str)
272 {
273 GNUNET_break_op (0);
274 return GNUNET_SYSERR;
275 }
276 *(const char **) spec->ptr = str;
277 return GNUNET_OK;
278}
279
280
283 const char **strptr)
284{
286 .parser = &parse_string,
287 .field = name,
288 .ptr = strptr
289 };
290
291 *strptr = NULL;
292 return ret;
293}
294
295
306 json_t *root,
307 struct GNUNET_JSON_Specification *spec)
308{
309 if (! (json_is_object (root) || json_is_array (root)))
310 {
311 GNUNET_break_op (0);
312 return GNUNET_SYSERR;
313 }
314 json_incref (root);
315 *(json_t **) spec->ptr = root;
316 return GNUNET_OK;
317}
318
319
326static void
328 struct GNUNET_JSON_Specification *spec)
329{
330 json_t **ptr = (json_t **) spec->ptr;
331
332 if (NULL != *ptr)
333 {
334 json_decref (*ptr);
335 *ptr = NULL;
336 }
337}
338
339
342 json_t **jsonp)
343{
345 .parser = &parse_json,
346 .cleaner = &clean_json,
347 .cls = NULL,
348 .field = name,
349 .ptr = jsonp,
350 .ptr_size = 0,
351 .size_ptr = NULL
352 };
353
354 *jsonp = NULL;
355 return ret;
356}
357
358
369 json_t *root,
370 struct GNUNET_JSON_Specification *spec)
371{
372 if (NULL == root)
373 return GNUNET_OK;
374 if (! json_is_object (root))
375 {
376 GNUNET_break_op (0);
377 return GNUNET_SYSERR;
378 }
379 *(const json_t **) spec->ptr = (const json_t *) root;
380 return GNUNET_OK;
381}
382
383
386 const json_t **jsonp)
387{
389 .parser = &parse_object_const,
390 .cls = NULL,
391 .field = name,
392 .ptr = jsonp,
393 .ptr_size = 0,
394 .size_ptr = NULL
395 };
396
397 *jsonp = NULL;
398 return ret;
399}
400
401
412 json_t *root,
413 struct GNUNET_JSON_Specification *spec)
414{
415 if (NULL == root)
416 return GNUNET_OK;
417 if (! json_is_array (root))
418 {
419 GNUNET_break_op (0);
420 return GNUNET_SYSERR;
421 }
422 *(const json_t **) spec->ptr = (const json_t *) root;
423 return GNUNET_OK;
424}
425
426
429 const json_t **jsonp)
430{
432 .parser = &parse_array_const,
433 .cls = NULL,
434 .field = name,
435 .ptr = jsonp,
436 .ptr_size = 0,
437 .size_ptr = NULL
438 };
439
440 *jsonp = NULL;
441 return ret;
442}
443
444
455 json_t *root,
456 struct GNUNET_JSON_Specification *spec)
457{
458 bool *b = spec->ptr;
459
460 if (json_true () == root)
461 {
462 *b = true;
463 return GNUNET_OK;
464 }
465 if (json_false () == root)
466 {
467 *b = false;
468 return GNUNET_OK;
469 }
470 GNUNET_break_op (0);
471 return GNUNET_SYSERR;
472}
473
474
477 bool *b)
478{
480 .parser = &parse_bool,
481 .cleaner = NULL,
482 .cls = NULL,
483 .field = name,
484 .ptr = b,
485 .ptr_size = sizeof(bool),
486 .size_ptr = NULL
487 };
488
489 return ret;
490}
491
492
503 json_t *root,
504 struct GNUNET_JSON_Specification *spec)
505{
506 double *f = spec->ptr;
507
508 if (! json_is_real (root))
509 {
510 GNUNET_break_op (0);
511 return GNUNET_SYSERR;
512 }
513 *f = json_real_value (root);
514 return GNUNET_OK;
515}
516
517
520 double *f)
521{
523 .parser = &parse_double,
524 .cleaner = NULL,
525 .cls = NULL,
526 .field = name,
527 .ptr = f,
528 .ptr_size = sizeof(double),
529 .size_ptr = NULL
530 };
531
532 return ret;
533}
534
535
546 json_t *root,
547 struct GNUNET_JSON_Specification *spec)
548{
549 json_int_t val;
550 uint8_t *up = spec->ptr;
551
552 if (! json_is_integer (root))
553 {
554 GNUNET_break_op (0);
555 return GNUNET_SYSERR;
556 }
557 val = json_integer_value (root);
558 if ((0 > val) || (val > UINT8_MAX))
559 {
560 GNUNET_break_op (0);
561 return GNUNET_SYSERR;
562 }
563 *up = (uint8_t) val;
564 return GNUNET_OK;
565}
566
567
570 uint8_t *u8)
571{
573 .parser = &parse_u8,
574 .cleaner = NULL,
575 .cls = NULL,
576 .field = name,
577 .ptr = u8,
578 .ptr_size = sizeof(uint8_t),
579 .size_ptr = NULL
580 };
581
582 return ret;
583}
584
585
596 json_t *root,
597 struct GNUNET_JSON_Specification *spec)
598{
599 json_int_t val;
600 uint16_t *up = spec->ptr;
601
602 if (! json_is_integer (root))
603 {
604 GNUNET_break_op (0);
605 return GNUNET_SYSERR;
606 }
607 val = json_integer_value (root);
608 if ((0 > val) || (val > UINT16_MAX))
609 {
610 GNUNET_break_op (0);
611 return GNUNET_SYSERR;
612 }
613 *up = (uint16_t) val;
614 return GNUNET_OK;
615}
616
617
620 uint16_t *u16)
621{
623 .parser = &parse_u16,
624 .cleaner = NULL,
625 .cls = NULL,
626 .field = name,
627 .ptr = u16,
628 .ptr_size = sizeof(uint16_t),
629 .size_ptr = NULL
630 };
631
632 return ret;
633}
634
635
646 json_t *root,
647 struct GNUNET_JSON_Specification *spec)
648{
649 json_int_t val;
650 uint32_t *up = spec->ptr;
651
652 if (! json_is_integer (root))
653 {
654 GNUNET_break_op (0);
655 return GNUNET_SYSERR;
656 }
657 val = json_integer_value (root);
658 if ((0 > val) || (val > UINT32_MAX))
659 {
660 GNUNET_break_op (0);
661 return GNUNET_SYSERR;
662 }
663 *up = (uint32_t) val;
664 return GNUNET_OK;
665}
666
667
670 uint32_t *u32)
671{
673 .parser = &parse_u32,
674 .cleaner = NULL,
675 .cls = NULL,
676 .field = name,
677 .ptr = u32,
678 .ptr_size = sizeof(uint32_t),
679 .size_ptr = NULL
680 };
681
682 return ret;
683}
684
685
696 json_t *root,
697 struct GNUNET_JSON_Specification *spec)
698{
699 json_int_t val;
700 uint64_t *up = spec->ptr;
701
702 if (! json_is_integer (root))
703 {
704 GNUNET_break_op (0);
705 return GNUNET_SYSERR;
706 }
707 val = json_integer_value (root);
708 *up = (uint64_t) val;
709 return GNUNET_OK;
710}
711
712
715 uint64_t *u64)
716{
718 .parser = &parse_u64,
719 .cleaner = NULL,
720 .cls = NULL,
721 .field = name,
722 .ptr = u64,
723 .ptr_size = sizeof(uint64_t),
724 .size_ptr = NULL
725 };
726
727 return ret;
728}
729
730
741 json_t *root,
742 struct GNUNET_JSON_Specification *spec)
743{
744 json_int_t val;
745 int64_t *up = spec->ptr;
746
747 if (! json_is_integer (root))
748 {
749 GNUNET_break_op (0);
750 return GNUNET_SYSERR;
751 }
752 val = json_integer_value (root);
753 *up = (int64_t) val;
754 return GNUNET_OK;
755}
756
757
760 int64_t *i64)
761{
763 .parser = &parse_i64,
764 .cleaner = NULL,
765 .cls = NULL,
766 .field = name,
767 .ptr = i64,
768 .ptr_size = sizeof(int64_t),
769 .size_ptr = NULL
770 };
771
772 return ret;
773}
774
775
776/* ************ GNUnet-specific parser specifications ******************* */
777
788 json_t *root,
789 struct GNUNET_JSON_Specification *spec)
790{
791 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
792 json_t *json_t_s;
793 unsigned long long int tval;
794
795 if (! json_is_object (root))
796 {
797 GNUNET_break_op (0);
798 return GNUNET_SYSERR;
799 }
800 json_t_s = json_object_get (root,
801 "t_s");
802 if (json_is_integer (json_t_s))
803 {
804 tval = json_integer_value (json_t_s);
805 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
807 = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
808 if (ts->abs_time.abs_value_us
809 / GNUNET_TIME_UNIT_SECONDS.rel_value_us
810 != tval)
811 {
812 /* Integer overflow */
813 GNUNET_break_op (0);
814 return GNUNET_SYSERR;
815 }
816 return GNUNET_OK;
817 }
818 if (json_is_string (json_t_s))
819 {
820 const char *val;
821
822 val = json_string_value (json_t_s);
823 if ((0 == strcasecmp (val,
824 "never")))
825 {
827 return GNUNET_OK;
828 }
829 GNUNET_break_op (0);
830 return GNUNET_SYSERR;
831 }
832 GNUNET_break_op (0);
833 return GNUNET_SYSERR;
834}
835
836
839 struct GNUNET_TIME_Timestamp *t)
840{
842 .parser = &parse_timestamp,
843 .field = name,
844 .ptr = t,
845 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
846 };
847
848 return ret;
849}
850
851
862 json_t *root,
863 struct GNUNET_JSON_Specification *spec)
864{
865 struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
866 struct GNUNET_TIME_Timestamp a;
867 struct GNUNET_JSON_Specification ispec;
868
869 ispec = *spec;
870 ispec.parser = &parse_timestamp;
871 ispec.ptr = &a;
872 if (GNUNET_OK !=
873 parse_timestamp (NULL,
874 root,
875 &ispec))
876 return GNUNET_SYSERR;
878 return GNUNET_OK;
879}
880
881
884 struct GNUNET_TIME_TimestampNBO *at)
885{
887 .parser = &parse_timestamp_nbo,
888 .field = name,
889 .ptr = at,
890 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
891 };
892
893 return ret;
894}
895
896
906parse_rel_time (void *cls,
907 json_t *root,
908 struct GNUNET_JSON_Specification *spec)
909{
910 struct GNUNET_TIME_Relative *rel = spec->ptr;
911 json_t *json_d_us;
912 unsigned long long int tval;
913
914 if (! json_is_object (root))
915 {
916 GNUNET_break_op (0);
917 return GNUNET_SYSERR;
918 }
919 json_d_us = json_object_get (root,
920 "d_us");
921 if (json_is_integer (json_d_us))
922 {
923 tval = json_integer_value (json_d_us);
924 if (tval >= (1LLU << 53))
925 {
926 /* value is larger than allowed */
927 GNUNET_break_op (0);
928 return GNUNET_SYSERR;
929 }
930 rel->rel_value_us = tval;
931 return GNUNET_OK;
932 }
933 if (json_is_string (json_d_us))
934 {
935 const char *val;
936
937 val = json_string_value (json_d_us);
938 if ((0 == strcasecmp (val,
939 "forever")))
940 {
942 return GNUNET_OK;
943 }
944 GNUNET_break_op (0);
945 return GNUNET_SYSERR;
946 }
947 GNUNET_break_op (0);
948 return GNUNET_SYSERR;
949}
950
951
954 struct GNUNET_TIME_Relative *rt)
955{
957 .parser = &parse_rel_time,
958 .field = name,
959 .ptr = rt,
960 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
961 };
962
963 return ret;
964}
965
966
977 json_t *root,
978 struct GNUNET_JSON_Specification *spec)
979{
980 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
981 const char *enc;
982 char *buf;
983 size_t len;
984 size_t buf_len;
985
986 if (NULL == (enc = json_string_value (root)))
987 {
988 GNUNET_break_op (0);
989 return GNUNET_SYSERR;
990 }
991 len = strlen (enc);
992 buf_len = (len * 5) / 8;
993 buf = GNUNET_malloc (buf_len);
994 if (GNUNET_OK !=
996 len,
997 buf,
998 buf_len))
999 {
1000 GNUNET_break_op (0);
1001 GNUNET_free (buf);
1002 return GNUNET_SYSERR;
1003 }
1004 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
1005 buf_len)))
1006 {
1007 GNUNET_break_op (0);
1008 GNUNET_free (buf);
1009 return GNUNET_SYSERR;
1010 }
1011 GNUNET_free (buf);
1012 return GNUNET_OK;
1013}
1014
1015
1022static void
1024 struct GNUNET_JSON_Specification *spec)
1025{
1026 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1027
1028 if (NULL != *pk)
1029 {
1031 *pk = NULL;
1032 }
1033}
1034
1035
1039{
1041 .parser = &parse_rsa_public_key,
1042 .cleaner = &clean_rsa_public_key,
1043 .field = name,
1044 .ptr = pk
1045 };
1046
1047 *pk = NULL;
1048 return ret;
1049}
1050
1051
1060static enum GNUNET_GenericReturnValue
1062 json_t *root,
1063 struct GNUNET_JSON_Specification *spec)
1064{
1065 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1066 size_t size;
1067 const char *str;
1068 int res;
1069 void *buf;
1070
1071 str = json_string_value (root);
1072 if (NULL == str)
1073 {
1074 GNUNET_break_op (0);
1075 return GNUNET_SYSERR;
1076 }
1077 size = (strlen (str) * 5) / 8;
1078 buf = GNUNET_malloc (size);
1080 strlen (str),
1081 buf,
1082 size);
1083 if (GNUNET_OK != res)
1084 {
1085 GNUNET_free (buf);
1086 GNUNET_break_op (0);
1087 return GNUNET_SYSERR;
1088 }
1089 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1090 size)))
1091 {
1092 GNUNET_break_op (0);
1093 GNUNET_free (buf);
1094 return GNUNET_SYSERR;
1095 }
1096 GNUNET_free (buf);
1097 return GNUNET_OK;
1098}
1099
1100
1107static void
1109 struct GNUNET_JSON_Specification *spec)
1110{
1111 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1112
1113 if (NULL != *sig)
1114 {
1116 *sig = NULL;
1117 }
1118}
1119
1120
1123 struct GNUNET_CRYPTO_RsaSignature **sig)
1124{
1126 .parser = &parse_rsa_signature,
1127 .cleaner = &clean_rsa_signature,
1128 .cls = NULL,
1129 .field = name,
1130 .ptr = sig,
1131 .ptr_size = 0,
1132 .size_ptr = NULL
1133 };
1134
1135 *sig = NULL;
1136 return ret;
1137}
1138
1139
1148static enum GNUNET_GenericReturnValue
1150 json_t *root,
1151 struct GNUNET_JSON_Specification *spec)
1152{
1153 int *bp = spec->ptr;
1154
1155 if (! json_is_boolean (root))
1156 {
1157 GNUNET_break_op (0);
1158 return GNUNET_SYSERR;
1159 }
1160 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1161 return GNUNET_OK;
1162}
1163
1164
1167 int *boolean)
1168{
1170 .parser = &parse_boolean,
1171 .cleaner = NULL,
1172 .cls = NULL,
1173 .field = name,
1174 .ptr = boolean,
1175 .ptr_size = sizeof(int),
1176 .size_ptr = NULL
1177 };
1178
1179 return ret;
1180}
1181
1182
1183/* end of json_helper.c */
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * data
The data to insert into the dht.
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_SCHEDULER_Task * t
Main task.
functions to parse JSON objects into GNUnet objects
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1063
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:423
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:855
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:789
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1723
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const(const char *name, const json_t **jsonp)
JSON object, reference counter not incremented.
Definition: json_helper.c:385
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:645
struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize(const char *name, void **obj, size_t *size)
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
Definition: json_helper.c:234
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed(const char *name, void *obj, size_t size)
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
Definition: json_helper.c:93
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:595
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:32
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:740
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:1061
static enum GNUNET_GenericReturnValue parse_double(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a double.
Definition: json_helper.c:502
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json(const char *name, json_t **jsonp)
JSON object or array.
Definition: json_helper.c:341
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_helper.c:1023
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1108
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean(const char *name, int *boolean)
Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
Definition: json_helper.c:1166
static enum GNUNET_GenericReturnValue parse_timestamp(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a timestamp.
Definition: json_helper.c:787
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key(const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk)
Specification for parsing an RSA public key.
Definition: json_helper.c:1037
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16)
16-bit integer.
Definition: json_helper.c:619
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:545
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:861
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo(const char *name, struct GNUNET_TIME_TimestampNBO *at)
Timestamp in network byte order.
Definition: json_helper.c:883
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:669
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:263
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:282
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double(const char *name, double *f)
double.
Definition: json_helper.c:519
static enum GNUNET_GenericReturnValue parse_object_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:368
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64(const char *name, int64_t *i64)
64-bit signed integer.
Definition: json_helper.c:759
static enum GNUNET_GenericReturnValue parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:1149
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
Specification for parsing an RSA signature.
Definition: json_helper.c:1122
static enum GNUNET_GenericReturnValue parse_fixed64_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:120
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:327
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *t)
Timestamp.
Definition: json_helper.c:838
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.
Definition: json_helper.c:411
static enum GNUNET_GenericReturnValue parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:53
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const(const char *name, const json_t **jsonp)
JSON array, reference counter not incremented.
Definition: json_helper.c:428
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed64(const char *name, void *obj, size_t size)
Variable size object (in network byte order, encoded using base64 encoding).
Definition: json_helper.c:157
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:695
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:454
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool(const char *name, bool *b)
boolean.
Definition: json_helper.c:476
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time.
Definition: json_helper.c:953
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8)
8-bit integer.
Definition: json_helper.c:569
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64)
64-bit integer.
Definition: json_helper.c:714
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:906
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:305
static enum GNUNET_GenericReturnValue parse_rsa_public_key(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA public key.
Definition: json_helper.c:976
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:220
static enum GNUNET_GenericReturnValue parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:184
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define SIZE_MAX
Definition: platform.h:208
The public information of an RSA key pair.
Definition: crypto_rsa.c:53
an RSA signature
Definition: crypto_rsa.c:65
Entry in parser specification for GNUNET_JSON_parse().
void * ptr
Pointer, details specific to the parser.
const char * field
Name of the field to parse, use NULL to get the JSON of the main object instead of the JSON of an ind...
size_t ptr_size
Number of bytes available in ptr.
size_t * size_ptr
Where should we store the final size of ptr.
void * cls
Closure for parser and cleaner.
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.