scout 5.7.1 → 5.7.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/lib/scout/command/run.rb +1 -1
  3. data/lib/scout/server.rb +2 -1
  4. data/lib/scout/streamer.rb +3 -2
  5. data/lib/scout/streamer_daemon.rb +4 -4
  6. data/lib/scout/version.rb +1 -1
  7. data/test/scout_test.rb +7 -8
  8. data/vendor/httpclient/README.txt +759 -0
  9. data/vendor/httpclient/bin/httpclient +65 -0
  10. data/vendor/httpclient/lib/hexdump.rb +50 -0
  11. data/vendor/httpclient/lib/http-access2.rb +55 -0
  12. data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
  13. data/vendor/httpclient/lib/http-access2/http.rb +1 -0
  14. data/vendor/httpclient/lib/httpclient.rb +1156 -0
  15. data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
  16. data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
  17. data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
  18. data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
  19. data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
  20. data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
  21. data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
  22. data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
  23. data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
  24. data/vendor/httpclient/lib/httpclient/util.rb +178 -0
  25. data/vendor/httpclient/lib/httpclient/version.rb +3 -0
  26. data/vendor/httpclient/lib/oauthclient.rb +110 -0
  27. data/vendor/httpclient/sample/async.rb +8 -0
  28. data/vendor/httpclient/sample/auth.rb +11 -0
  29. data/vendor/httpclient/sample/cookie.rb +18 -0
  30. data/vendor/httpclient/sample/dav.rb +103 -0
  31. data/vendor/httpclient/sample/howto.rb +49 -0
  32. data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
  33. data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
  34. data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
  35. data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
  36. data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
  37. data/vendor/httpclient/sample/ssl/0key.pem +30 -0
  38. data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
  39. data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
  40. data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
  41. data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
  42. data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/vendor/httpclient/sample/stream.rb +21 -0
  44. data/vendor/httpclient/sample/thread.rb +27 -0
  45. data/vendor/httpclient/sample/wcat.rb +21 -0
  46. data/vendor/httpclient/test/ca-chain.cert +44 -0
  47. data/vendor/httpclient/test/ca.cert +23 -0
  48. data/vendor/httpclient/test/client.cert +19 -0
  49. data/vendor/httpclient/test/client.key +15 -0
  50. data/vendor/httpclient/test/helper.rb +129 -0
  51. data/vendor/httpclient/test/htdigest +1 -0
  52. data/vendor/httpclient/test/htpasswd +2 -0
  53. data/vendor/httpclient/test/runner.rb +2 -0
  54. data/vendor/httpclient/test/server.cert +19 -0
  55. data/vendor/httpclient/test/server.key +15 -0
  56. data/vendor/httpclient/test/sslsvr.rb +65 -0
  57. data/vendor/httpclient/test/subca.cert +21 -0
  58. data/vendor/httpclient/test/test_auth.rb +321 -0
  59. data/vendor/httpclient/test/test_cookie.rb +391 -0
  60. data/vendor/httpclient/test/test_hexdump.rb +14 -0
  61. data/vendor/httpclient/test/test_http-access2.rb +507 -0
  62. data/vendor/httpclient/test/test_httpclient.rb +1783 -0
  63. data/vendor/httpclient/test/test_include_client.rb +52 -0
  64. data/vendor/httpclient/test/test_ssl.rb +235 -0
  65. data/vendor/multi_json/.document +5 -0
  66. data/vendor/multi_json/.rspec +3 -0
  67. data/vendor/multi_json/.travis.yml +11 -0
  68. data/vendor/multi_json/.yardopts +6 -0
  69. data/vendor/multi_json/CHANGELOG.md +169 -0
  70. data/vendor/multi_json/CONTRIBUTING.md +46 -0
  71. data/vendor/multi_json/Gemfile +31 -0
  72. data/vendor/multi_json/LICENSE.md +20 -0
  73. data/vendor/multi_json/README.md +109 -0
  74. data/vendor/multi_json/Rakefile +12 -0
  75. data/vendor/multi_json/lib/multi_json.rb +157 -0
  76. data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
  77. data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
  78. data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
  79. data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
  80. data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
  81. data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
  82. data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
  83. data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
  84. data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
  85. data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
  86. data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
  87. data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
  88. data/vendor/multi_json/lib/multi_json/options.rb +48 -0
  89. data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
  90. data/vendor/multi_json/lib/multi_json/version.rb +20 -0
  91. data/vendor/multi_json/multi_json.gemspec +22 -0
  92. data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
  93. data/vendor/multi_json/spec/has_options.rb +119 -0
  94. data/vendor/multi_json/spec/helper.rb +35 -0
  95. data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
  96. data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
  97. data/vendor/{signature → pusher}/.document +0 -0
  98. data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
  99. data/vendor/pusher/.gitignore +23 -0
  100. data/vendor/pusher/.travis.yml +15 -0
  101. data/vendor/pusher/Gemfile +2 -0
  102. data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
  103. data/vendor/pusher/README.md +186 -0
  104. data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
  105. data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
  106. data/vendor/pusher/lib/pusher.rb +60 -0
  107. data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
  108. data/vendor/pusher/lib/pusher/client.rb +306 -0
  109. data/vendor/pusher/lib/pusher/request.rb +107 -0
  110. data/vendor/pusher/lib/pusher/resource.rb +36 -0
  111. data/vendor/pusher/lib/pusher/webhook.rb +110 -0
  112. data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
  113. data/vendor/pusher/spec/channel_spec.rb +127 -0
  114. data/vendor/pusher/spec/client_spec.rb +464 -0
  115. data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
  116. data/vendor/pusher/spec/web_hook_spec.rb +117 -0
  117. data/vendor/signature/.travis.yml +15 -0
  118. data/vendor/signature/Gemfile +1 -1
  119. data/vendor/signature/README.md +38 -28
  120. data/vendor/signature/lib/signature.rb +97 -15
  121. data/vendor/signature/lib/signature/query_encoder.rb +47 -0
  122. data/vendor/signature/lib/signature/version.rb +1 -1
  123. data/vendor/signature/signature.gemspec +3 -2
  124. data/vendor/signature/spec/signature_spec.rb +164 -55
  125. data/vendor/signature/spec/spec_helper.rb +2 -3
  126. metadata +120 -145
  127. data/vendor/json_pure/.gitignore +0 -12
  128. data/vendor/json_pure/.travis.yml +0 -20
  129. data/vendor/json_pure/CHANGES +0 -282
  130. data/vendor/json_pure/COPYING +0 -58
  131. data/vendor/json_pure/COPYING-json-jruby +0 -57
  132. data/vendor/json_pure/GPL +0 -340
  133. data/vendor/json_pure/Gemfile +0 -11
  134. data/vendor/json_pure/README-json-jruby.markdown +0 -33
  135. data/vendor/json_pure/README.rdoc +0 -358
  136. data/vendor/json_pure/Rakefile +0 -412
  137. data/vendor/json_pure/TODO +0 -1
  138. data/vendor/json_pure/VERSION +0 -1
  139. data/vendor/json_pure/data/example.json +0 -1
  140. data/vendor/json_pure/data/index.html +0 -38
  141. data/vendor/json_pure/data/prototype.js +0 -4184
  142. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
  143. data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
  144. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
  145. data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
  146. data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
  147. data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
  148. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
  149. data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
  150. data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
  151. data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
  152. data/vendor/json_pure/install.rb +0 -23
  153. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
  154. data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
  155. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
  156. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
  157. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
  158. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
  159. data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
  160. data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
  161. data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
  162. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
  163. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
  164. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
  165. data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
  166. data/vendor/json_pure/json-java.gemspec +0 -23
  167. data/vendor/json_pure/json.gemspec +0 -37
  168. data/vendor/json_pure/json_pure.gemspec +0 -39
  169. data/vendor/json_pure/lib/json.rb +0 -62
  170. data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
  171. data/vendor/json_pure/lib/json/add/complex.rb +0 -22
  172. data/vendor/json_pure/lib/json/add/core.rb +0 -11
  173. data/vendor/json_pure/lib/json/add/date.rb +0 -34
  174. data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
  175. data/vendor/json_pure/lib/json/add/exception.rb +0 -31
  176. data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
  177. data/vendor/json_pure/lib/json/add/range.rb +0 -29
  178. data/vendor/json_pure/lib/json/add/rational.rb +0 -22
  179. data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
  180. data/vendor/json_pure/lib/json/add/struct.rb +0 -30
  181. data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
  182. data/vendor/json_pure/lib/json/add/time.rb +0 -38
  183. data/vendor/json_pure/lib/json/common.rb +0 -487
  184. data/vendor/json_pure/lib/json/ext.rb +0 -21
  185. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  186. data/vendor/json_pure/lib/json/generic_object.rb +0 -70
  187. data/vendor/json_pure/lib/json/pure.rb +0 -21
  188. data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
  189. data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
  190. data/vendor/json_pure/lib/json/version.rb +0 -8
  191. data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  192. data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  193. data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  194. data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  195. data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  196. data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  197. data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  198. data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  199. data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  200. data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  201. data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  202. data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  203. data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  204. data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  205. data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  206. data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  207. data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  208. data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  209. data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  210. data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  211. data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  212. data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  213. data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  214. data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  215. data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  216. data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  217. data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  218. data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  219. data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  220. data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  221. data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  222. data/vendor/json_pure/tests/setup_variant.rb +0 -11
  223. data/vendor/json_pure/tests/test_json.rb +0 -545
  224. data/vendor/json_pure/tests/test_json_addition.rb +0 -196
  225. data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
  226. data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
  227. data/vendor/json_pure/tests/test_json_generate.rb +0 -322
  228. data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
  229. data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
  230. data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
  231. data/vendor/json_pure/tools/fuzz.rb +0 -139
  232. data/vendor/json_pure/tools/server.rb +0 -62
  233. data/vendor/pusher-gem/Gemfile +0 -2
  234. data/vendor/pusher-gem/README.md +0 -80
  235. data/vendor/pusher-gem/lib/pusher.rb +0 -107
  236. data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
  237. data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
  238. data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
  239. data/vendor/ruby-hmac/History.txt +0 -15
  240. data/vendor/ruby-hmac/Manifest.txt +0 -11
  241. data/vendor/ruby-hmac/README.md +0 -41
  242. data/vendor/ruby-hmac/Rakefile +0 -23
  243. data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
  244. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
  245. data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
  246. data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
  247. data/vendor/ruby-hmac/lib/hmac.rb +0 -118
  248. data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
  249. data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
  250. data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
  251. data/vendor/signature/VERSION +0 -1
@@ -1,77 +0,0 @@
1
- #ifndef _PARSER_H_
2
- #define _PARSER_H_
3
-
4
- #include "ruby.h"
5
-
6
- #ifndef HAVE_RUBY_RE_H
7
- #include "re.h"
8
- #endif
9
-
10
- #ifdef HAVE_RUBY_ST_H
11
- #include "ruby/st.h"
12
- #else
13
- #include "st.h"
14
- #endif
15
-
16
- #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
17
-
18
- /* unicode */
19
-
20
- typedef unsigned long UTF32; /* at least 32 bits */
21
- typedef unsigned short UTF16; /* at least 16 bits */
22
- typedef unsigned char UTF8; /* typically 8 bits */
23
-
24
- #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
25
- #define UNI_SUR_HIGH_START (UTF32)0xD800
26
- #define UNI_SUR_HIGH_END (UTF32)0xDBFF
27
- #define UNI_SUR_LOW_START (UTF32)0xDC00
28
- #define UNI_SUR_LOW_END (UTF32)0xDFFF
29
-
30
- typedef struct JSON_ParserStruct {
31
- VALUE Vsource;
32
- char *source;
33
- long len;
34
- char *memo;
35
- VALUE create_id;
36
- int max_nesting;
37
- int current_nesting;
38
- int allow_nan;
39
- int parsing_name;
40
- int symbolize_names;
41
- int quirks_mode;
42
- VALUE object_class;
43
- VALUE array_class;
44
- int create_additions;
45
- VALUE match_string;
46
- FBuffer *fbuffer;
47
- } JSON_Parser;
48
-
49
- #define GET_PARSER \
50
- GET_PARSER_INIT; \
51
- if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
52
- #define GET_PARSER_INIT \
53
- JSON_Parser *json; \
54
- Data_Get_Struct(self, JSON_Parser, json)
55
-
56
- #define MinusInfinity "-Infinity"
57
- #define EVIL 0x666
58
-
59
- static UTF32 unescape_unicode(const unsigned char *p);
60
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
61
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
62
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
63
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
64
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
65
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
66
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
67
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
68
- static VALUE convert_encoding(VALUE source);
69
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
70
- static VALUE cParser_parse(VALUE self);
71
- static JSON_Parser *JSON_allocate();
72
- static void JSON_mark(JSON_Parser *json);
73
- static void JSON_free(JSON_Parser *json);
74
- static VALUE cJSON_parser_s_allocate(VALUE klass);
75
- static VALUE cParser_source(VALUE self);
76
-
77
- #endif
@@ -1,927 +0,0 @@
1
- #include "../fbuffer/fbuffer.h"
2
- #include "parser.h"
3
-
4
- /* unicode */
5
-
6
- static const char digit_values[256] = {
7
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
8
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
10
- -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
11
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
12
- 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
13
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
14
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
15
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
16
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
17
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
18
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
19
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
20
- -1, -1, -1, -1, -1, -1, -1
21
- };
22
-
23
- static UTF32 unescape_unicode(const unsigned char *p)
24
- {
25
- char b;
26
- UTF32 result = 0;
27
- b = digit_values[p[0]];
28
- if (b < 0) return UNI_REPLACEMENT_CHAR;
29
- result = (result << 4) | b;
30
- b = digit_values[p[1]];
31
- result = (result << 4) | b;
32
- if (b < 0) return UNI_REPLACEMENT_CHAR;
33
- b = digit_values[p[2]];
34
- result = (result << 4) | b;
35
- if (b < 0) return UNI_REPLACEMENT_CHAR;
36
- b = digit_values[p[3]];
37
- result = (result << 4) | b;
38
- if (b < 0) return UNI_REPLACEMENT_CHAR;
39
- return result;
40
- }
41
-
42
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
43
- {
44
- int len = 1;
45
- if (ch <= 0x7F) {
46
- buf[0] = (char) ch;
47
- } else if (ch <= 0x07FF) {
48
- buf[0] = (char) ((ch >> 6) | 0xC0);
49
- buf[1] = (char) ((ch & 0x3F) | 0x80);
50
- len++;
51
- } else if (ch <= 0xFFFF) {
52
- buf[0] = (char) ((ch >> 12) | 0xE0);
53
- buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
54
- buf[2] = (char) ((ch & 0x3F) | 0x80);
55
- len += 2;
56
- } else if (ch <= 0x1fffff) {
57
- buf[0] =(char) ((ch >> 18) | 0xF0);
58
- buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
59
- buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
60
- buf[3] =(char) ((ch & 0x3F) | 0x80);
61
- len += 3;
62
- } else {
63
- buf[0] = '?';
64
- }
65
- return len;
66
- }
67
-
68
- #ifdef HAVE_RUBY_ENCODING_H
69
- static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
70
- CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
71
- static ID i_encoding, i_encode;
72
- #else
73
- static ID i_iconv;
74
- #endif
75
-
76
- static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
77
- static VALUE CNaN, CInfinity, CMinusInfinity;
78
-
79
- static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
80
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode,
81
- i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match,
82
- i_match_string, i_aset, i_aref, i_leftshift;
83
-
84
- %%{
85
- machine JSON_common;
86
-
87
- cr = '\n';
88
- cr_neg = [^\n];
89
- ws = [ \t\r\n];
90
- c_comment = '/*' ( any* - (any* '*/' any* ) ) '*/';
91
- cpp_comment = '//' cr_neg* cr;
92
- comment = c_comment | cpp_comment;
93
- ignore = ws | comment;
94
- name_separator = ':';
95
- value_separator = ',';
96
- Vnull = 'null';
97
- Vfalse = 'false';
98
- Vtrue = 'true';
99
- VNaN = 'NaN';
100
- VInfinity = 'Infinity';
101
- VMinusInfinity = '-Infinity';
102
- begin_value = [nft\"\-\[\{NI] | digit;
103
- begin_object = '{';
104
- end_object = '}';
105
- begin_array = '[';
106
- end_array = ']';
107
- begin_string = '"';
108
- begin_name = begin_string;
109
- begin_number = digit | '-';
110
- }%%
111
-
112
- %%{
113
- machine JSON_object;
114
- include JSON_common;
115
-
116
- write data;
117
-
118
- action parse_value {
119
- VALUE v = Qnil;
120
- char *np = JSON_parse_value(json, fpc, pe, &v);
121
- if (np == NULL) {
122
- fhold; fbreak;
123
- } else {
124
- if (NIL_P(json->object_class)) {
125
- rb_hash_aset(*result, last_name, v);
126
- } else {
127
- rb_funcall(*result, i_aset, 2, last_name, v);
128
- }
129
- fexec np;
130
- }
131
- }
132
-
133
- action parse_name {
134
- char *np;
135
- json->parsing_name = 1;
136
- np = JSON_parse_string(json, fpc, pe, &last_name);
137
- json->parsing_name = 0;
138
- if (np == NULL) { fhold; fbreak; } else fexec np;
139
- }
140
-
141
- action exit { fhold; fbreak; }
142
-
143
- pair = ignore* begin_name >parse_name ignore* name_separator ignore* begin_value >parse_value;
144
- next_pair = ignore* value_separator pair;
145
-
146
- main := (
147
- begin_object
148
- (pair (next_pair)*)? ignore*
149
- end_object
150
- ) @exit;
151
- }%%
152
-
153
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
154
- {
155
- int cs = EVIL;
156
- VALUE last_name = Qnil;
157
- VALUE object_class = json->object_class;
158
-
159
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
160
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
161
- }
162
-
163
- *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
164
-
165
- %% write init;
166
- %% write exec;
167
-
168
- if (cs >= JSON_object_first_final) {
169
- if (json->create_additions) {
170
- VALUE klassname;
171
- if (NIL_P(json->object_class)) {
172
- klassname = rb_hash_aref(*result, json->create_id);
173
- } else {
174
- klassname = rb_funcall(*result, i_aref, 1, json->create_id);
175
- }
176
- if (!NIL_P(klassname)) {
177
- VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
178
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) {
179
- *result = rb_funcall(klass, i_json_create, 1, *result);
180
- }
181
- }
182
- }
183
- return p + 1;
184
- } else {
185
- return NULL;
186
- }
187
- }
188
-
189
-
190
- %%{
191
- machine JSON_value;
192
- include JSON_common;
193
-
194
- write data;
195
-
196
- action parse_null {
197
- *result = Qnil;
198
- }
199
- action parse_false {
200
- *result = Qfalse;
201
- }
202
- action parse_true {
203
- *result = Qtrue;
204
- }
205
- action parse_nan {
206
- if (json->allow_nan) {
207
- *result = CNaN;
208
- } else {
209
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
210
- }
211
- }
212
- action parse_infinity {
213
- if (json->allow_nan) {
214
- *result = CInfinity;
215
- } else {
216
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
217
- }
218
- }
219
- action parse_string {
220
- char *np = JSON_parse_string(json, fpc, pe, result);
221
- if (np == NULL) { fhold; fbreak; } else fexec np;
222
- }
223
-
224
- action parse_number {
225
- char *np;
226
- if(pe > fpc + 9 - json->quirks_mode && !strncmp(MinusInfinity, fpc, 9)) {
227
- if (json->allow_nan) {
228
- *result = CMinusInfinity;
229
- fexec p + 10;
230
- fhold; fbreak;
231
- } else {
232
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
233
- }
234
- }
235
- np = JSON_parse_float(json, fpc, pe, result);
236
- if (np != NULL) fexec np;
237
- np = JSON_parse_integer(json, fpc, pe, result);
238
- if (np != NULL) fexec np;
239
- fhold; fbreak;
240
- }
241
-
242
- action parse_array {
243
- char *np;
244
- json->current_nesting++;
245
- np = JSON_parse_array(json, fpc, pe, result);
246
- json->current_nesting--;
247
- if (np == NULL) { fhold; fbreak; } else fexec np;
248
- }
249
-
250
- action parse_object {
251
- char *np;
252
- json->current_nesting++;
253
- np = JSON_parse_object(json, fpc, pe, result);
254
- json->current_nesting--;
255
- if (np == NULL) { fhold; fbreak; } else fexec np;
256
- }
257
-
258
- action exit { fhold; fbreak; }
259
-
260
- main := (
261
- Vnull @parse_null |
262
- Vfalse @parse_false |
263
- Vtrue @parse_true |
264
- VNaN @parse_nan |
265
- VInfinity @parse_infinity |
266
- begin_number >parse_number |
267
- begin_string >parse_string |
268
- begin_array >parse_array |
269
- begin_object >parse_object
270
- ) %*exit;
271
- }%%
272
-
273
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
274
- {
275
- int cs = EVIL;
276
-
277
- %% write init;
278
- %% write exec;
279
-
280
- if (cs >= JSON_value_first_final) {
281
- return p;
282
- } else {
283
- return NULL;
284
- }
285
- }
286
-
287
- %%{
288
- machine JSON_integer;
289
-
290
- write data;
291
-
292
- action exit { fhold; fbreak; }
293
-
294
- main := '-'? ('0' | [1-9][0-9]*) (^[0-9]? @exit);
295
- }%%
296
-
297
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
298
- {
299
- int cs = EVIL;
300
-
301
- %% write init;
302
- json->memo = p;
303
- %% write exec;
304
-
305
- if (cs >= JSON_integer_first_final) {
306
- long len = p - json->memo;
307
- fbuffer_clear(json->fbuffer);
308
- fbuffer_append(json->fbuffer, json->memo, len);
309
- fbuffer_append_char(json->fbuffer, '\0');
310
- *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
311
- return p + 1;
312
- } else {
313
- return NULL;
314
- }
315
- }
316
-
317
- %%{
318
- machine JSON_float;
319
- include JSON_common;
320
-
321
- write data;
322
-
323
- action exit { fhold; fbreak; }
324
-
325
- main := '-'? (
326
- (('0' | [1-9][0-9]*) '.' [0-9]+ ([Ee] [+\-]?[0-9]+)?)
327
- | (('0' | [1-9][0-9]*) ([Ee] [+\-]?[0-9]+))
328
- ) (^[0-9Ee.\-]? @exit );
329
- }%%
330
-
331
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
332
- {
333
- int cs = EVIL;
334
-
335
- %% write init;
336
- json->memo = p;
337
- %% write exec;
338
-
339
- if (cs >= JSON_float_first_final) {
340
- long len = p - json->memo;
341
- fbuffer_clear(json->fbuffer);
342
- fbuffer_append(json->fbuffer, json->memo, len);
343
- fbuffer_append_char(json->fbuffer, '\0');
344
- *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
345
- return p + 1;
346
- } else {
347
- return NULL;
348
- }
349
- }
350
-
351
-
352
- %%{
353
- machine JSON_array;
354
- include JSON_common;
355
-
356
- write data;
357
-
358
- action parse_value {
359
- VALUE v = Qnil;
360
- char *np = JSON_parse_value(json, fpc, pe, &v);
361
- if (np == NULL) {
362
- fhold; fbreak;
363
- } else {
364
- if (NIL_P(json->array_class)) {
365
- rb_ary_push(*result, v);
366
- } else {
367
- rb_funcall(*result, i_leftshift, 1, v);
368
- }
369
- fexec np;
370
- }
371
- }
372
-
373
- action exit { fhold; fbreak; }
374
-
375
- next_element = value_separator ignore* begin_value >parse_value;
376
-
377
- main := begin_array ignore*
378
- ((begin_value >parse_value ignore*)
379
- (ignore* next_element ignore*)*)?
380
- end_array @exit;
381
- }%%
382
-
383
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
384
- {
385
- int cs = EVIL;
386
- VALUE array_class = json->array_class;
387
-
388
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
389
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
390
- }
391
- *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
392
-
393
- %% write init;
394
- %% write exec;
395
-
396
- if(cs >= JSON_array_first_final) {
397
- return p + 1;
398
- } else {
399
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
400
- return NULL;
401
- }
402
- }
403
-
404
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
405
- {
406
- char *p = string, *pe = string, *unescape;
407
- int unescape_len;
408
- char buf[4];
409
-
410
- while (pe < stringEnd) {
411
- if (*pe == '\\') {
412
- unescape = (char *) "?";
413
- unescape_len = 1;
414
- if (pe > p) rb_str_buf_cat(result, p, pe - p);
415
- switch (*++pe) {
416
- case 'n':
417
- unescape = (char *) "\n";
418
- break;
419
- case 'r':
420
- unescape = (char *) "\r";
421
- break;
422
- case 't':
423
- unescape = (char *) "\t";
424
- break;
425
- case '"':
426
- unescape = (char *) "\"";
427
- break;
428
- case '\\':
429
- unescape = (char *) "\\";
430
- break;
431
- case 'b':
432
- unescape = (char *) "\b";
433
- break;
434
- case 'f':
435
- unescape = (char *) "\f";
436
- break;
437
- case 'u':
438
- if (pe > stringEnd - 4) {
439
- return Qnil;
440
- } else {
441
- UTF32 ch = unescape_unicode((unsigned char *) ++pe);
442
- pe += 3;
443
- if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
444
- pe++;
445
- if (pe > stringEnd - 6) return Qnil;
446
- if (pe[0] == '\\' && pe[1] == 'u') {
447
- UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
448
- ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
449
- | (sur & 0x3FF));
450
- pe += 5;
451
- } else {
452
- unescape = (char *) "?";
453
- break;
454
- }
455
- }
456
- unescape_len = convert_UTF32_to_UTF8(buf, ch);
457
- unescape = buf;
458
- }
459
- break;
460
- default:
461
- p = pe;
462
- continue;
463
- }
464
- rb_str_buf_cat(result, unescape, unescape_len);
465
- p = ++pe;
466
- } else {
467
- pe++;
468
- }
469
- }
470
- rb_str_buf_cat(result, p, pe - p);
471
- return result;
472
- }
473
-
474
- %%{
475
- machine JSON_string;
476
- include JSON_common;
477
-
478
- write data;
479
-
480
- action parse_string {
481
- *result = json_string_unescape(*result, json->memo + 1, p);
482
- if (NIL_P(*result)) {
483
- fhold;
484
- fbreak;
485
- } else {
486
- FORCE_UTF8(*result);
487
- fexec p + 1;
488
- }
489
- }
490
-
491
- action exit { fhold; fbreak; }
492
-
493
- main := '"' ((^([\"\\] | 0..0x1f) | '\\'[\"\\/bfnrt] | '\\u'[0-9a-fA-F]{4} | '\\'^([\"\\/bfnrtu]|0..0x1f))* %parse_string) '"' @exit;
494
- }%%
495
-
496
- static int
497
- match_i(VALUE regexp, VALUE klass, VALUE memo)
498
- {
499
- if (regexp == Qundef) return ST_STOP;
500
- if (RTEST(rb_funcall(klass, i_json_creatable_p, 0)) &&
501
- RTEST(rb_funcall(regexp, i_match, 1, rb_ary_entry(memo, 0)))) {
502
- rb_ary_push(memo, klass);
503
- return ST_STOP;
504
- }
505
- return ST_CONTINUE;
506
- }
507
-
508
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
509
- {
510
- int cs = EVIL;
511
- VALUE match_string;
512
-
513
- *result = rb_str_buf_new(0);
514
- %% write init;
515
- json->memo = p;
516
- %% write exec;
517
-
518
- if (json->create_additions && RTEST(match_string = json->match_string)) {
519
- VALUE klass;
520
- VALUE memo = rb_ary_new2(2);
521
- rb_ary_push(memo, *result);
522
- rb_hash_foreach(match_string, match_i, memo);
523
- klass = rb_ary_entry(memo, 1);
524
- if (RTEST(klass)) {
525
- *result = rb_funcall(klass, i_json_create, 1, *result);
526
- }
527
- }
528
-
529
- if (json->symbolize_names && json->parsing_name) {
530
- *result = rb_str_intern(*result);
531
- }
532
- if (cs >= JSON_string_first_final) {
533
- return p + 1;
534
- } else {
535
- return NULL;
536
- }
537
- }
538
-
539
- /*
540
- * Document-class: JSON::Ext::Parser
541
- *
542
- * This is the JSON parser implemented as a C extension. It can be configured
543
- * to be used by setting
544
- *
545
- * JSON.parser = JSON::Ext::Parser
546
- *
547
- * with the method parser= in JSON.
548
- *
549
- */
550
-
551
- static VALUE convert_encoding(VALUE source)
552
- {
553
- char *ptr = RSTRING_PTR(source);
554
- long len = RSTRING_LEN(source);
555
- if (len < 2) {
556
- rb_raise(eParserError, "A JSON text must at least contain two octets!");
557
- }
558
- #ifdef HAVE_RUBY_ENCODING_H
559
- {
560
- VALUE encoding = rb_funcall(source, i_encoding, 0);
561
- if (encoding == CEncoding_ASCII_8BIT) {
562
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
563
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
564
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
565
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
566
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
567
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
568
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
569
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
570
- } else {
571
- source = rb_str_dup(source);
572
- FORCE_UTF8(source);
573
- }
574
- } else {
575
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
576
- }
577
- }
578
- #else
579
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
580
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
581
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
582
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
583
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
584
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
585
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
586
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
587
- }
588
- #endif
589
- return source;
590
- }
591
-
592
- /*
593
- * call-seq: new(source, opts => {})
594
- *
595
- * Creates a new JSON::Ext::Parser instance for the string _source_.
596
- *
597
- * Creates a new JSON::Ext::Parser instance for the string _source_.
598
- *
599
- * It will be configured by the _opts_ hash. _opts_ can have the following
600
- * keys:
601
- *
602
- * _opts_ can have the following keys:
603
- * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
604
- * structures. Disable depth checking with :max_nesting => false|nil|0, it
605
- * defaults to 100.
606
- * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
607
- * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
608
- * false.
609
- * * *symbolize_names*: If set to true, returns symbols for the names
610
- * (keys) in a JSON object. Otherwise strings are returned, which is also
611
- * the default.
612
- * * *create_additions*: If set to false, the Parser doesn't create
613
- * additions even if a matchin class and create_id was found. This option
614
- * defaults to true.
615
- * * *object_class*: Defaults to Hash
616
- * * *array_class*: Defaults to Array
617
- */
618
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
619
- {
620
- VALUE source, opts;
621
- GET_PARSER_INIT;
622
-
623
- if (json->Vsource) {
624
- rb_raise(rb_eTypeError, "already initialized instance");
625
- }
626
- rb_scan_args(argc, argv, "11", &source, &opts);
627
- if (!NIL_P(opts)) {
628
- opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
629
- if (NIL_P(opts)) {
630
- rb_raise(rb_eArgError, "opts needs to be like a hash");
631
- } else {
632
- VALUE tmp = ID2SYM(i_max_nesting);
633
- if (option_given_p(opts, tmp)) {
634
- VALUE max_nesting = rb_hash_aref(opts, tmp);
635
- if (RTEST(max_nesting)) {
636
- Check_Type(max_nesting, T_FIXNUM);
637
- json->max_nesting = FIX2INT(max_nesting);
638
- } else {
639
- json->max_nesting = 0;
640
- }
641
- } else {
642
- json->max_nesting = 100;
643
- }
644
- tmp = ID2SYM(i_allow_nan);
645
- if (option_given_p(opts, tmp)) {
646
- json->allow_nan = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
647
- } else {
648
- json->allow_nan = 0;
649
- }
650
- tmp = ID2SYM(i_symbolize_names);
651
- if (option_given_p(opts, tmp)) {
652
- json->symbolize_names = RTEST(rb_hash_aref(opts, tmp)) ? 1 : 0;
653
- } else {
654
- json->symbolize_names = 0;
655
- }
656
- tmp = ID2SYM(i_quirks_mode);
657
- if (option_given_p(opts, tmp)) {
658
- VALUE quirks_mode = rb_hash_aref(opts, tmp);
659
- json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
660
- } else {
661
- json->quirks_mode = 0;
662
- }
663
- tmp = ID2SYM(i_create_additions);
664
- if (option_given_p(opts, tmp)) {
665
- json->create_additions = RTEST(rb_hash_aref(opts, tmp));
666
- } else {
667
- json->create_additions = 0;
668
- }
669
- tmp = ID2SYM(i_create_id);
670
- if (option_given_p(opts, tmp)) {
671
- json->create_id = rb_hash_aref(opts, tmp);
672
- } else {
673
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
674
- }
675
- tmp = ID2SYM(i_object_class);
676
- if (option_given_p(opts, tmp)) {
677
- json->object_class = rb_hash_aref(opts, tmp);
678
- } else {
679
- json->object_class = Qnil;
680
- }
681
- tmp = ID2SYM(i_array_class);
682
- if (option_given_p(opts, tmp)) {
683
- json->array_class = rb_hash_aref(opts, tmp);
684
- } else {
685
- json->array_class = Qnil;
686
- }
687
- tmp = ID2SYM(i_match_string);
688
- if (option_given_p(opts, tmp)) {
689
- VALUE match_string = rb_hash_aref(opts, tmp);
690
- json->match_string = RTEST(match_string) ? match_string : Qnil;
691
- } else {
692
- json->match_string = Qnil;
693
- }
694
- }
695
- } else {
696
- json->max_nesting = 100;
697
- json->allow_nan = 0;
698
- json->create_additions = 1;
699
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
700
- json->object_class = Qnil;
701
- json->array_class = Qnil;
702
- }
703
- source = rb_convert_type(source, T_STRING, "String", "to_str");
704
- if (!json->quirks_mode) {
705
- source = convert_encoding(StringValue(source));
706
- }
707
- json->current_nesting = 0;
708
- StringValue(source);
709
- json->len = RSTRING_LEN(source);
710
- json->source = RSTRING_PTR(source);;
711
- json->Vsource = source;
712
- return self;
713
- }
714
-
715
- %%{
716
- machine JSON;
717
-
718
- write data;
719
-
720
- include JSON_common;
721
-
722
- action parse_object {
723
- char *np;
724
- json->current_nesting = 1;
725
- np = JSON_parse_object(json, fpc, pe, &result);
726
- if (np == NULL) { fhold; fbreak; } else fexec np;
727
- }
728
-
729
- action parse_array {
730
- char *np;
731
- json->current_nesting = 1;
732
- np = JSON_parse_array(json, fpc, pe, &result);
733
- if (np == NULL) { fhold; fbreak; } else fexec np;
734
- }
735
-
736
- main := ignore* (
737
- begin_object >parse_object |
738
- begin_array >parse_array
739
- ) ignore*;
740
- }%%
741
-
742
- static VALUE cParser_parse_strict(VALUE self)
743
- {
744
- char *p, *pe;
745
- int cs = EVIL;
746
- VALUE result = Qnil;
747
- GET_PARSER;
748
-
749
- %% write init;
750
- p = json->source;
751
- pe = p + json->len;
752
- %% write exec;
753
-
754
- if (cs >= JSON_first_final && p == pe) {
755
- return result;
756
- } else {
757
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
758
- return Qnil;
759
- }
760
- }
761
-
762
-
763
- %%{
764
- machine JSON_quirks_mode;
765
-
766
- write data;
767
-
768
- include JSON_common;
769
-
770
- action parse_value {
771
- char *np = JSON_parse_value(json, fpc, pe, &result);
772
- if (np == NULL) { fhold; fbreak; } else fexec np;
773
- }
774
-
775
- main := ignore* (
776
- begin_value >parse_value
777
- ) ignore*;
778
- }%%
779
-
780
- static VALUE cParser_parse_quirks_mode(VALUE self)
781
- {
782
- char *p, *pe;
783
- int cs = EVIL;
784
- VALUE result = Qnil;
785
- GET_PARSER;
786
-
787
- %% write init;
788
- p = json->source;
789
- pe = p + json->len;
790
- %% write exec;
791
-
792
- if (cs >= JSON_quirks_mode_first_final && p == pe) {
793
- return result;
794
- } else {
795
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
796
- return Qnil;
797
- }
798
- }
799
-
800
- /*
801
- * call-seq: parse()
802
- *
803
- * Parses the current JSON text _source_ and returns the complete data
804
- * structure as a result.
805
- */
806
- static VALUE cParser_parse(VALUE self)
807
- {
808
- GET_PARSER;
809
-
810
- if (json->quirks_mode) {
811
- return cParser_parse_quirks_mode(self);
812
- } else {
813
- return cParser_parse_strict(self);
814
- }
815
- }
816
-
817
-
818
- static JSON_Parser *JSON_allocate()
819
- {
820
- JSON_Parser *json = ALLOC(JSON_Parser);
821
- MEMZERO(json, JSON_Parser, 1);
822
- json->fbuffer = fbuffer_alloc(0);
823
- return json;
824
- }
825
-
826
- static void JSON_mark(JSON_Parser *json)
827
- {
828
- rb_gc_mark_maybe(json->Vsource);
829
- rb_gc_mark_maybe(json->create_id);
830
- rb_gc_mark_maybe(json->object_class);
831
- rb_gc_mark_maybe(json->array_class);
832
- rb_gc_mark_maybe(json->match_string);
833
- }
834
-
835
- static void JSON_free(JSON_Parser *json)
836
- {
837
- fbuffer_free(json->fbuffer);
838
- ruby_xfree(json);
839
- }
840
-
841
- static VALUE cJSON_parser_s_allocate(VALUE klass)
842
- {
843
- JSON_Parser *json = JSON_allocate();
844
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
845
- }
846
-
847
- /*
848
- * call-seq: source()
849
- *
850
- * Returns a copy of the current _source_ string, that was used to construct
851
- * this Parser.
852
- */
853
- static VALUE cParser_source(VALUE self)
854
- {
855
- GET_PARSER;
856
- return rb_str_dup(json->Vsource);
857
- }
858
-
859
- /*
860
- * call-seq: quirks_mode?()
861
- *
862
- * Returns a true, if this parser is in quirks_mode, false otherwise.
863
- */
864
- static VALUE cParser_quirks_mode_p(VALUE self)
865
- {
866
- GET_PARSER;
867
- return json->quirks_mode ? Qtrue : Qfalse;
868
- }
869
-
870
-
871
- void Init_parser()
872
- {
873
- rb_require("json/common");
874
- mJSON = rb_define_module("JSON");
875
- mExt = rb_define_module_under(mJSON, "Ext");
876
- cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
877
- eParserError = rb_path2class("JSON::ParserError");
878
- eNestingError = rb_path2class("JSON::NestingError");
879
- rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
880
- rb_define_method(cParser, "initialize", cParser_initialize, -1);
881
- rb_define_method(cParser, "parse", cParser_parse, 0);
882
- rb_define_method(cParser, "source", cParser_source, 0);
883
- rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
884
-
885
- CNaN = rb_const_get(mJSON, rb_intern("NaN"));
886
- CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
887
- CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
888
-
889
- i_json_creatable_p = rb_intern("json_creatable?");
890
- i_json_create = rb_intern("json_create");
891
- i_create_id = rb_intern("create_id");
892
- i_create_additions = rb_intern("create_additions");
893
- i_chr = rb_intern("chr");
894
- i_max_nesting = rb_intern("max_nesting");
895
- i_allow_nan = rb_intern("allow_nan");
896
- i_symbolize_names = rb_intern("symbolize_names");
897
- i_quirks_mode = rb_intern("quirks_mode");
898
- i_object_class = rb_intern("object_class");
899
- i_array_class = rb_intern("array_class");
900
- i_match = rb_intern("match");
901
- i_match_string = rb_intern("match_string");
902
- i_key_p = rb_intern("key?");
903
- i_deep_const_get = rb_intern("deep_const_get");
904
- i_aset = rb_intern("[]=");
905
- i_aref = rb_intern("[]");
906
- i_leftshift = rb_intern("<<");
907
- #ifdef HAVE_RUBY_ENCODING_H
908
- CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
909
- CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
910
- CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
911
- CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
912
- CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
913
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
914
- i_encoding = rb_intern("encoding");
915
- i_encode = rb_intern("encode");
916
- #else
917
- i_iconv = rb_intern("iconv");
918
- #endif
919
- }
920
-
921
- /*
922
- * Local variables:
923
- * mode: c
924
- * c-file-style: ruby
925
- * indent-tabs-mode: nil
926
- * End:
927
- */