nokogiri 1.11.1-x86-mingw32 → 1.11.6-x86-mingw32
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 +4 -4
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +21 -16
- data/dependencies.yml +12 -12
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +66 -65
- data/ext/nokogiri/html_sax_push_parser.c +29 -27
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +6 -4
- data/ext/nokogiri/include/libxml2/libxml/parser.h +9 -7
- data/ext/nokogiri/include/libxml2/libxml/tree.h +3 -3
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +2 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +39 -115
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +1 -1
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +6 -6
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +1 -3
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +190 -63
- data/ext/nokogiri/nokogiri.h +158 -75
- data/ext/nokogiri/test_global_handlers.c +3 -4
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +246 -188
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +385 -326
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +100 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +1 -22
- data/lib/nokogiri/2.5/nokogiri.so +0 -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/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +32 -8
- data/lib/nokogiri/xml/document.rb +74 -28
- data/lib/nokogiri/xml/node.rb +39 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +7 -41
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -25
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -359,8 +359,6 @@ struct _xmlXPathContext {
|
|
359
359
|
unsigned long opLimit;
|
360
360
|
unsigned long opCount;
|
361
361
|
int depth;
|
362
|
-
int maxDepth;
|
363
|
-
int maxParserDepth;
|
364
362
|
};
|
365
363
|
|
366
364
|
/*
|
@@ -373,7 +371,7 @@ typedef xmlXPathCompExpr *xmlXPathCompExprPtr;
|
|
373
371
|
/**
|
374
372
|
* xmlXPathParserContext:
|
375
373
|
*
|
376
|
-
* An XPath parser context. It contains pure parsing
|
374
|
+
* An XPath parser context. It contains pure parsing information,
|
377
375
|
* an xmlXPathContext, and the stack of objects.
|
378
376
|
*/
|
379
377
|
struct _xmlXPathParserContext {
|
@@ -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
|
data/ext/nokogiri/nokogiri.c
CHANGED
@@ -1,26 +1,67 @@
|
|
1
1
|
#include <nokogiri.h>
|
2
2
|
|
3
|
-
void init_test_global_handlers(); /* in lieu of test_global_handlers.h */
|
4
|
-
|
5
3
|
VALUE mNokogiri ;
|
6
|
-
VALUE mNokogiriXml ;
|
7
4
|
VALUE mNokogiriHtml ;
|
8
|
-
VALUE mNokogiriXslt ;
|
9
|
-
VALUE mNokogiriXmlSax ;
|
10
5
|
VALUE mNokogiriHtmlSax ;
|
6
|
+
VALUE mNokogiriXml ;
|
7
|
+
VALUE mNokogiriXmlSax ;
|
8
|
+
VALUE mNokogiriXmlXpath ;
|
9
|
+
VALUE mNokogiriXslt ;
|
10
|
+
|
11
|
+
VALUE cNokogiriSyntaxError;
|
12
|
+
VALUE cNokogiriXmlCharacterData;
|
13
|
+
VALUE cNokogiriXmlElement;
|
14
|
+
VALUE cNokogiriXmlXpathSyntaxError;
|
15
|
+
|
16
|
+
void noko_init_xml_attr();
|
17
|
+
void noko_init_xml_attribute_decl();
|
18
|
+
void noko_init_xml_cdata();
|
19
|
+
void noko_init_xml_comment();
|
20
|
+
void noko_init_xml_document();
|
21
|
+
void noko_init_xml_document_fragment();
|
22
|
+
void noko_init_xml_dtd();
|
23
|
+
void noko_init_xml_element_content();
|
24
|
+
void noko_init_xml_element_decl();
|
25
|
+
void noko_init_xml_encoding_handler();
|
26
|
+
void noko_init_xml_entity_decl();
|
27
|
+
void noko_init_xml_entity_reference();
|
28
|
+
void noko_init_xml_namespace();
|
29
|
+
void noko_init_xml_node();
|
30
|
+
void noko_init_xml_node_set();
|
31
|
+
void noko_init_xml_processing_instruction();
|
32
|
+
void noko_init_xml_reader();
|
33
|
+
void noko_init_xml_relax_ng();
|
34
|
+
void noko_init_xml_sax_parser();
|
35
|
+
void noko_init_xml_sax_parser_context();
|
36
|
+
void noko_init_xml_sax_push_parser();
|
37
|
+
void noko_init_xml_schema();
|
38
|
+
void noko_init_xml_syntax_error();
|
39
|
+
void noko_init_xml_text();
|
40
|
+
void noko_init_xml_xpath_context();
|
41
|
+
void noko_init_xslt_stylesheet();
|
42
|
+
void noko_init_html_document();
|
43
|
+
void noko_init_html_element_description();
|
44
|
+
void noko_init_html_entity_lookup();
|
45
|
+
void noko_init_html_sax_parser_context();
|
46
|
+
void noko_init_html_sax_push_parser();
|
47
|
+
void noko_init_test_global_handlers();
|
48
|
+
|
49
|
+
static ID id_read, id_write;
|
50
|
+
|
11
51
|
|
12
52
|
#ifndef HAVE_VASPRINTF
|
13
53
|
/*
|
14
54
|
* Thank you Geoffroy Couprie for this implementation of vasprintf!
|
15
55
|
*/
|
16
|
-
int
|
56
|
+
int
|
57
|
+
vasprintf(char **strp, const char *fmt, va_list ap)
|
17
58
|
{
|
18
59
|
/* Mingw32/64 have a broken vsnprintf implementation that fails when
|
19
60
|
* using a zero-byte limit in order to retrieve the required size for malloc.
|
20
61
|
* So we use a one byte buffer instead.
|
21
62
|
*/
|
22
63
|
char tmp[1];
|
23
|
-
int len = vsnprintf
|
64
|
+
int len = vsnprintf(tmp, 1, fmt, ap) + 1;
|
24
65
|
char *res = (char *)malloc((unsigned int)len);
|
25
66
|
if (res == NULL) {
|
26
67
|
return -1;
|
@@ -30,41 +71,91 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
|
|
30
71
|
}
|
31
72
|
#endif
|
32
73
|
|
33
|
-
#include "ruby/util.h"
|
34
74
|
|
35
|
-
|
75
|
+
static VALUE
|
76
|
+
read_check(VALUE val)
|
36
77
|
{
|
37
|
-
|
38
|
-
|
78
|
+
VALUE *args = (VALUE *)val;
|
79
|
+
return rb_funcall(args[0], id_read, 1, args[1]);
|
80
|
+
}
|
81
|
+
|
39
82
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
83
|
+
static VALUE
|
84
|
+
read_failed(VALUE arg, VALUE exc)
|
85
|
+
{
|
86
|
+
return Qundef;
|
44
87
|
}
|
45
88
|
|
46
|
-
|
89
|
+
|
90
|
+
int
|
91
|
+
noko_io_read(void *ctx, char *buffer, int len)
|
47
92
|
{
|
48
|
-
|
93
|
+
VALUE string, args[2];
|
94
|
+
size_t str_len, safe_len;
|
95
|
+
|
96
|
+
args[0] = (VALUE)ctx;
|
97
|
+
args[1] = INT2NUM(len);
|
98
|
+
|
99
|
+
string = rb_rescue(read_check, (VALUE)args, read_failed, 0);
|
100
|
+
|
101
|
+
if (NIL_P(string)) { return 0; }
|
102
|
+
if (string == Qundef) { return -1; }
|
103
|
+
if (TYPE(string) != T_STRING) { return -1; }
|
49
104
|
|
50
|
-
|
51
|
-
|
52
|
-
|
105
|
+
str_len = (size_t)RSTRING_LEN(string);
|
106
|
+
safe_len = str_len > (size_t)len ? (size_t)len : str_len;
|
107
|
+
memcpy(buffer, StringValuePtr(string), safe_len);
|
108
|
+
|
109
|
+
return (int)safe_len;
|
53
110
|
}
|
54
111
|
|
55
|
-
|
112
|
+
|
113
|
+
static VALUE
|
114
|
+
write_check(VALUE val)
|
56
115
|
{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
(xmlReallocFunc)ruby_xrealloc,
|
61
|
-
ruby_strdup
|
62
|
-
);
|
116
|
+
VALUE *args = (VALUE *)val;
|
117
|
+
return rb_funcall(args[0], id_write, 1, args[1]);
|
118
|
+
}
|
63
119
|
|
120
|
+
|
121
|
+
static VALUE
|
122
|
+
write_failed(VALUE arg, VALUE exc)
|
123
|
+
{
|
124
|
+
return Qundef;
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
int
|
129
|
+
noko_io_write(void *ctx, char *buffer, int len)
|
130
|
+
{
|
131
|
+
VALUE args[2], size;
|
132
|
+
|
133
|
+
args[0] = (VALUE)ctx;
|
134
|
+
args[1] = rb_str_new(buffer, (long)len);
|
135
|
+
|
136
|
+
size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
|
137
|
+
|
138
|
+
if (size == Qundef) { return -1; }
|
139
|
+
|
140
|
+
return NUM2INT(size);
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
int
|
145
|
+
noko_io_close(void *ctx)
|
146
|
+
{
|
147
|
+
return 0;
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
void
|
152
|
+
Init_nokogiri()
|
153
|
+
{
|
64
154
|
mNokogiri = rb_define_module("Nokogiri");
|
65
155
|
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
|
66
156
|
mNokogiriHtml = rb_define_module_under(mNokogiri, "HTML");
|
67
157
|
mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
|
158
|
+
mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
|
68
159
|
mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
|
69
160
|
mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
|
70
161
|
|
@@ -76,11 +167,11 @@ void Init_nokogiri()
|
|
76
167
|
|
77
168
|
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
|
78
169
|
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
|
79
|
-
#ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
170
|
+
# ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
80
171
|
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
|
81
|
-
#else
|
172
|
+
# else
|
82
173
|
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
83
|
-
#endif
|
174
|
+
# endif
|
84
175
|
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
|
85
176
|
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
|
86
177
|
#else
|
@@ -100,39 +191,75 @@ void Init_nokogiri()
|
|
100
191
|
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
|
101
192
|
#endif
|
102
193
|
|
194
|
+
#if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
195
|
+
/*
|
196
|
+
* We choose *not* to do use Ruby's memory management functions with windows DLLs because of this
|
197
|
+
* issue in libxml 2.9.12:
|
198
|
+
*
|
199
|
+
* https://github.com/sparklemotion/nokogiri/issues/2241
|
200
|
+
*
|
201
|
+
* If the atexit() issue gets fixed in a future version of libxml2, then we may be able to skip
|
202
|
+
* this config only for the specific libxml2 versions 2.9.12.
|
203
|
+
*
|
204
|
+
* Alternatively, now that Ruby has a generational GC, it might be OK to let libxml2 use its
|
205
|
+
* default memory management functions (recall that this config was introduced to reduce memory
|
206
|
+
* bloat and allow Ruby to GC more often); but we should *really* test with production workloads
|
207
|
+
* before making that kind of a potentially-invasive change.
|
208
|
+
*/
|
209
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
|
210
|
+
#else
|
211
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
|
212
|
+
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
|
213
|
+
#endif
|
214
|
+
|
103
215
|
xmlInitParser();
|
104
216
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
217
|
+
cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
|
218
|
+
noko_init_xml_syntax_error();
|
219
|
+
assert(cNokogiriXmlSyntaxError);
|
220
|
+
cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
|
221
|
+
|
222
|
+
noko_init_xml_element_content();
|
223
|
+
noko_init_xml_encoding_handler();
|
224
|
+
noko_init_xml_namespace();
|
225
|
+
noko_init_xml_node_set();
|
226
|
+
noko_init_xml_reader();
|
227
|
+
noko_init_xml_sax_parser();
|
228
|
+
noko_init_xml_xpath_context();
|
229
|
+
noko_init_xslt_stylesheet();
|
230
|
+
noko_init_html_element_description();
|
231
|
+
noko_init_html_entity_lookup();
|
232
|
+
|
233
|
+
noko_init_xml_schema();
|
234
|
+
noko_init_xml_relax_ng();
|
235
|
+
|
236
|
+
noko_init_xml_sax_parser_context();
|
237
|
+
noko_init_html_sax_parser_context();
|
238
|
+
|
239
|
+
noko_init_xml_sax_push_parser();
|
240
|
+
noko_init_html_sax_push_parser();
|
241
|
+
|
242
|
+
noko_init_xml_node();
|
243
|
+
noko_init_xml_attr();
|
244
|
+
noko_init_xml_attribute_decl();
|
245
|
+
noko_init_xml_dtd();
|
246
|
+
noko_init_xml_element_decl();
|
247
|
+
noko_init_xml_entity_decl();
|
248
|
+
noko_init_xml_entity_reference();
|
249
|
+
noko_init_xml_processing_instruction();
|
250
|
+
assert(cNokogiriXmlNode);
|
251
|
+
cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
|
252
|
+
cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
|
253
|
+
noko_init_xml_comment();
|
254
|
+
noko_init_xml_text();
|
255
|
+
noko_init_xml_cdata();
|
256
|
+
|
257
|
+
noko_init_xml_document_fragment();
|
258
|
+
noko_init_xml_document();
|
259
|
+
noko_init_html_document();
|
260
|
+
|
261
|
+
noko_init_test_global_handlers();
|
262
|
+
|
263
|
+
id_read = rb_intern("read");
|
264
|
+
id_write = rb_intern("write");
|
138
265
|
}
|
data/ext/nokogiri/nokogiri.h
CHANGED
@@ -15,17 +15,26 @@
|
|
15
15
|
# include <windows.h>
|
16
16
|
#endif
|
17
17
|
|
18
|
+
#if _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
|
+
|
18
27
|
#include <stdlib.h>
|
19
28
|
#include <string.h>
|
20
29
|
#include <assert.h>
|
21
30
|
#include <stdarg.h>
|
22
31
|
#include <stdio.h>
|
23
32
|
|
33
|
+
|
24
34
|
#include <libxml/parser.h>
|
35
|
+
#include <libxml/tree.h>
|
25
36
|
#include <libxml/entities.h>
|
26
|
-
#include <libxml/parserInternals.h>
|
27
37
|
#include <libxml/xpath.h>
|
28
|
-
#include <libxml/xpathInternals.h>
|
29
38
|
#include <libxml/xmlreader.h>
|
30
39
|
#include <libxml/xmlsave.h>
|
31
40
|
#include <libxml/xmlschemas.h>
|
@@ -33,98 +42,172 @@
|
|
33
42
|
#include <libxml/HTMLtree.h>
|
34
43
|
#include <libxml/relaxng.h>
|
35
44
|
#include <libxml/xinclude.h>
|
45
|
+
#include <libxml/c14n.h>
|
46
|
+
#include <libxml/parserInternals.h>
|
47
|
+
#include <libxml/xpathInternals.h>
|
48
|
+
|
36
49
|
#include <libxslt/extensions.h>
|
37
50
|
#include <libxslt/xsltconfig.h>
|
38
|
-
#include <
|
51
|
+
#include <libxslt/xsltutils.h>
|
52
|
+
#include <libxslt/transform.h>
|
53
|
+
#include <libxslt/xsltInternals.h>
|
39
54
|
|
40
|
-
#include <
|
41
|
-
#include <ruby/st.h>
|
42
|
-
#include <ruby/encoding.h>
|
55
|
+
#include <libexslt/exslt.h>
|
43
56
|
|
44
|
-
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# endif
|
57
|
+
/* libxml2_backwards_compat.c */
|
58
|
+
#ifndef HAVE_XMLFIRSTELEMENTCHILD
|
59
|
+
xmlNodePtr xmlFirstElementChild(xmlNodePtr parent);
|
60
|
+
xmlNodePtr xmlNextElementSibling(xmlNodePtr node);
|
61
|
+
xmlNodePtr xmlLastElementChild(xmlNodePtr parent);
|
50
62
|
#endif
|
51
63
|
|
52
|
-
#define
|
53
|
-
|
54
|
-
|
55
|
-
#define NOKOGIRI_STR_NEW(str, len) \
|
56
|
-
rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
|
57
|
-
|
58
|
-
#define RBSTR_OR_QNIL(_str) \
|
59
|
-
(_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
60
|
-
|
61
|
-
#include <xml_libxml2_hacks.h>
|
62
|
-
|
63
|
-
#include <xml_io.h>
|
64
|
-
#include <xml_document.h>
|
65
|
-
#include <html_entity_lookup.h>
|
66
|
-
#include <html_document.h>
|
67
|
-
#include <xml_node.h>
|
68
|
-
#include <xml_text.h>
|
69
|
-
#include <xml_cdata.h>
|
70
|
-
#include <xml_attr.h>
|
71
|
-
#include <xml_processing_instruction.h>
|
72
|
-
#include <xml_entity_reference.h>
|
73
|
-
#include <xml_document_fragment.h>
|
74
|
-
#include <xml_comment.h>
|
75
|
-
#include <xml_node_set.h>
|
76
|
-
#include <xml_dtd.h>
|
77
|
-
#include <xml_attribute_decl.h>
|
78
|
-
#include <xml_element_decl.h>
|
79
|
-
#include <xml_entity_decl.h>
|
80
|
-
#include <xml_xpath_context.h>
|
81
|
-
#include <xml_element_content.h>
|
82
|
-
#include <xml_sax_parser_context.h>
|
83
|
-
#include <xml_sax_parser.h>
|
84
|
-
#include <xml_sax_push_parser.h>
|
85
|
-
#include <xml_reader.h>
|
86
|
-
#include <html_sax_parser_context.h>
|
87
|
-
#include <html_sax_push_parser.h>
|
88
|
-
#include <xslt_stylesheet.h>
|
89
|
-
#include <xml_syntax_error.h>
|
90
|
-
#include <xml_schema.h>
|
91
|
-
#include <xml_relax_ng.h>
|
92
|
-
#include <html_element_description.h>
|
93
|
-
#include <xml_namespace.h>
|
94
|
-
#include <xml_encoding_handler.h>
|
95
|
-
|
96
|
-
extern VALUE mNokogiri ;
|
97
|
-
extern VALUE mNokogiriXml ;
|
98
|
-
extern VALUE mNokogiriXmlSax ;
|
99
|
-
extern VALUE mNokogiriHtml ;
|
100
|
-
extern VALUE mNokogiriHtmlSax ;
|
101
|
-
extern VALUE mNokogiriXslt ;
|
64
|
+
#define XMLNS_PREFIX "xmlns"
|
65
|
+
#define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
|
102
66
|
|
103
|
-
int vasprintf(char **strp, const char *fmt, va_list ap);
|
104
67
|
|
105
|
-
|
106
|
-
|
68
|
+
#include <ruby.h>
|
69
|
+
#include <ruby/st.h>
|
70
|
+
#include <ruby/encoding.h>
|
71
|
+
#include <ruby/util.h>
|
72
|
+
|
73
|
+
#define NOKOGIRI_STR_NEW2(str) NOKOGIRI_STR_NEW(str, strlen((const char *)(str)))
|
74
|
+
#define NOKOGIRI_STR_NEW(str, len) rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
|
75
|
+
#define RBSTR_OR_QNIL(_str) (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
107
76
|
|
108
77
|
#ifdef DEBUG
|
109
|
-
|
110
78
|
# 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);
|
111
79
|
# define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
|
112
|
-
|
113
80
|
#else
|
114
|
-
|
115
81
|
# define NOKOGIRI_DEBUG_START(p)
|
116
82
|
# define NOKOGIRI_DEBUG_END(p)
|
117
|
-
|
118
83
|
#endif
|
119
84
|
|
120
|
-
#ifndef
|
85
|
+
#ifndef NORETURN
|
121
86
|
# if defined(__GNUC__)
|
122
|
-
# define
|
87
|
+
# define NORETURN(name) __attribute__((noreturn)) name
|
88
|
+
# else
|
89
|
+
# define NORETURN(name) name
|
123
90
|
# endif
|
124
91
|
#endif
|
125
92
|
|
126
|
-
#define XMLNS_PREFIX "xmlns"
|
127
|
-
#define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
|
128
|
-
#define XMLNS_BUFFER_LEN 128
|
129
93
|
|
130
|
-
|
94
|
+
NOKOPUBVAR VALUE mNokogiri ;
|
95
|
+
NOKOPUBVAR VALUE mNokogiriHtml ;
|
96
|
+
NOKOPUBVAR VALUE mNokogiriHtmlSax ;
|
97
|
+
NOKOPUBVAR VALUE mNokogiriXml ;
|
98
|
+
NOKOPUBVAR VALUE mNokogiriXmlSax ;
|
99
|
+
NOKOPUBVAR VALUE mNokogiriXslt ;
|
100
|
+
|
101
|
+
NOKOPUBVAR VALUE cNokogiriSyntaxError;
|
102
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttr;
|
103
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttributeDecl;
|
104
|
+
NOKOPUBVAR VALUE cNokogiriXmlCData;
|
105
|
+
NOKOPUBVAR VALUE cNokogiriXmlCharacterData;
|
106
|
+
NOKOPUBVAR VALUE cNokogiriXmlComment;
|
107
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocument ;
|
108
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocumentFragment;
|
109
|
+
NOKOPUBVAR VALUE cNokogiriXmlDtd;
|
110
|
+
NOKOPUBVAR VALUE cNokogiriXmlElement ;
|
111
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementContent;
|
112
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementDecl;
|
113
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityDecl;
|
114
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityReference;
|
115
|
+
NOKOPUBVAR VALUE cNokogiriXmlNamespace ;
|
116
|
+
NOKOPUBVAR VALUE cNokogiriXmlNode ;
|
117
|
+
NOKOPUBVAR VALUE cNokogiriXmlNodeSet ;
|
118
|
+
NOKOPUBVAR VALUE cNokogiriXmlProcessingInstruction;
|
119
|
+
NOKOPUBVAR VALUE cNokogiriXmlReader;
|
120
|
+
NOKOPUBVAR VALUE cNokogiriXmlRelaxNG;
|
121
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParser ;
|
122
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParserContext;
|
123
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxPushParser ;
|
124
|
+
NOKOPUBVAR VALUE cNokogiriXmlSchema;
|
125
|
+
NOKOPUBVAR VALUE cNokogiriXmlSyntaxError;
|
126
|
+
NOKOPUBVAR VALUE cNokogiriXmlText ;
|
127
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathContext;
|
128
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathSyntaxError;
|
129
|
+
NOKOPUBVAR VALUE cNokogiriXsltStylesheet ;
|
130
|
+
|
131
|
+
NOKOPUBVAR VALUE cNokogiriHtmlDocument ;
|
132
|
+
NOKOPUBVAR VALUE cNokogiriHtmlSaxPushParser ;
|
133
|
+
NOKOPUBVAR VALUE cNokogiriHtmlElementDescription ;
|
134
|
+
NOKOPUBVAR VALUE cNokogiriHtmlSaxParserContext;
|
135
|
+
|
136
|
+
typedef struct _nokogiriTuple {
|
137
|
+
VALUE doc;
|
138
|
+
st_table *unlinkedNodes;
|
139
|
+
VALUE node_cache;
|
140
|
+
} nokogiriTuple;
|
141
|
+
typedef nokogiriTuple *nokogiriTuplePtr;
|
142
|
+
|
143
|
+
typedef struct _nokogiriSAXTuple {
|
144
|
+
xmlParserCtxtPtr ctxt;
|
145
|
+
VALUE self;
|
146
|
+
} nokogiriSAXTuple;
|
147
|
+
typedef nokogiriSAXTuple *nokogiriSAXTuplePtr;
|
148
|
+
|
149
|
+
typedef struct _libxmlStructuredErrorHandlerState {
|
150
|
+
void *user_data;
|
151
|
+
xmlStructuredErrorFunc handler;
|
152
|
+
} libxmlStructuredErrorHandlerState ;
|
153
|
+
|
154
|
+
typedef struct _nokogiriXsltStylesheetTuple {
|
155
|
+
xsltStylesheetPtr ss;
|
156
|
+
VALUE func_instances;
|
157
|
+
} nokogiriXsltStylesheetTuple;
|
158
|
+
|
159
|
+
int vasprintf(char **strp, const char *fmt, va_list ap);
|
160
|
+
void noko_xml_document_pin_node(xmlNodePtr);
|
161
|
+
void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
|
162
|
+
|
163
|
+
int noko_io_read(void *ctx, char *buffer, int len);
|
164
|
+
int noko_io_write(void *ctx, char *buffer, int len);
|
165
|
+
int noko_io_close(void *ctx);
|
166
|
+
|
167
|
+
VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
|
168
|
+
VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
|
169
|
+
VALUE noko_xml_node_attrs(xmlNodePtr node) ;
|
170
|
+
|
171
|
+
VALUE noko_xml_namespace_wrap(xmlNsPtr node, xmlDocPtr doc);
|
172
|
+
VALUE noko_xml_namespace_wrap_xpath_copy(xmlNsPtr node);
|
173
|
+
|
174
|
+
VALUE noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element);
|
175
|
+
|
176
|
+
VALUE noko_xml_node_set_wrap(xmlNodeSetPtr node_set, VALUE document) ;
|
177
|
+
|
178
|
+
VALUE noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr doc, int argc, VALUE *argv);
|
179
|
+
VALUE noko_xml_document_wrap(VALUE klass, xmlDocPtr doc);
|
180
|
+
NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc); /* deprecated. use noko_xml_document_wrap() instead. */
|
181
|
+
|
182
|
+
#define DOC_RUBY_OBJECT_TEST(x) ((nokogiriTuplePtr)(x->_private))
|
183
|
+
#define DOC_RUBY_OBJECT(x) (((nokogiriTuplePtr)(x->_private))->doc)
|
184
|
+
#define DOC_UNLINKED_NODE_HASH(x) (((nokogiriTuplePtr)(x->_private))->unlinkedNodes)
|
185
|
+
#define DOC_NODE_CACHE(x) (((nokogiriTuplePtr)(x->_private))->node_cache)
|
186
|
+
#define NOKOGIRI_NAMESPACE_EH(node) ((node)->type == XML_NAMESPACE_DECL)
|
187
|
+
|
188
|
+
#define NOKOGIRI_SAX_SELF(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->self
|
189
|
+
#define NOKOGIRI_SAX_CTXT(_ctxt) ((nokogiriSAXTuplePtr)(_ctxt))->ctxt
|
190
|
+
#define NOKOGIRI_SAX_TUPLE_NEW(_ctxt, _self) nokogiri_sax_tuple_new(_ctxt, _self)
|
191
|
+
#define NOKOGIRI_SAX_TUPLE_DESTROY(_tuple) free(_tuple)
|
192
|
+
|
193
|
+
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
194
|
+
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
|
195
|
+
xmlStructuredErrorFunc handler);
|
196
|
+
void Nokogiri_structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
|
197
|
+
VALUE Nokogiri_wrap_xml_syntax_error(xmlErrorPtr error);
|
198
|
+
void Nokogiri_error_array_pusher(void *ctx, xmlErrorPtr error);
|
199
|
+
NORETURN(void Nokogiri_error_raise(void *ctx, xmlErrorPtr error));
|
200
|
+
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
201
|
+
const char *function_name) ;
|
202
|
+
|
203
|
+
static inline
|
204
|
+
nokogiriSAXTuplePtr
|
205
|
+
nokogiri_sax_tuple_new(xmlParserCtxtPtr ctxt, VALUE self)
|
206
|
+
{
|
207
|
+
nokogiriSAXTuplePtr tuple = malloc(sizeof(nokogiriSAXTuple));
|
208
|
+
tuple->self = self;
|
209
|
+
tuple->ctxt = ctxt;
|
210
|
+
return tuple;
|
211
|
+
}
|
212
|
+
|
213
|
+
#endif /* NOKOGIRI_NATIVE */
|