nokogiri 1.13.0-aarch64-linux
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.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/LICENSE-DEPENDENCIES.md +1903 -0
- data/LICENSE.md +9 -0
- data/README.md +280 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +73 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1000 -0
- data/ext/nokogiri/gumbo.c +584 -0
- data/ext/nokogiri/html4_document.c +166 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +120 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1243 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +946 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +564 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +278 -0
- data/ext/nokogiri/nokogiri.h +223 -0
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_cdata.c +57 -0
- data/ext/nokogiri/xml_comment.c +62 -0
- data/ext/nokogiri/xml_document.c +680 -0
- data/ext/nokogiri/xml_document_fragment.c +44 -0
- data/ext/nokogiri/xml_dtd.c +208 -0
- data/ext/nokogiri/xml_element_content.c +128 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +104 -0
- data/ext/nokogiri/xml_entity_decl.c +112 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_namespace.c +120 -0
- data/ext/nokogiri/xml_node.c +2144 -0
- data/ext/nokogiri/xml_node_set.c +498 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +719 -0
- data/ext/nokogiri/xml_relax_ng.c +185 -0
- data/ext/nokogiri/xml_sax_parser.c +310 -0
- data/ext/nokogiri/xml_sax_parser_context.c +281 -0
- data/ext/nokogiri/xml_sax_push_parser.c +168 -0
- data/ext/nokogiri/xml_schema.c +284 -0
- data/ext/nokogiri/xml_syntax_error.c +85 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_xpath_context.c +406 -0
- data/ext/nokogiri/xslt_stylesheet.c +264 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/2.6/nokogiri.so +0 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +54 -0
- data/lib/nokogiri/css/parser.rb +759 -0
- data/lib/nokogiri/css/parser.y +280 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +56 -0
- data/lib/nokogiri/css/xpath_visitor.rb +359 -0
- data/lib/nokogiri/css.rb +60 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/extension.rb +31 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +48 -0
- data/lib/nokogiri/html4/builder.rb +37 -0
- data/lib/nokogiri/html4/document.rb +331 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +578 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +61 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +46 -0
- data/lib/nokogiri/html5/document.rb +88 -0
- data/lib/nokogiri/html5/document_fragment.rb +83 -0
- data/lib/nokogiri/html5/node.rb +96 -0
- data/lib/nokogiri/html5.rb +477 -0
- data/lib/nokogiri/jruby/dependencies.rb +21 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +221 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +17 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +485 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +418 -0
- data/lib/nokogiri/xml/document_fragment.rb +162 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +38 -0
- data/lib/nokogiri/xml/element_decl.rb +15 -0
- data/lib/nokogiri/xml/entity_decl.rb +21 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +16 -0
- data/lib/nokogiri/xml/node/save_options.rb +65 -0
- data/lib/nokogiri/xml/node.rb +1402 -0
- data/lib/nokogiri/xml/node_set.rb +364 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +133 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +55 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +10 -0
- data/lib/nokogiri/xml/reader.rb +107 -0
- data/lib/nokogiri/xml/relax_ng.rb +38 -0
- data/lib/nokogiri/xml/sax/document.rb +167 -0
- data/lib/nokogiri/xml/sax/parser.rb +125 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +6 -0
- data/lib/nokogiri/xml/schema.rb +73 -0
- data/lib/nokogiri/xml/searchable.rb +259 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
- data/lib/nokogiri/xml/xpath.rb +21 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xml.rb +75 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +58 -0
- data/lib/nokogiri.rb +128 -0
- data/lib/xsd/xmlparser/nokogiri.rb +104 -0
- metadata +539 -0
@@ -0,0 +1,281 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxParserContext ;
|
4
|
+
|
5
|
+
static void
|
6
|
+
deallocate(xmlParserCtxtPtr ctxt)
|
7
|
+
{
|
8
|
+
NOKOGIRI_DEBUG_START(ctxt);
|
9
|
+
|
10
|
+
ctxt->sax = NULL;
|
11
|
+
|
12
|
+
xmlFreeParserCtxt(ctxt);
|
13
|
+
|
14
|
+
NOKOGIRI_DEBUG_END(ctxt);
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
* call-seq:
|
19
|
+
* parse_io(io, encoding)
|
20
|
+
*
|
21
|
+
* Parse +io+ object with +encoding+
|
22
|
+
*/
|
23
|
+
static VALUE
|
24
|
+
parse_io(VALUE klass, VALUE io, VALUE encoding)
|
25
|
+
{
|
26
|
+
xmlParserCtxtPtr ctxt;
|
27
|
+
xmlCharEncoding enc = (xmlCharEncoding)NUM2INT(encoding);
|
28
|
+
|
29
|
+
ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
30
|
+
(xmlInputReadCallback)noko_io_read,
|
31
|
+
(xmlInputCloseCallback)noko_io_close,
|
32
|
+
(void *)io, enc);
|
33
|
+
if (ctxt->sax) {
|
34
|
+
xmlFree(ctxt->sax);
|
35
|
+
ctxt->sax = NULL;
|
36
|
+
}
|
37
|
+
|
38
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
39
|
+
}
|
40
|
+
|
41
|
+
/*
|
42
|
+
* call-seq:
|
43
|
+
* parse_file(filename)
|
44
|
+
*
|
45
|
+
* Parse file given +filename+
|
46
|
+
*/
|
47
|
+
static VALUE
|
48
|
+
parse_file(VALUE klass, VALUE filename)
|
49
|
+
{
|
50
|
+
xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValueCStr(filename));
|
51
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* call-seq:
|
56
|
+
* parse_memory(data)
|
57
|
+
*
|
58
|
+
* Parse the XML stored in memory in +data+
|
59
|
+
*/
|
60
|
+
static VALUE
|
61
|
+
parse_memory(VALUE klass, VALUE data)
|
62
|
+
{
|
63
|
+
xmlParserCtxtPtr ctxt;
|
64
|
+
|
65
|
+
if (NIL_P(data)) {
|
66
|
+
rb_raise(rb_eArgError, "data cannot be nil");
|
67
|
+
}
|
68
|
+
if (!(int)RSTRING_LEN(data)) {
|
69
|
+
rb_raise(rb_eRuntimeError, "data cannot be empty");
|
70
|
+
}
|
71
|
+
|
72
|
+
ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data),
|
73
|
+
(int)RSTRING_LEN(data));
|
74
|
+
if (ctxt->sax) {
|
75
|
+
xmlFree(ctxt->sax);
|
76
|
+
ctxt->sax = NULL;
|
77
|
+
}
|
78
|
+
|
79
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, ctxt);
|
80
|
+
}
|
81
|
+
|
82
|
+
static VALUE
|
83
|
+
parse_doc(VALUE ctxt_val)
|
84
|
+
{
|
85
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
86
|
+
xmlParseDocument(ctxt);
|
87
|
+
return Qnil;
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
parse_doc_finalize(VALUE ctxt_val)
|
92
|
+
{
|
93
|
+
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
|
94
|
+
|
95
|
+
if (NULL != ctxt->myDoc) {
|
96
|
+
xmlFreeDoc(ctxt->myDoc);
|
97
|
+
}
|
98
|
+
|
99
|
+
NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* call-seq:
|
105
|
+
* parse_with(sax_handler)
|
106
|
+
*
|
107
|
+
* Use +sax_handler+ and parse the current document
|
108
|
+
*/
|
109
|
+
static VALUE
|
110
|
+
parse_with(VALUE self, VALUE sax_handler)
|
111
|
+
{
|
112
|
+
xmlParserCtxtPtr ctxt;
|
113
|
+
xmlSAXHandlerPtr sax;
|
114
|
+
|
115
|
+
if (!rb_obj_is_kind_of(sax_handler, cNokogiriXmlSaxParser)) {
|
116
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::SAX::Parser");
|
117
|
+
}
|
118
|
+
|
119
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
120
|
+
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
|
121
|
+
|
122
|
+
/* Free the sax handler since we'll assign our own */
|
123
|
+
if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
|
124
|
+
xmlFree(ctxt->sax);
|
125
|
+
}
|
126
|
+
|
127
|
+
ctxt->sax = sax;
|
128
|
+
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
|
129
|
+
|
130
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
131
|
+
|
132
|
+
rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
|
133
|
+
|
134
|
+
return Qnil;
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* call-seq:
|
139
|
+
* replace_entities=(boolean)
|
140
|
+
*
|
141
|
+
* Should this parser replace entities? & will get converted to '&' if
|
142
|
+
* set to true
|
143
|
+
*/
|
144
|
+
static VALUE
|
145
|
+
set_replace_entities(VALUE self, VALUE value)
|
146
|
+
{
|
147
|
+
xmlParserCtxtPtr ctxt;
|
148
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
149
|
+
|
150
|
+
if (Qfalse == value) {
|
151
|
+
ctxt->replaceEntities = 0;
|
152
|
+
} else {
|
153
|
+
ctxt->replaceEntities = 1;
|
154
|
+
}
|
155
|
+
|
156
|
+
return value;
|
157
|
+
}
|
158
|
+
|
159
|
+
/*
|
160
|
+
* call-seq:
|
161
|
+
* replace_entities
|
162
|
+
*
|
163
|
+
* Should this parser replace entities? & will get converted to '&' if
|
164
|
+
* set to true
|
165
|
+
*/
|
166
|
+
static VALUE
|
167
|
+
get_replace_entities(VALUE self)
|
168
|
+
{
|
169
|
+
xmlParserCtxtPtr ctxt;
|
170
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
171
|
+
|
172
|
+
if (0 == ctxt->replaceEntities) {
|
173
|
+
return Qfalse;
|
174
|
+
} else {
|
175
|
+
return Qtrue;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
/*
|
180
|
+
* call-seq: line
|
181
|
+
*
|
182
|
+
* Get the current line the parser context is processing.
|
183
|
+
*/
|
184
|
+
static VALUE
|
185
|
+
line(VALUE self)
|
186
|
+
{
|
187
|
+
xmlParserCtxtPtr ctxt;
|
188
|
+
xmlParserInputPtr io;
|
189
|
+
|
190
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
191
|
+
|
192
|
+
io = ctxt->input;
|
193
|
+
if (io) {
|
194
|
+
return INT2NUM(io->line);
|
195
|
+
}
|
196
|
+
|
197
|
+
return Qnil;
|
198
|
+
}
|
199
|
+
|
200
|
+
/*
|
201
|
+
* call-seq: column
|
202
|
+
*
|
203
|
+
* Get the current column the parser context is processing.
|
204
|
+
*/
|
205
|
+
static VALUE
|
206
|
+
column(VALUE self)
|
207
|
+
{
|
208
|
+
xmlParserCtxtPtr ctxt;
|
209
|
+
xmlParserInputPtr io;
|
210
|
+
|
211
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
212
|
+
|
213
|
+
io = ctxt->input;
|
214
|
+
if (io) {
|
215
|
+
return INT2NUM(io->col);
|
216
|
+
}
|
217
|
+
|
218
|
+
return Qnil;
|
219
|
+
}
|
220
|
+
|
221
|
+
/*
|
222
|
+
* call-seq:
|
223
|
+
* recovery=(boolean)
|
224
|
+
*
|
225
|
+
* Should this parser recover from structural errors? It will not stop processing
|
226
|
+
* file on structural errors if set to true
|
227
|
+
*/
|
228
|
+
static VALUE
|
229
|
+
set_recovery(VALUE self, VALUE value)
|
230
|
+
{
|
231
|
+
xmlParserCtxtPtr ctxt;
|
232
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
233
|
+
|
234
|
+
if (value == Qfalse) {
|
235
|
+
ctxt->recovery = 0;
|
236
|
+
} else {
|
237
|
+
ctxt->recovery = 1;
|
238
|
+
}
|
239
|
+
|
240
|
+
return value;
|
241
|
+
}
|
242
|
+
|
243
|
+
/*
|
244
|
+
* call-seq:
|
245
|
+
* recovery
|
246
|
+
*
|
247
|
+
* Should this parser recover from structural errors? It will not stop processing
|
248
|
+
* file on structural errors if set to true
|
249
|
+
*/
|
250
|
+
static VALUE
|
251
|
+
get_recovery(VALUE self)
|
252
|
+
{
|
253
|
+
xmlParserCtxtPtr ctxt;
|
254
|
+
Data_Get_Struct(self, xmlParserCtxt, ctxt);
|
255
|
+
|
256
|
+
if (ctxt->recovery == 0) {
|
257
|
+
return Qfalse;
|
258
|
+
} else {
|
259
|
+
return Qtrue;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
void
|
264
|
+
noko_init_xml_sax_parser_context()
|
265
|
+
{
|
266
|
+
cNokogiriXmlSaxParserContext = rb_define_class_under(mNokogiriXmlSax, "ParserContext", rb_cObject);
|
267
|
+
|
268
|
+
rb_undef_alloc_func(cNokogiriXmlSaxParserContext);
|
269
|
+
|
270
|
+
rb_define_singleton_method(cNokogiriXmlSaxParserContext, "io", parse_io, 2);
|
271
|
+
rb_define_singleton_method(cNokogiriXmlSaxParserContext, "memory", parse_memory, 1);
|
272
|
+
rb_define_singleton_method(cNokogiriXmlSaxParserContext, "file", parse_file, 1);
|
273
|
+
|
274
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "parse_with", parse_with, 1);
|
275
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "replace_entities=", set_replace_entities, 1);
|
276
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "replace_entities", get_replace_entities, 0);
|
277
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "recovery=", set_recovery, 1);
|
278
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "recovery", get_recovery, 0);
|
279
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "line", line, 0);
|
280
|
+
rb_define_method(cNokogiriXmlSaxParserContext, "column", column, 0);
|
281
|
+
}
|
@@ -0,0 +1,168 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxPushParser ;
|
4
|
+
|
5
|
+
static void
|
6
|
+
deallocate(xmlParserCtxtPtr ctx)
|
7
|
+
{
|
8
|
+
NOKOGIRI_DEBUG_START(ctx);
|
9
|
+
if (ctx != NULL) {
|
10
|
+
NOKOGIRI_SAX_TUPLE_DESTROY(ctx->userData);
|
11
|
+
xmlFreeParserCtxt(ctx);
|
12
|
+
}
|
13
|
+
NOKOGIRI_DEBUG_END(ctx);
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
allocate(VALUE klass)
|
18
|
+
{
|
19
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, NULL);
|
20
|
+
}
|
21
|
+
|
22
|
+
/*
|
23
|
+
* call-seq:
|
24
|
+
* native_write(chunk, last_chunk)
|
25
|
+
*
|
26
|
+
* Write +chunk+ to PushParser. +last_chunk+ triggers the end_document handle
|
27
|
+
*/
|
28
|
+
static VALUE
|
29
|
+
native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
|
30
|
+
{
|
31
|
+
xmlParserCtxtPtr ctx;
|
32
|
+
const char *chunk = NULL;
|
33
|
+
int size = 0;
|
34
|
+
|
35
|
+
|
36
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
37
|
+
|
38
|
+
if (Qnil != _chunk) {
|
39
|
+
chunk = StringValuePtr(_chunk);
|
40
|
+
size = (int)RSTRING_LEN(_chunk);
|
41
|
+
}
|
42
|
+
|
43
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
44
|
+
|
45
|
+
if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
|
46
|
+
if (!(ctx->options & XML_PARSE_RECOVER)) {
|
47
|
+
xmlErrorPtr e = xmlCtxtGetLastError(ctx);
|
48
|
+
Nokogiri_error_raise(NULL, e);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
return self;
|
53
|
+
}
|
54
|
+
|
55
|
+
/*
|
56
|
+
* call-seq:
|
57
|
+
* initialize_native(xml_sax, filename)
|
58
|
+
*
|
59
|
+
* Initialize the push parser with +xml_sax+ using +filename+
|
60
|
+
*/
|
61
|
+
static VALUE
|
62
|
+
initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
|
63
|
+
{
|
64
|
+
xmlSAXHandlerPtr sax;
|
65
|
+
const char *filename = NULL;
|
66
|
+
xmlParserCtxtPtr ctx;
|
67
|
+
|
68
|
+
Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
|
69
|
+
|
70
|
+
if (_filename != Qnil) { filename = StringValueCStr(_filename); }
|
71
|
+
|
72
|
+
ctx = xmlCreatePushParserCtxt(
|
73
|
+
sax,
|
74
|
+
NULL,
|
75
|
+
NULL,
|
76
|
+
0,
|
77
|
+
filename
|
78
|
+
);
|
79
|
+
if (ctx == NULL) {
|
80
|
+
rb_raise(rb_eRuntimeError, "Could not create a parser context");
|
81
|
+
}
|
82
|
+
|
83
|
+
ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);
|
84
|
+
|
85
|
+
ctx->sax2 = 1;
|
86
|
+
DATA_PTR(self) = ctx;
|
87
|
+
return self;
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
get_options(VALUE self)
|
92
|
+
{
|
93
|
+
xmlParserCtxtPtr ctx;
|
94
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
95
|
+
|
96
|
+
return INT2NUM(ctx->options);
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE
|
100
|
+
set_options(VALUE self, VALUE options)
|
101
|
+
{
|
102
|
+
xmlParserCtxtPtr ctx;
|
103
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
104
|
+
|
105
|
+
if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0) {
|
106
|
+
rb_raise(rb_eRuntimeError, "Cannot set XML parser context options");
|
107
|
+
}
|
108
|
+
|
109
|
+
return Qnil;
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* replace_entities
|
115
|
+
*
|
116
|
+
* Should this parser replace entities? & will get converted to '&' if
|
117
|
+
* set to true
|
118
|
+
*/
|
119
|
+
static VALUE
|
120
|
+
get_replace_entities(VALUE self)
|
121
|
+
{
|
122
|
+
xmlParserCtxtPtr ctx;
|
123
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
124
|
+
|
125
|
+
if (0 == ctx->replaceEntities) {
|
126
|
+
return Qfalse;
|
127
|
+
} else {
|
128
|
+
return Qtrue;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* replace_entities=(boolean)
|
135
|
+
*
|
136
|
+
* Should this parser replace entities? & will get converted to '&' if
|
137
|
+
* set to true
|
138
|
+
*/
|
139
|
+
static VALUE
|
140
|
+
set_replace_entities(VALUE self, VALUE value)
|
141
|
+
{
|
142
|
+
xmlParserCtxtPtr ctx;
|
143
|
+
Data_Get_Struct(self, xmlParserCtxt, ctx);
|
144
|
+
|
145
|
+
if (Qfalse == value) {
|
146
|
+
ctx->replaceEntities = 0;
|
147
|
+
} else {
|
148
|
+
ctx->replaceEntities = 1;
|
149
|
+
}
|
150
|
+
|
151
|
+
return value;
|
152
|
+
}
|
153
|
+
|
154
|
+
void
|
155
|
+
noko_init_xml_sax_push_parser()
|
156
|
+
{
|
157
|
+
cNokogiriXmlSaxPushParser = rb_define_class_under(mNokogiriXmlSax, "PushParser", rb_cObject);
|
158
|
+
|
159
|
+
rb_define_alloc_func(cNokogiriXmlSaxPushParser, allocate);
|
160
|
+
|
161
|
+
rb_define_method(cNokogiriXmlSaxPushParser, "options", get_options, 0);
|
162
|
+
rb_define_method(cNokogiriXmlSaxPushParser, "options=", set_options, 1);
|
163
|
+
rb_define_method(cNokogiriXmlSaxPushParser, "replace_entities", get_replace_entities, 0);
|
164
|
+
rb_define_method(cNokogiriXmlSaxPushParser, "replace_entities=", set_replace_entities, 1);
|
165
|
+
|
166
|
+
rb_define_private_method(cNokogiriXmlSaxPushParser, "initialize_native", initialize_native, 2);
|
167
|
+
rb_define_private_method(cNokogiriXmlSaxPushParser, "native_write", native_write, 2);
|
168
|
+
}
|
@@ -0,0 +1,284 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSchema;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlSchemaPtr schema)
|
7
|
+
{
|
8
|
+
NOKOGIRI_DEBUG_START(schema);
|
9
|
+
xmlSchemaFree(schema);
|
10
|
+
NOKOGIRI_DEBUG_END(schema);
|
11
|
+
}
|
12
|
+
|
13
|
+
/*
|
14
|
+
* call-seq:
|
15
|
+
* validate_document(document)
|
16
|
+
*
|
17
|
+
* Validate a Nokogiri::XML::Document against this Schema.
|
18
|
+
*/
|
19
|
+
static VALUE
|
20
|
+
validate_document(VALUE self, VALUE document)
|
21
|
+
{
|
22
|
+
xmlDocPtr doc;
|
23
|
+
xmlSchemaPtr schema;
|
24
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
25
|
+
VALUE errors;
|
26
|
+
|
27
|
+
Data_Get_Struct(self, xmlSchema, schema);
|
28
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
29
|
+
|
30
|
+
errors = rb_ary_new();
|
31
|
+
|
32
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
33
|
+
|
34
|
+
if (NULL == valid_ctxt) {
|
35
|
+
/* we have a problem */
|
36
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
37
|
+
}
|
38
|
+
|
39
|
+
#ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
|
40
|
+
xmlSchemaSetValidStructuredErrors(
|
41
|
+
valid_ctxt,
|
42
|
+
Nokogiri_error_array_pusher,
|
43
|
+
(void *)errors
|
44
|
+
);
|
45
|
+
#endif
|
46
|
+
|
47
|
+
xmlSchemaValidateDoc(valid_ctxt, doc);
|
48
|
+
|
49
|
+
xmlSchemaFreeValidCtxt(valid_ctxt);
|
50
|
+
|
51
|
+
return errors;
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* call-seq:
|
56
|
+
* validate_file(filename)
|
57
|
+
*
|
58
|
+
* Validate a file against this Schema.
|
59
|
+
*/
|
60
|
+
static VALUE
|
61
|
+
validate_file(VALUE self, VALUE rb_filename)
|
62
|
+
{
|
63
|
+
xmlSchemaPtr schema;
|
64
|
+
xmlSchemaValidCtxtPtr valid_ctxt;
|
65
|
+
const char *filename ;
|
66
|
+
VALUE errors;
|
67
|
+
|
68
|
+
Data_Get_Struct(self, xmlSchema, schema);
|
69
|
+
filename = (const char *)StringValueCStr(rb_filename) ;
|
70
|
+
|
71
|
+
errors = rb_ary_new();
|
72
|
+
|
73
|
+
valid_ctxt = xmlSchemaNewValidCtxt(schema);
|
74
|
+
|
75
|
+
if (NULL == valid_ctxt) {
|
76
|
+
/* we have a problem */
|
77
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
78
|
+
}
|
79
|
+
|
80
|
+
#ifdef HAVE_XMLSCHEMASETVALIDSTRUCTUREDERRORS
|
81
|
+
xmlSchemaSetValidStructuredErrors(
|
82
|
+
valid_ctxt,
|
83
|
+
Nokogiri_error_array_pusher,
|
84
|
+
(void *)errors
|
85
|
+
);
|
86
|
+
#endif
|
87
|
+
|
88
|
+
xmlSchemaValidateFile(valid_ctxt, filename, 0);
|
89
|
+
|
90
|
+
xmlSchemaFreeValidCtxt(valid_ctxt);
|
91
|
+
|
92
|
+
return errors;
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
* call-seq:
|
97
|
+
* read_memory(string)
|
98
|
+
*
|
99
|
+
* Create a new Schema from the contents of +string+
|
100
|
+
*/
|
101
|
+
static VALUE
|
102
|
+
read_memory(int argc, VALUE *argv, VALUE klass)
|
103
|
+
{
|
104
|
+
VALUE content;
|
105
|
+
VALUE parse_options;
|
106
|
+
int parse_options_int;
|
107
|
+
xmlSchemaParserCtxtPtr ctx;
|
108
|
+
xmlSchemaPtr schema;
|
109
|
+
VALUE errors;
|
110
|
+
VALUE rb_schema;
|
111
|
+
int scanned_args = 0;
|
112
|
+
xmlExternalEntityLoader old_loader = 0;
|
113
|
+
|
114
|
+
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
115
|
+
if (scanned_args == 1) {
|
116
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
117
|
+
}
|
118
|
+
parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
119
|
+
|
120
|
+
ctx = xmlSchemaNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
121
|
+
|
122
|
+
errors = rb_ary_new();
|
123
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
124
|
+
|
125
|
+
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
126
|
+
xmlSchemaSetParserStructuredErrors(
|
127
|
+
ctx,
|
128
|
+
Nokogiri_error_array_pusher,
|
129
|
+
(void *)errors
|
130
|
+
);
|
131
|
+
#endif
|
132
|
+
|
133
|
+
if (parse_options_int & XML_PARSE_NONET) {
|
134
|
+
old_loader = xmlGetExternalEntityLoader();
|
135
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
136
|
+
}
|
137
|
+
|
138
|
+
schema = xmlSchemaParse(ctx);
|
139
|
+
|
140
|
+
if (old_loader) {
|
141
|
+
xmlSetExternalEntityLoader(old_loader);
|
142
|
+
}
|
143
|
+
|
144
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
145
|
+
xmlSchemaFreeParserCtxt(ctx);
|
146
|
+
|
147
|
+
if (NULL == schema) {
|
148
|
+
xmlErrorPtr error = xmlGetLastError();
|
149
|
+
if (error) {
|
150
|
+
Nokogiri_error_raise(NULL, error);
|
151
|
+
} else {
|
152
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
153
|
+
}
|
154
|
+
|
155
|
+
return Qnil;
|
156
|
+
}
|
157
|
+
|
158
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
159
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
160
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
161
|
+
|
162
|
+
return rb_schema;
|
163
|
+
}
|
164
|
+
|
165
|
+
/* Schema creation will remove and deallocate "blank" nodes.
|
166
|
+
* If those blank nodes have been exposed to Ruby, they could get freed
|
167
|
+
* out from under the VALUE pointer. This function checks to see if any of
|
168
|
+
* those nodes have been exposed to Ruby, and if so we should raise an exception.
|
169
|
+
*/
|
170
|
+
static int
|
171
|
+
has_blank_nodes_p(VALUE cache)
|
172
|
+
{
|
173
|
+
long i;
|
174
|
+
|
175
|
+
if (NIL_P(cache)) {
|
176
|
+
return 0;
|
177
|
+
}
|
178
|
+
|
179
|
+
for (i = 0; i < RARRAY_LEN(cache); i++) {
|
180
|
+
xmlNodePtr node;
|
181
|
+
VALUE element = rb_ary_entry(cache, i);
|
182
|
+
Data_Get_Struct(element, xmlNode, node);
|
183
|
+
if (xmlIsBlankNode(node)) {
|
184
|
+
return 1;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
return 0;
|
189
|
+
}
|
190
|
+
|
191
|
+
/*
|
192
|
+
* call-seq:
|
193
|
+
* from_document(doc)
|
194
|
+
*
|
195
|
+
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
196
|
+
*/
|
197
|
+
static VALUE
|
198
|
+
from_document(int argc, VALUE *argv, VALUE klass)
|
199
|
+
{
|
200
|
+
VALUE document;
|
201
|
+
VALUE parse_options;
|
202
|
+
int parse_options_int;
|
203
|
+
xmlDocPtr doc;
|
204
|
+
xmlSchemaParserCtxtPtr ctx;
|
205
|
+
xmlSchemaPtr schema;
|
206
|
+
VALUE errors;
|
207
|
+
VALUE rb_schema;
|
208
|
+
int scanned_args = 0;
|
209
|
+
xmlExternalEntityLoader old_loader = 0;
|
210
|
+
|
211
|
+
scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
212
|
+
|
213
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
214
|
+
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
215
|
+
|
216
|
+
if (scanned_args == 1) {
|
217
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
218
|
+
}
|
219
|
+
parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
220
|
+
|
221
|
+
if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
|
222
|
+
rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
|
223
|
+
}
|
224
|
+
|
225
|
+
ctx = xmlSchemaNewDocParserCtxt(doc);
|
226
|
+
|
227
|
+
errors = rb_ary_new();
|
228
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
229
|
+
|
230
|
+
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
231
|
+
xmlSchemaSetParserStructuredErrors(
|
232
|
+
ctx,
|
233
|
+
Nokogiri_error_array_pusher,
|
234
|
+
(void *)errors
|
235
|
+
);
|
236
|
+
#endif
|
237
|
+
|
238
|
+
if (parse_options_int & XML_PARSE_NONET) {
|
239
|
+
old_loader = xmlGetExternalEntityLoader();
|
240
|
+
xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
|
241
|
+
}
|
242
|
+
|
243
|
+
schema = xmlSchemaParse(ctx);
|
244
|
+
|
245
|
+
if (old_loader) {
|
246
|
+
xmlSetExternalEntityLoader(old_loader);
|
247
|
+
}
|
248
|
+
|
249
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
250
|
+
xmlSchemaFreeParserCtxt(ctx);
|
251
|
+
|
252
|
+
if (NULL == schema) {
|
253
|
+
xmlErrorPtr error = xmlGetLastError();
|
254
|
+
if (error) {
|
255
|
+
Nokogiri_error_raise(NULL, error);
|
256
|
+
} else {
|
257
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
258
|
+
}
|
259
|
+
|
260
|
+
return Qnil;
|
261
|
+
}
|
262
|
+
|
263
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
264
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
265
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
266
|
+
|
267
|
+
return rb_schema;
|
268
|
+
|
269
|
+
return Qnil;
|
270
|
+
}
|
271
|
+
|
272
|
+
void
|
273
|
+
noko_init_xml_schema()
|
274
|
+
{
|
275
|
+
cNokogiriXmlSchema = rb_define_class_under(mNokogiriXml, "Schema", rb_cObject);
|
276
|
+
|
277
|
+
rb_undef_alloc_func(cNokogiriXmlSchema);
|
278
|
+
|
279
|
+
rb_define_singleton_method(cNokogiriXmlSchema, "read_memory", read_memory, -1);
|
280
|
+
rb_define_singleton_method(cNokogiriXmlSchema, "from_document", from_document, -1);
|
281
|
+
|
282
|
+
rb_define_private_method(cNokogiriXmlSchema, "validate_document", validate_document, 1);
|
283
|
+
rb_define_private_method(cNokogiriXmlSchema, "validate_file", validate_file, 1);
|
284
|
+
}
|