nokogiri 1.14.0-arm-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 +38 -0
- data/LICENSE-DEPENDENCIES.md +2224 -0
- data/LICENSE.md +9 -0
- data/README.md +287 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +41 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1082 -0
- data/ext/nokogiri/gumbo.c +594 -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 +114 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +108 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +63 -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 +204 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +172 -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 +81 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +232 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +499 -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 +186 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1244 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +656 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +218 -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 +91 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1312 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +463 -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 +947 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +226 -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 +152 -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 +503 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +575 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +137 -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 +1982 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +179 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +310 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +260 -0
- data/ext/nokogiri/nokogiri.h +235 -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 +689 -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 +186 -0
- data/ext/nokogiri/xml_node.c +2425 -0
- data/ext/nokogiri/xml_node_set.c +496 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +794 -0
- data/ext/nokogiri/xml_relax_ng.c +183 -0
- data/ext/nokogiri/xml_sax_parser.c +316 -0
- data/ext/nokogiri/xml_sax_parser_context.c +283 -0
- data/ext/nokogiri/xml_sax_push_parser.c +166 -0
- data/ext/nokogiri/xml_schema.c +282 -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 +413 -0
- data/ext/nokogiri/xslt_stylesheet.c +363 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -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/3.2/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 +770 -0
- data/lib/nokogiri/css/parser.y +277 -0
- data/lib/nokogiri/css/parser_extras.rb +96 -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 +66 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -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 +214 -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 +572 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +63 -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 +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +98 -0
- data/lib/nokogiri/html5.rb +389 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +66 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +487 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +471 -0
- data/lib/nokogiri/xml/document_fragment.rb +205 -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 +58 -0
- data/lib/nokogiri/xml/node/save_options.rb +68 -0
- data/lib/nokogiri/xml/node.rb +1563 -0
- data/lib/nokogiri/xml/node_set.rb +446 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +213 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +11 -0
- data/lib/nokogiri/xml/reader.rb +105 -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 +270 -0
- data/lib/nokogiri/xml/syntax_error.rb +72 -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 +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +65 -0
- data/lib/nokogiri.rb +120 -0
- data/lib/xsd/xmlparser/nokogiri.rb +106 -0
- metadata +317 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlRelaxNG;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlRelaxNGPtr schema)
|
7
|
+
{
|
8
|
+
xmlRelaxNGFree(schema);
|
9
|
+
}
|
10
|
+
|
11
|
+
/*
|
12
|
+
* call-seq:
|
13
|
+
* validate_document(document)
|
14
|
+
*
|
15
|
+
* Validate a Nokogiri::XML::Document against this RelaxNG schema.
|
16
|
+
*/
|
17
|
+
static VALUE
|
18
|
+
validate_document(VALUE self, VALUE document)
|
19
|
+
{
|
20
|
+
xmlDocPtr doc;
|
21
|
+
xmlRelaxNGPtr schema;
|
22
|
+
VALUE errors;
|
23
|
+
xmlRelaxNGValidCtxtPtr valid_ctxt;
|
24
|
+
|
25
|
+
Data_Get_Struct(self, xmlRelaxNG, schema);
|
26
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
27
|
+
|
28
|
+
errors = rb_ary_new();
|
29
|
+
|
30
|
+
valid_ctxt = xmlRelaxNGNewValidCtxt(schema);
|
31
|
+
|
32
|
+
if (NULL == valid_ctxt) {
|
33
|
+
/* we have a problem */
|
34
|
+
rb_raise(rb_eRuntimeError, "Could not create a validation context");
|
35
|
+
}
|
36
|
+
|
37
|
+
#ifdef HAVE_XMLRELAXNGSETVALIDSTRUCTUREDERRORS
|
38
|
+
xmlRelaxNGSetValidStructuredErrors(
|
39
|
+
valid_ctxt,
|
40
|
+
Nokogiri_error_array_pusher,
|
41
|
+
(void *)errors
|
42
|
+
);
|
43
|
+
#endif
|
44
|
+
|
45
|
+
xmlRelaxNGValidateDoc(valid_ctxt, doc);
|
46
|
+
|
47
|
+
xmlRelaxNGFreeValidCtxt(valid_ctxt);
|
48
|
+
|
49
|
+
return errors;
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* read_memory(string)
|
55
|
+
*
|
56
|
+
* Create a new RelaxNG from the contents of +string+
|
57
|
+
*/
|
58
|
+
static VALUE
|
59
|
+
read_memory(int argc, VALUE *argv, VALUE klass)
|
60
|
+
{
|
61
|
+
VALUE content;
|
62
|
+
VALUE parse_options;
|
63
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
64
|
+
xmlRelaxNGPtr schema;
|
65
|
+
VALUE errors;
|
66
|
+
VALUE rb_schema;
|
67
|
+
int scanned_args = 0;
|
68
|
+
|
69
|
+
scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
70
|
+
if (scanned_args == 1) {
|
71
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
72
|
+
}
|
73
|
+
|
74
|
+
ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
75
|
+
|
76
|
+
errors = rb_ary_new();
|
77
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
78
|
+
|
79
|
+
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
80
|
+
xmlRelaxNGSetParserStructuredErrors(
|
81
|
+
ctx,
|
82
|
+
Nokogiri_error_array_pusher,
|
83
|
+
(void *)errors
|
84
|
+
);
|
85
|
+
#endif
|
86
|
+
|
87
|
+
schema = xmlRelaxNGParse(ctx);
|
88
|
+
|
89
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
90
|
+
xmlRelaxNGFreeParserCtxt(ctx);
|
91
|
+
|
92
|
+
if (NULL == schema) {
|
93
|
+
xmlErrorPtr error = xmlGetLastError();
|
94
|
+
if (error) {
|
95
|
+
Nokogiri_error_raise(NULL, error);
|
96
|
+
} else {
|
97
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
98
|
+
}
|
99
|
+
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
104
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
105
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
106
|
+
|
107
|
+
return rb_schema;
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* call-seq:
|
112
|
+
* from_document(doc)
|
113
|
+
*
|
114
|
+
* Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
|
115
|
+
*/
|
116
|
+
static VALUE
|
117
|
+
from_document(int argc, VALUE *argv, VALUE klass)
|
118
|
+
{
|
119
|
+
VALUE document;
|
120
|
+
VALUE parse_options;
|
121
|
+
xmlDocPtr doc;
|
122
|
+
xmlRelaxNGParserCtxtPtr ctx;
|
123
|
+
xmlRelaxNGPtr schema;
|
124
|
+
VALUE errors;
|
125
|
+
VALUE rb_schema;
|
126
|
+
int scanned_args = 0;
|
127
|
+
|
128
|
+
scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
129
|
+
|
130
|
+
Data_Get_Struct(document, xmlDoc, doc);
|
131
|
+
doc = doc->doc; /* In case someone passes us a node. ugh. */
|
132
|
+
|
133
|
+
if (scanned_args == 1) {
|
134
|
+
parse_options = rb_const_get_at(rb_const_get_at(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
135
|
+
}
|
136
|
+
|
137
|
+
ctx = xmlRelaxNGNewDocParserCtxt(doc);
|
138
|
+
|
139
|
+
errors = rb_ary_new();
|
140
|
+
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
141
|
+
|
142
|
+
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
143
|
+
xmlRelaxNGSetParserStructuredErrors(
|
144
|
+
ctx,
|
145
|
+
Nokogiri_error_array_pusher,
|
146
|
+
(void *)errors
|
147
|
+
);
|
148
|
+
#endif
|
149
|
+
|
150
|
+
schema = xmlRelaxNGParse(ctx);
|
151
|
+
|
152
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
153
|
+
xmlRelaxNGFreeParserCtxt(ctx);
|
154
|
+
|
155
|
+
if (NULL == schema) {
|
156
|
+
xmlErrorPtr error = xmlGetLastError();
|
157
|
+
if (error) {
|
158
|
+
Nokogiri_error_raise(NULL, error);
|
159
|
+
} else {
|
160
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
161
|
+
}
|
162
|
+
|
163
|
+
return Qnil;
|
164
|
+
}
|
165
|
+
|
166
|
+
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
167
|
+
rb_iv_set(rb_schema, "@errors", errors);
|
168
|
+
rb_iv_set(rb_schema, "@parse_options", parse_options);
|
169
|
+
|
170
|
+
return rb_schema;
|
171
|
+
}
|
172
|
+
|
173
|
+
void
|
174
|
+
noko_init_xml_relax_ng()
|
175
|
+
{
|
176
|
+
assert(cNokogiriXmlSchema);
|
177
|
+
cNokogiriXmlRelaxNG = rb_define_class_under(mNokogiriXml, "RelaxNG", cNokogiriXmlSchema);
|
178
|
+
|
179
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "read_memory", read_memory, -1);
|
180
|
+
rb_define_singleton_method(cNokogiriXmlRelaxNG, "from_document", from_document, -1);
|
181
|
+
|
182
|
+
rb_define_private_method(cNokogiriXmlRelaxNG, "validate_document", validate_document, 1);
|
183
|
+
}
|
@@ -0,0 +1,316 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlSaxParser ;
|
4
|
+
|
5
|
+
static ID id_start_document, id_end_document, id_start_element, id_end_element;
|
6
|
+
static ID id_start_element_namespace, id_end_element_namespace;
|
7
|
+
static ID id_comment, id_characters, id_xmldecl, id_error, id_warning;
|
8
|
+
static ID id_cdata_block;
|
9
|
+
static ID id_processing_instruction;
|
10
|
+
|
11
|
+
static void
|
12
|
+
start_document(void *ctx)
|
13
|
+
{
|
14
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
15
|
+
VALUE doc = rb_iv_get(self, "@document");
|
16
|
+
|
17
|
+
xmlParserCtxtPtr ctxt = NOKOGIRI_SAX_CTXT(ctx);
|
18
|
+
|
19
|
+
if (NULL != ctxt && ctxt->html != 1) {
|
20
|
+
if (ctxt->standalone != -1) { /* -1 means there was no declaration */
|
21
|
+
VALUE encoding = Qnil ;
|
22
|
+
VALUE standalone = Qnil;
|
23
|
+
VALUE version;
|
24
|
+
if (ctxt->encoding) {
|
25
|
+
encoding = NOKOGIRI_STR_NEW2(ctxt->encoding) ;
|
26
|
+
} else if (ctxt->input && ctxt->input->encoding) {
|
27
|
+
encoding = NOKOGIRI_STR_NEW2(ctxt->input->encoding) ;
|
28
|
+
}
|
29
|
+
|
30
|
+
version = ctxt->version ? NOKOGIRI_STR_NEW2(ctxt->version) : Qnil;
|
31
|
+
|
32
|
+
switch (ctxt->standalone) {
|
33
|
+
case 0:
|
34
|
+
standalone = NOKOGIRI_STR_NEW2("no");
|
35
|
+
break;
|
36
|
+
case 1:
|
37
|
+
standalone = NOKOGIRI_STR_NEW2("yes");
|
38
|
+
break;
|
39
|
+
}
|
40
|
+
|
41
|
+
rb_funcall(doc, id_xmldecl, 3, version, encoding, standalone);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
rb_funcall(doc, id_start_document, 0);
|
46
|
+
}
|
47
|
+
|
48
|
+
static void
|
49
|
+
end_document(void *ctx)
|
50
|
+
{
|
51
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
52
|
+
VALUE doc = rb_iv_get(self, "@document");
|
53
|
+
rb_funcall(doc, id_end_document, 0);
|
54
|
+
}
|
55
|
+
|
56
|
+
static void
|
57
|
+
start_element(void *ctx, const xmlChar *name, const xmlChar **atts)
|
58
|
+
{
|
59
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
60
|
+
VALUE doc = rb_iv_get(self, "@document");
|
61
|
+
VALUE attributes = rb_ary_new();
|
62
|
+
const xmlChar *attr;
|
63
|
+
int i = 0;
|
64
|
+
if (atts) {
|
65
|
+
while ((attr = atts[i]) != NULL) {
|
66
|
+
const xmlChar *val = atts[i + 1];
|
67
|
+
VALUE value = val != NULL ? NOKOGIRI_STR_NEW2(val) : Qnil;
|
68
|
+
rb_ary_push(attributes, rb_ary_new3(2, NOKOGIRI_STR_NEW2(attr), value));
|
69
|
+
i += 2;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
rb_funcall(doc,
|
74
|
+
id_start_element,
|
75
|
+
2,
|
76
|
+
NOKOGIRI_STR_NEW2(name),
|
77
|
+
attributes
|
78
|
+
);
|
79
|
+
}
|
80
|
+
|
81
|
+
static void
|
82
|
+
end_element(void *ctx, const xmlChar *name)
|
83
|
+
{
|
84
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
85
|
+
VALUE doc = rb_iv_get(self, "@document");
|
86
|
+
rb_funcall(doc, id_end_element, 1, NOKOGIRI_STR_NEW2(name));
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE
|
90
|
+
attributes_as_array(int attributes_len, const xmlChar **c_attributes)
|
91
|
+
{
|
92
|
+
VALUE rb_array = rb_ary_new2((long)attributes_len);
|
93
|
+
VALUE cNokogiriXmlSaxParserAttribute;
|
94
|
+
|
95
|
+
cNokogiriXmlSaxParserAttribute = rb_const_get_at(cNokogiriXmlSaxParser, rb_intern("Attribute"));
|
96
|
+
if (c_attributes) {
|
97
|
+
/* Each attribute is an array of [localname, prefix, URI, value, end] */
|
98
|
+
int i;
|
99
|
+
for (i = 0; i < attributes_len * 5; i += 5) {
|
100
|
+
VALUE rb_constructor_args[4], rb_attribute;
|
101
|
+
|
102
|
+
rb_constructor_args[0] = RBSTR_OR_QNIL(c_attributes[i + 0]); /* localname */
|
103
|
+
rb_constructor_args[1] = RBSTR_OR_QNIL(c_attributes[i + 1]); /* prefix */
|
104
|
+
rb_constructor_args[2] = RBSTR_OR_QNIL(c_attributes[i + 2]); /* URI */
|
105
|
+
|
106
|
+
/* value */
|
107
|
+
rb_constructor_args[3] = NOKOGIRI_STR_NEW((const char *)c_attributes[i + 3],
|
108
|
+
(c_attributes[i + 4] - c_attributes[i + 3]));
|
109
|
+
|
110
|
+
rb_attribute = rb_class_new_instance(4, rb_constructor_args, cNokogiriXmlSaxParserAttribute);
|
111
|
+
rb_ary_push(rb_array, rb_attribute);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
return rb_array;
|
116
|
+
}
|
117
|
+
|
118
|
+
static void
|
119
|
+
start_element_ns(
|
120
|
+
void *ctx,
|
121
|
+
const xmlChar *localname,
|
122
|
+
const xmlChar *prefix,
|
123
|
+
const xmlChar *uri,
|
124
|
+
int nb_namespaces,
|
125
|
+
const xmlChar **namespaces,
|
126
|
+
int nb_attributes,
|
127
|
+
int nb_defaulted,
|
128
|
+
const xmlChar **attributes)
|
129
|
+
{
|
130
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
131
|
+
VALUE doc = rb_iv_get(self, "@document");
|
132
|
+
|
133
|
+
VALUE attribute_ary = attributes_as_array(nb_attributes, attributes);
|
134
|
+
|
135
|
+
VALUE ns_list = rb_ary_new2((long)nb_namespaces);
|
136
|
+
|
137
|
+
if (namespaces) {
|
138
|
+
int i;
|
139
|
+
for (i = 0; i < nb_namespaces * 2; i += 2) {
|
140
|
+
rb_ary_push(ns_list,
|
141
|
+
rb_ary_new3((long)2,
|
142
|
+
RBSTR_OR_QNIL(namespaces[i + 0]),
|
143
|
+
RBSTR_OR_QNIL(namespaces[i + 1])
|
144
|
+
)
|
145
|
+
);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
rb_funcall(doc,
|
150
|
+
id_start_element_namespace,
|
151
|
+
5,
|
152
|
+
NOKOGIRI_STR_NEW2(localname),
|
153
|
+
attribute_ary,
|
154
|
+
RBSTR_OR_QNIL(prefix),
|
155
|
+
RBSTR_OR_QNIL(uri),
|
156
|
+
ns_list
|
157
|
+
);
|
158
|
+
}
|
159
|
+
|
160
|
+
/**
|
161
|
+
* end_element_ns was borrowed heavily from libxml-ruby.
|
162
|
+
*/
|
163
|
+
static void
|
164
|
+
end_element_ns(
|
165
|
+
void *ctx,
|
166
|
+
const xmlChar *localname,
|
167
|
+
const xmlChar *prefix,
|
168
|
+
const xmlChar *uri)
|
169
|
+
{
|
170
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
171
|
+
VALUE doc = rb_iv_get(self, "@document");
|
172
|
+
|
173
|
+
rb_funcall(doc, id_end_element_namespace, 3,
|
174
|
+
NOKOGIRI_STR_NEW2(localname),
|
175
|
+
RBSTR_OR_QNIL(prefix),
|
176
|
+
RBSTR_OR_QNIL(uri)
|
177
|
+
);
|
178
|
+
}
|
179
|
+
|
180
|
+
static void
|
181
|
+
characters_func(void *ctx, const xmlChar *ch, int len)
|
182
|
+
{
|
183
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
184
|
+
VALUE doc = rb_iv_get(self, "@document");
|
185
|
+
VALUE str = NOKOGIRI_STR_NEW(ch, len);
|
186
|
+
rb_funcall(doc, id_characters, 1, str);
|
187
|
+
}
|
188
|
+
|
189
|
+
static void
|
190
|
+
comment_func(void *ctx, const xmlChar *value)
|
191
|
+
{
|
192
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
193
|
+
VALUE doc = rb_iv_get(self, "@document");
|
194
|
+
VALUE str = NOKOGIRI_STR_NEW2(value);
|
195
|
+
rb_funcall(doc, id_comment, 1, str);
|
196
|
+
}
|
197
|
+
|
198
|
+
PRINTFLIKE_DECL(2, 3)
|
199
|
+
static void
|
200
|
+
warning_func(void *ctx, const char *msg, ...)
|
201
|
+
{
|
202
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
203
|
+
VALUE doc = rb_iv_get(self, "@document");
|
204
|
+
VALUE rb_message;
|
205
|
+
|
206
|
+
#ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
|
207
|
+
/* It is not currently possible to pass var args from native
|
208
|
+
functions to sulong, so we work around the issue here. */
|
209
|
+
rb_message = rb_sprintf("warning_func: %s", msg);
|
210
|
+
#else
|
211
|
+
va_list args;
|
212
|
+
va_start(args, msg);
|
213
|
+
rb_message = rb_vsprintf(msg, args);
|
214
|
+
va_end(args);
|
215
|
+
#endif
|
216
|
+
|
217
|
+
rb_funcall(doc, id_warning, 1, rb_message);
|
218
|
+
}
|
219
|
+
|
220
|
+
PRINTFLIKE_DECL(2, 3)
|
221
|
+
static void
|
222
|
+
error_func(void *ctx, const char *msg, ...)
|
223
|
+
{
|
224
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
225
|
+
VALUE doc = rb_iv_get(self, "@document");
|
226
|
+
VALUE rb_message;
|
227
|
+
|
228
|
+
#ifdef TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
|
229
|
+
/* It is not currently possible to pass var args from native
|
230
|
+
functions to sulong, so we work around the issue here. */
|
231
|
+
rb_message = rb_sprintf("error_func: %s", msg);
|
232
|
+
#else
|
233
|
+
va_list args;
|
234
|
+
va_start(args, msg);
|
235
|
+
rb_message = rb_vsprintf(msg, args);
|
236
|
+
va_end(args);
|
237
|
+
#endif
|
238
|
+
|
239
|
+
rb_funcall(doc, id_error, 1, rb_message);
|
240
|
+
}
|
241
|
+
|
242
|
+
static void
|
243
|
+
cdata_block(void *ctx, const xmlChar *value, int len)
|
244
|
+
{
|
245
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
246
|
+
VALUE doc = rb_iv_get(self, "@document");
|
247
|
+
VALUE string = NOKOGIRI_STR_NEW(value, len);
|
248
|
+
rb_funcall(doc, id_cdata_block, 1, string);
|
249
|
+
}
|
250
|
+
|
251
|
+
static void
|
252
|
+
processing_instruction(void *ctx, const xmlChar *name, const xmlChar *content)
|
253
|
+
{
|
254
|
+
VALUE rb_content;
|
255
|
+
VALUE self = NOKOGIRI_SAX_SELF(ctx);
|
256
|
+
VALUE doc = rb_iv_get(self, "@document");
|
257
|
+
|
258
|
+
rb_content = content ? NOKOGIRI_STR_NEW2(content) : Qnil;
|
259
|
+
|
260
|
+
rb_funcall(doc,
|
261
|
+
id_processing_instruction,
|
262
|
+
2,
|
263
|
+
NOKOGIRI_STR_NEW2(name),
|
264
|
+
rb_content
|
265
|
+
);
|
266
|
+
}
|
267
|
+
|
268
|
+
static void
|
269
|
+
deallocate(xmlSAXHandlerPtr handler)
|
270
|
+
{
|
271
|
+
ruby_xfree(handler);
|
272
|
+
}
|
273
|
+
|
274
|
+
static VALUE
|
275
|
+
allocate(VALUE klass)
|
276
|
+
{
|
277
|
+
xmlSAXHandlerPtr handler = ruby_xcalloc((size_t)1, sizeof(xmlSAXHandler));
|
278
|
+
|
279
|
+
handler->startDocument = start_document;
|
280
|
+
handler->endDocument = end_document;
|
281
|
+
handler->startElement = start_element;
|
282
|
+
handler->endElement = end_element;
|
283
|
+
handler->startElementNs = start_element_ns;
|
284
|
+
handler->endElementNs = end_element_ns;
|
285
|
+
handler->characters = characters_func;
|
286
|
+
handler->comment = comment_func;
|
287
|
+
handler->warning = warning_func;
|
288
|
+
handler->error = error_func;
|
289
|
+
handler->cdataBlock = cdata_block;
|
290
|
+
handler->processingInstruction = processing_instruction;
|
291
|
+
handler->initialized = XML_SAX2_MAGIC;
|
292
|
+
|
293
|
+
return Data_Wrap_Struct(klass, NULL, deallocate, handler);
|
294
|
+
}
|
295
|
+
|
296
|
+
void
|
297
|
+
noko_init_xml_sax_parser()
|
298
|
+
{
|
299
|
+
cNokogiriXmlSaxParser = rb_define_class_under(mNokogiriXmlSax, "Parser", rb_cObject);
|
300
|
+
|
301
|
+
rb_define_alloc_func(cNokogiriXmlSaxParser, allocate);
|
302
|
+
|
303
|
+
id_start_document = rb_intern("start_document");
|
304
|
+
id_end_document = rb_intern("end_document");
|
305
|
+
id_start_element = rb_intern("start_element");
|
306
|
+
id_end_element = rb_intern("end_element");
|
307
|
+
id_comment = rb_intern("comment");
|
308
|
+
id_characters = rb_intern("characters");
|
309
|
+
id_xmldecl = rb_intern("xmldecl");
|
310
|
+
id_error = rb_intern("error");
|
311
|
+
id_warning = rb_intern("warning");
|
312
|
+
id_cdata_block = rb_intern("cdata_block");
|
313
|
+
id_start_element_namespace = rb_intern("start_element_namespace");
|
314
|
+
id_end_element_namespace = rb_intern("end_element_namespace");
|
315
|
+
id_processing_instruction = rb_intern("processing_instruction");
|
316
|
+
}
|