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 
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);
69  return GNUNET_SYSERR;
70  }
71  if (GNUNET_OK !=
73  len,
74  spec->ptr,
75  spec->ptr_size))
76  {
77  GNUNET_break_op (0);
78  return GNUNET_SYSERR;
79  }
80  return GNUNET_OK;
81 }
82 
83 
85 GNUNET_JSON_spec_fixed (const char *name,
86  void *obj,
87  size_t size)
88 {
90  .parser = &parse_fixed_data,
91  .cleaner = NULL,
92  .cls = NULL,
93  .field = name,
94  .ptr = obj,
95  .ptr_size = size,
96  .size_ptr = NULL
97  };
98 
99  return ret;
100 }
101 
102 
111 static int
113  json_t *root,
114  struct GNUNET_JSON_Specification *spec)
115 {
116  const char *str;
117  size_t size;
118  void *data;
119 
120  str = json_string_value (root);
121  if (NULL == str)
122  {
123  GNUNET_break_op (0);
124  return GNUNET_SYSERR;
125  }
126  if (GNUNET_OK !=
128  strlen (str),
129  &data,
130  &size))
131  {
132  GNUNET_break_op (0);
133  return GNUNET_SYSERR;
134  }
135  *(void **) spec->ptr = data;
136  *spec->size_ptr = size;
137  return GNUNET_OK;
138 }
139 
140 
147 static void
149  struct GNUNET_JSON_Specification *spec)
150 {
151  (void) cls;
152  if (0 != *spec->size_ptr)
153  {
154  GNUNET_free (*(void **) spec->ptr);
155  *(void **) spec->ptr = NULL;
156  *spec->size_ptr = 0;
157  }
158 }
159 
160 
162 GNUNET_JSON_spec_varsize (const char *name,
163  void **obj,
164  size_t *size)
165 {
166  struct GNUNET_JSON_Specification ret = {
167  .parser = &parse_variable_data,
168  .cleaner = &clean_variable_data,
169  .cls = NULL,
170  .field = name,
171  .ptr = obj,
172  .ptr_size = 0,
173  .size_ptr = size
174  };
175 
176  *obj = NULL;
177  *size = 0;
178  return ret;
179 }
180 
181 
190 static int
192  json_t *root,
193  struct GNUNET_JSON_Specification *spec)
194 {
195  const char *str;
196 
197  (void) cls;
198  str = json_string_value (root);
199  if (NULL == str)
200  {
201  GNUNET_break_op (0);
202  return GNUNET_SYSERR;
203  }
204  *(const char **) spec->ptr = str;
205  return GNUNET_OK;
206 }
207 
208 
210 GNUNET_JSON_spec_string (const char *name,
211  const char **strptr)
212 {
213  struct GNUNET_JSON_Specification ret = {
214  .parser = &parse_string,
215  .cleaner = NULL,
216  .cls = NULL,
217  .field = name,
218  .ptr = strptr,
219  .ptr_size = 0,
220  .size_ptr = NULL
221  };
222 
223  *strptr = NULL;
224  return ret;
225 }
226 
227 
236 static int
238  json_t *root,
239  struct GNUNET_JSON_Specification *spec)
240 {
241  if (! (json_is_object (root) || json_is_array (root)))
242  {
243  GNUNET_break_op (0);
244  return GNUNET_SYSERR;
245  }
246  json_incref (root);
247  *(json_t **) spec->ptr = root;
248  return GNUNET_OK;
249 }
250 
251 
258 static void
260  struct GNUNET_JSON_Specification *spec)
261 {
262  json_t **ptr = (json_t **) spec->ptr;
263 
264  if (NULL != *ptr)
265  {
266  json_decref (*ptr);
267  *ptr = NULL;
268  }
269 }
270 
271 
273 GNUNET_JSON_spec_json (const char *name,
274  json_t **jsonp)
275 {
276  struct GNUNET_JSON_Specification ret = {
277  .parser = &parse_object,
278  .cleaner = &clean_object,
279  .cls = NULL,
280  .field = name,
281  .ptr = jsonp,
282  .ptr_size = 0,
283  .size_ptr = NULL
284  };
285 
286  *jsonp = NULL;
287  return ret;
288 }
289 
290 
299 static int
301  json_t *root,
302  struct GNUNET_JSON_Specification *spec)
303 {
304  bool *b = spec->ptr;
305 
306  if (json_true () == root)
307  {
308  *b = true;
309  return GNUNET_OK;
310  }
311  if (json_false () == root)
312  {
313  *b = false;
314  return GNUNET_OK;
315  }
316  GNUNET_break_op (0);
317  return GNUNET_SYSERR;
318 }
319 
320 
322 GNUNET_JSON_spec_bool (const char *name,
323  bool *b)
324 {
325  struct GNUNET_JSON_Specification ret = {
326  .parser = &parse_bool,
327  .cleaner = NULL,
328  .cls = NULL,
329  .field = name,
330  .ptr = b,
331  .ptr_size = sizeof(bool),
332  .size_ptr = NULL
333  };
334 
335  return ret;
336 }
337 
338 
347 static int
348 parse_u8 (void *cls,
349  json_t *root,
350  struct GNUNET_JSON_Specification *spec)
351 {
352  json_int_t val;
353  uint8_t *up = spec->ptr;
354 
355  if (! json_is_integer (root))
356  {
357  GNUNET_break_op (0);
358  return GNUNET_SYSERR;
359  }
360  val = json_integer_value (root);
361  if ((0 > val) || (val > UINT8_MAX))
362  {
363  GNUNET_break_op (0);
364  return GNUNET_SYSERR;
365  }
366  *up = (uint8_t) val;
367  return GNUNET_OK;
368 }
369 
370 
372 GNUNET_JSON_spec_uint8 (const char *name,
373  uint8_t *u8)
374 {
375  struct GNUNET_JSON_Specification ret = {
376  .parser = &parse_u8,
377  .cleaner = NULL,
378  .cls = NULL,
379  .field = name,
380  .ptr = u8,
381  .ptr_size = sizeof(uint8_t),
382  .size_ptr = NULL
383  };
384 
385  return ret;
386 }
387 
388 
397 static int
398 parse_u16 (void *cls,
399  json_t *root,
400  struct GNUNET_JSON_Specification *spec)
401 {
402  json_int_t val;
403  uint16_t *up = spec->ptr;
404 
405  if (! json_is_integer (root))
406  {
407  GNUNET_break_op (0);
408  return GNUNET_SYSERR;
409  }
410  val = json_integer_value (root);
411  if ((0 > val) || (val > UINT16_MAX))
412  {
413  GNUNET_break_op (0);
414  return GNUNET_SYSERR;
415  }
416  *up = (uint16_t) val;
417  return GNUNET_OK;
418 }
419 
420 
422 GNUNET_JSON_spec_uint16 (const char *name,
423  uint16_t *u16)
424 {
425  struct GNUNET_JSON_Specification ret = {
426  .parser = &parse_u16,
427  .cleaner = NULL,
428  .cls = NULL,
429  .field = name,
430  .ptr = u16,
431  .ptr_size = sizeof(uint16_t),
432  .size_ptr = NULL
433  };
434 
435  return ret;
436 }
437 
438 
447 static int
448 parse_u32 (void *cls,
449  json_t *root,
450  struct GNUNET_JSON_Specification *spec)
451 {
452  json_int_t val;
453  uint32_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 > UINT32_MAX))
462  {
463  GNUNET_break_op (0);
464  return GNUNET_SYSERR;
465  }
466  *up = (uint32_t) val;
467  return GNUNET_OK;
468 }
469 
470 
472 GNUNET_JSON_spec_uint32 (const char *name,
473  uint32_t *u32)
474 {
475  struct GNUNET_JSON_Specification ret = {
476  .parser = &parse_u32,
477  .cleaner = NULL,
478  .cls = NULL,
479  .field = name,
480  .ptr = u32,
481  .ptr_size = sizeof(uint32_t),
482  .size_ptr = NULL
483  };
484 
485  return ret;
486 }
487 
488 
497 static int
498 parse_u64 (void *cls,
499  json_t *root,
500  struct GNUNET_JSON_Specification *spec)
501 {
502  json_int_t val;
503  uint64_t *up = spec->ptr;
504 
505  if (! json_is_integer (root))
506  {
507  GNUNET_break_op (0);
508  return GNUNET_SYSERR;
509  }
510  val = json_integer_value (root);
511  *up = (uint64_t) val;
512  return GNUNET_OK;
513 }
514 
515 
517 GNUNET_JSON_spec_uint64 (const char *name,
518  uint64_t *u64)
519 {
520  struct GNUNET_JSON_Specification ret = {
521  .parser = &parse_u64,
522  .cleaner = NULL,
523  .cls = NULL,
524  .field = name,
525  .ptr = u64,
526  .ptr_size = sizeof(uint64_t),
527  .size_ptr = NULL
528  };
529 
530  return ret;
531 }
532 
533 
542 static int
543 parse_i64 (void *cls,
544  json_t *root,
545  struct GNUNET_JSON_Specification *spec)
546 {
547  json_int_t val;
548  int64_t *up = spec->ptr;
549 
550  if (! json_is_integer (root))
551  {
552  GNUNET_break_op (0);
553  return GNUNET_SYSERR;
554  }
555  val = json_integer_value (root);
556  *up = (int64_t) val;
557  return GNUNET_OK;
558 }
559 
560 
562 GNUNET_JSON_spec_int64 (const char *name,
563  int64_t *i64)
564 {
565  struct GNUNET_JSON_Specification ret = {
566  .parser = &parse_i64,
567  .cleaner = NULL,
568  .cls = NULL,
569  .field = name,
570  .ptr = i64,
571  .ptr_size = sizeof(int64_t),
572  .size_ptr = NULL
573  };
574 
575  return ret;
576 }
577 
578 
579 /* ************ GNUnet-specific parser specifications ******************* */
580 
589 static enum GNUNET_GenericReturnValue
590 parse_timestamp (void *cls,
591  json_t *root,
592  struct GNUNET_JSON_Specification *spec)
593 {
594  struct GNUNET_TIME_Timestamp *ts = spec->ptr;
595  json_t *json_t_s;
596  json_t *json_t_ms;
597  unsigned long long int tval;
598 
599  if (! json_is_object (root))
600  {
601  GNUNET_break_op (0);
602  return GNUNET_SYSERR;
603  }
604  json_t_s = json_object_get (root,
605  "t_s");
606  if (json_is_integer (json_t_s))
607  {
608  tval = json_integer_value (json_t_s);
609  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
611  = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
612  if (ts->abs_time.abs_value_us
613  / GNUNET_TIME_UNIT_SECONDS.rel_value_us
614  != tval)
615  {
616  /* Integer overflow */
617  GNUNET_break_op (0);
618  return GNUNET_SYSERR;
619  }
620  return GNUNET_OK;
621  }
622  if (json_is_string (json_t_s))
623  {
624  const char *val;
625 
626  val = json_string_value (json_t_s);
627  if ((0 == strcasecmp (val,
628  "never")))
629  {
631  return GNUNET_OK;
632  }
633  GNUNET_break_op (0);
634  return GNUNET_SYSERR;
635  }
636  json_t_ms = json_object_get (root,
637  "t_ms");
638  if (json_is_integer (json_t_ms))
639  {
640  tval = json_integer_value (json_t_ms);
641  GNUNET_break_op (0 == tval % 1000);
642  tval -= tval % 1000;
643  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
645  = tval * GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
646  if (ts->abs_time.abs_value_us
647  / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
648  != tval)
649  {
650  /* Integer overflow */
651  GNUNET_break_op (0);
652  return GNUNET_SYSERR;
653  }
654  return GNUNET_OK;
655  }
656  if (json_is_string (json_t_ms))
657  {
658  const char *val;
659 
660  val = json_string_value (json_t_ms);
661  if ((0 == strcasecmp (val,
662  "never")))
663  {
665  return GNUNET_OK;
666  }
667  GNUNET_break_op (0);
668  return GNUNET_SYSERR;
669  }
670  GNUNET_break_op (0);
671  return GNUNET_SYSERR;
672 }
673 
674 
676 GNUNET_JSON_spec_timestamp (const char *name,
677  struct GNUNET_TIME_Timestamp *t)
678 {
679  struct GNUNET_JSON_Specification ret = {
680  .parser = &parse_timestamp,
681  .field = name,
682  .ptr = t,
683  .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
684  };
685 
686  return ret;
687 }
688 
689 
698 static enum GNUNET_GenericReturnValue
699 parse_timestamp_nbo (void *cls,
700  json_t *root,
701  struct GNUNET_JSON_Specification *spec)
702 {
703  struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
704  struct GNUNET_TIME_Timestamp a;
705  struct GNUNET_JSON_Specification ispec;
706 
707  ispec = *spec;
708  ispec.parser = &parse_timestamp;
709  ispec.ptr = &a;
710  if (GNUNET_OK !=
711  parse_timestamp (NULL,
712  root,
713  &ispec))
714  return GNUNET_SYSERR;
715  *ts = GNUNET_TIME_timestamp_hton (a);
716  return GNUNET_OK;
717 }
718 
719 
722  struct GNUNET_TIME_TimestampNBO *at)
723 {
724  struct GNUNET_JSON_Specification ret = {
725  .parser = &parse_timestamp_nbo,
726  .field = name,
727  .ptr = at,
728  .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
729  };
730 
731  return ret;
732 }
733 
734 
743 static enum GNUNET_GenericReturnValue
744 parse_rel_time (void *cls,
745  json_t *root,
746  struct GNUNET_JSON_Specification *spec)
747 {
748  struct GNUNET_TIME_Relative *rel = spec->ptr;
749  json_t *json_d_us;
750  json_t *json_d_ms;
751  unsigned long long int tval;
752 
753  if (! json_is_object (root))
754  {
755  GNUNET_break_op (0);
756  return GNUNET_SYSERR;
757  }
758  json_d_us = json_object_get (root,
759  "d_us");
760  if (json_is_integer (json_d_us))
761  {
762  tval = json_integer_value (json_d_us);
763  if (tval >= (1LLU << 53))
764  {
765  /* value is larger than allowed */
766  GNUNET_break_op (0);
767  return GNUNET_SYSERR;
768  }
769  rel->rel_value_us = tval;
770  return GNUNET_OK;
771  }
772  if (json_is_string (json_d_us))
773  {
774  const char *val;
775 
776  val = json_string_value (json_d_us);
777  if ((0 == strcasecmp (val,
778  "forever")))
779  {
781  return GNUNET_OK;
782  }
783  GNUNET_break_op (0);
784  return GNUNET_SYSERR;
785  }
786 
787  json_d_ms = json_object_get (root,
788  "d_ms");
789  if (json_is_integer (json_d_ms))
790  {
791  tval = json_integer_value (json_d_ms);
794  tval);
795  return GNUNET_OK;
796  }
797  if (json_is_string (json_d_ms))
798  {
799  const char *val;
800 
801  val = json_string_value (json_d_ms);
802  if ((0 == strcasecmp (val,
803  "forever")))
804  {
806  return GNUNET_OK;
807  }
808  GNUNET_break_op (0);
809  return GNUNET_SYSERR;
810  }
811  GNUNET_break_op (0);
812  return GNUNET_SYSERR;
813 }
814 
815 
818  struct GNUNET_TIME_Relative *rt)
819 {
820  struct GNUNET_JSON_Specification ret = {
821  .parser = &parse_rel_time,
822  .field = name,
823  .ptr = rt,
824  .ptr_size = sizeof(struct GNUNET_TIME_Relative)
825  };
826 
827  return ret;
828 }
829 
830 
839 static enum GNUNET_GenericReturnValue
840 parse_rsa_public_key (void *cls,
841  json_t *root,
842  struct GNUNET_JSON_Specification *spec)
843 {
844  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
845  const char *enc;
846  char *buf;
847  size_t len;
848  size_t buf_len;
849 
850  if (NULL == (enc = json_string_value (root)))
851  {
852  GNUNET_break_op (0);
853  return GNUNET_SYSERR;
854  }
855  len = strlen (enc);
856  buf_len = (len * 5) / 8;
857  buf = GNUNET_malloc (buf_len);
858  if (GNUNET_OK !=
860  len,
861  buf,
862  buf_len))
863  {
864  GNUNET_break_op (0);
865  GNUNET_free (buf);
866  return GNUNET_SYSERR;
867  }
868  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
869  buf_len)))
870  {
871  GNUNET_break_op (0);
872  GNUNET_free (buf);
873  return GNUNET_SYSERR;
874  }
875  GNUNET_free (buf);
876  return GNUNET_OK;
877 }
878 
879 
886 static void
888  struct GNUNET_JSON_Specification *spec)
889 {
890  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
891 
892  if (NULL != *pk)
893  {
895  *pk = NULL;
896  }
897 }
898 
899 
903 {
904  struct GNUNET_JSON_Specification ret = {
905  .parser = &parse_rsa_public_key,
906  .cleaner = &clean_rsa_public_key,
907  .field = name,
908  .ptr = pk
909  };
910 
911  *pk = NULL;
912  return ret;
913 }
914 
915 
924 static enum GNUNET_GenericReturnValue
925 parse_rsa_signature (void *cls,
926  json_t *root,
927  struct GNUNET_JSON_Specification *spec)
928 {
929  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
930  size_t size;
931  const char *str;
932  int res;
933  void *buf;
934 
935  str = json_string_value (root);
936  if (NULL == str)
937  {
938  GNUNET_break_op (0);
939  return GNUNET_SYSERR;
940  }
941  size = (strlen (str) * 5) / 8;
942  buf = GNUNET_malloc (size);
944  strlen (str),
945  buf,
946  size);
947  if (GNUNET_OK != res)
948  {
949  GNUNET_free (buf);
950  GNUNET_break_op (0);
951  return GNUNET_SYSERR;
952  }
953  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
954  size)))
955  {
956  GNUNET_break_op (0);
957  GNUNET_free (buf);
958  return GNUNET_SYSERR;
959  }
960  GNUNET_free (buf);
961  return GNUNET_OK;
962 }
963 
964 
971 static void
973  struct GNUNET_JSON_Specification *spec)
974 {
975  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
976 
977  if (NULL != *sig)
978  {
980  *sig = NULL;
981  }
982 }
983 
984 
987  struct GNUNET_CRYPTO_RsaSignature **sig)
988 {
989  struct GNUNET_JSON_Specification ret = {
990  .parser = &parse_rsa_signature,
991  .cleaner = &clean_rsa_signature,
992  .cls = NULL,
993  .field = name,
994  .ptr = sig,
995  .ptr_size = 0,
996  .size_ptr = NULL
997  };
998 
999  *sig = NULL;
1000  return ret;
1001 }
1002 
1003 
1012 static enum GNUNET_GenericReturnValue
1013 parse_boolean (void *cls,
1014  json_t *root,
1015  struct GNUNET_JSON_Specification *spec)
1016 {
1017  int *bp = spec->ptr;
1018 
1019  if (! json_is_boolean (root))
1020  {
1021  GNUNET_break_op (0);
1022  return GNUNET_SYSERR;
1023  }
1024  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1025  return GNUNET_OK;
1026 }
1027 
1028 
1030 GNUNET_JSON_spec_boolean (const char *name,
1031  int *boolean)
1032 {
1033  struct GNUNET_JSON_Specification ret = {
1034  .parser = &parse_boolean,
1035  .cleaner = NULL,
1036  .cls = NULL,
1037  .field = name,
1038  .ptr = boolean,
1039  .ptr_size = sizeof(int),
1040  .size_ptr = NULL
1041  };
1042 
1043  return ret;
1044 }
1045 
1046 
1047 /* 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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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:1038
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:990
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:267
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:422
functions to parse JSON objects into GNUnet objects
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:483
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:90
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
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:348
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:191
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:162
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:85
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:32
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:925
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:259
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:398
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json(const char *name, json_t **jsonp)
JSON object.
Definition: json_helper.c:273
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:887
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:972
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:1030
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:590
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:901
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16)
16-bit integer.
Definition: json_helper.c:422
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:699
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:721
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:472
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:210
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:300
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:237
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64(const char *name, int64_t *i64)
64-bit signed integer.
Definition: json_helper.c:562
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:1013
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:986
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:448
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *t)
Timestamp.
Definition: json_helper.c:676
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
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:498
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:543
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool(const char *name, bool *b)
boolean.
Definition: json_helper.c:322
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:112
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time.
Definition: json_helper.c:817
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8)
8-bit integer.
Definition: json_helper.c:372
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64)
64-bit integer.
Definition: json_helper.c:517
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:744
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:840
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:148
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
The public information of an RSA key pair.
Definition: crypto_rsa.c:52
an RSA signature
Definition: crypto_rsa.c:64
Entry in parser specification for GNUNET_JSON_parse().
void * ptr
Pointer, details specific to the parser.
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.