libyajl2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitmodules +3 -0
  4. data/.kitchen.cloud.yml +87 -0
  5. data/.kitchen.yml +38 -0
  6. data/.reek.yml +3 -0
  7. data/.rspec +1 -0
  8. data/.rubocop.yml +38 -0
  9. data/.travis.yml +8 -0
  10. data/CONTRIBUTING.md +4 -0
  11. data/Gemfile +12 -0
  12. data/LICENSE +201 -0
  13. data/README.md +9 -0
  14. data/Rakefile +144 -0
  15. data/bootstrap.sh +60 -0
  16. data/ext/libyajl2/Makefile +7 -0
  17. data/ext/libyajl2/extconf.rb +66 -0
  18. data/ext/libyajl2/vendor/yajl/.gitignore +3 -0
  19. data/ext/libyajl2/vendor/yajl/BUILDING +23 -0
  20. data/ext/libyajl2/vendor/yajl/BUILDING.win32 +27 -0
  21. data/ext/libyajl2/vendor/yajl/CMakeLists.txt +81 -0
  22. data/ext/libyajl2/vendor/yajl/COPYING +13 -0
  23. data/ext/libyajl2/vendor/yajl/ChangeLog +189 -0
  24. data/ext/libyajl2/vendor/yajl/README +74 -0
  25. data/ext/libyajl2/vendor/yajl/TODO +9 -0
  26. data/ext/libyajl2/vendor/yajl/YAJLDoc.cmake +26 -0
  27. data/ext/libyajl2/vendor/yajl/configure +81 -0
  28. data/ext/libyajl2/vendor/yajl/example/CMakeLists.txt +23 -0
  29. data/ext/libyajl2/vendor/yajl/example/README.md +7 -0
  30. data/ext/libyajl2/vendor/yajl/example/parse_config.c +69 -0
  31. data/ext/libyajl2/vendor/yajl/example/sample.config +101 -0
  32. data/ext/libyajl2/vendor/yajl/perf/CMakeLists.txt +23 -0
  33. data/ext/libyajl2/vendor/yajl/perf/documents.c +1418 -0
  34. data/ext/libyajl2/vendor/yajl/perf/documents.h +28 -0
  35. data/ext/libyajl2/vendor/yajl/perf/perftest.c +134 -0
  36. data/ext/libyajl2/vendor/yajl/reformatter/CMakeLists.txt +43 -0
  37. data/ext/libyajl2/vendor/yajl/reformatter/json_reformat.c +210 -0
  38. data/ext/libyajl2/vendor/yajl/src/CMakeLists.txt +87 -0
  39. data/ext/libyajl2/vendor/yajl/src/YAJL.dxy +1258 -0
  40. data/ext/libyajl2/vendor/yajl/src/api/yajl_common.h +75 -0
  41. data/ext/libyajl2/vendor/yajl/src/api/yajl_gen.h +167 -0
  42. data/ext/libyajl2/vendor/yajl/src/api/yajl_parse.h +226 -0
  43. data/ext/libyajl2/vendor/yajl/src/api/yajl_tree.h +186 -0
  44. data/ext/libyajl2/vendor/yajl/src/api/yajl_version.h.cmake +23 -0
  45. data/ext/libyajl2/vendor/yajl/src/yajl +33 -0
  46. data/ext/libyajl2/vendor/yajl/src/yajl.c +175 -0
  47. data/ext/libyajl2/vendor/yajl/src/yajl.pc.cmake +9 -0
  48. data/ext/libyajl2/vendor/yajl/src/yajl_alloc.c +52 -0
  49. data/ext/libyajl2/vendor/yajl/src/yajl_alloc.h +34 -0
  50. data/ext/libyajl2/vendor/yajl/src/yajl_buf.c +103 -0
  51. data/ext/libyajl2/vendor/yajl/src/yajl_buf.h +57 -0
  52. data/ext/libyajl2/vendor/yajl/src/yajl_bytestack.h +69 -0
  53. data/ext/libyajl2/vendor/yajl/src/yajl_encode.c +220 -0
  54. data/ext/libyajl2/vendor/yajl/src/yajl_encode.h +34 -0
  55. data/ext/libyajl2/vendor/yajl/src/yajl_gen.c +362 -0
  56. data/ext/libyajl2/vendor/yajl/src/yajl_lex.c +763 -0
  57. data/ext/libyajl2/vendor/yajl/src/yajl_lex.h +117 -0
  58. data/ext/libyajl2/vendor/yajl/src/yajl_parser.c +498 -0
  59. data/ext/libyajl2/vendor/yajl/src/yajl_parser.h +78 -0
  60. data/ext/libyajl2/vendor/yajl/src/yajl_tree.c +503 -0
  61. data/ext/libyajl2/vendor/yajl/src/yajl_version.c +7 -0
  62. data/ext/libyajl2/vendor/yajl/test/CMakeLists.txt +16 -0
  63. data/ext/libyajl2/vendor/yajl/test/api/CMakeLists.txt +25 -0
  64. data/ext/libyajl2/vendor/yajl/test/api/gen-extra-close.c +19 -0
  65. data/ext/libyajl2/vendor/yajl/test/api/run_tests.sh +23 -0
  66. data/ext/libyajl2/vendor/yajl/test/parsing/CMakeLists.txt +23 -0
  67. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_difficult_json_c_test_case_with_comments.json +1 -0
  68. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_difficult_json_c_test_case_with_comments.json.gold +36 -0
  69. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_simple_with_comments.json +11 -0
  70. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ac_simple_with_comments.json.gold +9 -0
  71. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_false_then_garbage.json +1 -0
  72. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_false_then_garbage.json.gold +2 -0
  73. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_null_then_garbage.json +1 -0
  74. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_null_then_garbage.json.gold +2 -0
  75. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_true_then_garbage.json +1 -0
  76. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ag_true_then_garbage.json.gold +2 -0
  77. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_eof.json +1 -0
  78. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_eof.json.gold +4 -0
  79. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_integers.json +1 -0
  80. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_integers.json.gold +3 -0
  81. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_multiple.json +3 -0
  82. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_multiple.json.gold +5 -0
  83. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_stuff.json +7 -0
  84. data/ext/libyajl2/vendor/yajl/test/parsing/cases/am_stuff.json.gold +14 -0
  85. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_array_open.json +1 -0
  86. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_array_open.json.gold +2 -0
  87. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_eof_str.json +1 -0
  88. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_eof_str.json.gold +1 -0
  89. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_map_open.json +1 -0
  90. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_map_open.json.gold +2 -0
  91. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_partial_ok.json +1 -0
  92. data/ext/libyajl2/vendor/yajl/test/parsing/cases/ap_partial_ok.json.gold +4 -0
  93. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array.json +6 -0
  94. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array.json.gold +22 -0
  95. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array_close.json +1 -0
  96. data/ext/libyajl2/vendor/yajl/test/parsing/cases/array_close.json.gold +2 -0
  97. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bignums.json +1 -0
  98. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bignums.json.gold +5 -0
  99. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bogus_char.json +4 -0
  100. data/ext/libyajl2/vendor/yajl/test/parsing/cases/bogus_char.json.gold +10 -0
  101. data/ext/libyajl2/vendor/yajl/test/parsing/cases/codepoints_from_unicode_org.json +1 -0
  102. data/ext/libyajl2/vendor/yajl/test/parsing/cases/codepoints_from_unicode_org.json.gold +2 -0
  103. data/ext/libyajl2/vendor/yajl/test/parsing/cases/deep_arrays.json +1 -0
  104. data/ext/libyajl2/vendor/yajl/test/parsing/cases/deep_arrays.json.gold +2049 -0
  105. data/ext/libyajl2/vendor/yajl/test/parsing/cases/difficult_json_c_test_case.json +1 -0
  106. data/ext/libyajl2/vendor/yajl/test/parsing/cases/difficult_json_c_test_case.json.gold +36 -0
  107. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles.json +1 -0
  108. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles.json.gold +7 -0
  109. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles_in_array.json +1 -0
  110. data/ext/libyajl2/vendor/yajl/test/parsing/cases/doubles_in_array.json.gold +8 -0
  111. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_array.json +1 -0
  112. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_array.json.gold +3 -0
  113. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_string.json +1 -0
  114. data/ext/libyajl2/vendor/yajl/test/parsing/cases/empty_string.json.gold +2 -0
  115. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_bulgarian.json +4 -0
  116. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_bulgarian.json.gold +7 -0
  117. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_foobar.json +1 -0
  118. data/ext/libyajl2/vendor/yajl/test/parsing/cases/escaped_foobar.json.gold +2 -0
  119. data/ext/libyajl2/vendor/yajl/test/parsing/cases/false.json +1 -0
  120. data/ext/libyajl2/vendor/yajl/test/parsing/cases/false.json.gold +2 -0
  121. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_false_then_garbage.json +1 -0
  122. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_false_then_garbage.json.gold +3 -0
  123. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_issue_7.json +1 -0
  124. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_issue_7.json.gold +3 -0
  125. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_null_then_garbage.json +1 -0
  126. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_null_then_garbage.json.gold +3 -0
  127. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_true_then_garbage.json +1 -0
  128. data/ext/libyajl2/vendor/yajl/test/parsing/cases/fg_true_then_garbage.json.gold +3 -0
  129. data/ext/libyajl2/vendor/yajl/test/parsing/cases/four_byte_utf8.json +2 -0
  130. data/ext/libyajl2/vendor/yajl/test/parsing/cases/four_byte_utf8.json.gold +5 -0
  131. data/ext/libyajl2/vendor/yajl/test/parsing/cases/high_overflow.json +1 -0
  132. data/ext/libyajl2/vendor/yajl/test/parsing/cases/high_overflow.json.gold +2 -0
  133. data/ext/libyajl2/vendor/yajl/test/parsing/cases/integers.json +3 -0
  134. data/ext/libyajl2/vendor/yajl/test/parsing/cases/integers.json.gold +14 -0
  135. data/ext/libyajl2/vendor/yajl/test/parsing/cases/invalid_utf8.json +1 -0
  136. data/ext/libyajl2/vendor/yajl/test/parsing/cases/invalid_utf8.json.gold +3 -0
  137. data/ext/libyajl2/vendor/yajl/test/parsing/cases/isolated_surrogate_marker.json +1 -0
  138. data/ext/libyajl2/vendor/yajl/test/parsing/cases/isolated_surrogate_marker.json.gold +2 -0
  139. data/ext/libyajl2/vendor/yajl/test/parsing/cases/leading_zero_in_number.json +1 -0
  140. data/ext/libyajl2/vendor/yajl/test/parsing/cases/leading_zero_in_number.json.gold +5 -0
  141. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_minus_sign.json +7 -0
  142. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_minus_sign.json.gold +9 -0
  143. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_number.json +1 -0
  144. data/ext/libyajl2/vendor/yajl/test/parsing/cases/lonely_number.json.gold +2 -0
  145. data/ext/libyajl2/vendor/yajl/test/parsing/cases/low_overflow.json +1 -0
  146. data/ext/libyajl2/vendor/yajl/test/parsing/cases/low_overflow.json.gold +2 -0
  147. data/ext/libyajl2/vendor/yajl/test/parsing/cases/map_close.json +1 -0
  148. data/ext/libyajl2/vendor/yajl/test/parsing/cases/map_close.json.gold +2 -0
  149. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_decimal_point.json +1 -0
  150. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_decimal_point.json.gold +2 -0
  151. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_exponent.json +1 -0
  152. data/ext/libyajl2/vendor/yajl/test/parsing/cases/missing_integer_after_exponent.json.gold +2 -0
  153. data/ext/libyajl2/vendor/yajl/test/parsing/cases/multiple.json +3 -0
  154. data/ext/libyajl2/vendor/yajl/test/parsing/cases/multiple.json.gold +4 -0
  155. data/ext/libyajl2/vendor/yajl/test/parsing/cases/non_utf8_char_in_string.json +1 -0
  156. data/ext/libyajl2/vendor/yajl/test/parsing/cases/non_utf8_char_in_string.json.gold +8 -0
  157. data/ext/libyajl2/vendor/yajl/test/parsing/cases/np_partial_bad.json +1 -0
  158. data/ext/libyajl2/vendor/yajl/test/parsing/cases/np_partial_bad.json.gold +5 -0
  159. data/ext/libyajl2/vendor/yajl/test/parsing/cases/null.json +1 -0
  160. data/ext/libyajl2/vendor/yajl/test/parsing/cases/null.json.gold +2 -0
  161. data/ext/libyajl2/vendor/yajl/test/parsing/cases/nulls_and_bools.json +5 -0
  162. data/ext/libyajl2/vendor/yajl/test/parsing/cases/nulls_and_bools.json.gold +9 -0
  163. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple.json +5 -0
  164. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple.json.gold +9 -0
  165. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple_with_comments.json +11 -0
  166. data/ext/libyajl2/vendor/yajl/test/parsing/cases/simple_with_comments.json.gold +5 -0
  167. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_escape.json +1 -0
  168. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_escape.json.gold +3 -0
  169. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_hex_char.json +1 -0
  170. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_invalid_hex_char.json.gold +2 -0
  171. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_escapes.json +3 -0
  172. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_escapes.json.gold +7 -0
  173. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_invalid_newline.json +2 -0
  174. data/ext/libyajl2/vendor/yajl/test/parsing/cases/string_with_invalid_newline.json.gold +2 -0
  175. data/ext/libyajl2/vendor/yajl/test/parsing/cases/three_byte_utf8.json +1 -0
  176. data/ext/libyajl2/vendor/yajl/test/parsing/cases/three_byte_utf8.json.gold +7 -0
  177. data/ext/libyajl2/vendor/yajl/test/parsing/cases/true.json +1 -0
  178. data/ext/libyajl2/vendor/yajl/test/parsing/cases/true.json.gold +2 -0
  179. data/ext/libyajl2/vendor/yajl/test/parsing/cases/unescaped_bulgarian.json +1 -0
  180. data/ext/libyajl2/vendor/yajl/test/parsing/cases/unescaped_bulgarian.json.gold +4 -0
  181. data/ext/libyajl2/vendor/yajl/test/parsing/cases/zerobyte.json +1 -0
  182. data/ext/libyajl2/vendor/yajl/test/parsing/cases/zerobyte.json.gold +0 -0
  183. data/ext/libyajl2/vendor/yajl/test/parsing/run_tests.sh +94 -0
  184. data/ext/libyajl2/vendor/yajl/test/parsing/yajl_test.c +291 -0
  185. data/ext/libyajl2/vendor/yajl/verify/CMakeLists.txt +37 -0
  186. data/ext/libyajl2/vendor/yajl/verify/json_verify.c +120 -0
  187. data/lib/libyajl2.rb +13 -0
  188. data/lib/libyajl2/version.rb +3 -0
  189. data/libyajl2.gemspec +29 -0
  190. data/spec/ffi_spec.rb +20 -0
  191. data/spec/path_spec.rb +15 -0
  192. data/spec/spec_helper.rb +13 -0
  193. metadata +296 -0
@@ -0,0 +1,186 @@
1
+ /*
2
+ * Copyright (c) 2010-2011 Florian Forster <ff at octo.it>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ /**
18
+ * \file yajl_tree.h
19
+ *
20
+ * Parses JSON data and returns the data in tree form.
21
+ *
22
+ * \author Florian Forster
23
+ * \date August 2010
24
+ *
25
+ * This interface makes quick parsing and extraction of
26
+ * smallish JSON docs trivial:
27
+ *
28
+ * \include example/parse_config.c
29
+ */
30
+
31
+ #ifndef YAJL_TREE_H
32
+ #define YAJL_TREE_H 1
33
+
34
+ #include <yajl/yajl_common.h>
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ /** possible data types that a yajl_val_s can hold */
41
+ typedef enum {
42
+ yajl_t_string = 1,
43
+ yajl_t_number = 2,
44
+ yajl_t_object = 3,
45
+ yajl_t_array = 4,
46
+ yajl_t_true = 5,
47
+ yajl_t_false = 6,
48
+ yajl_t_null = 7,
49
+ /** The any type isn't valid for yajl_val_s.type, but can be
50
+ * used as an argument to routines like yajl_tree_get().
51
+ */
52
+ yajl_t_any = 8
53
+ } yajl_type;
54
+
55
+ #define YAJL_NUMBER_INT_VALID 0x01
56
+ #define YAJL_NUMBER_DOUBLE_VALID 0x02
57
+
58
+ /** A pointer to a node in the parse tree */
59
+ typedef struct yajl_val_s * yajl_val;
60
+
61
+ /**
62
+ * A JSON value representation capable of holding one of the seven
63
+ * types above. For "string", "number", "object", and "array"
64
+ * additional data is available in the union. The "YAJL_IS_*"
65
+ * and "YAJL_GET_*" macros below allow type checking and convenient
66
+ * value extraction.
67
+ */
68
+ struct yajl_val_s
69
+ {
70
+ /** Type of the value contained. Use the "YAJL_IS_*" macros to check for a
71
+ * specific type. */
72
+ yajl_type type;
73
+ /** Type-specific data. You may use the "YAJL_GET_*" macros to access these
74
+ * members. */
75
+ union
76
+ {
77
+ char * string;
78
+ struct {
79
+ long long i; /*< integer value, if representable. */
80
+ double d; /*< double value, if representable. */
81
+ char *r; /*< unparsed number in string form. */
82
+ /** Signals whether the \em i and \em d members are
83
+ * valid. See \c YAJL_NUMBER_INT_VALID and
84
+ * \c YAJL_NUMBER_DOUBLE_VALID. */
85
+ unsigned int flags;
86
+ } number;
87
+ struct {
88
+ const char **keys; /*< Array of keys */
89
+ yajl_val *values; /*< Array of values. */
90
+ size_t len; /*< Number of key-value-pairs. */
91
+ } object;
92
+ struct {
93
+ yajl_val *values; /*< Array of elements. */
94
+ size_t len; /*< Number of elements. */
95
+ } array;
96
+ } u;
97
+ };
98
+
99
+ /**
100
+ * Parse a string.
101
+ *
102
+ * Parses an null-terminated string containing JSON data and returns a pointer
103
+ * to the top-level value (root of the parse tree).
104
+ *
105
+ * \param input Pointer to a null-terminated utf8 string containing
106
+ * JSON data.
107
+ * \param error_buffer Pointer to a buffer in which an error message will
108
+ * be stored if \em yajl_tree_parse fails, or
109
+ * \c NULL. The buffer will be initialized before
110
+ * parsing, so its content will be destroyed even if
111
+ * \em yajl_tree_parse succeeds.
112
+ * \param error_buffer_size Size of the memory area pointed to by
113
+ * \em error_buffer_size. If \em error_buffer_size is
114
+ * \c NULL, this argument is ignored.
115
+ *
116
+ * \returns Pointer to the top-level value or \c NULL on error. The memory
117
+ * pointed to must be freed using \em yajl_tree_free. In case of an error, a
118
+ * null terminated message describing the error in more detail is stored in
119
+ * \em error_buffer if it is not \c NULL.
120
+ */
121
+ YAJL_API yajl_val yajl_tree_parse (const char *input,
122
+ char *error_buffer, size_t error_buffer_size);
123
+
124
+
125
+ /**
126
+ * Free a parse tree returned by "yajl_tree_parse".
127
+ *
128
+ * \param v Pointer to a JSON value returned by "yajl_tree_parse". Passing NULL
129
+ * is valid and results in a no-op.
130
+ */
131
+ YAJL_API void yajl_tree_free (yajl_val v);
132
+
133
+ /**
134
+ * Access a nested value inside a tree.
135
+ *
136
+ * \param parent the node under which you'd like to extract values.
137
+ * \param path A null terminated array of strings, each the name of an object key
138
+ * \param type the yajl_type of the object you seek, or yajl_t_any if any will do.
139
+ *
140
+ * \returns a pointer to the found value, or NULL if we came up empty.
141
+ *
142
+ * Future Ideas: it'd be nice to move path to a string and implement support for
143
+ * a teeny tiny micro language here, so you can extract array elements, do things
144
+ * like .first and .last, even .length. Inspiration from JSONPath and css selectors?
145
+ * No it wouldn't be fast, but that's not what this API is about.
146
+ */
147
+ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
148
+
149
+ /* Various convenience macros to check the type of a `yajl_val` */
150
+ #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
151
+ #define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
152
+ #define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
153
+ #define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
154
+ #define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
155
+ #define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
156
+ #define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
157
+ #define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
158
+ #define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
159
+
160
+ /** Given a yajl_val_string return a ptr to the bare string it contains,
161
+ * or NULL if the value is not a string. */
162
+ #define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
163
+
164
+ /** Get the string representation of a number. You should check type first,
165
+ * perhaps using YAJL_IS_NUMBER */
166
+ #define YAJL_GET_NUMBER(v) ((v)->u.number.r)
167
+
168
+ /** Get the double representation of a number. You should check type first,
169
+ * perhaps using YAJL_IS_DOUBLE */
170
+ #define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
171
+
172
+ /** Get the 64bit (long long) integer representation of a number. You should
173
+ * check type first, perhaps using YAJL_IS_INTEGER */
174
+ #define YAJL_GET_INTEGER(v) ((v)->u.number.i)
175
+
176
+ /** Get a pointer to a yajl_val_object or NULL if the value is not an object. */
177
+ #define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
178
+
179
+ /** Get a pointer to a yajl_val_array or NULL if the value is not an object. */
180
+ #define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
181
+
182
+ #ifdef __cplusplus
183
+ }
184
+ #endif
185
+
186
+ #endif /* YAJL_TREE_H */
@@ -0,0 +1,23 @@
1
+ #ifndef YAJL_VERSION_H_
2
+ #define YAJL_VERSION_H_
3
+
4
+ #include <yajl/yajl_common.h>
5
+
6
+ #define YAJL_MAJOR ${YAJL_MAJOR}
7
+ #define YAJL_MINOR ${YAJL_MINOR}
8
+ #define YAJL_MICRO ${YAJL_MICRO}
9
+
10
+ #define YAJL_VERSION ((YAJL_MAJOR * 10000) + (YAJL_MINOR * 100) + YAJL_MICRO)
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ extern int YAJL_API yajl_version(void);
17
+
18
+ #ifdef __cplusplus
19
+ }
20
+ #endif
21
+
22
+ #endif /* YAJL_VERSION_H_ */
23
+
@@ -0,0 +1,33 @@
1
+ /**
2
+ \example reformatter/json_reformat.c
3
+ \example example/parse_config.c
4
+ */
5
+
6
+ /*!
7
+ \mainpage Yet Another JSON Library (YAJL)
8
+ \author Lloyd Hilaiel
9
+ \date 2007-2014
10
+
11
+ Yet Another JSON Library (YAJL) is a small event-driven (SAX-style)
12
+ JSON parser written in ANSI C, and a small validating JSON
13
+ generator. YAJL is released under the permissive ISC license.
14
+
15
+ \section features Features
16
+
17
+ -# Stream (incremental) parsing and generation of JSON
18
+ -# ANSI C
19
+ -# Human readable error messages with context
20
+ -# tiny
21
+ -# event driven
22
+ -# support for generating "beautified" JSON
23
+ -# includes
24
+ It also includes a small simplified tree interface for
25
+ simplified parsing and extraction of data from smallish JSON documents.
26
+
27
+ \section usage Usage
28
+
29
+ See <a href="reformatter_2json_reformat_8c-example.html">json_reformat.c</a> for a complete example of stream based parsing
30
+ and generation of JSON. See <a href="example_2parse_config_8c-example.html">parse_config.c</a> for an example of the
31
+ simplified tree interface.
32
+
33
+ */
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #include "api/yajl_parse.h"
18
+ #include "yajl_lex.h"
19
+ #include "yajl_parser.h"
20
+ #include "yajl_alloc.h"
21
+
22
+ #include <stdlib.h>
23
+ #include <string.h>
24
+ #include <stdarg.h>
25
+ #include <assert.h>
26
+
27
+ const char *
28
+ yajl_status_to_string(yajl_status stat)
29
+ {
30
+ const char * statStr = "unknown";
31
+ switch (stat) {
32
+ case yajl_status_ok:
33
+ statStr = "ok, no error";
34
+ break;
35
+ case yajl_status_client_canceled:
36
+ statStr = "client canceled parse";
37
+ break;
38
+ case yajl_status_error:
39
+ statStr = "parse error";
40
+ break;
41
+ }
42
+ return statStr;
43
+ }
44
+
45
+ yajl_handle
46
+ yajl_alloc(const yajl_callbacks * callbacks,
47
+ yajl_alloc_funcs * afs,
48
+ void * ctx)
49
+ {
50
+ yajl_handle hand = NULL;
51
+ yajl_alloc_funcs afsBuffer;
52
+
53
+ /* first order of business is to set up memory allocation routines */
54
+ if (afs != NULL) {
55
+ if (afs->malloc == NULL || afs->realloc == NULL || afs->free == NULL)
56
+ {
57
+ return NULL;
58
+ }
59
+ } else {
60
+ yajl_set_default_alloc_funcs(&afsBuffer);
61
+ afs = &afsBuffer;
62
+ }
63
+
64
+ hand = (yajl_handle) YA_MALLOC(afs, sizeof(struct yajl_handle_t));
65
+
66
+ /* copy in pointers to allocation routines */
67
+ memcpy((void *) &(hand->alloc), (void *) afs, sizeof(yajl_alloc_funcs));
68
+
69
+ hand->callbacks = callbacks;
70
+ hand->ctx = ctx;
71
+ hand->lexer = NULL;
72
+ hand->bytesConsumed = 0;
73
+ hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
74
+ hand->flags = 0;
75
+ yajl_bs_init(hand->stateStack, &(hand->alloc));
76
+ yajl_bs_push(hand->stateStack, yajl_state_start);
77
+
78
+ return hand;
79
+ }
80
+
81
+ int
82
+ yajl_config(yajl_handle h, yajl_option opt, ...)
83
+ {
84
+ int rv = 1;
85
+ va_list ap;
86
+ va_start(ap, opt);
87
+
88
+ switch(opt) {
89
+ case yajl_allow_comments:
90
+ case yajl_dont_validate_strings:
91
+ case yajl_allow_trailing_garbage:
92
+ case yajl_allow_multiple_values:
93
+ case yajl_allow_partial_values:
94
+ if (va_arg(ap, int)) h->flags |= opt;
95
+ else h->flags &= ~opt;
96
+ break;
97
+ default:
98
+ rv = 0;
99
+ }
100
+ va_end(ap);
101
+
102
+ return rv;
103
+ }
104
+
105
+ void
106
+ yajl_free(yajl_handle handle)
107
+ {
108
+ yajl_bs_free(handle->stateStack);
109
+ yajl_buf_free(handle->decodeBuf);
110
+ if (handle->lexer) {
111
+ yajl_lex_free(handle->lexer);
112
+ handle->lexer = NULL;
113
+ }
114
+ YA_FREE(&(handle->alloc), handle);
115
+ }
116
+
117
+ yajl_status
118
+ yajl_parse(yajl_handle hand, const unsigned char * jsonText,
119
+ size_t jsonTextLen)
120
+ {
121
+ yajl_status status;
122
+
123
+ /* lazy allocation of the lexer */
124
+ if (hand->lexer == NULL) {
125
+ hand->lexer = yajl_lex_alloc(&(hand->alloc),
126
+ hand->flags & yajl_allow_comments,
127
+ !(hand->flags & yajl_dont_validate_strings));
128
+ }
129
+
130
+ status = yajl_do_parse(hand, jsonText, jsonTextLen);
131
+ return status;
132
+ }
133
+
134
+
135
+ yajl_status
136
+ yajl_complete_parse(yajl_handle hand)
137
+ {
138
+ /* The lexer is lazy allocated in the first call to parse. if parse is
139
+ * never called, then no data was provided to parse at all. This is a
140
+ * "premature EOF" error unless yajl_allow_partial_values is specified.
141
+ * allocating the lexer now is the simplest possible way to handle this
142
+ * case while preserving all the other semantics of the parser
143
+ * (multiple values, partial values, etc). */
144
+ if (hand->lexer == NULL) {
145
+ hand->lexer = yajl_lex_alloc(&(hand->alloc),
146
+ hand->flags & yajl_allow_comments,
147
+ !(hand->flags & yajl_dont_validate_strings));
148
+ }
149
+
150
+ return yajl_do_finish(hand);
151
+ }
152
+
153
+ unsigned char *
154
+ yajl_get_error(yajl_handle hand, int verbose,
155
+ const unsigned char * jsonText, size_t jsonTextLen)
156
+ {
157
+ return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose);
158
+ }
159
+
160
+ size_t
161
+ yajl_get_bytes_consumed(yajl_handle hand)
162
+ {
163
+ if (!hand) return 0;
164
+ else return hand->bytesConsumed;
165
+ }
166
+
167
+
168
+ void
169
+ yajl_free_error(yajl_handle hand, unsigned char * str)
170
+ {
171
+ /* use memory allocation functions if set */
172
+ YA_FREE(&(hand->alloc), str);
173
+ }
174
+
175
+ /* XXX: add utility routines to parse from file */
@@ -0,0 +1,9 @@
1
+ prefix=${CMAKE_INSTALL_PREFIX}
2
+ libdir=${dollar}{prefix}/lib${LIB_SUFFIX}
3
+ includedir=${dollar}{prefix}/include/yajl
4
+
5
+ Name: Yet Another JSON Library
6
+ Description: A Portable JSON parsing and serialization library in ANSI C
7
+ Version: ${YAJL_MAJOR}.${YAJL_MINOR}.${YAJL_MICRO}
8
+ Cflags: -I${dollar}{includedir}
9
+ Libs: -L${dollar}{libdir} -lyajl
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright (c) 2007-2014, Lloyd Hilaiel <me@lloyd.io>
3
+ *
4
+ * Permission to use, copy, modify, and/or distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ /**
18
+ * \file yajl_alloc.h
19
+ * default memory allocation routines for yajl which use malloc/realloc and
20
+ * free
21
+ */
22
+
23
+ #include "yajl_alloc.h"
24
+ #include <stdlib.h>
25
+
26
+ static void * yajl_internal_malloc(void *ctx, size_t sz)
27
+ {
28
+ (void)ctx;
29
+ return malloc(sz);
30
+ }
31
+
32
+ static void * yajl_internal_realloc(void *ctx, void * previous,
33
+ size_t sz)
34
+ {
35
+ (void)ctx;
36
+ return realloc(previous, sz);
37
+ }
38
+
39
+ static void yajl_internal_free(void *ctx, void * ptr)
40
+ {
41
+ (void)ctx;
42
+ free(ptr);
43
+ }
44
+
45
+ void yajl_set_default_alloc_funcs(yajl_alloc_funcs * yaf)
46
+ {
47
+ yaf->malloc = yajl_internal_malloc;
48
+ yaf->free = yajl_internal_free;
49
+ yaf->realloc = yajl_internal_realloc;
50
+ yaf->ctx = NULL;
51
+ }
52
+