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,75 @@
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
+ #ifndef __YAJL_COMMON_H__
18
+ #define __YAJL_COMMON_H__
19
+
20
+ #include <stddef.h>
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ #define YAJL_MAX_DEPTH 128
27
+
28
+ /* msft dll export gunk. To build a DLL on windows, you
29
+ * must define WIN32, YAJL_SHARED, and YAJL_BUILD. To use a shared
30
+ * DLL, you must define YAJL_SHARED and WIN32 */
31
+ #if (defined(_WIN32) || defined(WIN32)) && defined(YAJL_SHARED)
32
+ # ifdef YAJL_BUILD
33
+ # define YAJL_API __declspec(dllexport)
34
+ # else
35
+ # define YAJL_API __declspec(dllimport)
36
+ # endif
37
+ #else
38
+ # if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303
39
+ # define YAJL_API __attribute__ ((visibility("default")))
40
+ # else
41
+ # define YAJL_API
42
+ # endif
43
+ #endif
44
+
45
+ /** pointer to a malloc function, supporting client overriding memory
46
+ * allocation routines */
47
+ typedef void * (*yajl_malloc_func)(void *ctx, size_t sz);
48
+
49
+ /** pointer to a free function, supporting client overriding memory
50
+ * allocation routines */
51
+ typedef void (*yajl_free_func)(void *ctx, void * ptr);
52
+
53
+ /** pointer to a realloc function which can resize an allocation. */
54
+ typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz);
55
+
56
+ /** A structure which can be passed to yajl_*_alloc routines to allow the
57
+ * client to specify memory allocation functions to be used. */
58
+ typedef struct
59
+ {
60
+ /** pointer to a function that can allocate uninitialized memory */
61
+ yajl_malloc_func malloc;
62
+ /** pointer to a function that can resize memory allocations */
63
+ yajl_realloc_func realloc;
64
+ /** pointer to a function that can free memory allocated using
65
+ * reallocFunction or mallocFunction */
66
+ yajl_free_func free;
67
+ /** a context pointer that will be passed to above allocation routines */
68
+ void * ctx;
69
+ } yajl_alloc_funcs;
70
+
71
+ #ifdef __cplusplus
72
+ }
73
+ #endif
74
+
75
+ #endif
@@ -0,0 +1,167 @@
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_gen.h
19
+ * Interface to YAJL's JSON generation facilities.
20
+ */
21
+
22
+ #include <yajl/yajl_common.h>
23
+
24
+ #ifndef __YAJL_GEN_H__
25
+ #define __YAJL_GEN_H__
26
+
27
+ #include <stddef.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+ /** generator status codes */
33
+ typedef enum {
34
+ /** no error */
35
+ yajl_gen_status_ok = 0,
36
+ /** at a point where a map key is generated, a function other than
37
+ * yajl_gen_string was called */
38
+ yajl_gen_keys_must_be_strings,
39
+ /** YAJL's maximum generation depth was exceeded. see
40
+ * YAJL_MAX_DEPTH */
41
+ yajl_max_depth_exceeded,
42
+ /** A generator function (yajl_gen_XXX) was called while in an error
43
+ * state */
44
+ yajl_gen_in_error_state,
45
+ /** A complete JSON document has been generated */
46
+ yajl_gen_generation_complete,
47
+ /** yajl_gen_double was passed an invalid floating point value
48
+ * (infinity or NaN). */
49
+ yajl_gen_invalid_number,
50
+ /** A print callback was passed in, so there is no internal
51
+ * buffer to get from */
52
+ yajl_gen_no_buf,
53
+ /** returned from yajl_gen_string() when the yajl_gen_validate_utf8
54
+ * option is enabled and an invalid was passed by client code.
55
+ */
56
+ yajl_gen_invalid_string
57
+ } yajl_gen_status;
58
+
59
+ /** an opaque handle to a generator */
60
+ typedef struct yajl_gen_t * yajl_gen;
61
+
62
+ /** a callback used for "printing" the results. */
63
+ typedef void (*yajl_print_t)(void * ctx,
64
+ const char * str,
65
+ size_t len);
66
+
67
+ /** configuration parameters for the parser, these may be passed to
68
+ * yajl_gen_config() along with option specific argument(s). In general,
69
+ * all configuration parameters default to *off*. */
70
+ typedef enum {
71
+ /** generate indented (beautiful) output */
72
+ yajl_gen_beautify = 0x01,
73
+ /**
74
+ * Set an indent string which is used when yajl_gen_beautify
75
+ * is enabled. Maybe something like \\t or some number of
76
+ * spaces. The default is four spaces ' '.
77
+ */
78
+ yajl_gen_indent_string = 0x02,
79
+ /**
80
+ * Set a function and context argument that should be used to
81
+ * output generated json. the function should conform to the
82
+ * yajl_print_t prototype while the context argument is a
83
+ * void * of your choosing.
84
+ *
85
+ * example:
86
+ * yajl_gen_config(g, yajl_gen_print_callback, myFunc, myVoidPtr);
87
+ */
88
+ yajl_gen_print_callback = 0x04,
89
+ /**
90
+ * Normally the generator does not validate that strings you
91
+ * pass to it via yajl_gen_string() are valid UTF8. Enabling
92
+ * this option will cause it to do so.
93
+ */
94
+ yajl_gen_validate_utf8 = 0x08,
95
+ /**
96
+ * the forward solidus (slash or '/' in human) is not required to be
97
+ * escaped in json text. By default, YAJL will not escape it in the
98
+ * iterest of saving bytes. Setting this flag will cause YAJL to
99
+ * always escape '/' in generated JSON strings.
100
+ */
101
+ yajl_gen_escape_solidus = 0x10
102
+ } yajl_gen_option;
103
+
104
+ /** allow the modification of generator options subsequent to handle
105
+ * allocation (via yajl_alloc)
106
+ * \returns zero in case of errors, non-zero otherwise
107
+ */
108
+ YAJL_API int yajl_gen_config(yajl_gen g, yajl_gen_option opt, ...);
109
+
110
+ /** allocate a generator handle
111
+ * \param allocFuncs an optional pointer to a structure which allows
112
+ * the client to overide the memory allocation
113
+ * used by yajl. May be NULL, in which case
114
+ * malloc/free/realloc will be used.
115
+ *
116
+ * \returns an allocated handle on success, NULL on failure (bad params)
117
+ */
118
+ YAJL_API yajl_gen yajl_gen_alloc(const yajl_alloc_funcs * allocFuncs);
119
+
120
+ /** free a generator handle */
121
+ YAJL_API void yajl_gen_free(yajl_gen handle);
122
+
123
+ YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long long int number);
124
+ /** generate a floating point number. number may not be infinity or
125
+ * NaN, as these have no representation in JSON. In these cases the
126
+ * generator will return 'yajl_gen_invalid_number' */
127
+ YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number);
128
+ YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand,
129
+ const char * num,
130
+ size_t len);
131
+ YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand,
132
+ const unsigned char * str,
133
+ size_t len);
134
+ YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
135
+ YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);
136
+ YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
137
+ YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
138
+ YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
139
+ YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand);
140
+
141
+ /** access the null terminated generator buffer. If incrementally
142
+ * outputing JSON, one should call yajl_gen_clear to clear the
143
+ * buffer. This allows stream generation. */
144
+ YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
145
+ const unsigned char ** buf,
146
+ size_t * len);
147
+
148
+ /** clear yajl's output buffer, but maintain all internal generation
149
+ * state. This function will not "reset" the generator state, and is
150
+ * intended to enable incremental JSON outputing. */
151
+ YAJL_API void yajl_gen_clear(yajl_gen hand);
152
+
153
+ /** Reset the generator state. Allows a client to generate multiple
154
+ * json entities in a stream. The "sep" string will be inserted to
155
+ * separate the previously generated entity from the current,
156
+ * NULL means *no separation* of entites (clients beware, generating
157
+ * multiple JSON numbers without a separator, for instance, will result in ambiguous output)
158
+ *
159
+ * Note: this call will not clear yajl's output buffer. This
160
+ * may be accomplished explicitly by calling yajl_gen_clear() */
161
+ YAJL_API void yajl_gen_reset(yajl_gen hand, const char * sep);
162
+
163
+ #ifdef __cplusplus
164
+ }
165
+ #endif
166
+
167
+ #endif
@@ -0,0 +1,226 @@
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_parse.h
19
+ * Interface to YAJL's JSON stream parsing facilities.
20
+ */
21
+
22
+ #include <yajl/yajl_common.h>
23
+
24
+ #ifndef __YAJL_PARSE_H__
25
+ #define __YAJL_PARSE_H__
26
+
27
+ #include <stddef.h>
28
+
29
+ #ifdef __cplusplus
30
+ extern "C" {
31
+ #endif
32
+ /** error codes returned from this interface */
33
+ typedef enum {
34
+ /** no error was encountered */
35
+ yajl_status_ok,
36
+ /** a client callback returned zero, stopping the parse */
37
+ yajl_status_client_canceled,
38
+ /** An error occured during the parse. Call yajl_get_error for
39
+ * more information about the encountered error */
40
+ yajl_status_error
41
+ } yajl_status;
42
+
43
+ /** attain a human readable, english, string for an error */
44
+ YAJL_API const char * yajl_status_to_string(yajl_status code);
45
+
46
+ /** an opaque handle to a parser */
47
+ typedef struct yajl_handle_t * yajl_handle;
48
+
49
+ /** yajl is an event driven parser. this means as json elements are
50
+ * parsed, you are called back to do something with the data. The
51
+ * functions in this table indicate the various events for which
52
+ * you will be called back. Each callback accepts a "context"
53
+ * pointer, this is a void * that is passed into the yajl_parse
54
+ * function which the client code may use to pass around context.
55
+ *
56
+ * All callbacks return an integer. If non-zero, the parse will
57
+ * continue. If zero, the parse will be canceled and
58
+ * yajl_status_client_canceled will be returned from the parse.
59
+ *
60
+ * \attention {
61
+ * A note about the handling of numbers:
62
+ *
63
+ * yajl will only convert numbers that can be represented in a
64
+ * double or a 64 bit (long long) int. All other numbers will
65
+ * be passed to the client in string form using the yajl_number
66
+ * callback. Furthermore, if yajl_number is not NULL, it will
67
+ * always be used to return numbers, that is yajl_integer and
68
+ * yajl_double will be ignored. If yajl_number is NULL but one
69
+ * of yajl_integer or yajl_double are defined, parsing of a
70
+ * number larger than is representable in a double or 64 bit
71
+ * integer will result in a parse error.
72
+ * }
73
+ */
74
+ typedef struct {
75
+ int (* yajl_null)(void * ctx);
76
+ int (* yajl_boolean)(void * ctx, int boolVal);
77
+ int (* yajl_integer)(void * ctx, long long integerVal);
78
+ int (* yajl_double)(void * ctx, double doubleVal);
79
+ /** A callback which passes the string representation of the number
80
+ * back to the client. Will be used for all numbers when present */
81
+ int (* yajl_number)(void * ctx, const char * numberVal,
82
+ size_t numberLen);
83
+
84
+ /** strings are returned as pointers into the JSON text when,
85
+ * possible, as a result, they are _not_ null padded */
86
+ int (* yajl_string)(void * ctx, const unsigned char * stringVal,
87
+ size_t stringLen);
88
+
89
+ int (* yajl_start_map)(void * ctx);
90
+ int (* yajl_map_key)(void * ctx, const unsigned char * key,
91
+ size_t stringLen);
92
+ int (* yajl_end_map)(void * ctx);
93
+
94
+ int (* yajl_start_array)(void * ctx);
95
+ int (* yajl_end_array)(void * ctx);
96
+ } yajl_callbacks;
97
+
98
+ /** allocate a parser handle
99
+ * \param callbacks a yajl callbacks structure specifying the
100
+ * functions to call when different JSON entities
101
+ * are encountered in the input text. May be NULL,
102
+ * which is only useful for validation.
103
+ * \param afs memory allocation functions, may be NULL for to use
104
+ * C runtime library routines (malloc and friends)
105
+ * \param ctx a context pointer that will be passed to callbacks.
106
+ */
107
+ YAJL_API yajl_handle yajl_alloc(const yajl_callbacks * callbacks,
108
+ yajl_alloc_funcs * afs,
109
+ void * ctx);
110
+
111
+
112
+ /** configuration parameters for the parser, these may be passed to
113
+ * yajl_config() along with option specific argument(s). In general,
114
+ * all configuration parameters default to *off*. */
115
+ typedef enum {
116
+ /** Ignore javascript style comments present in
117
+ * JSON input. Non-standard, but rather fun
118
+ * arguments: toggled off with integer zero, on otherwise.
119
+ *
120
+ * example:
121
+ * yajl_config(h, yajl_allow_comments, 1); // turn comment support on
122
+ */
123
+ yajl_allow_comments = 0x01,
124
+ /**
125
+ * When set the parser will verify that all strings in JSON input are
126
+ * valid UTF8 and will emit a parse error if this is not so. When set,
127
+ * this option makes parsing slightly more expensive (~7% depending
128
+ * on processor and compiler in use)
129
+ *
130
+ * example:
131
+ * yajl_config(h, yajl_dont_validate_strings, 1); // disable utf8 checking
132
+ */
133
+ yajl_dont_validate_strings = 0x02,
134
+ /**
135
+ * By default, upon calls to yajl_complete_parse(), yajl will
136
+ * ensure the entire input text was consumed and will raise an error
137
+ * otherwise. Enabling this flag will cause yajl to disable this
138
+ * check. This can be useful when parsing json out of a that contains more
139
+ * than a single JSON document.
140
+ */
141
+ yajl_allow_trailing_garbage = 0x04,
142
+ /**
143
+ * Allow multiple values to be parsed by a single handle. The
144
+ * entire text must be valid JSON, and values can be seperated
145
+ * by any kind of whitespace. This flag will change the
146
+ * behavior of the parser, and cause it continue parsing after
147
+ * a value is parsed, rather than transitioning into a
148
+ * complete state. This option can be useful when parsing multiple
149
+ * values from an input stream.
150
+ */
151
+ yajl_allow_multiple_values = 0x08,
152
+ /**
153
+ * When yajl_complete_parse() is called the parser will
154
+ * check that the top level value was completely consumed. I.E.,
155
+ * if called whilst in the middle of parsing a value
156
+ * yajl will enter an error state (premature EOF). Setting this
157
+ * flag suppresses that check and the corresponding error.
158
+ */
159
+ yajl_allow_partial_values = 0x10
160
+ } yajl_option;
161
+
162
+ /** allow the modification of parser options subsequent to handle
163
+ * allocation (via yajl_alloc)
164
+ * \returns zero in case of errors, non-zero otherwise
165
+ */
166
+ YAJL_API int yajl_config(yajl_handle h, yajl_option opt, ...);
167
+
168
+ /** free a parser handle */
169
+ YAJL_API void yajl_free(yajl_handle handle);
170
+
171
+ /** Parse some json!
172
+ * \param hand - a handle to the json parser allocated with yajl_alloc
173
+ * \param jsonText - a pointer to the UTF8 json text to be parsed
174
+ * \param jsonTextLength - the length, in bytes, of input text
175
+ */
176
+ YAJL_API yajl_status yajl_parse(yajl_handle hand,
177
+ const unsigned char * jsonText,
178
+ size_t jsonTextLength);
179
+
180
+ /** Parse any remaining buffered json.
181
+ * Since yajl is a stream-based parser, without an explicit end of
182
+ * input, yajl sometimes can't decide if content at the end of the
183
+ * stream is valid or not. For example, if "1" has been fed in,
184
+ * yajl can't know whether another digit is next or some character
185
+ * that would terminate the integer token.
186
+ *
187
+ * \param hand - a handle to the json parser allocated with yajl_alloc
188
+ */
189
+ YAJL_API yajl_status yajl_complete_parse(yajl_handle hand);
190
+
191
+ /** get an error string describing the state of the
192
+ * parse.
193
+ *
194
+ * If verbose is non-zero, the message will include the JSON
195
+ * text where the error occured, along with an arrow pointing to
196
+ * the specific char.
197
+ *
198
+ * \returns A dynamically allocated string will be returned which should
199
+ * be freed with yajl_free_error
200
+ */
201
+ YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose,
202
+ const unsigned char * jsonText,
203
+ size_t jsonTextLength);
204
+
205
+ /**
206
+ * get the amount of data consumed from the last chunk passed to YAJL.
207
+ *
208
+ * In the case of a successful parse this can help you understand if
209
+ * the entire buffer was consumed (which will allow you to handle
210
+ * "junk at end of input").
211
+ *
212
+ * In the event an error is encountered during parsing, this function
213
+ * affords the client a way to get the offset into the most recent
214
+ * chunk where the error occured. 0 will be returned if no error
215
+ * was encountered.
216
+ */
217
+ YAJL_API size_t yajl_get_bytes_consumed(yajl_handle hand);
218
+
219
+ /** free an error returned from yajl_get_error */
220
+ YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str);
221
+
222
+ #ifdef __cplusplus
223
+ }
224
+ #endif
225
+
226
+ #endif