nokogiri 1.18.0.rc1-arm-linux-gnu
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +38 -0
- data/LICENSE-DEPENDENCIES.md +2224 -0
- data/LICENSE.md +9 -0
- data/README.md +293 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +42 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1173 -0
- data/ext/nokogiri/gumbo.c +610 -0
- data/ext/nokogiri/html4_document.c +171 -0
- data/ext/nokogiri/html4_element_description.c +299 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser.c +40 -0
- data/ext/nokogiri/html4_sax_parser_context.c +98 -0
- data/ext/nokogiri/html4_sax_push_parser.c +96 -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 +336 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +171 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +115 -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 +82 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +244 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +166 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +41 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +251 -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 +98 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1390 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +671 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +106 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +219 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +959 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +143 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +87 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1382 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +106 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +477 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +136 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +438 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +962 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +188 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +436 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +215 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +102 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +249 -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 +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +347 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +489 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +579 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +633 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +138 -0
- data/ext/nokogiri/include/libxslt/attributes.h +39 -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 +1995 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +146 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +44 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +343 -0
- data/ext/nokogiri/libxml2_polyfill.c +114 -0
- data/ext/nokogiri/nokogiri.c +294 -0
- data/ext/nokogiri/nokogiri.h +238 -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 +62 -0
- data/ext/nokogiri/xml_comment.c +57 -0
- data/ext/nokogiri/xml_document.c +784 -0
- data/ext/nokogiri/xml_document_fragment.c +29 -0
- data/ext/nokogiri/xml_dtd.c +208 -0
- data/ext/nokogiri/xml_element_content.c +131 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +112 -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 +181 -0
- data/ext/nokogiri/xml_node.c +2459 -0
- data/ext/nokogiri/xml_node_set.c +518 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +777 -0
- data/ext/nokogiri/xml_relax_ng.c +149 -0
- data/ext/nokogiri/xml_sax_parser.c +403 -0
- data/ext/nokogiri/xml_sax_parser_context.c +390 -0
- data/ext/nokogiri/xml_sax_push_parser.c +206 -0
- data/ext/nokogiri/xml_schema.c +226 -0
- data/ext/nokogiri/xml_syntax_error.c +93 -0
- data/ext/nokogiri/xml_text.c +59 -0
- data/ext/nokogiri/xml_xpath_context.c +502 -0
- data/ext/nokogiri/xslt_stylesheet.c +421 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +129 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/3.2/nokogiri.so +0 -0
- data/lib/nokogiri/3.3/nokogiri.so +0 -0
- data/lib/nokogiri/3.4/nokogiri.so +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +58 -0
- data/lib/nokogiri/css/parser.rb +772 -0
- data/lib/nokogiri/css/parser.y +277 -0
- data/lib/nokogiri/css/parser_extras.rb +36 -0
- data/lib/nokogiri/css/selector_cache.rb +38 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +57 -0
- data/lib/nokogiri/css/xpath_visitor.rb +375 -0
- data/lib/nokogiri/css.rb +132 -0
- data/lib/nokogiri/decorators/slop.rb +42 -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 +235 -0
- data/lib/nokogiri/html4/document_fragment.rb +166 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +2040 -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 +48 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +15 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +42 -0
- data/lib/nokogiri/html5/builder.rb +40 -0
- data/lib/nokogiri/html5/document.rb +199 -0
- data/lib/nokogiri/html5/document_fragment.rb +200 -0
- data/lib/nokogiri/html5/node.rb +103 -0
- data/lib/nokogiri/html5.rb +368 -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 +224 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +66 -0
- data/lib/nokogiri/xml/attribute_decl.rb +22 -0
- data/lib/nokogiri/xml/builder.rb +494 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +514 -0
- data/lib/nokogiri/xml/document_fragment.rb +276 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +46 -0
- data/lib/nokogiri/xml/element_decl.rb +17 -0
- data/lib/nokogiri/xml/entity_decl.rb +23 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +57 -0
- data/lib/nokogiri/xml/node/save_options.rb +76 -0
- data/lib/nokogiri/xml/node.rb +1650 -0
- data/lib/nokogiri/xml/node_set.rb +449 -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 +73 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +11 -0
- data/lib/nokogiri/xml/reader.rb +139 -0
- data/lib/nokogiri/xml/relax_ng.rb +75 -0
- data/lib/nokogiri/xml/sax/document.rb +258 -0
- data/lib/nokogiri/xml/sax/parser.rb +199 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +129 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +64 -0
- data/lib/nokogiri/xml/sax.rb +54 -0
- data/lib/nokogiri/xml/schema.rb +140 -0
- data/lib/nokogiri/xml/searchable.rb +297 -0
- data/lib/nokogiri/xml/syntax_error.rb +94 -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 +49 -0
- data/lib/nokogiri/xml.rb +65 -0
- data/lib/nokogiri/xslt/stylesheet.rb +49 -0
- data/lib/nokogiri/xslt.rb +129 -0
- data/lib/nokogiri.rb +128 -0
- data/lib/xsd/xmlparser/nokogiri.rb +105 -0
- metadata +324 -0
@@ -0,0 +1,294 @@
|
|
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_html4_sax_parser(void);
|
50
|
+
void noko_init_gumbo(void);
|
51
|
+
void noko_init_test_global_handlers(void);
|
52
|
+
|
53
|
+
static ID id_read, id_write, id_external_encoding;
|
54
|
+
|
55
|
+
|
56
|
+
static VALUE
|
57
|
+
noko_io_read_check(VALUE val)
|
58
|
+
{
|
59
|
+
VALUE *args = (VALUE *)val;
|
60
|
+
return rb_funcall(args[0], id_read, 1, args[1]);
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static VALUE
|
65
|
+
noko_io_read_failed(VALUE arg, VALUE exc)
|
66
|
+
{
|
67
|
+
return Qundef;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
int
|
72
|
+
noko_io_read(void *io, char *c_buffer, int c_buffer_len)
|
73
|
+
{
|
74
|
+
VALUE rb_io = (VALUE)io;
|
75
|
+
VALUE rb_read_string, rb_args[2];
|
76
|
+
size_t n_bytes_read, safe_len;
|
77
|
+
|
78
|
+
rb_args[0] = rb_io;
|
79
|
+
rb_args[1] = INT2NUM(c_buffer_len);
|
80
|
+
|
81
|
+
rb_read_string = rb_rescue(noko_io_read_check, (VALUE)rb_args, noko_io_read_failed, 0);
|
82
|
+
|
83
|
+
if (NIL_P(rb_read_string)) { return 0; }
|
84
|
+
if (rb_read_string == Qundef) { return -1; }
|
85
|
+
if (TYPE(rb_read_string) != T_STRING) { return -1; }
|
86
|
+
|
87
|
+
n_bytes_read = (size_t)RSTRING_LEN(rb_read_string);
|
88
|
+
safe_len = (n_bytes_read > (size_t)c_buffer_len) ? (size_t)c_buffer_len : n_bytes_read;
|
89
|
+
memcpy(c_buffer, StringValuePtr(rb_read_string), safe_len);
|
90
|
+
|
91
|
+
return (int)safe_len;
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
static VALUE
|
96
|
+
noko_io_write_check(VALUE rb_args)
|
97
|
+
{
|
98
|
+
VALUE rb_io = ((VALUE *)rb_args)[0];
|
99
|
+
VALUE rb_output = ((VALUE *)rb_args)[1];
|
100
|
+
return rb_funcall(rb_io, id_write, 1, rb_output);
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
static VALUE
|
105
|
+
noko_io_write_failed(VALUE arg, VALUE exc)
|
106
|
+
{
|
107
|
+
return Qundef;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
int
|
112
|
+
noko_io_write(void *io, char *c_buffer, int c_buffer_len)
|
113
|
+
{
|
114
|
+
VALUE rb_args[2], rb_n_bytes_written;
|
115
|
+
VALUE rb_io = (VALUE)io;
|
116
|
+
VALUE rb_enc = Qnil;
|
117
|
+
rb_encoding *io_encoding;
|
118
|
+
|
119
|
+
if (rb_respond_to(rb_io, id_external_encoding)) {
|
120
|
+
rb_enc = rb_funcall(rb_io, id_external_encoding, 0);
|
121
|
+
}
|
122
|
+
io_encoding = RB_NIL_P(rb_enc) ? rb_ascii8bit_encoding() : rb_to_encoding(rb_enc);
|
123
|
+
|
124
|
+
rb_args[0] = rb_io;
|
125
|
+
rb_args[1] = rb_enc_str_new(c_buffer, (long)c_buffer_len, io_encoding);
|
126
|
+
|
127
|
+
rb_n_bytes_written = rb_rescue(noko_io_write_check, (VALUE)rb_args, noko_io_write_failed, 0);
|
128
|
+
if (rb_n_bytes_written == Qundef) { return -1; }
|
129
|
+
|
130
|
+
return NUM2INT(rb_n_bytes_written);
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
int
|
135
|
+
noko_io_close(void *io)
|
136
|
+
{
|
137
|
+
return 0;
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
#if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
142
|
+
# define NOKOGIRI_WINDOWS_DLLS 1
|
143
|
+
#else
|
144
|
+
# define NOKOGIRI_WINDOWS_DLLS 0
|
145
|
+
#endif
|
146
|
+
|
147
|
+
//
|
148
|
+
// | dlls || true | false |
|
149
|
+
// | nlmm || | |
|
150
|
+
// |-----------++---------+---------|
|
151
|
+
// | NULL || default | ruby |
|
152
|
+
// | "random" || default | ruby |
|
153
|
+
// | "ruby" || ruby | ruby |
|
154
|
+
// | "default" || default | default |
|
155
|
+
//
|
156
|
+
// We choose *not* to use Ruby's memory management functions with windows DLLs because of this
|
157
|
+
// issue: https://github.com/sparklemotion/nokogiri/issues/2241
|
158
|
+
//
|
159
|
+
static void
|
160
|
+
set_libxml_memory_management(void)
|
161
|
+
{
|
162
|
+
const char *nlmm = getenv("NOKOGIRI_LIBXML_MEMORY_MANAGEMENT");
|
163
|
+
if (nlmm) {
|
164
|
+
if (strcmp(nlmm, "default") == 0) {
|
165
|
+
goto libxml_uses_default_memory_management;
|
166
|
+
} else if (strcmp(nlmm, "ruby") == 0) {
|
167
|
+
goto libxml_uses_ruby_memory_management;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
if (NOKOGIRI_WINDOWS_DLLS) {
|
171
|
+
libxml_uses_default_memory_management:
|
172
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
|
173
|
+
return;
|
174
|
+
} else {
|
175
|
+
libxml_uses_ruby_memory_management:
|
176
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
|
177
|
+
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
|
183
|
+
void
|
184
|
+
Init_nokogiri(void)
|
185
|
+
{
|
186
|
+
mNokogiri = rb_define_module("Nokogiri");
|
187
|
+
mNokogiriGumbo = rb_define_module_under(mNokogiri, "Gumbo");
|
188
|
+
mNokogiriHtml4 = rb_define_module_under(mNokogiri, "HTML4");
|
189
|
+
mNokogiriHtml4Sax = rb_define_module_under(mNokogiriHtml4, "SAX");
|
190
|
+
mNokogiriHtml5 = rb_define_module_under(mNokogiri, "HTML5");
|
191
|
+
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
|
192
|
+
mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
|
193
|
+
mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
|
194
|
+
mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
|
195
|
+
|
196
|
+
set_libxml_memory_management(); /* must be before any function calls that might invoke xmlInitParser() */
|
197
|
+
xmlInitParser();
|
198
|
+
exsltRegisterAll();
|
199
|
+
|
200
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
|
201
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
|
202
|
+
|
203
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
|
204
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
|
205
|
+
|
206
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_ZLIB_ENABLED"),
|
207
|
+
xmlHasFeature(XML_WITH_ZLIB) == 1 ? Qtrue : Qfalse);
|
208
|
+
|
209
|
+
#ifdef NOKOGIRI_PACKAGED_LIBRARIES
|
210
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
|
211
|
+
# ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
|
212
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
|
213
|
+
# else
|
214
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
215
|
+
# endif
|
216
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
|
217
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
|
218
|
+
#else
|
219
|
+
rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
|
220
|
+
rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
|
221
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
|
222
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
|
223
|
+
#endif
|
224
|
+
|
225
|
+
#ifdef LIBXML_ICONV_ENABLED
|
226
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qtrue);
|
227
|
+
#else
|
228
|
+
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
|
229
|
+
#endif
|
230
|
+
|
231
|
+
#ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
|
232
|
+
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
|
233
|
+
#endif
|
234
|
+
|
235
|
+
if (xsltExtModuleFunctionLookup((const xmlChar *)"date-time", EXSLT_DATE_NAMESPACE)) {
|
236
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qtrue);
|
237
|
+
} else {
|
238
|
+
rb_const_set(mNokogiri, rb_intern("LIBXSLT_DATETIME_ENABLED"), Qfalse);
|
239
|
+
}
|
240
|
+
|
241
|
+
cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
|
242
|
+
noko_init_xml_syntax_error();
|
243
|
+
assert(cNokogiriXmlSyntaxError);
|
244
|
+
cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
|
245
|
+
|
246
|
+
noko_init_xml_element_content();
|
247
|
+
noko_init_xml_encoding_handler();
|
248
|
+
noko_init_xml_namespace();
|
249
|
+
noko_init_xml_node_set();
|
250
|
+
noko_init_xml_reader();
|
251
|
+
|
252
|
+
noko_init_xml_sax_parser();
|
253
|
+
noko_init_html4_sax_parser();
|
254
|
+
|
255
|
+
noko_init_xml_xpath_context();
|
256
|
+
noko_init_xslt_stylesheet();
|
257
|
+
noko_init_html_element_description();
|
258
|
+
noko_init_html_entity_lookup();
|
259
|
+
|
260
|
+
noko_init_xml_schema();
|
261
|
+
noko_init_xml_relax_ng();
|
262
|
+
|
263
|
+
noko_init_xml_sax_parser_context();
|
264
|
+
noko_init_html_sax_parser_context();
|
265
|
+
|
266
|
+
noko_init_xml_sax_push_parser();
|
267
|
+
noko_init_html_sax_push_parser();
|
268
|
+
|
269
|
+
noko_init_xml_node();
|
270
|
+
noko_init_xml_attr();
|
271
|
+
noko_init_xml_attribute_decl();
|
272
|
+
noko_init_xml_dtd();
|
273
|
+
noko_init_xml_element_decl();
|
274
|
+
noko_init_xml_entity_decl();
|
275
|
+
noko_init_xml_entity_reference();
|
276
|
+
noko_init_xml_processing_instruction();
|
277
|
+
assert(cNokogiriXmlNode);
|
278
|
+
cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
|
279
|
+
cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
|
280
|
+
noko_init_xml_comment();
|
281
|
+
noko_init_xml_text();
|
282
|
+
noko_init_xml_cdata();
|
283
|
+
|
284
|
+
noko_init_xml_document_fragment();
|
285
|
+
noko_init_xml_document();
|
286
|
+
noko_init_html_document();
|
287
|
+
noko_init_gumbo();
|
288
|
+
|
289
|
+
noko_init_test_global_handlers();
|
290
|
+
|
291
|
+
id_read = rb_intern("read");
|
292
|
+
id_write = rb_intern("write");
|
293
|
+
id_external_encoding = rb_intern("external_encoding");
|
294
|
+
}
|
@@ -0,0 +1,238 @@
|
|
1
|
+
#ifndef NOKOGIRI_NATIVE
|
2
|
+
#define NOKOGIRI_NATIVE
|
3
|
+
|
4
|
+
#include <ruby/defines.h> // https://github.com/sparklemotion/nokogiri/issues/2696
|
5
|
+
|
6
|
+
#ifdef _MSC_VER
|
7
|
+
# ifndef WIN32_LEAN_AND_MEAN
|
8
|
+
# define WIN32_LEAN_AND_MEAN
|
9
|
+
# endif /* WIN32_LEAN_AND_MEAN */
|
10
|
+
|
11
|
+
# ifndef WIN32
|
12
|
+
# define WIN32
|
13
|
+
# endif /* WIN32 */
|
14
|
+
|
15
|
+
# include <winsock2.h>
|
16
|
+
# include <ws2tcpip.h>
|
17
|
+
# include <windows.h>
|
18
|
+
#endif
|
19
|
+
|
20
|
+
#ifdef _WIN32
|
21
|
+
# define NOKOPUBFUN __declspec(dllexport)
|
22
|
+
# define NOKOPUBVAR __declspec(dllexport) extern
|
23
|
+
#else
|
24
|
+
# define NOKOPUBFUN
|
25
|
+
# define NOKOPUBVAR extern
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#include <stdlib.h>
|
29
|
+
#include <string.h>
|
30
|
+
#include <assert.h>
|
31
|
+
#include <stdarg.h>
|
32
|
+
#include <stdio.h>
|
33
|
+
|
34
|
+
|
35
|
+
#include <libxml/parser.h>
|
36
|
+
#include <libxml/tree.h>
|
37
|
+
#include <libxml/entities.h>
|
38
|
+
#include <libxml/xpath.h>
|
39
|
+
#include <libxml/xmlreader.h>
|
40
|
+
#include <libxml/xmlsave.h>
|
41
|
+
#include <libxml/xmlschemas.h>
|
42
|
+
#include <libxml/HTMLparser.h>
|
43
|
+
#include <libxml/HTMLtree.h>
|
44
|
+
#include <libxml/relaxng.h>
|
45
|
+
#include <libxml/xinclude.h>
|
46
|
+
#include <libxml/c14n.h>
|
47
|
+
#include <libxml/parserInternals.h>
|
48
|
+
#include <libxml/xpathInternals.h>
|
49
|
+
|
50
|
+
#include <libxslt/extensions.h>
|
51
|
+
#include <libxslt/xsltconfig.h>
|
52
|
+
#include <libxslt/xsltutils.h>
|
53
|
+
#include <libxslt/transform.h>
|
54
|
+
#include <libxslt/imports.h>
|
55
|
+
#include <libxslt/xsltInternals.h>
|
56
|
+
|
57
|
+
#include <libexslt/exslt.h>
|
58
|
+
|
59
|
+
/* libxml2_polyfill.c */
|
60
|
+
#ifndef HAVE_XMLCTXTSETOPTIONS
|
61
|
+
int xmlCtxtSetOptions(xmlParserCtxtPtr ctxt, int options);
|
62
|
+
#endif
|
63
|
+
#ifndef HAVE_XMLCTXTGETOPTIONS
|
64
|
+
int xmlCtxtGetOptions(xmlParserCtxtPtr ctxt);
|
65
|
+
#endif
|
66
|
+
#ifndef HAVE_XMLSWITCHENCODINGNAME
|
67
|
+
int xmlSwitchEncodingName(xmlParserCtxtPtr ctxt, const char *encoding);
|
68
|
+
#endif
|
69
|
+
|
70
|
+
#define XMLNS_PREFIX "xmlns"
|
71
|
+
#define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
|
72
|
+
|
73
|
+
#ifndef xmlErrorConstPtr
|
74
|
+
# if LIBXML_VERSION >= 21200
|
75
|
+
# define xmlErrorConstPtr const xmlError *
|
76
|
+
# else
|
77
|
+
# define xmlErrorConstPtr xmlError *
|
78
|
+
# endif
|
79
|
+
#endif
|
80
|
+
|
81
|
+
#include <ruby.h>
|
82
|
+
#include <ruby/st.h>
|
83
|
+
#include <ruby/encoding.h>
|
84
|
+
#include <ruby/util.h>
|
85
|
+
#include <ruby/version.h>
|
86
|
+
|
87
|
+
#define NOKOGIRI_STR_NEW2(str) NOKOGIRI_STR_NEW(str, strlen((const char *)(str)))
|
88
|
+
#define NOKOGIRI_STR_NEW(str, len) rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
|
89
|
+
#define RBSTR_OR_QNIL(_str) (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
|
90
|
+
|
91
|
+
#ifndef NORETURN_DECL
|
92
|
+
# if defined(__GNUC__)
|
93
|
+
# define NORETURN_DECL __attribute__ ((noreturn))
|
94
|
+
# else
|
95
|
+
# define NORETURN_DECL
|
96
|
+
# endif
|
97
|
+
#endif
|
98
|
+
|
99
|
+
#ifndef PRINTFLIKE_DECL
|
100
|
+
# if defined(__GNUC__)
|
101
|
+
# define PRINTFLIKE_DECL(stringidx, argidx) __attribute__ ((format(printf,stringidx,argidx)))
|
102
|
+
# else
|
103
|
+
# define PRINTFLIKE_DECL(stringidx, argidx)
|
104
|
+
# endif
|
105
|
+
#endif
|
106
|
+
|
107
|
+
#if defined(TRUFFLERUBY) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
|
108
|
+
# define TRUFFLERUBY_NOKOGIRI_SYSTEM_LIBRARIES
|
109
|
+
#endif
|
110
|
+
|
111
|
+
NOKOPUBVAR VALUE mNokogiri ;
|
112
|
+
NOKOPUBVAR VALUE mNokogiriGumbo ;
|
113
|
+
NOKOPUBVAR VALUE mNokogiriHtml4 ;
|
114
|
+
NOKOPUBVAR VALUE mNokogiriHtml4Sax ;
|
115
|
+
NOKOPUBVAR VALUE mNokogiriHtml5 ;
|
116
|
+
NOKOPUBVAR VALUE mNokogiriXml ;
|
117
|
+
NOKOPUBVAR VALUE mNokogiriXmlSax ;
|
118
|
+
NOKOPUBVAR VALUE mNokogiriXmlXpath ;
|
119
|
+
NOKOPUBVAR VALUE mNokogiriXslt ;
|
120
|
+
|
121
|
+
NOKOPUBVAR VALUE cNokogiriEncodingHandler;
|
122
|
+
NOKOPUBVAR VALUE cNokogiriSyntaxError;
|
123
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttr;
|
124
|
+
NOKOPUBVAR VALUE cNokogiriXmlAttributeDecl;
|
125
|
+
NOKOPUBVAR VALUE cNokogiriXmlCData;
|
126
|
+
NOKOPUBVAR VALUE cNokogiriXmlCharacterData;
|
127
|
+
NOKOPUBVAR VALUE cNokogiriXmlComment;
|
128
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocument ;
|
129
|
+
NOKOPUBVAR VALUE cNokogiriXmlDocumentFragment;
|
130
|
+
NOKOPUBVAR VALUE cNokogiriXmlDtd;
|
131
|
+
NOKOPUBVAR VALUE cNokogiriXmlElement ;
|
132
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementContent;
|
133
|
+
NOKOPUBVAR VALUE cNokogiriXmlElementDecl;
|
134
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityDecl;
|
135
|
+
NOKOPUBVAR VALUE cNokogiriXmlEntityReference;
|
136
|
+
NOKOPUBVAR VALUE cNokogiriXmlNamespace ;
|
137
|
+
NOKOPUBVAR VALUE cNokogiriXmlNode ;
|
138
|
+
NOKOPUBVAR VALUE cNokogiriXmlNodeSet ;
|
139
|
+
NOKOPUBVAR VALUE cNokogiriXmlProcessingInstruction;
|
140
|
+
NOKOPUBVAR VALUE cNokogiriXmlReader;
|
141
|
+
NOKOPUBVAR VALUE cNokogiriXmlRelaxNG;
|
142
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParser ;
|
143
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxParserContext;
|
144
|
+
NOKOPUBVAR VALUE cNokogiriXmlSaxPushParser ;
|
145
|
+
NOKOPUBVAR VALUE cNokogiriXmlSchema;
|
146
|
+
NOKOPUBVAR VALUE cNokogiriXmlSyntaxError;
|
147
|
+
NOKOPUBVAR VALUE cNokogiriXmlText ;
|
148
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathContext;
|
149
|
+
NOKOPUBVAR VALUE cNokogiriXmlXpathSyntaxError;
|
150
|
+
NOKOPUBVAR VALUE cNokogiriXsltStylesheet ;
|
151
|
+
|
152
|
+
NOKOPUBVAR VALUE cNokogiriHtml4Document ;
|
153
|
+
NOKOPUBVAR VALUE cNokogiriHtml4SaxPushParser ;
|
154
|
+
NOKOPUBVAR VALUE cNokogiriHtml4ElementDescription ;
|
155
|
+
NOKOPUBVAR VALUE cNokogiriHtml4SaxParser;
|
156
|
+
NOKOPUBVAR VALUE cNokogiriHtml4SaxParserContext;
|
157
|
+
NOKOPUBVAR VALUE cNokogiriHtml5Document ;
|
158
|
+
|
159
|
+
typedef struct _nokogiriTuple {
|
160
|
+
VALUE doc;
|
161
|
+
st_table *unlinkedNodes;
|
162
|
+
VALUE node_cache;
|
163
|
+
} nokogiriTuple;
|
164
|
+
typedef nokogiriTuple *nokogiriTuplePtr;
|
165
|
+
|
166
|
+
typedef struct _libxmlStructuredErrorHandlerState {
|
167
|
+
void *user_data;
|
168
|
+
xmlStructuredErrorFunc handler;
|
169
|
+
} libxmlStructuredErrorHandlerState ;
|
170
|
+
|
171
|
+
typedef struct _nokogiriXsltStylesheetTuple {
|
172
|
+
xsltStylesheetPtr ss;
|
173
|
+
VALUE func_instances;
|
174
|
+
} nokogiriXsltStylesheetTuple;
|
175
|
+
|
176
|
+
void noko_xml_document_pin_node(xmlNodePtr);
|
177
|
+
void noko_xml_document_pin_namespace(xmlNsPtr, xmlDocPtr);
|
178
|
+
int noko_xml_document_has_wrapped_blank_nodes_p(xmlDocPtr c_document);
|
179
|
+
|
180
|
+
int noko_io_read(void *ctx, char *buffer, int len);
|
181
|
+
int noko_io_write(void *ctx, char *buffer, int len);
|
182
|
+
int noko_io_close(void *ctx);
|
183
|
+
|
184
|
+
#define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
|
185
|
+
#define Noko_Namespace_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))
|
186
|
+
|
187
|
+
VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
|
188
|
+
VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
|
189
|
+
VALUE noko_xml_node_attrs(xmlNodePtr node) ;
|
190
|
+
|
191
|
+
VALUE noko_xml_namespace_wrap(xmlNsPtr node, xmlDocPtr doc);
|
192
|
+
VALUE noko_xml_namespace_wrap_xpath_copy(xmlNsPtr node);
|
193
|
+
|
194
|
+
VALUE noko_xml_element_content_wrap(VALUE doc, xmlElementContentPtr element);
|
195
|
+
|
196
|
+
VALUE noko_xml_node_set_wrap(xmlNodeSetPtr node_set, VALUE document) ;
|
197
|
+
xmlNodeSetPtr noko_xml_node_set_unwrap(VALUE rb_node_set) ;
|
198
|
+
|
199
|
+
VALUE noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr doc, int argc, VALUE *argv);
|
200
|
+
VALUE noko_xml_document_wrap(VALUE klass, xmlDocPtr doc);
|
201
|
+
xmlDocPtr noko_xml_document_unwrap(VALUE rb_document);
|
202
|
+
NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
|
203
|
+
xmlDocPtr doc); /* deprecated. use noko_xml_document_wrap() instead. */
|
204
|
+
|
205
|
+
xmlSAXHandlerPtr noko_xml_sax_parser_unwrap(VALUE rb_sax_handler);
|
206
|
+
|
207
|
+
xmlParserCtxtPtr noko_xml_sax_push_parser_unwrap(VALUE rb_parser);
|
208
|
+
|
209
|
+
VALUE noko_xml_sax_parser_context_wrap(VALUE klass, xmlParserCtxtPtr c_context);
|
210
|
+
xmlParserCtxtPtr noko_xml_sax_parser_context_unwrap(VALUE rb_context);
|
211
|
+
void noko_xml_sax_parser_context_set_encoding(xmlParserCtxtPtr c_context, VALUE rb_encoding);
|
212
|
+
|
213
|
+
#define DOC_RUBY_OBJECT_TEST(x) ((nokogiriTuplePtr)(x->_private))
|
214
|
+
#define DOC_RUBY_OBJECT(x) (((nokogiriTuplePtr)(x->_private))->doc)
|
215
|
+
#define DOC_UNLINKED_NODE_HASH(x) (((nokogiriTuplePtr)(x->_private))->unlinkedNodes)
|
216
|
+
#define DOC_NODE_CACHE(x) (((nokogiriTuplePtr)(x->_private))->node_cache)
|
217
|
+
#define NOKOGIRI_NAMESPACE_EH(node) ((node)->type == XML_NAMESPACE_DECL)
|
218
|
+
|
219
|
+
#define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
|
220
|
+
#define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
|
221
|
+
|
222
|
+
#if HAVE_RB_CATEGORY_WARNING
|
223
|
+
# define NOKO_WARN_DEPRECATION(message...) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
|
224
|
+
#else
|
225
|
+
# define NOKO_WARN_DEPRECATION(message...) rb_warning(message)
|
226
|
+
#endif
|
227
|
+
|
228
|
+
void noko__structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
|
229
|
+
void noko__structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
|
230
|
+
xmlStructuredErrorFunc handler);
|
231
|
+
void noko__structured_error_func_restore(libxmlStructuredErrorHandlerState *handler_state);
|
232
|
+
VALUE noko_xml_syntax_error__wrap(xmlErrorConstPtr error);
|
233
|
+
void noko__error_array_pusher(void *ctx, xmlErrorConstPtr error);
|
234
|
+
NORETURN_DECL void noko__error_raise(void *ctx, xmlErrorConstPtr error);
|
235
|
+
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler,
|
236
|
+
const char *function_name) ;
|
237
|
+
|
238
|
+
#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, xmlErrorConstPtr 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(void)
|
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
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlAttr;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* call-seq:
|
7
|
+
* value=(content)
|
8
|
+
*
|
9
|
+
* Set the value for this Attr to +content+. Use +nil+ to remove the value
|
10
|
+
* (e.g., a HTML boolean attribute).
|
11
|
+
*/
|
12
|
+
static VALUE
|
13
|
+
set_value(VALUE self, VALUE content)
|
14
|
+
{
|
15
|
+
xmlAttrPtr attr;
|
16
|
+
xmlChar *value;
|
17
|
+
xmlNode *cur;
|
18
|
+
|
19
|
+
Noko_Node_Get_Struct(self, xmlAttr, attr);
|
20
|
+
|
21
|
+
if (attr->children) {
|
22
|
+
xmlFreeNodeList(attr->children);
|
23
|
+
}
|
24
|
+
attr->children = attr->last = NULL;
|
25
|
+
|
26
|
+
if (content == Qnil) {
|
27
|
+
return content;
|
28
|
+
}
|
29
|
+
|
30
|
+
value = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValueCStr(content));
|
31
|
+
if (xmlStrlen(value) == 0) {
|
32
|
+
attr->children = xmlNewDocText(attr->doc, value);
|
33
|
+
} else {
|
34
|
+
attr->children = xmlStringGetNodeList(attr->doc, value);
|
35
|
+
}
|
36
|
+
xmlFree(value);
|
37
|
+
|
38
|
+
for (cur = attr->children; cur; cur = cur->next) {
|
39
|
+
cur->parent = (xmlNode *)attr;
|
40
|
+
cur->doc = attr->doc;
|
41
|
+
if (cur->next == NULL) {
|
42
|
+
attr->last = cur;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
return content;
|
47
|
+
}
|
48
|
+
|
49
|
+
/*
|
50
|
+
* call-seq:
|
51
|
+
* new(document, name)
|
52
|
+
*
|
53
|
+
* Create a new Attr element on the +document+ with +name+
|
54
|
+
*/
|
55
|
+
static VALUE
|
56
|
+
new (int argc, VALUE *argv, VALUE klass)
|
57
|
+
{
|
58
|
+
xmlDocPtr xml_doc;
|
59
|
+
VALUE document;
|
60
|
+
VALUE name;
|
61
|
+
VALUE rest;
|
62
|
+
xmlAttrPtr node;
|
63
|
+
VALUE rb_node;
|
64
|
+
|
65
|
+
rb_scan_args(argc, argv, "2*", &document, &name, &rest);
|
66
|
+
|
67
|
+
if (! rb_obj_is_kind_of(document, cNokogiriXmlDocument)) {
|
68
|
+
rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
|
69
|
+
}
|
70
|
+
|
71
|
+
xml_doc = noko_xml_document_unwrap(document);
|
72
|
+
|
73
|
+
node = xmlNewDocProp(
|
74
|
+
xml_doc,
|
75
|
+
(const xmlChar *)StringValueCStr(name),
|
76
|
+
NULL
|
77
|
+
);
|
78
|
+
|
79
|
+
noko_xml_document_pin_node((xmlNodePtr)node);
|
80
|
+
|
81
|
+
rb_node = noko_xml_node_wrap(klass, (xmlNodePtr)node);
|
82
|
+
rb_obj_call_init(rb_node, argc, argv);
|
83
|
+
|
84
|
+
if (rb_block_given_p()) {
|
85
|
+
rb_yield(rb_node);
|
86
|
+
}
|
87
|
+
|
88
|
+
return rb_node;
|
89
|
+
}
|
90
|
+
|
91
|
+
void
|
92
|
+
noko_init_xml_attr(void)
|
93
|
+
{
|
94
|
+
assert(cNokogiriXmlNode);
|
95
|
+
/*
|
96
|
+
* Attr represents a Attr node in an xml document.
|
97
|
+
*/
|
98
|
+
cNokogiriXmlAttr = rb_define_class_under(mNokogiriXml, "Attr", cNokogiriXmlNode);
|
99
|
+
|
100
|
+
rb_define_singleton_method(cNokogiriXmlAttr, "new", new, -1);
|
101
|
+
|
102
|
+
rb_define_method(cNokogiriXmlAttr, "value=", set_value, 1);
|
103
|
+
}
|