ffi-yajl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +201 -0
  3. data/README.md +17 -0
  4. data/Rakefile +62 -0
  5. data/bin/ffi-yajl-bench +36 -0
  6. data/ext/ffi_yajl/ext/encoder/encoder.c +240 -0
  7. data/ext/ffi_yajl/ext/encoder/extconf.rb +29 -0
  8. data/ext/ffi_yajl/ext/parser/extconf.rb +29 -0
  9. data/ext/ffi_yajl/ext/parser/parser.c +199 -0
  10. data/ext/libyajl2/extconf.rb +65 -0
  11. data/ext/libyajl2/vendored/.gitignore +3 -0
  12. data/ext/libyajl2/vendored/BUILDING +23 -0
  13. data/ext/libyajl2/vendored/BUILDING.win32 +27 -0
  14. data/ext/libyajl2/vendored/CMakeLists.txt +79 -0
  15. data/ext/libyajl2/vendored/COPYING +13 -0
  16. data/ext/libyajl2/vendored/ChangeLog +175 -0
  17. data/ext/libyajl2/vendored/README +74 -0
  18. data/ext/libyajl2/vendored/TODO +9 -0
  19. data/ext/libyajl2/vendored/YAJLDoc.cmake +26 -0
  20. data/ext/libyajl2/vendored/configure +79 -0
  21. data/ext/libyajl2/vendored/example/CMakeLists.txt +23 -0
  22. data/ext/libyajl2/vendored/example/README.md +7 -0
  23. data/ext/libyajl2/vendored/example/parse_config.c +69 -0
  24. data/ext/libyajl2/vendored/example/sample.config +101 -0
  25. data/ext/libyajl2/vendored/perf/CMakeLists.txt +23 -0
  26. data/ext/libyajl2/vendored/perf/documents.c +1418 -0
  27. data/ext/libyajl2/vendored/perf/documents.h +28 -0
  28. data/ext/libyajl2/vendored/perf/perftest.c +134 -0
  29. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +39 -0
  30. data/ext/libyajl2/vendored/reformatter/json_reformat.c +194 -0
  31. data/ext/libyajl2/vendored/src/CMakeLists.txt +86 -0
  32. data/ext/libyajl2/vendored/src/YAJL.dxy +1258 -0
  33. data/ext/libyajl2/vendored/src/api/yajl_common.h +75 -0
  34. data/ext/libyajl2/vendored/src/api/yajl_gen.h +157 -0
  35. data/ext/libyajl2/vendored/src/api/yajl_parse.h +226 -0
  36. data/ext/libyajl2/vendored/src/api/yajl_tree.h +185 -0
  37. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +23 -0
  38. data/ext/libyajl2/vendored/src/yajl +33 -0
  39. data/ext/libyajl2/vendored/src/yajl.c +175 -0
  40. data/ext/libyajl2/vendored/src/yajl.pc.cmake +9 -0
  41. data/ext/libyajl2/vendored/src/yajl_alloc.c +52 -0
  42. data/ext/libyajl2/vendored/src/yajl_alloc.h +34 -0
  43. data/ext/libyajl2/vendored/src/yajl_buf.c +103 -0
  44. data/ext/libyajl2/vendored/src/yajl_buf.h +57 -0
  45. data/ext/libyajl2/vendored/src/yajl_bytestack.h +69 -0
  46. data/ext/libyajl2/vendored/src/yajl_encode.c +220 -0
  47. data/ext/libyajl2/vendored/src/yajl_encode.h +34 -0
  48. data/ext/libyajl2/vendored/src/yajl_gen.c +354 -0
  49. data/ext/libyajl2/vendored/src/yajl_lex.c +763 -0
  50. data/ext/libyajl2/vendored/src/yajl_lex.h +117 -0
  51. data/ext/libyajl2/vendored/src/yajl_parser.c +498 -0
  52. data/ext/libyajl2/vendored/src/yajl_parser.h +78 -0
  53. data/ext/libyajl2/vendored/src/yajl_tree.c +503 -0
  54. data/ext/libyajl2/vendored/src/yajl_version.c +7 -0
  55. data/ext/libyajl2/vendored/test/CMakeLists.txt +23 -0
  56. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +1 -0
  57. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +36 -0
  58. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +11 -0
  59. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +9 -0
  60. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +1 -0
  61. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +2 -0
  62. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +1 -0
  63. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +2 -0
  64. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +1 -0
  65. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +2 -0
  66. data/ext/libyajl2/vendored/test/cases/am_eof.json +1 -0
  67. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +4 -0
  68. data/ext/libyajl2/vendored/test/cases/am_integers.json +1 -0
  69. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +3 -0
  70. data/ext/libyajl2/vendored/test/cases/am_multiple.json +3 -0
  71. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +5 -0
  72. data/ext/libyajl2/vendored/test/cases/am_stuff.json +7 -0
  73. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +14 -0
  74. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +1 -0
  75. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +2 -0
  76. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +1 -0
  77. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +1 -0
  78. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +1 -0
  79. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +2 -0
  80. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +1 -0
  81. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +4 -0
  82. data/ext/libyajl2/vendored/test/cases/array.json +6 -0
  83. data/ext/libyajl2/vendored/test/cases/array.json.gold +22 -0
  84. data/ext/libyajl2/vendored/test/cases/array_close.json +1 -0
  85. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +2 -0
  86. data/ext/libyajl2/vendored/test/cases/bignums.json +1 -0
  87. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +5 -0
  88. data/ext/libyajl2/vendored/test/cases/bogus_char.json +4 -0
  89. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +10 -0
  90. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +1 -0
  91. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +2 -0
  92. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +1 -0
  93. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +2049 -0
  94. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +1 -0
  95. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +36 -0
  96. data/ext/libyajl2/vendored/test/cases/doubles.json +1 -0
  97. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +7 -0
  98. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +1 -0
  99. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +8 -0
  100. data/ext/libyajl2/vendored/test/cases/empty_array.json +1 -0
  101. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +3 -0
  102. data/ext/libyajl2/vendored/test/cases/empty_string.json +1 -0
  103. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +2 -0
  104. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +4 -0
  105. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +7 -0
  106. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +1 -0
  107. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +2 -0
  108. data/ext/libyajl2/vendored/test/cases/false.json +1 -0
  109. data/ext/libyajl2/vendored/test/cases/false.json.gold +2 -0
  110. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +1 -0
  111. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +3 -0
  112. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +1 -0
  113. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +3 -0
  114. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +1 -0
  115. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +3 -0
  116. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +1 -0
  117. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +3 -0
  118. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +2 -0
  119. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +5 -0
  120. data/ext/libyajl2/vendored/test/cases/high_overflow.json +1 -0
  121. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +2 -0
  122. data/ext/libyajl2/vendored/test/cases/integers.json +3 -0
  123. data/ext/libyajl2/vendored/test/cases/integers.json.gold +14 -0
  124. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +1 -0
  125. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +3 -0
  126. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +1 -0
  127. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +2 -0
  128. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +1 -0
  129. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +5 -0
  130. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +7 -0
  131. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +9 -0
  132. data/ext/libyajl2/vendored/test/cases/lonely_number.json +1 -0
  133. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +2 -0
  134. data/ext/libyajl2/vendored/test/cases/low_overflow.json +1 -0
  135. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +2 -0
  136. data/ext/libyajl2/vendored/test/cases/map_close.json +1 -0
  137. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +2 -0
  138. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +1 -0
  139. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +2 -0
  140. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +1 -0
  141. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +2 -0
  142. data/ext/libyajl2/vendored/test/cases/multiple.json +3 -0
  143. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +4 -0
  144. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +1 -0
  145. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +8 -0
  146. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +1 -0
  147. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +5 -0
  148. data/ext/libyajl2/vendored/test/cases/null.json +1 -0
  149. data/ext/libyajl2/vendored/test/cases/null.json.gold +2 -0
  150. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +5 -0
  151. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +9 -0
  152. data/ext/libyajl2/vendored/test/cases/simple.json +5 -0
  153. data/ext/libyajl2/vendored/test/cases/simple.json.gold +9 -0
  154. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +11 -0
  155. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +5 -0
  156. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +1 -0
  157. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +3 -0
  158. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +1 -0
  159. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +2 -0
  160. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +3 -0
  161. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +7 -0
  162. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +2 -0
  163. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +2 -0
  164. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +1 -0
  165. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +7 -0
  166. data/ext/libyajl2/vendored/test/cases/true.json +1 -0
  167. data/ext/libyajl2/vendored/test/cases/true.json.gold +2 -0
  168. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +1 -0
  169. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +4 -0
  170. data/ext/libyajl2/vendored/test/cases/zerobyte.json +1 -0
  171. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  172. data/ext/libyajl2/vendored/test/run_tests.sh +94 -0
  173. data/ext/libyajl2/vendored/test/yajl_test.c +281 -0
  174. data/ext/libyajl2/vendored/verify/CMakeLists.txt +39 -0
  175. data/ext/libyajl2/vendored/verify/json_verify.c +116 -0
  176. data/lib/ffi_yajl.rb +14 -0
  177. data/lib/ffi_yajl/benchmark.rb +7 -0
  178. data/lib/ffi_yajl/benchmark/MIT-LICENSE +20 -0
  179. data/lib/ffi_yajl/benchmark/encode.rb +135 -0
  180. data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +42 -0
  181. data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +53 -0
  182. data/lib/ffi_yajl/benchmark/encode_profile.rb +38 -0
  183. data/lib/ffi_yajl/benchmark/http.rb +32 -0
  184. data/lib/ffi_yajl/benchmark/parse.rb +133 -0
  185. data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +50 -0
  186. data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +55 -0
  187. data/lib/ffi_yajl/benchmark/parse_profile.rb +37 -0
  188. data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +39 -0
  189. data/lib/ffi_yajl/benchmark/parse_stream.rb +54 -0
  190. data/lib/ffi_yajl/benchmark/subjects/item.json +1 -0
  191. data/lib/ffi_yajl/benchmark/subjects/ohai.json +1216 -0
  192. data/lib/ffi_yajl/benchmark/subjects/ohai.marshal_dump +0 -0
  193. data/lib/ffi_yajl/benchmark/subjects/ohai.yml +975 -0
  194. data/lib/ffi_yajl/benchmark/subjects/twitter_search.json +1 -0
  195. data/lib/ffi_yajl/benchmark/subjects/twitter_stream.json +430 -0
  196. data/lib/ffi_yajl/benchmark/subjects/unicode.json +1 -0
  197. data/lib/ffi_yajl/encoder.rb +53 -0
  198. data/lib/ffi_yajl/ext.rb +22 -0
  199. data/lib/ffi_yajl/ext/.keep +0 -0
  200. data/lib/ffi_yajl/ffi.rb +129 -0
  201. data/lib/ffi_yajl/ffi/encoder.rb +175 -0
  202. data/lib/ffi_yajl/ffi/parser.rb +145 -0
  203. data/lib/ffi_yajl/json_gem.rb +121 -0
  204. data/lib/ffi_yajl/parser.rb +23 -0
  205. data/lib/ffi_yajl/version.rb +3 -0
  206. data/lib/libyajl.so +0 -0
  207. data/lib/libyajl.so.2 +0 -0
  208. data/lib/libyajl.so.2.0.5 +0 -0
  209. data/lib/libyajl_s.a +0 -0
  210. data/spec/ffi_yajl/encoder_spec.rb +39 -0
  211. data/spec/ffi_yajl/json_gem_spec.rb +355 -0
  212. data/spec/ffi_yajl/parser_spec.rb +78 -0
  213. data/spec/spec_helper.rb +14 -0
  214. metadata +332 -0
@@ -0,0 +1,75 @@
1
+ /*
2
+ * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
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,157 @@
1
+ /*
2
+ * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
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
+ #ifdef __cplusplus
154
+ }
155
+ #endif
156
+
157
+ #endif
@@ -0,0 +1,226 @@
1
+ /*
2
+ * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
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