nokogiri 1.13.0-x64-mingw-ucrt
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/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 +536 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
#ifndef HAVE_XMLFIRSTELEMENTCHILD
|
2
|
+
#include <nokogiri.h>
|
3
|
+
/**
|
4
|
+
* xmlFirstElementChild:
|
5
|
+
* @parent: the parent node
|
6
|
+
*
|
7
|
+
* Finds the first child node of that element which is a Element node
|
8
|
+
* Note the handling of entities references is different than in
|
9
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
10
|
+
* from entities content to entities references.
|
11
|
+
*
|
12
|
+
* Returns the first element child or NULL if not available
|
13
|
+
*/
|
14
|
+
xmlNodePtr
|
15
|
+
xmlFirstElementChild(xmlNodePtr parent)
|
16
|
+
{
|
17
|
+
xmlNodePtr cur = NULL;
|
18
|
+
|
19
|
+
if (parent == NULL) {
|
20
|
+
return (NULL);
|
21
|
+
}
|
22
|
+
switch (parent->type) {
|
23
|
+
case XML_ELEMENT_NODE:
|
24
|
+
case XML_ENTITY_NODE:
|
25
|
+
case XML_DOCUMENT_NODE:
|
26
|
+
case XML_HTML_DOCUMENT_NODE:
|
27
|
+
cur = parent->children;
|
28
|
+
break;
|
29
|
+
default:
|
30
|
+
return (NULL);
|
31
|
+
}
|
32
|
+
while (cur != NULL) {
|
33
|
+
if (cur->type == XML_ELEMENT_NODE) {
|
34
|
+
return (cur);
|
35
|
+
}
|
36
|
+
cur = cur->next;
|
37
|
+
}
|
38
|
+
return (NULL);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* xmlNextElementSibling:
|
43
|
+
* @node: the current node
|
44
|
+
*
|
45
|
+
* Finds the first closest next sibling of the node which is an
|
46
|
+
* element node.
|
47
|
+
* Note the handling of entities references is different than in
|
48
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
49
|
+
* from entities content to entities references.
|
50
|
+
*
|
51
|
+
* Returns the next element sibling or NULL if not available
|
52
|
+
*/
|
53
|
+
xmlNodePtr
|
54
|
+
xmlNextElementSibling(xmlNodePtr node)
|
55
|
+
{
|
56
|
+
if (node == NULL) {
|
57
|
+
return (NULL);
|
58
|
+
}
|
59
|
+
switch (node->type) {
|
60
|
+
case XML_ELEMENT_NODE:
|
61
|
+
case XML_TEXT_NODE:
|
62
|
+
case XML_CDATA_SECTION_NODE:
|
63
|
+
case XML_ENTITY_REF_NODE:
|
64
|
+
case XML_ENTITY_NODE:
|
65
|
+
case XML_PI_NODE:
|
66
|
+
case XML_COMMENT_NODE:
|
67
|
+
case XML_DTD_NODE:
|
68
|
+
case XML_XINCLUDE_START:
|
69
|
+
case XML_XINCLUDE_END:
|
70
|
+
node = node->next;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
return (NULL);
|
74
|
+
}
|
75
|
+
while (node != NULL) {
|
76
|
+
if (node->type == XML_ELEMENT_NODE) {
|
77
|
+
return (node);
|
78
|
+
}
|
79
|
+
node = node->next;
|
80
|
+
}
|
81
|
+
return (NULL);
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* xmlLastElementChild:
|
86
|
+
* @parent: the parent node
|
87
|
+
*
|
88
|
+
* Finds the last child node of that element which is a Element node
|
89
|
+
* Note the handling of entities references is different than in
|
90
|
+
* the W3C DOM element traversal spec since we don't have back reference
|
91
|
+
* from entities content to entities references.
|
92
|
+
*
|
93
|
+
* Returns the last element child or NULL if not available
|
94
|
+
*/
|
95
|
+
xmlNodePtr
|
96
|
+
xmlLastElementChild(xmlNodePtr parent)
|
97
|
+
{
|
98
|
+
xmlNodePtr cur = NULL;
|
99
|
+
|
100
|
+
if (parent == NULL) {
|
101
|
+
return (NULL);
|
102
|
+
}
|
103
|
+
switch (parent->type) {
|
104
|
+
case XML_ELEMENT_NODE:
|
105
|
+
case XML_ENTITY_NODE:
|
106
|
+
case XML_DOCUMENT_NODE:
|
107
|
+
case XML_HTML_DOCUMENT_NODE:
|
108
|
+
cur = parent->last;
|
109
|
+
break;
|
110
|
+
default:
|
111
|
+
return (NULL);
|
112
|
+
}
|
113
|
+
while (cur != NULL) {
|
114
|
+
if (cur->type == XML_ELEMENT_NODE) {
|
115
|
+
return (cur);
|
116
|
+
}
|
117
|
+
cur = cur->prev;
|
118
|
+
}
|
119
|
+
return (NULL);
|
120
|
+
}
|
121
|
+
#endif
|
@@ -0,0 +1,278 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE mNokogiri ;
|
4
|
+
VALUE mNokogiriGumbo ;
|
5
|
+
VALUE mNokogiriHtml4 ;
|
6
|
+
VALUE mNokogiriHtml4Sax ;
|
7
|
+
VALUE mNokogiriHtml5 ;
|
8
|
+
VALUE mNokogiriXml ;
|
9
|
+
VALUE mNokogiriXmlSax ;
|
10
|
+
VALUE mNokogiriXmlXpath ;
|
11
|
+
VALUE mNokogiriXslt ;
|
12
|
+
|
13
|
+
VALUE cNokogiriSyntaxError;
|
14
|
+
VALUE cNokogiriXmlCharacterData;
|
15
|
+
VALUE cNokogiriXmlElement;
|
16
|
+
VALUE cNokogiriXmlXpathSyntaxError;
|
17
|
+
|
18
|
+
void noko_init_xml_attr(void);
|
19
|
+
void noko_init_xml_attribute_decl(void);
|
20
|
+
void noko_init_xml_cdata(void);
|
21
|
+
void noko_init_xml_comment(void);
|
22
|
+
void noko_init_xml_document(void);
|
23
|
+
void noko_init_xml_document_fragment(void);
|
24
|
+
void noko_init_xml_dtd(void);
|
25
|
+
void noko_init_xml_element_content(void);
|
26
|
+
void noko_init_xml_element_decl(void);
|
27
|
+
void noko_init_xml_encoding_handler(void);
|
28
|
+
void noko_init_xml_entity_decl(void);
|
29
|
+
void noko_init_xml_entity_reference(void);
|
30
|
+
void noko_init_xml_namespace(void);
|
31
|
+
void noko_init_xml_node(void);
|
32
|
+
void noko_init_xml_node_set(void);
|
33
|
+
void noko_init_xml_processing_instruction(void);
|
34
|
+
void noko_init_xml_reader(void);
|
35
|
+
void noko_init_xml_relax_ng(void);
|
36
|
+
void noko_init_xml_sax_parser(void);
|
37
|
+
void noko_init_xml_sax_parser_context(void);
|
38
|
+
void noko_init_xml_sax_push_parser(void);
|
39
|
+
void noko_init_xml_schema(void);
|
40
|
+
void noko_init_xml_syntax_error(void);
|
41
|
+
void noko_init_xml_text(void);
|
42
|
+
void noko_init_xml_xpath_context(void);
|
43
|
+
void noko_init_xslt_stylesheet(void);
|
44
|
+
void noko_init_html_document(void);
|
45
|
+
void noko_init_html_element_description(void);
|
46
|
+
void noko_init_html_entity_lookup(void);
|
47
|
+
void noko_init_html_sax_parser_context(void);
|
48
|
+
void noko_init_html_sax_push_parser(void);
|
49
|
+
void noko_init_gumbo(void);
|
50
|
+
void noko_init_test_global_handlers(void);
|
51
|
+
|
52
|
+
static ID id_read, id_write;
|
53
|
+
|
54
|
+
|
55
|
+
#ifndef HAVE_VASPRINTF
|
56
|
+
/*
|
57
|
+
* Thank you Geoffroy Couprie for this implementation of vasprintf!
|
58
|
+
*/
|
59
|
+
int
|
60
|
+
vasprintf(char **strp, const char *fmt, va_list ap)
|
61
|
+
{
|
62
|
+
/* Mingw32/64 have a broken vsnprintf implementation that fails when
|
63
|
+
* using a zero-byte limit in order to retrieve the required size for malloc.
|
64
|
+
* So we use a one byte buffer instead.
|
65
|
+
*/
|
66
|
+
char tmp[1];
|
67
|
+
int len = vsnprintf(tmp, 1, fmt, ap) + 1;
|
68
|
+
char *res = (char *)malloc((unsigned int)len);
|
69
|
+
if (res == NULL) {
|
70
|
+
return -1;
|
71
|
+
}
|
72
|
+
*strp = res;
|
73
|
+
return vsnprintf(res, (unsigned int)len, fmt, ap);
|
74
|
+
}
|
75
|
+
#endif
|
76
|
+
|
77
|
+
|
78
|
+
static VALUE
|
79
|
+
read_check(VALUE val)
|
80
|
+
{
|
81
|
+
VALUE *args = (VALUE *)val;
|
82
|
+
return rb_funcall(args[0], id_read, 1, args[1]);
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
read_failed(VALUE arg, VALUE exc)
|
88
|
+
{
|
89
|
+
return Qundef;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
int
|
94
|
+
noko_io_read(void *ctx, char *buffer, int len)
|
95
|
+
{
|
96
|
+
VALUE string, args[2];
|
97
|
+
size_t str_len, safe_len;
|
98
|
+
|
99
|
+
args[0] = (VALUE)ctx;
|
100
|
+
args[1] = INT2NUM(len);
|
101
|
+
|
102
|
+
string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
|
103
|
+
|
104
|
+
if (NIL_P(string)) { return 0; }
|
105
|
+
if (string == Qundef) { return -1; }
|
106
|
+
if (TYPE(string) != T_STRING) { return -1; }
|
107
|
+
|
108
|
+
str_len = (size_t)RSTRING_LEN(string);
|
109
|
+
safe_len = str_len > (size_t)len ? (size_t)len : str_len;
|
110
|
+
memcpy(buffer, StringValuePtr(string), safe_len);
|
111
|
+
|
112
|
+
return (int)safe_len;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
write_check(VALUE val)
|
118
|
+
{
|
119
|
+
VALUE *args = (VALUE *)val;
|
120
|
+
return rb_funcall(args[0], id_write, 1, args[1]);
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
static VALUE
|
125
|
+
write_failed(VALUE arg, VALUE exc)
|
126
|
+
{
|
127
|
+
return Qundef;
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
int
|
132
|
+
noko_io_write(void *ctx, char *buffer, int len)
|
133
|
+
{
|
134
|
+
VALUE args[2], size;
|
135
|
+
|
136
|
+
args[0] = (VALUE)ctx;
|
137
|
+
args[1] = rb_str_new(buffer, (long)len);
|
138
|
+
|
139
|
+
size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
|
140
|
+
|
141
|
+
if (size == Qundef) { return -1; }
|
142
|
+
|
143
|
+
return NUM2INT(size);
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
int
|
148
|
+
noko_io_close(void *ctx)
|
149
|
+
{
|
150
|
+
return 0;
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
void
|
155
|
+
Init_nokogiri()
|
156
|
+
{
|
157
|
+
mNokogiri = rb_define_module("Nokogiri");
|
158
|
+
mNokogiriGumbo = rb_define_module_under(mNokogiri, "Gumbo");
|
159
|
+
mNokogiriHtml4 = rb_define_module_under(mNokogiri, "HTML4");
|
160
|
+
mNokogiriHtml4Sax = rb_define_module_under(mNokogiriHtml4, "SAX");
|
161
|
+
mNokogiriHtml5 = rb_define_module_under(mNokogiri, "HTML5");
|
162
|
+
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
|
163
|
+
mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
|
164
|
+
mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
|
165
|
+
mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
|
166
|
+
|
167
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
|
168
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
|
169
|
+
|
170
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
|
171
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
|
172
|
+
|
173
|
+
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
|
174
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
|
175
|
+
# ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
176
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
|
177
|
+
# else
|
178
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
179
|
+
# endif
|
180
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
|
181
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
|
182
|
+
#else
|
183
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
|
184
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
185
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
|
186
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
|
187
|
+
#endif
|
188
|
+
|
189
|
+
#ifdef LIBXML_ICONV_ENABLED
|
190
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qtrue);
|
191
|
+
#else
|
192
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
|
193
|
+
#endif
|
194
|
+
|
195
|
+
#ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
|
196
|
+
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
|
197
|
+
#endif
|
198
|
+
|
199
|
+
#if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
200
|
+
/*
|
201
|
+
* We choose *not* to do use Ruby's memory management functions with windows DLLs because of this
|
202
|
+
* issue in libxml 2.9.12:
|
203
|
+
*
|
204
|
+
* https://github.com/sparklemotion/nokogiri/issues/2241
|
205
|
+
*
|
206
|
+
* If the atexit() issue gets fixed in a future version of libxml2, then we may be able to skip
|
207
|
+
* this config only for the specific libxml2 versions 2.9.12.
|
208
|
+
*
|
209
|
+
* Alternatively, now that Ruby has a generational GC, it might be OK to let libxml2 use its
|
210
|
+
* default memory management functions (recall that this config was introduced to reduce memory
|
211
|
+
* bloat and allow Ruby to GC more often); but we should *really* test with production workloads
|
212
|
+
* before making that kind of a potentially-invasive change.
|
213
|
+
*/
|
214
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
|
215
|
+
#else
|
216
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
|
217
|
+
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
|
218
|
+
#endif
|
219
|
+
|
220
|
+
xmlInitParser();
|
221
|
+
exsltRegisterAll();
|
222
|
+
|
223
|
+
if (xsltExtModuleFunctionLookup((const xmlChar *)"date-time", EXSLT_DATE_NAMESPACE)) {
|
224
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue);
|
225
|
+
} else {
|
226
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qfalse);
|
227
|
+
}
|
228
|
+
|
229
|
+
cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
|
230
|
+
noko_init_xml_syntax_error();
|
231
|
+
assert(cNokogiriXmlSyntaxError);
|
232
|
+
cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
|
233
|
+
|
234
|
+
noko_init_xml_element_content();
|
235
|
+
noko_init_xml_encoding_handler();
|
236
|
+
noko_init_xml_namespace();
|
237
|
+
noko_init_xml_node_set();
|
238
|
+
noko_init_xml_reader();
|
239
|
+
noko_init_xml_sax_parser();
|
240
|
+
noko_init_xml_xpath_context();
|
241
|
+
noko_init_xslt_stylesheet();
|
242
|
+
noko_init_html_element_description();
|
243
|
+
noko_init_html_entity_lookup();
|
244
|
+
|
245
|
+
noko_init_xml_schema();
|
246
|
+
noko_init_xml_relax_ng();
|
247
|
+
|
248
|
+
noko_init_xml_sax_parser_context();
|
249
|
+
noko_init_html_sax_parser_context();
|
250
|
+
|
251
|
+
noko_init_xml_sax_push_parser();
|
252
|
+
noko_init_html_sax_push_parser();
|
253
|
+
|
254
|
+
noko_init_xml_node();
|
255
|
+
noko_init_xml_attr();
|
256
|
+
noko_init_xml_attribute_decl();
|
257
|
+
noko_init_xml_dtd();
|
258
|
+
noko_init_xml_element_decl();
|
259
|
+
noko_init_xml_entity_decl();
|
260
|
+
noko_init_xml_entity_reference();
|
261
|
+
noko_init_xml_processing_instruction();
|
262
|
+
assert(cNokogiriXmlNode);
|
263
|
+
cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
|
264
|
+
cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
|
265
|
+
noko_init_xml_comment();
|
266
|
+
noko_init_xml_text();
|
267
|
+
noko_init_xml_cdata();
|
268
|
+
|
269
|
+
noko_init_xml_document_fragment();
|
270
|
+
noko_init_xml_document();
|
271
|
+
noko_init_html_document();
|
272
|
+
noko_init_gumbo();
|
273
|
+
|
274
|
+
noko_init_test_global_handlers();
|
275
|
+
|
276
|
+
id_read = rb_intern("read");
|
277
|
+
id_write = rb_intern("write");
|
278
|
+
}
|
@@ -0,0 +1,223 @@
|
|
1
|
+
#ifndef NOKOGIRI_NATIVE
|
2
|
+
#define NOKOGIRI_NATIVE
|
3
|
+
|
4
|
+
#ifdef _MSC_VER
|
5
|
+
# ifndef WIN32_LEAN_AND_MEAN
|
6
|
+
# define WIN32_LEAN_AND_MEAN
|
7
|
+
# endif /* WIN32_LEAN_AND_MEAN */
|
8
|
+
|
9
|
+
# ifndef WIN32
|
10
|
+
# define WIN32
|
11
|
+
# endif /* WIN32 */
|
12
|
+
|
13
|
+
# include <winsock2.h>
|
14
|
+
# include <ws2tcpip.h>
|
15
|
+
# include <windows.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#ifdef _WIN32
|
19
|
+
# define NOKOPUBFUN __declspec(dllexport)
|
20
|
+
# define NOKOPUBVAR __declspec(dllexport) extern
|
21
|
+
#else
|
22
|
+
# define NOKOPUBFUN
|
23
|
+
# define NOKOPUBVAR extern
|
24
|
+
#endif
|
25
|
+
|
26
|
+
|
27
|
+
#include <stdlib.h>
|
28
|
+
#include <string.h>
|
29
|
+
#include <assert.h>
|
30
|
+
#include <stdarg.h>
|
31
|
+
#include <stdio.h>
|
32
|
+
|
33
|
+
|
34
|
+
#include <libxml/parser.h>
|
35
|
+
#include <libxml/tree.h>
|
36
|
+
#include <libxml/entities.h>
|
37
|
+
#include <libxml/xpath.h>
|
38
|
+
#include <libxml/xmlreader.h>
|
39
|
+
#include <libxml/xmlsave.h>
|
40
|
+
#include <libxml/xmlschemas.h>
|
41
|
+
#include <libxml/HTMLparser.h>
|
42
|
+
#include <libxml/HTMLtree.h>
|
43
|
+
#include <libxml/relaxng.h>
|
44
|
+
#include <libxml/xinclude.h>
|
45
|
+
#include <libxml/c14n.h>
|
46
|
+
#include <libxml/parserInternals.h>
|
47
|
+
#include <libxml/xpathInternals.h>
|
48
|
+
|
49
|
+
#include <libxslt/extensions.h>
|
50
|
+
#include <libxslt/xsltconfig.h>
|
51
|
+
#include <libxslt/xsltutils.h>
|
52
|
+
#include <libxslt/transform.h>
|
53
|
+
#include <libxslt/xsltInternals.h>
|
54
|
+
|
55
|
+
#include <libexslt/exslt.h>
|
56
|
+
|
57
|
+
/* libxml2_backwards_compat.c */
|
58
|
+
#ifndef HAVE_XMLFIRSTELEMENTCHILD
|
59
|
+
xmlNodePtr xmlFirstElementChild(xmlNodePtr parent);
|
60
|
+
xmlNodePtr xmlNextElementSibling(xmlNodePtr node);
|
61
|
+
xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
|
62
|
+
#endif
|
63
|
+
|
64
|
+
#define XMLNS_PREFIX "xmlns"
|
65
|
+
#define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
|
66
|
+
|
67
|
+
|
68
|
+
#include <ruby.h>
|
69
|
+
#include <ruby/st.h>
|
70
|
+
#include <ruby/encoding.h>
|
71
|
+
#include <ruby/util.h>
|
72
|
+
#include <ruby/version.h>
|
73
|
+
|
74
|
+
#define NOKOGIRI_STR_NEW2(str) NOKOGIRI_STR_NEW(str, strlen((const char *)(str)))
|
75
|
+
#define NOKOGIRI_STR_NEW(str, len) rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
|
76
|
+
#define RBSTR_OR_QNIL(_str) (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
77
|
+
|
78
|
+
#ifdef DEBUG
|
79
|
+
# define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
|
80
|
+
# define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
|
81
|
+
#else
|
82
|
+
# define NOKOGIRI_DEBUG_START(p)
|
83
|
+
# define NOKOGIRI_DEBUG_END(p)
|
84
|
+
#endif
|
85
|
+
|
86
|
+
#ifndef NORETURN
|
87
|
+
# if defined(__GNUC__)
|
88
|
+
# define NORETURN(name) __attribute__((noreturn)) name
|
89
|
+
# else
|
90
|
+
# define NORETURN(name) name
|
91
|
+
# endif
|
92
|
+
#endif
|
93
|
+
|
94
|
+
|
95
|
+
NOKOPUBVAR VALUE mNokogiri ;
|
96
|
+
NOKOPUBVAR VALUE mNokogiriGumbo ;
|
97
|
+
NOKOPUBVAR VALUE mNokogiriHtml4 ;
|
98
|
+
NOKOPUBVAR VALUE mNokogiriHtml4Sax ;
|
99
|
+
NOKOPUBVAR VALUE mNokogiriHtml5 ;
|
100
|
+
NOKOPUBVAR VALUE mNokogiriXml ;
|
101
|
+
NOKOPUBVAR VALUE mNokogiriXmlSax ;
|
102
|
+
NOKOPUBVAR VALUE mNokogiriXmlXpath ;
|
103
|
+
NOKOPUBVAR VALUE mNokogiriXslt ;
|
104
|
+
|
105
|
+
NOKOPUBVAR VALUE cNokogiriEncodingHandler;
|
106
|
+
NOKOPUBVAR VALUE cNokogiriSyntaxError;
|
107
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttr;
|
108
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttributeDecl;
|
109
|
+
NOKOPUBVAR VALUE cNokogiriXmlCData;
|
110
|
+
NOKOPUBVAR VALUE cNokogiriXmlCharacterData;
|
111
|
+
NOKOPUBVAR VALUE cNokogiriXmlComment;
|
112
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocument ;
|
113
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocumentFragment;
|
114
|
+
NOKOPUBVAR VALUE cNokogiriXmlDtd;
|
115
|
+
NOKOPUBVAR VALUE cNokogiriXmlElement ;
|
116
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementContent;
|
117
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementDecl;
|
118
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityDecl;
|
119
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityReference;
|
120
|
+
NOKOPUBVAR VALUE cNokogiriXmlNamespace ;
|
121
|
+
NOKOPUBVAR VALUE cNokogiriXmlNode ;
|
122
|
+
NOKOPUBVAR VALUE cNokogiriXmlNodeSet ;
|
123
|
+
NOKOPUBVAR VALUE cNokogiriXmlProcessingInstruction;
|
124
|
+
NOKOPUBVAR VALUE cNokogiriXmlReader;
|
125
|
+
NOKOPUBVAR VALUE cNokogiriXmlRelaxNG;
|
126
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParser ;
|
127
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParserContext;
|
128
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxPushParser ;
|
129
|
+
NOKOPUBVAR VALUE cNokogiriXmlSchema;
|
130
|
+
NOKOPUBVAR VALUE cNokogiriXmlSyntaxError;
|
131
|
+
NOKOPUBVAR VALUE cNokogiriXmlText ;
|
132
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathContext;
|
133
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathSyntaxError;
|
134
|
+
NOKOPUBVAR VALUE cNokogiriXsltStylesheet ;
|
135
|
+
|
136
|
+
NOKOPUBVAR VALUE cNokogiriHtml4Document ;
|
137
|
+
NOKOPUBVAR VALUE cNokogiriHtml4SaxPushParser ;
|
138
|
+
NOKOPUBVAR VALUE cNokogiriHtml4ElementDescription ;
|
139
|
+
NOKOPUBVAR VALUE cNokogiriHtml4SaxParserContext;
|
140
|
+
NOKOPUBVAR VALUE cNokogiriHtml5Document ;
|
141
|
+
|
142
|
+
typedef struct _nokogiriTuple {
|
143
|
+
VALUE doc;
|
144
|
+
st_table *unlinkedNodes;
|
145
|
+
VALUE node_cache;
|
146
|
+
} nokogiriTuple;
|
147
|
+
typedef nokogiriTuple *nokogiriTuplePtr;
|
148
|
+
|
149
|
+
typedef struct _nokogiriSAXTuple {
|
150
|
+
xmlParserCtxtPtr ctxt;
|
151
|
+
VALUE self;
|
152
|
+
} nokogiriSAXTuple;
|
153
|
+
typedef nokogiriSAXTuple *nokogiriSAXTuplePtr;
|
154
|
+
|
155
|
+
typedef struct _libxmlStructuredErrorHandlerState {
|
156
|
+
void *user_data;
|
157
|
+
xmlStructuredErrorFunc handler;
|
158
|
+
} libxmlStructuredErrorHandlerState ;
|
159
|
+
|
160
|
+
typedef struct _nokogiriXsltStylesheetTuple {
|
161
|
+
xsltStylesheetPtr ss;
|
162
|
+
VALUE func_instances;
|
163
|
+
} nokogiriXsltStylesheetTuple;
|
164
|
+
|
165
|
+
int vasprintf(char **strp, const char *fmt, va_list ap);
|
166
|
+
void noko_xml_document_pin_node(xmlNodePtr);
|
167
|
+
void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
|
168
|
+
|
169
|
+
int noko_io_read(void *ctx, char *buffer, int len);
|
170
|
+
int noko_io_write(void *ctx, char *buffer, int len);
|
171
|
+
int noko_io_close(void *ctx);
|
172
|
+
|
173
|
+
VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
|
174
|
+
VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
|
175
|
+
VALUE noko_xml_node_attrs(xmlNodePtr node) ;
|
176
|
+
|
177
|
+
VALUE noko_xml_namespace_wrap(xmlNsPtr node, xmlDocPtr doc);
|
178
|
+
VALUE noko_xml_namespace_wrap_xpath_copy(xmlNsPtr node);
|
179
|
+
|
180
|
+
VALUE noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element);
|
181
|
+
|
182
|
+
VALUE noko_xml_node_set_wrap(xmlNodeSetPtr node_set, VALUE document) ;
|
183
|
+
|
184
|
+
VALUE noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr doc, int argc, VALUE *argv);
|
185
|
+
VALUE noko_xml_document_wrap(VALUE klass, xmlDocPtr doc);
|
186
|
+
NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
|
187
|
+
xmlDocPtr doc); /* deprecated. use noko_xml_document_wrap() instead. */
|
188
|
+
|
189
|
+
#define DOC_RUBY_OBJECT_TEST(x) ((nokogiriTuplePtr)(x->_private))
|
190
|
+
#define DOC_RUBY_OBJECT(x) (((nokogiriTuplePtr)(x->_private))->doc)
|
191
|
+
#define DOC_UNLINKED_NODE_HASH(x) (((nokogiriTuplePtr)(x->_private))->unlinkedNodes)
|
192
|
+
#define DOC_NODE_CACHE(x) (((nokogiriTuplePtr)(x->_private))->node_cache)
|
193
|
+
#define NOKOGIRI_NAMESPACE_EH(node) ((node)->type == XML_NAMESPACE_DECL)
|
194
|
+
|
195
|
+
#define NOKOGIRI_SAX_SELF(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->self
|
196
|
+
#define NOKOGIRI_SAX_CTXT(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->ctxt
|
197
|
+
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) nokogiri_sax_tuple_new(_ctxt, _self)
|
198
|
+
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) free(_tuple)
|
199
|
+
|
200
|
+
#define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
|
201
|
+
#define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
|
202
|
+
|
203
|
+
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
204
|
+
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
|
205
|
+
xmlStructuredErrorFunc handler);
|
206
|
+
void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
|
207
|
+
VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
|
208
|
+
void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
|
209
|
+
NORETURN(void Nokogiri_error_raise(void *ctx, xmlErrorPtr error));
|
210
|
+
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
211
|
+
const char *function_name) ;
|
212
|
+
|
213
|
+
static inline
|
214
|
+
nokogiriSAXTuplePtr
|
215
|
+
nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
|
216
|
+
{
|
217
|
+
nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
|
218
|
+
tuple->self = self;
|
219
|
+
tuple->ctxt = ctxt;
|
220
|
+
return tuple;
|
221
|
+
}
|
222
|
+
|
223
|
+
#endif /* NOKOGIRI_NATIVE */
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
static VALUE foreign_error_handler_block = Qnil;
|
4
|
+
|
5
|
+
static void
|
6
|
+
foreign_error_handler(void *user_data, xmlErrorPtr c_error)
|
7
|
+
{
|
8
|
+
rb_funcall(foreign_error_handler_block, rb_intern("call"), 0);
|
9
|
+
}
|
10
|
+
|
11
|
+
/*
|
12
|
+
* call-seq:
|
13
|
+
* __foreign_error_handler { ... } -> nil
|
14
|
+
*
|
15
|
+
* Override libxml2's global error handlers to call the block. This method thus has very little
|
16
|
+
* value except to test that Nokogiri is properly setting error handlers elsewhere in the code. See
|
17
|
+
* test/helper.rb for how this is being used.
|
18
|
+
*/
|
19
|
+
static VALUE
|
20
|
+
rb_foreign_error_handler(VALUE klass)
|
21
|
+
{
|
22
|
+
rb_need_block();
|
23
|
+
foreign_error_handler_block = rb_block_proc();
|
24
|
+
xmlSetStructuredErrorFunc(NULL, foreign_error_handler);
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Document-module: Nokogiri::Test
|
30
|
+
*
|
31
|
+
* The Nokogiri::Test module should only be used for testing Nokogiri.
|
32
|
+
* Do NOT use this outside of the Nokogiri test suite.
|
33
|
+
*/
|
34
|
+
void
|
35
|
+
noko_init_test_global_handlers()
|
36
|
+
{
|
37
|
+
VALUE mNokogiriTest = rb_define_module_under(mNokogiri, "Test");
|
38
|
+
|
39
|
+
rb_define_singleton_method(mNokogiriTest, "__foreign_error_handler", rb_foreign_error_handler, 0);
|
40
|
+
}
|