nokogiri 1.11.0.rc2 → 1.11.2

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.

Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +171 -94
  6. data/ext/nokogiri/depend +37 -358
  7. data/ext/nokogiri/extconf.rb +581 -374
  8. data/ext/nokogiri/html_document.c +78 -82
  9. data/ext/nokogiri/html_element_description.c +84 -71
  10. data/ext/nokogiri/html_entity_lookup.c +21 -16
  11. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  12. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  13. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  14. data/ext/nokogiri/nokogiri.c +192 -93
  15. data/ext/nokogiri/nokogiri.h +177 -98
  16. data/ext/nokogiri/test_global_handlers.c +40 -0
  17. data/ext/nokogiri/xml_attr.c +15 -15
  18. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  19. data/ext/nokogiri/xml_cdata.c +13 -18
  20. data/ext/nokogiri/xml_comment.c +19 -26
  21. data/ext/nokogiri/xml_document.c +225 -163
  22. data/ext/nokogiri/xml_document_fragment.c +13 -15
  23. data/ext/nokogiri/xml_dtd.c +54 -48
  24. data/ext/nokogiri/xml_element_content.c +30 -27
  25. data/ext/nokogiri/xml_element_decl.c +22 -22
  26. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  27. data/ext/nokogiri/xml_entity_decl.c +32 -30
  28. data/ext/nokogiri/xml_entity_reference.c +16 -18
  29. data/ext/nokogiri/xml_namespace.c +56 -49
  30. data/ext/nokogiri/xml_node.c +338 -286
  31. data/ext/nokogiri/xml_node_set.c +168 -156
  32. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  33. data/ext/nokogiri/xml_reader.c +191 -157
  34. data/ext/nokogiri/xml_relax_ng.c +52 -28
  35. data/ext/nokogiri/xml_sax_parser.c +118 -118
  36. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  37. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  38. data/ext/nokogiri/xml_schema.c +95 -47
  39. data/ext/nokogiri/xml_syntax_error.c +42 -21
  40. data/ext/nokogiri/xml_text.c +13 -17
  41. data/ext/nokogiri/xml_xpath_context.c +206 -123
  42. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  43. data/lib/nokogiri.rb +4 -8
  44. data/lib/nokogiri/css/parser.rb +62 -62
  45. data/lib/nokogiri/css/parser.y +2 -2
  46. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  47. data/lib/nokogiri/extension.rb +26 -0
  48. data/lib/nokogiri/html/document.rb +12 -26
  49. data/lib/nokogiri/html/document_fragment.rb +15 -15
  50. data/lib/nokogiri/version.rb +2 -148
  51. data/lib/nokogiri/version/constant.rb +5 -0
  52. data/lib/nokogiri/version/info.rb +205 -0
  53. data/lib/nokogiri/xml/builder.rb +2 -2
  54. data/lib/nokogiri/xml/document.rb +48 -18
  55. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  56. data/lib/nokogiri/xml/node.rb +88 -69
  57. data/lib/nokogiri/xml/parse_options.rb +6 -0
  58. data/lib/nokogiri/xml/reader.rb +2 -9
  59. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  60. data/lib/nokogiri/xml/schema.rb +12 -4
  61. data/lib/nokogiri/xml/searchable.rb +3 -1
  62. data/lib/nokogiri/xml/xpath.rb +1 -3
  63. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  64. data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +73 -0
  65. data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +103 -0
  66. data/patches/libxml2/0008-use-glibc-strlen.patch +53 -0
  67. data/patches/libxml2/0009-avoid-isnan-isinf.patch +81 -0
  68. data/patches/libxml2/0010-parser.c-shrink-the-input-buffer-when-appropriate.patch +70 -0
  69. metadata +85 -155
  70. data/ext/nokogiri/html_document.h +0 -10
  71. data/ext/nokogiri/html_element_description.h +0 -10
  72. data/ext/nokogiri/html_entity_lookup.h +0 -8
  73. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  74. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  75. data/ext/nokogiri/xml_attr.h +0 -9
  76. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  77. data/ext/nokogiri/xml_cdata.h +0 -9
  78. data/ext/nokogiri/xml_comment.h +0 -9
  79. data/ext/nokogiri/xml_document.h +0 -23
  80. data/ext/nokogiri/xml_document_fragment.h +0 -10
  81. data/ext/nokogiri/xml_dtd.h +0 -10
  82. data/ext/nokogiri/xml_element_content.h +0 -10
  83. data/ext/nokogiri/xml_element_decl.h +0 -9
  84. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  85. data/ext/nokogiri/xml_entity_decl.h +0 -10
  86. data/ext/nokogiri/xml_entity_reference.h +0 -9
  87. data/ext/nokogiri/xml_io.c +0 -61
  88. data/ext/nokogiri/xml_io.h +0 -11
  89. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  90. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  91. data/ext/nokogiri/xml_namespace.h +0 -14
  92. data/ext/nokogiri/xml_node.h +0 -13
  93. data/ext/nokogiri/xml_node_set.h +0 -12
  94. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  95. data/ext/nokogiri/xml_reader.h +0 -10
  96. data/ext/nokogiri/xml_relax_ng.h +0 -9
  97. data/ext/nokogiri/xml_sax_parser.h +0 -39
  98. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  99. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  100. data/ext/nokogiri/xml_schema.h +0 -9
  101. data/ext/nokogiri/xml_syntax_error.h +0 -13
  102. data/ext/nokogiri/xml_text.h +0 -9
  103. data/ext/nokogiri/xml_xpath_context.h +0 -10
  104. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,107 +1,184 @@
1
1
  #include <nokogiri.h>
2
2
 
3
3
  VALUE mNokogiri ;
4
- VALUE mNokogiriXml ;
5
4
  VALUE mNokogiriHtml ;
6
- VALUE mNokogiriXslt ;
7
- VALUE mNokogiriXmlSax ;
8
5
  VALUE mNokogiriHtmlSax ;
6
+ VALUE mNokogiriXml ;
7
+ VALUE mNokogiriXmlSax ;
8
+ VALUE mNokogiriXmlXpath ;
9
+ VALUE mNokogiriXslt ;
9
10
 
10
- #ifdef USE_INCLUDED_VASPRINTF
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
+
51
+
52
+ #ifndef HAVE_VASPRINTF
11
53
  /*
12
- * I srsly hate windows. it doesn't have vasprintf.
13
54
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
55
  */
15
- int vasprintf (char **strp, const char *fmt, va_list ap)
56
+ int
57
+ vasprintf(char **strp, const char *fmt, va_list ap)
16
58
  {
17
59
  /* Mingw32/64 have a broken vsnprintf implementation that fails when
18
60
  * using a zero-byte limit in order to retrieve the required size for malloc.
19
61
  * So we use a one byte buffer instead.
20
62
  */
21
63
  char tmp[1];
22
- int len = vsnprintf (tmp, 1, fmt, ap) + 1;
64
+ int len = vsnprintf(tmp, 1, fmt, ap) + 1;
23
65
  char *res = (char *)malloc((unsigned int)len);
24
- if (res == NULL)
25
- return -1;
66
+ if (res == NULL) {
67
+ return -1;
68
+ }
26
69
  *strp = res;
27
70
  return vsnprintf(res, (unsigned int)len, fmt, ap);
28
71
  }
29
72
  #endif
30
73
 
31
- void vasprintf_free (void *p)
74
+
75
+ static VALUE
76
+ read_check(VALUE val)
32
77
  {
33
- free(p);
78
+ VALUE *args = (VALUE *)val;
79
+ return rb_funcall(args[0], id_read, 1, args[1]);
34
80
  }
35
81
 
36
- #ifdef HAVE_RUBY_UTIL_H
37
- #include "ruby/util.h"
38
- #else
39
- #include "util.h"
40
- #endif
41
82
 
42
- void nokogiri_root_node(xmlNodePtr node)
83
+ static VALUE
84
+ read_failed(VALUE arg, VALUE exc)
85
+ {
86
+ return Qundef;
87
+ }
88
+
89
+
90
+ int
91
+ noko_io_read(void *ctx, char *buffer, int len)
92
+ {
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; }
104
+
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;
110
+ }
111
+
112
+
113
+ static VALUE
114
+ write_check(VALUE val)
43
115
  {
44
- xmlDocPtr doc;
45
- nokogiriTuplePtr tuple;
116
+ VALUE *args = (VALUE *)val;
117
+ return rb_funcall(args[0], id_write, 1, args[1]);
118
+ }
46
119
 
47
- doc = node->doc;
48
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
49
- tuple = (nokogiriTuplePtr)doc->_private;
50
- st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
120
+
121
+ static VALUE
122
+ write_failed(VALUE arg, VALUE exc)
123
+ {
124
+ return Qundef;
51
125
  }
52
126
 
53
- void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
127
+
128
+ int
129
+ noko_io_write(void *ctx, char *buffer, int len)
54
130
  {
55
- nokogiriTuplePtr tuple;
131
+ VALUE args[2], size;
132
+
133
+ args[0] = (VALUE)ctx;
134
+ args[1] = rb_str_new(buffer, (long)len);
56
135
 
57
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
58
- tuple = (nokogiriTuplePtr)doc->_private;
59
- st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
136
+ size = rb_rescue(write_check, (VALUE)args, write_failed, 0);
137
+
138
+ if (size == Qundef) { return -1; }
139
+
140
+ return NUM2INT(size);
60
141
  }
61
142
 
62
- void Init_nokogiri()
143
+
144
+ int
145
+ noko_io_close(void *ctx)
63
146
  {
64
- xmlMemSetup(
65
- (xmlFreeFunc)ruby_xfree,
66
- (xmlMallocFunc)ruby_xmalloc,
67
- (xmlReallocFunc)ruby_xrealloc,
68
- ruby_strdup
69
- );
147
+ return 0;
148
+ }
149
+
70
150
 
151
+ void
152
+ Init_nokogiri()
153
+ {
71
154
  mNokogiri = rb_define_module("Nokogiri");
72
155
  mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
73
156
  mNokogiriHtml = rb_define_module_under(mNokogiri, "HTML");
74
157
  mNokogiriXslt = rb_define_module_under(mNokogiri, "XSLT");
158
+ mNokogiriXmlXpath = rb_define_module_under(mNokogiriXml, "XPath");
75
159
  mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
76
160
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
161
 
78
- rb_const_set( mNokogiri,
79
- rb_intern("LIBXML_COMPILED_VERSION"),
80
- NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION)
81
- );
82
- rb_const_set( mNokogiri,
83
- rb_intern("LIBXML_LOADED_VERSION"),
84
- NOKOGIRI_STR_NEW2(xmlParserVersion)
85
- );
86
-
87
-
88
- rb_const_set( mNokogiri,
89
- rb_intern("LIBXSLT_COMPILED_VERSION"),
90
- NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION)
91
- );
92
- rb_const_set( mNokogiri,
93
- rb_intern("LIBXSLT_LOADED_VERSION"),
94
- NOKOGIRI_STR_NEW2(xsltEngineVersion)
95
- );
96
-
97
- #ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
98
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
99
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
100
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
162
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
163
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
164
+
165
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
166
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
167
+
168
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
169
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
170
+ # ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
171
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
172
+ # else
173
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
174
+ # endif
175
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
176
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
101
177
  #else
102
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
103
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), Qnil);
104
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), Qnil);
178
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
179
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
180
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
181
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
105
182
  #endif
106
183
 
107
184
  #ifdef LIBXML_ICONV_ENABLED
@@ -110,38 +187,60 @@ void Init_nokogiri()
110
187
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
111
188
  #endif
112
189
 
190
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
191
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
192
+ #endif
193
+
194
+ xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
195
+
113
196
  xmlInitParser();
114
197
 
115
- init_xml_document();
116
- init_html_document();
117
- init_xml_node();
118
- init_xml_document_fragment();
119
- init_xml_text();
120
- init_xml_cdata();
121
- init_xml_processing_instruction();
122
- init_xml_attr();
123
- init_xml_entity_reference();
124
- init_xml_comment();
125
- init_xml_node_set();
126
- init_xml_xpath_context();
127
- init_xml_sax_parser_context();
128
- init_xml_sax_parser();
129
- init_xml_sax_push_parser();
130
- init_xml_reader();
131
- init_xml_dtd();
132
- init_xml_element_content();
133
- init_xml_attribute_decl();
134
- init_xml_element_decl();
135
- init_xml_entity_decl();
136
- init_xml_namespace();
137
- init_html_sax_parser_context();
138
- init_html_sax_push_parser();
139
- init_xslt_stylesheet();
140
- init_xml_syntax_error();
141
- init_html_entity_lookup();
142
- init_html_element_description();
143
- init_xml_schema();
144
- init_xml_relax_ng();
145
- init_nokogiri_io();
146
- init_xml_encoding_handler();
198
+ cNokogiriSyntaxError = rb_define_class_under(mNokogiri, "SyntaxError", rb_eStandardError);
199
+ noko_init_xml_syntax_error();
200
+ assert(cNokogiriXmlSyntaxError);
201
+ cNokogiriXmlXpathSyntaxError = rb_define_class_under(mNokogiriXmlXpath, "SyntaxError", cNokogiriXmlSyntaxError);
202
+
203
+ noko_init_xml_element_content();
204
+ noko_init_xml_encoding_handler();
205
+ noko_init_xml_namespace();
206
+ noko_init_xml_node_set();
207
+ noko_init_xml_reader();
208
+ noko_init_xml_sax_parser();
209
+ noko_init_xml_xpath_context();
210
+ noko_init_xslt_stylesheet();
211
+ noko_init_html_element_description();
212
+ noko_init_html_entity_lookup();
213
+
214
+ noko_init_xml_schema();
215
+ noko_init_xml_relax_ng();
216
+
217
+ noko_init_xml_sax_parser_context();
218
+ noko_init_html_sax_parser_context();
219
+
220
+ noko_init_xml_sax_push_parser();
221
+ noko_init_html_sax_push_parser();
222
+
223
+ noko_init_xml_node();
224
+ noko_init_xml_attr();
225
+ noko_init_xml_attribute_decl();
226
+ noko_init_xml_dtd();
227
+ noko_init_xml_element_decl();
228
+ noko_init_xml_entity_decl();
229
+ noko_init_xml_entity_reference();
230
+ noko_init_xml_processing_instruction();
231
+ assert(cNokogiriXmlNode);
232
+ cNokogiriXmlElement = rb_define_class_under(mNokogiriXml, "Element", cNokogiriXmlNode);
233
+ cNokogiriXmlCharacterData = rb_define_class_under(mNokogiriXml, "CharacterData", cNokogiriXmlNode);
234
+ noko_init_xml_comment();
235
+ noko_init_xml_text();
236
+ noko_init_xml_cdata();
237
+
238
+ noko_init_xml_document_fragment();
239
+ noko_init_xml_document();
240
+ noko_init_html_document();
241
+
242
+ noko_init_test_global_handlers();
243
+
244
+ id_read = rb_intern("read");
245
+ id_write = rb_intern("write");
147
246
  }
@@ -2,37 +2,39 @@
2
2
  #define NOKOGIRI_NATIVE
3
3
 
4
4
  #if _MSC_VER
5
- #ifndef WIN32_LEAN_AND_MEAN
6
- #define WIN32_LEAN_AND_MEAN
7
- #endif /* WIN32_LEAN_AND_MEAN */
8
- #ifndef WIN32
9
- #define WIN32
10
- #endif /* WIN32 */
11
- #include <winsock2.h>
12
- #include <ws2tcpip.h>
13
- #include <windows.h>
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
+ #if _WIN32
19
+ # define NOKOPUBFUN __declspec(dllexport)
20
+ # define NOKOPUBVAR __declspec(dllexport) extern
21
+ #else
22
+ # define NOKOPUBFUN
23
+ # define NOKOPUBVAR extern
14
24
  #endif
15
25
 
26
+
16
27
  #include <stdlib.h>
17
28
  #include <string.h>
18
29
  #include <assert.h>
19
30
  #include <stdarg.h>
31
+ #include <stdio.h>
20
32
 
21
- #ifdef USE_INCLUDED_VASPRINTF
22
- int vasprintf (char **strp, const char *fmt, va_list ap);
23
- #else
24
-
25
- #define _GNU_SOURCE
26
- # include <stdio.h>
27
- #undef _GNU_SOURCE
28
-
29
- #endif
30
33
 
31
34
  #include <libxml/parser.h>
35
+ #include <libxml/tree.h>
32
36
  #include <libxml/entities.h>
33
- #include <libxml/parserInternals.h>
34
37
  #include <libxml/xpath.h>
35
- #include <libxml/xpathInternals.h>
36
38
  #include <libxml/xmlreader.h>
37
39
  #include <libxml/xmlsave.h>
38
40
  #include <libxml/xmlschemas.h>
@@ -40,95 +42,172 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
40
42
  #include <libxml/HTMLtree.h>
41
43
  #include <libxml/relaxng.h>
42
44
  #include <libxml/xinclude.h>
45
+ #include <libxml/c14n.h>
46
+ #include <libxml/parserInternals.h>
47
+ #include <libxml/xpathInternals.h>
48
+
43
49
  #include <libxslt/extensions.h>
44
50
  #include <libxslt/xsltconfig.h>
45
- #include <libxml/c14n.h>
46
- #include <ruby.h>
47
- #include <ruby/st.h>
48
- #include <ruby/encoding.h>
51
+ #include <libxslt/xsltutils.h>
52
+ #include <libxslt/transform.h>
53
+ #include <libxslt/xsltInternals.h>
49
54
 
50
- #ifndef NORETURN
51
- # if defined(__GNUC__)
52
- # define NORETURN(name) __attribute__((noreturn)) name
53
- # else
54
- # define NORETURN(name) name
55
- # endif
56
- #endif
55
+ #include <libexslt/exslt.h>
57
56
 
58
- #define NOKOGIRI_STR_NEW2(str) \
59
- NOKOGIRI_STR_NEW(str, strlen((const char *)(str)))
60
-
61
- #define NOKOGIRI_STR_NEW(str, len) \
62
- rb_external_str_new_with_enc((const char *)(str), (long)(len), rb_utf8_encoding())
63
-
64
- #define RBSTR_OR_QNIL(_str) \
65
- (_str ? NOKOGIRI_STR_NEW2(_str) : Qnil)
66
-
67
- #include <xml_libxml2_hacks.h>
68
-
69
- #include <xml_io.h>
70
- #include <xml_document.h>
71
- #include <html_entity_lookup.h>
72
- #include <html_document.h>
73
- #include <xml_node.h>
74
- #include <xml_text.h>
75
- #include <xml_cdata.h>
76
- #include <xml_attr.h>
77
- #include <xml_processing_instruction.h>
78
- #include <xml_entity_reference.h>
79
- #include <xml_document_fragment.h>
80
- #include <xml_comment.h>
81
- #include <xml_node_set.h>
82
- #include <xml_dtd.h>
83
- #include <xml_attribute_decl.h>
84
- #include <xml_element_decl.h>
85
- #include <xml_entity_decl.h>
86
- #include <xml_xpath_context.h>
87
- #include <xml_element_content.h>
88
- #include <xml_sax_parser_context.h>
89
- #include <xml_sax_parser.h>
90
- #include <xml_sax_push_parser.h>
91
- #include <xml_reader.h>
92
- #include <html_sax_parser_context.h>
93
- #include <html_sax_push_parser.h>
94
- #include <xslt_stylesheet.h>
95
- #include <xml_syntax_error.h>
96
- #include <xml_schema.h>
97
- #include <xml_relax_ng.h>
98
- #include <html_element_description.h>
99
- #include <xml_namespace.h>
100
- #include <xml_encoding_handler.h>
101
-
102
- extern VALUE mNokogiri ;
103
- extern VALUE mNokogiriXml ;
104
- extern VALUE mNokogiriXmlSax ;
105
- extern VALUE mNokogiriHtml ;
106
- extern VALUE mNokogiriHtmlSax ;
107
- extern VALUE mNokogiriXslt ;
108
-
109
- void nokogiri_root_node(xmlNodePtr);
110
- void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
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
111
63
 
112
- #ifdef DEBUG
64
+ #define XMLNS_PREFIX "xmlns"
65
+ #define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
113
66
 
114
- #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);
115
- #define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
116
67
 
117
- #else
68
+ #include <ruby.h>
69
+ #include <ruby/st.h>
70
+ #include <ruby/encoding.h>
71
+ #include <ruby/util.h>
118
72
 
119
- #define NOKOGIRI_DEBUG_START(p)
120
- #define NOKOGIRI_DEBUG_END(p)
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)
121
76
 
77
+ #ifdef DEBUG
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);
79
+ # define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
80
+ #else
81
+ # define NOKOGIRI_DEBUG_START(p)
82
+ # define NOKOGIRI_DEBUG_END(p)
122
83
  #endif
123
84
 
124
- #ifndef __builtin_expect
125
- # if defined(__GNUC__)
126
- # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
127
- # endif
85
+ #ifndef NORETURN
86
+ # if defined(__GNUC__)
87
+ # define NORETURN(name) __attribute__((noreturn)) name
88
+ # else
89
+ # define NORETURN(name) name
90
+ # endif
128
91
  #endif
129
92
 
130
- #define XMLNS_PREFIX "xmlns"
131
- #define XMLNS_PREFIX_LEN 6 /* including either colon or \0 */
132
- #define XMLNS_BUFFER_LEN 128
133
93
 
134
- #endif
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 */