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,96 @@
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriHtml4SaxPushParser;
4
+
5
+ /*
6
+ * Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
7
+ */
8
+ static VALUE
9
+ noko_html4_sax_push_parser__native_write(VALUE self, VALUE rb_chunk, VALUE rb_last_chunk)
10
+ {
11
+ xmlParserCtxtPtr ctx;
12
+ const char *chunk = NULL;
13
+ int size = 0;
14
+ int status = 0;
15
+ libxmlStructuredErrorHandlerState handler_state;
16
+
17
+ ctx = noko_xml_sax_push_parser_unwrap(self);
18
+
19
+ if (Qnil != rb_chunk) {
20
+ chunk = StringValuePtr(rb_chunk);
21
+ size = (int)RSTRING_LEN(rb_chunk);
22
+ }
23
+
24
+ noko__structured_error_func_save_and_set(&handler_state, NULL, NULL);
25
+
26
+ status = htmlParseChunk(ctx, chunk, size, Qtrue == rb_last_chunk ? 1 : 0);
27
+
28
+ noko__structured_error_func_restore(&handler_state);
29
+
30
+ if ((status != 0) && !(xmlCtxtGetOptions(ctx) & XML_PARSE_RECOVER)) {
31
+ // TODO: there appear to be no tests for this block
32
+ xmlErrorConstPtr e = xmlCtxtGetLastError(ctx);
33
+ noko__error_raise(NULL, e);
34
+ }
35
+
36
+ return self;
37
+ }
38
+
39
+ /*
40
+ * Initialize the push parser with +xml_sax+ using +filename+
41
+ */
42
+ static VALUE
43
+ noko_html4_sax_push_parser__initialize_native(
44
+ VALUE self,
45
+ VALUE rb_xml_sax,
46
+ VALUE rb_filename,
47
+ VALUE encoding
48
+ )
49
+ {
50
+ htmlSAXHandlerPtr sax;
51
+ const char *filename = NULL;
52
+ htmlParserCtxtPtr ctx;
53
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
54
+
55
+ sax = noko_xml_sax_parser_unwrap(rb_xml_sax);
56
+
57
+ if (rb_filename != Qnil) { filename = StringValueCStr(rb_filename); }
58
+
59
+ if (!NIL_P(encoding)) {
60
+ enc = xmlParseCharEncoding(StringValueCStr(encoding));
61
+ if (enc == XML_CHAR_ENCODING_ERROR) {
62
+ rb_raise(rb_eArgError, "Unsupported Encoding");
63
+ }
64
+ }
65
+
66
+ ctx = htmlCreatePushParserCtxt(
67
+ sax,
68
+ NULL,
69
+ NULL,
70
+ 0,
71
+ filename,
72
+ enc
73
+ );
74
+ if (ctx == NULL) {
75
+ rb_raise(rb_eRuntimeError, "Could not create a parser context");
76
+ }
77
+
78
+ ctx->userData = ctx;
79
+ ctx->_private = (void *)rb_xml_sax;
80
+
81
+ DATA_PTR(self) = ctx;
82
+ return self;
83
+ }
84
+
85
+ void
86
+ noko_init_html_sax_push_parser(void)
87
+ {
88
+ assert(cNokogiriXmlSaxPushParser);
89
+ cNokogiriHtml4SaxPushParser =
90
+ rb_define_class_under(mNokogiriHtml4Sax, "PushParser", cNokogiriXmlSaxPushParser);
91
+
92
+ rb_define_private_method(cNokogiriHtml4SaxPushParser, "initialize_native",
93
+ noko_html4_sax_push_parser__initialize_native, 3);
94
+ rb_define_private_method(cNokogiriHtml4SaxPushParser, "native_write",
95
+ noko_html4_sax_push_parser__native_write, 2);
96
+ }
@@ -0,0 +1,114 @@
1
+ #include <nokogiri.h>
2
+
3
+ #ifndef HAVE_XMLCTXTSETOPTIONS
4
+ /* based on libxml2-2.14.0-dev (1d8bd126) parser.c xmlCtxtSetInternalOptions */
5
+ int
6
+ xmlCtxtSetOptions(xmlParserCtxtPtr ctxt, int options)
7
+ {
8
+ int keepMask = 0;
9
+ int allMask;
10
+
11
+ if (ctxt == NULL) {
12
+ return (-1);
13
+ }
14
+
15
+ /*
16
+ * XInclude options aren't handled by the parser.
17
+ *
18
+ * XML_PARSE_XINCLUDE
19
+ * XML_PARSE_NOXINCNODE
20
+ * XML_PARSE_NOBASEFIX
21
+ */
22
+ allMask = XML_PARSE_RECOVER |
23
+ XML_PARSE_NOENT |
24
+ XML_PARSE_DTDLOAD |
25
+ XML_PARSE_DTDATTR |
26
+ XML_PARSE_DTDVALID |
27
+ XML_PARSE_NOERROR |
28
+ XML_PARSE_NOWARNING |
29
+ XML_PARSE_PEDANTIC |
30
+ XML_PARSE_NOBLANKS |
31
+ #ifdef LIBXML_SAX1_ENABLED
32
+ XML_PARSE_SAX1 |
33
+ #endif
34
+ XML_PARSE_NONET |
35
+ XML_PARSE_NODICT |
36
+ XML_PARSE_NSCLEAN |
37
+ XML_PARSE_NOCDATA |
38
+ XML_PARSE_COMPACT |
39
+ XML_PARSE_OLD10 |
40
+ XML_PARSE_HUGE |
41
+ XML_PARSE_OLDSAX |
42
+ XML_PARSE_IGNORE_ENC |
43
+ XML_PARSE_BIG_LINES;
44
+
45
+ ctxt->options = (ctxt->options & keepMask) | (options & allMask);
46
+
47
+ /*
48
+ * For some options, struct members are historically the source
49
+ * of truth. The values are initalized from global variables and
50
+ * old code could also modify them directly. Several older API
51
+ * functions that don't take an options argument rely on these
52
+ * deprecated mechanisms.
53
+ *
54
+ * Once public access to struct members and the globals are
55
+ * disabled, we can use the options bitmask as source of
56
+ * truth, making all these struct members obsolete.
57
+ *
58
+ * The XML_DETECT_IDS flags is misnamed. It simply enables
59
+ * loading of the external subset.
60
+ */
61
+ ctxt->recovery = (options & XML_PARSE_RECOVER) ? 1 : 0;
62
+ ctxt->replaceEntities = (options & XML_PARSE_NOENT) ? 1 : 0;
63
+ ctxt->loadsubset = (options & XML_PARSE_DTDLOAD) ? XML_DETECT_IDS : 0;
64
+ ctxt->loadsubset |= (options & XML_PARSE_DTDATTR) ? XML_COMPLETE_ATTRS : 0;
65
+ ctxt->validate = (options & XML_PARSE_DTDVALID) ? 1 : 0;
66
+ ctxt->pedantic = (options & XML_PARSE_PEDANTIC) ? 1 : 0;
67
+ ctxt->keepBlanks = (options & XML_PARSE_NOBLANKS) ? 0 : 1;
68
+ ctxt->dictNames = (options & XML_PARSE_NODICT) ? 0 : 1;
69
+
70
+ /*
71
+ * Changing SAX callbacks is a bad idea. This should be fixed.
72
+ */
73
+ if (options & XML_PARSE_NOBLANKS) {
74
+ ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
75
+ }
76
+ if (options & XML_PARSE_NOCDATA) {
77
+ ctxt->sax->cdataBlock = NULL;
78
+ }
79
+ if (options & XML_PARSE_HUGE) {
80
+ if (ctxt->dict != NULL) {
81
+ xmlDictSetLimit(ctxt->dict, 0);
82
+ }
83
+ }
84
+
85
+ ctxt->linenumbers = 1;
86
+
87
+ return (options & ~allMask);
88
+ }
89
+ #endif
90
+
91
+ #ifndef HAVE_XMLCTXTGETOPTIONS
92
+ int
93
+ xmlCtxtGetOptions(xmlParserCtxtPtr ctxt)
94
+ {
95
+ return (ctxt->options);
96
+ }
97
+ #endif
98
+
99
+ #ifndef HAVE_XMLSWITCHENCODINGNAME
100
+ int
101
+ xmlSwitchEncodingName(xmlParserCtxtPtr ctxt, const char *encoding)
102
+ {
103
+ if (ctxt == NULL) {
104
+ return (-1);
105
+ }
106
+
107
+ xmlCharEncodingHandlerPtr handler = xmlFindCharEncodingHandler(encoding);
108
+ if (handler == NULL) {
109
+ return (-1);
110
+ }
111
+
112
+ return (xmlSwitchToEncoding(ctxt, handler));
113
+ }
114
+ #endif
@@ -0,0 +1,297 @@
1
+ #include <nokogiri.h>
2
+
3
+ VALUE mNokogiri ;
4
+ VALUE mNokogiriGumbo ;
5
+ VALUE mNokogiriHtml4 ;
6
+ VALUE mNokogiriHtml4Sax ;
7
+ VALUE mNokogiriHtml5 ;
8
+ VALUE mNokogiriXml ;
9
+ VALUE mNokogiriXmlSax ;
10
+ VALUE mNokogiriXmlXpath ;
11
+ VALUE mNokogiriXslt ;
12
+
13
+ VALUE cNokogiriSyntaxError;
14
+ VALUE cNokogiriXmlCharacterData;
15
+ VALUE cNokogiriXmlElement;
16
+ VALUE cNokogiriXmlXpathSyntaxError;
17
+
18
+ void noko_init_xml_attr(void);
19
+ void noko_init_xml_attribute_decl(void);
20
+ void noko_init_xml_cdata(void);
21
+ void noko_init_xml_comment(void);
22
+ void noko_init_xml_document(void);
23
+ void noko_init_xml_document_fragment(void);
24
+ void noko_init_xml_dtd(void);
25
+ void noko_init_xml_element_content(void);
26
+ void noko_init_xml_element_decl(void);
27
+ void noko_init_xml_encoding_handler(void);
28
+ void noko_init_xml_entity_decl(void);
29
+ void noko_init_xml_entity_reference(void);
30
+ void noko_init_xml_namespace(void);
31
+ void noko_init_xml_node(void);
32
+ void noko_init_xml_node_set(void);
33
+ void noko_init_xml_processing_instruction(void);
34
+ void noko_init_xml_reader(void);
35
+ void noko_init_xml_relax_ng(void);
36
+ void noko_init_xml_sax_parser(void);
37
+ void noko_init_xml_sax_parser_context(void);
38
+ void noko_init_xml_sax_push_parser(void);
39
+ void noko_init_xml_schema(void);
40
+ void noko_init_xml_syntax_error(void);
41
+ void noko_init_xml_text(void);
42
+ void noko_init_xml_xpath_context(void);
43
+ void noko_init_xslt_stylesheet(void);
44
+ void noko_init_html_document(void);
45
+ void noko_init_html_element_description(void);
46
+ void noko_init_html_entity_lookup(void);
47
+ void noko_init_html_sax_parser_context(void);
48
+ void noko_init_html_sax_push_parser(void);
49
+ void noko_init_html4_sax_parser(void);
50
+ void noko_init_gumbo(void);
51
+ void noko_init_test_global_handlers(void);
52
+
53
+ static ID id_read, id_write, id_external_encoding;
54
+
55
+
56
+ static VALUE
57
+ noko_io_read_check(VALUE val)
58
+ {
59
+ VALUE *args = (VALUE *)val;
60
+ return rb_funcall(args[0], id_read, 1, args[1]);
61
+ }
62
+
63
+
64
+ static VALUE
65
+ noko_io_read_failed(VALUE arg, VALUE exc)
66
+ {
67
+ return Qundef;
68
+ }
69
+
70
+
71
+ int
72
+ noko_io_read(void *io, char *c_buffer, int c_buffer_len)
73
+ {
74
+ VALUE rb_io = (VALUE)io;
75
+ VALUE rb_read_string, rb_args[2];
76
+ size_t n_bytes_read, safe_len;
77
+
78
+ rb_args[0] = rb_io;
79
+ rb_args[1] = INT2NUM(c_buffer_len);
80
+
81
+ rb_read_string = rb_rescue(noko_io_read_check, (VALUE)rb_args, noko_io_read_failed, 0);
82
+
83
+ if (NIL_P(rb_read_string)) { return 0; }
84
+ if (rb_read_string == Qundef) { return -1; }
85
+ if (TYPE(rb_read_string) != T_STRING) { return -1; }
86
+
87
+ n_bytes_read = (size_t)RSTRING_LEN(rb_read_string);
88
+ safe_len = (n_bytes_read > (size_t)c_buffer_len) ? (size_t)c_buffer_len : n_bytes_read;
89
+ memcpy(c_buffer, StringValuePtr(rb_read_string), safe_len);
90
+
91
+ return (int)safe_len;
92
+ }
93
+
94
+
95
+ static VALUE
96
+ noko_io_write_check(VALUE rb_args)
97
+ {
98
+ VALUE rb_io = ((VALUE *)rb_args)[0];
99
+ VALUE rb_output = ((VALUE *)rb_args)[1];
100
+ return rb_funcall(rb_io, id_write, 1, rb_output);
101
+ }
102
+
103
+
104
+ static VALUE
105
+ noko_io_write_failed(VALUE arg, VALUE exc)
106
+ {
107
+ return Qundef;
108
+ }
109
+
110
+
111
+ int
112
+ noko_io_write(void *io, char *c_buffer, int c_buffer_len)
113
+ {
114
+ VALUE rb_args[2], rb_n_bytes_written;
115
+ VALUE rb_io = (VALUE)io;
116
+ VALUE rb_enc = Qnil;
117
+ rb_encoding *io_encoding;
118
+
119
+ if (rb_respond_to(rb_io, id_external_encoding)) {
120
+ rb_enc = rb_funcall(rb_io, id_external_encoding, 0);
121
+ }
122
+ io_encoding = RB_NIL_P(rb_enc) ? rb_ascii8bit_encoding() : rb_to_encoding(rb_enc);
123
+
124
+ rb_args[0] = rb_io;
125
+ rb_args[1] = rb_enc_str_new(c_buffer, (long)c_buffer_len, io_encoding);
126
+
127
+ rb_n_bytes_written = rb_rescue(noko_io_write_check, (VALUE)rb_args, noko_io_write_failed, 0);
128
+ if (rb_n_bytes_written == Qundef) { return -1; }
129
+
130
+ return NUM2INT(rb_n_bytes_written);
131
+ }
132
+
133
+
134
+ int
135
+ noko_io_close(void *io)
136
+ {
137
+ return 0;
138
+ }
139
+
140
+
141
+ #if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
142
+ # define NOKOGIRI_WINDOWS_DLLS 1
143
+ #else
144
+ # define NOKOGIRI_WINDOWS_DLLS 0
145
+ #endif
146
+
147
+ //
148
+ // | dlls || true | false |
149
+ // | nlmm || | |
150
+ // |-----------++---------+---------|
151
+ // | NULL || default | ruby |
152
+ // | "random" || default | ruby |
153
+ // | "ruby" || ruby | ruby |
154
+ // | "default" || default | default |
155
+ //
156
+ // We choose *not* to use Ruby's memory management functions with windows DLLs because of this
157
+ // issue: https://github.com/sparklemotion/nokogiri/issues/2241
158
+ //
159
+ static void
160
+ set_libxml_memory_management(void)
161
+ {
162
+ const char *nlmm = getenv("NOKOGIRI_LIBXML_MEMORY_MANAGEMENT");
163
+ if (nlmm) {
164
+ if (strcmp(nlmm, "default") == 0) {
165
+ goto libxml_uses_default_memory_management;
166
+ } else if (strcmp(nlmm, "ruby") == 0) {
167
+ goto libxml_uses_ruby_memory_management;
168
+ }
169
+ }
170
+ if (NOKOGIRI_WINDOWS_DLLS) {
171
+ libxml_uses_default_memory_management:
172
+ rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
173
+ return;
174
+ } else {
175
+ libxml_uses_ruby_memory_management:
176
+ rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
177
+ xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
178
+ return;
179
+ }
180
+ }
181
+
182
+
183
+ void
184
+ Init_nokogiri(void)
185
+ {
186
+ mNokogiri = rb_define_module("Nokogiri");
187
+ mNokogiriGumbo = rb_define_module_under(mNokogiri, "Gumbo");
188
+ mNokogiriHtml4 = rb_define_module_under(mNokogiri, "HTML4");
189
+ mNokogiriHtml4Sax = rb_define_module_under(mNokogiriHtml4, "SAX");
190
+ mNokogiriHtml5 = rb_define_module_under(mNokogiri, "HTML5");
191
+ mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
192
+ mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
193
+ mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
194
+ mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
195
+
196
+ set_libxml_memory_management(); /* must be before any function calls that might invoke xmlInitParser() */
197
+ xmlInitParser();
198
+ exsltRegisterAll();
199
+
200
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
201
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
202
+
203
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
204
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
205
+
206
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
207
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
208
+ # ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
209
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
210
+ # else
211
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
212
+ # endif
213
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
214
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
215
+ #else
216
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
217
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
218
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
219
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
220
+ #endif
221
+
222
+ #ifdef LIBXML_ICONV_ENABLED
223
+ rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qtrue);
224
+ #else
225
+ rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
226
+ #endif
227
+
228
+ rb_const_set(mNokogiri, rb_intern("LIBXML_ZLIB_ENABLED"),
229
+ xmlHasFeature(XML_WITH_ZLIB) == 1 ? Qtrue : Qfalse);
230
+
231
+ rb_const_set(mNokogiri, rb_intern("LIBXML_HTTP_ENABLED"),
232
+ xmlHasFeature(XML_WITH_HTTP) == 1 ? Qtrue : Qfalse);
233
+
234
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
235
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
236
+ #endif
237
+
238
+ if (xsltExtModuleFunctionLookup((const xmlChar *)"date-time", EXSLT_DATE_NAMESPACE)) {
239
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue);
240
+ } else {
241
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qfalse);
242
+ }
243
+
244
+ cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
245
+ noko_init_xml_syntax_error();
246
+ assert(cNokogiriXmlSyntaxError);
247
+ cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
248
+
249
+ noko_init_xml_element_content();
250
+ noko_init_xml_encoding_handler();
251
+ noko_init_xml_namespace();
252
+ noko_init_xml_node_set();
253
+ noko_init_xml_reader();
254
+
255
+ noko_init_xml_sax_parser();
256
+ noko_init_html4_sax_parser();
257
+
258
+ noko_init_xml_xpath_context();
259
+ noko_init_xslt_stylesheet();
260
+ noko_init_html_element_description();
261
+ noko_init_html_entity_lookup();
262
+
263
+ noko_init_xml_schema();
264
+ noko_init_xml_relax_ng();
265
+
266
+ noko_init_xml_sax_parser_context();
267
+ noko_init_html_sax_parser_context();
268
+
269
+ noko_init_xml_sax_push_parser();
270
+ noko_init_html_sax_push_parser();
271
+
272
+ noko_init_xml_node();
273
+ noko_init_xml_attr();
274
+ noko_init_xml_attribute_decl();
275
+ noko_init_xml_dtd();
276
+ noko_init_xml_element_decl();
277
+ noko_init_xml_entity_decl();
278
+ noko_init_xml_entity_reference();
279
+ noko_init_xml_processing_instruction();
280
+ assert(cNokogiriXmlNode);
281
+ cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
282
+ cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
283
+ noko_init_xml_comment();
284
+ noko_init_xml_text();
285
+ noko_init_xml_cdata();
286
+
287
+ noko_init_xml_document_fragment();
288
+ noko_init_xml_document();
289
+ noko_init_html_document();
290
+ noko_init_gumbo();
291
+
292
+ noko_init_test_global_handlers();
293
+
294
+ id_read = rb_intern("read");
295
+ id_write = rb_intern("write");
296
+ id_external_encoding = rb_intern("external_encoding");
297
+ }