GNUnet  0.11.x
json_helper.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2014, 2015, 2016 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 
36 {
37  struct GNUNET_JSON_Specification ret = {
38  .parser = NULL,
39  .cleaner = NULL,
40  .cls = NULL
41  };
42 
43  return ret;
44 }
45 
46 
55 static int
57  json_t *root,
58  struct GNUNET_JSON_Specification *spec)
59 {
60  const char *enc;
61  unsigned int len;
62 
63  if (NULL == (enc = json_string_value (root)))
64  {
65  GNUNET_break_op (0);
66  return GNUNET_SYSERR;
67  }
68  len = strlen (enc);
69  if (((len * 5) / 8) != spec->ptr_size)
70  {
71  GNUNET_break_op (0);
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 
97  void *obj,
98  size_t size)
99 {
100  struct GNUNET_JSON_Specification ret = {
102  .cleaner = NULL,
103  .cls = NULL,
104  .field = name,
105  .ptr = obj,
106  .ptr_size = size,
107  .size_ptr = NULL
108  };
109 
110  return ret;
111 }
112 
113 
122 static int
124  json_t *root,
125  struct GNUNET_JSON_Specification *spec)
126 {
127  const char *str;
128  size_t size;
129  void *data;
130  int res;
131 
132  str = json_string_value (root);
133  if (NULL == str)
134  {
135  GNUNET_break_op (0);
136  return GNUNET_SYSERR;
137  }
138  size = (strlen (str) * 5) / 8;
139  if (size >= 1024)
140  {
141  GNUNET_break_op (0);
142  return GNUNET_SYSERR;
143  }
144  data = GNUNET_malloc (size);
146  strlen (str),
147  data,
148  size);
149  if (GNUNET_OK != res)
150  {
151  GNUNET_break_op (0);
152  GNUNET_free (data);
153  return GNUNET_SYSERR;
154  }
155  *(void **) spec->ptr = data;
156  *spec->size_ptr = size;
157  return GNUNET_OK;
158 }
159 
160 
167 static void
169  struct GNUNET_JSON_Specification *spec)
170 {
171  if (0 != *spec->size_ptr)
172  {
173  GNUNET_free (*(void **) spec->ptr);
174  *(void **) spec->ptr = NULL;
175  *spec->size_ptr = 0;
176  }
177 }
178 
179 
190  void **obj,
191  size_t *size)
192 {
193  struct GNUNET_JSON_Specification ret = {
195  .cleaner = &clean_variable_data,
196  .cls = NULL,
197  .field = name,
198  .ptr = obj,
199  .ptr_size = 0,
200  .size_ptr = size
201  };
202 
203  *obj = NULL;
204  *size = 0;
205  return ret;
206 }
207 
208 
217 static int
219  json_t *root,
220  struct GNUNET_JSON_Specification *spec)
221 {
222  const char *str;
223 
224  str = json_string_value (root);
225  if (NULL == str)
226  {
227  GNUNET_break_op (0);
228  return GNUNET_SYSERR;
229  }
230  *(const char **) spec->ptr = str;
231  return GNUNET_OK;
232 }
233 
234 
243  const char **strptr)
244 {
245  struct GNUNET_JSON_Specification ret = {
246  .parser = &parse_string,
247  .cleaner = NULL,
248  .cls = NULL,
249  .field = name,
250  .ptr = strptr,
251  .ptr_size = 0,
252  .size_ptr = NULL
253  };
254 
255  *strptr = NULL;
256  return ret;
257 }
258 
259 
268 static int
270  json_t *root,
271  struct GNUNET_JSON_Specification *spec)
272 {
273  if (! (json_is_object (root) || json_is_array (root)))
274  {
275  GNUNET_break_op (0);
276  return GNUNET_SYSERR;
277  }
278  json_incref (root);
279  *(json_t **) spec->ptr = root;
280  return GNUNET_OK;
281 }
282 
283 
290 static void
292  struct GNUNET_JSON_Specification *spec)
293 {
294  json_t **ptr = (json_t **) spec->ptr;
295 
296  if (NULL != *ptr)
297  {
298  json_decref (*ptr);
299  *ptr = NULL;
300  }
301 }
302 
303 
312  json_t **jsonp)
313 {
314  struct GNUNET_JSON_Specification ret = {
315  .parser = &parse_object,
316  .cleaner = &clean_object,
317  .cls = NULL,
318  .field = name,
319  .ptr = jsonp,
320  .ptr_size = 0,
321  .size_ptr = NULL
322  };
323 
324  *jsonp = NULL;
325  return ret;
326 }
327 
328 
337 static int
339  json_t *root,
340  struct GNUNET_JSON_Specification *spec)
341 {
342  bool *b = spec->ptr;
343 
344  if (json_true () == root)
345  {
346  *b = true;
347  return GNUNET_OK;
348  }
349  if (json_false () == root)
350  {
351  *b = false;
352  return GNUNET_OK;
353  }
354  GNUNET_break_op (0);
355  return GNUNET_SYSERR;
356 }
357 
358 
367  bool *b)
368 {
369  struct GNUNET_JSON_Specification ret = {
370  .parser = &parse_bool,
371  .cleaner = NULL,
372  .cls = NULL,
373  .field = name,
374  .ptr = b,
375  .ptr_size = sizeof(bool),
376  .size_ptr = NULL
377  };
378 
379  return ret;
380 }
381 
382 
391 static int
392 parse_u8 (void *cls,
393  json_t *root,
394  struct GNUNET_JSON_Specification *spec)
395 {
396  json_int_t val;
397  uint8_t *up = spec->ptr;
398 
399  if (! json_is_integer (root))
400  {
401  GNUNET_break_op (0);
402  return GNUNET_SYSERR;
403  }
404  val = json_integer_value (root);
405  if ((0 > val) || (val > UINT8_MAX))
406  {
407  GNUNET_break_op (0);
408  return GNUNET_SYSERR;
409  }
410  *up = (uint8_t) val;
411  return GNUNET_OK;
412 }
413 
414 
423  uint8_t *u8)
424 {
425  struct GNUNET_JSON_Specification ret = {
426  .parser = &parse_u8,
427  .cleaner = NULL,
428  .cls = NULL,
429  .field = name,
430  .ptr = u8,
431  .ptr_size = sizeof(uint8_t),
432  .size_ptr = NULL
433  };
434 
435  return ret;
436 }
437 
438 
447 static int
448 parse_u16 (void *cls,
449  json_t *root,
450  struct GNUNET_JSON_Specification *spec)
451 {
452  json_int_t val;
453  uint16_t *up = spec->ptr;
454 
455  if (! json_is_integer (root))
456  {
457  GNUNET_break_op (0);
458  return GNUNET_SYSERR;
459  }
460  val = json_integer_value (root);
461  if ((0 > val) || (val > UINT16_MAX))
462  {
463  GNUNET_break_op (0);
464  return GNUNET_SYSERR;
465  }
466  *up = (uint16_t) val;
467  return GNUNET_OK;
468 }
469 
470 
479  uint16_t *u16)
480 {
481  struct GNUNET_JSON_Specification ret = {
482  .parser = &parse_u16,
483  .cleaner = NULL,
484  .cls = NULL,
485  .field = name,
486  .ptr = u16,
487  .ptr_size = sizeof(uint16_t),
488  .size_ptr = NULL
489  };
490 
491  return ret;
492 }
493 
494 
503 static int
504 parse_u32 (void *cls,
505  json_t *root,
506  struct GNUNET_JSON_Specification *spec)
507 {
508  json_int_t val;
509  uint32_t *up = spec->ptr;
510 
511  if (! json_is_integer (root))
512  {
513  GNUNET_break_op (0);
514  return GNUNET_SYSERR;
515  }
516  val = json_integer_value (root);
517  if ((0 > val) || (val > UINT32_MAX))
518  {
519  GNUNET_break_op (0);
520  return GNUNET_SYSERR;
521  }
522  *up = (uint32_t) val;
523  return GNUNET_OK;
524 }
525 
526 
535  uint32_t *u32)
536 {
537  struct GNUNET_JSON_Specification ret = {
538  .parser = &parse_u32,
539  .cleaner = NULL,
540  .cls = NULL,
541  .field = name,
542  .ptr = u32,
543  .ptr_size = sizeof(uint32_t),
544  .size_ptr = NULL
545  };
546 
547  return ret;
548 }
549 
550 
559 static int
560 parse_u64 (void *cls,
561  json_t *root,
562  struct GNUNET_JSON_Specification *spec)
563 {
564  json_int_t val;
565  uint64_t *up = spec->ptr;
566 
567  if (! json_is_integer (root))
568  {
569  GNUNET_break_op (0);
570  return GNUNET_SYSERR;
571  }
572  val = json_integer_value (root);
573  *up = (uint64_t) val;
574  return GNUNET_OK;
575 }
576 
577 
586  uint64_t *u64)
587 {
588  struct GNUNET_JSON_Specification ret = {
589  .parser = &parse_u64,
590  .cleaner = NULL,
591  .cls = NULL,
592  .field = name,
593  .ptr = u64,
594  .ptr_size = sizeof(uint64_t),
595  .size_ptr = NULL
596  };
597 
598  return ret;
599 }
600 
601 
610 static int
611 parse_i64 (void *cls,
612  json_t *root,
613  struct GNUNET_JSON_Specification *spec)
614 {
615  json_int_t val;
616  int64_t *up = spec->ptr;
617 
618  if (! json_is_integer (root))
619  {
620  GNUNET_break_op (0);
621  return GNUNET_SYSERR;
622  }
623  val = json_integer_value (root);
624  *up = (int64_t) val;
625  return GNUNET_OK;
626 }
627 
628 
637  int64_t *i64)
638 {
639  struct GNUNET_JSON_Specification ret = {
640  .parser = &parse_i64,
641  .cleaner = NULL,
642  .cls = NULL,
643  .field = name,
644  .ptr = i64,
645  .ptr_size = sizeof(int64_t),
646  .size_ptr = NULL
647  };
648 
649  return ret;
650 }
651 
652 
653 /* ************ GNUnet-specific parser specifications ******************* */
654 
663 static int
665  json_t *root,
666  struct GNUNET_JSON_Specification *spec)
667 {
668  struct GNUNET_TIME_Absolute *abs = spec->ptr;
669  json_t *json_t_ms;
670  unsigned long long int tval;
671 
672  if (! json_is_object (root))
673  {
674  GNUNET_break_op (0);
675  return GNUNET_SYSERR;
676  }
677  json_t_ms = json_object_get (root, "t_ms");
678  if (json_is_integer (json_t_ms))
679  {
680  tval = json_integer_value (json_t_ms);
681  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
682  abs->abs_value_us = tval * 1000LL;
683  if ((abs->abs_value_us) / 1000LL != tval)
684  {
685  /* Integer overflow */
686  GNUNET_break_op (0);
687  return GNUNET_SYSERR;
688  }
689  return GNUNET_OK;
690  }
691  if (json_is_string (json_t_ms))
692  {
693  const char *val;
694  val = json_string_value (json_t_ms);
695  if ((0 == strcasecmp (val, "never")))
696  {
698  return GNUNET_OK;
699  }
700  GNUNET_break_op (0);
701  return GNUNET_SYSERR;
702  }
703  GNUNET_break_op (0);
704  return GNUNET_SYSERR;
705 }
706 
707 
716  struct GNUNET_TIME_Absolute *at)
717 {
718  struct GNUNET_JSON_Specification ret = {
720  .cleaner = NULL,
721  .cls = NULL,
722  .field = name,
723  .ptr = at,
724  .ptr_size = sizeof(struct GNUNET_TIME_Absolute),
725  .size_ptr = NULL
726  };
727 
728  return ret;
729 }
730 
731 
740 static int
742  json_t *root,
743  struct GNUNET_JSON_Specification *spec)
744 {
745  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
746  struct GNUNET_TIME_Absolute a;
747  struct GNUNET_JSON_Specification ispec;
748 
749  ispec = *spec;
750  ispec.parser = &parse_abs_time;
751  ispec.ptr = &a;
752  if (GNUNET_OK !=
753  parse_abs_time (NULL,
754  root,
755  &ispec))
756  return GNUNET_SYSERR;
757  *abs = GNUNET_TIME_absolute_hton (a);
758  return GNUNET_OK;
759 }
760 
761 
770  struct GNUNET_TIME_AbsoluteNBO *at)
771 {
772  struct GNUNET_JSON_Specification ret = {
774  .cleaner = NULL,
775  .cls = NULL,
776  .field = name,
777  .ptr = at,
778  .ptr_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
779  .size_ptr = NULL
780  };
781 
782  return ret;
783 }
784 
785 
794 static int
796  json_t *root,
797  struct GNUNET_JSON_Specification *spec)
798 {
799  struct GNUNET_TIME_Relative *rel = spec->ptr;
800  json_t *json_d_ms;
801  unsigned long long int tval;
802 
803  if (! json_is_object (root))
804  {
805  GNUNET_break_op (0);
806  return GNUNET_SYSERR;
807  }
808  json_d_ms = json_object_get (root, "d_ms");
809  if (json_is_integer (json_d_ms))
810  {
811  tval = json_integer_value (json_d_ms);
812  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
813  rel->rel_value_us = tval * 1000LL;
814  if ((rel->rel_value_us) / 1000LL != tval)
815  {
816  /* Integer overflow */
817  GNUNET_break_op (0);
818  return GNUNET_SYSERR;
819  }
820  return GNUNET_OK;
821  }
822  if (json_is_string (json_d_ms))
823  {
824  const char *val;
825  val = json_string_value (json_d_ms);
826  if ((0 == strcasecmp (val, "forever")))
827  {
829  return GNUNET_OK;
830  }
831  GNUNET_break_op (0);
832  return GNUNET_SYSERR;
833  }
834  GNUNET_break_op (0);
835  return GNUNET_SYSERR;
836 }
837 
838 
847  struct GNUNET_TIME_Relative *rt)
848 {
849  struct GNUNET_JSON_Specification ret = {
851  .cleaner = NULL,
852  .cls = NULL,
853  .field = name,
854  .ptr = rt,
855  .ptr_size = sizeof(struct GNUNET_TIME_Relative),
856  .size_ptr = NULL
857  };
858 
859  return ret;
860 }
861 
862 
871 static int
873  json_t *root,
874  struct GNUNET_JSON_Specification *spec)
875 {
876  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
877  const char *enc;
878  char *buf;
879  size_t len;
880  size_t buf_len;
881 
882  if (NULL == (enc = json_string_value (root)))
883  {
884  GNUNET_break_op (0);
885  return GNUNET_SYSERR;
886  }
887  len = strlen (enc);
888  buf_len = (len * 5) / 8;
889  buf = GNUNET_malloc (buf_len);
890  if (GNUNET_OK !=
892  len,
893  buf,
894  buf_len))
895  {
896  GNUNET_break_op (0);
897  GNUNET_free (buf);
898  return GNUNET_SYSERR;
899  }
900  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
901  buf_len)))
902  {
903  GNUNET_break_op (0);
904  GNUNET_free (buf);
905  return GNUNET_SYSERR;
906  }
907  GNUNET_free (buf);
908  return GNUNET_OK;
909 }
910 
911 
918 static void
920  struct GNUNET_JSON_Specification *spec)
921 {
922  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
923 
924  if (NULL != *pk)
925  {
927  *pk = NULL;
928  }
929 }
930 
931 
941 {
942  struct GNUNET_JSON_Specification ret = {
944  .cleaner = &clean_rsa_public_key,
945  .cls = NULL,
946  .field = name,
947  .ptr = pk,
948  .ptr_size = 0,
949  .size_ptr = NULL
950  };
951 
952  *pk = NULL;
953  return ret;
954 }
955 
956 
965 static int
967  json_t *root,
968  struct GNUNET_JSON_Specification *spec)
969 {
970  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
971  size_t size;
972  const char *str;
973  int res;
974  void *buf;
975 
976  str = json_string_value (root);
977  if (NULL == str)
978  {
979  GNUNET_break_op (0);
980  return GNUNET_SYSERR;
981  }
982  size = (strlen (str) * 5) / 8;
983  buf = GNUNET_malloc (size);
985  strlen (str),
986  buf,
987  size);
988  if (GNUNET_OK != res)
989  {
990  GNUNET_free (buf);
991  GNUNET_break_op (0);
992  return GNUNET_SYSERR;
993  }
994  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
995  size)))
996  {
997  GNUNET_break_op (0);
998  GNUNET_free (buf);
999  return GNUNET_SYSERR;
1000  }
1001  GNUNET_free (buf);
1002  return GNUNET_OK;
1003 }
1004 
1005 
1012 static void
1014  struct GNUNET_JSON_Specification *spec)
1015 {
1016  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1017 
1018  if (NULL != *sig)
1019  {
1021  *sig = NULL;
1022  }
1023 }
1024 
1025 
1034  struct GNUNET_CRYPTO_RsaSignature **sig)
1035 {
1036  struct GNUNET_JSON_Specification ret = {
1038  .cleaner = &clean_rsa_signature,
1039  .cls = NULL,
1040  .field = name,
1041  .ptr = sig,
1042  .ptr_size = 0,
1043  .size_ptr = NULL
1044  };
1045 
1046  *sig = NULL;
1047  return ret;
1048 }
1049 
1050 
1059 static int
1061  json_t *root,
1062  struct GNUNET_JSON_Specification *spec)
1063 {
1064  int *bp = spec->ptr;
1065 
1066  if (! json_is_boolean (root))
1067  {
1068  GNUNET_break_op (0);
1069  return GNUNET_SYSERR;
1070  }
1071  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1072  return GNUNET_OK;
1073 }
1074 
1075 
1084  int *boolean)
1085 {
1086  struct GNUNET_JSON_Specification ret = {
1087  .parser = &parse_boolean,
1088  .cleaner = NULL,
1089  .cls = NULL,
1090  .field = name,
1091  .ptr = boolean,
1092  .ptr_size = sizeof(int),
1093  .size_ptr = NULL
1094  };
1095 
1096  return ret;
1097 }
1098 
1099 
1100 /* end of json_helper.c */
void * cls
Closure for parser and cleaner.
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:168
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:534
uint64_t rel_value_us
The actual value.
an RSA signature
Definition: crypto_rsa.c:63
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1061
functions to parse JSON objects into GNUnet objects
static int 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:872
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json(const char *name, json_t **jsonp)
JSON object.
Definition: json_helper.c:311
static int parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:448
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16)
16-bit integer.
Definition: json_helper.c:478
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo(const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
Absolute time in network byte order.
Definition: json_helper.c:769
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:966
static int parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:338
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1013
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
uint64_t abs_value_us
The actual value.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
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:1124
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:504
static int parse_object(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:269
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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:443
static char buf[2048]
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:919
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:291
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:96
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool(const char *name, bool *b)
boolean.
Definition: json_helper.c:366
static int parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:611
static int res
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:35
static int 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:1060
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int 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:123
void * ptr
Pointer, details specific to the parser.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8)
8-bit integer.
Definition: json_helper.c:422
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:1033
static int parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:560
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:218
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64)
64-bit integer.
Definition: json_helper.c:585
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:242
static int parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:795
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time.
Definition: json_helper.c:846
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
const char * name
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:1083
static int 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:56
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time(const char *name, struct GNUNET_TIME_Absolute *at)
Absolute time.
Definition: json_helper.c:715
size_t ptr_size
Number of bytes available in ptr.
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:392
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:189
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:939
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:305
Time for absolute times used by GNUnet, in microseconds.
static int parse_abs_time_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:741
uint32_t data
The data value.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64(const char *name, int64_t *i64)
64-bit signed integer.
Definition: json_helper.c:636
static int parse_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:664
#define GNUNET_malloc(size)
Wrapper around malloc.
int 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:972
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...