mini-pro-gem 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/mini-pro-gem.gemspec +12 -0
  3. data/nokogiri-1.19.4/Gemfile +40 -0
  4. data/nokogiri-1.19.4/LICENSE-DEPENDENCIES.md +2411 -0
  5. data/nokogiri-1.19.4/LICENSE.md +9 -0
  6. data/nokogiri-1.19.4/README.md +308 -0
  7. data/nokogiri-1.19.4/bin/nokogiri +131 -0
  8. data/nokogiri-1.19.4/dependencies.yml +31 -0
  9. data/nokogiri-1.19.4/ext/nokogiri/depend +38 -0
  10. data/nokogiri-1.19.4/ext/nokogiri/extconf.rb +1165 -0
  11. data/nokogiri-1.19.4/ext/nokogiri/gumbo.c +610 -0
  12. data/nokogiri-1.19.4/ext/nokogiri/html4_document.c +171 -0
  13. data/nokogiri-1.19.4/ext/nokogiri/html4_element_description.c +299 -0
  14. data/nokogiri-1.19.4/ext/nokogiri/html4_entity_lookup.c +37 -0
  15. data/nokogiri-1.19.4/ext/nokogiri/html4_sax_parser.c +40 -0
  16. data/nokogiri-1.19.4/ext/nokogiri/html4_sax_parser_context.c +98 -0
  17. data/nokogiri-1.19.4/ext/nokogiri/html4_sax_push_parser.c +96 -0
  18. data/nokogiri-1.19.4/ext/nokogiri/libxml2_polyfill.c +114 -0
  19. data/nokogiri-1.19.4/ext/nokogiri/nokogiri.c +297 -0
  20. data/nokogiri-1.19.4/ext/nokogiri/nokogiri.h +247 -0
  21. data/nokogiri-1.19.4/ext/nokogiri/test_global_handlers.c +40 -0
  22. data/nokogiri-1.19.4/ext/nokogiri/xml_attr.c +108 -0
  23. data/nokogiri-1.19.4/ext/nokogiri/xml_attribute_decl.c +70 -0
  24. data/nokogiri-1.19.4/ext/nokogiri/xml_cdata.c +62 -0
  25. data/nokogiri-1.19.4/ext/nokogiri/xml_comment.c +57 -0
  26. data/nokogiri-1.19.4/ext/nokogiri/xml_document.c +796 -0
  27. data/nokogiri-1.19.4/ext/nokogiri/xml_document_fragment.c +29 -0
  28. data/nokogiri-1.19.4/ext/nokogiri/xml_dtd.c +208 -0
  29. data/nokogiri-1.19.4/ext/nokogiri/xml_element_content.c +131 -0
  30. data/nokogiri-1.19.4/ext/nokogiri/xml_element_decl.c +69 -0
  31. data/nokogiri-1.19.4/ext/nokogiri/xml_encoding_handler.c +112 -0
  32. data/nokogiri-1.19.4/ext/nokogiri/xml_entity_decl.c +112 -0
  33. data/nokogiri-1.19.4/ext/nokogiri/xml_entity_reference.c +50 -0
  34. data/nokogiri-1.19.4/ext/nokogiri/xml_namespace.c +181 -0
  35. data/nokogiri-1.19.4/ext/nokogiri/xml_node.c +2523 -0
  36. data/nokogiri-1.19.4/ext/nokogiri/xml_node_set.c +518 -0
  37. data/nokogiri-1.19.4/ext/nokogiri/xml_processing_instruction.c +54 -0
  38. data/nokogiri-1.19.4/ext/nokogiri/xml_reader.c +777 -0
  39. data/nokogiri-1.19.4/ext/nokogiri/xml_relax_ng.c +149 -0
  40. data/nokogiri-1.19.4/ext/nokogiri/xml_sax_parser.c +403 -0
  41. data/nokogiri-1.19.4/ext/nokogiri/xml_sax_parser_context.c +396 -0
  42. data/nokogiri-1.19.4/ext/nokogiri/xml_sax_push_parser.c +206 -0
  43. data/nokogiri-1.19.4/ext/nokogiri/xml_schema.c +226 -0
  44. data/nokogiri-1.19.4/ext/nokogiri/xml_syntax_error.c +93 -0
  45. data/nokogiri-1.19.4/ext/nokogiri/xml_text.c +59 -0
  46. data/nokogiri-1.19.4/ext/nokogiri/xml_xpath_context.c +496 -0
  47. data/nokogiri-1.19.4/ext/nokogiri/xslt_stylesheet.c +457 -0
  48. data/nokogiri-1.19.4/gumbo-parser/CHANGES.md +63 -0
  49. data/nokogiri-1.19.4/gumbo-parser/Makefile +129 -0
  50. data/nokogiri-1.19.4/gumbo-parser/THANKS +27 -0
  51. data/nokogiri-1.19.4/gumbo-parser/src/Makefile +34 -0
  52. data/nokogiri-1.19.4/gumbo-parser/src/README.md +41 -0
  53. data/nokogiri-1.19.4/gumbo-parser/src/ascii.c +75 -0
  54. data/nokogiri-1.19.4/gumbo-parser/src/ascii.h +115 -0
  55. data/nokogiri-1.19.4/gumbo-parser/src/attribute.c +42 -0
  56. data/nokogiri-1.19.4/gumbo-parser/src/attribute.h +17 -0
  57. data/nokogiri-1.19.4/gumbo-parser/src/char_ref.c +22225 -0
  58. data/nokogiri-1.19.4/gumbo-parser/src/char_ref.h +29 -0
  59. data/nokogiri-1.19.4/gumbo-parser/src/char_ref.rl +2154 -0
  60. data/nokogiri-1.19.4/gumbo-parser/src/error.c +658 -0
  61. data/nokogiri-1.19.4/gumbo-parser/src/error.h +152 -0
  62. data/nokogiri-1.19.4/gumbo-parser/src/foreign_attrs.c +103 -0
  63. data/nokogiri-1.19.4/gumbo-parser/src/foreign_attrs.gperf +27 -0
  64. data/nokogiri-1.19.4/gumbo-parser/src/insertion_mode.h +33 -0
  65. data/nokogiri-1.19.4/gumbo-parser/src/macros.h +91 -0
  66. data/nokogiri-1.19.4/gumbo-parser/src/nokogiri_gumbo.h +953 -0
  67. data/nokogiri-1.19.4/gumbo-parser/src/parser.c +4932 -0
  68. data/nokogiri-1.19.4/gumbo-parser/src/parser.h +41 -0
  69. data/nokogiri-1.19.4/gumbo-parser/src/replacement.h +33 -0
  70. data/nokogiri-1.19.4/gumbo-parser/src/string_buffer.c +103 -0
  71. data/nokogiri-1.19.4/gumbo-parser/src/string_buffer.h +68 -0
  72. data/nokogiri-1.19.4/gumbo-parser/src/string_piece.c +48 -0
  73. data/nokogiri-1.19.4/gumbo-parser/src/svg_attrs.c +174 -0
  74. data/nokogiri-1.19.4/gumbo-parser/src/svg_attrs.gperf +77 -0
  75. data/nokogiri-1.19.4/gumbo-parser/src/svg_tags.c +137 -0
  76. data/nokogiri-1.19.4/gumbo-parser/src/svg_tags.gperf +55 -0
  77. data/nokogiri-1.19.4/gumbo-parser/src/tag.c +223 -0
  78. data/nokogiri-1.19.4/gumbo-parser/src/tag_lookup.c +382 -0
  79. data/nokogiri-1.19.4/gumbo-parser/src/tag_lookup.gperf +170 -0
  80. data/nokogiri-1.19.4/gumbo-parser/src/tag_lookup.h +13 -0
  81. data/nokogiri-1.19.4/gumbo-parser/src/token_buffer.c +79 -0
  82. data/nokogiri-1.19.4/gumbo-parser/src/token_buffer.h +71 -0
  83. data/nokogiri-1.19.4/gumbo-parser/src/token_type.h +17 -0
  84. data/nokogiri-1.19.4/gumbo-parser/src/tokenizer.c +3464 -0
  85. data/nokogiri-1.19.4/gumbo-parser/src/tokenizer.h +112 -0
  86. data/nokogiri-1.19.4/gumbo-parser/src/tokenizer_states.h +339 -0
  87. data/nokogiri-1.19.4/gumbo-parser/src/utf8.c +245 -0
  88. data/nokogiri-1.19.4/gumbo-parser/src/utf8.h +164 -0
  89. data/nokogiri-1.19.4/gumbo-parser/src/util.c +66 -0
  90. data/nokogiri-1.19.4/gumbo-parser/src/util.h +34 -0
  91. data/nokogiri-1.19.4/gumbo-parser/src/vector.c +111 -0
  92. data/nokogiri-1.19.4/gumbo-parser/src/vector.h +45 -0
  93. data/nokogiri-1.19.4/lib/nokogiri/class_resolver.rb +65 -0
  94. data/nokogiri-1.19.4/lib/nokogiri/css/node.rb +58 -0
  95. data/nokogiri-1.19.4/lib/nokogiri/css/parser.rb +772 -0
  96. data/nokogiri-1.19.4/lib/nokogiri/css/parser.y +277 -0
  97. data/nokogiri-1.19.4/lib/nokogiri/css/parser_extras.rb +36 -0
  98. data/nokogiri-1.19.4/lib/nokogiri/css/selector_cache.rb +38 -0
  99. data/nokogiri-1.19.4/lib/nokogiri/css/syntax_error.rb +9 -0
  100. data/nokogiri-1.19.4/lib/nokogiri/css/tokenizer.rb +155 -0
  101. data/nokogiri-1.19.4/lib/nokogiri/css/tokenizer.rex +57 -0
  102. data/nokogiri-1.19.4/lib/nokogiri/css/xpath_visitor.rb +376 -0
  103. data/nokogiri-1.19.4/lib/nokogiri/css.rb +132 -0
  104. data/nokogiri-1.19.4/lib/nokogiri/decorators/slop.rb +42 -0
  105. data/nokogiri-1.19.4/lib/nokogiri/encoding_handler.rb +57 -0
  106. data/nokogiri-1.19.4/lib/nokogiri/extension.rb +32 -0
  107. data/nokogiri-1.19.4/lib/nokogiri/gumbo.rb +15 -0
  108. data/nokogiri-1.19.4/lib/nokogiri/html.rb +48 -0
  109. data/nokogiri-1.19.4/lib/nokogiri/html4/builder.rb +37 -0
  110. data/nokogiri-1.19.4/lib/nokogiri/html4/document.rb +235 -0
  111. data/nokogiri-1.19.4/lib/nokogiri/html4/document_fragment.rb +166 -0
  112. data/nokogiri-1.19.4/lib/nokogiri/html4/element_description.rb +25 -0
  113. data/nokogiri-1.19.4/lib/nokogiri/html4/element_description_defaults.rb +2040 -0
  114. data/nokogiri-1.19.4/lib/nokogiri/html4/encoding_reader.rb +121 -0
  115. data/nokogiri-1.19.4/lib/nokogiri/html4/entity_lookup.rb +15 -0
  116. data/nokogiri-1.19.4/lib/nokogiri/html4/sax/parser.rb +48 -0
  117. data/nokogiri-1.19.4/lib/nokogiri/html4/sax/parser_context.rb +15 -0
  118. data/nokogiri-1.19.4/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  119. data/nokogiri-1.19.4/lib/nokogiri/html4.rb +42 -0
  120. data/nokogiri-1.19.4/lib/nokogiri/html5/builder.rb +40 -0
  121. data/nokogiri-1.19.4/lib/nokogiri/html5/document.rb +199 -0
  122. data/nokogiri-1.19.4/lib/nokogiri/html5/document_fragment.rb +200 -0
  123. data/nokogiri-1.19.4/lib/nokogiri/html5/node.rb +103 -0
  124. data/nokogiri-1.19.4/lib/nokogiri/html5.rb +368 -0
  125. data/nokogiri-1.19.4/lib/nokogiri/jruby/dependencies.rb +3 -0
  126. data/nokogiri-1.19.4/lib/nokogiri/jruby/nokogiri_jars.rb +48 -0
  127. data/nokogiri-1.19.4/lib/nokogiri/syntax_error.rb +6 -0
  128. data/nokogiri-1.19.4/lib/nokogiri/version/constant.rb +6 -0
  129. data/nokogiri-1.19.4/lib/nokogiri/version/info.rb +234 -0
  130. data/nokogiri-1.19.4/lib/nokogiri/version.rb +4 -0
  131. data/nokogiri-1.19.4/lib/nokogiri/xml/attr.rb +66 -0
  132. data/nokogiri-1.19.4/lib/nokogiri/xml/attribute_decl.rb +22 -0
  133. data/nokogiri-1.19.4/lib/nokogiri/xml/builder.rb +494 -0
  134. data/nokogiri-1.19.4/lib/nokogiri/xml/cdata.rb +13 -0
  135. data/nokogiri-1.19.4/lib/nokogiri/xml/character_data.rb +9 -0
  136. data/nokogiri-1.19.4/lib/nokogiri/xml/document.rb +515 -0
  137. data/nokogiri-1.19.4/lib/nokogiri/xml/document_fragment.rb +276 -0
  138. data/nokogiri-1.19.4/lib/nokogiri/xml/dtd.rb +34 -0
  139. data/nokogiri-1.19.4/lib/nokogiri/xml/element_content.rb +46 -0
  140. data/nokogiri-1.19.4/lib/nokogiri/xml/element_decl.rb +17 -0
  141. data/nokogiri-1.19.4/lib/nokogiri/xml/entity_decl.rb +23 -0
  142. data/nokogiri-1.19.4/lib/nokogiri/xml/entity_reference.rb +20 -0
  143. data/nokogiri-1.19.4/lib/nokogiri/xml/namespace.rb +57 -0
  144. data/nokogiri-1.19.4/lib/nokogiri/xml/node/save_options.rb +76 -0
  145. data/nokogiri-1.19.4/lib/nokogiri/xml/node.rb +1701 -0
  146. data/nokogiri-1.19.4/lib/nokogiri/xml/node_set.rb +449 -0
  147. data/nokogiri-1.19.4/lib/nokogiri/xml/notation.rb +19 -0
  148. data/nokogiri-1.19.4/lib/nokogiri/xml/parse_options.rb +217 -0
  149. data/nokogiri-1.19.4/lib/nokogiri/xml/pp/character_data.rb +21 -0
  150. data/nokogiri-1.19.4/lib/nokogiri/xml/pp/node.rb +73 -0
  151. data/nokogiri-1.19.4/lib/nokogiri/xml/pp.rb +4 -0
  152. data/nokogiri-1.19.4/lib/nokogiri/xml/processing_instruction.rb +11 -0
  153. data/nokogiri-1.19.4/lib/nokogiri/xml/reader.rb +139 -0
  154. data/nokogiri-1.19.4/lib/nokogiri/xml/relax_ng.rb +75 -0
  155. data/nokogiri-1.19.4/lib/nokogiri/xml/sax/document.rb +258 -0
  156. data/nokogiri-1.19.4/lib/nokogiri/xml/sax/parser.rb +199 -0
  157. data/nokogiri-1.19.4/lib/nokogiri/xml/sax/parser_context.rb +129 -0
  158. data/nokogiri-1.19.4/lib/nokogiri/xml/sax/push_parser.rb +64 -0
  159. data/nokogiri-1.19.4/lib/nokogiri/xml/sax.rb +54 -0
  160. data/nokogiri-1.19.4/lib/nokogiri/xml/schema.rb +140 -0
  161. data/nokogiri-1.19.4/lib/nokogiri/xml/searchable.rb +274 -0
  162. data/nokogiri-1.19.4/lib/nokogiri/xml/syntax_error.rb +94 -0
  163. data/nokogiri-1.19.4/lib/nokogiri/xml/text.rb +11 -0
  164. data/nokogiri-1.19.4/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  165. data/nokogiri-1.19.4/lib/nokogiri/xml/xpath.rb +21 -0
  166. data/nokogiri-1.19.4/lib/nokogiri/xml/xpath_context.rb +27 -0
  167. data/nokogiri-1.19.4/lib/nokogiri/xml.rb +65 -0
  168. data/nokogiri-1.19.4/lib/nokogiri/xslt/stylesheet.rb +54 -0
  169. data/nokogiri-1.19.4/lib/nokogiri/xslt.rb +138 -0
  170. data/nokogiri-1.19.4/lib/nokogiri.rb +128 -0
  171. data/nokogiri-1.19.4/lib/xsd/xmlparser/nokogiri.rb +105 -0
  172. data/nokogiri-1.19.4/patches/libxml2/0001-Remove-script-macro-support.patch +40 -0
  173. data/nokogiri-1.19.4/patches/libxml2/0002-Update-entities-to-remove-handling-of-ssi.patch +44 -0
  174. data/nokogiri-1.19.4/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
  175. data/nokogiri-1.19.4/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
  176. data/nokogiri-1.19.4/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
  177. data/nokogiri-1.19.4/patches/libxml2/0019-xpath-Use-separate-static-hash-table-for-standard-fu.patch +244 -0
  178. data/nokogiri-1.19.4/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
  179. data/nokogiri-1.19.4/ports/archives/libxml2-2.13.9.tar.xz +0 -0
  180. data/nokogiri-1.19.4/ports/archives/libxslt-1.1.43.tar.xz +0 -0
  181. metadata +220 -0
@@ -0,0 +1,396 @@
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlSaxParserContext ;
4
+
5
+ static ID id_read;
6
+
7
+ static void
8
+ xml_sax_parser_context_type_free(void *data)
9
+ {
10
+ xmlParserCtxtPtr ctxt = data;
11
+ ctxt->sax = NULL;
12
+ if (ctxt->myDoc) {
13
+ xmlFreeDoc(ctxt->myDoc);
14
+ }
15
+ if (ctxt) {
16
+ xmlFreeParserCtxt(ctxt);
17
+ }
18
+ }
19
+
20
+ /*
21
+ * note that htmlParserCtxtPtr == xmlParserCtxtPtr and xmlFreeParserCtxt() == htmlFreeParserCtxt()
22
+ * so we use this type for both XML::SAX::ParserContext and HTML::SAX::ParserContext
23
+ */
24
+ static const rb_data_type_t xml_sax_parser_context_type = {
25
+ .wrap_struct_name = "xmlParserCtxt",
26
+ .function = {
27
+ .dfree = xml_sax_parser_context_type_free,
28
+ },
29
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
30
+ };
31
+
32
+ xmlParserCtxtPtr
33
+ noko_xml_sax_parser_context_unwrap(VALUE rb_context)
34
+ {
35
+ xmlParserCtxtPtr c_context;
36
+ TypedData_Get_Struct(rb_context, xmlParserCtxt, &xml_sax_parser_context_type, c_context);
37
+ return c_context;
38
+ }
39
+
40
+ VALUE
41
+ noko_xml_sax_parser_context_wrap(VALUE klass, xmlParserCtxtPtr c_context)
42
+ {
43
+ return TypedData_Wrap_Struct(klass, &xml_sax_parser_context_type, c_context);
44
+ }
45
+
46
+ void
47
+ noko_xml_sax_parser_context_set_encoding(xmlParserCtxtPtr c_context, VALUE rb_encoding)
48
+ {
49
+ if (!NIL_P(rb_encoding)) {
50
+ VALUE rb_encoding_name = rb_funcall(rb_encoding, rb_intern("name"), 0);
51
+
52
+ char *encoding_name = StringValueCStr(rb_encoding_name);
53
+ if (encoding_name) {
54
+ libxmlStructuredErrorHandlerState handler_state;
55
+ VALUE rb_errors = rb_ary_new();
56
+
57
+ noko__structured_error_func_save_and_set(&handler_state, (void *)rb_errors, noko__error_array_pusher);
58
+
59
+ int result = xmlSwitchEncodingName(c_context, encoding_name);
60
+
61
+ noko__structured_error_func_restore(&handler_state);
62
+
63
+ if (result != 0) {
64
+ xmlFreeParserCtxt(c_context);
65
+
66
+ VALUE exception = rb_funcall(cNokogiriXmlSyntaxError, rb_intern("aggregate"), 1, rb_errors);
67
+ if (!NIL_P(exception)) {
68
+ rb_exc_raise(exception);
69
+ } else {
70
+ rb_raise(rb_eRuntimeError, "could not set encoding");
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ /* :nodoc: */
78
+ static VALUE
79
+ noko_xml_sax_parser_context_s_native_io(VALUE rb_class, VALUE rb_io, VALUE rb_encoding)
80
+ {
81
+ if (!rb_respond_to(rb_io, id_read)) {
82
+ rb_raise(rb_eTypeError, "argument expected to respond to :read");
83
+ }
84
+
85
+ if (!NIL_P(rb_encoding) && !rb_obj_is_kind_of(rb_encoding, rb_cEncoding)) {
86
+ rb_raise(rb_eTypeError, "argument must be an Encoding object");
87
+ }
88
+
89
+ xmlParserCtxtPtr c_context =
90
+ xmlCreateIOParserCtxt(NULL, NULL,
91
+ (xmlInputReadCallback)noko_io_read,
92
+ (xmlInputCloseCallback)noko_io_close,
93
+ (void *)rb_io, XML_CHAR_ENCODING_NONE);
94
+ if (!c_context) {
95
+ rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
96
+ }
97
+
98
+ noko_xml_sax_parser_context_set_encoding(c_context, rb_encoding);
99
+
100
+ if (c_context->sax) {
101
+ xmlFree(c_context->sax);
102
+ c_context->sax = NULL;
103
+ }
104
+
105
+ VALUE rb_context = noko_xml_sax_parser_context_wrap(rb_class, c_context);
106
+ rb_iv_set(rb_context, "@input", rb_io);
107
+
108
+ return rb_context;
109
+ }
110
+
111
+ /* :nodoc: */
112
+ static VALUE
113
+ noko_xml_sax_parser_context_s_native_file(VALUE rb_class, VALUE rb_path, VALUE rb_encoding)
114
+ {
115
+ if (!NIL_P(rb_encoding) && !rb_obj_is_kind_of(rb_encoding, rb_cEncoding)) {
116
+ rb_raise(rb_eTypeError, "argument must be an Encoding object");
117
+ }
118
+
119
+ xmlParserCtxtPtr c_context = xmlCreateFileParserCtxt(StringValueCStr(rb_path));
120
+ if (!c_context) {
121
+ rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
122
+ }
123
+
124
+ noko_xml_sax_parser_context_set_encoding(c_context, rb_encoding);
125
+
126
+ if (c_context->sax) {
127
+ xmlFree(c_context->sax);
128
+ c_context->sax = NULL;
129
+ }
130
+
131
+ return noko_xml_sax_parser_context_wrap(rb_class, c_context);
132
+ }
133
+
134
+ /* :nodoc: */
135
+ static VALUE
136
+ noko_xml_sax_parser_context_s_native_memory(VALUE rb_class, VALUE rb_input, VALUE rb_encoding)
137
+ {
138
+ Check_Type(rb_input, T_STRING);
139
+ if (!(int)RSTRING_LEN(rb_input)) {
140
+ rb_raise(rb_eRuntimeError, "input string cannot be empty");
141
+ }
142
+
143
+ if (!NIL_P(rb_encoding) && !rb_obj_is_kind_of(rb_encoding, rb_cEncoding)) {
144
+ rb_raise(rb_eTypeError, "argument must be an Encoding object");
145
+ }
146
+
147
+ xmlParserCtxtPtr c_context =
148
+ xmlCreateMemoryParserCtxt(StringValuePtr(rb_input), (int)RSTRING_LEN(rb_input));
149
+ if (!c_context) {
150
+ rb_raise(rb_eRuntimeError, "failed to create xml sax parser context");
151
+ }
152
+
153
+ noko_xml_sax_parser_context_set_encoding(c_context, rb_encoding);
154
+
155
+ if (c_context->sax) {
156
+ xmlFree(c_context->sax);
157
+ c_context->sax = NULL;
158
+ }
159
+
160
+ VALUE rb_context = noko_xml_sax_parser_context_wrap(rb_class, c_context);
161
+ rb_iv_set(rb_context, "@input", rb_input);
162
+
163
+ return rb_context;
164
+ }
165
+
166
+ /*
167
+ * call-seq:
168
+ * parse_with(sax_handler)
169
+ *
170
+ * Use +sax_handler+ and parse the current document
171
+ *
172
+ * 💡 Calling this method directly is discouraged. Use Nokogiri::XML::SAX::Parser methods which are
173
+ * more convenient for most use cases.
174
+ */
175
+ static VALUE
176
+ noko_xml_sax_parser_context__parse_with(VALUE rb_context, VALUE rb_sax_parser)
177
+ {
178
+ xmlParserCtxtPtr c_context;
179
+ xmlSAXHandlerPtr sax;
180
+
181
+ if (!rb_obj_is_kind_of(rb_sax_parser, cNokogiriXmlSaxParser)) {
182
+ rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
183
+ }
184
+
185
+ c_context = noko_xml_sax_parser_context_unwrap(rb_context);
186
+ sax = noko_xml_sax_parser_unwrap(rb_sax_parser);
187
+
188
+ c_context->sax = sax;
189
+ c_context->userData = c_context; /* so we can use libxml2/SAX2.c handlers if we want to */
190
+ c_context->_private = (void *)rb_sax_parser;
191
+
192
+ xmlSetStructuredErrorFunc(NULL, NULL);
193
+
194
+ /* although we're calling back into Ruby here, we don't need to worry about exceptions, because we
195
+ * don't have any cleanup to do. The only memory we need to free is handled by
196
+ * xml_sax_parser_context_type_free */
197
+ xmlParseDocument(c_context);
198
+
199
+ return Qnil;
200
+ }
201
+
202
+ /*
203
+ * call-seq:
204
+ * replace_entities=(value)
205
+ *
206
+ * See Document@Entity+Handling for an explanation of the behavior controlled by this flag.
207
+ *
208
+ * [Parameters]
209
+ * - +value+ (Boolean) Whether external parsed entities will be resolved.
210
+ *
211
+ * ⚠ <b>It is UNSAFE to set this option to +true+</b> when parsing untrusted documents. The option
212
+ * defaults to +false+ for this reason.
213
+ *
214
+ * This option is perhaps misnamed by the libxml2 author, since it controls resolution and not
215
+ * replacement.
216
+ *
217
+ * [Example]
218
+ * Because this class is generally not instantiated directly, you would typically set this option
219
+ * via the block argument to Nokogiri::XML::SAX::Parser.parse et al:
220
+ *
221
+ * parser = Nokogiri::XML::SAX::Parser.new(document_handler)
222
+ * parser.parse(xml) do |ctx|
223
+ * ctx.replace_entities = true # this is UNSAFE for untrusted documents!
224
+ * end
225
+ */
226
+ static VALUE
227
+ noko_xml_sax_parser_context__replace_entities_set(VALUE rb_context, VALUE rb_value)
228
+ {
229
+ int error;
230
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
231
+
232
+ if (RB_TEST(rb_value)) {
233
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) | XML_PARSE_NOENT);
234
+ } else {
235
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) & ~XML_PARSE_NOENT);
236
+ }
237
+
238
+ if (error) {
239
+ rb_raise(rb_eRuntimeError, "failed to set parser context options (%x)", error);
240
+ }
241
+
242
+ return rb_value;
243
+ }
244
+
245
+ /*
246
+ * call-seq:
247
+ * replace_entities
248
+ *
249
+ * See Document@Entity+Handling for an explanation of the behavior controlled by this flag.
250
+ *
251
+ * [Returns] (Boolean) Value of the parse option. (Default +false+)
252
+ *
253
+ * This option is perhaps misnamed by the libxml2 author, since it controls resolution and not
254
+ * replacement.
255
+ */
256
+ static VALUE
257
+ noko_xml_sax_parser_context__replace_entities_get(VALUE rb_context)
258
+ {
259
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
260
+
261
+ if (xmlCtxtGetOptions(ctxt) & XML_PARSE_NOENT) {
262
+ return Qtrue;
263
+ } else {
264
+ return Qfalse;
265
+ }
266
+ }
267
+
268
+ /*
269
+ * call-seq: line
270
+ *
271
+ * [Returns] (Integer) the line number of the line being currently parsed.
272
+ */
273
+ static VALUE
274
+ noko_xml_sax_parser_context__line(VALUE rb_context)
275
+ {
276
+ xmlParserInputPtr io;
277
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
278
+
279
+ io = ctxt->input;
280
+ if (io) {
281
+ return INT2NUM(io->line);
282
+ }
283
+
284
+ return Qnil;
285
+ }
286
+
287
+ /*
288
+ * call-seq: column
289
+ *
290
+ * [Returns] (Integer) the column number of the column being currently parsed.
291
+ */
292
+ static VALUE
293
+ noko_xml_sax_parser_context__column(VALUE rb_context)
294
+ {
295
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
296
+ xmlParserInputPtr io;
297
+
298
+ io = ctxt->input;
299
+ if (io) {
300
+ return INT2NUM(io->col);
301
+ }
302
+
303
+ return Qnil;
304
+ }
305
+
306
+ /*
307
+ * call-seq:
308
+ * recovery=(value)
309
+ *
310
+ * Controls whether this parser will recover from parsing errors. If set to +true+, the parser will
311
+ * invoke the SAX::Document#error callback and continue processing the file. If set to +false+, the
312
+ * parser will stop processing the file on the first parsing error.
313
+ *
314
+ * [Parameters]
315
+ * - +value+ (Boolean) Recover from parsing errors. (Default is +false+ for XML and +true+ for HTML.)
316
+ *
317
+ * [Returns] (Boolean) The passed +value+.
318
+ *
319
+ * [Example]
320
+ * Because this class is generally not instantiated directly, you would typically set this option
321
+ * via the block argument to Nokogiri::XML::SAX::Parser.parse et al:
322
+ *
323
+ * parser = Nokogiri::XML::SAX::Parser.new(document_handler)
324
+ * parser.parse(xml) do |ctx|
325
+ * ctx.recovery = true
326
+ * end
327
+ */
328
+ static VALUE
329
+ noko_xml_sax_parser_context__recovery_set(VALUE rb_context, VALUE rb_value)
330
+ {
331
+ int error;
332
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
333
+
334
+ if (RB_TEST(rb_value)) {
335
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) | XML_PARSE_RECOVER);
336
+ } else {
337
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) & ~XML_PARSE_RECOVER);
338
+ }
339
+
340
+ if (error) {
341
+ rb_raise(rb_eRuntimeError, "failed to set parser context options (%x)", error);
342
+ }
343
+
344
+ return rb_value;
345
+ }
346
+
347
+ /*
348
+ * call-seq:
349
+ * recovery
350
+ *
351
+ * Inspect whether this parser will recover from parsing errors. If set to +true+, the parser will
352
+ * invoke the SAX::Document#error callback and continue processing the file. If set to +false+, the
353
+ * parser will stop processing the file on the first parsing error.
354
+ *
355
+ * [Returns] (Boolean) Whether this parser will recover from parsing errors.
356
+ *
357
+ * Default is +false+ for XML and +true+ for HTML.
358
+ */
359
+ static VALUE
360
+ noko_xml_sax_parser_context__recovery_get(VALUE rb_context)
361
+ {
362
+ xmlParserCtxtPtr ctxt = noko_xml_sax_parser_context_unwrap(rb_context);
363
+
364
+ if (xmlCtxtGetOptions(ctxt) & XML_PARSE_RECOVER) {
365
+ return Qtrue;
366
+ } else {
367
+ return Qfalse;
368
+ }
369
+ }
370
+
371
+ void
372
+ noko_init_xml_sax_parser_context(void)
373
+ {
374
+ cNokogiriXmlSaxParserContext = rb_define_class_under(mNokogiriXmlSax, "ParserContext", rb_cObject);
375
+
376
+ rb_undef_alloc_func(cNokogiriXmlSaxParserContext);
377
+
378
+ rb_define_singleton_method(cNokogiriXmlSaxParserContext, "native_io",
379
+ noko_xml_sax_parser_context_s_native_io, 2);
380
+ rb_define_singleton_method(cNokogiriXmlSaxParserContext, "native_memory",
381
+ noko_xml_sax_parser_context_s_native_memory, 2);
382
+ rb_define_singleton_method(cNokogiriXmlSaxParserContext, "native_file",
383
+ noko_xml_sax_parser_context_s_native_file, 2);
384
+
385
+ rb_define_method(cNokogiriXmlSaxParserContext, "parse_with", noko_xml_sax_parser_context__parse_with, 1);
386
+ rb_define_method(cNokogiriXmlSaxParserContext, "replace_entities=",
387
+ noko_xml_sax_parser_context__replace_entities_set, 1);
388
+ rb_define_method(cNokogiriXmlSaxParserContext, "replace_entities",
389
+ noko_xml_sax_parser_context__replace_entities_get, 0);
390
+ rb_define_method(cNokogiriXmlSaxParserContext, "recovery=", noko_xml_sax_parser_context__recovery_set, 1);
391
+ rb_define_method(cNokogiriXmlSaxParserContext, "recovery", noko_xml_sax_parser_context__recovery_get, 0);
392
+ rb_define_method(cNokogiriXmlSaxParserContext, "line", noko_xml_sax_parser_context__line, 0);
393
+ rb_define_method(cNokogiriXmlSaxParserContext, "column", noko_xml_sax_parser_context__column, 0);
394
+
395
+ id_read = rb_intern("read");
396
+ }
@@ -0,0 +1,206 @@
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlSaxPushParser ;
4
+
5
+ static void
6
+ xml_sax_push_parser_free(void *data)
7
+ {
8
+ xmlParserCtxtPtr ctx = data;
9
+ if (ctx->myDoc) {
10
+ xmlFreeDoc(ctx->myDoc);
11
+ }
12
+ if (ctx) {
13
+ xmlFreeParserCtxt(ctx);
14
+ }
15
+ }
16
+
17
+ static const rb_data_type_t xml_sax_push_parser_type = {
18
+ .wrap_struct_name = "xmlParserCtxt",
19
+ .function = {
20
+ .dfree = xml_sax_push_parser_free,
21
+ },
22
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
23
+ };
24
+
25
+ static VALUE
26
+ xml_sax_push_parser_allocate(VALUE klass)
27
+ {
28
+ return TypedData_Wrap_Struct(klass, &xml_sax_push_parser_type, NULL);
29
+ }
30
+
31
+ xmlParserCtxtPtr
32
+ noko_xml_sax_push_parser_unwrap(VALUE rb_parser)
33
+ {
34
+ xmlParserCtxtPtr c_parser;
35
+ TypedData_Get_Struct(rb_parser, xmlParserCtxt, &xml_sax_push_parser_type, c_parser);
36
+ return c_parser;
37
+ }
38
+
39
+ /*
40
+ * Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
41
+ */
42
+ static VALUE
43
+ noko_xml_sax_push_parser__native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
44
+ {
45
+ xmlParserCtxtPtr ctx;
46
+ const char *chunk = NULL;
47
+ int size = 0;
48
+
49
+ ctx = noko_xml_sax_push_parser_unwrap(self);
50
+
51
+ if (Qnil != _chunk) {
52
+ chunk = StringValuePtr(_chunk);
53
+ size = (int)RSTRING_LEN(_chunk);
54
+ }
55
+
56
+ xmlSetStructuredErrorFunc(NULL, NULL);
57
+
58
+ if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
59
+ if (!(xmlCtxtGetOptions(ctx) & XML_PARSE_RECOVER)) {
60
+ xmlErrorConstPtr e = xmlCtxtGetLastError(ctx);
61
+ noko__error_raise(NULL, e);
62
+ }
63
+ }
64
+
65
+ return self;
66
+ }
67
+
68
+ /*
69
+ * call-seq:
70
+ * initialize_native(xml_sax, filename)
71
+ *
72
+ * Initialize the push parser with +xml_sax+ using +filename+
73
+ */
74
+ static VALUE
75
+ noko_xml_sax_push_parser__initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
76
+ {
77
+ xmlSAXHandlerPtr sax;
78
+ const char *filename = NULL;
79
+ xmlParserCtxtPtr ctx;
80
+
81
+ sax = noko_xml_sax_parser_unwrap(_xml_sax);
82
+
83
+ if (_filename != Qnil) { filename = StringValueCStr(_filename); }
84
+
85
+ ctx = xmlCreatePushParserCtxt(
86
+ sax,
87
+ NULL,
88
+ NULL,
89
+ 0,
90
+ filename
91
+ );
92
+ if (ctx == NULL) {
93
+ rb_raise(rb_eRuntimeError, "Could not create a parser context");
94
+ }
95
+
96
+ ctx->userData = ctx;
97
+ ctx->_private = (void *)_xml_sax;
98
+
99
+ DATA_PTR(self) = ctx;
100
+ return self;
101
+ }
102
+
103
+ static VALUE
104
+ noko_xml_sax_push_parser__options_get(VALUE self)
105
+ {
106
+ xmlParserCtxtPtr ctx;
107
+
108
+ ctx = noko_xml_sax_push_parser_unwrap(self);
109
+
110
+ return INT2NUM(xmlCtxtGetOptions(ctx));
111
+ }
112
+
113
+ static VALUE
114
+ noko_xml_sax_push_parser__options_set(VALUE self, VALUE options)
115
+ {
116
+ int error;
117
+ xmlParserCtxtPtr ctx;
118
+
119
+ ctx = noko_xml_sax_push_parser_unwrap(self);
120
+
121
+ error = xmlCtxtSetOptions(ctx, (int)NUM2INT(options));
122
+ if (error) {
123
+ rb_raise(rb_eRuntimeError, "Cannot set XML parser context options (%x)", error);
124
+ }
125
+
126
+ return Qnil;
127
+ }
128
+
129
+ /*
130
+ * call-seq:
131
+ * replace_entities
132
+ *
133
+ * See Document@Entity+Handling for an explanation of the behavior controlled by this flag.
134
+ *
135
+ * [Returns] (Boolean) Value of the parse option. (Default +false+)
136
+ *
137
+ * This option is perhaps misnamed by the libxml2 author, since it controls resolution and not
138
+ * replacement.
139
+ */
140
+ static VALUE
141
+ noko_xml_sax_push_parser__replace_entities_get(VALUE self)
142
+ {
143
+ xmlParserCtxtPtr ctxt = noko_xml_sax_push_parser_unwrap(self);
144
+
145
+ if (xmlCtxtGetOptions(ctxt) & XML_PARSE_NOENT) {
146
+ return Qtrue;
147
+ } else {
148
+ return Qfalse;
149
+ }
150
+ }
151
+
152
+ /*
153
+ * call-seq:
154
+ * replace_entities=(value)
155
+ *
156
+ * See Document@Entity+Handling for an explanation of the behavior controlled by this flag.
157
+ *
158
+ * [Parameters]
159
+ * - +value+ (Boolean) Whether external parsed entities will be resolved.
160
+ *
161
+ * ⚠ <b>It is UNSAFE to set this option to +true+</b> when parsing untrusted documents. The option
162
+ * defaults to +false+ for this reason.
163
+ *
164
+ * This option is perhaps misnamed by the libxml2 author, since it controls resolution and not
165
+ * replacement.
166
+ */
167
+ static VALUE
168
+ noko_xml_sax_push_parser__replace_entities_set(VALUE self, VALUE value)
169
+ {
170
+ int error;
171
+ xmlParserCtxtPtr ctxt = noko_xml_sax_push_parser_unwrap(self);
172
+
173
+ if (RB_TEST(value)) {
174
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) | XML_PARSE_NOENT);
175
+ } else {
176
+ error = xmlCtxtSetOptions(ctxt, xmlCtxtGetOptions(ctxt) & ~XML_PARSE_NOENT);
177
+ }
178
+
179
+ if (error) {
180
+ rb_raise(rb_eRuntimeError, "failed to set parser context options (%x)", error);
181
+ }
182
+
183
+ return value;
184
+ }
185
+
186
+ void
187
+ noko_init_xml_sax_push_parser(void)
188
+ {
189
+ cNokogiriXmlSaxPushParser = rb_define_class_under(mNokogiriXmlSax, "PushParser", rb_cObject);
190
+
191
+ rb_define_alloc_func(cNokogiriXmlSaxPushParser, xml_sax_push_parser_allocate);
192
+
193
+ rb_define_method(cNokogiriXmlSaxPushParser, "options",
194
+ noko_xml_sax_push_parser__options_get, 0);
195
+ rb_define_method(cNokogiriXmlSaxPushParser, "options=",
196
+ noko_xml_sax_push_parser__options_set, 1);
197
+ rb_define_method(cNokogiriXmlSaxPushParser, "replace_entities",
198
+ noko_xml_sax_push_parser__replace_entities_get, 0);
199
+ rb_define_method(cNokogiriXmlSaxPushParser, "replace_entities=",
200
+ noko_xml_sax_push_parser__replace_entities_set, 1);
201
+
202
+ rb_define_private_method(cNokogiriXmlSaxPushParser, "initialize_native",
203
+ noko_xml_sax_push_parser__initialize_native, 2);
204
+ rb_define_private_method(cNokogiriXmlSaxPushParser, "native_write",
205
+ noko_xml_sax_push_parser__native_write, 2);
206
+ }