engineyard-serverside 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/lib/engineyard-serverside.rb +3 -3
  2. data/lib/engineyard-serverside/configuration.rb +6 -6
  3. data/lib/engineyard-serverside/deploy.rb +11 -7
  4. data/lib/engineyard-serverside/version.rb +1 -1
  5. data/lib/vendor/multi_json/CHANGELOG.md +121 -0
  6. data/lib/vendor/multi_json/CONTRIBUTING.md +46 -0
  7. data/lib/vendor/multi_json/Gemfile +31 -0
  8. data/lib/vendor/multi_json/LICENSE.md +20 -0
  9. data/lib/vendor/multi_json/README.md +105 -0
  10. data/lib/vendor/multi_json/Rakefile +12 -0
  11. data/lib/vendor/multi_json/lib/multi_json.rb +137 -0
  12. data/lib/vendor/multi_json/lib/multi_json/adapters/gson.rb +20 -0
  13. data/lib/vendor/multi_json/lib/multi_json/adapters/json_common.rb +35 -0
  14. data/lib/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +12 -0
  15. data/lib/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +12 -0
  16. data/lib/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +35 -0
  17. data/lib/vendor/multi_json/lib/multi_json/adapters/oj.rb +29 -0
  18. data/lib/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +58 -0
  19. data/lib/vendor/multi_json/lib/multi_json/adapters/yajl.rb +20 -0
  20. data/lib/vendor/multi_json/lib/multi_json/vendor/okjson.rb +602 -0
  21. data/lib/vendor/multi_json/lib/multi_json/version.rb +3 -0
  22. data/lib/vendor/multi_json/multi_json.gemspec +22 -0
  23. data/lib/vendor/multi_json/spec/adapter_shared_example.rb +162 -0
  24. data/lib/vendor/multi_json/spec/helper.rb +45 -0
  25. data/lib/vendor/multi_json/spec/json_common_shared_example.rb +36 -0
  26. data/lib/vendor/multi_json/spec/multi_json_spec.rb +151 -0
  27. data/spec/configuration_spec.rb +79 -1
  28. data/spec/deploy_hook_spec.rb +2 -2
  29. data/spec/spec_helper.rb +1 -1
  30. metadata +26 -120
  31. data/lib/vendor/json_pure/CHANGES +0 -166
  32. data/lib/vendor/json_pure/COPYING +0 -58
  33. data/lib/vendor/json_pure/GPL +0 -340
  34. data/lib/vendor/json_pure/README +0 -358
  35. data/lib/vendor/json_pure/Rakefile +0 -292
  36. data/lib/vendor/json_pure/TODO +0 -1
  37. data/lib/vendor/json_pure/VERSION +0 -1
  38. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
  39. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
  40. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
  41. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
  42. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
  43. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
  44. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
  45. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
  46. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
  47. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
  48. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
  49. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
  50. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
  51. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
  52. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
  53. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
  54. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
  55. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
  56. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
  57. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
  58. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
  59. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
  60. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
  61. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
  62. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
  63. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
  64. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
  65. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
  66. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
  67. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
  68. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
  69. data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
  70. data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
  71. data/lib/vendor/json_pure/benchmarks/ohai.json +0 -1216
  72. data/lib/vendor/json_pure/benchmarks/ohai.ruby +0 -1
  73. data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
  74. data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
  75. data/lib/vendor/json_pure/bin/edit_json.rb +0 -9
  76. data/lib/vendor/json_pure/bin/prettify_json.rb +0 -75
  77. data/lib/vendor/json_pure/data/example.json +0 -1
  78. data/lib/vendor/json_pure/data/index.html +0 -38
  79. data/lib/vendor/json_pure/data/prototype.js +0 -4184
  80. data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -16
  81. data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1323
  82. data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +0 -170
  83. data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -15
  84. data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +0 -1935
  85. data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +0 -71
  86. data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -792
  87. data/lib/vendor/json_pure/install.rb +0 -26
  88. data/lib/vendor/json_pure/lib/json.rb +0 -10
  89. data/lib/vendor/json_pure/lib/json/Array.xpm +0 -21
  90. data/lib/vendor/json_pure/lib/json/FalseClass.xpm +0 -21
  91. data/lib/vendor/json_pure/lib/json/Hash.xpm +0 -21
  92. data/lib/vendor/json_pure/lib/json/Key.xpm +0 -73
  93. data/lib/vendor/json_pure/lib/json/NilClass.xpm +0 -21
  94. data/lib/vendor/json_pure/lib/json/Numeric.xpm +0 -28
  95. data/lib/vendor/json_pure/lib/json/String.xpm +0 -96
  96. data/lib/vendor/json_pure/lib/json/TrueClass.xpm +0 -21
  97. data/lib/vendor/json_pure/lib/json/add/core.rb +0 -148
  98. data/lib/vendor/json_pure/lib/json/add/rails.rb +0 -58
  99. data/lib/vendor/json_pure/lib/json/common.rb +0 -397
  100. data/lib/vendor/json_pure/lib/json/editor.rb +0 -1371
  101. data/lib/vendor/json_pure/lib/json/ext.rb +0 -15
  102. data/lib/vendor/json_pure/lib/json/json.xpm +0 -1499
  103. data/lib/vendor/json_pure/lib/json/pure.rb +0 -77
  104. data/lib/vendor/json_pure/lib/json/pure/generator.rb +0 -452
  105. data/lib/vendor/json_pure/lib/json/pure/parser.rb +0 -307
  106. data/lib/vendor/json_pure/lib/json/version.rb +0 -8
  107. data/lib/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  108. data/lib/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  109. data/lib/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  110. data/lib/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  111. data/lib/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  112. data/lib/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  113. data/lib/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  114. data/lib/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  115. data/lib/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  116. data/lib/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  117. data/lib/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  118. data/lib/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  119. data/lib/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  120. data/lib/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  121. data/lib/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  122. data/lib/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  123. data/lib/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  124. data/lib/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  125. data/lib/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  126. data/lib/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  127. data/lib/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  128. data/lib/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  129. data/lib/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  130. data/lib/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  131. data/lib/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  132. data/lib/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  133. data/lib/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  134. data/lib/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  135. data/lib/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  136. data/lib/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  137. data/lib/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  138. data/lib/vendor/json_pure/tests/test_json.rb +0 -361
  139. data/lib/vendor/json_pure/tests/test_json_addition.rb +0 -162
  140. data/lib/vendor/json_pure/tests/test_json_encoding.rb +0 -68
  141. data/lib/vendor/json_pure/tests/test_json_fixtures.rb +0 -34
  142. data/lib/vendor/json_pure/tests/test_json_generate.rb +0 -122
  143. data/lib/vendor/json_pure/tests/test_json_rails.rb +0 -144
  144. data/lib/vendor/json_pure/tests/test_json_unicode.rb +0 -76
  145. data/lib/vendor/json_pure/tools/fuzz.rb +0 -139
  146. data/lib/vendor/json_pure/tools/server.rb +0 -61
@@ -1,71 +0,0 @@
1
- #ifndef _PARSER_H_
2
- #define _PARSER_H_
3
-
4
- #include "ruby.h"
5
-
6
- #if HAVE_RE_H
7
- #include "re.h"
8
- #endif
9
-
10
- #ifdef HAVE_RUBY_ENCODING_H
11
- #include "ruby/encoding.h"
12
- #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
13
- #else
14
- #define FORCE_UTF8(obj)
15
- #endif
16
-
17
- #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
18
-
19
- /* unicode */
20
-
21
- typedef unsigned long UTF32; /* at least 32 bits */
22
- typedef unsigned short UTF16; /* at least 16 bits */
23
- typedef unsigned char UTF8; /* typically 8 bits */
24
-
25
- #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
26
- #define UNI_SUR_HIGH_START (UTF32)0xD800
27
- #define UNI_SUR_HIGH_END (UTF32)0xDBFF
28
- #define UNI_SUR_LOW_START (UTF32)0xDC00
29
- #define UNI_SUR_LOW_END (UTF32)0xDFFF
30
-
31
- typedef struct JSON_ParserStruct {
32
- VALUE Vsource;
33
- char *source;
34
- long len;
35
- char *memo;
36
- VALUE create_id;
37
- int max_nesting;
38
- int current_nesting;
39
- int allow_nan;
40
- int parsing_name;
41
- int symbolize_names;
42
- VALUE object_class;
43
- VALUE array_class;
44
- } JSON_Parser;
45
-
46
- #define GET_PARSER \
47
- JSON_Parser *json; \
48
- Data_Get_Struct(self, JSON_Parser, json)
49
-
50
- #define MinusInfinity "-Infinity"
51
- #define EVIL 0x666
52
-
53
- static UTF32 unescape_unicode(const unsigned char *p);
54
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
55
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
56
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
57
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
58
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
59
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
60
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
61
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
62
- static VALUE convert_encoding(VALUE source);
63
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
64
- static VALUE cParser_parse(VALUE self);
65
- static JSON_Parser *JSON_allocate();
66
- static void JSON_mark(JSON_Parser *json);
67
- static void JSON_free(JSON_Parser *json);
68
- static VALUE cJSON_parser_s_allocate(VALUE klass);
69
- static VALUE cParser_source(VALUE self);
70
-
71
- #endif
@@ -1,792 +0,0 @@
1
- #include "parser.h"
2
-
3
- /* unicode */
4
-
5
- static const char digit_values[256] = {
6
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
9
- -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1,
10
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
11
- 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
12
- -1, -1, -1, -1, -1, -1, -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
20
- };
21
-
22
- static UTF32 unescape_unicode(const unsigned char *p)
23
- {
24
- char b;
25
- UTF32 result = 0;
26
- b = digit_values[p[0]];
27
- if (b < 0) return UNI_REPLACEMENT_CHAR;
28
- result = (result << 4) | b;
29
- b = digit_values[p[1]];
30
- result = (result << 4) | b;
31
- if (b < 0) return UNI_REPLACEMENT_CHAR;
32
- b = digit_values[p[2]];
33
- result = (result << 4) | b;
34
- if (b < 0) return UNI_REPLACEMENT_CHAR;
35
- b = digit_values[p[3]];
36
- result = (result << 4) | b;
37
- if (b < 0) return UNI_REPLACEMENT_CHAR;
38
- return result;
39
- }
40
-
41
- static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
42
- {
43
- int len = 1;
44
- if (ch <= 0x7F) {
45
- buf[0] = (char) ch;
46
- } else if (ch <= 0x07FF) {
47
- buf[0] = (char) ((ch >> 6) | 0xC0);
48
- buf[1] = (char) ((ch & 0x3F) | 0x80);
49
- len++;
50
- } else if (ch <= 0xFFFF) {
51
- buf[0] = (char) ((ch >> 12) | 0xE0);
52
- buf[1] = (char) (((ch >> 6) & 0x3F) | 0x80);
53
- buf[2] = (char) ((ch & 0x3F) | 0x80);
54
- len += 2;
55
- } else if (ch <= 0x1fffff) {
56
- buf[0] =(char) ((ch >> 18) | 0xF0);
57
- buf[1] =(char) (((ch >> 12) & 0x3F) | 0x80);
58
- buf[2] =(char) (((ch >> 6) & 0x3F) | 0x80);
59
- buf[3] =(char) ((ch & 0x3F) | 0x80);
60
- len += 3;
61
- } else {
62
- buf[0] = '?';
63
- }
64
- return len;
65
- }
66
-
67
- #ifdef HAVE_RUBY_ENCODING_H
68
- static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
69
- CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
70
- static ID i_encoding, i_encode, i_encode_bang, i_force_encoding;
71
- #else
72
- static ID i_iconv;
73
- #endif
74
-
75
- static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
76
- static VALUE CNaN, CInfinity, CMinusInfinity;
77
-
78
- static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
79
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class,
80
- i_array_class, i_key_p, i_deep_const_get;
81
-
82
- %%{
83
- machine JSON_common;
84
-
85
- cr = '\n';
86
- cr_neg = [^\n];
87
- ws = [ \t\r\n];
88
- c_comment = '/*' ( any* - (any* '*/' any* ) ) '*/';
89
- cpp_comment = '//' cr_neg* cr;
90
- comment = c_comment | cpp_comment;
91
- ignore = ws | comment;
92
- name_separator = ':';
93
- value_separator = ',';
94
- Vnull = 'null';
95
- Vfalse = 'false';
96
- Vtrue = 'true';
97
- VNaN = 'NaN';
98
- VInfinity = 'Infinity';
99
- VMinusInfinity = '-Infinity';
100
- begin_value = [nft"\-[{NI] | digit;
101
- begin_object = '{';
102
- end_object = '}';
103
- begin_array = '[';
104
- end_array = ']';
105
- begin_string = '"';
106
- begin_name = begin_string;
107
- begin_number = digit | '-';
108
- }%%
109
-
110
- %%{
111
- machine JSON_object;
112
- include JSON_common;
113
-
114
- write data;
115
-
116
- action parse_value {
117
- VALUE v = Qnil;
118
- char *np = JSON_parse_value(json, fpc, pe, &v);
119
- if (np == NULL) {
120
- fhold; fbreak;
121
- } else {
122
- rb_hash_aset(*result, last_name, v);
123
- fexec np;
124
- }
125
- }
126
-
127
- action parse_name {
128
- char *np;
129
- json->parsing_name = 1;
130
- np = JSON_parse_string(json, fpc, pe, &last_name);
131
- json->parsing_name = 0;
132
- if (np == NULL) { fhold; fbreak; } else fexec np;
133
- }
134
-
135
- action exit { fhold; fbreak; }
136
-
137
- a_pair = ignore* begin_name >parse_name
138
- ignore* name_separator ignore*
139
- begin_value >parse_value;
140
-
141
- main := begin_object
142
- (a_pair (ignore* value_separator a_pair)*)?
143
- ignore* end_object @exit;
144
- }%%
145
-
146
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
147
- {
148
- int cs = EVIL;
149
- VALUE last_name = Qnil;
150
- VALUE object_class = json->object_class;
151
-
152
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
153
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
154
- }
155
-
156
- *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
157
-
158
- %% write init;
159
- %% write exec;
160
-
161
- if (cs >= JSON_object_first_final) {
162
- if (RTEST(json->create_id)) {
163
- VALUE klassname = rb_hash_aref(*result, json->create_id);
164
- if (!NIL_P(klassname)) {
165
- VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname);
166
- if RTEST(rb_funcall(klass, i_json_creatable_p, 0)) {
167
- *result = rb_funcall(klass, i_json_create, 1, *result);
168
- }
169
- }
170
- }
171
- return p + 1;
172
- } else {
173
- return NULL;
174
- }
175
- }
176
-
177
- %%{
178
- machine JSON_value;
179
- include JSON_common;
180
-
181
- write data;
182
-
183
- action parse_null {
184
- *result = Qnil;
185
- }
186
- action parse_false {
187
- *result = Qfalse;
188
- }
189
- action parse_true {
190
- *result = Qtrue;
191
- }
192
- action parse_nan {
193
- if (json->allow_nan) {
194
- *result = CNaN;
195
- } else {
196
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
197
- }
198
- }
199
- action parse_infinity {
200
- if (json->allow_nan) {
201
- *result = CInfinity;
202
- } else {
203
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
204
- }
205
- }
206
- action parse_string {
207
- char *np = JSON_parse_string(json, fpc, pe, result);
208
- if (np == NULL) { fhold; fbreak; } else fexec np;
209
- }
210
-
211
- action parse_number {
212
- char *np;
213
- if(pe > fpc + 9 && !strncmp(MinusInfinity, fpc, 9)) {
214
- if (json->allow_nan) {
215
- *result = CMinusInfinity;
216
- fexec p + 10;
217
- fhold; fbreak;
218
- } else {
219
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
220
- }
221
- }
222
- np = JSON_parse_float(json, fpc, pe, result);
223
- if (np != NULL) fexec np;
224
- np = JSON_parse_integer(json, fpc, pe, result);
225
- if (np != NULL) fexec np;
226
- fhold; fbreak;
227
- }
228
-
229
- action parse_array {
230
- char *np;
231
- json->current_nesting++;
232
- np = JSON_parse_array(json, fpc, pe, result);
233
- json->current_nesting--;
234
- if (np == NULL) { fhold; fbreak; } else fexec np;
235
- }
236
-
237
- action parse_object {
238
- char *np;
239
- json->current_nesting++;
240
- np = JSON_parse_object(json, fpc, pe, result);
241
- json->current_nesting--;
242
- if (np == NULL) { fhold; fbreak; } else fexec np;
243
- }
244
-
245
- action exit { fhold; fbreak; }
246
-
247
- main := (
248
- Vnull @parse_null |
249
- Vfalse @parse_false |
250
- Vtrue @parse_true |
251
- VNaN @parse_nan |
252
- VInfinity @parse_infinity |
253
- begin_number >parse_number |
254
- begin_string >parse_string |
255
- begin_array >parse_array |
256
- begin_object >parse_object
257
- ) %*exit;
258
- }%%
259
-
260
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
261
- {
262
- int cs = EVIL;
263
-
264
- %% write init;
265
- %% write exec;
266
-
267
- if (cs >= JSON_value_first_final) {
268
- return p;
269
- } else {
270
- return NULL;
271
- }
272
- }
273
-
274
- %%{
275
- machine JSON_integer;
276
-
277
- write data;
278
-
279
- action exit { fhold; fbreak; }
280
-
281
- main := '-'? ('0' | [1-9][0-9]*) (^[0-9] @exit);
282
- }%%
283
-
284
- static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
285
- {
286
- int cs = EVIL;
287
-
288
- %% write init;
289
- json->memo = p;
290
- %% write exec;
291
-
292
- if (cs >= JSON_integer_first_final) {
293
- long len = p - json->memo;
294
- *result = rb_Integer(rb_str_new(json->memo, len));
295
- return p + 1;
296
- } else {
297
- return NULL;
298
- }
299
- }
300
-
301
- %%{
302
- machine JSON_float;
303
- include JSON_common;
304
-
305
- write data;
306
-
307
- action exit { fhold; fbreak; }
308
-
309
- main := '-'? (
310
- (('0' | [1-9][0-9]*) '.' [0-9]+ ([Ee] [+\-]?[0-9]+)?)
311
- | (('0' | [1-9][0-9]*) ([Ee] [+\-]?[0-9]+))
312
- ) (^[0-9Ee.\-] @exit );
313
- }%%
314
-
315
- static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
316
- {
317
- int cs = EVIL;
318
-
319
- %% write init;
320
- json->memo = p;
321
- %% write exec;
322
-
323
- if (cs >= JSON_float_first_final) {
324
- long len = p - json->memo;
325
- *result = rb_Float(rb_str_new(json->memo, len));
326
- return p + 1;
327
- } else {
328
- return NULL;
329
- }
330
- }
331
-
332
-
333
- %%{
334
- machine JSON_array;
335
- include JSON_common;
336
-
337
- write data;
338
-
339
- action parse_value {
340
- VALUE v = Qnil;
341
- char *np = JSON_parse_value(json, fpc, pe, &v);
342
- if (np == NULL) {
343
- fhold; fbreak;
344
- } else {
345
- rb_ary_push(*result, v);
346
- fexec np;
347
- }
348
- }
349
-
350
- action exit { fhold; fbreak; }
351
-
352
- next_element = value_separator ignore* begin_value >parse_value;
353
-
354
- main := begin_array ignore*
355
- ((begin_value >parse_value ignore*)
356
- (ignore* next_element ignore*)*)?
357
- end_array @exit;
358
- }%%
359
-
360
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
361
- {
362
- int cs = EVIL;
363
- VALUE array_class = json->array_class;
364
-
365
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
366
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
367
- }
368
- *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
369
-
370
- %% write init;
371
- %% write exec;
372
-
373
- if(cs >= JSON_array_first_final) {
374
- return p + 1;
375
- } else {
376
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
377
- return NULL;
378
- }
379
- }
380
-
381
- static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
382
- {
383
- char *p = string, *pe = string, *unescape;
384
- int unescape_len;
385
-
386
- while (pe < stringEnd) {
387
- if (*pe == '\\') {
388
- unescape = (char *) "?";
389
- unescape_len = 1;
390
- if (pe > p) rb_str_buf_cat(result, p, pe - p);
391
- switch (*++pe) {
392
- case 'n':
393
- unescape = (char *) "\n";
394
- break;
395
- case 'r':
396
- unescape = (char *) "\r";
397
- break;
398
- case 't':
399
- unescape = (char *) "\t";
400
- break;
401
- case '"':
402
- unescape = (char *) "\"";
403
- break;
404
- case '\\':
405
- unescape = (char *) "\\";
406
- break;
407
- case 'b':
408
- unescape = (char *) "\b";
409
- break;
410
- case 'f':
411
- unescape = (char *) "\f";
412
- break;
413
- case 'u':
414
- if (pe > stringEnd - 4) {
415
- return Qnil;
416
- } else {
417
- char buf[4];
418
- UTF32 ch = unescape_unicode((unsigned char *) ++pe);
419
- pe += 3;
420
- if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
421
- pe++;
422
- if (pe > stringEnd - 6) return Qnil;
423
- if (pe[0] == '\\' && pe[1] == 'u') {
424
- UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
425
- ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
426
- | (sur & 0x3FF));
427
- pe += 5;
428
- } else {
429
- unescape = (char *) "?";
430
- break;
431
- }
432
- }
433
- unescape_len = convert_UTF32_to_UTF8(buf, ch);
434
- unescape = buf;
435
- }
436
- break;
437
- default:
438
- p = pe;
439
- continue;
440
- }
441
- rb_str_buf_cat(result, unescape, unescape_len);
442
- p = ++pe;
443
- } else {
444
- pe++;
445
- }
446
- }
447
- rb_str_buf_cat(result, p, pe - p);
448
- return result;
449
- }
450
-
451
- %%{
452
- machine JSON_string;
453
- include JSON_common;
454
-
455
- write data;
456
-
457
- action parse_string {
458
- *result = json_string_unescape(*result, json->memo + 1, p);
459
- if (NIL_P(*result)) {
460
- fhold;
461
- fbreak;
462
- } else {
463
- FORCE_UTF8(*result);
464
- fexec p + 1;
465
- }
466
- }
467
-
468
- action exit { fhold; fbreak; }
469
-
470
- main := '"' ((^(["\\] | 0..0x1f) | '\\'["\\/bfnrt] | '\\u'[0-9a-fA-F]{4} | '\\'^(["\\/bfnrtu]|0..0x1f))* %parse_string) '"' @exit;
471
- }%%
472
-
473
- static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
474
- {
475
- int cs = EVIL;
476
-
477
- *result = rb_str_buf_new(0);
478
- %% write init;
479
- json->memo = p;
480
- %% write exec;
481
-
482
- if (json->symbolize_names && json->parsing_name) {
483
- *result = rb_str_intern(*result);
484
- }
485
- if (cs >= JSON_string_first_final) {
486
- return p + 1;
487
- } else {
488
- return NULL;
489
- }
490
- }
491
-
492
-
493
- %%{
494
- machine JSON;
495
-
496
- write data;
497
-
498
- include JSON_common;
499
-
500
- action parse_object {
501
- char *np;
502
- json->current_nesting = 1;
503
- np = JSON_parse_object(json, fpc, pe, &result);
504
- if (np == NULL) { fhold; fbreak; } else fexec np;
505
- }
506
-
507
- action parse_array {
508
- char *np;
509
- json->current_nesting = 1;
510
- np = JSON_parse_array(json, fpc, pe, &result);
511
- if (np == NULL) { fhold; fbreak; } else fexec np;
512
- }
513
-
514
- main := ignore* (
515
- begin_object >parse_object |
516
- begin_array >parse_array
517
- ) ignore*;
518
- }%%
519
-
520
- /*
521
- * Document-class: JSON::Ext::Parser
522
- *
523
- * This is the JSON parser implemented as a C extension. It can be configured
524
- * to be used by setting
525
- *
526
- * JSON.parser = JSON::Ext::Parser
527
- *
528
- * with the method parser= in JSON.
529
- *
530
- */
531
-
532
- static VALUE convert_encoding(VALUE source)
533
- {
534
- char *ptr = RSTRING_PTR(source);
535
- long len = RSTRING_LEN(source);
536
- if (len < 2) {
537
- rb_raise(eParserError, "A JSON text must at least contain two octets!");
538
- }
539
- #ifdef HAVE_RUBY_ENCODING_H
540
- {
541
- VALUE encoding = rb_funcall(source, i_encoding, 0);
542
- if (encoding == CEncoding_ASCII_8BIT) {
543
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
544
- source = rb_str_dup(source);
545
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32BE);
546
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
547
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
548
- source = rb_str_dup(source);
549
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16BE);
550
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
551
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
552
- source = rb_str_dup(source);
553
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32LE);
554
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
555
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
556
- source = rb_str_dup(source);
557
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16LE);
558
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
559
- } else {
560
- FORCE_UTF8(source);
561
- }
562
- } else {
563
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
564
- }
565
- }
566
- #else
567
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
568
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
569
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
570
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
571
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
572
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
573
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
574
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
575
- }
576
- #endif
577
- return source;
578
- }
579
-
580
- /*
581
- * call-seq: new(source, opts => {})
582
- *
583
- * Creates a new JSON::Ext::Parser instance for the string _source_.
584
- *
585
- * Creates a new JSON::Ext::Parser instance for the string _source_.
586
- *
587
- * It will be configured by the _opts_ hash. _opts_ can have the following
588
- * keys:
589
- *
590
- * _opts_ can have the following keys:
591
- * * *max_nesting*: The maximum depth of nesting allowed in the parsed data
592
- * structures. Disable depth checking with :max_nesting => false|nil|0, it
593
- * defaults to 19.
594
- * * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
595
- * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
596
- * false.
597
- * * *symbolize_names*: If set to true, returns symbols for the names
598
- * (keys) in a JSON object. Otherwise strings are returned, which is also
599
- * the default.
600
- * * *create_additions*: If set to false, the Parser doesn't create
601
- * additions even if a matchin class and create_id was found. This option
602
- * defaults to true.
603
- * * *object_class*: Defaults to Hash
604
- * * *array_class*: Defaults to Array
605
- */
606
- static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
607
- {
608
- char *ptr;
609
- long len;
610
- VALUE source, opts;
611
- GET_PARSER;
612
- rb_scan_args(argc, argv, "11", &source, &opts);
613
- source = convert_encoding(StringValue(source));
614
- ptr = RSTRING_PTR(source);
615
- len = RSTRING_LEN(source);
616
- if (!NIL_P(opts)) {
617
- opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
618
- if (NIL_P(opts)) {
619
- rb_raise(rb_eArgError, "opts needs to be like a hash");
620
- } else {
621
- VALUE tmp = ID2SYM(i_max_nesting);
622
- if (option_given_p(opts, tmp)) {
623
- VALUE max_nesting = rb_hash_aref(opts, tmp);
624
- if (RTEST(max_nesting)) {
625
- Check_Type(max_nesting, T_FIXNUM);
626
- json->max_nesting = FIX2INT(max_nesting);
627
- } else {
628
- json->max_nesting = 0;
629
- }
630
- } else {
631
- json->max_nesting = 19;
632
- }
633
- tmp = ID2SYM(i_allow_nan);
634
- if (option_given_p(opts, tmp)) {
635
- VALUE allow_nan = rb_hash_aref(opts, tmp);
636
- json->allow_nan = RTEST(allow_nan) ? 1 : 0;
637
- } else {
638
- json->allow_nan = 0;
639
- }
640
- tmp = ID2SYM(i_symbolize_names);
641
- if (option_given_p(opts, tmp)) {
642
- VALUE symbolize_names = rb_hash_aref(opts, tmp);
643
- json->symbolize_names = RTEST(symbolize_names) ? 1 : 0;
644
- } else {
645
- json->symbolize_names = 0;
646
- }
647
- tmp = ID2SYM(i_create_additions);
648
- if (option_given_p(opts, tmp)) {
649
- VALUE create_additions = rb_hash_aref(opts, tmp);
650
- if (RTEST(create_additions)) {
651
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
652
- } else {
653
- json->create_id = Qnil;
654
- }
655
- } else {
656
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
657
- }
658
- tmp = ID2SYM(i_object_class);
659
- if (option_given_p(opts, tmp)) {
660
- json->object_class = rb_hash_aref(opts, tmp);
661
- } else {
662
- json->object_class = Qnil;
663
- }
664
- tmp = ID2SYM(i_array_class);
665
- if (option_given_p(opts, tmp)) {
666
- json->array_class = rb_hash_aref(opts, tmp);
667
- } else {
668
- json->array_class = Qnil;
669
- }
670
- }
671
- } else {
672
- json->max_nesting = 19;
673
- json->allow_nan = 0;
674
- json->create_id = rb_funcall(mJSON, i_create_id, 0);
675
- json->object_class = Qnil;
676
- json->array_class = Qnil;
677
- }
678
- json->current_nesting = 0;
679
- json->len = len;
680
- json->source = ptr;
681
- json->Vsource = source;
682
- return self;
683
- }
684
-
685
- /*
686
- * call-seq: parse()
687
- *
688
- * Parses the current JSON text _source_ and returns the complete data
689
- * structure as a result.
690
- */
691
- static VALUE cParser_parse(VALUE self)
692
- {
693
- char *p, *pe;
694
- int cs = EVIL;
695
- VALUE result = Qnil;
696
- GET_PARSER;
697
-
698
- %% write init;
699
- p = json->source;
700
- pe = p + json->len;
701
- %% write exec;
702
-
703
- if (cs >= JSON_first_final && p == pe) {
704
- return result;
705
- } else {
706
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
707
- return Qnil;
708
- }
709
- }
710
-
711
- static JSON_Parser *JSON_allocate()
712
- {
713
- JSON_Parser *json = ALLOC(JSON_Parser);
714
- MEMZERO(json, JSON_Parser, 1);
715
- return json;
716
- }
717
-
718
- static void JSON_mark(JSON_Parser *json)
719
- {
720
- rb_gc_mark_maybe(json->Vsource);
721
- rb_gc_mark_maybe(json->create_id);
722
- rb_gc_mark_maybe(json->object_class);
723
- rb_gc_mark_maybe(json->array_class);
724
- }
725
-
726
- static void JSON_free(JSON_Parser *json)
727
- {
728
- ruby_xfree(json);
729
- }
730
-
731
- static VALUE cJSON_parser_s_allocate(VALUE klass)
732
- {
733
- JSON_Parser *json = JSON_allocate();
734
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
735
- }
736
-
737
- /*
738
- * call-seq: source()
739
- *
740
- * Returns a copy of the current _source_ string, that was used to construct
741
- * this Parser.
742
- */
743
- static VALUE cParser_source(VALUE self)
744
- {
745
- GET_PARSER;
746
- return rb_str_dup(json->Vsource);
747
- }
748
-
749
- void Init_parser()
750
- {
751
- rb_require("json/common");
752
- mJSON = rb_define_module("JSON");
753
- mExt = rb_define_module_under(mJSON, "Ext");
754
- cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
755
- eParserError = rb_path2class("JSON::ParserError");
756
- eNestingError = rb_path2class("JSON::NestingError");
757
- rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
758
- rb_define_method(cParser, "initialize", cParser_initialize, -1);
759
- rb_define_method(cParser, "parse", cParser_parse, 0);
760
- rb_define_method(cParser, "source", cParser_source, 0);
761
-
762
- CNaN = rb_const_get(mJSON, rb_intern("NaN"));
763
- CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
764
- CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
765
-
766
- i_json_creatable_p = rb_intern("json_creatable?");
767
- i_json_create = rb_intern("json_create");
768
- i_create_id = rb_intern("create_id");
769
- i_create_additions = rb_intern("create_additions");
770
- i_chr = rb_intern("chr");
771
- i_max_nesting = rb_intern("max_nesting");
772
- i_allow_nan = rb_intern("allow_nan");
773
- i_symbolize_names = rb_intern("symbolize_names");
774
- i_object_class = rb_intern("object_class");
775
- i_array_class = rb_intern("array_class");
776
- i_key_p = rb_intern("key?");
777
- i_deep_const_get = rb_intern("deep_const_get");
778
- #ifdef HAVE_RUBY_ENCODING_H
779
- CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
780
- CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
781
- CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
782
- CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
783
- CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
784
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
785
- i_encoding = rb_intern("encoding");
786
- i_encode = rb_intern("encode");
787
- i_encode_bang = rb_intern("encode!");
788
- i_force_encoding = rb_intern("force_encoding");
789
- #else
790
- i_iconv = rb_intern("iconv");
791
- #endif
792
- }