MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
json_object.c
Go to the documentation of this file.
1 /*
2  * $Id: json_object.c,v 1.17 2006/07/25 03:24:50 mclark Exp $
3  *
4  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5  * Michael Clark <michael@metaparadigm.com>
6  * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the MIT license. See COPYING for details.
10  *
11  */
12 
13 #include "config.h"
14 
15 #include <assert.h>
16 #include <errno.h>
17 #include <limits.h>
18 #include <math.h>
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <stddef.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "debug.h"
26 #include "printbuf.h"
27 #include "linkhash.h"
28 #include "arraylist.h"
29 #include "json_inttypes.h"
30 #include "json_object.h"
31 #include "json_object_private.h"
32 #include "json_util.h"
33 #include "math_compat.h"
34 
35 #if !defined(HAVE_STRDUP) && defined(_MSC_VER)
36  /* MSC has the version as _strdup */
37 # define strdup _strdup
38 #elif !defined(HAVE_STRDUP)
39 # error You do not have strdup on your system.
40 #endif /* HAVE_STRDUP */
41 
42 #if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
43  /* MSC has the version as _snprintf */
44 # define snprintf _snprintf
45 #elif !defined(HAVE_SNPRINTF)
46 # error You do not have snprintf on your system.
47 #endif /* HAVE_SNPRINTF */
48 
49 // Don't define this. It's not thread-safe.
50 /* #define REFCOUNT_DEBUG 1 */
51 
52 const char *json_number_chars = "0123456789.+-eE";
53 const char *json_hex_chars = "0123456789abcdefABCDEF";
54 
55 static void json_object_generic_delete(struct json_object* jso);
56 static struct json_object* json_object_new(enum json_type o_type);
57 
66 
67 
68 /* ref count debugging */
69 
70 #ifdef REFCOUNT_DEBUG
71 
72 static struct lh_table *json_object_table;
73 
74 static void json_object_init(void) __attribute__ ((constructor));
75 static void json_object_init(void) {
76  MC_DEBUG("json_object_init: creating object table\n");
77  json_object_table = lh_kptr_table_new(128, "json_object_table", NULL);
78 }
79 
80 static void json_object_fini(void) __attribute__ ((destructor));
81 static void json_object_fini(void) {
82  struct lh_entry *ent;
83  if(MC_GET_DEBUG()) {
84  if (json_object_table->count) {
85  MC_DEBUG("json_object_fini: %d referenced objects at exit\n",
86  json_object_table->count);
87  lh_foreach(json_object_table, ent) {
88  struct json_object* obj = (struct json_object*)ent->v;
89  MC_DEBUG("\t%s:%p\n", json_type_to_name(obj->o_type), obj);
90  }
91  }
92  }
93  MC_DEBUG("json_object_fini: freeing object table\n");
94  lh_table_free(json_object_table);
95 }
96 #endif /* REFCOUNT_DEBUG */
97 
98 
99 /* string escaping */
100 
101 static int json_escape_str(struct printbuf *pb, char *str, int len)
102 {
103  int pos = 0, start_offset = 0;
104  unsigned char c;
105  while (len--) {
106  c = str[pos];
107  switch(c) {
108  case '\b':
109  case '\n':
110  case '\r':
111  case '\t':
112  case '\f':
113  case '"':
114  case '\\':
115  case '/':
116  if(pos - start_offset > 0)
117  printbuf_memappend(pb, str + start_offset, pos - start_offset);
118  if(c == '\b') printbuf_memappend(pb, "\\b", 2);
119  else if(c == '\n') printbuf_memappend(pb, "\\n", 2);
120  else if(c == '\r') printbuf_memappend(pb, "\\r", 2);
121  else if(c == '\t') printbuf_memappend(pb, "\\t", 2);
122  else if(c == '\f') printbuf_memappend(pb, "\\f", 2);
123  else if(c == '"') printbuf_memappend(pb, "\\\"", 2);
124  else if(c == '\\') printbuf_memappend(pb, "\\\\", 2);
125  else if(c == '/') printbuf_memappend(pb, "\\/", 2);
126  start_offset = ++pos;
127  break;
128  default:
129  if(c < ' ') {
130  if(pos - start_offset > 0)
131  printbuf_memappend(pb, str + start_offset, pos - start_offset);
132  sprintbuf(pb, "\\u00%c%c",
133  json_hex_chars[c >> 4],
134  json_hex_chars[c & 0xf]);
135  start_offset = ++pos;
136  } else pos++;
137  }
138  }
139  if(pos - start_offset > 0)
140  printbuf_memappend(pb, str + start_offset, pos - start_offset);
141  return 0;
142 }
143 
144 
145 /* reference counting */
146 
147 extern struct json_object* json_object_get(struct json_object *jso)
148 {
149  if(jso) {
150  jso->_ref_count++;
151  }
152  return jso;
153 }
154 
155 int json_object_put(struct json_object *jso)
156 {
157  if(jso)
158  {
159  jso->_ref_count--;
160  if(!jso->_ref_count)
161  {
162  if (jso->_user_delete)
163  jso->_user_delete(jso, jso->_userdata);
164  jso->_delete(jso);
165  return 1;
166  }
167  }
168  return 0;
169 }
170 
171 
172 /* generic object construction and destruction parts */
173 
174 static void json_object_generic_delete(struct json_object* jso)
175 {
176 #ifdef REFCOUNT_DEBUG
177  MC_DEBUG("json_object_delete_%s: %p\n",
178  json_type_to_name(jso->o_type), jso);
179  lh_table_delete(json_object_table, jso);
180 #endif /* REFCOUNT_DEBUG */
181  printbuf_free(jso->_pb);
182  free(jso);
183 }
184 
186 {
187  struct json_object *jso;
188 
189  jso = (struct json_object*)calloc(sizeof(struct json_object), 1);
190  if(!jso) return NULL;
191  jso->o_type = o_type;
192  jso->_ref_count = 1;
194 #ifdef REFCOUNT_DEBUG
195  lh_table_insert(json_object_table, jso, jso);
196  MC_DEBUG("json_object_new_%s: %p\n", json_type_to_name(jso->o_type), jso);
197 #endif /* REFCOUNT_DEBUG */
198  return jso;
199 }
200 
201 
202 /* type checking functions */
203 
204 int json_object_is_type(struct json_object *jso, enum json_type type)
205 {
206  if (!jso)
207  return (type == json_type_null);
208  return (jso->o_type == type);
209 }
210 
212 {
213  if (!jso)
214  return json_type_null;
215  return jso->o_type;
216 }
217 
218 /* set a custom conversion to string */
219 
221  json_object_to_json_string_fn to_string_func,
222  void *userdata,
223  json_object_delete_fn *user_delete)
224 {
225  // First, clean up any previously existing user info
226  if (jso->_user_delete)
227  {
228  jso->_user_delete(jso, jso->_userdata);
229  }
230  jso->_userdata = NULL;
231  jso->_user_delete = NULL;
232 
233  if (to_string_func == NULL)
234  {
235  // Reset to the standard serialization function
236  switch(jso->o_type)
237  {
238  case json_type_null:
239  jso->_to_json_string = NULL;
240  break;
241  case json_type_boolean:
243  break;
244  case json_type_double:
246  break;
247  case json_type_int:
249  break;
250  case json_type_object:
252  break;
253  case json_type_array:
255  break;
256  case json_type_string:
258  break;
259  case json_type_extarr:
261  break;
262  case json_type_enum:
264  break;
265  }
266  return;
267  }
268 
269  jso->_to_json_string = to_string_func;
270  jso->_userdata = userdata;
271  jso->_user_delete = user_delete;
272 }
273 
274 
275 /* extended conversion to string */
276 
277 const char* json_object_to_json_string_ext(struct json_object *jso, int flags)
278 {
279  if (!jso)
280  return "null";
281 
282  if ((!jso->_pb) && !(jso->_pb = printbuf_new()))
283  return NULL;
284 
285  printbuf_reset(jso->_pb);
286 
287  if(jso->_to_json_string(jso, jso->_pb, 0, flags) < 0)
288  return NULL;
289 
290  return jso->_pb->buf;
291 }
292 
293 /* backwards-compatible conversion to string */
294 
295 const char* json_object_to_json_string(struct json_object *jso)
296 {
298 }
299 
300 static void indent(struct printbuf *pb, int level, int flags)
301 {
302  if (flags & JSON_C_TO_STRING_PRETTY)
303  {
304  printbuf_memset(pb, -1, ' ', level * 2);
305  }
306 }
307 
308 /* json_object_object */
309 
311  struct printbuf *pb,
312  int level,
313  int flags)
314 {
315  int had_children = 0;
316  struct json_object_iter iter;
317 
318  sprintbuf(pb, "{" /*}*/);
319  if (flags & JSON_C_TO_STRING_PRETTY)
320  sprintbuf(pb, "\n");
321  json_object_object_foreachC(jso, iter)
322  {
323  if (had_children)
324  {
325  sprintbuf(pb, ",");
326  if (flags & JSON_C_TO_STRING_PRETTY)
327  sprintbuf(pb, "\n");
328  }
329  had_children = 1;
330  if (flags & JSON_C_TO_STRING_SPACED)
331  sprintbuf(pb, " ");
332  indent(pb, level+1, flags);
333  sprintbuf(pb, "\"");
334  json_escape_str(pb, iter.key, strlen(iter.key));
335  if (flags & JSON_C_TO_STRING_SPACED)
336  sprintbuf(pb, "\": ");
337  else
338  sprintbuf(pb, "\":");
339  if(iter.val == NULL)
340  sprintbuf(pb, "null");
341  else
342  iter.val->_to_json_string(iter.val, pb, level+1,flags);
343  }
344  if (flags & JSON_C_TO_STRING_PRETTY)
345  {
346  if (had_children)
347  sprintbuf(pb, "\n");
348  indent(pb,level,flags);
349  }
350  if (flags & JSON_C_TO_STRING_SPACED)
351  return sprintbuf(pb, /*{*/ " }");
352  else
353  return sprintbuf(pb, /*{*/ "}");
354 }
355 
356 
357 static void json_object_lh_entry_free(struct lh_entry *ent)
358 {
359  free(ent->k);
360  json_object_put((struct json_object*)ent->v);
361 }
362 
363 static void json_object_object_delete(struct json_object* jso)
364 {
365  lh_table_free(jso->o.c_object);
367 }
368 
370 {
372  if(!jso) return NULL;
377  return jso;
378 }
379 
381 {
382  if(!jso) return NULL;
383  switch(jso->o_type) {
384  case json_type_object:
385  return jso->o.c_object;
386  default:
387  return NULL;
388  }
389 }
390 
391 void json_object_object_add(struct json_object* jso, const char *key,
392  struct json_object *val)
393 {
394  // We lookup the entry and replace the value, rather than just deleting
395  // and re-adding it, so the existing key remains valid.
396  json_object *existing_value = NULL;
397  struct lh_entry *existing_entry;
398  existing_entry = lh_table_lookup_entry(jso->o.c_object, (void*)key);
399  if (!existing_entry)
400  {
401  lh_table_insert(jso->o.c_object, strdup(key), val);
402  return;
403  }
404  existing_value = (json_object *)existing_entry->v;
405  if (existing_value)
406  json_object_put(existing_value);
407  existing_entry->v = val;
408 }
409 
411 {
412  return lh_table_length(jso->o.c_object);
413 }
414 
415 struct json_object* json_object_object_get(struct json_object* jso, const char *key)
416 {
417  struct json_object *result = NULL;
418  json_object_object_get_ex(jso, key, &result);
419  return result;
420 }
421 
422 json_bool json_object_object_get_ex(struct json_object* jso, const char *key, struct json_object **value)
423 {
424  if (value != NULL)
425  *value = NULL;
426 
427  if (NULL == jso)
428  return JSON_C_FALSE;
429 
430  switch(jso->o_type)
431  {
432  case json_type_object:
433  return lh_table_lookup_ex(jso->o.c_object, (void*)key, (void**)value);
434  default:
435  if (value != NULL)
436  *value = NULL;
437  return JSON_C_FALSE;
438  }
439 }
440 
441 void json_object_object_del(struct json_object* jso, const char *key)
442 {
443  lh_table_delete(jso->o.c_object, key);
444 }
445 
446 
447 /* json_object_boolean */
448 
450  struct printbuf *pb,
451  int level,
452  int flags)
453 {
454  if(jso->o.c_boolean) return sprintbuf(pb, "true");
455  else return sprintbuf(pb, "false");
456 }
457 
459 {
461  if(!jso) return NULL;
463  jso->o.c_boolean = b;
464  return jso;
465 }
466 
468 {
469  if(!jso) return JSON_C_FALSE;
470  switch(jso->o_type) {
471  case json_type_boolean:
472  return jso->o.c_boolean;
473  case json_type_int:
474  return (jso->o.c_int64 != 0);
475  case json_type_double:
476  return (jso->o.c_double != 0);
477  case json_type_string:
478  return (jso->o.c_string.len != 0);
479  default:
480  return JSON_C_FALSE;
481  }
482 }
483 
484 
485 /* json_object_int */
486 
488  struct printbuf *pb,
489  int level,
490  int flags)
491 {
492  return sprintbuf(pb, "%"PRId64, jso->o.c_int64);
493 }
494 
496 {
498  if(!jso) return NULL;
500  jso->o.c_int64 = i;
501  return jso;
502 }
503 
504 int32_t json_object_get_int(struct json_object *jso)
505 {
506  int64_t cint64;
507  enum json_type o_type;
508 
509  if(!jso) return 0;
510 
511  o_type = jso->o_type;
512  cint64 = jso->o.c_int64;
513 
514  if (o_type == json_type_string)
515  {
516  /*
517  * Parse strings into 64-bit numbers, then use the
518  * 64-to-32-bit number handling below.
519  */
520  if (json_parse_int64(jso->o.c_string.str, &cint64) != 0)
521  return 0; /* whoops, it didn't work. */
522  o_type = json_type_int;
523  }
524 
525  switch(o_type) {
526  case json_type_int:
527  /* Make sure we return the correct values for out of range numbers. */
528 #ifdef INT32_MIN
529  if (cint64 <= INT32_MIN)
530  return INT32_MIN;
531  else if (cint64 >= INT32_MAX)
532  return INT32_MAX;
533 #else
534  if (cint64 <= INT_MIN)
535  return INT_MIN;
536  else if (cint64 >= INT_MAX)
537  return INT_MAX;
538 #endif
539  else
540  return (int32_t)cint64;
541  case json_type_double:
542  return (int32_t)jso->o.c_double;
543  case json_type_boolean:
544  return jso->o.c_boolean;
545  default:
546  return 0;
547  }
548 }
549 
551 {
553  if(!jso) return NULL;
555  jso->o.c_int64 = i;
556  return jso;
557 }
558 
559 int64_t json_object_get_int64(struct json_object *jso)
560 {
561  int64_t cint;
562 
563  if(!jso) return 0;
564  switch(jso->o_type) {
565  case json_type_int:
566  return jso->o.c_int64;
567  case json_type_double:
568  return (int64_t)jso->o.c_double;
569  case json_type_boolean:
570  return jso->o.c_boolean;
571  case json_type_string:
572  if (json_parse_int64(jso->o.c_string.str, &cint) == 0) return cint;
573  default:
574  return 0;
575  }
576 }
577 
578 
579 /* json_object_double */
580 
582  struct printbuf *pb,
583  int level,
584  int flags)
585 {
586  char buf[128], *p, *q;
587  int size;
588  /* Although JSON RFC does not support
589  NaN or Infinity as numeric values
590  ECMA 262 section 9.8.1 defines
591  how to handle these cases as strings */
592  if(isnan(jso->o.c_double))
593  size = snprintf(buf, sizeof(buf), "NaN");
594  else if(isinf(jso->o.c_double))
595  if(jso->o.c_double > 0)
596  size = snprintf(buf, sizeof(buf), "Infinity");
597  else
598  size = snprintf(buf, sizeof(buf), "-Infinity");
599  else
600  size = snprintf(buf, sizeof(buf), "%.17g", jso->o.c_double);
601 
602  p = strchr(buf, ',');
603  if (p) {
604  *p = '.';
605  } else {
606  p = strchr(buf, '.');
607  }
608  if (p && (flags & JSON_C_TO_STRING_NOZERO)) {
609  /* last useful digit, always keep 1 zero */
610  p++;
611  for (q=p ; *q ; q++) {
612  if (*q!='0') p=q;
613  }
614  /* drop trailing zeroes */
615  *(++p) = 0;
616  size = p-buf;
617  }
618  printbuf_memappend(pb, buf, size);
619  return size;
620 }
621 
623 {
625  if (!jso)
626  return NULL;
628  jso->o.c_double = d;
629  return jso;
630 }
631 
632 struct json_object* json_object_new_double_s(double d, const char *ds)
633 {
634  struct json_object *jso = json_object_new_double(d);
635  if (!jso)
636  return NULL;
637 
639  strdup(ds), json_object_free_userdata);
640  return jso;
641 }
642 
644  struct printbuf *pb, int level, int flags)
645 {
646  int userdata_len = strlen((char*)jso->_userdata);
647  printbuf_memappend(pb, (char*)jso->_userdata, userdata_len);
648  return userdata_len;
649 }
650 
651 void json_object_free_userdata(struct json_object *jso, void *userdata)
652 {
653  free(userdata);
654 }
655 
657 {
658  double cdouble;
659  char *errPtr = NULL;
660 
661  if(!jso) return 0.0;
662  switch(jso->o_type) {
663  case json_type_double:
664  return jso->o.c_double;
665  case json_type_int:
666  return jso->o.c_int64;
667  case json_type_boolean:
668  return jso->o.c_boolean;
669  case json_type_string:
670  errno = 0;
671  cdouble = strtod(jso->o.c_string.str,&errPtr);
672 
673  /* if conversion stopped at the first character, return 0.0 */
674  if (errPtr == jso->o.c_string.str)
675  return 0.0;
676 
677  /*
678  * Check that the conversion terminated on something sensible
679  *
680  * For example, { "pay" : 123AB } would parse as 123.
681  */
682  if (*errPtr != '\0')
683  return 0.0;
684 
685  /*
686  * If strtod encounters a string which would exceed the
687  * capacity of a double, it returns +/- HUGE_VAL and sets
688  * errno to ERANGE. But +/- HUGE_VAL is also a valid result
689  * from a conversion, so we need to check errno.
690  *
691  * Underflow also sets errno to ERANGE, but it returns 0 in
692  * that case, which is what we will return anyway.
693  *
694  * See CERT guideline ERR30-C
695  */
696  if ((HUGE_VAL == cdouble || -HUGE_VAL == cdouble) &&
697  (ERANGE == errno))
698  cdouble = 0.0;
699  return cdouble;
700  default:
701  return 0.0;
702  }
703 }
704 
705 
706 /* json_object_string */
707 
709  struct printbuf *pb,
710  int level,
711  int flags)
712 {
713  if (!(flags & JSON_C_TO_STRING_UNQUOTED))
714  sprintbuf(pb, "\"");
715  json_escape_str(pb, jso->o.c_string.str, jso->o.c_string.len);
716  if (!(flags & JSON_C_TO_STRING_UNQUOTED))
717  sprintbuf(pb, "\"");
718  return 0;
719 }
720 
721 static void json_object_string_delete(struct json_object* jso)
722 {
723  free(jso->o.c_string.str);
725 }
726 
727 struct json_object* json_object_new_string(const char *s)
728 {
730  if(!jso) return NULL;
733  jso->o.c_string.str = strdup(s);
734  jso->o.c_string.len = strlen(s);
735  return jso;
736 }
737 
738 struct json_object* json_object_new_string_len(const char *s, int len)
739 {
741  if(!jso) return NULL;
744  jso->o.c_string.str = (char*)malloc(len + 1);
745  memcpy(jso->o.c_string.str, (void *)s, len);
746  jso->o.c_string.str[len] = '\0';
747  jso->o.c_string.len = len;
748  return jso;
749 }
750 
751 const char* json_object_get_string(struct json_object *jso)
752 {
753  if(!jso) return NULL;
754  switch(jso->o_type) {
755  case json_type_string:
756  return jso->o.c_string.str;
757  default:
758  return json_object_to_json_string(jso);
759  }
760 }
761 
763  if(!jso) return 0;
764  switch(jso->o_type) {
765  case json_type_string:
766  return jso->o.c_string.len;
767  default:
768  return 0;
769  }
770 }
771 
772 
773 /* json_object_array */
774 
776  struct printbuf *pb,
777  int level,
778  int flags)
779 {
780  int had_children = 0;
781  int ii;
782  sprintbuf(pb, "[");
783  if (flags & JSON_C_TO_STRING_PRETTY)
784  sprintbuf(pb, "\n");
785  for(ii=0; ii < json_object_array_length(jso); ii++)
786  {
787  struct json_object *val;
788  if (had_children)
789  {
790  sprintbuf(pb, ",");
791  if (flags & JSON_C_TO_STRING_PRETTY)
792  sprintbuf(pb, "\n");
793  }
794  had_children = 1;
795  if (flags & JSON_C_TO_STRING_SPACED)
796  sprintbuf(pb, " ");
797  indent(pb, level + 1, flags);
798  val = json_object_array_get_idx(jso, ii);
799  if(val == NULL)
800  sprintbuf(pb, "null");
801  else
802  val->_to_json_string(val, pb, level+1, flags);
803  }
804  if (flags & JSON_C_TO_STRING_PRETTY)
805  {
806  if (had_children)
807  sprintbuf(pb, "\n");
808  indent(pb,level,flags);
809  }
810 
811  if (flags & JSON_C_TO_STRING_SPACED)
812  return sprintbuf(pb, " ]");
813  else
814  return sprintbuf(pb, "]");
815 }
816 
817 static void json_object_array_entry_free(void *data)
818 {
819  json_object_put((struct json_object*)data);
820 }
821 
822 static void json_object_array_delete(struct json_object* jso)
823 {
824  array_list_free(jso->o.c_array);
826 }
827 
829 {
831  if(!jso) return NULL;
835  return jso;
836 }
837 
839 {
840  if(!jso) return NULL;
841  switch(jso->o_type) {
842  case json_type_array:
843  return jso->o.c_array;
844  default:
845  return NULL;
846  }
847 }
848 
849 void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *))
850 {
852 }
853 
855 {
856  return array_list_length(jso->o.c_array);
857 }
858 
859 int json_object_array_add(struct json_object *jso,struct json_object *val)
860 {
861  return array_list_add(jso->o.c_array, val);
862 }
863 
864 int json_object_array_put_idx(struct json_object *jso, int idx,
865  struct json_object *val)
866 {
867  return array_list_put_idx(jso->o.c_array, idx, val);
868 }
869 
871  int idx)
872 {
873  return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
874 }
875 
877  struct printbuf *pb,
878  int level,
879  int flags)
880 {
881  int do_vals = !(flags & JSON_C_TO_STRING_NO_EXTARR_VALS);
882  int had_children = 0;
883  int ii;
884  if (do_vals)
885  sprintbuf(pb, "( %d, %d, ",
887  else
888  sprintbuf(pb, "[ %d, %d, ",
890  for (ii = 0; ii < json_object_extarr_ndims(jso)-1; ii++)
891  sprintbuf(pb, "%d, ", json_object_extarr_dim(jso, ii));
892  if (do_vals)
893  sprintbuf(pb, "%d,", json_object_extarr_dim(jso, ii));
894  else
895  sprintbuf(pb, "%d", json_object_extarr_dim(jso, ii));
896  if (flags & JSON_C_TO_STRING_PRETTY)
897  sprintbuf(pb, "\n");
898  for(ii=0; ii < json_object_extarr_nvals(jso) && do_vals; ii++)
899  {
900  struct json_object *val = 0;
901  if (had_children)
902  {
903  sprintbuf(pb, ",");
904  if (flags & JSON_C_TO_STRING_PRETTY)
905  sprintbuf(pb, "\n");
906  }
907  had_children = 1;
908  if (flags & JSON_C_TO_STRING_SPACED)
909  sprintbuf(pb, " ");
910  indent(pb, level + 1, flags);
911  switch (json_object_extarr_type(jso))
912  {
915  {
916  val = NULL;
917  break;
918  }
920  {
921  unsigned char dval = *((unsigned char*)json_object_extarr_data(jso)+ii);
922  val = json_object_new_int(dval);
923  break;
924  }
926  {
927  int dval = *((int*)json_object_extarr_data(jso)+ii);
928  val = json_object_new_int(dval);
929  break;
930  }
932  {
933  int64_t dval = *((int64_t*)json_object_extarr_data(jso)+ii);
934  val = json_object_new_int64(dval);
935  break;
936  }
938  {
939  float dval = *((float*)json_object_extarr_data(jso)+ii);
940  val = json_object_new_double(dval);
941  break;
942  }
944  {
945  double dval = *((double*)json_object_extarr_data(jso)+ii);
946  val = json_object_new_double(dval);
947  break;
948  }
949  }
950  if(val == NULL)
951  sprintbuf(pb, "null");
952  else
953  val->_to_json_string(val, pb, level+1, flags);
954  json_object_put(val);
955  }
956  if (flags & JSON_C_TO_STRING_PRETTY)
957  {
958  if (had_children)
959  sprintbuf(pb, "\n");
960  indent(pb,level,flags);
961  }
962 
963  if (do_vals)
964  {
965  if (flags & JSON_C_TO_STRING_SPACED)
966  return sprintbuf(pb, " )");
967  else
968  return sprintbuf(pb, ")");
969  }
970  else
971  {
972  if (flags & JSON_C_TO_STRING_SPACED)
973  return sprintbuf(pb, " ]");
974  else
975  return sprintbuf(pb, "]");
976  }
977 }
978 
979 static void json_object_extarr_delete(struct json_object* jso)
980 {
981  assert(jso && json_object_is_type(jso, json_type_extarr));
982  array_list_free(jso->o.c_extarr.dims);
984 }
985 
986 #warning MOVE ADDTOGROUP TO TOP OF NON-STATIC FUNCTIONS
987 
1085 struct json_object*
1087  void const *data,
1088  enum json_extarr_type type,
1089  int ndims,
1090  int const *dims
1092 )
1093 {
1094  int i;
1096  if(!jso) return NULL;
1099  jso->o.c_extarr.data = data;
1100  jso->o.c_extarr.type = type;
1102  for (i = 0; i < ndims; i++)
1103  array_list_put_idx(jso->o.c_extarr.dims, i, json_object_new_int(dims[i]));
1104  return jso;
1105 }
1106 
1114 struct json_object*
1116  enum json_extarr_type etype,
1117  int ndims,
1118  int const *dims
1120 )
1121 {
1122  int i, nvals;
1124  if(!jso) return NULL;
1127  jso->o.c_extarr.type = etype;
1129  for (i = 0, nvals = 1; i < ndims; i++)
1130  {
1131  array_list_put_idx(jso->o.c_extarr.dims, i, json_object_new_int(dims[i]));
1132  nvals *= dims[i];
1133  }
1134  jso->o.c_extarr.data = malloc(nvals * json_extarr_type_nbytes(etype));
1135  if (!jso->o.c_extarr.data)
1136  {
1138  return NULL;
1139  }
1140  return jso;
1141 }
1142 
1144 {
1145  if (!jso || !json_object_is_type(jso, json_type_extarr)) return json_extarr_type_null;
1146  return jso->o.c_extarr.type;
1147 }
1148 
1150 {
1151  int i, nvals;
1152  if (!jso || !json_object_is_type(jso, json_type_extarr)) return 0;
1153  for (i = 0, nvals=1; i < json_object_extarr_ndims(jso); i++)
1154  {
1155  struct json_object* dimobj = (struct json_object*) array_list_get_idx(jso->o.c_extarr.dims, i);
1156  nvals *= json_object_get_int(dimobj);
1157  }
1158  return nvals;
1159 }
1160 
1162 {
1163  if (!obj || !json_object_is_type(obj, json_type_extarr)) return 0;
1164 
1165  switch (json_object_extarr_type(obj))
1166  {
1167  case json_extarr_type_null: return(0);
1168  case json_extarr_type_bit01: return(1);
1169  case json_extarr_type_byt08: return(1);
1170  case json_extarr_type_int32: return(4);
1171  case json_extarr_type_int64: return(8);
1172  case json_extarr_type_flt32: return(4);
1173  case json_extarr_type_flt64: return(8);
1174  }
1175 
1176  return 0;
1177 }
1178 
1180 {
1181  if (!obj || !json_object_is_type(obj, json_type_extarr)) return 0;
1182 
1183  /* We include the space necessary to store the type, #dims and
1184  size of each dim */
1185  return json_object_extarr_nvals(obj) *
1187  (json_object_extarr_ndims(obj)+2) * sizeof(int);
1188 }
1189 
1191 {
1192  if (!jso) return 0;
1193  return array_list_length(jso->o.c_extarr.dims);
1194 }
1195 
1196 int json_object_extarr_dim(struct json_object* jso, int dimidx)
1197 {
1198  struct json_object *dimobj;
1199  if (!jso || !json_object_is_type(jso, json_type_extarr)) return 0;
1200  if (dimidx < 0) return 0;
1201  dimobj = (struct json_object *) array_list_get_idx(jso->o.c_extarr.dims, dimidx);
1202  if (!dimobj) return 0;
1203  return json_object_get_int(dimobj);
1204 }
1205 
1206 void const *json_object_extarr_data(struct json_object* jso)
1207 {
1208  if (!jso || !json_object_is_type(jso, json_type_extarr)) return 0;
1209  return jso->o.c_extarr.data;
1210 }
1211 
1212 #define COPYNCAST_EXTARR_DATA(SRCT, SRCP, DSTT, DSTP, NVALS) \
1213 { \
1214  if (!strcmp(#SRCT, #DSTT)) \
1215  memcpy(DSTP, SRCP, NVALS * sizeof(SRCT)); \
1216  else \
1217  { \
1218  int i; \
1219  SRCT *psrc = (SRCT*) json_object_extarr_data(jso); \
1220  DSTT *pdst = (DSTT*) DSTP; \
1221  for (i = 0; i < NVALS; i++) \
1222  pdst[i] = (DSTT) psrc[i]; \
1223  } \
1224 }
1225 
1226 #define JSON_OBJECT_EXTARR_DATA_AS(DSTT,DSTN) \
1227 int json_object_extarr_data_as_ ## DSTN(struct json_object* jso, DSTT **buf) \
1228 { \
1229  json_extarr_type etype; \
1230  int nvals; \
1231  void const *srcp; \
1232  \
1233  if (buf == 0) return 0; \
1234  if (!jso || !json_object_is_type(jso, json_type_extarr)) return 0; \
1235  \
1236  etype = json_object_extarr_type(jso); \
1237  if (etype == json_extarr_type_null) return 0; \
1238  nvals = json_object_extarr_nvals(jso); \
1239  \
1240  if (*buf == 0) \
1241  *buf = (DSTT*) malloc(nvals * sizeof(DSTT)); \
1242  srcp = json_object_extarr_data(jso); \
1243  \
1244  switch (etype) \
1245  { \
1246  case json_extarr_type_byt08: COPYNCAST_EXTARR_DATA(unsigned char, srcp, DSTT, *buf, nvals); break; \
1247  case json_extarr_type_int32: COPYNCAST_EXTARR_DATA(int, srcp, DSTT, *buf, nvals); break; \
1248  case json_extarr_type_int64: COPYNCAST_EXTARR_DATA(int64_t, srcp, DSTT, *buf, nvals); break; \
1249  case json_extarr_type_flt32: COPYNCAST_EXTARR_DATA(float, srcp, DSTT, *buf, nvals); break; \
1250  case json_extarr_type_flt64: COPYNCAST_EXTARR_DATA(double, srcp, DSTT, *buf, nvals); break; \
1251  default: return 0; \
1252  } \
1253  \
1254  return 1; \
1255 }
1256 
1257 JSON_OBJECT_EXTARR_DATA_AS(unsigned char,unsigned_char)
1259 JSON_OBJECT_EXTARR_DATA_AS(int64_t,int64_t)
1260 JSON_OBJECT_EXTARR_DATA_AS(float,float)
1261 JSON_OBJECT_EXTARR_DATA_AS(double,double)
1262 
1267 /* json_object_enum */
1268 static void json_object_enum_delete(struct json_object* jso)
1269 {
1270  assert(jso && json_object_is_type(jso, json_type_enum));
1271  lh_table_free(jso->o.c_enum.choices);
1273 }
1274 
1306 {
1308  if(!jso) return NULL;
1312  NULL, &json_object_lh_entry_free);
1313  jso->o.c_enum.choice = 0;
1314  return jso;
1315 }
1316 
1326 void
1328  struct json_object* jso,
1329  char const *name,
1330  int64_t val,
1331  json_bool selected
1332 )
1333 {
1334  if (!name) return;
1335  if (!jso || !json_object_is_type(jso, json_type_enum)) return;
1336 
1337  if (selected)
1338  jso->o.c_enum.choice = val;
1339  /* We lookup the entry and replace the value, rather than just deleting
1340  and re-adding it, so the existing key remains valid. */
1341  json_object *existing_value = NULL;
1342  struct lh_entry *existing_entry;
1343  existing_entry = lh_table_lookup_entry(jso->o.c_enum.choices, (void*)name);
1344  if (!existing_entry)
1345  {
1346  lh_table_insert(jso->o.c_enum.choices, strdup(name), json_object_new_int(val));
1347  return;
1348  }
1349  existing_value = (json_object *)existing_entry->v;
1350  if (existing_value)
1351  json_object_put(existing_value);
1352  existing_entry->v = json_object_new_int(val);
1353 }
1354 
1363 {
1364  if (!jso || !json_object_is_type(jso, json_type_enum)) return -1;
1365  return lh_table_length(jso->o.c_enum.choices);
1366 }
1367 
1377 char const *json_object_enum_get_idx_name(struct json_object* jso, int idx)
1378 {
1379  int i = 0;
1380  struct lh_entry *ent;
1381  if (!jso || !json_object_is_type(jso, json_type_enum)) return NULL;
1382  lh_foreach(jso->o.c_enum.choices, ent)
1383  {
1384  if (i == idx)
1385  return (char const *) ent->k;
1386  i++;
1387  }
1388  return NULL;
1389 }
1390 
1398 char const *json_object_enum_get_name(struct json_object* jso, int64_t val)
1399 {
1400  struct lh_entry *ent;
1401  if (!jso || !json_object_is_type(jso, json_type_enum)) return NULL;
1402  lh_foreach(jso->o.c_enum.choices, ent)
1403  {
1404  if (json_object_get_int((struct json_object*)ent->v) == val)
1405  return (char const *) ent->k;
1406  }
1407  return NULL;
1408 }
1409 
1410 #warning MAY WANT TO USE -INT_MAX FOR BAD ENUM VALUE
1411 
1420 int64_t json_object_enum_get_idx_val(struct json_object* jso, int idx)
1421 {
1422  int i = 0;
1423  struct lh_entry *ent;
1424  if (!jso || !json_object_is_type(jso, json_type_enum)) return -1;
1425  lh_foreach(jso->o.c_enum.choices, ent)
1426  {
1427  if (i == idx)
1428  return json_object_get_int((struct json_object*)ent->v);
1429  i++;
1430  }
1431  return -1;
1432 }
1433 
1441 int64_t json_object_enum_get_val(struct json_object *jso, char const *name)
1442 {
1443  struct lh_entry *ent;
1444  if (!jso || !json_object_is_type(jso, json_type_enum)) return -1;
1445  lh_foreach(jso->o.c_enum.choices, ent)
1446  {
1447  if (!strcmp((char const *)ent->k, name))
1448  return json_object_get_int((struct json_object*)ent->v);
1449  }
1450  return -1;
1451 }
1452 
1461 {
1462  if (!jso || !json_object_is_type(jso, json_type_enum)) return -1;
1463  return jso->o.c_enum.choice;
1464 }
1465 
1474 {
1475  if (!jso || !json_object_is_type(jso, json_type_enum)) return NULL;
1476  return json_object_enum_get_name(jso, jso->o.c_enum.choice);
1477 }
1478 
1483  struct printbuf *pb,
1484  int level,
1485  int flags)
1486 {
1487  int had_children = 0;
1488  int ii;
1489  sprintbuf(pb, "<");
1490  if (flags & JSON_C_TO_STRING_PRETTY)
1491  sprintbuf(pb, "\n");
1492  for(ii=-1; ii < json_object_enum_length(jso); ii++)
1493  {
1494  struct json_object *val;
1495  if (had_children)
1496  {
1497  sprintbuf(pb, ",");
1498  if (flags & JSON_C_TO_STRING_PRETTY)
1499  sprintbuf(pb, "\n");
1500  }
1501  had_children = 1;
1502  if (flags & JSON_C_TO_STRING_SPACED)
1503  sprintbuf(pb, " ");
1504  indent(pb, level + 1, flags);
1505  if (ii < 0)
1507  else
1509  if(val == NULL)
1510  sprintbuf(pb, "null");
1511  else
1512  val->_to_json_string(val, pb, level+1, flags);
1513  json_object_put(val);
1514  sprintbuf(pb, ":");
1515  if (ii < 0)
1517  else
1519  if(val == NULL)
1520  sprintbuf(pb, "null");
1521  else
1522  val->_to_json_string(val, pb, level+1, flags);
1523  json_object_put(val);
1524 
1525  }
1526  if (flags & JSON_C_TO_STRING_PRETTY)
1527  {
1528  if (had_children)
1529  sprintbuf(pb, "\n");
1530  indent(pb,level,flags);
1531  }
1532 
1533  if (flags & JSON_C_TO_STRING_SPACED)
1534  return sprintbuf(pb, " >");
1535  else
1536  return sprintbuf(pb, ">");
1537 }
1538 
1553 {
1554  if (!bool_obj || !json_object_is_type(bool_obj, json_type_boolean)) return JSON_C_FALSE;
1555  bool_obj->o.c_boolean = val;
1556  return JSON_C_TRUE;
1557 }
1558 
1559 json_bool json_object_set_enum_choice_name(struct json_object *enum_obj, char const *name)
1560 {
1561  struct lh_entry *ent;
1562  if (!enum_obj || !json_object_is_type(enum_obj, json_type_enum)) return JSON_C_FALSE;
1563  lh_foreach(enum_obj->o.c_enum.choices, ent)
1564  {
1565  if (!strcmp((char const *)ent->k, name))
1566  {
1567  enum_obj->o.c_enum.choice = json_object_get_int((struct json_object*)ent->v);
1568  break;
1569  }
1570  }
1571  return JSON_C_TRUE;
1572 }
1573 
1575 {
1576  if (!enum_obj || !json_object_is_type(enum_obj, json_type_enum)) return JSON_C_FALSE;
1577  enum_obj->o.c_enum.choice = val;
1578  return JSON_C_TRUE;
1579 }
1580 
1581 json_bool json_object_set_int(struct json_object *int_obj, int32_t val)
1582 {
1583  if (!int_obj || !json_object_is_type(int_obj, json_type_int)) return JSON_C_FALSE;
1584  int_obj->o.c_int64 = (int64_t) val;
1585  return JSON_C_TRUE;
1586 }
1587 
1588 json_bool json_object_set_int64(struct json_object *int_obj, int64_t val)
1589 {
1590  if (!int_obj || !json_object_is_type(int_obj, json_type_int)) return JSON_C_FALSE;
1591  int_obj->o.c_int64 = val;
1592  return JSON_C_TRUE;
1593 }
1594 
1595 json_bool json_object_set_double(struct json_object *double_obj, double val)
1596 {
1597  if (!double_obj || !json_object_is_type(double_obj, json_type_double)) return JSON_C_FALSE;
1598  double_obj->o.c_double = val;
1599  return JSON_C_TRUE;
1600 }
1601 
1602 json_bool json_object_set_string(struct json_object *string_obj, char const *val)
1603 {
1604  if (!string_obj || !json_object_is_type(string_obj, json_type_string)) return JSON_C_FALSE;
1605  if (string_obj->o.c_string.str) free(string_obj->o.c_string.str);
1606  string_obj->o.c_string.str = strdup(val);
1607  string_obj->o.c_string.len = strlen(val);
1608  return JSON_C_TRUE;
1609 }
1614 /* "apath" methods handle paths with possible array indexes embedded within them
1615  (e.g. "/foo/bar/123/front/567/back") */
1616 static void *json_object_apath_get_leafobj_recurse(struct json_object *src, char *key_path)
1617 {
1618 #warning we need to support . and .. notation here too
1619  int idx;
1620  struct json_object *sub_object = 0;
1621  char *slash_char_p, *next = 0;
1622  int add1;
1623 
1624  if (!src) return 0;
1625  if (!key_path) return src;
1626 
1627  add1 = key_path[0]=='/'?1:0;
1628  slash_char_p = strchr(key_path+add1, '/');
1629  if (slash_char_p)
1630  {
1631  *slash_char_p = '\0';
1632  next = slash_char_p+1;
1633  }
1634  errno = 0;
1635  idx = (int) strtol(key_path+add1, 0, 10);
1636 
1637  if (json_object_is_type(src, json_type_array) && errno == 0 &&
1638  0 <= idx && idx < json_object_array_length(src))
1639  {
1640  if ((sub_object = json_object_array_get_idx(src, idx)) && sub_object)
1641  {
1642  if (next)
1643  return json_object_apath_get_leafobj_recurse(sub_object, next);
1644  else
1645  return sub_object;
1646  }
1647  }
1648 
1649  if (json_object_object_get_ex(src, key_path, &sub_object) && sub_object)
1650  {
1651  if (next)
1652  return json_object_apath_get_leafobj_recurse(sub_object, next);
1653  else
1654  return sub_object;
1655  }
1656 
1657  return 0;
1658 }
1659 
1660 static struct json_object* json_object_apath_get_leafobj(struct json_object *obj, char const *key_path)
1661 {
1662  char *kp = strdup(key_path);
1663  struct json_object *retval = (struct json_object *) json_object_apath_get_leafobj_recurse(obj, kp);
1664  free(kp);
1665  return retval;
1666 }
1667 
1702 json_bool json_object_apath_get_boolean(struct json_object *obj, char const *key_path)
1703 {
1704  struct json_object *leafobj = json_object_apath_get_leafobj(obj, key_path);
1705  if (leafobj)
1706  {
1707  switch (json_object_get_type(leafobj))
1708  {
1709  case json_type_null: return JSON_C_FALSE;
1710  case json_type_boolean: return json_object_get_boolean(leafobj);
1711  case json_type_int: return json_object_get_int(leafobj)!=0?JSON_C_TRUE:JSON_C_FALSE;
1716  case json_type_string:
1717  {
1718  char const *str = json_object_get_string(leafobj);
1719  return (!str || *str=='\0')?JSON_C_FALSE:JSON_C_TRUE;
1720  }
1721  case json_type_extarr:
1722  {
1723  int i, ndims = json_object_extarr_ndims(leafobj);
1724  if (!ndims) return JSON_C_FALSE;
1725  for (i = 0; i < ndims; i++)
1726  if (!json_object_extarr_dim(leafobj, i)) return JSON_C_FALSE;
1728  }
1729  }
1730  }
1731  return JSON_C_FALSE;
1732 }
1733 
1739 int64_t json_object_apath_get_int64(struct json_object *obj, char const *key_path)
1740 {
1741  struct json_object *leafobj = json_object_apath_get_leafobj(obj, key_path);
1742  if (leafobj)
1743  {
1744  switch (json_object_get_type(leafobj))
1745  {
1746  case json_type_null: return 0;
1747  case json_type_boolean: return json_object_get_boolean(leafobj)==JSON_C_TRUE?1:0;
1748  case json_type_int: return json_object_get_int64(leafobj);
1749  case json_type_double: return (int64_t) json_object_get_double(leafobj);
1750  case json_type_array: return json_object_array_length(leafobj);
1751  case json_type_object: return json_object_object_length(leafobj);
1752  case json_type_enum: return json_object_enum_get_choice_val(leafobj);
1753  case json_type_string:
1754  {
1755  char const *str = json_object_get_string(leafobj);
1756  errno = 0;
1757  if (str && *str != '\0')
1758  {
1759  char *ep = 0;
1760  long long val = strtoll(json_object_get_string(leafobj), &ep, 10);
1761  if (errno == 0 && ep != str)
1762  return (int64_t) val;
1763  }
1764  }
1765  case json_type_extarr:
1766  {
1767  int i, ndims = json_object_extarr_ndims(leafobj), n = ndims?1:0;
1768  for (i = 0; i < ndims; i++)
1769  n *= json_object_extarr_dim(leafobj, i);
1770  return n;
1771  }
1772  }
1773  }
1774  return 0;
1775 }
1776 
1782 int json_object_apath_get_int(struct json_object *obj, char const *key_path)
1783 {
1784  int64_t val64 = json_object_apath_get_int64(obj, key_path);
1785  if (INT_MIN <= val64 && val64 <= INT_MAX)
1786  return (int) val64;
1787  else
1788  return 0;
1789 }
1790 
1796 double json_object_apath_get_double(struct json_object *obj, char const *key_path)
1797 {
1798  struct json_object *leafobj = json_object_apath_get_leafobj(obj, key_path);
1799  if (leafobj)
1800  {
1801  switch (json_object_get_type(leafobj))
1802  {
1803  case json_type_null: return 0.0;
1804  case json_type_boolean: return json_object_get_boolean(leafobj)?1.0:0.0;
1805  case json_type_int: return (double) json_object_get_int(leafobj);
1806  case json_type_double: return json_object_get_double(leafobj);
1807  case json_type_array: return (double) json_object_array_length(leafobj);
1808  case json_type_object: return (double) json_object_object_length(leafobj);
1809  case json_type_enum: return (double) json_object_enum_get_choice_val(leafobj);
1810  case json_type_string:
1811  {
1812  char const *str = json_object_get_string(leafobj);
1813  errno = 0;
1814  if (str && *str != '\0')
1815  {
1816  char *ep = 0;
1817  double val = strtod(json_object_get_string(leafobj), &ep);
1818  if (errno == 0 && ep != str)
1819  return val;
1820  }
1821  }
1822  case json_type_extarr:
1823  {
1824  int i, ndims = json_object_extarr_ndims(leafobj), n = ndims?1:0;
1825  for (i = 0; i < ndims; i++)
1826  n *= json_object_extarr_dim(leafobj, i);
1827  return (double) n;
1828  }
1829  }
1830  }
1831  return 0.0;
1832 }
1833 
1834 #define CIRCBUF_SIZE 1024
1835 static int circbuf_idx = 0;
1837 #define CIRCBUF_RET(STR) \
1838 { \
1839  if (circbuf_retval[circbuf_idx] != 0) \
1840  free(circbuf_retval[circbuf_idx]); \
1841  circbuf_retval[circbuf_idx] = strdup(STR); \
1842  retval = circbuf_retval[circbuf_idx]; \
1843  circbuf_idx = (circbuf_idx+1) % CIRCBUF_SIZE; \
1844  return retval; \
1845 }
1846 
1852 char const *json_object_apath_get_string(struct json_object *obj, char const *key_path)
1853 {
1854  char *retval;
1855 
1856  struct json_object *leafobj = json_object_apath_get_leafobj(obj, key_path);
1857  if (leafobj)
1858  {
1860  }
1861  else
1862  {
1863  CIRCBUF_RET("null");
1864  }
1865 }
1866 
1872 struct json_object *json_object_apath_get_object(struct json_object *obj, char const *key_path)
1873 {
1874  struct json_object *leafobj = json_object_apath_get_leafobj(obj, key_path);
1875  if (leafobj) return leafobj;
1876  return 0;
1877 }
1878 
1879 struct json_object *json_object_apath_find_object(struct json_object *root, char const *key_path)
1880 {
1881  struct json_object *foundobj = json_object_apath_get_object(root, key_path);
1882 
1883  /* if we found a matching key_path from root, we're done */
1884  if (foundobj) return foundobj;
1885 
1887  {
1888  struct json_object_iter iter;
1889 
1890  /* Ok, we need to recurse on the members of root */
1891  json_object_object_foreachC(root, iter)
1892  {
1893  foundobj = json_object_apath_find_object(iter.val, key_path);
1894  if (foundobj) return foundobj;
1895  }
1896  }
1897  else if (json_object_is_type(root, json_type_array))
1898  {
1899  int i;
1900  for (i = 0; i < json_object_array_length(root); i++)
1901  {
1902  struct json_object *arrmember = json_object_array_get_idx(root, i);
1903  foundobj = json_object_apath_find_object(arrmember, key_path);
1904  if (foundobj) return foundobj;
1905  }
1906  }
1907 
1908  return 0;
1909 }
1910 
1920 char const *json_paste_apath(
1921  char const *va_args_str,
1922  char const *first,
1923  ...
1924 )
1925 {
1926  static char retbuf[4096];
1927  int nargs = 1, i = 0, n = sizeof(retbuf);
1928  static char tmpstr[32];
1929  int val;
1930  char *str;
1931 
1932  /* count the number of args using commas in va_args_str */
1933  while (va_args_str[i] != '\0')
1934  {
1935  if (va_args_str[i] == ',') nargs++;
1936  i++;
1937  }
1938 
1939  va_list ap;
1940  va_start(ap, first);
1941  nargs--;
1942 
1943  retbuf[0] = '\0';
1944  strncat(retbuf, first, n);
1945  n -= strlen(first);
1946  val = va_arg(ap, int);
1947 
1948  while (nargs > 0)
1949  {
1950  snprintf(tmpstr, sizeof(tmpstr), "%d", val);
1951  tmpstr[sizeof(tmpstr)-1] = '\0';
1952  if (retbuf[sizeof(retbuf)-n-1] != '/')
1953  {
1954  strncat(retbuf, "/", n);
1955  n -= 1;
1956  }
1957  strncat(retbuf, tmpstr, n);
1958  n -= strlen(tmpstr);
1959  str = va_arg(ap, char*);
1960  nargs--;
1961  if (nargs == 0) break;
1962  if (str[0] != '/')
1963  {
1964  strncat(retbuf, "/", n);
1965  n -= 1;
1966  }
1967  strncat(retbuf, str, n);
1968  n -= strlen(str);
1969  val = va_arg(ap, int);
1970  nargs--;
1971  }
1972  va_end(ap);
1973 
1974  return retbuf;
1975 }
1978 static void *json_object_path_get_leafobj_recurse(struct json_object *src, char *key_path, json_type jtype)
1979 {
1980 #warning we need to support . and .. notation here too
1981 
1982  struct json_object *sub_object = 0;
1983  char *slash_char_p;
1984 
1985  if (!src || !key_path) return 0;
1986 
1987  slash_char_p = strchr(key_path,'/');
1988  if (slash_char_p)
1989  {
1990  *slash_char_p = '\0';
1991  if (json_object_object_get_ex(src, key_path, &sub_object))
1992  return json_object_path_get_leafobj_recurse(sub_object, slash_char_p+1, jtype);
1993  }
1994  else
1995  {
1996  if (json_object_object_get_ex(src, key_path, &sub_object))
1997  {
1998  if (jtype == json_type_null)
1999  return sub_object;
2000  else if (json_object_is_type(sub_object, jtype))
2001  return sub_object;
2002  }
2003  }
2004  return 0;
2005 }
2006 
2007 static struct json_object* json_object_path_get_leafobj(struct json_object *obj, char const *key_path, json_type jtype)
2008 {
2009  char *kp = strdup(key_path);
2010  struct json_object *retval = (struct json_object *) json_object_path_get_leafobj_recurse(obj, kp, jtype);
2011  free(kp);
2012  return retval;
2013 }
2014 
2025 json_bool json_object_path_set_boolean(struct json_object *obj, char const *key_path, json_bool val)
2026 {
2027  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_boolean);
2028  if (leafobj) return json_object_set_boolean(leafobj, val);
2029  return JSON_C_FALSE;
2030 }
2031 
2032 json_bool json_object_path_set_enum_choice_val(struct json_object *obj, char const *key_path, int64_t val)
2033 {
2034  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_enum);
2035  if (leafobj) return json_object_set_enum_choice_val(leafobj, val);
2036  return JSON_C_FALSE;
2037 }
2038 
2039 json_bool json_object_path_set_enum_choice_name(struct json_object *obj, char const *key_path, char const *val)
2040 {
2041  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_enum);
2042  if (leafobj) return json_object_set_enum_choice_name(leafobj, val);
2043  return JSON_C_FALSE;
2044 }
2045 
2046 json_bool json_object_path_set_int(struct json_object *obj, char const *key_path, int32_t val)
2047 {
2048  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_int);
2049  if (leafobj) return json_object_set_int(leafobj, val);
2050  return JSON_C_FALSE;
2051 }
2052 
2053 json_bool json_object_path_set_int64(struct json_object *obj, char const *key_path, int64_t val)
2054 {
2055  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_int);
2056  if (leafobj) return json_object_set_int64(leafobj, val);
2057  return JSON_C_FALSE;
2058 }
2059 
2060 json_bool json_object_path_set_double(struct json_object *obj, char const *key_path, double val)
2061 {
2062  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_double);
2063  if (leafobj) return json_object_set_double(leafobj, val);
2064  return JSON_C_FALSE;
2065 }
2066 
2067 json_bool json_object_path_set_string(struct json_object *obj, char const *key_path, char const *val)
2068 {
2069  struct json_object *leafobj = json_object_path_get_leafobj(obj, key_path, json_type_string);
2070  if (leafobj) return json_object_set_string(leafobj, val);
2071  return JSON_C_FALSE;
2072 }
2103 int32_t json_object_path_get_int(struct json_object *src, char const *key_path)
2104 {
2105  int32_t retval = 0;
2106  char *kp = strdup(key_path);
2107  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_int);
2108  free(kp);
2109  if (leafobj) retval = json_object_get_int(leafobj);
2110  return retval;
2111 }
2112 
2118 int64_t json_object_path_get_int64(struct json_object *src, char const *key_path)
2119 {
2120  int64_t retval = 0;
2121  char *kp = strdup(key_path);
2122  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_int);
2123  free(kp);
2124  if (leafobj) retval = json_object_get_int64(leafobj);
2125  return retval;
2126 }
2127 
2140 double json_object_path_get_double(struct json_object *src, char const *key_path)
2141 {
2142  double retval = 0;
2143  char *kp = strdup(key_path);
2144  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_double);
2145  free(kp);
2146  if (leafobj) retval = json_object_get_double(leafobj);
2147  return retval;
2148 }
2149 
2161 json_bool json_object_path_get_boolean(struct json_object *src, char const *key_path)
2162 {
2163  json_bool retval = JSON_C_FALSE;
2164  char *kp = strdup(key_path);
2165  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_boolean);
2166  free(kp);
2167  if (leafobj) retval = json_object_get_boolean(leafobj);
2168  return retval;
2169 }
2170 
2198 char const *json_object_path_get_string(struct json_object *src, char const *key_path)
2199 {
2200  char const *retval = "";
2201  char *kp = strdup(key_path);
2202  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_string);
2203  free(kp);
2204  if (leafobj) retval = json_object_get_string(leafobj);
2205  return retval;
2206 }
2207 
2215 struct json_object *json_object_path_get_array(struct json_object *src, char const *key_path)
2216 {
2217  struct json_object *retval = 0;
2218  char *kp = strdup(key_path);
2219  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_array);
2220  free(kp);
2221  if (leafobj) retval = leafobj;
2222  return retval;
2223 }
2224 
2232 struct json_object *json_object_path_get_object(struct json_object *src, char const *key_path)
2233 {
2234  struct json_object *retval = 0;
2235  char *kp = strdup(key_path);
2236  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_object);
2237  free(kp);
2238  if (leafobj) retval = leafobj;
2239  return retval;
2240 }
2241 
2249 struct json_object *json_object_path_get_extarr(struct json_object *src, char const *key_path)
2250 {
2251  struct json_object *retval = 0;
2252  char *kp = strdup(key_path);
2253  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_extarr);
2254  free(kp);
2255  if (leafobj) retval = leafobj;
2256  return retval;
2257 }
2258 
2265 struct json_object *json_object_path_get_any(struct json_object *src, char const *key_path)
2266 {
2267  struct json_object *retval = 0;
2268  char *kp = strdup(key_path);
2269  struct json_object *leafobj = json_object_path_get_leafobj(src, key_path, json_type_null);
2270  free(kp);
2271  if (leafobj) retval = leafobj;
2272  return retval;
2273 }
2289 {
2290  printbuf_free(jso->_pb);
2291  jso->_pb = 0;
2292 }
2296 {
2297  if (!obj) return 0;
2298  switch (json_object_get_type(obj))
2299  {
2300  case json_type_null: return 0;
2301  case json_type_boolean: return sizeof(json_bool);
2302  case json_type_int: return sizeof(int64_t);
2303  case json_type_double: return sizeof(double);
2304  case json_type_string: return json_object_get_string_len(obj);
2305  case json_type_extarr: return json_object_extarr_nbytes(obj);
2306  case json_type_enum: return json_object_enum_length(obj) * sizeof(int);
2307  case json_type_array:
2308  {
2309  int i;
2310  int64_t retval = 0;
2311  for (i = 0; i < json_object_array_length(obj); i++)
2313  return retval;
2314  }
2315  case json_type_object:
2316  {
2317  int64_t retval = 0;
2318  struct json_object_iter iter;
2319  json_object_object_foreachC(obj, iter)
2320  retval += json_object_object_nbytes(iter.val);
2321  return retval;
2322  }
2323  }
2324  return 0;
2325 }
2326 
int array_list_add(struct array_list *al, void *data)
Definition: arraylist.c:85
int lh_table_insert(struct lh_table *t, void *k, const void *v)
Definition: linkhash.c:493
struct json_object * json_object_new_extarr_alloc(enum json_extarr_type etype, int ndims, int const *dims)
Definition: json_object.c:1115
#define PRId64
Definition: json_inttypes.h:23
#define CIRCBUF_SIZE
Definition: json_object.c:1834
void json_object_enum_add(struct json_object *jso, char const *name, int64_t val, json_bool selected)
Add a name/value pair to an enumeration.
Definition: json_object.c:1327
void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *))
Definition: json_object.c:849
json_object_private_delete_fn * _delete
struct json_object * val
Definition: json_object.h:74
void json_object_object_del(struct json_object *jso, const char *key)
Definition: json_object.c:441
static void indent(struct printbuf *pb, int level, int flags)
Definition: json_object.c:300
struct json_object * json_object_new_string(const char *s)
Definition: json_object.c:727
int array_list_length(struct array_list *al)
Definition: arraylist.c:98
int64_t json_object_enum_get_idx_val(struct json_object *jso, int idx)
Get the value of a specific name/value pair in the enumeration.
Definition: json_object.c:1420
int json_object_extarr_valsize(struct json_object *obj)
Definition: json_object.c:1161
char const * json_object_enum_get_idx_name(struct json_object *jso, int idx)
Get the name of a specific name/value pair in the enumeration.
Definition: json_object.c:1377
static json_object_to_json_string_fn json_object_double_to_json_string
Definition: json_object.c:61
static void * json_object_apath_get_leafobj_recurse(struct json_object *src, char *key_path)
Definition: json_object.c:1616
json_bool json_object_apath_get_boolean(struct json_object *obj, char const *key_path)
Query boolean value at specified path.
Definition: json_object.c:1702
static char * circbuf_retval[CIRCBUF_SIZE]
Definition: json_object.c:1836
int64_t json_object_apath_get_int64(struct json_object *obj, char const *key_path)
Query int64_t value at specified path.
Definition: json_object.c:1739
int json_object_object_length(struct json_object *jso)
Definition: json_object.c:410
struct json_object * json_object_new_object(void)
Definition: json_object.c:369
Definition: linkhash.h:62
struct json_object * json_object_path_get_any(struct json_object *src, char const *key_path)
Get object of any type at specified path.
Definition: json_object.c:2265
#define JSON_C_TO_STRING_NO_EXTARR_VALS
Definition: json_object.h:62
void const * json_object_extarr_data(struct json_object *jso)
Definition: json_object.c:1206
enum json_type json_object_get_type(struct json_object *jso)
Definition: json_object.c:211
struct printbuf * _pb
struct json_object * json_object_path_get_extarr(struct json_object *src, char const *key_path)
Get the extarr object at specified path.
Definition: json_object.c:2249
struct lh_table * json_object_get_object(struct json_object *jso)
Definition: json_object.c:380
union json_object::data o
char const * json_paste_apath(char const *va_args_str, char const *first,...)
Helper method to automatically construct paths from values.
Definition: json_object.c:1920
int json_object_is_type(struct json_object *jso, enum json_type type)
Definition: json_object.c:204
int64_t json_object_enum_get_choice_val(struct json_object *jso)
Get chosen value of an enumeration.
Definition: json_object.c:1460
double json_object_apath_get_double(struct json_object *obj, char const *key_path)
Query double value at specified path.
Definition: json_object.c:1796
json_bool json_object_path_set_enum_choice_name(struct json_object *obj, char const *key_path, char const *val)
Definition: json_object.c:2039
json_bool json_object_object_get_ex(struct json_object *jso, const char *key, struct json_object **value)
Definition: json_object.c:422
int sprintbuf(struct printbuf *p, const char *msg,...)
Definition: printbuf.c:152
void array_list_free(struct array_list *al)
Definition: arraylist.c:44
static json_object_to_json_string_fn json_object_enum_to_json_string
Definition: json_object.c:65
char const * json_object_apath_get_string(struct json_object *obj, char const *key_path)
Query string value at specified path.
Definition: json_object.c:1852
int64_t json_object_object_nbytes(struct json_object *const obj)
Definition: json_object.c:2295
json_bool lh_table_lookup_ex(struct lh_table *t, const void *k, void **v)
Definition: linkhash.c:552
static json_object_to_json_string_fn json_object_int_to_json_string
Definition: json_object.c:60
struct json_object * json_object_new_string_len(const char *s, int len)
Definition: json_object.c:738
json_bool json_object_get_boolean(struct json_object *jso)
Definition: json_object.c:467
#define JSON_C_TO_STRING_UNQUOTED
Definition: json_object.h:60
const char * json_type_to_name(enum json_type o_type)
Definition: json_util.c:308
struct json_object::data::@2 c_enum
static void json_object_generic_delete(struct json_object *jso)
Definition: json_object.c:174
int64_t json_object_extarr_nbytes(struct json_object *obj)
Definition: json_object.c:1179
static void json_object_array_delete(struct json_object *jso)
Definition: json_object.c:822
static int circbuf_idx
Definition: json_object.c:1835
struct lh_table * c_object
#define CIRCBUF_RET(STR)
Definition: json_object.c:1837
struct array_list * array_list_new(array_list_free_fn *free_fn)
Definition: arraylist.c:27
struct json_object * json_object_new_double_s(double d, const char *ds)
Definition: json_object.c:632
json_bool json_object_path_set_int64(struct json_object *obj, char const *key_path, int64_t val)
Definition: json_object.c:2053
static void json_object_enum_delete(struct json_object *jso)
Definition: json_object.c:1268
static void * json_object_path_get_leafobj_recurse(struct json_object *src, char *key_path, json_type jtype)
Definition: json_object.c:1978
static void json_object_object_delete(struct json_object *jso)
Definition: json_object.c:363
const char * json_hex_chars
Definition: json_object.c:53
int json_bool
Definition: json_object.h:80
static void json_object_extarr_delete(struct json_object *jso)
Definition: json_object.c:979
int count
Definition: linkhash.h:93
void json_object_set_serializer(json_object *jso, json_object_to_json_string_fn to_string_func, void *userdata, json_object_delete_fn *user_delete)
Definition: json_object.c:220
struct printbuf * printbuf_new(void)
Definition: printbuf.c:34
struct json_object * json_object_new_int(int32_t i)
Definition: json_object.c:495
void( json_object_delete_fn)(struct json_object *jso, void *userdata)
Definition: json_object.h:94
struct json_object * json_object_object_get(struct json_object *jso, const char *key)
Definition: json_object.c:415
void printbuf_reset(struct printbuf *p)
Definition: printbuf.c:180
static int sort_fn(const void *j1, const void *j2)
Definition: test1.c:10
int json_object_array_add(struct json_object *jso, struct json_object *val)
Definition: json_object.c:859
int64_t json_object_path_get_int64(struct json_object *src, char const *key_path)
Get int64 value for object at specified path.
Definition: json_object.c:2118
void * array_list_get_idx(struct array_list *al, int i)
Definition: arraylist.c:54
int lh_table_length(struct lh_table *t)
Definition: linkhash.c:599
json_extarr_type
Definition: json_object.h:120
int json_object_extarr_dim(struct json_object *jso, int dimidx)
Definition: json_object.c:1196
json_bool json_object_path_set_string(struct json_object *obj, char const *key_path, char const *val)
Definition: json_object.c:2067
static json_object_to_json_string_fn json_object_string_to_json_string
Definition: json_object.c:62
json_bool json_object_path_set_enum_choice_val(struct json_object *obj, char const *key_path, int64_t val)
Definition: json_object.c:2032
static void json_object_string_delete(struct json_object *jso)
Definition: json_object.c:721
int json_object_array_length(struct json_object *jso)
Definition: json_object.c:854
int array_list_put_idx(struct array_list *al, int i, void *data)
Definition: arraylist.c:75
static int json_escape_str(struct printbuf *pb, char *str, int len)
Definition: json_object.c:101
struct json_object * json_object_new_int64(int64_t i)
Definition: json_object.c:550
struct lh_table * lh_kptr_table_new(int size, const char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:454
int json_object_apath_get_int(struct json_object *obj, char const *key_path)
Query int value at specified path.
Definition: json_object.c:1782
enum json_type o_type
struct json_object * json_object_new_array(void)
Definition: json_object.c:828
int json_object_extarr_nvals(struct json_object *jso)
Definition: json_object.c:1149
struct json_object * json_object_new_boolean(json_bool b)
Definition: json_object.c:458
void printbuf_free(struct printbuf *p)
Definition: printbuf.c:186
static json_object_to_json_string_fn json_object_object_to_json_string
Definition: json_object.c:58
struct json_object::data::@1 c_extarr
int json_object_extarr_ndims(struct json_object *jso)
Definition: json_object.c:1190
int64_t json_object_enum_get_val(struct json_object *jso, char const *name)
Get value of name in an enumeration.
Definition: json_object.c:1441
double json_object_path_get_double(struct json_object *src, char const *key_path)
Get a double value for the object at specified path.
Definition: json_object.c:2140
void lh_table_free(struct lh_table *t)
Definition: linkhash.c:480
struct json_object * json_object_path_get_array(struct json_object *src, char const *key_path)
Get the array object at specified path.
Definition: json_object.c:2215
json_bool json_object_path_get_boolean(struct json_object *src, char const *key_path)
Get boolean value for the object at specified path.
Definition: json_object.c:2161
#define JSON_C_TRUE
Definition: json_object.h:65
const char * json_object_get_string(struct json_object *jso)
Definition: json_object.c:751
struct json_object * json_object_new_double(double d)
Definition: json_object.c:622
int( json_object_to_json_string_fn)(struct json_object *jso, struct printbuf *pb, int level, int flags)
Definition: json_object.h:99
char const * json_object_path_get_string(struct json_object *src, char const *key_path)
Get a string value for the object at specified path.
Definition: json_object.c:2198
#define JSON_OBJECT_EXTARR_DATA_AS(DSTT, DSTN)
Definition: json_object.c:1226
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
Definition: printbuf.c:79
double json_object_get_double(struct json_object *jso)
Definition: json_object.c:656
json_object_to_json_string_fn * _to_json_string
int json_object_userdata_to_json_string(struct json_object *jso, struct printbuf *pb, int level, int flags)
Definition: json_object.c:643
static json_object_to_json_string_fn json_object_array_to_json_string
Definition: json_object.c:63
#define JSON_C_TO_STRING_NOZERO
Definition: json_object.h:59
struct json_object * json_object_new_enum(void)
Create a new, empty enumeration object.
Definition: json_object.c:1305
static struct json_object * json_object_path_get_leafobj(struct json_object *obj, char const *key_path, json_type jtype)
Definition: json_object.c:2007
struct array_list * json_object_get_array(struct json_object *jso)
Definition: json_object.c:838
static void json_object_array_entry_free(void *data)
Definition: json_object.c:817
struct json_object * json_object_array_get_idx(struct json_object *jso, int idx)
Definition: json_object.c:870
void json_object_free_userdata(struct json_object *jso, void *userdata)
Definition: json_object.c:651
json_bool json_object_path_set_int(struct json_object *obj, char const *key_path, int32_t val)
Definition: json_object.c:2046
int printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len)
Definition: printbuf.c:91
static struct json_object * json_object_apath_get_leafobj(struct json_object *obj, char const *key_path)
Definition: json_object.c:1660
struct json_object::data::@0 c_string
struct array_list * c_array
json_bool json_object_set_boolean(struct json_object *bool_obj, json_bool val)
Definition: json_object.c:1552
struct json_object * json_object_new_extarr(void const *data, enum json_extarr_type type, int ndims, int const *dims)
Definition: json_object.c:1086
struct json_object * json_object_apath_get_object(struct json_object *obj, char const *key_path)
Query any object at specified path.
Definition: json_object.c:1872
int json_object_array_put_idx(struct json_object *jso, int idx, struct json_object *val)
Definition: json_object.c:864
#define JSON_C_TO_STRING_PRETTY
Definition: json_object.h:55
json_bool json_object_set_double(struct json_object *double_obj, double val)
Definition: json_object.c:1595
struct json_object * json_object_path_get_object(struct json_object *src, char const *key_path)
Get the object at specified path.
Definition: json_object.c:2232
struct json_object * json_object_apath_find_object(struct json_object *root, char const *key_path)
Definition: json_object.c:1879
json_bool json_object_set_int(struct json_object *int_obj, int32_t val)
Definition: json_object.c:1581
struct json_object * json_object_get(struct json_object *jso)
Definition: json_object.c:147
char * buf
Definition: printbuf.h:24
struct lh_table * lh_kchar_table_new(int size, const char *name, lh_entry_free_fn *free_fn)
Definition: linkhash.c:448
int json_object_put(struct json_object *jso)
Definition: json_object.c:155
int64_t json_object_get_int64(struct json_object *jso)
Definition: json_object.c:559
static void json_object_lh_entry_free(struct lh_entry *ent)
Definition: json_object.c:357
#define MC_DEBUG(x,...)
Definition: debug.h:63
static json_object_to_json_string_fn json_object_extarr_to_json_string
Definition: json_object.c:64
int32_t json_object_get_int(struct json_object *jso)
Definition: json_object.c:504
int json_parse_int64(const char *buf, int64_t *retval)
Definition: json_util.c:188
enum json_extarr_type json_object_extarr_type(struct json_object *jso)
Definition: json_object.c:1143
static json_object_to_json_string_fn json_object_boolean_to_json_string
Definition: json_object.c:59
json_bool json_object_set_int64(struct json_object *int_obj, int64_t val)
Definition: json_object.c:1588
#define JSON_C_TO_STRING_SPACED
Definition: json_object.h:46
json_bool json_object_set_enum_choice_val(struct json_object *enum_obj, int64_t val)
Definition: json_object.c:1574
const char * json_object_to_json_string_ext(struct json_object *jso, int flags)
Definition: json_object.c:277
#define lh_foreach(table, entry)
Definition: linkhash.h:159
#define JSON_C_FALSE
Definition: json_object.h:64
int32_t json_object_path_get_int(struct json_object *src, char const *key_path)
Get integer value for object at specified path.
Definition: json_object.c:2103
json_bool json_object_set_string(struct json_object *string_obj, char const *val)
Definition: json_object.c:1602
#define MC_GET_DEBUG()
Definition: debug.h:61
int json_object_get_string_len(struct json_object *jso)
Definition: json_object.c:762
int json_extarr_type_nbytes(enum json_extarr_type o_type)
Definition: json_util.c:356
#define json_object_object_foreachC(obj, iter)
Definition: json_object.h:406
char const * json_object_enum_get_choice_name(struct json_object *jso)
Get chosen name of an enumeration.
Definition: json_object.c:1473
struct lh_entry * lh_table_lookup_entry(struct lh_table *t, const void *k)
Definition: linkhash.c:527
const void * v
Definition: linkhash.h:70
void * k
Definition: linkhash.h:66
const char * json_object_to_json_string(struct json_object *jso)
Definition: json_object.c:295
void array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *))
Definition: arraylist.c:91
json_bool json_object_path_set_boolean(struct json_object *obj, char const *key_path, json_bool val)
Definition: json_object.c:2025
int json_object_enum_length(struct json_object *jso)
Get the length (or size) of an enumeration.
Definition: json_object.c:1362
void json_object_free_printbuf(struct json_object *jso)
Definition: json_object.c:2288
const char * json_number_chars
Definition: json_object.c:52
char const * json_object_enum_get_name(struct json_object *jso, int64_t val)
Get name of value in an enumeration.
Definition: json_object.c:1398
#define JSON_OBJECT_DEF_HASH_ENTRIES
Definition: json_object.h:33
void json_object_object_add(struct json_object *jso, const char *key, struct json_object *val)
Definition: json_object.c:391
json_bool json_object_path_set_double(struct json_object *obj, char const *key_path, double val)
Definition: json_object.c:2060
json_bool json_object_set_enum_choice_name(struct json_object *enum_obj, char const *name)
Definition: json_object.c:1559
int lh_table_delete(struct lh_table *t, const void *k)
Definition: linkhash.c:592
json_type
Definition: json_object.h:107
static struct json_object * json_object_new(enum json_type o_type)
Definition: json_object.c:185
json_object_delete_fn * _user_delete