FreeRDP
json.c
1 
20 #include <math.h>
21 #include <errno.h>
22 
23 #include <winpr/json.h>
24 #include <winpr/assert.h>
25 
26 #if defined(WITH_CJSON)
27 #include <cjson/cJSON.h>
28 #endif
29 #if defined(WITH_JSONC)
30 #include <json-c/json.h>
31 #endif
32 
33 #if defined(WITH_CJSON)
34 #if CJSON_VERSION_MAJOR == 1
35 #if CJSON_VERSION_MINOR <= 7
36 #if CJSON_VERSION_PATCH < 13
37 #define USE_CJSON_COMPAT
38 #endif
39 #endif
40 #endif
41 #endif
42 
43 #if defined(WITH_JSONC)
44 #if JSON_C_MAJOR_VERSION == 0
45 #if JSON_C_MINOR_VERSION < 14
46 static struct json_object* json_object_new_null(void)
47 {
48  return NULL;
49 }
50 #endif
51 #endif
52 #endif
53 
54 #if defined(USE_CJSON_COMPAT)
55 static double cJSON_GetNumberValue(const cJSON* prop)
56 {
57 #ifndef NAN
58 #ifdef _WIN32
59 #define NAN sqrt(-1.0)
60 #define COMPAT_NAN_UNDEF
61 #else
62 #define NAN 0.0 / 0.0
63 #define COMPAT_NAN_UNDEF
64 #endif
65 #endif
66 
67  if (!cJSON_IsNumber(prop))
68  return NAN;
69  char* val = cJSON_GetStringValue(prop);
70  if (!val)
71  return NAN;
72 
73  errno = 0;
74  char* endptr = NULL;
75  double dval = strtod(val, &endptr);
76  if (val == endptr)
77  return NAN;
78  if (endptr != NULL)
79  return NAN;
80  if (errno != 0)
81  return NAN;
82  return dval;
83 
84 #ifdef COMPAT_NAN_UNDEF
85 #undef NAN
86 #endif
87 }
88 
89 static cJSON* cJSON_ParseWithLength(const char* value, size_t buffer_length)
90 {
91  // Check for string '\0' termination.
92  const size_t slen = strnlen(value, buffer_length);
93  if (slen >= buffer_length)
94  {
95  if (value[buffer_length] != '\0')
96  return NULL;
97  }
98  return cJSON_Parse(value);
99 }
100 #endif
101 
102 int WINPR_JSON_version(char* buffer, size_t len)
103 {
104 #if defined(WITH_JSONC)
105  return _snprintf(buffer, len, "json-c %s", json_c_version());
106 #elif defined(WITH_CJSON)
107  return _snprintf(buffer, len, "cJSON %s", cJSON_Version());
108 #else
109  return _snprintf(buffer, len, "JSON support not available");
110 #endif
111 }
112 
113 WINPR_JSON* WINPR_JSON_Parse(const char* value)
114 {
115 #if defined(WITH_JSONC)
116  return json_tokener_parse(value);
117 #elif defined(WITH_CJSON)
118  return cJSON_Parse(value);
119 #else
120  WINPR_UNUSED(value);
121  return NULL;
122 #endif
123 }
124 
125 WINPR_JSON* WINPR_JSON_ParseWithLength(const char* value, size_t buffer_length)
126 {
127 #if defined(WITH_JSONC)
128  WINPR_ASSERT(buffer_length <= INT_MAX);
129  json_tokener* tok = json_tokener_new();
130  if (!tok)
131  return NULL;
132  json_object* obj = json_tokener_parse_ex(tok, value, (int)buffer_length);
133  json_tokener_free(tok);
134  return obj;
135 #elif defined(WITH_CJSON)
136  return cJSON_ParseWithLength(value, buffer_length);
137 #else
138  WINPR_UNUSED(value);
139  WINPR_UNUSED(buffer_length);
140  return NULL;
141 #endif
142 }
143 
144 void WINPR_JSON_Delete(WINPR_JSON* item)
145 {
146 #if defined(WITH_JSONC)
147  json_object_put((json_object*)item);
148 #elif defined(WITH_CJSON)
149  cJSON_Delete((cJSON*)item);
150 #else
151  WINPR_UNUSED(item);
152 #endif
153 }
154 
155 WINPR_JSON* WINPR_JSON_GetArrayItem(const WINPR_JSON* array, size_t index)
156 {
157 #if defined(WITH_JSONC)
158  return json_object_array_get_idx((const json_object*)array, index);
159 #elif defined(WITH_CJSON)
160  WINPR_ASSERT(index <= INT_MAX);
161  return cJSON_GetArrayItem((const cJSON*)array, (INT)index);
162 #else
163  WINPR_UNUSED(array);
164  WINPR_UNUSED(index);
165  return NULL;
166 #endif
167 }
168 
169 size_t WINPR_JSON_GetArraySize(const WINPR_JSON* array)
170 {
171 #if defined(WITH_JSONC)
172  return json_object_array_length((const json_object*)array);
173 #elif defined(WITH_CJSON)
174  const int rc = cJSON_GetArraySize((const cJSON*)array);
175  if (rc <= 0)
176  return 0;
177  return (size_t)rc;
178 #else
179  WINPR_UNUSED(array);
180  return 0;
181 #endif
182 }
183 
184 WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string)
185 {
186 #if defined(WITH_JSONC)
187  return json_object_object_get((const json_object*)object, string);
188 #elif defined(WITH_CJSON)
189  return cJSON_GetObjectItem((const cJSON*)object, string);
190 #else
191  WINPR_UNUSED(object);
192  WINPR_UNUSED(string);
193  return NULL;
194 #endif
195 }
196 
197 WINPR_JSON* WINPR_JSON_GetObjectItemCaseSensitive(const WINPR_JSON* object, const char* string)
198 {
199 #if defined(WITH_JSONC)
200  return json_object_object_get((const json_object*)object, string);
201 #elif defined(WITH_CJSON)
202  return cJSON_GetObjectItemCaseSensitive((const cJSON*)object, string);
203 #else
204  WINPR_UNUSED(object);
205  WINPR_UNUSED(string);
206  return NULL;
207 #endif
208 }
209 
210 BOOL WINPR_JSON_HasObjectItem(const WINPR_JSON* object, const char* string)
211 {
212 #if defined(WITH_JSONC)
213  return json_object_object_get_ex((const json_object*)object, string, NULL);
214 #elif defined(WITH_CJSON)
215  return cJSON_HasObjectItem((const cJSON*)object, string);
216 #else
217  WINPR_UNUSED(object);
218  WINPR_UNUSED(string);
219  return FALSE;
220 #endif
221 }
222 
223 const char* WINPR_JSON_GetErrorPtr(void)
224 {
225 #if defined(WITH_JSONC)
226  return json_util_get_last_err();
227 #elif defined(WITH_CJSON)
228  return cJSON_GetErrorPtr();
229 #else
230  return NULL;
231 #endif
232 }
233 
234 const char* WINPR_JSON_GetStringValue(WINPR_JSON* item)
235 {
236 #if defined(WITH_JSONC)
237  return json_object_get_string((json_object*)item);
238 #elif defined(WITH_CJSON)
239  return cJSON_GetStringValue((cJSON*)item);
240 #else
241  WINPR_UNUSED(item);
242  return NULL;
243 #endif
244 }
245 
246 double WINPR_JSON_GetNumberValue(const WINPR_JSON* item)
247 {
248 #if defined(WITH_JSONC)
249  return json_object_get_double((const json_object*)item);
250 #elif defined(WITH_CJSON)
251  return cJSON_GetNumberValue((const cJSON*)item);
252 #else
253  WINPR_UNUSED(item);
254  return nan("");
255 #endif
256 }
257 
258 BOOL WINPR_JSON_IsInvalid(const WINPR_JSON* item)
259 {
260 #if defined(WITH_JSONC)
261  if (WINPR_JSON_IsArray(item))
262  return FALSE;
263  if (WINPR_JSON_IsObject(item))
264  return FALSE;
265  if (WINPR_JSON_IsNull(item))
266  return FALSE;
267  if (WINPR_JSON_IsNumber(item))
268  return FALSE;
269  if (WINPR_JSON_IsBool(item))
270  return FALSE;
271  if (WINPR_JSON_IsString(item))
272  return FALSE;
273  return TRUE;
274 #elif defined(WITH_CJSON)
275  return cJSON_IsInvalid((const cJSON*)item);
276 #else
277  WINPR_UNUSED(item);
278  return TRUE;
279 #endif
280 }
281 
282 BOOL WINPR_JSON_IsFalse(const WINPR_JSON* item)
283 {
284 #if defined(WITH_JSONC)
285  if (!json_object_is_type((const json_object*)item, json_type_boolean))
286  return FALSE;
287  json_bool val = json_object_get_boolean((const json_object*)item);
288  return val == 0;
289 #elif defined(WITH_CJSON)
290  return cJSON_IsFalse((const cJSON*)item);
291 #else
292  WINPR_UNUSED(item);
293  return FALSE;
294 #endif
295 }
296 
297 BOOL WINPR_JSON_IsTrue(const WINPR_JSON* item)
298 {
299 #if defined(WITH_JSONC)
300  if (!json_object_is_type((const json_object*)item, json_type_boolean))
301  return FALSE;
302  json_bool val = json_object_get_boolean((const json_object*)item);
303  return val != 0;
304 #elif defined(WITH_CJSON)
305  return cJSON_IsTrue((const cJSON*)item);
306 #else
307  WINPR_UNUSED(item);
308  return FALSE;
309 #endif
310 }
311 
312 BOOL WINPR_JSON_IsBool(const WINPR_JSON* item)
313 {
314 #if defined(WITH_JSONC)
315  return json_object_is_type((const json_object*)item, json_type_boolean);
316 #elif defined(WITH_CJSON)
317  return cJSON_IsBool((const cJSON*)item);
318 #else
319  WINPR_UNUSED(item);
320  return FALSE;
321 #endif
322 }
323 
324 BOOL WINPR_JSON_IsNull(const WINPR_JSON* item)
325 {
326 #if defined(WITH_JSONC)
327  return json_object_is_type((const json_object*)item, json_type_null);
328 #elif defined(WITH_CJSON)
329  return cJSON_IsNull((const cJSON*)item);
330 #else
331  WINPR_UNUSED(item);
332  return FALSE;
333 #endif
334 }
335 
336 BOOL WINPR_JSON_IsNumber(const WINPR_JSON* item)
337 {
338 #if defined(WITH_JSONC)
339  return json_object_is_type((const json_object*)item, json_type_int) ||
340  json_object_is_type((const json_object*)item, json_type_double);
341 #elif defined(WITH_CJSON)
342  return cJSON_IsNumber((const cJSON*)item);
343 #else
344  WINPR_UNUSED(item);
345  return FALSE;
346 #endif
347 }
348 
349 BOOL WINPR_JSON_IsString(const WINPR_JSON* item)
350 {
351 #if defined(WITH_JSONC)
352  return json_object_is_type((const json_object*)item, json_type_string);
353 #elif defined(WITH_CJSON)
354  return cJSON_IsString((const cJSON*)item);
355 #else
356  WINPR_UNUSED(item);
357  return FALSE;
358 #endif
359 }
360 
361 BOOL WINPR_JSON_IsArray(const WINPR_JSON* item)
362 {
363 #if defined(WITH_JSONC)
364  return json_object_is_type((const json_object*)item, json_type_array);
365 #elif defined(WITH_CJSON)
366  return cJSON_IsArray((const cJSON*)item);
367 #else
368  WINPR_UNUSED(item);
369  return FALSE;
370 #endif
371 }
372 
373 BOOL WINPR_JSON_IsObject(const WINPR_JSON* item)
374 {
375 #if defined(WITH_JSONC)
376  return json_object_is_type((const json_object*)item, json_type_object);
377 #elif defined(WITH_CJSON)
378  return cJSON_IsObject((const cJSON*)item);
379 #else
380  WINPR_UNUSED(item);
381  return FALSE;
382 #endif
383 }
384 
385 WINPR_JSON* WINPR_JSON_CreateNull(void)
386 {
387 #if defined(WITH_JSONC)
388  return json_object_new_null();
389 #elif defined(WITH_CJSON)
390  return cJSON_CreateNull();
391 #else
392  return NULL;
393 #endif
394 }
395 
396 WINPR_JSON* WINPR_JSON_CreateTrue(void)
397 {
398 #if defined(WITH_JSONC)
399  return json_object_new_boolean(TRUE);
400 #elif defined(WITH_CJSON)
401  return cJSON_CreateTrue();
402 #else
403  return NULL;
404 #endif
405 }
406 
407 WINPR_JSON* WINPR_JSON_CreateFalse(void)
408 {
409 #if defined(WITH_JSONC)
410  return json_object_new_boolean(FALSE);
411 #elif defined(WITH_CJSON)
412  return cJSON_CreateFalse();
413 #else
414  return NULL;
415 #endif
416 }
417 
418 WINPR_JSON* WINPR_JSON_CreateBool(BOOL boolean)
419 {
420 #if defined(WITH_JSONC)
421  return json_object_new_boolean(boolean);
422 #elif defined(WITH_CJSON)
423  return cJSON_CreateBool(boolean);
424 #else
425  WINPR_UNUSED(boolean);
426  return NULL;
427 #endif
428 }
429 
430 WINPR_JSON* WINPR_JSON_CreateNumber(double num)
431 {
432 #if defined(WITH_JSONC)
433  return json_object_new_double(num);
434 #elif defined(WITH_CJSON)
435  return cJSON_CreateNumber(num);
436 #else
437  WINPR_UNUSED(num);
438  return NULL;
439 #endif
440 }
441 
442 WINPR_JSON* WINPR_JSON_CreateString(const char* string)
443 {
444 #if defined(WITH_JSONC)
445  return json_object_new_string(string);
446 #elif defined(WITH_CJSON)
447  return cJSON_CreateString(string);
448 #else
449  WINPR_UNUSED(string);
450  return NULL;
451 #endif
452 }
453 
454 WINPR_JSON* WINPR_JSON_CreateArray(void)
455 {
456 #if defined(WITH_JSONC)
457  return json_object_new_array();
458 #elif defined(WITH_CJSON)
459  return cJSON_CreateArray();
460 #else
461  return NULL;
462 #endif
463 }
464 
465 WINPR_JSON* WINPR_JSON_CreateObject(void)
466 {
467 #if defined(WITH_JSONC)
468  return json_object_new_object();
469 #elif defined(WITH_CJSON)
470  return cJSON_CreateObject();
471 #else
472  return NULL;
473 #endif
474 }
475 
476 WINPR_JSON* WINPR_JSON_AddNullToObject(WINPR_JSON* object, const char* name)
477 {
478 #if defined(WITH_JSONC)
479  struct json_object* obj = json_object_new_null();
480  if (json_object_object_add((json_object*)object, name, obj) != 0)
481  {
482  json_object_put(obj);
483  return NULL;
484  }
485  return obj;
486 #elif defined(WITH_CJSON)
487  return cJSON_AddNullToObject((cJSON*)object, name);
488 #else
489  WINPR_UNUSED(object);
490  WINPR_UNUSED(name);
491  return NULL;
492 #endif
493 }
494 
495 WINPR_JSON* WINPR_JSON_AddTrueToObject(WINPR_JSON* object, const char* name)
496 {
497 #if defined(WITH_JSONC)
498  struct json_object* obj = json_object_new_boolean(TRUE);
499  if (json_object_object_add((json_object*)object, name, obj) != 0)
500  {
501  json_object_put(obj);
502  return NULL;
503  }
504  return obj;
505 #elif defined(WITH_CJSON)
506  return cJSON_AddTrueToObject((cJSON*)object, name);
507 #else
508  WINPR_UNUSED(object);
509  WINPR_UNUSED(name);
510  return NULL;
511 #endif
512 }
513 
514 WINPR_JSON* WINPR_JSON_AddFalseToObject(WINPR_JSON* object, const char* name)
515 {
516 #if defined(WITH_JSONC)
517  struct json_object* obj = json_object_new_boolean(FALSE);
518  if (json_object_object_add((json_object*)object, name, obj) != 0)
519  {
520  json_object_put(obj);
521  return NULL;
522  }
523  return obj;
524 #elif defined(WITH_CJSON)
525  return cJSON_AddFalseToObject((cJSON*)object, name);
526 #else
527  WINPR_UNUSED(object);
528  WINPR_UNUSED(name);
529  return NULL;
530 #endif
531 }
532 
533 WINPR_JSON* WINPR_JSON_AddBoolToObject(WINPR_JSON* object, const char* name, BOOL boolean)
534 {
535 #if defined(WITH_JSONC)
536  struct json_object* obj = json_object_new_boolean(boolean);
537  if (json_object_object_add((json_object*)object, name, obj) != 0)
538  {
539  json_object_put(obj);
540  return NULL;
541  }
542  return obj;
543 #elif defined(WITH_CJSON)
544  return cJSON_AddBoolToObject((cJSON*)object, name, boolean);
545 #else
546  WINPR_UNUSED(object);
547  WINPR_UNUSED(name);
548  WINPR_UNUSED(boolean);
549  return NULL;
550 #endif
551 }
552 
553 WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, double number)
554 {
555 #if defined(WITH_JSONC)
556  struct json_object* obj = json_object_new_double(number);
557  if (json_object_object_add((json_object*)object, name, obj) != 0)
558  {
559  json_object_put(obj);
560  return NULL;
561  }
562  return obj;
563 #elif defined(WITH_CJSON)
564  return cJSON_AddNumberToObject((cJSON*)object, name, number);
565 #else
566  WINPR_UNUSED(object);
567  WINPR_UNUSED(name);
568  WINPR_UNUSED(number);
569  return NULL;
570 #endif
571 }
572 
573 WINPR_JSON* WINPR_JSON_AddStringToObject(WINPR_JSON* object, const char* name, const char* string)
574 {
575 #if defined(WITH_JSONC)
576  struct json_object* obj = json_object_new_string(string);
577  if (json_object_object_add((json_object*)object, name, obj) != 0)
578  {
579  json_object_put(obj);
580  return NULL;
581  }
582  return obj;
583 #elif defined(WITH_CJSON)
584  return cJSON_AddStringToObject((cJSON*)object, name, string);
585 #else
586  WINPR_UNUSED(object);
587  WINPR_UNUSED(name);
588  WINPR_UNUSED(string);
589  return NULL;
590 #endif
591 }
592 
593 WINPR_JSON* WINPR_JSON_AddObjectToObject(WINPR_JSON* object, const char* name)
594 {
595 #if defined(WITH_JSONC)
596  struct json_object* obj = json_object_new_object();
597  if (json_object_object_add((json_object*)object, name, obj) != 0)
598  {
599  json_object_put(obj);
600  return NULL;
601  }
602  return obj;
603 #elif defined(WITH_CJSON)
604  return cJSON_AddObjectToObject((cJSON*)object, name);
605 #else
606  WINPR_UNUSED(object);
607  WINPR_UNUSED(name);
608  return NULL;
609 #endif
610 }
611 
612 BOOL WINPR_JSON_AddItemToArray(WINPR_JSON* array, WINPR_JSON* item)
613 {
614 #if defined(WITH_JSONC)
615  const int rc = json_object_array_add((json_object*)array, (json_object*)item);
616  if (rc != 0)
617  return FALSE;
618  return TRUE;
619 #elif defined(WITH_CJSON)
620  return cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
621 #else
622  WINPR_UNUSED(array);
623  WINPR_UNUSED(item);
624  return FALSE;
625 #endif
626 }
627 
628 WINPR_JSON* WINPR_JSON_AddArrayToObject(WINPR_JSON* object, const char* name)
629 {
630 #if defined(WITH_JSONC)
631  struct json_object* obj = json_object_new_array();
632  if (json_object_object_add((json_object*)object, name, obj) != 0)
633  {
634  json_object_put(obj);
635  return NULL;
636  }
637  return obj;
638 #elif defined(WITH_CJSON)
639  return cJSON_AddArrayToObject((cJSON*)object, name);
640 #else
641  WINPR_UNUSED(object);
642  WINPR_UNUSED(name);
643  return NULL;
644 #endif
645 }
646 
647 char* WINPR_JSON_Print(WINPR_JSON* item)
648 {
649 #if defined(WITH_JSONC)
650  const char* str = json_object_to_json_string_ext((json_object*)item, JSON_C_TO_STRING_PRETTY);
651  if (!str)
652  return NULL;
653  return _strdup(str);
654 #elif defined(WITH_CJSON)
655  return cJSON_Print((const cJSON*)item);
656 #else
657  WINPR_UNUSED(item);
658  return NULL;
659 #endif
660 }
661 
662 char* WINPR_JSON_PrintUnformatted(WINPR_JSON* item)
663 {
664 #if defined(WITH_JSONC)
665  const char* str = json_object_to_json_string_ext((json_object*)item, JSON_C_TO_STRING_PLAIN);
666  if (!str)
667  return NULL;
668  return _strdup(str);
669 #elif defined(WITH_CJSON)
670  return cJSON_PrintUnformatted((const cJSON*)item);
671 #else
672  WINPR_UNUSED(item);
673  return NULL;
674 #endif
675 }
BOOL WINPR_JSON_HasObjectItem(const WINPR_JSON *object, const char *string)
Check if JSON has an object matching the name.
Definition: json.c:210
WINPR_JSON * WINPR_JSON_ParseWithLength(const char *value, size_t buffer_length)
Parse a JSON string.
Definition: json.c:125
WINPR_JSON * WINPR_JSON_AddFalseToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddFalseToObject.
Definition: json.c:514
WINPR_JSON * WINPR_JSON_AddObjectToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddObjectToObject.
Definition: json.c:593
WINPR_JSON * WINPR_JSON_AddStringToObject(WINPR_JSON *object, const char *name, const char *string)
WINPR_JSON_AddStringToObject.
Definition: json.c:573
BOOL WINPR_JSON_IsNull(const WINPR_JSON *item)
Check if JSON item is Null.
Definition: json.c:324
BOOL WINPR_JSON_IsString(const WINPR_JSON *item)
Check if JSON item is of type String.
Definition: json.c:349
WINPR_JSON * WINPR_JSON_AddTrueToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddTrueToObject.
Definition: json.c:495
BOOL WINPR_JSON_AddItemToArray(WINPR_JSON *array, WINPR_JSON *item)
Add an item to an existing array.
Definition: json.c:612
WINPR_JSON * WINPR_JSON_AddNumberToObject(WINPR_JSON *object, const char *name, double number)
WINPR_JSON_AddNumberToObject.
Definition: json.c:553
BOOL WINPR_JSON_IsBool(const WINPR_JSON *item)
Check if JSON item is of type BOOL.
Definition: json.c:312
double WINPR_JSON_GetNumberValue(const WINPR_JSON *item)
Return the Number value of a JSON item.
Definition: json.c:246
int WINPR_JSON_version(char *buffer, size_t len)
Get the library version string.
Definition: json.c:102
WINPR_JSON * WINPR_JSON_Parse(const char *value)
Parse a '\0' terminated JSON string.
Definition: json.c:113
char * WINPR_JSON_Print(WINPR_JSON *item)
Serialize a JSON instance to string for minimal size without formatting see WINPR_JSON_PrintUnformatt...
Definition: json.c:647
WINPR_JSON * WINPR_JSON_CreateNumber(double num)
WINPR_JSON_CreateNumber.
Definition: json.c:430
BOOL WINPR_JSON_IsNumber(const WINPR_JSON *item)
Check if JSON item is of type Number.
Definition: json.c:336
WINPR_JSON * WINPR_JSON_GetObjectItemCaseSensitive(const WINPR_JSON *object, const char *string)
Same as WINPR_JSON_GetObjectItem but with case insensitive matching.
Definition: json.c:197
char * WINPR_JSON_PrintUnformatted(WINPR_JSON *item)
Serialize a JSON instance to string without formatting for human readable formatted output see WINPR_...
Definition: json.c:662
WINPR_JSON * WINPR_JSON_CreateArray(void)
WINPR_JSON_CreateArray.
Definition: json.c:454
WINPR_JSON * WINPR_JSON_CreateNull(void)
WINPR_JSON_CreateNull.
Definition: json.c:385
WINPR_JSON * WINPR_JSON_CreateFalse(void)
WINPR_JSON_CreateFalse.
Definition: json.c:407
WINPR_JSON * WINPR_JSON_AddArrayToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddArrayToObject.
Definition: json.c:628
WINPR_JSON * WINPR_JSON_AddBoolToObject(WINPR_JSON *object, const char *name, BOOL boolean)
WINPR_JSON_AddBoolToObject.
Definition: json.c:533
WINPR_JSON * WINPR_JSON_AddNullToObject(WINPR_JSON *object, const char *name)
WINPR_JSON_AddNullToObject.
Definition: json.c:476
BOOL WINPR_JSON_IsObject(const WINPR_JSON *item)
Check if JSON item is of type Object.
Definition: json.c:373
WINPR_JSON * WINPR_JSON_GetArrayItem(const WINPR_JSON *array, size_t index)
Return a pointer to an item in the array.
Definition: json.c:155
BOOL WINPR_JSON_IsInvalid(const WINPR_JSON *item)
Check if JSON item is valid.
Definition: json.c:258
const char * WINPR_JSON_GetErrorPtr(void)
Return an error string.
Definition: json.c:223
WINPR_JSON * WINPR_JSON_CreateTrue(void)
WINPR_JSON_CreateTrue.
Definition: json.c:396
BOOL WINPR_JSON_IsFalse(const WINPR_JSON *item)
Check if JSON item is BOOL value False.
Definition: json.c:282
void WINPR_JSON_Delete(WINPR_JSON *item)
Delete a WinPR JSON wrapper object.
Definition: json.c:144
WINPR_JSON * WINPR_JSON_GetObjectItem(const WINPR_JSON *object, const char *string)
Return a pointer to an JSON object item.
Definition: json.c:184
WINPR_JSON * WINPR_JSON_CreateObject(void)
WINPR_JSON_CreateObject.
Definition: json.c:465
size_t WINPR_JSON_GetArraySize(const WINPR_JSON *array)
Get the number of arrayitems from an array.
Definition: json.c:169
WINPR_JSON * WINPR_JSON_CreateString(const char *string)
WINPR_JSON_CreateString.
Definition: json.c:442
BOOL WINPR_JSON_IsArray(const WINPR_JSON *item)
Check if JSON item is of type Array.
Definition: json.c:361
const char * WINPR_JSON_GetStringValue(WINPR_JSON *item)
Return the String value of a JSON item.
Definition: json.c:234
WINPR_JSON * WINPR_JSON_CreateBool(BOOL boolean)
WINPR_JSON_CreateBool.
Definition: json.c:418
BOOL WINPR_JSON_IsTrue(const WINPR_JSON *item)
Check if JSON item is BOOL value True.
Definition: json.c:297