ffi-yajl 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +114 -30
  3. data/ext/ffi_yajl/ext/encoder/extconf.rb +5 -5
  4. data/ext/ffi_yajl/ext/parser/extconf.rb +5 -5
  5. data/lib/ffi_yajl/ffi.rb +2 -1
  6. data/lib/ffi_yajl/version.rb +1 -1
  7. data/spec/ffi_yajl/encoder_spec.rb +6 -6
  8. data/spec/ffi_yajl/json_gem_spec.rb +13 -13
  9. data/spec/ffi_yajl/parser_spec.rb +9 -9
  10. metadata +16 -174
  11. data/ext/libyajl2/extconf.rb +0 -60
  12. data/ext/libyajl2/vendored/.gitignore +0 -3
  13. data/ext/libyajl2/vendored/BUILDING +0 -23
  14. data/ext/libyajl2/vendored/BUILDING.win32 +0 -27
  15. data/ext/libyajl2/vendored/CMakeLists.txt +0 -79
  16. data/ext/libyajl2/vendored/COPYING +0 -13
  17. data/ext/libyajl2/vendored/ChangeLog +0 -175
  18. data/ext/libyajl2/vendored/README +0 -74
  19. data/ext/libyajl2/vendored/TODO +0 -9
  20. data/ext/libyajl2/vendored/YAJLDoc.cmake +0 -26
  21. data/ext/libyajl2/vendored/configure +0 -79
  22. data/ext/libyajl2/vendored/example/CMakeLists.txt +0 -23
  23. data/ext/libyajl2/vendored/example/README.md +0 -7
  24. data/ext/libyajl2/vendored/example/parse_config.c +0 -69
  25. data/ext/libyajl2/vendored/example/sample.config +0 -101
  26. data/ext/libyajl2/vendored/perf/CMakeLists.txt +0 -23
  27. data/ext/libyajl2/vendored/perf/documents.c +0 -1418
  28. data/ext/libyajl2/vendored/perf/documents.h +0 -28
  29. data/ext/libyajl2/vendored/perf/perftest.c +0 -134
  30. data/ext/libyajl2/vendored/reformatter/CMakeLists.txt +0 -39
  31. data/ext/libyajl2/vendored/reformatter/json_reformat.c +0 -194
  32. data/ext/libyajl2/vendored/src/CMakeLists.txt +0 -86
  33. data/ext/libyajl2/vendored/src/YAJL.dxy +0 -1258
  34. data/ext/libyajl2/vendored/src/api/yajl_common.h +0 -75
  35. data/ext/libyajl2/vendored/src/api/yajl_gen.h +0 -157
  36. data/ext/libyajl2/vendored/src/api/yajl_parse.h +0 -226
  37. data/ext/libyajl2/vendored/src/api/yajl_tree.h +0 -185
  38. data/ext/libyajl2/vendored/src/api/yajl_version.h.cmake +0 -23
  39. data/ext/libyajl2/vendored/src/yajl +0 -33
  40. data/ext/libyajl2/vendored/src/yajl.c +0 -175
  41. data/ext/libyajl2/vendored/src/yajl.pc.cmake +0 -9
  42. data/ext/libyajl2/vendored/src/yajl_alloc.c +0 -52
  43. data/ext/libyajl2/vendored/src/yajl_alloc.h +0 -34
  44. data/ext/libyajl2/vendored/src/yajl_buf.c +0 -103
  45. data/ext/libyajl2/vendored/src/yajl_buf.h +0 -57
  46. data/ext/libyajl2/vendored/src/yajl_bytestack.h +0 -69
  47. data/ext/libyajl2/vendored/src/yajl_encode.c +0 -220
  48. data/ext/libyajl2/vendored/src/yajl_encode.h +0 -34
  49. data/ext/libyajl2/vendored/src/yajl_gen.c +0 -354
  50. data/ext/libyajl2/vendored/src/yajl_lex.c +0 -763
  51. data/ext/libyajl2/vendored/src/yajl_lex.h +0 -117
  52. data/ext/libyajl2/vendored/src/yajl_parser.c +0 -498
  53. data/ext/libyajl2/vendored/src/yajl_parser.h +0 -78
  54. data/ext/libyajl2/vendored/src/yajl_tree.c +0 -503
  55. data/ext/libyajl2/vendored/src/yajl_version.c +0 -7
  56. data/ext/libyajl2/vendored/test/CMakeLists.txt +0 -23
  57. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json +0 -1
  58. data/ext/libyajl2/vendored/test/cases/ac_difficult_json_c_test_case_with_comments.json.gold +0 -36
  59. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json +0 -11
  60. data/ext/libyajl2/vendored/test/cases/ac_simple_with_comments.json.gold +0 -9
  61. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json +0 -1
  62. data/ext/libyajl2/vendored/test/cases/ag_false_then_garbage.json.gold +0 -2
  63. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json +0 -1
  64. data/ext/libyajl2/vendored/test/cases/ag_null_then_garbage.json.gold +0 -2
  65. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json +0 -1
  66. data/ext/libyajl2/vendored/test/cases/ag_true_then_garbage.json.gold +0 -2
  67. data/ext/libyajl2/vendored/test/cases/am_eof.json +0 -1
  68. data/ext/libyajl2/vendored/test/cases/am_eof.json.gold +0 -4
  69. data/ext/libyajl2/vendored/test/cases/am_integers.json +0 -1
  70. data/ext/libyajl2/vendored/test/cases/am_integers.json.gold +0 -3
  71. data/ext/libyajl2/vendored/test/cases/am_multiple.json +0 -3
  72. data/ext/libyajl2/vendored/test/cases/am_multiple.json.gold +0 -5
  73. data/ext/libyajl2/vendored/test/cases/am_stuff.json +0 -7
  74. data/ext/libyajl2/vendored/test/cases/am_stuff.json.gold +0 -14
  75. data/ext/libyajl2/vendored/test/cases/ap_array_open.json +0 -1
  76. data/ext/libyajl2/vendored/test/cases/ap_array_open.json.gold +0 -2
  77. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json +0 -1
  78. data/ext/libyajl2/vendored/test/cases/ap_eof_str.json.gold +0 -1
  79. data/ext/libyajl2/vendored/test/cases/ap_map_open.json +0 -1
  80. data/ext/libyajl2/vendored/test/cases/ap_map_open.json.gold +0 -2
  81. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json +0 -1
  82. data/ext/libyajl2/vendored/test/cases/ap_partial_ok.json.gold +0 -4
  83. data/ext/libyajl2/vendored/test/cases/array.json +0 -6
  84. data/ext/libyajl2/vendored/test/cases/array.json.gold +0 -22
  85. data/ext/libyajl2/vendored/test/cases/array_close.json +0 -1
  86. data/ext/libyajl2/vendored/test/cases/array_close.json.gold +0 -2
  87. data/ext/libyajl2/vendored/test/cases/bignums.json +0 -1
  88. data/ext/libyajl2/vendored/test/cases/bignums.json.gold +0 -5
  89. data/ext/libyajl2/vendored/test/cases/bogus_char.json +0 -4
  90. data/ext/libyajl2/vendored/test/cases/bogus_char.json.gold +0 -10
  91. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json +0 -1
  92. data/ext/libyajl2/vendored/test/cases/codepoints_from_unicode_org.json.gold +0 -2
  93. data/ext/libyajl2/vendored/test/cases/deep_arrays.json +0 -1
  94. data/ext/libyajl2/vendored/test/cases/deep_arrays.json.gold +0 -2049
  95. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json +0 -1
  96. data/ext/libyajl2/vendored/test/cases/difficult_json_c_test_case.json.gold +0 -36
  97. data/ext/libyajl2/vendored/test/cases/doubles.json +0 -1
  98. data/ext/libyajl2/vendored/test/cases/doubles.json.gold +0 -7
  99. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json +0 -1
  100. data/ext/libyajl2/vendored/test/cases/doubles_in_array.json.gold +0 -8
  101. data/ext/libyajl2/vendored/test/cases/empty_array.json +0 -1
  102. data/ext/libyajl2/vendored/test/cases/empty_array.json.gold +0 -3
  103. data/ext/libyajl2/vendored/test/cases/empty_string.json +0 -1
  104. data/ext/libyajl2/vendored/test/cases/empty_string.json.gold +0 -2
  105. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json +0 -4
  106. data/ext/libyajl2/vendored/test/cases/escaped_bulgarian.json.gold +0 -7
  107. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json +0 -1
  108. data/ext/libyajl2/vendored/test/cases/escaped_foobar.json.gold +0 -2
  109. data/ext/libyajl2/vendored/test/cases/false.json +0 -1
  110. data/ext/libyajl2/vendored/test/cases/false.json.gold +0 -2
  111. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json +0 -1
  112. data/ext/libyajl2/vendored/test/cases/fg_false_then_garbage.json.gold +0 -3
  113. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json +0 -1
  114. data/ext/libyajl2/vendored/test/cases/fg_issue_7.json.gold +0 -3
  115. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json +0 -1
  116. data/ext/libyajl2/vendored/test/cases/fg_null_then_garbage.json.gold +0 -3
  117. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json +0 -1
  118. data/ext/libyajl2/vendored/test/cases/fg_true_then_garbage.json.gold +0 -3
  119. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json +0 -2
  120. data/ext/libyajl2/vendored/test/cases/four_byte_utf8.json.gold +0 -5
  121. data/ext/libyajl2/vendored/test/cases/high_overflow.json +0 -1
  122. data/ext/libyajl2/vendored/test/cases/high_overflow.json.gold +0 -2
  123. data/ext/libyajl2/vendored/test/cases/integers.json +0 -3
  124. data/ext/libyajl2/vendored/test/cases/integers.json.gold +0 -14
  125. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json +0 -1
  126. data/ext/libyajl2/vendored/test/cases/invalid_utf8.json.gold +0 -3
  127. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json +0 -1
  128. data/ext/libyajl2/vendored/test/cases/isolated_surrogate_marker.json.gold +0 -2
  129. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json +0 -1
  130. data/ext/libyajl2/vendored/test/cases/leading_zero_in_number.json.gold +0 -5
  131. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json +0 -7
  132. data/ext/libyajl2/vendored/test/cases/lonely_minus_sign.json.gold +0 -9
  133. data/ext/libyajl2/vendored/test/cases/lonely_number.json +0 -1
  134. data/ext/libyajl2/vendored/test/cases/lonely_number.json.gold +0 -2
  135. data/ext/libyajl2/vendored/test/cases/low_overflow.json +0 -1
  136. data/ext/libyajl2/vendored/test/cases/low_overflow.json.gold +0 -2
  137. data/ext/libyajl2/vendored/test/cases/map_close.json +0 -1
  138. data/ext/libyajl2/vendored/test/cases/map_close.json.gold +0 -2
  139. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json +0 -1
  140. data/ext/libyajl2/vendored/test/cases/missing_integer_after_decimal_point.json.gold +0 -2
  141. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json +0 -1
  142. data/ext/libyajl2/vendored/test/cases/missing_integer_after_exponent.json.gold +0 -2
  143. data/ext/libyajl2/vendored/test/cases/multiple.json +0 -3
  144. data/ext/libyajl2/vendored/test/cases/multiple.json.gold +0 -4
  145. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json +0 -1
  146. data/ext/libyajl2/vendored/test/cases/non_utf8_char_in_string.json.gold +0 -8
  147. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json +0 -1
  148. data/ext/libyajl2/vendored/test/cases/np_partial_bad.json.gold +0 -5
  149. data/ext/libyajl2/vendored/test/cases/null.json +0 -1
  150. data/ext/libyajl2/vendored/test/cases/null.json.gold +0 -2
  151. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json +0 -5
  152. data/ext/libyajl2/vendored/test/cases/nulls_and_bools.json.gold +0 -9
  153. data/ext/libyajl2/vendored/test/cases/simple.json +0 -5
  154. data/ext/libyajl2/vendored/test/cases/simple.json.gold +0 -9
  155. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json +0 -11
  156. data/ext/libyajl2/vendored/test/cases/simple_with_comments.json.gold +0 -5
  157. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json +0 -1
  158. data/ext/libyajl2/vendored/test/cases/string_invalid_escape.json.gold +0 -3
  159. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json +0 -1
  160. data/ext/libyajl2/vendored/test/cases/string_invalid_hex_char.json.gold +0 -2
  161. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json +0 -3
  162. data/ext/libyajl2/vendored/test/cases/string_with_escapes.json.gold +0 -7
  163. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json +0 -2
  164. data/ext/libyajl2/vendored/test/cases/string_with_invalid_newline.json.gold +0 -2
  165. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json +0 -1
  166. data/ext/libyajl2/vendored/test/cases/three_byte_utf8.json.gold +0 -7
  167. data/ext/libyajl2/vendored/test/cases/true.json +0 -1
  168. data/ext/libyajl2/vendored/test/cases/true.json.gold +0 -2
  169. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json +0 -1
  170. data/ext/libyajl2/vendored/test/cases/unescaped_bulgarian.json.gold +0 -4
  171. data/ext/libyajl2/vendored/test/cases/zerobyte.json +0 -1
  172. data/ext/libyajl2/vendored/test/cases/zerobyte.json.gold +0 -0
  173. data/ext/libyajl2/vendored/test/run_tests.sh +0 -94
  174. data/ext/libyajl2/vendored/test/yajl_test.c +0 -281
  175. data/ext/libyajl2/vendored/verify/CMakeLists.txt +0 -39
  176. data/ext/libyajl2/vendored/verify/json_verify.c +0 -116
  177. data/lib/libyajl.so +0 -0
  178. data/lib/libyajl.so.2 +0 -0
  179. data/lib/libyajl.so.2.0.5 +0 -0
  180. data/lib/libyajl_s.a +0 -0
@@ -1 +0,0 @@
1
- "\u0000"
@@ -1,94 +0,0 @@
1
- #!/bin/sh
2
-
3
- ECHO=`which echo`
4
-
5
- DIFF_FLAGS="-u"
6
- case "$(uname)" in
7
- *W32*)
8
- DIFF_FLAGS="-wu"
9
- ;;
10
- esac
11
-
12
- if [ -z "$testBin" ]; then
13
- testBin="$1"
14
- fi
15
-
16
- # find test binary on both platforms. allow the caller to force a
17
- # particular test binary (useful for non-cmake build systems).
18
- if [ -z "$testBin" ]; then
19
- testBin="../build/test/Release/yajl_test.exe"
20
- if [ ! -x $testBin ] ; then
21
- testBin="../build/test/Debug/yajl_test.exe"
22
- if [ ! -x $testBin ] ; then
23
- testBin="../build/test/yajl_test"
24
- if [ ! -x $testBin ] ; then
25
- ${ECHO} "cannot execute test binary: '$testBin'"
26
- exit 1;
27
- fi
28
- fi
29
- fi
30
- fi
31
-
32
- ${ECHO} "using test binary: $testBin"
33
-
34
- testBinShort=`basename $testBin`
35
-
36
- testsSucceeded=0
37
- testsTotal=0
38
-
39
- for file in cases/*.json ; do
40
- allowComments=""
41
- allowGarbage=""
42
- allowMultiple=""
43
- allowPartials=""
44
-
45
- # if the filename starts with dc_, we disallow comments for this test
46
- case $(basename $file) in
47
- ac_*)
48
- allowComments="-c "
49
- ;;
50
- ag_*)
51
- allowGarbage="-g "
52
- ;;
53
- am_*)
54
- allowMultiple="-m ";
55
- ;;
56
- ap_*)
57
- allowPartials="-p ";
58
- ;;
59
- esac
60
- fileShort=`basename $file`
61
- testName=`echo $fileShort | sed -e 's/\.json$//'`
62
-
63
- ${ECHO} -n " test ($testName): "
64
- iter=1
65
- success="SUCCESS"
66
-
67
- # ${ECHO} -n "$testBinShort $allowPartials$allowComments$allowGarbage$allowMultiple-b $iter < $fileShort > ${fileShort}.test : "
68
- # parse with a read buffer size ranging from 1-31 to stress stream parsing
69
- while [ $iter -lt 32 ] && [ $success = "SUCCESS" ] ; do
70
- $testBin $allowPartials $allowComments $allowGarbage $allowMultiple -b $iter < $file > ${file}.test 2>&1
71
- diff ${DIFF_FLAGS} ${file}.gold ${file}.test > ${file}.out
72
- if [ $? -eq 0 ] ; then
73
- if [ $iter -eq 31 ] ; then testsSucceeded=$(( $testsSucceeded + 1 )) ; fi
74
- else
75
- success="FAILURE"
76
- iter=32
77
- ${ECHO}
78
- cat ${file}.out
79
- fi
80
- iter=$(( iter + 1 ))
81
- rm ${file}.test ${file}.out
82
- done
83
-
84
- ${ECHO} $success
85
- testsTotal=$(( testsTotal + 1 ))
86
- done
87
-
88
- ${ECHO} $testsSucceeded/$testsTotal tests successful
89
-
90
- if [ $testsSucceeded != $testsTotal ] ; then
91
- exit 1
92
- fi
93
-
94
- exit 0
@@ -1,281 +0,0 @@
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
- #include <yajl/yajl_parse.h>
18
- #include <yajl/yajl_gen.h>
19
-
20
- #include <stdio.h>
21
- #include <stdlib.h>
22
- #include <string.h>
23
-
24
- #include <assert.h>
25
-
26
- /* memory debugging routines */
27
- typedef struct
28
- {
29
- unsigned int numFrees;
30
- unsigned int numMallocs;
31
- /* XXX: we really need a hash table here with per-allocation
32
- * information */
33
- } yajlTestMemoryContext;
34
-
35
- /* cast void * into context */
36
- #define TEST_CTX(vptr) ((yajlTestMemoryContext *) (vptr))
37
-
38
- static void yajlTestFree(void * ctx, void * ptr)
39
- {
40
- assert(ptr != NULL);
41
- TEST_CTX(ctx)->numFrees++;
42
- free(ptr);
43
- }
44
-
45
- static void * yajlTestMalloc(void * ctx, size_t sz)
46
- {
47
- assert(sz != 0);
48
- TEST_CTX(ctx)->numMallocs++;
49
- return malloc(sz);
50
- }
51
-
52
- static void * yajlTestRealloc(void * ctx, void * ptr, size_t sz)
53
- {
54
- if (ptr == NULL) {
55
- assert(sz != 0);
56
- TEST_CTX(ctx)->numMallocs++;
57
- } else if (sz == 0) {
58
- TEST_CTX(ctx)->numFrees++;
59
- }
60
-
61
- return realloc(ptr, sz);
62
- }
63
-
64
-
65
- /* begin parsing callback routines */
66
- #define BUF_SIZE 2048
67
-
68
- static int test_yajl_null(void *ctx)
69
- {
70
- printf("null\n");
71
- return 1;
72
- }
73
-
74
- static int test_yajl_boolean(void * ctx, int boolVal)
75
- {
76
- printf("bool: %s\n", boolVal ? "true" : "false");
77
- return 1;
78
- }
79
-
80
- static int test_yajl_integer(void *ctx, long long integerVal)
81
- {
82
- printf("integer: %lld\n", integerVal);
83
- return 1;
84
- }
85
-
86
- static int test_yajl_double(void *ctx, double doubleVal)
87
- {
88
- printf("double: %g\n", doubleVal);
89
- return 1;
90
- }
91
-
92
- static int test_yajl_string(void *ctx, const unsigned char * stringVal,
93
- size_t stringLen)
94
- {
95
- printf("string: '");
96
- fwrite(stringVal, 1, stringLen, stdout);
97
- printf("'\n");
98
- return 1;
99
- }
100
-
101
- static int test_yajl_map_key(void *ctx, const unsigned char * stringVal,
102
- size_t stringLen)
103
- {
104
- char * str = (char *) malloc(stringLen + 1);
105
- str[stringLen] = 0;
106
- memcpy(str, stringVal, stringLen);
107
- printf("key: '%s'\n", str);
108
- free(str);
109
- return 1;
110
- }
111
-
112
- static int test_yajl_start_map(void *ctx)
113
- {
114
- printf("map open '{'\n");
115
- return 1;
116
- }
117
-
118
-
119
- static int test_yajl_end_map(void *ctx)
120
- {
121
- printf("map close '}'\n");
122
- return 1;
123
- }
124
-
125
- static int test_yajl_start_array(void *ctx)
126
- {
127
- printf("array open '['\n");
128
- return 1;
129
- }
130
-
131
- static int test_yajl_end_array(void *ctx)
132
- {
133
- printf("array close ']'\n");
134
- return 1;
135
- }
136
-
137
- static yajl_callbacks callbacks = {
138
- test_yajl_null,
139
- test_yajl_boolean,
140
- test_yajl_integer,
141
- test_yajl_double,
142
- NULL,
143
- test_yajl_string,
144
- test_yajl_start_map,
145
- test_yajl_map_key,
146
- test_yajl_end_map,
147
- test_yajl_start_array,
148
- test_yajl_end_array
149
- };
150
-
151
- static void usage(const char * progname)
152
- {
153
- fprintf(stderr,
154
- "usage: %s [options]\n"
155
- "Parse input from stdin as JSON and ouput parsing details "
156
- "to stdout\n"
157
- " -b set the read buffer size\n"
158
- " -c allow comments\n"
159
- " -g allow *g*arbage after valid JSON text\n"
160
- " -m allows the parser to consume multiple JSON values\n"
161
- " from a single string separated by whitespace\n"
162
- " -p partial JSON documents should not cause errors\n",
163
- progname);
164
- exit(1);
165
- }
166
-
167
- int
168
- main(int argc, char ** argv)
169
- {
170
- yajl_handle hand;
171
- const char * fileName;
172
- static unsigned char * fileData = NULL;
173
- size_t bufSize = BUF_SIZE;
174
- yajl_status stat;
175
- size_t rd;
176
- int i, j;
177
-
178
- /* memory allocation debugging: allocate a structure which collects
179
- * statistics */
180
- yajlTestMemoryContext memCtx = { 0,0 };
181
-
182
- /* memory allocation debugging: allocate a structure which holds
183
- * allocation routines */
184
- yajl_alloc_funcs allocFuncs = {
185
- yajlTestMalloc,
186
- yajlTestRealloc,
187
- yajlTestFree,
188
- (void *) NULL
189
- };
190
-
191
- allocFuncs.ctx = (void *) &memCtx;
192
-
193
- /* allocate the parser */
194
- hand = yajl_alloc(&callbacks, &allocFuncs, NULL);
195
-
196
- /* check arguments. We expect exactly one! */
197
- for (i=1;i<argc;i++) {
198
- if (!strcmp("-c", argv[i])) {
199
- yajl_config(hand, yajl_allow_comments, 1);
200
- } else if (!strcmp("-b", argv[i])) {
201
- if (++i >= argc) usage(argv[0]);
202
-
203
- /* validate integer */
204
- for (j=0;j<(int)strlen(argv[i]);j++) {
205
- if (argv[i][j] <= '9' && argv[i][j] >= '0') continue;
206
- fprintf(stderr, "-b requires an integer argument. '%s' "
207
- "is invalid\n", argv[i]);
208
- usage(argv[0]);
209
- }
210
-
211
- bufSize = atoi(argv[i]);
212
- if (!bufSize) {
213
- fprintf(stderr, "%zu is an invalid buffer size\n",
214
- bufSize);
215
- }
216
- } else if (!strcmp("-g", argv[i])) {
217
- yajl_config(hand, yajl_allow_trailing_garbage, 1);
218
- } else if (!strcmp("-m", argv[i])) {
219
- yajl_config(hand, yajl_allow_multiple_values, 1);
220
- } else if (!strcmp("-p", argv[i])) {
221
- yajl_config(hand, yajl_allow_partial_values, 1);
222
- } else {
223
- fprintf(stderr, "invalid command line option: '%s'\n",
224
- argv[i]);
225
- usage(argv[0]);
226
- }
227
- }
228
-
229
- fileData = (unsigned char *) malloc(bufSize);
230
-
231
- if (fileData == NULL) {
232
- fprintf(stderr,
233
- "failed to allocate read buffer of %zu bytes, exiting.",
234
- bufSize);
235
- yajl_free(hand);
236
- exit(2);
237
- }
238
-
239
- fileName = argv[argc-1];
240
-
241
- for (;;) {
242
- rd = fread((void *) fileData, 1, bufSize, stdin);
243
-
244
- if (rd == 0) {
245
- if (!feof(stdin)) {
246
- fprintf(stderr, "error reading from '%s'\n", fileName);
247
- }
248
- break;
249
- }
250
- /* read file data, now pass to parser */
251
- stat = yajl_parse(hand, fileData, rd);
252
-
253
- if (stat != yajl_status_ok) break;
254
- }
255
-
256
- stat = yajl_complete_parse(hand);
257
- if (stat != yajl_status_ok)
258
- {
259
- unsigned char * str = yajl_get_error(hand, 0, fileData, rd);
260
- fflush(stdout);
261
- fprintf(stderr, "%s", (char *) str);
262
- yajl_free_error(hand, str);
263
- }
264
-
265
- yajl_free(hand);
266
- free(fileData);
267
-
268
- /* finally, print out some memory statistics */
269
-
270
- /* (lth) only print leaks here, as allocations and frees may vary depending
271
- * on read buffer size, causing false failures.
272
- *
273
- * printf("allocations:\t%u\n", memCtx.numMallocs);
274
- * printf("frees:\t\t%u\n", memCtx.numFrees);
275
- */
276
- fflush(stderr);
277
- fflush(stdout);
278
- printf("memory leaks:\t%u\n", memCtx.numMallocs - memCtx.numFrees);
279
-
280
- return 0;
281
- }
@@ -1,39 +0,0 @@
1
- # Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for any
4
- # purpose with or without fee is hereby granted, provided that the above
5
- # copyright notice and this permission notice appear in all copies.
6
- #
7
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
-
15
- # set up some paths
16
- SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/bin)
17
-
18
- # create some directories
19
- FILE(MAKE_DIRECTORY ${binDir})
20
-
21
- SET (SRCS json_verify.c)
22
-
23
- # use the library we build, duh.
24
- INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/include)
25
- LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../${YAJL_DIST_NAME}/lib)
26
-
27
- ADD_EXECUTABLE(json_verify ${SRCS})
28
-
29
- TARGET_LINK_LIBRARIES(json_verify yajl_s)
30
-
31
- # copy in the binary
32
- GET_TARGET_PROPERTY(binPath json_verify LOCATION)
33
-
34
- ADD_CUSTOM_COMMAND(TARGET json_verify POST_BUILD
35
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir})
36
-
37
- IF (NOT WIN32)
38
- INSTALL(TARGETS json_verify RUNTIME DESTINATION bin)
39
- ENDIF ()
@@ -1,116 +0,0 @@
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
- #include <yajl/yajl_parse.h>
18
-
19
- #include <stdio.h>
20
- #include <stdlib.h>
21
- #include <string.h>
22
-
23
- static void
24
- usage(const char * progname)
25
- {
26
- fprintf(stderr, "%s: validate json from stdin\n"
27
- "usage: json_verify [options]\n"
28
- " -q quiet mode\n"
29
- " -c allow comments\n"
30
- " -u allow invalid utf8 inside strings\n",
31
- progname);
32
- exit(1);
33
- }
34
-
35
- int
36
- main(int argc, char ** argv)
37
- {
38
- yajl_status stat;
39
- size_t rd;
40
- yajl_handle hand;
41
- static unsigned char fileData[65536];
42
- int quiet = 0;
43
- int retval = 0;
44
- int a = 1;
45
-
46
- /* allocate a parser */
47
- hand = yajl_alloc(NULL, NULL, NULL);
48
-
49
- /* check arguments.*/
50
- while ((a < argc) && (argv[a][0] == '-') && (strlen(argv[a]) > 1)) {
51
- unsigned int i;
52
- for ( i=1; i < strlen(argv[a]); i++) {
53
- switch (argv[a][i]) {
54
- case 'q':
55
- quiet = 1;
56
- break;
57
- case 'c':
58
- yajl_config(hand, yajl_allow_comments, 1);
59
- break;
60
- case 'u':
61
- yajl_config(hand, yajl_dont_validate_strings, 1);
62
- break;
63
- default:
64
- fprintf(stderr, "unrecognized option: '%c'\n\n", argv[a][i]);
65
- usage(argv[0]);
66
- }
67
- }
68
- ++a;
69
- }
70
- if (a < argc) {
71
- usage(argv[0]);
72
- }
73
-
74
- for (;;) {
75
- rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
76
-
77
- retval = 0;
78
-
79
- if (rd == 0) {
80
- if (!feof(stdin)) {
81
- if (!quiet) {
82
- fprintf(stderr, "error encountered on file read\n");
83
- }
84
- retval = 1;
85
- }
86
- break;
87
- }
88
- fileData[rd] = 0;
89
-
90
- /* read file data, pass to parser */
91
- stat = yajl_parse(hand, fileData, rd);
92
-
93
- if (stat != yajl_status_ok) break;
94
- }
95
-
96
- /* parse any remaining buffered data */
97
- stat = yajl_complete_parse(hand);
98
-
99
- if (stat != yajl_status_ok)
100
- {
101
- if (!quiet) {
102
- unsigned char * str = yajl_get_error(hand, 1, fileData, rd);
103
- fprintf(stderr, "%s", (const char *) str);
104
- yajl_free_error(hand, str);
105
- }
106
- retval = 1;
107
- }
108
-
109
- yajl_free(hand);
110
-
111
- if (!quiet) {
112
- printf("JSON is %s\n", retval ? "invalid" : "valid");
113
- }
114
-
115
- return retval;
116
- }