nokogiri 1.11.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1682 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +272 -0
  6. data/bin/nokogiri +118 -0
  7. data/dependencies.yml +74 -0
  8. data/ext/nokogiri/depend +477 -0
  9. data/ext/nokogiri/extconf.rb +836 -0
  10. data/ext/nokogiri/html_document.c +171 -0
  11. data/ext/nokogiri/html_document.h +10 -0
  12. data/ext/nokogiri/html_element_description.c +279 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.c +32 -0
  15. data/ext/nokogiri/html_entity_lookup.h +8 -0
  16. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  17. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  18. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  19. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  20. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  21. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  22. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  23. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  24. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  25. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  26. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  27. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  28. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  29. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  30. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  31. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  32. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  33. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  34. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  35. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  36. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  37. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  38. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  39. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  40. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  41. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  42. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  43. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  44. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  45. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  46. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  47. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  48. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  49. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  66. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  67. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  68. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  69. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  70. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  71. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  72. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  73. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  74. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  75. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  76. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  77. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  78. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  79. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  80. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  81. data/ext/nokogiri/include/libxslt/security.h +104 -0
  82. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  83. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  84. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  85. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  86. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  87. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  88. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  89. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  90. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  91. data/ext/nokogiri/nokogiri.c +135 -0
  92. data/ext/nokogiri/nokogiri.h +130 -0
  93. data/ext/nokogiri/xml_attr.c +103 -0
  94. data/ext/nokogiri/xml_attr.h +9 -0
  95. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  96. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  97. data/ext/nokogiri/xml_cdata.c +62 -0
  98. data/ext/nokogiri/xml_cdata.h +9 -0
  99. data/ext/nokogiri/xml_comment.c +69 -0
  100. data/ext/nokogiri/xml_comment.h +9 -0
  101. data/ext/nokogiri/xml_document.c +622 -0
  102. data/ext/nokogiri/xml_document.h +23 -0
  103. data/ext/nokogiri/xml_document_fragment.c +48 -0
  104. data/ext/nokogiri/xml_document_fragment.h +10 -0
  105. data/ext/nokogiri/xml_dtd.c +202 -0
  106. data/ext/nokogiri/xml_dtd.h +10 -0
  107. data/ext/nokogiri/xml_element_content.c +123 -0
  108. data/ext/nokogiri/xml_element_content.h +10 -0
  109. data/ext/nokogiri/xml_element_decl.c +69 -0
  110. data/ext/nokogiri/xml_element_decl.h +9 -0
  111. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  112. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  113. data/ext/nokogiri/xml_entity_decl.c +110 -0
  114. data/ext/nokogiri/xml_entity_decl.h +10 -0
  115. data/ext/nokogiri/xml_entity_reference.c +52 -0
  116. data/ext/nokogiri/xml_entity_reference.h +9 -0
  117. data/ext/nokogiri/xml_io.c +63 -0
  118. data/ext/nokogiri/xml_io.h +11 -0
  119. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  120. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  121. data/ext/nokogiri/xml_namespace.c +111 -0
  122. data/ext/nokogiri/xml_namespace.h +14 -0
  123. data/ext/nokogiri/xml_node.c +1773 -0
  124. data/ext/nokogiri/xml_node.h +13 -0
  125. data/ext/nokogiri/xml_node_set.c +486 -0
  126. data/ext/nokogiri/xml_node_set.h +12 -0
  127. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  128. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  129. data/ext/nokogiri/xml_reader.c +657 -0
  130. data/ext/nokogiri/xml_reader.h +10 -0
  131. data/ext/nokogiri/xml_relax_ng.c +179 -0
  132. data/ext/nokogiri/xml_relax_ng.h +9 -0
  133. data/ext/nokogiri/xml_sax_parser.c +305 -0
  134. data/ext/nokogiri/xml_sax_parser.h +39 -0
  135. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  136. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  137. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  138. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  139. data/ext/nokogiri/xml_schema.c +276 -0
  140. data/ext/nokogiri/xml_schema.h +9 -0
  141. data/ext/nokogiri/xml_syntax_error.c +64 -0
  142. data/ext/nokogiri/xml_syntax_error.h +13 -0
  143. data/ext/nokogiri/xml_text.c +52 -0
  144. data/ext/nokogiri/xml_text.h +9 -0
  145. data/ext/nokogiri/xml_xpath_context.c +374 -0
  146. data/ext/nokogiri/xml_xpath_context.h +10 -0
  147. data/ext/nokogiri/xslt_stylesheet.c +263 -0
  148. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  149. data/lib/nokogiri.rb +144 -0
  150. data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
  151. data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
  152. data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
  153. data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
  154. data/lib/nokogiri/css.rb +28 -0
  155. data/lib/nokogiri/css/node.rb +53 -0
  156. data/lib/nokogiri/css/parser.rb +751 -0
  157. data/lib/nokogiri/css/parser.y +272 -0
  158. data/lib/nokogiri/css/parser_extras.rb +94 -0
  159. data/lib/nokogiri/css/syntax_error.rb +8 -0
  160. data/lib/nokogiri/css/tokenizer.rb +154 -0
  161. data/lib/nokogiri/css/tokenizer.rex +55 -0
  162. data/lib/nokogiri/css/xpath_visitor.rb +260 -0
  163. data/lib/nokogiri/decorators/slop.rb +43 -0
  164. data/lib/nokogiri/html.rb +38 -0
  165. data/lib/nokogiri/html/builder.rb +36 -0
  166. data/lib/nokogiri/html/document.rb +322 -0
  167. data/lib/nokogiri/html/document_fragment.rb +50 -0
  168. data/lib/nokogiri/html/element_description.rb +24 -0
  169. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  170. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  171. data/lib/nokogiri/html/sax/parser.rb +63 -0
  172. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  173. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  174. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  175. data/lib/nokogiri/syntax_error.rb +5 -0
  176. data/lib/nokogiri/version.rb +3 -0
  177. data/lib/nokogiri/version/constant.rb +5 -0
  178. data/lib/nokogiri/version/info.rb +182 -0
  179. data/lib/nokogiri/xml.rb +76 -0
  180. data/lib/nokogiri/xml/attr.rb +15 -0
  181. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  182. data/lib/nokogiri/xml/builder.rb +447 -0
  183. data/lib/nokogiri/xml/cdata.rb +12 -0
  184. data/lib/nokogiri/xml/character_data.rb +8 -0
  185. data/lib/nokogiri/xml/document.rb +290 -0
  186. data/lib/nokogiri/xml/document_fragment.rb +159 -0
  187. data/lib/nokogiri/xml/dtd.rb +33 -0
  188. data/lib/nokogiri/xml/element_content.rb +37 -0
  189. data/lib/nokogiri/xml/element_decl.rb +14 -0
  190. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  191. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  192. data/lib/nokogiri/xml/namespace.rb +14 -0
  193. data/lib/nokogiri/xml/node.rb +1240 -0
  194. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  195. data/lib/nokogiri/xml/node_set.rb +372 -0
  196. data/lib/nokogiri/xml/notation.rb +7 -0
  197. data/lib/nokogiri/xml/parse_options.rb +127 -0
  198. data/lib/nokogiri/xml/pp.rb +3 -0
  199. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  200. data/lib/nokogiri/xml/pp/node.rb +57 -0
  201. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  202. data/lib/nokogiri/xml/reader.rb +116 -0
  203. data/lib/nokogiri/xml/relax_ng.rb +37 -0
  204. data/lib/nokogiri/xml/sax.rb +5 -0
  205. data/lib/nokogiri/xml/sax/document.rb +172 -0
  206. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  207. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  208. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  209. data/lib/nokogiri/xml/schema.rb +72 -0
  210. data/lib/nokogiri/xml/searchable.rb +239 -0
  211. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  212. data/lib/nokogiri/xml/text.rb +10 -0
  213. data/lib/nokogiri/xml/xpath.rb +11 -0
  214. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  215. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  216. data/lib/nokogiri/xslt.rb +57 -0
  217. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  218. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  219. metadata +499 -0
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_SAX_PUSH_PARSER
2
+ #define NOKOGIRI_XML_SAX_PUSH_PARSER
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_sax_push_parser();
7
+
8
+ extern VALUE cNokogiriXmlSaxPushParser ;
9
+ #endif
@@ -0,0 +1,276 @@
1
+ #include <xml_schema.h>
2
+
3
+ static void dealloc(xmlSchemaPtr schema)
4
+ {
5
+ NOKOGIRI_DEBUG_START(schema);
6
+ xmlSchemaFree(schema);
7
+ NOKOGIRI_DEBUG_END(schema);
8
+ }
9
+
10
+ /*
11
+ * call-seq:
12
+ * validate_document(document)
13
+ *
14
+ * Validate a Nokogiri::XML::Document against this Schema.
15
+ */
16
+ static VALUE validate_document(VALUE self, VALUE document)
17
+ {
18
+ xmlDocPtr doc;
19
+ xmlSchemaPtr schema;
20
+ xmlSchemaValidCtxtPtr valid_ctxt;
21
+ VALUE errors;
22
+
23
+ Data_Get_Struct(self, xmlSchema, schema);
24
+ Data_Get_Struct(document, xmlDoc, doc);
25
+
26
+ errors = rb_ary_new();
27
+
28
+ valid_ctxt = xmlSchemaNewValidCtxt(schema);
29
+
30
+ if(NULL == valid_ctxt) {
31
+ /* we have a problem */
32
+ rb_raise(rb_eRuntimeError, "Could not create a validation context");
33
+ }
34
+
35
+ #ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
36
+ xmlSchemaSetValidStructuredErrors(
37
+ valid_ctxt,
38
+ Nokogiri_error_array_pusher,
39
+ (void *)errors
40
+ );
41
+ #endif
42
+
43
+ xmlSchemaValidateDoc(valid_ctxt, doc);
44
+
45
+ xmlSchemaFreeValidCtxt(valid_ctxt);
46
+
47
+ return errors;
48
+ }
49
+
50
+ /*
51
+ * call-seq:
52
+ * validate_file(filename)
53
+ *
54
+ * Validate a file against this Schema.
55
+ */
56
+ static VALUE validate_file(VALUE self, VALUE rb_filename)
57
+ {
58
+ xmlSchemaPtr schema;
59
+ xmlSchemaValidCtxtPtr valid_ctxt;
60
+ const char *filename ;
61
+ VALUE errors;
62
+
63
+ Data_Get_Struct(self, xmlSchema, schema);
64
+ filename = (const char*)StringValueCStr(rb_filename) ;
65
+
66
+ errors = rb_ary_new();
67
+
68
+ valid_ctxt = xmlSchemaNewValidCtxt(schema);
69
+
70
+ if(NULL == valid_ctxt) {
71
+ /* we have a problem */
72
+ rb_raise(rb_eRuntimeError, "Could not create a validation context");
73
+ }
74
+
75
+ #ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
76
+ xmlSchemaSetValidStructuredErrors(
77
+ valid_ctxt,
78
+ Nokogiri_error_array_pusher,
79
+ (void *)errors
80
+ );
81
+ #endif
82
+
83
+ xmlSchemaValidateFile(valid_ctxt, filename, 0);
84
+
85
+ xmlSchemaFreeValidCtxt(valid_ctxt);
86
+
87
+ return errors;
88
+ }
89
+
90
+ /*
91
+ * call-seq:
92
+ * read_memory(string)
93
+ *
94
+ * Create a new Schema from the contents of +string+
95
+ */
96
+ static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
97
+ {
98
+ VALUE content;
99
+ VALUE parse_options;
100
+ int parse_options_int;
101
+ xmlSchemaParserCtxtPtr ctx;
102
+ xmlSchemaPtr schema;
103
+ VALUE errors;
104
+ VALUE rb_schema;
105
+ int scanned_args = 0;
106
+ xmlExternalEntityLoader old_loader = 0;
107
+
108
+ scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
109
+ if (scanned_args == 1) {
110
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
111
+ }
112
+ parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
113
+
114
+ ctx = xmlSchemaNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
115
+
116
+ errors = rb_ary_new();
117
+ xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
118
+
119
+ #ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
120
+ xmlSchemaSetParserStructuredErrors(
121
+ ctx,
122
+ Nokogiri_error_array_pusher,
123
+ (void *)errors
124
+ );
125
+ #endif
126
+
127
+ if (parse_options_int & XML_PARSE_NONET) {
128
+ old_loader = xmlGetExternalEntityLoader();
129
+ xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
130
+ }
131
+
132
+ schema = xmlSchemaParse(ctx);
133
+
134
+ if (old_loader) {
135
+ xmlSetExternalEntityLoader(old_loader);
136
+ }
137
+
138
+ xmlSetStructuredErrorFunc(NULL, NULL);
139
+ xmlSchemaFreeParserCtxt(ctx);
140
+
141
+ if(NULL == schema) {
142
+ xmlErrorPtr error = xmlGetLastError();
143
+ if(error)
144
+ Nokogiri_error_raise(NULL, error);
145
+ else
146
+ rb_raise(rb_eRuntimeError, "Could not parse document");
147
+
148
+ return Qnil;
149
+ }
150
+
151
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
152
+ rb_iv_set(rb_schema, "@errors", errors);
153
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
154
+
155
+ return rb_schema;
156
+ }
157
+
158
+ /* Schema creation will remove and deallocate "blank" nodes.
159
+ * If those blank nodes have been exposed to Ruby, they could get freed
160
+ * out from under the VALUE pointer. This function checks to see if any of
161
+ * those nodes have been exposed to Ruby, and if so we should raise an exception.
162
+ */
163
+ static int has_blank_nodes_p(VALUE cache)
164
+ {
165
+ long i;
166
+
167
+ if (NIL_P(cache)) {
168
+ return 0;
169
+ }
170
+
171
+ for (i = 0; i < RARRAY_LEN(cache); i++) {
172
+ xmlNodePtr node;
173
+ VALUE element = rb_ary_entry(cache, i);
174
+ Data_Get_Struct(element, xmlNode, node);
175
+ if (xmlIsBlankNode(node)) {
176
+ return 1;
177
+ }
178
+ }
179
+
180
+ return 0;
181
+ }
182
+
183
+ /*
184
+ * call-seq:
185
+ * from_document(doc)
186
+ *
187
+ * Create a new Schema from the Nokogiri::XML::Document +doc+
188
+ */
189
+ static VALUE from_document(int argc, VALUE *argv, VALUE klass)
190
+ {
191
+ VALUE document;
192
+ VALUE parse_options;
193
+ int parse_options_int;
194
+ xmlDocPtr doc;
195
+ xmlSchemaParserCtxtPtr ctx;
196
+ xmlSchemaPtr schema;
197
+ VALUE errors;
198
+ VALUE rb_schema;
199
+ int scanned_args = 0;
200
+ xmlExternalEntityLoader old_loader = 0;
201
+
202
+ scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
203
+
204
+ Data_Get_Struct(document, xmlDoc, doc);
205
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
206
+
207
+ if (scanned_args == 1) {
208
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
209
+ }
210
+ parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
211
+
212
+ if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
213
+ rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
214
+ }
215
+
216
+ ctx = xmlSchemaNewDocParserCtxt(doc);
217
+
218
+ errors = rb_ary_new();
219
+ xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
220
+
221
+ #ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
222
+ xmlSchemaSetParserStructuredErrors(
223
+ ctx,
224
+ Nokogiri_error_array_pusher,
225
+ (void *)errors
226
+ );
227
+ #endif
228
+
229
+ if (parse_options_int & XML_PARSE_NONET) {
230
+ old_loader = xmlGetExternalEntityLoader();
231
+ xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
232
+ }
233
+
234
+ schema = xmlSchemaParse(ctx);
235
+
236
+ if (old_loader) {
237
+ xmlSetExternalEntityLoader(old_loader);
238
+ }
239
+
240
+ xmlSetStructuredErrorFunc(NULL, NULL);
241
+ xmlSchemaFreeParserCtxt(ctx);
242
+
243
+ if(NULL == schema) {
244
+ xmlErrorPtr error = xmlGetLastError();
245
+ if(error)
246
+ Nokogiri_error_raise(NULL, error);
247
+ else
248
+ rb_raise(rb_eRuntimeError, "Could not parse document");
249
+
250
+ return Qnil;
251
+ }
252
+
253
+ rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
254
+ rb_iv_set(rb_schema, "@errors", errors);
255
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
256
+
257
+ return rb_schema;
258
+
259
+ return Qnil;
260
+ }
261
+
262
+ VALUE cNokogiriXmlSchema;
263
+ void init_xml_schema()
264
+ {
265
+ VALUE nokogiri = rb_define_module("Nokogiri");
266
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
267
+ VALUE klass = rb_define_class_under(xml, "Schema", rb_cObject);
268
+
269
+ cNokogiriXmlSchema = klass;
270
+
271
+ rb_define_singleton_method(klass, "read_memory", read_memory, -1);
272
+ rb_define_singleton_method(klass, "from_document", from_document, -1);
273
+
274
+ rb_define_private_method(klass, "validate_document", validate_document, 1);
275
+ rb_define_private_method(klass, "validate_file", validate_file, 1);
276
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_SCHEMA
2
+ #define NOKOGIRI_XML_SCHEMA
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_schema();
7
+
8
+ extern VALUE cNokogiriXmlSchema;
9
+ #endif
@@ -0,0 +1,64 @@
1
+ #include <xml_syntax_error.h>
2
+
3
+ void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error)
4
+ {
5
+ VALUE list = (VALUE)ctx;
6
+ Check_Type(list, T_ARRAY);
7
+ rb_ary_push(list, Nokogiri_wrap_xml_syntax_error(error));
8
+ }
9
+
10
+ void Nokogiri_error_raise(void * ctx, xmlErrorPtr error)
11
+ {
12
+ rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
13
+ }
14
+
15
+ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error)
16
+ {
17
+ VALUE msg, e, klass;
18
+
19
+ klass = cNokogiriXmlSyntaxError;
20
+
21
+ if (error && error->domain == XML_FROM_XPATH) {
22
+ VALUE xpath = rb_const_get(mNokogiriXml, rb_intern("XPath"));
23
+ klass = rb_const_get(xpath, rb_intern("SyntaxError"));
24
+ }
25
+
26
+ msg = (error && error->message) ? NOKOGIRI_STR_NEW2(error->message) : Qnil;
27
+
28
+ e = rb_class_new_instance(
29
+ 1,
30
+ &msg,
31
+ klass
32
+ );
33
+
34
+ if (error)
35
+ {
36
+ rb_iv_set(e, "@domain", INT2NUM(error->domain));
37
+ rb_iv_set(e, "@code", INT2NUM(error->code));
38
+ rb_iv_set(e, "@level", INT2NUM((short)error->level));
39
+ rb_iv_set(e, "@file", RBSTR_OR_QNIL(error->file));
40
+ rb_iv_set(e, "@line", INT2NUM(error->line));
41
+ rb_iv_set(e, "@str1", RBSTR_OR_QNIL(error->str1));
42
+ rb_iv_set(e, "@str2", RBSTR_OR_QNIL(error->str2));
43
+ rb_iv_set(e, "@str3", RBSTR_OR_QNIL(error->str3));
44
+ rb_iv_set(e, "@int1", INT2NUM(error->int1));
45
+ rb_iv_set(e, "@column", INT2NUM(error->int2));
46
+ }
47
+
48
+ return e;
49
+ }
50
+
51
+ VALUE cNokogiriXmlSyntaxError;
52
+ void init_xml_syntax_error()
53
+ {
54
+ VALUE nokogiri = rb_define_module("Nokogiri");
55
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
56
+
57
+ /*
58
+ * The XML::SyntaxError is raised on parse errors
59
+ */
60
+ VALUE syntax_error_mommy = rb_define_class_under(nokogiri, "SyntaxError", rb_eStandardError);
61
+ VALUE klass = rb_define_class_under(xml, "SyntaxError", syntax_error_mommy);
62
+ cNokogiriXmlSyntaxError = klass;
63
+
64
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef NOKOGIRI_XML_SYNTAX_ERROR
2
+ #define NOKOGIRI_XML_SYNTAX_ERROR
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_syntax_error();
7
+ VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
8
+ void Nokogiri_error_array_pusher(void * ctx, xmlErrorPtr error);
9
+ NORETURN(void Nokogiri_error_raise(void * ctx, xmlErrorPtr error));
10
+
11
+ extern VALUE cNokogiriXmlSyntaxError;
12
+ #endif
13
+
@@ -0,0 +1,52 @@
1
+ #include <xml_text.h>
2
+
3
+ /*
4
+ * call-seq:
5
+ * new(content, document)
6
+ *
7
+ * Create a new Text element on the +document+ with +content+
8
+ */
9
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
10
+ {
11
+ xmlDocPtr doc;
12
+ xmlNodePtr node;
13
+ VALUE string;
14
+ VALUE document;
15
+ VALUE rest;
16
+ VALUE rb_node;
17
+
18
+ rb_scan_args(argc, argv, "2*", &string, &document, &rest);
19
+
20
+ Data_Get_Struct(document, xmlDoc, doc);
21
+
22
+ node = xmlNewText((xmlChar *)StringValueCStr(string));
23
+ node->doc = doc->doc;
24
+
25
+ nokogiri_root_node(node);
26
+
27
+ rb_node = Nokogiri_wrap_xml_node(klass, node) ;
28
+ rb_obj_call_init(rb_node, argc, argv);
29
+
30
+ if(rb_block_given_p()) rb_yield(rb_node);
31
+
32
+ return rb_node;
33
+ }
34
+
35
+ VALUE cNokogiriXmlText ;
36
+ void init_xml_text()
37
+ {
38
+ VALUE nokogiri = rb_define_module("Nokogiri");
39
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
40
+ /* */
41
+ VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
42
+ VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
43
+
44
+ /*
45
+ * Wraps Text nodes.
46
+ */
47
+ VALUE klass = rb_define_class_under(xml, "Text", char_data);
48
+
49
+ cNokogiriXmlText = klass;
50
+
51
+ rb_define_singleton_method(klass, "new", new, -1);
52
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_TEXT
2
+ #define NOKOGIRI_XML_TEXT
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_text();
7
+
8
+ extern VALUE cNokogiriXmlText ;
9
+ #endif
@@ -0,0 +1,374 @@
1
+ #include <xml_xpath_context.h>
2
+
3
+ /*
4
+ * these constants have matching declarations in
5
+ * ext/java/nokogiri/internals/NokogiriNamespaceContext.java
6
+ */
7
+ static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
8
+ static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
9
+
10
+ static void deallocate(xmlXPathContextPtr ctx)
11
+ {
12
+ NOKOGIRI_DEBUG_START(ctx);
13
+ xmlXPathFreeContext(ctx);
14
+ NOKOGIRI_DEBUG_END(ctx);
15
+ }
16
+
17
+ /* find a CSS class in an HTML element's `class` attribute */
18
+ const xmlChar* builtin_css_class(const xmlChar* str, const xmlChar *val)
19
+ {
20
+ int val_len;
21
+
22
+ if (str == NULL) { return(NULL); }
23
+ if (val == NULL) { return(NULL); }
24
+
25
+ val_len = xmlStrlen(val);
26
+ if (val_len == 0) { return(str); }
27
+
28
+ while (*str != 0) {
29
+ if ((*str == *val) && !xmlStrncmp(str, val, val_len)) {
30
+ const xmlChar* next_byte = str + val_len;
31
+
32
+ /* only match if the next byte is whitespace or end of string */
33
+ if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
34
+ return((const xmlChar*)str);
35
+ }
36
+ }
37
+
38
+ /* advance str to whitespace */
39
+ while ((*str != 0) && !IS_BLANK_CH(*str)) {
40
+ str++;
41
+ }
42
+
43
+ /* advance str to start of next word or end of string */
44
+ while ((*str != 0) && IS_BLANK_CH(*str)) {
45
+ str++;
46
+ }
47
+ }
48
+
49
+ return(NULL);
50
+ }
51
+
52
+ /* xmlXPathFunction to wrap builtin_css_class() */
53
+ static void xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
54
+ {
55
+ xmlXPathObjectPtr hay, needle;
56
+
57
+ CHECK_ARITY(2);
58
+
59
+ CAST_TO_STRING;
60
+ needle = valuePop(ctxt);
61
+ if ((needle == NULL) || (needle->type != XPATH_STRING)) {
62
+ xmlXPathFreeObject(needle);
63
+ XP_ERROR(XPATH_INVALID_TYPE);
64
+ }
65
+
66
+ CAST_TO_STRING;
67
+ hay = valuePop(ctxt);
68
+ if ((hay == NULL) || (hay->type != XPATH_STRING)) {
69
+ xmlXPathFreeObject(hay);
70
+ xmlXPathFreeObject(needle);
71
+ XP_ERROR(XPATH_INVALID_TYPE);
72
+ }
73
+
74
+ if (builtin_css_class(hay->stringval, needle->stringval)) {
75
+ valuePush(ctxt, xmlXPathNewBoolean(1));
76
+ } else {
77
+ valuePush(ctxt, xmlXPathNewBoolean(0));
78
+ }
79
+
80
+ xmlXPathFreeObject(hay);
81
+ xmlXPathFreeObject(needle);
82
+ }
83
+
84
+ /*
85
+ * call-seq:
86
+ * register_ns(prefix, uri)
87
+ *
88
+ * Register the namespace with +prefix+ and +uri+.
89
+ */
90
+ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri)
91
+ {
92
+ xmlXPathContextPtr ctx;
93
+ Data_Get_Struct(self, xmlXPathContext, ctx);
94
+
95
+ xmlXPathRegisterNs( ctx,
96
+ (const xmlChar *)StringValueCStr(prefix),
97
+ (const xmlChar *)StringValueCStr(uri)
98
+ );
99
+ return self;
100
+ }
101
+
102
+ /*
103
+ * call-seq:
104
+ * register_variable(name, value)
105
+ *
106
+ * Register the variable +name+ with +value+.
107
+ */
108
+ static VALUE register_variable(VALUE self, VALUE name, VALUE value)
109
+ {
110
+ xmlXPathContextPtr ctx;
111
+ xmlXPathObjectPtr xmlValue;
112
+ Data_Get_Struct(self, xmlXPathContext, ctx);
113
+
114
+ xmlValue = xmlXPathNewCString(StringValueCStr(value));
115
+
116
+ xmlXPathRegisterVariable( ctx,
117
+ (const xmlChar *)StringValueCStr(name),
118
+ xmlValue
119
+ );
120
+
121
+ return self;
122
+ }
123
+
124
+ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name)
125
+ {
126
+ int i;
127
+ VALUE result, doc;
128
+ VALUE *argv;
129
+ VALUE node_set = Qnil;
130
+ xmlNodeSetPtr xml_node_set = NULL;
131
+ xmlXPathObjectPtr obj;
132
+
133
+ assert(ctx->context->doc);
134
+ assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));
135
+
136
+ argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
137
+ for (i = 0 ; i < nargs ; ++i) {
138
+ rb_gc_register_address(&argv[i]);
139
+ }
140
+
141
+ doc = DOC_RUBY_OBJECT(ctx->context->doc);
142
+
143
+ if (nargs > 0) {
144
+ i = nargs - 1;
145
+ do {
146
+ obj = valuePop(ctx);
147
+ switch(obj->type) {
148
+ case XPATH_STRING:
149
+ argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
150
+ break;
151
+ case XPATH_BOOLEAN:
152
+ argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
153
+ break;
154
+ case XPATH_NUMBER:
155
+ argv[i] = rb_float_new(obj->floatval);
156
+ break;
157
+ case XPATH_NODESET:
158
+ argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
159
+ break;
160
+ default:
161
+ argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
162
+ }
163
+ xmlXPathFreeNodeSetList(obj);
164
+ } while(i-- > 0);
165
+ }
166
+
167
+ result = rb_funcall2(handler, rb_intern((const char*)function_name), nargs, argv);
168
+
169
+ for (i = 0 ; i < nargs ; ++i) {
170
+ rb_gc_unregister_address(&argv[i]);
171
+ }
172
+ free(argv);
173
+
174
+ switch(TYPE(result)) {
175
+ case T_FLOAT:
176
+ case T_BIGNUM:
177
+ case T_FIXNUM:
178
+ xmlXPathReturnNumber(ctx, NUM2DBL(result));
179
+ break;
180
+ case T_STRING:
181
+ xmlXPathReturnString(
182
+ ctx,
183
+ xmlCharStrdup(StringValueCStr(result))
184
+ );
185
+ break;
186
+ case T_TRUE:
187
+ xmlXPathReturnTrue(ctx);
188
+ break;
189
+ case T_FALSE:
190
+ xmlXPathReturnFalse(ctx);
191
+ break;
192
+ case T_NIL:
193
+ break;
194
+ case T_ARRAY:
195
+ {
196
+ VALUE args[2];
197
+ args[0] = doc;
198
+ args[1] = result;
199
+ node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
200
+ Data_Get_Struct(node_set, xmlNodeSet, xml_node_set);
201
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
202
+ }
203
+ break;
204
+ case T_DATA:
205
+ if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
206
+ Data_Get_Struct(result, xmlNodeSet, xml_node_set);
207
+ /* Copy the node set, otherwise it will get GC'd. */
208
+ xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
209
+ break;
210
+ }
211
+ default:
212
+ rb_raise(rb_eRuntimeError, "Invalid return type");
213
+ }
214
+ }
215
+
216
+ static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
217
+ {
218
+ VALUE handler = Qnil;
219
+ const char *function = NULL ;
220
+
221
+ assert(ctx);
222
+ assert(ctx->context);
223
+ assert(ctx->context->userData);
224
+ assert(ctx->context->function);
225
+
226
+ handler = (VALUE)(ctx->context->userData);
227
+ function = (const char*)(ctx->context->function);
228
+
229
+ Nokogiri_marshal_xpath_funcall_and_return_values(ctx, nargs, handler, function);
230
+ }
231
+
232
+ static xmlXPathFunction lookup( void *ctx,
233
+ const xmlChar * name,
234
+ const xmlChar* ns_uri )
235
+ {
236
+ VALUE xpath_handler = (VALUE)ctx;
237
+ if(rb_respond_to(xpath_handler, rb_intern((const char *)name)))
238
+ return ruby_funcall;
239
+
240
+ return NULL;
241
+ }
242
+
243
+ NORETURN(static void xpath_generic_exception_handler(void * ctx, const char *msg, ...));
244
+ static void xpath_generic_exception_handler(void * ctx, const char *msg, ...)
245
+ {
246
+ char * message;
247
+
248
+ va_list args;
249
+ va_start(args, msg);
250
+ vasprintf(&message, msg, args);
251
+ va_end(args);
252
+
253
+ rb_raise(rb_eRuntimeError, "%s", message);
254
+ }
255
+
256
+ /*
257
+ * call-seq:
258
+ * evaluate(search_path, handler = nil)
259
+ *
260
+ * Evaluate the +search_path+ returning an XML::XPath object.
261
+ */
262
+ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
263
+ {
264
+ VALUE search_path, xpath_handler;
265
+ VALUE thing = Qnil;
266
+ xmlXPathContextPtr ctx;
267
+ xmlXPathObjectPtr xpath;
268
+ xmlChar *query;
269
+
270
+ Data_Get_Struct(self, xmlXPathContext, ctx);
271
+
272
+ if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1)
273
+ xpath_handler = Qnil;
274
+
275
+ query = (xmlChar *)StringValueCStr(search_path);
276
+
277
+ if(Qnil != xpath_handler) {
278
+ /* FIXME: not sure if this is the correct place to shove private data. */
279
+ ctx->userData = (void *)xpath_handler;
280
+ xmlXPathRegisterFuncLookup(ctx, lookup, (void *)xpath_handler);
281
+ }
282
+
283
+ xmlResetLastError();
284
+ xmlSetStructuredErrorFunc(NULL, Nokogiri_error_raise);
285
+
286
+ /* For some reason, xmlXPathEvalExpression will blow up with a generic error */
287
+ /* when there is a non existent function. */
288
+ xmlSetGenericErrorFunc(NULL, xpath_generic_exception_handler);
289
+
290
+ xpath = xmlXPathEvalExpression(query, ctx);
291
+ xmlSetStructuredErrorFunc(NULL, NULL);
292
+ xmlSetGenericErrorFunc(NULL, NULL);
293
+
294
+ if(xpath == NULL) {
295
+ xmlErrorPtr error = xmlGetLastError();
296
+ rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
297
+ }
298
+
299
+ assert(ctx->doc);
300
+ assert(DOC_RUBY_OBJECT_TEST(ctx->doc));
301
+
302
+ switch(xpath->type) {
303
+ case XPATH_STRING:
304
+ thing = NOKOGIRI_STR_NEW2(xpath->stringval);
305
+ xmlFree(xpath->stringval);
306
+ break;
307
+ case XPATH_NODESET:
308
+ thing = Nokogiri_wrap_xml_node_set(xpath->nodesetval,
309
+ DOC_RUBY_OBJECT(ctx->doc));
310
+ break;
311
+ case XPATH_NUMBER:
312
+ thing = rb_float_new(xpath->floatval);
313
+ break;
314
+ case XPATH_BOOLEAN:
315
+ thing = xpath->boolval == 1 ? Qtrue : Qfalse;
316
+ break;
317
+ default:
318
+ thing = Nokogiri_wrap_xml_node_set(NULL, DOC_RUBY_OBJECT(ctx->doc));
319
+ }
320
+
321
+ xmlXPathFreeNodeSetList(xpath);
322
+
323
+ return thing;
324
+ }
325
+
326
+ /*
327
+ * call-seq:
328
+ * new(node)
329
+ *
330
+ * Create a new XPathContext with +node+ as the reference point.
331
+ */
332
+ static VALUE new(VALUE klass, VALUE nodeobj)
333
+ {
334
+ xmlNodePtr node;
335
+ xmlXPathContextPtr ctx;
336
+ VALUE self;
337
+
338
+ Data_Get_Struct(nodeobj, xmlNode, node);
339
+
340
+ xmlXPathInit();
341
+
342
+ ctx = xmlXPathNewContext(node->doc);
343
+ ctx->node = node;
344
+
345
+ xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
346
+ xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
347
+ xpath_builtin_css_class);
348
+
349
+ self = Data_Wrap_Struct(klass, 0, deallocate, ctx);
350
+ return self;
351
+ }
352
+
353
+ VALUE cNokogiriXmlXpathContext;
354
+ void init_xml_xpath_context(void)
355
+ {
356
+ VALUE module = rb_define_module("Nokogiri");
357
+
358
+ /*
359
+ * Nokogiri::XML
360
+ */
361
+ VALUE xml = rb_define_module_under(module, "XML");
362
+
363
+ /*
364
+ * XPathContext is the entry point for searching a Document by using XPath.
365
+ */
366
+ VALUE klass = rb_define_class_under(xml, "XPathContext", rb_cObject);
367
+
368
+ cNokogiriXmlXpathContext = klass;
369
+
370
+ rb_define_singleton_method(klass, "new", new, 1);
371
+ rb_define_method(klass, "evaluate", evaluate, -1);
372
+ rb_define_method(klass, "register_variable", register_variable, 2);
373
+ rb_define_method(klass, "register_ns", register_ns, 2);
374
+ }