GNUnet  0.19.3
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 
52 static enum GNUNET_GenericReturnValue
53 parse_fixed_data (void *cls,
54  json_t *root,
55  struct GNUNET_JSON_Specification *spec)
56 {
57  const char *enc;
58  unsigned int len;
59 
60  if (NULL == (enc = json_string_value (root)))
61  {
62  GNUNET_break_op (0);
63  return GNUNET_SYSERR;
64  }
65  len = strlen (enc);
66  if (((len * 5) / 8) != spec->ptr_size)
67  {
68  GNUNET_break_op (0);
70  "Field `%s' has wrong length\n",
71  spec->field);
72  return GNUNET_SYSERR;
73  }
74  if (GNUNET_OK !=
76  len,
77  spec->ptr,
78  spec->ptr_size))
79  {
80  GNUNET_break_op (0);
81  return GNUNET_SYSERR;
82  }
83  return GNUNET_OK;
84 }
85 
86 
88 GNUNET_JSON_spec_fixed (const char *name,
89  void *obj,
90  size_t size)
91 {
93  .parser = &parse_fixed_data,
94  .cleaner = NULL,
95  .cls = NULL,
96  .field = name,
97  .ptr = obj,
98  .ptr_size = size,
99  .size_ptr = NULL
100  };
101 
102  return ret;
103 }
104 
105 
114 static enum GNUNET_GenericReturnValue
115 parse_fixed64_data (void *cls,
116  json_t *root,
117  struct GNUNET_JSON_Specification *spec)
118 {
119  const char *enc;
120  unsigned int len;
121  void *output;
122  size_t olen;
123 
124  if (NULL == (enc = json_string_value (root)))
125  {
126  GNUNET_break_op (0);
127  return GNUNET_SYSERR;
128  }
129  len = strlen (enc);
130  output = NULL;
132  len,
133  &output);
134  if (olen != spec->ptr_size)
135  {
136  GNUNET_break_op (0);
138  "Field `%s' has wrong length\n",
139  spec->field);
140  GNUNET_free (output);
141  return GNUNET_SYSERR;
142  }
143  memcpy (spec->ptr,
144  output,
145  olen);
146  GNUNET_free (output);
147  return GNUNET_OK;
148 }
149 
150 
152 GNUNET_JSON_spec_fixed64 (const char *name,
153  void *obj,
154  size_t size)
155 {
156  struct GNUNET_JSON_Specification ret = {
157  .parser = &parse_fixed64_data,
158  .cleaner = NULL,
159  .cls = NULL,
160  .field = name,
161  .ptr = obj,
162  .ptr_size = size,
163  .size_ptr = NULL
164  };
165 
166  return ret;
167 }
168 
169 
178 static enum GNUNET_GenericReturnValue
179 parse_variable_data (void *cls,
180  json_t *root,
181  struct GNUNET_JSON_Specification *spec)
182 {
183  const char *str;
184  size_t size;
185  void *data;
186 
187  str = json_string_value (root);
188  if (NULL == str)
189  {
190  GNUNET_break_op (0);
191  return GNUNET_SYSERR;
192  }
193  if (GNUNET_OK !=
195  strlen (str),
196  &data,
197  &size))
198  {
199  GNUNET_break_op (0);
200  return GNUNET_SYSERR;
201  }
202  *(void **) spec->ptr = data;
203  *spec->size_ptr = size;
204  return GNUNET_OK;
205 }
206 
207 
214 static void
216  struct GNUNET_JSON_Specification *spec)
217 {
218  (void) cls;
219  if (0 != *spec->size_ptr)
220  {
221  GNUNET_free (*(void **) spec->ptr);
222  *(void **) spec->ptr = NULL;
223  *spec->size_ptr = 0;
224  }
225 }
226 
227 
229 GNUNET_JSON_spec_varsize (const char *name,
230  void **obj,
231  size_t *size)
232 {
233  struct GNUNET_JSON_Specification ret = {
234  .parser = &parse_variable_data,
235  .cleaner = &clean_variable_data,
236  .cls = NULL,
237  .field = name,
238  .ptr = obj,
239  .ptr_size = 0,
240  .size_ptr = size
241  };
242 
243  *obj = NULL;
244  *size = 0;
245  return ret;
246 }
247 
248 
257 static enum GNUNET_GenericReturnValue
258 parse_string (void *cls,
259  json_t *root,
260  struct GNUNET_JSON_Specification *spec)
261 {
262  const char *str;
263 
264  (void) cls;
265  str = json_string_value (root);
266  if (NULL == str)
267  {
268  GNUNET_break_op (0);
269  return GNUNET_SYSERR;
270  }
271  *(const char **) spec->ptr = str;
272  return GNUNET_OK;
273 }
274 
275 
277 GNUNET_JSON_spec_string (const char *name,
278  const char **strptr)
279 {
280  struct GNUNET_JSON_Specification ret = {
281  .parser = &parse_string,
282  .cleaner = NULL,
283  .cls = NULL,
284  .field = name,
285  .ptr = strptr,
286  .ptr_size = 0,
287  .size_ptr = NULL
288  };
289 
290  *strptr = NULL;
291  return ret;
292 }
293 
294 
303 static enum GNUNET_GenericReturnValue
304 parse_object (void *cls,
305  json_t *root,
306  struct GNUNET_JSON_Specification *spec)
307 {
308  if (! (json_is_object (root) || json_is_array (root)))
309  {
310  GNUNET_break_op (0);
311  return GNUNET_SYSERR;
312  }
313  json_incref (root);
314  *(json_t **) spec->ptr = root;
315  return GNUNET_OK;
316 }
317 
318 
325 static void
327  struct GNUNET_JSON_Specification *spec)
328 {
329  json_t **ptr = (json_t **) spec->ptr;
330 
331  if (NULL != *ptr)
332  {
333  json_decref (*ptr);
334  *ptr = NULL;
335  }
336 }
337 
338 
340 GNUNET_JSON_spec_json (const char *name,
341  json_t **jsonp)
342 {
343  struct GNUNET_JSON_Specification ret = {
344  .parser = &parse_object,
345  .cleaner = &clean_object,
346  .cls = NULL,
347  .field = name,
348  .ptr = jsonp,
349  .ptr_size = 0,
350  .size_ptr = NULL
351  };
352 
353  *jsonp = NULL;
354  return ret;
355 }
356 
357 
366 static enum GNUNET_GenericReturnValue
367 parse_bool (void *cls,
368  json_t *root,
369  struct GNUNET_JSON_Specification *spec)
370 {
371  bool *b = spec->ptr;
372 
373  if (json_true () == root)
374  {
375  *b = true;
376  return GNUNET_OK;
377  }
378  if (json_false () == root)
379  {
380  *b = false;
381  return GNUNET_OK;
382  }
383  GNUNET_break_op (0);
384  return GNUNET_SYSERR;
385 }
386 
387 
389 GNUNET_JSON_spec_bool (const char *name,
390  bool *b)
391 {
392  struct GNUNET_JSON_Specification ret = {
393  .parser = &parse_bool,
394  .cleaner = NULL,
395  .cls = NULL,
396  .field = name,
397  .ptr = b,
398  .ptr_size = sizeof(bool),
399  .size_ptr = NULL
400  };
401 
402  return ret;
403 }
404 
405 
414 static enum GNUNET_GenericReturnValue
415 parse_u8 (void *cls,
416  json_t *root,
417  struct GNUNET_JSON_Specification *spec)
418 {
419  json_int_t val;
420  uint8_t *up = spec->ptr;
421 
422  if (! json_is_integer (root))
423  {
424  GNUNET_break_op (0);
425  return GNUNET_SYSERR;
426  }
427  val = json_integer_value (root);
428  if ((0 > val) || (val > UINT8_MAX))
429  {
430  GNUNET_break_op (0);
431  return GNUNET_SYSERR;
432  }
433  *up = (uint8_t) val;
434  return GNUNET_OK;
435 }
436 
437 
439 GNUNET_JSON_spec_uint8 (const char *name,
440  uint8_t *u8)
441 {
442  struct GNUNET_JSON_Specification ret = {
443  .parser = &parse_u8,
444  .cleaner = NULL,
445  .cls = NULL,
446  .field = name,
447  .ptr = u8,
448  .ptr_size = sizeof(uint8_t),
449  .size_ptr = NULL
450  };
451 
452  return ret;
453 }
454 
455 
464 static enum GNUNET_GenericReturnValue
465 parse_u16 (void *cls,
466  json_t *root,
467  struct GNUNET_JSON_Specification *spec)
468 {
469  json_int_t val;
470  uint16_t *up = spec->ptr;
471 
472  if (! json_is_integer (root))
473  {
474  GNUNET_break_op (0);
475  return GNUNET_SYSERR;
476  }
477  val = json_integer_value (root);
478  if ((0 > val) || (val > UINT16_MAX))
479  {
480  GNUNET_break_op (0);
481  return GNUNET_SYSERR;
482  }
483  *up = (uint16_t) val;
484  return GNUNET_OK;
485 }
486 
487 
489 GNUNET_JSON_spec_uint16 (const char *name,
490  uint16_t *u16)
491 {
492  struct GNUNET_JSON_Specification ret = {
493  .parser = &parse_u16,
494  .cleaner = NULL,
495  .cls = NULL,
496  .field = name,
497  .ptr = u16,
498  .ptr_size = sizeof(uint16_t),
499  .size_ptr = NULL
500  };
501 
502  return ret;
503 }
504 
505 
514 static enum GNUNET_GenericReturnValue
515 parse_u32 (void *cls,
516  json_t *root,
517  struct GNUNET_JSON_Specification *spec)
518 {
519  json_int_t val;
520  uint32_t *up = spec->ptr;
521 
522  if (! json_is_integer (root))
523  {
524  GNUNET_break_op (0);
525  return GNUNET_SYSERR;
526  }
527  val = json_integer_value (root);
528  if ((0 > val) || (val > UINT32_MAX))
529  {
530  GNUNET_break_op (0);
531  return GNUNET_SYSERR;
532  }
533  *up = (uint32_t) val;
534  return GNUNET_OK;
535 }
536 
537 
539 GNUNET_JSON_spec_uint32 (const char *name,
540  uint32_t *u32)
541 {
542  struct GNUNET_JSON_Specification ret = {
543  .parser = &parse_u32,
544  .cleaner = NULL,
545  .cls = NULL,
546  .field = name,
547  .ptr = u32,
548  .ptr_size = sizeof(uint32_t),
549  .size_ptr = NULL
550  };
551 
552  return ret;
553 }
554 
555 
564 static enum GNUNET_GenericReturnValue
565 parse_u64 (void *cls,
566  json_t *root,
567  struct GNUNET_JSON_Specification *spec)
568 {
569  json_int_t val;
570  uint64_t *up = spec->ptr;
571 
572  if (! json_is_integer (root))
573  {
574  GNUNET_break_op (0);
575  return GNUNET_SYSERR;
576  }
577  val = json_integer_value (root);
578  *up = (uint64_t) val;
579  return GNUNET_OK;
580 }
581 
582 
584 GNUNET_JSON_spec_uint64 (const char *name,
585  uint64_t *u64)
586 {
587  struct GNUNET_JSON_Specification ret = {
588  .parser = &parse_u64,
589  .cleaner = NULL,
590  .cls = NULL,
591  .field = name,
592  .ptr = u64,
593  .ptr_size = sizeof(uint64_t),
594  .size_ptr = NULL
595  };
596 
597  return ret;
598 }
599 
600 
609 static enum GNUNET_GenericReturnValue
610 parse_i64 (void *cls,
611  json_t *root,
612  struct GNUNET_JSON_Specification *spec)
613 {
614  json_int_t val;
615  int64_t *up = spec->ptr;
616 
617  if (! json_is_integer (root))
618  {
619  GNUNET_break_op (0);
620  return GNUNET_SYSERR;
621  }
622  val = json_integer_value (root);
623  *up = (int64_t) val;
624  return GNUNET_OK;
625 }
626 
627 
629 GNUNET_JSON_spec_int64 (const char *name,
630  int64_t *i64)
631 {
632  struct GNUNET_JSON_Specification ret = {
633  .parser = &parse_i64,
634  .cleaner = NULL,
635  .cls = NULL,
636  .field = name,
637  .ptr = i64,
638  .ptr_size = sizeof(int64_t),
639  .size_ptr = NULL
640  };
641 
642  return ret;
643 }
644 
645 
646 /* ************ GNUnet-specific parser specifications ******************* */
647 
656 static enum GNUNET_GenericReturnValue
657 parse_timestamp (void *cls,
658  json_t *root,
659  struct GNUNET_JSON_Specification *spec)
660 {
661  struct GNUNET_TIME_Timestamp *ts = spec->ptr;
662  json_t *json_t_s;
663  unsigned long long int tval;
664 
665  if (! json_is_object (root))
666  {
667  GNUNET_break_op (0);
668  return GNUNET_SYSERR;
669  }
670  json_t_s = json_object_get (root,
671  "t_s");
672  if (json_is_integer (json_t_s))
673  {
674  tval = json_integer_value (json_t_s);
675  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
677  = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
678  if (ts->abs_time.abs_value_us
679  / GNUNET_TIME_UNIT_SECONDS.rel_value_us
680  != tval)
681  {
682  /* Integer overflow */
683  GNUNET_break_op (0);
684  return GNUNET_SYSERR;
685  }
686  return GNUNET_OK;
687  }
688  if (json_is_string (json_t_s))
689  {
690  const char *val;
691 
692  val = json_string_value (json_t_s);
693  if ((0 == strcasecmp (val,
694  "never")))
695  {
697  return GNUNET_OK;
698  }
699  GNUNET_break_op (0);
700  return GNUNET_SYSERR;
701  }
702  GNUNET_break_op (0);
703  return GNUNET_SYSERR;
704 }
705 
706 
708 GNUNET_JSON_spec_timestamp (const char *name,
709  struct GNUNET_TIME_Timestamp *t)
710 {
711  struct GNUNET_JSON_Specification ret = {
712  .parser = &parse_timestamp,
713  .field = name,
714  .ptr = t,
715  .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
716  };
717 
718  return ret;
719 }
720 
721 
730 static enum GNUNET_GenericReturnValue
731 parse_timestamp_nbo (void *cls,
732  json_t *root,
733  struct GNUNET_JSON_Specification *spec)
734 {
735  struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
736  struct GNUNET_TIME_Timestamp a;
737  struct GNUNET_JSON_Specification ispec;
738 
739  ispec = *spec;
740  ispec.parser = &parse_timestamp;
741  ispec.ptr = &a;
742  if (GNUNET_OK !=
743  parse_timestamp (NULL,
744  root,
745  &ispec))
746  return GNUNET_SYSERR;
747  *ts = GNUNET_TIME_timestamp_hton (a);
748  return GNUNET_OK;
749 }
750 
751 
754  struct GNUNET_TIME_TimestampNBO *at)
755 {
756  struct GNUNET_JSON_Specification ret = {
757  .parser = &parse_timestamp_nbo,
758  .field = name,
759  .ptr = at,
760  .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
761  };
762 
763  return ret;
764 }
765 
766 
775 static enum GNUNET_GenericReturnValue
776 parse_rel_time (void *cls,
777  json_t *root,
778  struct GNUNET_JSON_Specification *spec)
779 {
780  struct GNUNET_TIME_Relative *rel = spec->ptr;
781  json_t *json_d_us;
782  unsigned long long int tval;
783 
784  if (! json_is_object (root))
785  {
786  GNUNET_break_op (0);
787  return GNUNET_SYSERR;
788  }
789  json_d_us = json_object_get (root,
790  "d_us");
791  if (json_is_integer (json_d_us))
792  {
793  tval = json_integer_value (json_d_us);
794  if (tval >= (1LLU << 53))
795  {
796  /* value is larger than allowed */
797  GNUNET_break_op (0);
798  return GNUNET_SYSERR;
799  }
800  rel->rel_value_us = tval;
801  return GNUNET_OK;
802  }
803  if (json_is_string (json_d_us))
804  {
805  const char *val;
806 
807  val = json_string_value (json_d_us);
808  if ((0 == strcasecmp (val,
809  "forever")))
810  {
812  return GNUNET_OK;
813  }
814  GNUNET_break_op (0);
815  return GNUNET_SYSERR;
816  }
817  GNUNET_break_op (0);
818  return GNUNET_SYSERR;
819 }
820 
821 
824  struct GNUNET_TIME_Relative *rt)
825 {
826  struct GNUNET_JSON_Specification ret = {
827  .parser = &parse_rel_time,
828  .field = name,
829  .ptr = rt,
830  .ptr_size = sizeof(struct GNUNET_TIME_Relative)
831  };
832 
833  return ret;
834 }
835 
836 
845 static enum GNUNET_GenericReturnValue
846 parse_rsa_public_key (void *cls,
847  json_t *root,
848  struct GNUNET_JSON_Specification *spec)
849 {
850  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
851  const char *enc;
852  char *buf;
853  size_t len;
854  size_t buf_len;
855 
856  if (NULL == (enc = json_string_value (root)))
857  {
858  GNUNET_break_op (0);
859  return GNUNET_SYSERR;
860  }
861  len = strlen (enc);
862  buf_len = (len * 5) / 8;
863  buf = GNUNET_malloc (buf_len);
864  if (GNUNET_OK !=
866  len,
867  buf,
868  buf_len))
869  {
870  GNUNET_break_op (0);
871  GNUNET_free (buf);
872  return GNUNET_SYSERR;
873  }
874  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
875  buf_len)))
876  {
877  GNUNET_break_op (0);
878  GNUNET_free (buf);
879  return GNUNET_SYSERR;
880  }
881  GNUNET_free (buf);
882  return GNUNET_OK;
883 }
884 
885 
892 static void
894  struct GNUNET_JSON_Specification *spec)
895 {
896  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
897 
898  if (NULL != *pk)
899  {
901  *pk = NULL;
902  }
903 }
904 
905 
909 {
910  struct GNUNET_JSON_Specification ret = {
911  .parser = &parse_rsa_public_key,
912  .cleaner = &clean_rsa_public_key,
913  .field = name,
914  .ptr = pk
915  };
916 
917  *pk = NULL;
918  return ret;
919 }
920 
921 
930 static enum GNUNET_GenericReturnValue
931 parse_rsa_signature (void *cls,
932  json_t *root,
933  struct GNUNET_JSON_Specification *spec)
934 {
935  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
936  size_t size;
937  const char *str;
938  int res;
939  void *buf;
940 
941  str = json_string_value (root);
942  if (NULL == str)
943  {
944  GNUNET_break_op (0);
945  return GNUNET_SYSERR;
946  }
947  size = (strlen (str) * 5) / 8;
948  buf = GNUNET_malloc (size);
950  strlen (str),
951  buf,
952  size);
953  if (GNUNET_OK != res)
954  {
955  GNUNET_free (buf);
956  GNUNET_break_op (0);
957  return GNUNET_SYSERR;
958  }
959  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
960  size)))
961  {
962  GNUNET_break_op (0);
963  GNUNET_free (buf);
964  return GNUNET_SYSERR;
965  }
966  GNUNET_free (buf);
967  return GNUNET_OK;
968 }
969 
970 
977 static void
979  struct GNUNET_JSON_Specification *spec)
980 {
981  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
982 
983  if (NULL != *sig)
984  {
986  *sig = NULL;
987  }
988 }
989 
990 
993  struct GNUNET_CRYPTO_RsaSignature **sig)
994 {
995  struct GNUNET_JSON_Specification ret = {
996  .parser = &parse_rsa_signature,
997  .cleaner = &clean_rsa_signature,
998  .cls = NULL,
999  .field = name,
1000  .ptr = sig,
1001  .ptr_size = 0,
1002  .size_ptr = NULL
1003  };
1004 
1005  *sig = NULL;
1006  return ret;
1007 }
1008 
1009 
1018 static enum GNUNET_GenericReturnValue
1019 parse_boolean (void *cls,
1020  json_t *root,
1021  struct GNUNET_JSON_Specification *spec)
1022 {
1023  int *bp = spec->ptr;
1024 
1025  if (! json_is_boolean (root))
1026  {
1027  GNUNET_break_op (0);
1028  return GNUNET_SYSERR;
1029  }
1030  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1031  return GNUNET_OK;
1032 }
1033 
1034 
1036 GNUNET_JSON_spec_boolean (const char *name,
1037  int *boolean)
1038 {
1039  struct GNUNET_JSON_Specification ret = {
1040  .parser = &parse_boolean,
1041  .cleaner = NULL,
1042  .cls = NULL,
1043  .field = name,
1044  .ptr = boolean,
1045  .ptr_size = sizeof(int),
1046  .size_ptr = NULL
1047  };
1048 
1049  return ret;
1050 }
1051 
1052 
1053 /* end of json_helper.c */
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int res
static OpusEncoder * enc
OPUS encoder.
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static char buf[2048]
static struct GNUNET_SCHEDULER_Task * t
Main task.
functions to parse JSON objects into GNUnet objects
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:1039
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:991
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268
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
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:854
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:788
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695
#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".
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:515
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:229
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:88
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:465
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:610
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:931
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:326
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json(const char *name, json_t **jsonp)
JSON object.
Definition: json_helper.c:340
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:893
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:978
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:1036
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:657
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:907
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16)
16-bit integer.
Definition: json_helper.c:489
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:415
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:731
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:753
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:539
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:258
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:277
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64(const char *name, int64_t *i64)
64-bit signed integer.
Definition: json_helper.c:629
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:1019
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:992
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:115
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *t)
Timestamp.
Definition: json_helper.c:708
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_fixed64(const char *name, void *obj, size_t size)
Variable size object (in network byte order, encoded using base64 encoding).
Definition: json_helper.c:152
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:565
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:367
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool(const char *name, bool *b)
boolean.
Definition: json_helper.c:389
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time.
Definition: json_helper.c:823
static enum GNUNET_GenericReturnValue parse_object(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:304
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8)
8-bit integer.
Definition: json_helper.c:439
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64)
64-bit integer.
Definition: json_helper.c:584
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:776
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:846
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:215
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:179
static unsigned int size
Size of the "table".
Definition: peer.c:68
const char * name
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.