NCBI C++ ToolKit
parson.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2 Parson ( http://kgabis.github.com/parson/ )
3 Copyright (c) 2012 - 2016 Krzysztof Gabis
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 #ifdef _MSC_VER
23 #ifndef _CRT_SECURE_NO_WARNINGS
24 #define _CRT_SECURE_NO_WARNINGS
25 #endif /* _CRT_SECURE_NO_WARNINGS */
26 #endif /* _MSC_VER */
27 
28 #include "parson.h"
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <math.h>
35 
36 #define STARTING_CAPACITY 15
37 #define ARRAY_MAX_CAPACITY 122880 /* 15*(2^13) */
38 #define OBJECT_MAX_CAPACITY 960 /* 15*(2^6) */
39 #define MAX_NESTING 19
40 #define DOUBLE_SERIALIZATION_FORMAT "%f"
41 
42 #define SIZEOF_TOKEN(a) (sizeof(a) - 1)
43 #define SKIP_CHAR(str) ((*str)++)
44 #define SKIP_WHITESPACES(str) while (isspace((unsigned char)(**str))) { SKIP_CHAR(str); }
45 #define MAX(a, b) ((a) > (b) ? (a) : (b))
46 
47 #undef malloc
48 #undef free
49 
52 
53 #define IS_CONT(b) (((unsigned char)(b) & 0xC0) == 0x80) /* is utf-8 continuation byte */
54 
55 /* Type definitions */
56 typedef union x_json_value_value {
57  char *string;
58  double number;
61  int boolean;
62  int null;
64 
68 };
69 
71  char **names;
73  size_t count;
74  size_t capacity;
75 };
76 
79  size_t count;
80  size_t capacity;
81 };
82 
83 /* Various */
84 static char * read_file(const char *filename);
85 static void remove_comments(char *string, const char *start_token, const char *end_token);
86 static char * parson_strndup(const char *string, size_t n);
87 static char * parson_strdup(const char *string);
88 static int is_utf16_hex(const unsigned char *string);
89 static int num_bytes_in_utf8_sequence(unsigned char c);
90 static int verify_utf8_sequence(const unsigned char *string, int *len);
91 static int is_valid_utf8(const char *string, size_t string_len);
92 static int is_decimal(const char *string, size_t length);
93 
94 /* JSON Object */
95 static x_JSON_Object * x_json_object_init(void);
96 static x_JSON_Status x_json_object_add(x_JSON_Object *object, const char *name, x_JSON_Value *value);
97 static x_JSON_Status x_json_object_resize(x_JSON_Object *object, size_t new_capacity);
98 static x_JSON_Value * x_json_object_nget_value(const x_JSON_Object *object, const char *name, size_t n);
99 static void x_json_object_free(x_JSON_Object *object);
100 
101 /* JSON Array */
102 static x_JSON_Array * x_json_array_init(void);
104 static x_JSON_Status x_json_array_resize(x_JSON_Array *array, size_t new_capacity);
105 static void x_json_array_free(x_JSON_Array *array);
106 
107 /* JSON Value */
108 static x_JSON_Value * x_json_value_init_string_no_copy(char *string);
109 
110 /* Parser */
111 static void skip_quotes(const char **string);
112 static int parse_utf_16(const char **unprocessed, char **processed);
113 static char * process_string(const char *input, size_t len);
114 static char * get_quoted_string(const char **string);
115 static x_JSON_Value * parse_object_value(const char **string, size_t nesting);
116 static x_JSON_Value * parse_array_value(const char **string, size_t nesting);
117 static x_JSON_Value * parse_string_value(const char **string);
118 static x_JSON_Value * parse_boolean_value(const char **string);
119 static x_JSON_Value * parse_number_value(const char **string);
120 static x_JSON_Value * parse_null_value(const char **string);
121 static x_JSON_Value * parse_value(const char **string, size_t nesting);
122 
123 /* Serialization */
124 static int x_json_serialize_to_buffer_r(const x_JSON_Value *value, char *buf, int level, int is_pretty, char *num_buf);
125 static int x_json_serialize_string(const char *string, char *buf);
126 static int append_indent(char *buf, int level);
127 static int append_string(char *buf, const char *string);
128 
129 /* Various */
130 static char * parson_strndup(const char *string, size_t n) {
131  char *output_string = (char*)parson_malloc(n + 1);
132  if (!output_string)
133  return NULL;
134  output_string[n] = '\0';
135  strncpy(output_string, string, n);
136  return output_string;
137 }
138 
139 static char * parson_strdup(const char *string) {
140  return parson_strndup(string, strlen(string));
141 }
142 
143 static int is_utf16_hex(const unsigned char *s) {
144  return isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) && isxdigit(s[3]);
145 }
146 
147 static int num_bytes_in_utf8_sequence(unsigned char c) {
148  if (c == 0xC0 || c == 0xC1 || c > 0xF4 || IS_CONT(c)) {
149  return 0;
150  } else if ((c & 0x80) == 0) { /* 0xxxxxxx */
151  return 1;
152  } else if ((c & 0xE0) == 0xC0) { /* 110xxxxx */
153  return 2;
154  } else if ((c & 0xF0) == 0xE0) { /* 1110xxxx */
155  return 3;
156  } else if ((c & 0xF8) == 0xF0) { /* 11110xxx */
157  return 4;
158  }
159  return 0; /* won't happen */
160 }
161 
162 static int verify_utf8_sequence(const unsigned char *string, int *len) {
163  unsigned int cp = 0;
164  *len = num_bytes_in_utf8_sequence(string[0]);
165 
166  if (*len == 1) {
167  cp = string[0];
168  } else if (*len == 2 && IS_CONT(string[1])) {
169  cp = string[0] & 0x1F;
170  cp = (cp << 6) | (string[1] & 0x3F);
171  } else if (*len == 3 && IS_CONT(string[1]) && IS_CONT(string[2])) {
172  cp = ((unsigned char)string[0]) & 0xF;
173  cp = (cp << 6) | (string[1] & 0x3F);
174  cp = (cp << 6) | (string[2] & 0x3F);
175  } else if (*len == 4 && IS_CONT(string[1]) && IS_CONT(string[2]) && IS_CONT(string[3])) {
176  cp = string[0] & 0x7;
177  cp = (cp << 6) | (string[1] & 0x3F);
178  cp = (cp << 6) | (string[2] & 0x3F);
179  cp = (cp << 6) | (string[3] & 0x3F);
180  } else {
181  return 0;
182  }
183 
184  /* overlong encodings */
185  if ((cp < 0x80 && *len > 1) ||
186  (cp < 0x800 && *len > 2) ||
187  (cp < 0x10000 && *len > 3)) {
188  return 0;
189  }
190 
191  /* invalid unicode */
192  if (cp > 0x10FFFF) {
193  return 0;
194  }
195 
196  /* surrogate halves */
197  if (cp >= 0xD800 && cp <= 0xDFFF) {
198  return 0;
199  }
200 
201  return 1;
202 }
203 
204 static int is_valid_utf8(const char *string, size_t string_len) {
205  int len = 0;
206  const char *string_end = string + string_len;
207  while (string < string_end) {
208  if (!verify_utf8_sequence((const unsigned char*)string, &len)) {
209  return 0;
210  }
211  string += len;
212  }
213  return 1;
214 }
215 
216 static int is_decimal(const char *string, size_t length) {
217  if (length > 1 && string[0] == '0' && string[1] != '.')
218  return 0;
219  if (length > 2 && !strncmp(string, "-0", 2) && string[2] != '.')
220  return 0;
221  while (length--)
222  if (strchr("xX", string[length]))
223  return 0;
224  return 1;
225 }
226 
227 static char * read_file(const char * filename) {
228  FILE *fp = fopen(filename, "r");
229  size_t file_size;
230  long pos;
231  char *file_contents;
232  if (!fp)
233  return NULL;
234  fseek(fp, 0L, SEEK_END);
235  pos = ftell(fp);
236  if (pos < 0) {
237  fclose(fp);
238  return NULL;
239  }
240  file_size = pos;
241  rewind(fp);
242  file_contents = (char*)parson_malloc(sizeof(char) * (file_size + 1));
243  if (!file_contents) {
244  fclose(fp);
245  return NULL;
246  }
247  if (fread(file_contents, file_size, 1, fp) < 1) {
248  if (ferror(fp)) {
249  fclose(fp);
250  parson_free(file_contents);
251  return NULL;
252  }
253  }
254  fclose(fp);
255  file_contents[file_size] = '\0';
256  return file_contents;
257 }
258 
259 static void remove_comments(char *string, const char *start_token, const char *end_token) {
260  int in_string = 0, escaped = 0;
261  size_t i;
262  char *ptr = NULL, current_char;
263  size_t start_token_len = strlen(start_token);
264  size_t end_token_len = strlen(end_token);
265  if (start_token_len == 0 || end_token_len == 0)
266  return;
267  while ((current_char = *string) != '\0') {
268  if (current_char == '\\' && !escaped) {
269  escaped = 1;
270  string++;
271  continue;
272  } else if (current_char == '\"' && !escaped) {
273  in_string = !in_string;
274  } else if (!in_string && strncmp(string, start_token, start_token_len) == 0) {
275  for(i = 0; i < start_token_len; i++)
276  string[i] = ' ';
277  string = string + start_token_len;
278  ptr = strstr(string, end_token);
279  if (!ptr)
280  return;
281  for (i = 0; i < (ptr - string) + end_token_len; i++)
282  string[i] = ' ';
283  string = ptr + end_token_len - 1;
284  }
285  escaped = 0;
286  string++;
287  }
288 }
289 
290 /* JSON Object */
293  if (!new_obj)
294  return NULL;
295  new_obj->names = (char**)NULL;
296  new_obj->values = (x_JSON_Value**)NULL;
297  new_obj->capacity = 0;
298  new_obj->count = 0;
299  return new_obj;
300 }
301 
302 static x_JSON_Status x_json_object_add(x_JSON_Object *object, const char *name, x_JSON_Value *value) {
303  size_t index = 0;
304  if (object == NULL || name == NULL || value == NULL) {
305  return JSONFailure;
306  }
307  if (x_json_object_get_value(object, name) != NULL) {
308  return JSONFailure;
309  }
310  if (object->count >= object->capacity) {
311  size_t new_capacity = MAX(object->capacity * 2, STARTING_CAPACITY);
312  if (new_capacity > OBJECT_MAX_CAPACITY)
313  return JSONFailure;
314  if (x_json_object_resize(object, new_capacity) == JSONFailure)
315  return JSONFailure;
316  }
317  index = object->count;
318  object->names[index] = parson_strdup(name);
319  if (object->names[index] == NULL)
320  return JSONFailure;
321  object->values[index] = value;
322  object->count++;
323  return JSONSuccess;
324 }
325 
326 static x_JSON_Status x_json_object_resize(x_JSON_Object *object, size_t new_capacity) {
327  char **temp_names = NULL;
328  x_JSON_Value **temp_values = NULL;
329 
330  if ((object->names == NULL && object->values != NULL) ||
331  (object->names != NULL && object->values == NULL) ||
332  new_capacity == 0) {
333  return JSONFailure; /* Shouldn't happen */
334  }
335 
336  temp_names = (char**)parson_malloc(new_capacity * sizeof(char*));
337  if (temp_names == NULL)
338  return JSONFailure;
339 
340  temp_values = (x_JSON_Value**)parson_malloc(new_capacity * sizeof(x_JSON_Value*));
341  if (temp_values == NULL) {
342  parson_free(temp_names);
343  return JSONFailure;
344  }
345 
346  if (object->names != NULL && object->values != NULL && object->count > 0) {
347  memcpy(temp_names, object->names, object->count * sizeof(char*));
348  memcpy(temp_values, object->values, object->count * sizeof(x_JSON_Value*));
349  }
350  parson_free(object->names);
351  parson_free(object->values);
352  object->names = temp_names;
353  object->values = temp_values;
354  object->capacity = new_capacity;
355  return JSONSuccess;
356 }
357 
358 static x_JSON_Value * x_json_object_nget_value(const x_JSON_Object *object, const char *name, size_t n) {
359  size_t i, name_length;
360  for (i = 0; i < x_json_object_get_count(object); i++) {
361  name_length = strlen(object->names[i]);
362  if (name_length != n)
363  continue;
364  if (strncmp(object->names[i], name, n) == 0)
365  return object->values[i];
366  }
367  return NULL;
368 }
369 
370 static void x_json_object_free(x_JSON_Object *object) {
371  while(object->count--) {
372  parson_free(object->names[object->count]);
373  x_json_value_free(object->values[object->count]);
374  }
375  parson_free(object->names);
376  parson_free(object->values);
377  parson_free(object);
378 }
379 
380 /* JSON Array */
382  x_JSON_Array *new_array = (x_JSON_Array*)parson_malloc(sizeof(x_JSON_Array));
383  if (!new_array)
384  return NULL;
385  new_array->items = (x_JSON_Value**)NULL;
386  new_array->capacity = 0;
387  new_array->count = 0;
388  return new_array;
389 }
390 
392  if (array->count >= array->capacity) {
393  size_t new_capacity = MAX(array->capacity * 2, STARTING_CAPACITY);
394  if (new_capacity > ARRAY_MAX_CAPACITY)
395  return JSONFailure;
396  if (x_json_array_resize(array, new_capacity) == JSONFailure)
397  return JSONFailure;
398  }
399  array->items[array->count] = value;
400  array->count++;
401  return JSONSuccess;
402 }
403 
404 static x_JSON_Status x_json_array_resize(x_JSON_Array *array, size_t new_capacity) {
405  x_JSON_Value **new_items = NULL;
406  if (new_capacity == 0) {
407  return JSONFailure;
408  }
409  new_items = (x_JSON_Value**)parson_malloc(new_capacity * sizeof(x_JSON_Value*));
410  if (new_items == NULL) {
411  return JSONFailure;
412  }
413  if (array->items != NULL && array->count > 0) {
414  memcpy(new_items, array->items, array->count * sizeof(x_JSON_Value*));
415  }
416  parson_free(array->items);
417  array->items = new_items;
418  array->capacity = new_capacity;
419  return JSONSuccess;
420 }
421 
423  while (array->count--)
424  x_json_value_free(array->items[array->count]);
425  parson_free(array->items);
427 }
428 
429 /* JSON Value */
431  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
432  if (!new_value)
433  return NULL;
434  new_value->type = JSONString;
435  new_value->value.string = string;
436  return new_value;
437 }
438 
439 /* Parser */
440 static void skip_quotes(const char **string) {
441  SKIP_CHAR(string);
442  while (**string != '\"') {
443  if (**string == '\0')
444  return;
445  if (**string == '\\') {
446  SKIP_CHAR(string);
447  if (**string == '\0')
448  return;
449  }
450  SKIP_CHAR(string);
451  }
452  SKIP_CHAR(string);
453 }
454 
455 static int parse_utf_16(const char **unprocessed, char **processed) {
456  unsigned int cp, lead, trail;
457  char *processed_ptr = *processed;
458  const char *unprocessed_ptr = *unprocessed;
459  unprocessed_ptr++; /* skips u */
460  if (!is_utf16_hex((const unsigned char*)unprocessed_ptr) || sscanf(unprocessed_ptr, "%4x", &cp) == EOF)
461  return JSONFailure;
462  if (cp < 0x80) {
463  *processed_ptr = cp; /* 0xxxxxxx */
464  } else if (cp < 0x800) {
465  *processed_ptr++ = ((cp >> 6) & 0x1F) | 0xC0; /* 110xxxxx */
466  *processed_ptr = ((cp ) & 0x3F) | 0x80; /* 10xxxxxx */
467  } else if (cp < 0xD800 || cp > 0xDFFF) {
468  *processed_ptr++ = ((cp >> 12) & 0x0F) | 0xE0; /* 1110xxxx */
469  *processed_ptr++ = ((cp >> 6) & 0x3F) | 0x80; /* 10xxxxxx */
470  *processed_ptr = ((cp ) & 0x3F) | 0x80; /* 10xxxxxx */
471  } else if (cp >= 0xD800 && cp <= 0xDBFF) { /* lead surrogate (0xD800..0xDBFF) */
472  lead = cp;
473  unprocessed_ptr += 4; /* should always be within the buffer, otherwise previous sscanf would fail */
474  if (*unprocessed_ptr++ != '\\' || *unprocessed_ptr++ != 'u' || /* starts with \u? */
475  !is_utf16_hex((const unsigned char*)unprocessed_ptr) ||
476  sscanf(unprocessed_ptr, "%4x", &trail) == EOF ||
477  trail < 0xDC00 || trail > 0xDFFF) { /* valid trail surrogate? (0xDC00..0xDFFF) */
478  return JSONFailure;
479  }
480  cp = ((((lead-0xD800)&0x3FF)<<10)|((trail-0xDC00)&0x3FF))+0x010000;
481  *processed_ptr++ = (((cp >> 18) & 0x07) | 0xF0); /* 11110xxx */
482  *processed_ptr++ = (((cp >> 12) & 0x3F) | 0x80); /* 10xxxxxx */
483  *processed_ptr++ = (((cp >> 6) & 0x3F) | 0x80); /* 10xxxxxx */
484  *processed_ptr = (((cp ) & 0x3F) | 0x80); /* 10xxxxxx */
485  } else { /* trail surrogate before lead surrogate */
486  return JSONFailure;
487  }
488  unprocessed_ptr += 3;
489  *processed = processed_ptr;
490  *unprocessed = unprocessed_ptr;
491  return JSONSuccess;
492 }
493 
494 
495 /* Copies and processes passed string up to supplied length.
496 Example: "\u006Corem ipsum" -> lorem ipsum */
497 static char* process_string(const char *input, size_t len) {
498  const char *input_ptr = input;
499  size_t initial_size = (len + 1) * sizeof(char);
500  size_t final_size = 0;
501  char *output = (char*)parson_malloc(initial_size);
502  char *output_ptr = output;
503  char *resized_output = NULL;
504  while ((*input_ptr != '\0') && (size_t)(input_ptr - input) < len) {
505  if (*input_ptr == '\\') {
506  input_ptr++;
507  switch (*input_ptr) {
508  case '\"': *output_ptr = '\"'; break;
509  case '\\': *output_ptr = '\\'; break;
510  case '/': *output_ptr = '/'; break;
511  case 'b': *output_ptr = '\b'; break;
512  case 'f': *output_ptr = '\f'; break;
513  case 'n': *output_ptr = '\n'; break;
514  case 'r': *output_ptr = '\r'; break;
515  case 't': *output_ptr = '\t'; break;
516  case 'u':
517  if (parse_utf_16(&input_ptr, &output_ptr) == JSONFailure)
518  goto error;
519  break;
520  default:
521  goto error;
522  }
523  } else if ((unsigned char)*input_ptr < 0x20) {
524  goto error; /* 0x00-0x19 are invalid characters for json string (http://www.ietf.org/rfc/rfc4627.txt) */
525  } else {
526  *output_ptr = *input_ptr;
527  }
528  output_ptr++;
529  input_ptr++;
530  }
531  *output_ptr = '\0';
532  /* resize to new length */
533  final_size = (size_t)(output_ptr-output) + 1;
534  resized_output = (char*)parson_malloc(final_size);
535  if (resized_output == NULL)
536  goto error;
537  memcpy(resized_output, output, final_size);
539  return resized_output;
540 error:
542  return NULL;
543 }
544 
545 /* Return processed contents of a string between quotes and
546  skips passed argument to a matching quote. */
547 static char * get_quoted_string(const char **string) {
548  const char *string_start = *string;
549  size_t string_len = 0;
550  skip_quotes(string);
551  string_len = *string - string_start - 2; /* length without quotes */
552  return process_string(string_start + 1, string_len);
553 }
554 
555 static x_JSON_Value * parse_value(const char **string, size_t nesting) {
556  if (nesting > MAX_NESTING)
557  return NULL;
558  SKIP_WHITESPACES(string);
559  switch (**string) {
560  case '{':
561  return parse_object_value(string, nesting + 1);
562  case '[':
563  return parse_array_value(string, nesting + 1);
564  case '\"':
565  return parse_string_value(string);
566  case 'f': case 't':
567  return parse_boolean_value(string);
568  case '-':
569  case '0': case '1': case '2': case '3': case '4':
570  case '5': case '6': case '7': case '8': case '9':
571  return parse_number_value(string);
572  case 'n':
573  return parse_null_value(string);
574  default:
575  return NULL;
576  }
577 }
578 
579 static x_JSON_Value * parse_object_value(const char **string, size_t nesting) {
580  x_JSON_Value *output_value = x_json_value_init_object(), *new_value = NULL;
581  x_JSON_Object *output_object = x_json_value_get_object(output_value);
582  char *new_key = NULL;
583  if (output_value == NULL)
584  return NULL;
585  SKIP_CHAR(string);
586  SKIP_WHITESPACES(string);
587  if (**string == '}') { /* empty object */
588  SKIP_CHAR(string);
589  return output_value;
590  }
591  while (**string != '\0') {
592  new_key = get_quoted_string(string);
593  SKIP_WHITESPACES(string);
594  if (new_key == NULL || **string != ':') {
595  x_json_value_free(output_value);
596  return NULL;
597  }
598  SKIP_CHAR(string);
599  new_value = parse_value(string, nesting);
600  if (new_value == NULL) {
601  parson_free(new_key);
602  x_json_value_free(output_value);
603  return NULL;
604  }
605  if(x_json_object_add(output_object, new_key, new_value) == JSONFailure) {
606  parson_free(new_key);
607  parson_free(new_value);
608  x_json_value_free(output_value);
609  return NULL;
610  }
611  parson_free(new_key);
612  SKIP_WHITESPACES(string);
613  if (**string != ',')
614  break;
615  SKIP_CHAR(string);
616  SKIP_WHITESPACES(string);
617  }
618  SKIP_WHITESPACES(string);
619  if (**string != '}' || /* Trim object after parsing is over */
620  x_json_object_resize(output_object, x_json_object_get_count(output_object)) == JSONFailure) {
621  x_json_value_free(output_value);
622  return NULL;
623  }
624  SKIP_CHAR(string);
625  return output_value;
626 }
627 
628 static x_JSON_Value * parse_array_value(const char **string, size_t nesting) {
629  x_JSON_Value *output_value = x_json_value_init_array(), *new_array_value = NULL;
630  x_JSON_Array *output_array = x_json_value_get_array(output_value);
631  if (!output_value)
632  return NULL;
633  SKIP_CHAR(string);
634  SKIP_WHITESPACES(string);
635  if (**string == ']') { /* empty array */
636  SKIP_CHAR(string);
637  return output_value;
638  }
639  while (**string != '\0') {
640  new_array_value = parse_value(string, nesting);
641  if (!new_array_value) {
642  x_json_value_free(output_value);
643  return NULL;
644  }
645  if(x_json_array_add(output_array, new_array_value) == JSONFailure) {
646  parson_free(new_array_value);
647  x_json_value_free(output_value);
648  return NULL;
649  }
650  SKIP_WHITESPACES(string);
651  if (**string != ',')
652  break;
653  SKIP_CHAR(string);
654  SKIP_WHITESPACES(string);
655  }
656  SKIP_WHITESPACES(string);
657  if (**string != ']' || /* Trim array after parsing is over */
658  x_json_array_resize(output_array, x_json_array_get_count(output_array)) == JSONFailure) {
659  x_json_value_free(output_value);
660  return NULL;
661  }
662  SKIP_CHAR(string);
663  return output_value;
664 }
665 
666 static x_JSON_Value * parse_string_value(const char **string) {
668  char *new_string = get_quoted_string(string);
669  if (new_string == NULL)
670  return NULL;
672  if (value == NULL) {
673  parson_free(new_string);
674  return NULL;
675  }
676  return value;
677 }
678 
679 static x_JSON_Value * parse_boolean_value(const char **string) {
680  size_t true_token_size = SIZEOF_TOKEN("true");
681  size_t false_token_size = SIZEOF_TOKEN("false");
682  if (strncmp("true", *string, true_token_size) == 0) {
683  *string += true_token_size;
684  return x_json_value_init_boolean(1);
685  } else if (strncmp("false", *string, false_token_size) == 0) {
686  *string += false_token_size;
687  return x_json_value_init_boolean(0);
688  }
689  return NULL;
690 }
691 
692 static x_JSON_Value * parse_number_value(const char **string) {
693  char *end;
694  double number = strtod(*string, &end);
695  x_JSON_Value *output_value;
696  if (is_decimal(*string, end - *string)) {
697  *string = end;
698  output_value = x_json_value_init_number(number);
699  } else {
700  output_value = NULL;
701  }
702  return output_value;
703 }
704 
705 static x_JSON_Value * parse_null_value(const char **string) {
706  size_t token_size = SIZEOF_TOKEN("null");
707  if (strncmp("null", *string, token_size) == 0) {
708  *string += token_size;
709  return x_json_value_init_null();
710  }
711  return NULL;
712 }
713 
714 /* Serialization */
715 #define APPEND_STRING(str) do { written = append_string(buf, (str));\
716  if (written < 0) { return -1; }\
717  if (buf != NULL) { buf += written; }\
718  written_total += written; } while(0)
719 
720 #define APPEND_INDENT(level) do { written = append_indent(buf, (level));\
721  if (written < 0) { return -1; }\
722  if (buf != NULL) { buf += written; }\
723  written_total += written; } while(0)
724 
725 static int x_json_serialize_to_buffer_r(const x_JSON_Value *value, char *buf, int level, int is_pretty, char *num_buf)
726 {
727  const char *key = NULL, *string = NULL;
728  x_JSON_Value *temp_value = NULL;
730  x_JSON_Object *object = NULL;
731  size_t i = 0, count = 0;
732  double num = 0.0;
733  int written = -1, written_total = 0;
734 
735  switch (x_json_value_get_type(value)) {
736  case JSONArray:
738  count = x_json_array_get_count(array);
739  APPEND_STRING("[");
740  if (count > 0 && is_pretty)
741  APPEND_STRING("\n");
742  for (i = 0; i < count; i++) {
743  if (is_pretty)
744  APPEND_INDENT(level+1);
745  temp_value = x_json_array_get_value(array, i);
746  written = x_json_serialize_to_buffer_r(temp_value, buf, level+1, is_pretty, num_buf);
747  if (written < 0)
748  return -1;
749  if (buf != NULL)
750  buf += written;
751  written_total += written;
752  if (i < (count - 1))
753  APPEND_STRING(",");
754  if (is_pretty)
755  APPEND_STRING("\n");
756  }
757  if (count > 0 && is_pretty)
758  APPEND_INDENT(level);
759  APPEND_STRING("]");
760  return written_total;
761  case JSONObject:
762  object = x_json_value_get_object(value);
763  count = x_json_object_get_count(object);
764  APPEND_STRING("{");
765  if (count > 0 && is_pretty)
766  APPEND_STRING("\n");
767  for (i = 0; i < count; i++) {
768  key = x_json_object_get_name(object, i);
769  if (is_pretty)
770  APPEND_INDENT(level+1);
771  written = x_json_serialize_string(key, buf);
772  if (written < 0)
773  return -1;
774  if (buf != NULL)
775  buf += written;
776  written_total += written;
777  APPEND_STRING(":");
778  if (is_pretty)
779  APPEND_STRING(" ");
780  temp_value = x_json_object_get_value(object, key);
781  written = x_json_serialize_to_buffer_r(temp_value, buf, level+1, is_pretty, num_buf);
782  if (written < 0)
783  return -1;
784  if (buf != NULL)
785  buf += written;
786  written_total += written;
787  if (i < (count - 1))
788  APPEND_STRING(",");
789  if (is_pretty)
790  APPEND_STRING("\n");
791  }
792  if (count > 0 && is_pretty)
793  APPEND_INDENT(level);
794  APPEND_STRING("}");
795  return written_total;
796  case JSONString:
797  string = x_json_value_get_string(value);
798  written = x_json_serialize_string(string, buf);
799  if (written < 0)
800  return -1;
801  if (buf != NULL)
802  buf += written;
803  written_total += written;
804  return written_total;
805  case JSONBoolean:
807  APPEND_STRING("true");
808  else
809  APPEND_STRING("false");
810  return written_total;
811  case JSONNumber:
813  if (buf != NULL)
814  num_buf = buf;
815  if (num == ((double)(int)num)) /* check if num is integer */
816  written = sprintf(num_buf, "%d", (int)num);
817  else
818  written = sprintf(num_buf, DOUBLE_SERIALIZATION_FORMAT, num);
819  if (written < 0)
820  return -1;
821  if (buf != NULL)
822  buf += written;
823  written_total += written;
824  return written_total;
825  case JSONNull:
826  APPEND_STRING("null");
827  return written_total;
828  case JSONError:
829  return -1;
830  default:
831  return -1;
832  }
833 }
834 
835 static int x_json_serialize_string(const char *string, char *buf) {
836  size_t i = 0, len = strlen(string);
837  char c = '\0';
838  int written = -1, written_total = 0;
839  APPEND_STRING("\"");
840  for (i = 0; i < len; i++) {
841  c = string[i];
842  switch (c) {
843  case '\"': APPEND_STRING("\\\""); break;
844  case '\\': APPEND_STRING("\\\\"); break;
845  case '/': APPEND_STRING("\\/"); break; /* to make json embeddable in xml\/html */
846  case '\b': APPEND_STRING("\\b"); break;
847  case '\f': APPEND_STRING("\\f"); break;
848  case '\n': APPEND_STRING("\\n"); break;
849  case '\r': APPEND_STRING("\\r"); break;
850  case '\t': APPEND_STRING("\\t"); break;
851  default:
852  if (buf != NULL) {
853  buf[0] = c;
854  buf += 1;
855  }
856  written_total += 1;
857  break;
858  }
859  }
860  APPEND_STRING("\"");
861  return written_total;
862 }
863 
864 static int append_indent(char *buf, int level) {
865  int i;
866  int written = -1, written_total = 0;
867  for (i = 0; i < level; i++) {
868  APPEND_STRING(" ");
869  }
870  return written_total;
871 }
872 
873 static int append_string(char *buf, const char *string) {
874  if (buf == NULL) {
875  return (int)strlen(string);
876  }
877  return sprintf(buf, "%s", string);
878 }
879 
880 #undef APPEND_STRING
881 #undef APPEND_INDENT
882 
883 /* Parser API */
884 x_JSON_Value * x_json_parse_file(const char *filename) {
885  char *file_contents = read_file(filename);
886  x_JSON_Value *output_value = NULL;
887  if (file_contents == NULL)
888  return NULL;
889  output_value = x_json_parse_string(file_contents);
890  parson_free(file_contents);
891  return output_value;
892 }
893 
895  char *file_contents = read_file(filename);
896  x_JSON_Value *output_value = NULL;
897  if (file_contents == NULL)
898  return NULL;
899  output_value = x_json_parse_string_with_comments(file_contents);
900  parson_free(file_contents);
901  return output_value;
902 }
903 
904 x_JSON_Value * x_json_parse_string(const char *string) {
905  if (string == NULL)
906  return NULL;
907  return parse_value((const char**)&string, 0);
908 }
909 
912  char *string_mutable_copy = NULL, *string_mutable_copy_ptr = NULL;
913  string_mutable_copy = parson_strdup(string);
914  if (string_mutable_copy == NULL)
915  return NULL;
916  remove_comments(string_mutable_copy, "/*", "*/");
917  remove_comments(string_mutable_copy, "//", "\n");
918  string_mutable_copy_ptr = string_mutable_copy;
919  result = parse_value((const char**)&string_mutable_copy_ptr, 0);
920  parson_free(string_mutable_copy);
921  return result;
922 }
923 
924 /* JSON Object API */
925 
926 x_JSON_Value * x_json_object_get_value(const x_JSON_Object *object, const char *name) {
927  if (object == NULL || name == NULL)
928  return NULL;
929  return x_json_object_nget_value(object, name, strlen(name));
930 }
931 
932 const char * x_json_object_get_string(const x_JSON_Object *object, const char *name) {
933  return x_json_value_get_string(x_json_object_get_value(object, name));
934 }
935 
936 double x_json_object_get_number(const x_JSON_Object *object, const char *name) {
937  return x_json_value_get_number(x_json_object_get_value(object, name));
938 }
939 
940 x_JSON_Object * x_json_object_get_object(const x_JSON_Object *object, const char *name) {
941  return x_json_value_get_object(x_json_object_get_value(object, name));
942 }
943 
944 x_JSON_Array * x_json_object_get_array(const x_JSON_Object *object, const char *name) {
945  return x_json_value_get_array(x_json_object_get_value(object, name));
946 }
947 
948 int x_json_object_get_boolean(const x_JSON_Object *object, const char *name) {
950 }
951 
952 x_JSON_Value * x_json_object_dotget_value(const x_JSON_Object *object, const char *name) {
953  const char *dot_position = strchr(name, '.');
954  if (!dot_position)
955  return x_json_object_get_value(object, name);
956  object = x_json_value_get_object(x_json_object_nget_value(object, name, dot_position - name));
957  return x_json_object_dotget_value(object, dot_position + 1);
958 }
959 
960 const char * x_json_object_dotget_string(const x_JSON_Object *object, const char *name) {
962 }
963 
964 double x_json_object_dotget_number(const x_JSON_Object *object, const char *name) {
966 }
967 
968 x_JSON_Object * x_json_object_dotget_object(const x_JSON_Object *object, const char *name) {
970 }
971 
972 x_JSON_Array * x_json_object_dotget_array(const x_JSON_Object *object, const char *name) {
974 }
975 
976 int x_json_object_dotget_boolean(const x_JSON_Object *object, const char *name) {
978 }
979 
980 size_t x_json_object_get_count(const x_JSON_Object *object) {
981  return object ? object->count : 0;
982 }
983 
984 const char * x_json_object_get_name(const x_JSON_Object *object, size_t index) {
985  if (object == NULL || index >= x_json_object_get_count(object))
986  return NULL;
987  return object->names[index];
988 }
989 
990 x_JSON_Value * x_json_object_get_value_at(const x_JSON_Object *object, size_t index) {
991  if (object == NULL || index >= x_json_object_get_count(object))
992  return NULL;
993  return object->values[index];
994 }
995 
996 int x_json_object_has_value (const x_JSON_Object *object, const char *name) {
997  return x_json_object_get_value(object, name) != NULL;
998 }
999 
1001  x_JSON_Value *val = x_json_object_get_value(object, name);
1002  return val != NULL && x_json_value_get_type(val) == type;
1003 }
1004 
1005 int x_json_object_dothas_value (const x_JSON_Object *object, const char *name) {
1006  return x_json_object_dotget_value(object, name) != NULL;
1007 }
1008 
1010  x_JSON_Value *val = x_json_object_dotget_value(object, name);
1011  return val != NULL && x_json_value_get_type(val) == type;
1012 }
1013 
1014 /* JSON Array API */
1016  if (array == NULL || index >= x_json_array_get_count(array))
1017  return NULL;
1018  return array->items[index];
1019 }
1020 
1021 const char * x_json_array_get_string(const x_JSON_Array *array, size_t index) {
1023 }
1024 
1025 double x_json_array_get_number(const x_JSON_Array *array, size_t index) {
1027 }
1028 
1031 }
1032 
1035 }
1036 
1037 int x_json_array_get_boolean(const x_JSON_Array *array, size_t index) {
1039 }
1040 
1042  return array ? array->count : 0;
1043 }
1044 
1045 /* JSON Value API */
1047  return value ? value->type : JSONError;
1048 }
1049 
1051  return x_json_value_get_type(value) == JSONObject ? value->value.object : NULL;
1052 }
1053 
1055  return x_json_value_get_type(value) == JSONArray ? value->value.array : NULL;
1056 }
1057 
1059  return x_json_value_get_type(value) == JSONString ? value->value.string : NULL;
1060 }
1061 
1063  return x_json_value_get_type(value) == JSONNumber ? value->value.number : 0;
1064 }
1065 
1067  return x_json_value_get_type(value) == JSONBoolean ? value->value.boolean : -1;
1068 }
1069 
1071  switch (x_json_value_get_type(value)) {
1072  case JSONObject:
1073  x_json_object_free(value->value.object);
1074  break;
1075  case JSONString:
1076  if (value->value.string) { parson_free(value->value.string); }
1077  break;
1078  case JSONArray:
1079  x_json_array_free(value->value.array);
1080  break;
1081  default:
1082  break;
1083  }
1084  parson_free(value);
1085 }
1086 
1088  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
1089  if (!new_value)
1090  return NULL;
1091  new_value->type = JSONObject;
1092  new_value->value.object = x_json_object_init();
1093  if (!new_value->value.object) {
1094  parson_free(new_value);
1095  return NULL;
1096  }
1097  return new_value;
1098 }
1099 
1101  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
1102  if (!new_value)
1103  return NULL;
1104  new_value->type = JSONArray;
1105  new_value->value.array = x_json_array_init();
1106  if (!new_value->value.array) {
1107  parson_free(new_value);
1108  return NULL;
1109  }
1110  return new_value;
1111 }
1112 
1114  char *copy = NULL;
1116  size_t string_len = 0;
1117  if (string == NULL)
1118  return NULL;
1119  string_len = strlen(string);
1120  if (!is_valid_utf8(string, string_len))
1121  return NULL;
1122  copy = parson_strndup(string, string_len);
1123  if (copy == NULL)
1124  return NULL;
1126  if (value == NULL)
1127  parson_free(copy);
1128  return value;
1129 }
1130 
1132  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
1133  if (!new_value)
1134  return NULL;
1135  new_value->type = JSONNumber;
1136  new_value->value.number = number;
1137  return new_value;
1138 }
1139 
1141  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
1142  if (!new_value)
1143  return NULL;
1144  new_value->type = JSONBoolean;
1145  new_value->value.boolean = boolean ? 1 : 0;
1146  return new_value;
1147 }
1148 
1150  x_JSON_Value *new_value = (x_JSON_Value*)parson_malloc(sizeof(x_JSON_Value));
1151  if (!new_value)
1152  return NULL;
1153  new_value->type = JSONNull;
1154  return new_value;
1155 }
1156 
1158  size_t i = 0;
1159  x_JSON_Value *return_value = NULL, *temp_value_copy = NULL, *temp_value = NULL;
1160  const char *temp_string = NULL, *temp_key = NULL;
1161  char *temp_string_copy = NULL;
1162  x_JSON_Array *temp_array = NULL, *temp_array_copy = NULL;
1163  x_JSON_Object *temp_object = NULL, *temp_object_copy = NULL;
1164 
1165  switch (x_json_value_get_type(value)) {
1166  case JSONArray:
1167  temp_array = x_json_value_get_array(value);
1169  if (return_value == NULL)
1170  return NULL;
1171  temp_array_copy = x_json_value_get_array(return_value);
1172  for (i = 0; i < x_json_array_get_count(temp_array); i++) {
1173  temp_value = x_json_array_get_value(temp_array, i);
1174  temp_value_copy = x_json_value_deep_copy(temp_value);
1175  if (temp_value_copy == NULL) {
1177  return NULL;
1178  }
1179  if (x_json_array_add(temp_array_copy, temp_value_copy) == JSONFailure) {
1181  x_json_value_free(temp_value_copy);
1182  return NULL;
1183  }
1184  }
1185  return return_value;
1186  case JSONObject:
1187  temp_object = x_json_value_get_object(value);
1189  if (return_value == NULL)
1190  return NULL;
1191  temp_object_copy = x_json_value_get_object(return_value);
1192  for (i = 0; i < x_json_object_get_count(temp_object); i++) {
1193  temp_key = x_json_object_get_name(temp_object, i);
1194  temp_value = x_json_object_get_value(temp_object, temp_key);
1195  temp_value_copy = x_json_value_deep_copy(temp_value);
1196  if (temp_value_copy == NULL) {
1198  return NULL;
1199  }
1200  if (x_json_object_add(temp_object_copy, temp_key, temp_value_copy) == JSONFailure) {
1202  x_json_value_free(temp_value_copy);
1203  return NULL;
1204  }
1205  }
1206  return return_value;
1207  case JSONBoolean:
1209  case JSONNumber:
1211  case JSONString:
1212  temp_string = x_json_value_get_string(value);
1213  temp_string_copy = parson_strdup(temp_string);
1214  if (temp_string_copy == NULL)
1215  return NULL;
1216  return_value = x_json_value_init_string_no_copy(temp_string_copy);
1217  if (return_value == NULL)
1218  parson_free(temp_string_copy);
1219  return return_value;
1220  case JSONNull:
1221  return x_json_value_init_null();
1222  case JSONError:
1223  return NULL;
1224  default:
1225  return NULL;
1226  }
1227 }
1228 
1230  char num_buf[1100]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
1231  int res = x_json_serialize_to_buffer_r(value, NULL, 0, 0, num_buf);
1232  return res < 0 ? 0 : (size_t)(res + 1);
1233 }
1234 
1235 x_JSON_Status x_json_serialize_to_buffer(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes) {
1236  int written = -1;
1237  size_t needed_size_in_bytes = x_json_serialization_size(value);
1238  if (needed_size_in_bytes == 0 || buf_size_in_bytes < needed_size_in_bytes) {
1239  return JSONFailure;
1240  }
1241  written = x_json_serialize_to_buffer_r(value, buf, 0, 0, NULL);
1242  if (written < 0)
1243  return JSONFailure;
1244  return JSONSuccess;
1245 }
1246 
1248  x_JSON_Status return_code = JSONSuccess;
1249  FILE *fp = NULL;
1250  char *serialized_string = x_json_serialize_to_string(value);
1251  if (serialized_string == NULL) {
1252  return JSONFailure;
1253  }
1254  fp = fopen (filename, "w");
1255  if (fp == NULL) {
1256  x_json_free_serialized_string(serialized_string);
1257  return JSONFailure;
1258  }
1259  if (fputs(serialized_string, fp) == EOF) {
1260  return_code = JSONFailure;
1261  }
1262  if (fclose(fp) == EOF) {
1263  return_code = JSONFailure;
1264  }
1265  x_json_free_serialized_string(serialized_string);
1266  return return_code;
1267 }
1268 
1270  x_JSON_Status serialization_result = JSONFailure;
1271  size_t buf_size_bytes = x_json_serialization_size(value);
1272  char *buf = NULL;
1273  if (buf_size_bytes == 0) {
1274  return NULL;
1275  }
1276  buf = (char*)parson_malloc(buf_size_bytes);
1277  if (buf == NULL)
1278  return NULL;
1279  serialization_result = x_json_serialize_to_buffer(value, buf, buf_size_bytes);
1280  if (serialization_result == JSONFailure) {
1282  return NULL;
1283  }
1284  return buf;
1285 }
1286 
1288  char num_buf[1100]; /* recursively allocating buffer on stack is a bad idea, so let's do it only once */
1289  int res = x_json_serialize_to_buffer_r(value, NULL, 0, 1, num_buf);
1290  return res < 0 ? 0 : (size_t)(res + 1);
1291 }
1292 
1293 x_JSON_Status x_json_serialize_to_buffer_pretty(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes) {
1294  int written = -1;
1295  size_t needed_size_in_bytes = x_json_serialization_size_pretty(value);
1296  if (needed_size_in_bytes == 0 || buf_size_in_bytes < needed_size_in_bytes)
1297  return JSONFailure;
1298  written = x_json_serialize_to_buffer_r(value, buf, 0, 1, NULL);
1299  if (written < 0)
1300  return JSONFailure;
1301  return JSONSuccess;
1302 }
1303 
1305  x_JSON_Status return_code = JSONSuccess;
1306  FILE *fp = NULL;
1307  char *serialized_string = x_json_serialize_to_string_pretty(value);
1308  if (serialized_string == NULL) {
1309  return JSONFailure;
1310  }
1311  fp = fopen (filename, "w");
1312  if (fp == NULL) {
1313  x_json_free_serialized_string(serialized_string);
1314  return JSONFailure;
1315  }
1316  if (fputs(serialized_string, fp) == EOF) {
1317  return_code = JSONFailure;
1318  }
1319  if (fclose(fp) == EOF) {
1320  return_code = JSONFailure;
1321  }
1322  x_json_free_serialized_string(serialized_string);
1323  return return_code;
1324 }
1325 
1327  x_JSON_Status serialization_result = JSONFailure;
1328  size_t buf_size_bytes = x_json_serialization_size_pretty(value);
1329  char *buf = NULL;
1330  if (buf_size_bytes == 0) {
1331  return NULL;
1332  }
1333  buf = (char*)parson_malloc(buf_size_bytes);
1334  if (buf == NULL)
1335  return NULL;
1336  serialization_result = x_json_serialize_to_buffer_pretty(value, buf, buf_size_bytes);
1337  if (serialization_result == JSONFailure) {
1339  return NULL;
1340  }
1341  return buf;
1342 }
1343 
1344 void x_json_free_serialized_string(char *string) {
1345  parson_free(string);
1346 }
1347 
1349  x_JSON_Value *temp_value = NULL;
1350  size_t last_element_ix = 0;
1351  if (array == NULL || ix >= x_json_array_get_count(array)) {
1352  return JSONFailure;
1353  }
1354  last_element_ix = x_json_array_get_count(array) - 1;
1356  if (ix != last_element_ix) { /* Replace value with one from the end of array */
1357  temp_value = x_json_array_get_value(array, last_element_ix);
1358  if (temp_value == NULL) {
1359  return JSONFailure;
1360  }
1361  array->items[ix] = temp_value;
1362  }
1363  array->count -= 1;
1364  return JSONSuccess;
1365 }
1366 
1368  if (array == NULL || value == NULL || ix >= x_json_array_get_count(array)) {
1369  return JSONFailure;
1370  }
1372  array->items[ix] = value;
1373  return JSONSuccess;
1374 }
1375 
1378  if (value == NULL)
1379  return JSONFailure;
1382  return JSONFailure;
1383  }
1384  return JSONSuccess;
1385 }
1386 
1389  if (value == NULL)
1390  return JSONFailure;
1393  return JSONFailure;
1394  }
1395  return JSONSuccess;
1396 }
1397 
1400  if (value == NULL)
1401  return JSONFailure;
1404  return JSONFailure;
1405  }
1406  return JSONSuccess;
1407 }
1408 
1411  if (value == NULL)
1412  return JSONFailure;
1415  return JSONFailure;
1416  }
1417  return JSONSuccess;
1418 }
1419 
1421  size_t i = 0;
1422  if (array == NULL)
1423  return JSONFailure;
1424  for (i = 0; i < x_json_array_get_count(array); i++) {
1426  }
1427  array->count = 0;
1428  return JSONSuccess;
1429 }
1430 
1432  if (array == NULL || value == NULL)
1433  return JSONFailure;
1434  return x_json_array_add(array, value);
1435 }
1436 
1439  if (value == NULL)
1440  return JSONFailure;
1443  return JSONFailure;
1444  }
1445  return JSONSuccess;
1446 }
1447 
1450  if (value == NULL)
1451  return JSONFailure;
1454  return JSONFailure;
1455  }
1456  return JSONSuccess;
1457 }
1458 
1461  if (value == NULL)
1462  return JSONFailure;
1465  return JSONFailure;
1466  }
1467  return JSONSuccess;
1468 }
1469 
1472  if (value == NULL)
1473  return JSONFailure;
1476  return JSONFailure;
1477  }
1478  return JSONSuccess;
1479 }
1480 
1482  size_t i = 0;
1483  x_JSON_Value *old_value;
1484  if (object == NULL || name == NULL || value == NULL)
1485  return JSONFailure;
1486  old_value = x_json_object_get_value(object, name);
1487  if (old_value != NULL) { /* free and overwrite old value */
1488  x_json_value_free(old_value);
1489  for (i = 0; i < x_json_object_get_count(object); i++) {
1490  if (strcmp(object->names[i], name) == 0) {
1491  object->values[i] = value;
1492  return JSONSuccess;
1493  }
1494  }
1495  }
1496  /* add new key value pair */
1497  return x_json_object_add(object, name, value);
1498 }
1499 
1500 x_JSON_Status x_json_object_set_string(x_JSON_Object *object, const char *name, const char *string) {
1501  return x_json_object_set_value(object, name, x_json_value_init_string(string));
1502 }
1503 
1504 x_JSON_Status x_json_object_set_number(x_JSON_Object *object, const char *name, double number) {
1506 }
1507 
1508 x_JSON_Status x_json_object_set_boolean(x_JSON_Object *object, const char *name, int boolean) {
1509  return x_json_object_set_value(object, name, x_json_value_init_boolean(boolean));
1510 }
1511 
1513  return x_json_object_set_value(object, name, x_json_value_init_null());
1514 }
1515 
1517  const char *dot_pos = NULL;
1518  char *current_name = NULL;
1519  x_JSON_Object *temp_obj = NULL;
1520  x_JSON_Value *new_value = NULL;
1521  if (value == NULL || name == NULL || value == NULL)
1522  return JSONFailure;
1523  dot_pos = strchr(name, '.');
1524  if (dot_pos == NULL) {
1525  return x_json_object_set_value(object, name, value);
1526  } else {
1527  current_name = parson_strndup(name, dot_pos - name);
1528  temp_obj = x_json_object_get_object(object, current_name);
1529  if (temp_obj == NULL) {
1530  new_value = x_json_value_init_object();
1531  if (new_value == NULL) {
1532  parson_free(current_name);
1533  return JSONFailure;
1534  }
1535  if (x_json_object_add(object, current_name, new_value) == JSONFailure) {
1536  x_json_value_free(new_value);
1537  parson_free(current_name);
1538  return JSONFailure;
1539  }
1540  temp_obj = x_json_object_get_object(object, current_name);
1541  }
1542  parson_free(current_name);
1543  return x_json_object_dotset_value(temp_obj, dot_pos + 1, value);
1544  }
1545 }
1546 
1547 x_JSON_Status x_json_object_dotset_string(x_JSON_Object *object, const char *name, const char *string) {
1549  if (value == NULL)
1550  return JSONFailure;
1551  if (x_json_object_dotset_value(object, name, value) == JSONFailure) {
1553  return JSONFailure;
1554  }
1555  return JSONSuccess;
1556 }
1557 
1560  if (value == NULL)
1561  return JSONFailure;
1562  if (x_json_object_dotset_value(object, name, value) == JSONFailure) {
1564  return JSONFailure;
1565  }
1566  return JSONSuccess;
1567 }
1568 
1569 x_JSON_Status x_json_object_dotset_boolean(x_JSON_Object *object, const char *name, int boolean) {
1571  if (value == NULL)
1572  return JSONFailure;
1573  if (x_json_object_dotset_value(object, name, value) == JSONFailure) {
1575  return JSONFailure;
1576  }
1577  return JSONSuccess;
1578 }
1579 
1582  if (value == NULL)
1583  return JSONFailure;
1584  if (x_json_object_dotset_value(object, name, value) == JSONFailure) {
1586  return JSONFailure;
1587  }
1588  return JSONSuccess;
1589 }
1590 
1592  size_t i = 0, last_item_index = 0;
1593  if (object == NULL || x_json_object_get_value(object, name) == NULL)
1594  return JSONFailure;
1595  last_item_index = x_json_object_get_count(object) - 1;
1596  for (i = 0; i < x_json_object_get_count(object); i++) {
1597  if (strcmp(object->names[i], name) == 0) {
1598  parson_free(object->names[i]);
1599  x_json_value_free(object->values[i]);
1600  if (i != last_item_index) { /* Replace key value pair with one from the end */
1601  object->names[i] = object->names[last_item_index];
1602  object->values[i] = object->values[last_item_index];
1603  }
1604  object->count -= 1;
1605  return JSONSuccess;
1606  }
1607  }
1608  return JSONFailure; /* No execution path should end here */
1609 }
1610 
1612  const char *dot_pos = strchr(name, '.');
1613  char *current_name = NULL;
1614  x_JSON_Object *temp_obj = NULL;
1615  if (dot_pos == NULL) {
1616  return x_json_object_remove(object, name);
1617  } else {
1618  current_name = parson_strndup(name, dot_pos - name);
1619  temp_obj = x_json_object_get_object(object, current_name);
1620  if (temp_obj == NULL) {
1621  parson_free(current_name);
1622  return JSONFailure;
1623  }
1624  parson_free(current_name);
1625  return x_json_object_dotremove(temp_obj, dot_pos + 1);
1626  }
1627 }
1628 
1630  size_t i = 0;
1631  if (object == NULL) {
1632  return JSONFailure;
1633  }
1634  for (i = 0; i < x_json_object_get_count(object); i++) {
1635  parson_free(object->names[i]);
1636  x_json_value_free(object->values[i]);
1637  }
1638  object->count = 0;
1639  return JSONSuccess;
1640 }
1641 
1643  x_JSON_Value *temp_schema_value = NULL, *temp_value = NULL;
1644  x_JSON_Array *schema_array = NULL, *value_array = NULL;
1645  x_JSON_Object *schema_object = NULL, *value_object = NULL;
1647  const char *key = NULL;
1648  size_t i = 0, count = 0;
1649  if (schema == NULL || value == NULL)
1650  return JSONFailure;
1651  schema_type = x_json_value_get_type(schema);
1653  if (schema_type != value_type && schema_type != JSONNull) /* null represents all values */
1654  return JSONFailure;
1655  switch (schema_type) {
1656  case JSONArray:
1657  schema_array = x_json_value_get_array(schema);
1658  value_array = x_json_value_get_array(value);
1659  count = x_json_array_get_count(schema_array);
1660  if (count == 0)
1661  return JSONSuccess; /* Empty array allows all types */
1662  /* Get first value from array, rest is ignored */
1663  temp_schema_value = x_json_array_get_value(schema_array, 0);
1664  for (i = 0; i < x_json_array_get_count(value_array); i++) {
1665  temp_value = x_json_array_get_value(value_array, i);
1666  if (x_json_validate(temp_schema_value, temp_value) == 0) {
1667  return JSONFailure;
1668  }
1669  }
1670  return JSONSuccess;
1671  case JSONObject:
1672  schema_object = x_json_value_get_object(schema);
1673  value_object = x_json_value_get_object(value);
1674  count = x_json_object_get_count(schema_object);
1675  if (count == 0)
1676  return JSONSuccess; /* Empty object allows all objects */
1677  else if (x_json_object_get_count(value_object) < count)
1678  return JSONFailure; /* Tested object mustn't have less name-value pairs than schema */
1679  for (i = 0; i < count; i++) {
1680  key = x_json_object_get_name(schema_object, i);
1681  temp_schema_value = x_json_object_get_value(schema_object, key);
1682  temp_value = x_json_object_get_value(value_object, key);
1683  if (temp_value == NULL)
1684  return JSONFailure;
1685  if (x_json_validate(temp_schema_value, temp_value) == JSONFailure)
1686  return JSONFailure;
1687  }
1688  return JSONSuccess;
1689  case JSONString: case JSONNumber: case JSONBoolean: case JSONNull:
1690  return JSONSuccess; /* equality already tested before switch */
1691  case JSONError: default:
1692  return JSONFailure;
1693  }
1694 }
1695 
1697  x_JSON_Object *a_object = NULL, *b_object = NULL;
1698  x_JSON_Array *a_array = NULL, *b_array = NULL;
1699  const char *a_string = NULL, *b_string = NULL;
1700  const char *key = NULL;
1701  size_t a_count = 0, b_count = 0, i = 0;
1702  x_JSON_Value_Type a_type, b_type;
1703  a_type = x_json_value_get_type(a);
1704  b_type = x_json_value_get_type(b);
1705  if (a_type != b_type) {
1706  return 0;
1707  }
1708  switch (a_type) {
1709  case JSONArray:
1710  a_array = x_json_value_get_array(a);
1711  b_array = x_json_value_get_array(b);
1712  a_count = x_json_array_get_count(a_array);
1713  b_count = x_json_array_get_count(b_array);
1714  if (a_count != b_count) {
1715  return 0;
1716  }
1717  for (i = 0; i < a_count; i++) {
1719  x_json_array_get_value(b_array, i))) {
1720  return 0;
1721  }
1722  }
1723  return 1;
1724  case JSONObject:
1725  a_object = x_json_value_get_object(a);
1726  b_object = x_json_value_get_object(b);
1727  a_count = x_json_object_get_count(a_object);
1728  b_count = x_json_object_get_count(b_object);
1729  if (a_count != b_count) {
1730  return 0;
1731  }
1732  for (i = 0; i < a_count; i++) {
1733  key = x_json_object_get_name(a_object, i);
1735  x_json_object_get_value(b_object, key))) {
1736  return 0;
1737  }
1738  }
1739  return 1;
1740  case JSONString:
1741  a_string = x_json_value_get_string(a);
1742  b_string = x_json_value_get_string(b);
1743  return strcmp(a_string, b_string) == 0;
1744  case JSONBoolean:
1746  case JSONNumber:
1747  return fabs(x_json_value_get_number(a) - x_json_value_get_number(b)) < 0.000001; /* EPSILON */
1748  case JSONError:
1749  return 1;
1750  case JSONNull:
1751  return 1;
1752  default:
1753  return 1;
1754  }
1755 }
1756 
1758  return x_json_value_get_type(value);
1759 }
1760 
1763 }
1764 
1766  return x_json_value_get_array(value);
1767 }
1768 
1769 const char * x_json_string (const x_JSON_Value *value) {
1771 }
1772 
1775 }
1776 
1779 }
1780 
1782  parson_malloc = malloc_fun;
1783  parson_free = free_fun;
1784 }
static const char fp[]
Definition: des.c:87
static int type
Definition: getdata.c:31
static SQLCHAR output[256]
Definition: print.c:5
static const char * schema
Definition: stats.c:20
static char * return_value
Definition: readconf.c:24
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
char * buf
static int input()
int i
yy_size_t n
int len
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
int strncmp(const char *str1, const char *str2, size_t count)
Definition: odbc_utils.hpp:133
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
#define fabs(v)
Definition: ncbi_dispd.c:46
#define fseek
unsigned int a
Definition: ncbi_localip.c:102
int isxdigit(Uchar c)
Definition: ncbictype.hpp:71
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
x_JSON_Array * x_json_array(const x_JSON_Value *value)
Definition: parson.c:1765
static x_JSON_Value * x_json_value_init_string_no_copy(char *string)
Definition: parson.c:430
static void x_json_array_free(x_JSON_Array *array)
Definition: parson.c:422
static char * process_string(const char *input, size_t len)
Definition: parson.c:497
x_JSON_Status x_json_array_replace_value(x_JSON_Array *array, size_t ix, x_JSON_Value *value)
Definition: parson.c:1367
x_JSON_Value * x_json_value_init_boolean(int boolean)
Definition: parson.c:1140
static x_JSON_Status x_json_object_add(x_JSON_Object *object, const char *name, x_JSON_Value *value)
Definition: parson.c:302
#define SKIP_CHAR(str)
Definition: parson.c:43
static x_JSON_Value * parse_object_value(const char **string, size_t nesting)
Definition: parson.c:579
double x_json_object_get_number(const x_JSON_Object *object, const char *name)
Definition: parson.c:936
x_JSON_Status x_json_object_set_value(x_JSON_Object *object, const char *name, x_JSON_Value *value)
Definition: parson.c:1481
x_JSON_Array * x_json_array_get_array(const x_JSON_Array *array, size_t index)
Definition: parson.c:1033
static int verify_utf8_sequence(const unsigned char *string, int *len)
Definition: parson.c:162
static x_JSON_Value * x_json_object_nget_value(const x_JSON_Object *object, const char *name, size_t n)
Definition: parson.c:358
x_JSON_Object * x_json_object_dotget_object(const x_JSON_Object *object, const char *name)
Definition: parson.c:968
x_JSON_Status x_json_object_dotset_value(x_JSON_Object *object, const char *name, x_JSON_Value *value)
Definition: parson.c:1516
const char * x_json_string(const x_JSON_Value *value)
Definition: parson.c:1769
static int append_indent(char *buf, int level)
Definition: parson.c:864
const char * x_json_object_get_string(const x_JSON_Object *object, const char *name)
Definition: parson.c:932
void x_json_free_serialized_string(char *string)
Definition: parson.c:1344
int x_json_object_get_boolean(const x_JSON_Object *object, const char *name)
Definition: parson.c:948
x_JSON_Value * x_json_array_get_value(const x_JSON_Array *array, size_t index)
Definition: parson.c:1015
static x_JSON_Value * parse_number_value(const char **string)
Definition: parson.c:692
x_JSON_Object * x_json_value_get_object(const x_JSON_Value *value)
Definition: parson.c:1050
x_JSON_Value * x_json_object_get_value_at(const x_JSON_Object *object, size_t index)
Definition: parson.c:990
x_JSON_Status x_json_array_remove(x_JSON_Array *array, size_t ix)
Definition: parson.c:1348
static char * parson_strdup(const char *string)
Definition: parson.c:139
#define SKIP_WHITESPACES(str)
Definition: parson.c:44
x_JSON_Value * x_json_parse_file_with_comments(const char *filename)
Definition: parson.c:894
static x_JSON_Malloc_Function parson_malloc
Definition: parson.c:50
x_JSON_Array * x_json_value_get_array(const x_JSON_Value *value)
Definition: parson.c:1054
void x_json_value_free(x_JSON_Value *value)
Definition: parson.c:1070
double x_json_value_get_number(const x_JSON_Value *value)
Definition: parson.c:1062
int x_json_object_has_value(const x_JSON_Object *object, const char *name)
Definition: parson.c:996
x_JSON_Array * x_json_object_dotget_array(const x_JSON_Object *object, const char *name)
Definition: parson.c:972
x_JSON_Status x_json_serialize_to_file_pretty(const x_JSON_Value *value, const char *filename)
Definition: parson.c:1304
static char * read_file(const char *filename)
Definition: parson.c:227
int x_json_value_get_boolean(const x_JSON_Value *value)
Definition: parson.c:1066
static x_JSON_Status x_json_array_add(x_JSON_Array *array, x_JSON_Value *value)
Definition: parson.c:391
const char * x_json_object_get_name(const x_JSON_Object *object, size_t index)
Definition: parson.c:984
char * x_json_serialize_to_string(const x_JSON_Value *value)
Definition: parson.c:1269
const char * x_json_value_get_string(const x_JSON_Value *value)
Definition: parson.c:1058
x_JSON_Status x_json_object_set_number(x_JSON_Object *object, const char *name, double number)
Definition: parson.c:1504
x_JSON_Value * x_json_value_init_object(void)
Definition: parson.c:1087
x_JSON_Value * x_json_value_deep_copy(const x_JSON_Value *value)
Definition: parson.c:1157
#define DOUBLE_SERIALIZATION_FORMAT
Definition: parson.c:40
size_t x_json_serialization_size_pretty(const x_JSON_Value *value)
Definition: parson.c:1287
static char * get_quoted_string(const char **string)
Definition: parson.c:547
static void skip_quotes(const char **string)
Definition: parson.c:440
double x_json_number(const x_JSON_Value *value)
Definition: parson.c:1773
#define ARRAY_MAX_CAPACITY
Definition: parson.c:37
x_JSON_Status x_json_serialize_to_buffer_pretty(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes)
Definition: parson.c:1293
static int is_decimal(const char *string, size_t length)
Definition: parson.c:216
x_JSON_Status x_json_array_clear(x_JSON_Array *array)
Definition: parson.c:1420
static x_JSON_Value * parse_boolean_value(const char **string)
Definition: parson.c:679
x_JSON_Status x_json_array_replace_boolean(x_JSON_Array *array, size_t i, int boolean)
Definition: parson.c:1398
static int x_json_serialize_to_buffer_r(const x_JSON_Value *value, char *buf, int level, int is_pretty, char *num_buf)
Definition: parson.c:725
#define STARTING_CAPACITY
Definition: parson.c:36
x_JSON_Status x_json_validate(const x_JSON_Value *schema, const x_JSON_Value *value)
Definition: parson.c:1642
void x_json_set_allocation_functions(x_JSON_Malloc_Function malloc_fun, x_JSON_Free_Function free_fun)
Definition: parson.c:1781
int x_json_boolean(const x_JSON_Value *value)
Definition: parson.c:1777
char * x_json_serialize_to_string_pretty(const x_JSON_Value *value)
Definition: parson.c:1326
x_JSON_Object * x_json_object(const x_JSON_Value *value)
Definition: parson.c:1761
x_JSON_Status x_json_array_append_value(x_JSON_Array *array, x_JSON_Value *value)
Definition: parson.c:1431
static x_JSON_Status x_json_object_resize(x_JSON_Object *object, size_t new_capacity)
Definition: parson.c:326
x_JSON_Value * x_json_object_dotget_value(const x_JSON_Object *object, const char *name)
Definition: parson.c:952
double x_json_object_dotget_number(const x_JSON_Object *object, const char *name)
Definition: parson.c:964
#define APPEND_INDENT(level)
Definition: parson.c:720
static int is_valid_utf8(const char *string, size_t string_len)
Definition: parson.c:204
static x_JSON_Value * parse_value(const char **string, size_t nesting)
Definition: parson.c:555
x_JSON_Status x_json_array_append_null(x_JSON_Array *array)
Definition: parson.c:1470
x_JSON_Status x_json_object_dotset_number(x_JSON_Object *object, const char *name, double number)
Definition: parson.c:1558
#define OBJECT_MAX_CAPACITY
Definition: parson.c:38
x_JSON_Object * x_json_array_get_object(const x_JSON_Array *array, size_t index)
Definition: parson.c:1029
x_JSON_Value * x_json_value_init_string(const char *string)
Definition: parson.c:1113
const char * x_json_array_get_string(const x_JSON_Array *array, size_t index)
Definition: parson.c:1021
x_JSON_Status x_json_array_replace_number(x_JSON_Array *array, size_t i, double number)
Definition: parson.c:1387
x_JSON_Value * x_json_parse_string_with_comments(const char *string)
Definition: parson.c:910
static void x_json_object_free(x_JSON_Object *object)
Definition: parson.c:370
static x_JSON_Object * x_json_object_init(void)
Definition: parson.c:291
#define MAX_NESTING
Definition: parson.c:39
x_JSON_Status x_json_value_equals(const x_JSON_Value *a, const x_JSON_Value *b)
Definition: parson.c:1696
x_JSON_Status x_json_object_dotset_string(x_JSON_Object *object, const char *name, const char *string)
Definition: parson.c:1547
x_JSON_Value * x_json_parse_string(const char *string)
Definition: parson.c:904
x_JSON_Value * x_json_value_init_array(void)
Definition: parson.c:1100
int x_json_object_dotget_boolean(const x_JSON_Object *object, const char *name)
Definition: parson.c:976
x_JSON_Status x_json_object_set_string(x_JSON_Object *object, const char *name, const char *string)
Definition: parson.c:1500
x_JSON_Value * x_json_value_init_null(void)
Definition: parson.c:1149
#define IS_CONT(b)
Definition: parson.c:53
static int append_string(char *buf, const char *string)
Definition: parson.c:873
static x_JSON_Value * parse_array_value(const char **string, size_t nesting)
Definition: parson.c:628
x_JSON_Array * x_json_object_get_array(const x_JSON_Object *object, const char *name)
Definition: parson.c:944
x_JSON_Status x_json_array_replace_null(x_JSON_Array *array, size_t i)
Definition: parson.c:1409
static int x_json_serialize_string(const char *string, char *buf)
Definition: parson.c:835
static x_JSON_Value * parse_string_value(const char **string)
Definition: parson.c:666
size_t x_json_array_get_count(const x_JSON_Array *array)
Definition: parson.c:1041
x_JSON_Status x_json_object_dotset_boolean(x_JSON_Object *object, const char *name, int boolean)
Definition: parson.c:1569
x_JSON_Status x_json_object_set_boolean(x_JSON_Object *object, const char *name, int boolean)
Definition: parson.c:1508
#define APPEND_STRING(str)
Definition: parson.c:715
x_JSON_Status x_json_object_clear(x_JSON_Object *object)
Definition: parson.c:1629
int x_json_object_dothas_value(const x_JSON_Object *object, const char *name)
Definition: parson.c:1005
static x_JSON_Status x_json_array_resize(x_JSON_Array *array, size_t new_capacity)
Definition: parson.c:404
size_t x_json_serialization_size(const x_JSON_Value *value)
Definition: parson.c:1229
static char * parson_strndup(const char *string, size_t n)
Definition: parson.c:130
x_JSON_Status x_json_array_append_number(x_JSON_Array *array, double number)
Definition: parson.c:1448
x_JSON_Status x_json_serialize_to_file(const x_JSON_Value *value, const char *filename)
Definition: parson.c:1247
static x_JSON_Array * x_json_array_init(void)
Definition: parson.c:381
x_JSON_Value_Type x_json_value_get_type(const x_JSON_Value *value)
Definition: parson.c:1046
static int is_utf16_hex(const unsigned char *string)
Definition: parson.c:143
x_JSON_Status x_json_array_append_boolean(x_JSON_Array *array, int boolean)
Definition: parson.c:1459
int x_json_object_dothas_value_of_type(const x_JSON_Object *object, const char *name, x_JSON_Value_Type type)
Definition: parson.c:1009
x_JSON_Value_Type x_json_type(const x_JSON_Value *value)
Definition: parson.c:1757
x_JSON_Status x_json_array_append_string(x_JSON_Array *array, const char *string)
Definition: parson.c:1437
#define SIZEOF_TOKEN(a)
Definition: parson.c:42
static int parse_utf_16(const char **unprocessed, char **processed)
Definition: parson.c:455
x_JSON_Status x_json_array_replace_string(x_JSON_Array *array, size_t i, const char *string)
Definition: parson.c:1376
size_t x_json_object_get_count(const x_JSON_Object *object)
Definition: parson.c:980
double x_json_array_get_number(const x_JSON_Array *array, size_t index)
Definition: parson.c:1025
x_JSON_Value * x_json_parse_file(const char *filename)
Definition: parson.c:884
x_JSON_Status x_json_object_set_null(x_JSON_Object *object, const char *name)
Definition: parson.c:1512
int x_json_object_has_value_of_type(const x_JSON_Object *object, const char *name, x_JSON_Value_Type type)
Definition: parson.c:1000
x_JSON_Status x_json_object_dotset_null(x_JSON_Object *object, const char *name)
Definition: parson.c:1580
x_JSON_Status x_json_object_remove(x_JSON_Object *object, const char *name)
Definition: parson.c:1591
x_JSON_Value * x_json_object_get_value(const x_JSON_Object *object, const char *name)
Definition: parson.c:926
static int num_bytes_in_utf8_sequence(unsigned char c)
Definition: parson.c:147
x_JSON_Status x_json_serialize_to_buffer(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes)
Definition: parson.c:1235
const char * x_json_object_dotget_string(const x_JSON_Object *object, const char *name)
Definition: parson.c:960
union x_json_value_value x_JSON_Value_Value
int x_json_array_get_boolean(const x_JSON_Array *array, size_t index)
Definition: parson.c:1037
x_JSON_Object * x_json_object_get_object(const x_JSON_Object *object, const char *name)
Definition: parson.c:940
static void remove_comments(char *string, const char *start_token, const char *end_token)
Definition: parson.c:259
x_JSON_Status x_json_object_dotremove(x_JSON_Object *object, const char *name)
Definition: parson.c:1611
static x_JSON_Free_Function parson_free
Definition: parson.c:51
x_JSON_Value * x_json_value_init_number(double number)
Definition: parson.c:1131
#define MAX(a, b)
Definition: parson.c:45
static x_JSON_Value * parse_null_value(const char **string)
Definition: parson.c:705
void *(* x_JSON_Malloc_Function)(size_t)
Definition: parson.h:56
int x_JSON_Value_Type
Definition: parson.h:48
int x_JSON_Status
Definition: parson.h:54
void(* x_JSON_Free_Function)(void *)
Definition: parson.h:57
@ JSONSuccess
Definition: parson.h:51
@ JSONFailure
Definition: parson.h:52
@ JSONError
Definition: parson.h:40
@ JSONObject
Definition: parson.h:44
@ JSONNull
Definition: parson.h:41
@ JSONNumber
Definition: parson.h:43
@ JSONBoolean
Definition: parson.h:46
@ JSONString
Definition: parson.h:42
@ JSONArray
Definition: parson.h:45
static BOOL number
Definition: pcregrep.c:193
Definition: type.c:6
size_t count
Definition: parson.c:79
x_JSON_Value ** items
Definition: parson.c:78
size_t capacity
Definition: parson.c:80
char ** names
Definition: parson.c:71
size_t count
Definition: parson.c:73
x_JSON_Value ** values
Definition: parson.c:72
size_t capacity
Definition: parson.c:74
x_JSON_Value_Type type
Definition: parson.c:66
x_JSON_Value_Value value
Definition: parson.c:67
else result
Definition: token2.c:20
x_JSON_Object * object
Definition: parson.c:59
double number
Definition: parson.c:58
char * string
Definition: parson.c:57
x_JSON_Array * array
Definition: parson.c:60
#define SEEK_END
Definition: zconf.h:502
void free(voidpf ptr)
voidp malloc(uInt size)
Modified on Sat Apr 13 11:46:17 2024 by modify_doxy.py rev. 669887