libxml-ruby 4.1.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/{HISTORY → CHANGELOG.md} +875 -887
  3. data/LICENSE +20 -20
  4. data/README.md +67 -0
  5. data/Rakefile +77 -98
  6. data/ext/libxml/extconf.rb +39 -20
  7. data/ext/libxml/libxml.c +67 -79
  8. data/ext/libxml/ruby_libxml.h +43 -44
  9. data/ext/libxml/ruby_xml.c +556 -899
  10. data/ext/libxml/ruby_xml.h +9 -10
  11. data/ext/libxml/ruby_xml_attr.c +338 -333
  12. data/ext/libxml/ruby_xml_attr.h +13 -12
  13. data/ext/libxml/ruby_xml_attr_decl.c +19 -12
  14. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  15. data/ext/libxml/ruby_xml_attributes.c +18 -9
  16. data/ext/libxml/ruby_xml_attributes.h +17 -15
  17. data/ext/libxml/ruby_xml_document.c +1142 -1129
  18. data/ext/libxml/ruby_xml_document.h +12 -11
  19. data/ext/libxml/ruby_xml_dtd.c +287 -248
  20. data/ext/libxml/ruby_xml_dtd.h +10 -9
  21. data/ext/libxml/ruby_xml_encoding.c +250 -250
  22. data/ext/libxml/ruby_xml_encoding.h +20 -18
  23. data/ext/libxml/ruby_xml_error.c +1003 -996
  24. data/ext/libxml/ruby_xml_error.h +14 -14
  25. data/ext/libxml/ruby_xml_html_parser.c +91 -91
  26. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  27. data/ext/libxml/ruby_xml_html_parser_context.c +364 -337
  28. data/ext/libxml/ruby_xml_html_parser_context.h +11 -10
  29. data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
  30. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  31. data/ext/libxml/ruby_xml_input_cbg.c +216 -188
  32. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  33. data/ext/libxml/ruby_xml_io.c +49 -47
  34. data/ext/libxml/ruby_xml_io.h +10 -10
  35. data/ext/libxml/ruby_xml_namespace.c +159 -154
  36. data/ext/libxml/ruby_xml_namespace.h +11 -10
  37. data/ext/libxml/ruby_xml_namespaces.c +313 -293
  38. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  39. data/ext/libxml/ruby_xml_node.c +1433 -1398
  40. data/ext/libxml/ruby_xml_node.h +15 -13
  41. data/ext/libxml/ruby_xml_parser.c +91 -91
  42. data/ext/libxml/ruby_xml_parser.h +10 -10
  43. data/ext/libxml/ruby_xml_parser_context.c +1016 -1001
  44. data/ext/libxml/ruby_xml_parser_context.h +11 -10
  45. data/ext/libxml/ruby_xml_parser_options.c +74 -66
  46. data/ext/libxml/ruby_xml_parser_options.h +10 -10
  47. data/ext/libxml/ruby_xml_reader.c +40 -31
  48. data/ext/libxml/ruby_xml_reader.h +14 -14
  49. data/ext/libxml/ruby_xml_registry.c +31 -0
  50. data/ext/libxml/ruby_xml_registry.h +22 -0
  51. data/ext/libxml/ruby_xml_relaxng.c +21 -5
  52. data/ext/libxml/ruby_xml_relaxng.h +9 -8
  53. data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
  54. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  55. data/ext/libxml/ruby_xml_sax_parser.c +108 -116
  56. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  57. data/ext/libxml/ruby_xml_schema.c +22 -15
  58. data/ext/libxml/ruby_xml_schema.h +26 -25
  59. data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
  60. data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
  61. data/ext/libxml/ruby_xml_schema_element.c +8 -8
  62. data/ext/libxml/ruby_xml_schema_element.h +11 -11
  63. data/ext/libxml/ruby_xml_schema_facet.c +50 -50
  64. data/ext/libxml/ruby_xml_schema_facet.h +9 -9
  65. data/ext/libxml/ruby_xml_schema_type.c +12 -19
  66. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  67. data/ext/libxml/ruby_xml_version.h +9 -9
  68. data/ext/libxml/ruby_xml_writer.c +183 -185
  69. data/ext/libxml/ruby_xml_writer.h +6 -6
  70. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  71. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  72. data/ext/libxml/ruby_xml_xpath.c +195 -195
  73. data/ext/libxml/ruby_xml_xpath.h +15 -15
  74. data/ext/libxml/ruby_xml_xpath_context.c +408 -362
  75. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  76. data/ext/libxml/ruby_xml_xpath_expression.c +12 -6
  77. data/ext/libxml/ruby_xml_xpath_expression.h +11 -10
  78. data/ext/libxml/ruby_xml_xpath_object.c +69 -54
  79. data/ext/libxml/ruby_xml_xpath_object.h +19 -17
  80. data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
  81. data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
  82. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  83. data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  84. data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
  85. data/lib/libxml/attr.rb +122 -122
  86. data/lib/libxml/attr_decl.rb +80 -80
  87. data/lib/libxml/attributes.rb +13 -13
  88. data/lib/libxml/document.rb +165 -194
  89. data/lib/libxml/error.rb +122 -95
  90. data/lib/libxml/html_parser.rb +80 -96
  91. data/lib/libxml/namespace.rb +61 -61
  92. data/lib/libxml/namespaces.rb +37 -37
  93. data/lib/libxml/node.rb +321 -323
  94. data/lib/libxml/parser.rb +94 -100
  95. data/lib/libxml/sax_callbacks.rb +179 -179
  96. data/lib/libxml/sax_parser.rb +40 -40
  97. data/lib/libxml/schema/attribute.rb +27 -19
  98. data/lib/libxml/schema/element.rb +20 -0
  99. data/lib/libxml/schema/type.rb +44 -21
  100. data/lib/libxml/schema.rb +47 -47
  101. data/lib/libxml/tree.rb +28 -28
  102. data/lib/libxml-ruby.rb +30 -30
  103. data/libxml-ruby.gemspec +46 -48
  104. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  105. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  106. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  107. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  108. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  109. data/test/c14n/result/with-comments/example-1 +5 -5
  110. data/test/c14n/result/with-comments/example-2 +10 -10
  111. data/test/c14n/result/with-comments/example-3 +13 -13
  112. data/test/c14n/result/with-comments/example-4 +8 -8
  113. data/test/c14n/result/with-comments/example-5 +3 -3
  114. data/test/c14n/result/without-comments/example-1 +3 -3
  115. data/test/c14n/result/without-comments/example-2 +10 -10
  116. data/test/c14n/result/without-comments/example-3 +13 -13
  117. data/test/c14n/result/without-comments/example-4 +8 -8
  118. data/test/c14n/result/without-comments/example-5 +2 -2
  119. data/test/test_attr.rb +179 -180
  120. data/test/test_attr_decl.rb +131 -131
  121. data/test/test_attributes.rb +135 -135
  122. data/test/test_canonicalize.rb +122 -120
  123. data/test/test_document.rb +138 -132
  124. data/test/test_document_write.rb +142 -145
  125. data/test/test_dtd.rb +134 -129
  126. data/test/test_encoding.rb +126 -129
  127. data/test/test_encoding_sax.rb +114 -114
  128. data/test/test_error.rb +197 -194
  129. data/test/test_helper.rb +21 -13
  130. data/test/test_html_parser.rb +166 -162
  131. data/test/test_html_parser_context.rb +22 -22
  132. data/test/test_input_callbacks.rb +36 -0
  133. data/test/test_namespace.rb +58 -60
  134. data/test/test_namespaces.rb +200 -200
  135. data/test/test_node.rb +251 -237
  136. data/test/test_node_cdata.rb +50 -50
  137. data/test/test_node_comment.rb +32 -32
  138. data/test/test_node_copy.rb +40 -40
  139. data/test/test_node_edit.rb +176 -158
  140. data/test/test_node_pi.rb +37 -37
  141. data/test/test_node_text.rb +69 -69
  142. data/test/test_node_write.rb +93 -96
  143. data/test/test_node_xlink.rb +28 -28
  144. data/test/test_parser.rb +297 -324
  145. data/test/test_parser_context.rb +198 -198
  146. data/test/test_properties.rb +38 -38
  147. data/test/test_reader.rb +413 -364
  148. data/test/test_relaxng.rb +59 -53
  149. data/test/test_sax_parser.rb +345 -326
  150. data/test/test_schema.rb +28 -0
  151. data/test/test_traversal.rb +152 -152
  152. data/test/test_writer.rb +469 -468
  153. data/test/test_xinclude.rb +20 -20
  154. data/test/test_xml.rb +164 -267
  155. data/test/test_xpath.rb +244 -244
  156. data/test/test_xpath_context.rb +87 -87
  157. data/test/test_xpath_expression.rb +37 -37
  158. metadata +49 -31
  159. data/README.rdoc +0 -217
  160. data/ext/libxml/extconf.h +0 -3
  161. data/ext/libxml/ruby_xml_cbg.c +0 -85
  162. data/lib/libxml/hpricot.rb +0 -78
  163. data/lib/libxml.rb +0 -5
  164. data/lib/xml/libxml.rb +0 -10
  165. data/lib/xml.rb +0 -14
  166. data/script/benchmark/depixelate +0 -634
  167. data/script/benchmark/hamlet.xml +0 -9055
  168. data/script/benchmark/parsecount +0 -170
  169. data/script/benchmark/sock_entries.xml +0 -507
  170. data/script/benchmark/throughput +0 -41
  171. data/script/test +0 -6
  172. data/test/test_deprecated_require.rb +0 -12
@@ -1,899 +1,556 @@
1
- #include "ruby_libxml.h"
2
- #include "ruby_xml.h"
3
-
4
- #include <libxml/catalog.h>
5
-
6
- VALUE mXML;
7
-
8
- /*
9
- * call-seq:
10
- * XML.catalog_dump -> true
11
- *
12
- * Dump all the global catalog content stdout.
13
- */
14
- static VALUE rxml_catalog_dump(VALUE self)
15
- {
16
- xmlCatalogDump(stdout);
17
- return (Qtrue);
18
- }
19
-
20
- /*
21
- * call-seq:
22
- * XML.catalog_remove(catalog) -> true
23
- *
24
- * Remove the specified resource catalog.
25
- */
26
- static VALUE rxml_catalog_remove(VALUE self, VALUE cat)
27
- {
28
- Check_Type(cat, T_STRING);
29
- xmlCatalogRemove((xmlChar *) StringValuePtr(cat));
30
- return (Qtrue);
31
- }
32
-
33
- /*
34
- * call-seq:
35
- * XML.check_lib_versions -> true
36
- *
37
- * Check LIBXML version matches version the bindings
38
- * were compiled to. Throws an exception if not.
39
- */
40
- static VALUE rxml_check_lib_versions(VALUE klass)
41
- {
42
- xmlCheckVersion(LIBXML_VERSION);
43
- return (Qtrue);
44
- }
45
-
46
- /*
47
- * call-seq:
48
- * XML.enabled_automata? -> (true|false)
49
- *
50
- * Determine whether libxml regexp automata support is enabled.
51
- */
52
- static VALUE rxml_enabled_automata_q(VALUE klass)
53
- {
54
- #ifdef LIBXML_AUTOMATA_ENABLED
55
- return(Qtrue);
56
- #else
57
- return (Qfalse);
58
- #endif
59
- }
60
-
61
- /*
62
- * call-seq:
63
- * XML.enabled_c14n? -> (true|false)
64
- *
65
- * Determine whether libxml 'canonical XML' support is enabled.
66
- * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
67
- */
68
- static VALUE rxml_enabled_c14n_q(VALUE klass)
69
- {
70
- #ifdef LIBXML_C14N_ENABLED
71
- return(Qtrue);
72
- #else
73
- return (Qfalse);
74
- #endif
75
- }
76
-
77
- /*
78
- * call-seq:
79
- * XML.enabled_catalog? -> (true|false)
80
- *
81
- * Determine whether libxml resource catalog support is enabled.
82
- */
83
- static VALUE rxml_enabled_catalog_q(VALUE klass)
84
- {
85
- #ifdef LIBXML_CATALOG_ENABLED
86
- return(Qtrue);
87
- #else
88
- return (Qfalse);
89
- #endif
90
- }
91
-
92
- /*
93
- * call-seq:
94
- * XML.enabled_debug? -> (true|false)
95
- *
96
- * Determine whether libxml debugging support is enabled.
97
- */
98
- static VALUE rxml_enabled_debug_q(VALUE klass)
99
- {
100
- #ifdef LIBXML_DEBUG_ENABLED
101
- return(Qtrue);
102
- #else
103
- return (Qfalse);
104
- #endif
105
- }
106
-
107
- /*
108
- * call-seq:
109
- * XML.enabled_docbook? -> (true|false)
110
- *
111
- * Determine whether libxml docbook support is enabled.
112
- */
113
- static VALUE rxml_enabled_docbook_q(VALUE klass)
114
- {
115
- #ifdef LIBXML_DOCB_ENABLED
116
- return(Qtrue);
117
- #else
118
- return (Qfalse);
119
- #endif
120
- }
121
-
122
- /*
123
- * call-seq:
124
- * XML.enabled_ftp? -> (true|false)
125
- *
126
- * Determine whether libxml ftp client support is enabled.
127
- */
128
- static VALUE rxml_enabled_ftp_q(VALUE klass)
129
- {
130
- #ifdef LIBXML_FTP_ENABLED
131
- return(Qtrue);
132
- #else
133
- return (Qfalse);
134
- #endif
135
- }
136
-
137
- /*
138
- * call-seq:
139
- * XML.enabled_http? -> (true|false)
140
- *
141
- * Determine whether libxml http client support is enabled.
142
- */
143
- static VALUE rxml_enabled_http_q(VALUE klass)
144
- {
145
- #ifdef LIBXML_HTTP_ENABLED
146
- return(Qtrue);
147
- #else
148
- return (Qfalse);
149
- #endif
150
- }
151
-
152
- /*
153
- * call-seq:
154
- * XML.enabled_html? -> (true|false)
155
- *
156
- * Determine whether libxml html support is enabled.
157
- */
158
- static VALUE rxml_enabled_html_q(VALUE klass)
159
- {
160
- #ifdef LIBXML_HTML_ENABLED
161
- return(Qtrue);
162
- #else
163
- return (Qfalse);
164
- #endif
165
- }
166
-
167
- /*
168
- * call-seq:
169
- * XML.enabled_iconv? -> (true|false)
170
- *
171
- * Determine whether libxml iconv support is enabled.
172
- */
173
- static VALUE rxml_enabled_iconv_q(VALUE klass)
174
- {
175
- #ifdef LIBXML_ICONV_ENABLED
176
- return(Qtrue);
177
- #else
178
- return (Qfalse);
179
- #endif
180
- }
181
-
182
- /*
183
- * call-seq:
184
- * XML.enabled_memory_debug? -> (true|false)
185
- *
186
- * Determine whether libxml memory location debugging support
187
- * is enabled.
188
- */
189
- static VALUE rxml_enabled_memory_debug_location_q(VALUE klass)
190
- {
191
- #ifdef DEBUG_MEMORY_LOCATION
192
- return(Qtrue);
193
- #else
194
- return (Qfalse);
195
- #endif
196
- }
197
-
198
- /*
199
- * call-seq:
200
- * XML.enabled_regexp? -> (true|false)
201
- *
202
- * Determine whether libxml regular expression support is enabled.
203
- */
204
- static VALUE rxml_enabled_regexp_q(VALUE klass)
205
- {
206
- #ifdef LIBXML_REGEXP_ENABLED
207
- return(Qtrue);
208
- #else
209
- return (Qfalse);
210
- #endif
211
- }
212
-
213
- /*
214
- * call-seq:
215
- * XML.enabled_schemas? -> (true|false)
216
- *
217
- * Determine whether libxml schema support is enabled.
218
- */
219
- static VALUE rxml_enabled_schemas_q(VALUE klass)
220
- {
221
- #ifdef LIBXML_SCHEMAS_ENABLED
222
- return(Qtrue);
223
- #else
224
- return (Qfalse);
225
- #endif
226
- }
227
-
228
- /*
229
- * call-seq:
230
- * XML.enabled_thread? -> (true|false)
231
- *
232
- * Determine whether thread-safe semantics support for libxml is enabled and
233
- * is used by this ruby extension. Threading support in libxml uses pthread
234
- * on Unix-like systems and Win32 threads on Windows.
235
- */
236
- static VALUE rxml_enabled_thread_q(VALUE klass)
237
- {
238
- /* This won't be defined unless this code is compiled with _REENTRANT or __MT__
239
- * defined or the compiler is in C99 mode.
240
- *
241
- * Note the relevant portion libxml/xmlversion.h on a thread-enabled build:
242
- *
243
- * #if defined(_REENTRANT) || defined(__MT__) || \
244
- * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L))
245
- * #define LIBXML_THREAD_ENABLED
246
- * #endif
247
- *
248
- */
249
- #ifdef LIBXML_THREAD_ENABLED
250
- return(Qtrue);
251
- #else
252
- return (Qfalse);
253
- #endif
254
- }
255
-
256
- /*
257
- * call-seq:
258
- * XML.enabled_unicode? -> (true|false)
259
- *
260
- * Determine whether libxml unicode support is enabled.
261
- */
262
- static VALUE rxml_enabled_unicode_q(VALUE klass)
263
- {
264
- #ifdef LIBXML_UNICODE_ENABLED
265
- return(Qtrue);
266
- #else
267
- return (Qfalse);
268
- #endif
269
- }
270
-
271
- /*
272
- * call-seq:
273
- * XML.enabled_xinclude? -> (true|false)
274
- *
275
- * Determine whether libxml xinclude support is enabled.
276
- */
277
- static VALUE rxml_enabled_xinclude_q(VALUE klass)
278
- {
279
- #ifdef LIBXML_XINCLUDE_ENABLED
280
- return(Qtrue);
281
- #else
282
- return (Qfalse);
283
- #endif
284
- }
285
-
286
- /*
287
- * call-seq:
288
- * XML.enabled_xpath? -> (true|false)
289
- *
290
- * Determine whether libxml xpath support is enabled.
291
- */
292
- static VALUE rxml_enabled_xpath_q(VALUE klass)
293
- {
294
- #ifdef LIBXML_XPATH_ENABLED
295
- return(Qtrue);
296
- #else
297
- return (Qfalse);
298
- #endif
299
- }
300
-
301
- /*
302
- * call-seq:
303
- * XML.enabled_xpointer? -> (true|false)
304
- *
305
- * Determine whether libxml xpointer support is enabled.
306
- */
307
- static VALUE rxml_enabled_xpointer_q(VALUE klass)
308
- {
309
- #ifdef LIBXML_XPTR_ENABLED
310
- return(Qtrue);
311
- #else
312
- return (Qfalse);
313
- #endif
314
- }
315
-
316
- /*
317
- * call-seq:
318
- * XML.enabled_zlib? -> (true|false)
319
- *
320
- * Determine whether libxml zlib support is enabled.
321
- */
322
- static VALUE rxml_enabled_zlib_q(VALUE klass)
323
- {
324
- #ifdef HAVE_ZLIB_H
325
- return(Qtrue);
326
- #else
327
- return (Qfalse);
328
- #endif
329
- }
330
-
331
- /*
332
- * call-seq:
333
- * XML.debug_entities -> (true|false)
334
- *
335
- * Determine whether included-entity debugging is enabled.
336
- * (Requires Libxml to be compiled with debugging support)
337
- */
338
- static VALUE rxml_debug_entities_get(VALUE klass)
339
- {
340
- #ifdef LIBXML_DEBUG_ENABLED
341
- if (xmlParserDebugEntities)
342
- return(Qtrue);
343
- else
344
- return(Qfalse);
345
- #else
346
- rb_warn("libxml was compiled with debugging turned off");
347
- return (Qfalse);
348
- #endif
349
- }
350
-
351
- /*
352
- * call-seq:
353
- * XML.debug_entities = true|false
354
- *
355
- * Enable or disable included-entity debugging.
356
- * (Requires Libxml to be compiled with debugging support)
357
- */
358
- static VALUE rxml_debug_entities_set(VALUE klass, VALUE value)
359
- {
360
- #ifdef LIBXML_DEBUG_ENABLED
361
- if (value == Qfalse)
362
- {
363
- xmlParserDebugEntities = 0;
364
- return(Qfalse);
365
- }
366
- else
367
- {
368
- xmlParserDebugEntities = 1;
369
- return(Qtrue);
370
- }
371
- #else
372
- rb_warn("libxml was compiled with debugging turned off");
373
- #endif
374
- }
375
-
376
- /*
377
- * call-seq:
378
- * XML.default_keep_blanks -> (true|false)
379
- *
380
- * Determine whether parsers retain whitespace by default.
381
- */
382
- static VALUE rxml_default_keep_blanks_get(VALUE klass)
383
- {
384
- if (xmlKeepBlanksDefaultValue)
385
- return (Qtrue);
386
- else
387
- return (Qfalse);
388
- }
389
-
390
- /*
391
- * call-seq:
392
- * XML.default_keep_blanks = true|false
393
- *
394
- * Controls whether parsers retain whitespace by default.
395
- */
396
- static VALUE rxml_default_keep_blanks_set(VALUE klass, VALUE value)
397
- {
398
- if (value == Qfalse)
399
- {
400
- xmlKeepBlanksDefaultValue = 0;
401
- return (Qfalse);
402
- }
403
- else if (value == Qtrue)
404
- {
405
- xmlKeepBlanksDefaultValue = 1;
406
- return (Qtrue);
407
- }
408
- else
409
- {
410
- rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
411
- }
412
- }
413
-
414
- /*
415
- * call-seq:
416
- * XML.default_load_external_dtd -> (true|false)
417
- *
418
- * Determine whether parsers load external DTDs by default.
419
- */
420
- static VALUE rxml_default_load_external_dtd_get(VALUE klass)
421
- {
422
- if (xmlLoadExtDtdDefaultValue)
423
- return (Qtrue);
424
- else
425
- return (Qfalse);
426
- }
427
-
428
- /*
429
- * call-seq:
430
- * XML.default_load_external_dtd = true|false
431
- *
432
- * Controls whether parsers load external DTDs by default.
433
- */
434
- static VALUE rxml_default_load_external_dtd_set(VALUE klass, VALUE value)
435
- {
436
- if (value == Qfalse)
437
- {
438
- xmlLoadExtDtdDefaultValue = 0;
439
- return (Qfalse);
440
- }
441
- else
442
- {
443
- xmlLoadExtDtdDefaultValue = 1;
444
- return (Qtrue);
445
- }
446
- }
447
-
448
- /*
449
- * call-seq:
450
- * XML.default_line_numbers -> (true|false)
451
- *
452
- * Determine whether parsers retain line-numbers by default.
453
- */
454
- static VALUE rxml_default_line_numbers_get(VALUE klass)
455
- {
456
- if (xmlLineNumbersDefaultValue)
457
- return (Qtrue);
458
- else
459
- return (Qfalse);
460
- }
461
-
462
- /*
463
- * call-seq:
464
- * XML.default_line_numbers = true|false
465
- *
466
- * Controls whether parsers retain line-numbers by default.
467
- */
468
- static VALUE rxml_default_line_numbers_set(VALUE klass, VALUE value)
469
- {
470
- if (value == Qfalse)
471
- {
472
- xmlLineNumbersDefault(0);
473
- return (Qfalse);
474
- }
475
- else
476
- {
477
- xmlLineNumbersDefault(1);
478
- return (Qtrue);
479
- }
480
- }
481
-
482
- int rxml_libxml_default_options(void)
483
- {
484
- int options = 0;
485
-
486
- if (xmlLoadExtDtdDefaultValue)
487
- options |= XML_PARSE_DTDLOAD;
488
-
489
- if (xmlDoValidityCheckingDefaultValue)
490
- options |= XML_PARSE_DTDVALID;
491
-
492
- if (!xmlKeepBlanksDefaultValue)
493
- options |= XML_PARSE_NOBLANKS;
494
-
495
- if (xmlSubstituteEntitiesDefaultValue)
496
- options |= XML_PARSE_NOENT;
497
-
498
- if (!xmlGetWarningsDefaultValue)
499
- options |= XML_PARSE_NOWARNING;
500
-
501
- if (xmlPedanticParserDefaultValue)
502
- options |= XML_PARSE_PEDANTIC;
503
-
504
- return options;
505
- }
506
-
507
- /*
508
- * call-seq:
509
- * XML.default_options -> int
510
- *
511
- * Returns an integer that summarize libxml2's default options.
512
- */
513
- static VALUE rxml_default_options_get(VALUE klass)
514
- {
515
- int options = rxml_libxml_default_options();
516
- return INT2NUM(options);
517
- }
518
-
519
- /*
520
- * call-seq:
521
- * XML.default_pedantic_parser -> (true|false)
522
- *
523
- * Determine whether parsers are pedantic by default.
524
- */
525
- static VALUE rxml_default_pedantic_parser_get(VALUE klass)
526
- {
527
- if (xmlPedanticParserDefaultValue)
528
- return (Qtrue);
529
- else
530
- return (Qfalse);
531
- }
532
-
533
- /*
534
- * call-seq:
535
- * XML.default_pedantic_parser = true|false
536
- *
537
- * Controls whether parsers are pedantic by default.
538
- */
539
- static VALUE rxml_default_pedantic_parser_set(VALUE klass, VALUE value)
540
- {
541
- if (value == Qfalse)
542
- {
543
- xmlPedanticParserDefault(0);
544
- return (Qfalse);
545
- }
546
- else
547
- {
548
- xmlPedanticParserDefault(1);
549
- return (Qtrue);
550
- }
551
- }
552
-
553
- /*
554
- * call-seq:
555
- * XML.default_substitute_entities -> (true|false)
556
- *
557
- * Determine whether parsers perform inline entity substitution
558
- * (for external entities) by default.
559
- */
560
- static VALUE rxml_default_substitute_entities_get(VALUE klass)
561
- {
562
- if (xmlSubstituteEntitiesDefaultValue)
563
- return (Qtrue);
564
- else
565
- return (Qfalse);
566
- }
567
-
568
- /*
569
- * call-seq:
570
- * XML.default_substitute_entities = true|false
571
- *
572
- * Controls whether parsers perform inline entity substitution
573
- * (for external entities) by default.
574
- */
575
- static VALUE rxml_default_substitute_entities_set(VALUE klass, VALUE value)
576
- {
577
- if (value == Qfalse)
578
- {
579
- xmlSubstituteEntitiesDefault(0);
580
- return (Qfalse);
581
- }
582
- else
583
- {
584
- xmlSubstituteEntitiesDefault(1);
585
- return (Qtrue);
586
- }
587
- }
588
-
589
- /*
590
- * call-seq:
591
- * XML.default_tree_indent_string -> "string"
592
- *
593
- * Obtain the default string used by parsers to indent the XML tree
594
- * for output.
595
- */
596
- static VALUE rxml_default_tree_indent_string_get(VALUE klass)
597
- {
598
- if (xmlTreeIndentString == NULL)
599
- return (Qnil);
600
- else
601
- return (rb_str_new2(xmlTreeIndentString));
602
- }
603
-
604
- /*
605
- * call-seq:
606
- * XML.default_tree_indent_string = "string"
607
- *
608
- * Set the default string used by parsers to indent the XML tree
609
- * for output.
610
- */
611
- static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
612
- {
613
- Check_Type(string, T_STRING);
614
- xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string));
615
- return (string);
616
- }
617
-
618
- /*
619
- * call-seq:
620
- * XML.default_validity_checking -> (true|false)
621
- *
622
- * Determine whether parsers perform XML validation by default.
623
- */
624
- static VALUE rxml_default_validity_checking_get(VALUE klass)
625
- {
626
- if (xmlDoValidityCheckingDefaultValue)
627
- return (Qtrue);
628
- else
629
- return (Qfalse);
630
- }
631
-
632
- /*
633
- * call-seq:
634
- * XML.default_validity_checking = true|false
635
- *
636
- * Controls whether parsers perform XML validation by default.
637
- */
638
- static VALUE rxml_default_validity_checking_set(VALUE klass, VALUE value)
639
- {
640
- if (value == Qfalse)
641
- {
642
- xmlDoValidityCheckingDefaultValue = 0;
643
- return (Qfalse);
644
- }
645
- else
646
- {
647
- xmlDoValidityCheckingDefaultValue = 1;
648
- return (Qtrue);
649
- }
650
- }
651
-
652
- /*
653
- * call-seq:
654
- * XML.default_warnings -> (true|false)
655
- *
656
- * Determine whether parsers output warnings by default.
657
- */
658
- static VALUE rxml_default_warnings_get(VALUE klass)
659
- {
660
- if (xmlGetWarningsDefaultValue)
661
- return (Qtrue);
662
- else
663
- return (Qfalse);
664
- }
665
-
666
- /*
667
- * call-seq:
668
- * XML.default_warnings = true|false
669
- *
670
- * Controls whether parsers output warnings by default.
671
- */
672
- static VALUE rxml_default_warnings_set(VALUE klass, VALUE value)
673
- {
674
- if (value == Qfalse)
675
- {
676
- xmlGetWarningsDefaultValue = 0;
677
- return (Qfalse);
678
- }
679
- else
680
- {
681
- xmlGetWarningsDefaultValue = 1;
682
- return (Qtrue);
683
- }
684
- }
685
-
686
- /*
687
- * call-seq:
688
- * XML.default_compression -> (true|false)
689
- *
690
- * Determine whether parsers use Zlib compression by default
691
- * (requires libxml to be compiled with Zlib support).
692
- */
693
- static VALUE rxml_default_compression_get(VALUE klass)
694
- {
695
- #ifdef HAVE_ZLIB_H
696
- return(INT2FIX(xmlGetCompressMode()));
697
- #else
698
- rb_warn("libxml was compiled without zlib support");
699
- return (Qfalse);
700
- #endif
701
- }
702
-
703
- /*
704
- * call-seq:
705
- * XML.default_compression = true|false
706
- *
707
- * Controls whether parsers use Zlib compression by default
708
- * (requires libxml to be compiled with Zlib support).
709
- */
710
- static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
711
- {
712
- #ifdef HAVE_ZLIB_H
713
- Check_Type(num, T_FIXNUM);
714
- xmlSetCompressMode(FIX2INT(num));
715
- return(num);
716
- #else
717
- rb_warn("libxml was compiled without zlib support");
718
- return (Qfalse);
719
- #endif
720
- }
721
-
722
- /*
723
- * call-seq:
724
- * XML.default_save_no_empty_tags -> (true|false)
725
- *
726
- * Determine whether serializer outputs empty tags by default.
727
- */
728
- static VALUE rxml_default_save_no_empty_tags_get(VALUE klass)
729
- {
730
- if (xmlSaveNoEmptyTags)
731
- return (Qtrue);
732
- else
733
- return (Qfalse);
734
- }
735
-
736
- /*
737
- * call-seq:
738
- * XML.default_save_no_empty_tags = true|false
739
- *
740
- * Controls whether serializer outputs empty tags by default.
741
- */
742
- static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value)
743
- {
744
- if (value == Qfalse)
745
- {
746
- xmlSaveNoEmptyTags = 0;
747
- return (Qfalse);
748
- }
749
- else if (value == Qtrue)
750
- {
751
- xmlSaveNoEmptyTags = 1;
752
- return (Qtrue);
753
- }
754
- else
755
- {
756
- rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
757
- }
758
- }
759
-
760
- /*
761
- * call-seq:
762
- * XML.indent_tree_output -> (true|false)
763
- *
764
- * Determines whether XML output will be indented
765
- * (using the string supplied to +default_indent_tree_string+)
766
- */
767
- static VALUE rxml_indent_tree_output_get(VALUE klass)
768
- {
769
- if (xmlIndentTreeOutput)
770
- return (Qtrue);
771
- else
772
- return (Qfalse);
773
- }
774
-
775
- /*
776
- * call-seq:
777
- * XML.indent_tree_output = true|false
778
- *
779
- * Controls whether XML output will be indented
780
- * (using the string supplied to +default_indent_tree_string+)
781
- */
782
- static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value)
783
- {
784
- if (value == Qtrue)
785
- {
786
- xmlIndentTreeOutput = 1;
787
- return (Qtrue);
788
- }
789
- else if (value == Qfalse)
790
- {
791
- xmlIndentTreeOutput = 0;
792
- return (Qfalse);
793
- }
794
- else
795
- {
796
- rb_raise(rb_eArgError, "Invalid argument, must be boolean");
797
- }
798
- }
799
-
800
- /*
801
- * call-seq:
802
- * XML.memory_dump -> (true|false)
803
- *
804
- * Perform a parser memory dump (requires memory debugging
805
- * support in libxml).
806
- */
807
- static VALUE rxml_memory_dump(VALUE self)
808
- {
809
- #ifdef DEBUG_MEMORY_LOCATION
810
- xmlMemoryDump();
811
- return(Qtrue);
812
- #else
813
- rb_warn("libxml was compiled without memory debugging support");
814
- return (Qfalse);
815
- #endif
816
- }
817
-
818
- /*
819
- * call-seq:
820
- * XML.memory_used -> num_bytes
821
- *
822
- * Perform a parser memory dump (requires memory debugging
823
- * support in libxml).
824
- */
825
- static VALUE rxml_memory_used(VALUE self)
826
- {
827
- #ifdef DEBUG_MEMORY_LOCATION
828
- return(INT2NUM(xmlMemUsed()));
829
- #else
830
- rb_warn("libxml was compiled without memory debugging support");
831
- return (Qfalse);
832
- #endif
833
- }
834
-
835
- /* The libxml gem provides Ruby language bindings for GNOME's Libxml2
836
- * XML toolkit. Refer to the README file to get started
837
- * and the LICENSE file for copyright and distribution information.
838
- */
839
-
840
- void rxml_init_xml(void)
841
- {
842
- mXML = rb_define_module_under(mLibXML, "XML");
843
-
844
- /* Constants */
845
- rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
846
- rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
847
- rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
848
- rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE));
849
-
850
- rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0);
851
- rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0);
852
- rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0);
853
- rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0);
854
- rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0);
855
- rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0);
856
- rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0);
857
- rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0);
858
- rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0);
859
- rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0);
860
- rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0);
861
- rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0);
862
- rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0);
863
- rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0);
864
- rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0);
865
- rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0);
866
- rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0);
867
- rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0);
868
-
869
- rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0);
870
- rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1);
871
- rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0);
872
- rb_define_module_function(mXML, "debug_entities", rxml_debug_entities_get, 0);
873
- rb_define_module_function(mXML, "debug_entities=", rxml_debug_entities_set, 1);
874
- rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0);
875
- rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1);
876
- rb_define_module_function(mXML, "default_keep_blanks", rxml_default_keep_blanks_get, 0);
877
- rb_define_module_function(mXML, "default_keep_blanks=", rxml_default_keep_blanks_set, 1);
878
- rb_define_module_function(mXML, "default_load_external_dtd", rxml_default_load_external_dtd_get, 0);
879
- rb_define_module_function(mXML, "default_load_external_dtd=", rxml_default_load_external_dtd_set, 1);
880
- rb_define_module_function(mXML, "default_line_numbers", rxml_default_line_numbers_get, 0);
881
- rb_define_module_function(mXML, "default_line_numbers=", rxml_default_line_numbers_set, 1);
882
- rb_define_module_function(mXML, "default_options", rxml_default_options_get, 0);
883
- rb_define_module_function(mXML, "default_pedantic_parser", rxml_default_pedantic_parser_get, 0);
884
- rb_define_module_function(mXML, "default_pedantic_parser=", rxml_default_pedantic_parser_set, 1);
885
- rb_define_module_function(mXML, "default_substitute_entities", rxml_default_substitute_entities_get, 0);
886
- rb_define_module_function(mXML, "default_substitute_entities=", rxml_default_substitute_entities_set, 1);
887
- rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0);
888
- rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1);
889
- rb_define_module_function(mXML, "default_validity_checking", rxml_default_validity_checking_get, 0);
890
- rb_define_module_function(mXML, "default_validity_checking=", rxml_default_validity_checking_set, 1);
891
- rb_define_module_function(mXML, "default_warnings", rxml_default_warnings_get, 0);
892
- rb_define_module_function(mXML, "default_warnings=", rxml_default_warnings_set, 1);
893
- rb_define_module_function(mXML, "default_save_no_empty_tags", rxml_default_save_no_empty_tags_get, 0);
894
- rb_define_module_function(mXML, "default_save_no_empty_tags=", rxml_default_save_no_empty_tags_set, 1);
895
- rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
896
- rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
897
- rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0);
898
- rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0);
899
- }
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml.h"
3
+
4
+ #include <libxml/catalog.h>
5
+
6
+ VALUE mXML;
7
+
8
+ /*
9
+ * call-seq:
10
+ * XML.catalog_dump -> true
11
+ *
12
+ * Dump all the global catalog content stdout.
13
+ */
14
+ static VALUE rxml_catalog_dump(VALUE self)
15
+ {
16
+ xmlCatalogDump(stdout);
17
+ return (Qtrue);
18
+ }
19
+
20
+ /*
21
+ * call-seq:
22
+ * XML.catalog_remove(catalog) -> true
23
+ *
24
+ * Remove the specified resource catalog.
25
+ */
26
+ static VALUE rxml_catalog_remove(VALUE self, VALUE cat)
27
+ {
28
+ Check_Type(cat, T_STRING);
29
+ xmlCatalogRemove((xmlChar *) StringValuePtr(cat));
30
+ return (Qtrue);
31
+ }
32
+
33
+ /*
34
+ * call-seq:
35
+ * XML.check_lib_versions -> true
36
+ *
37
+ * Check LIBXML version matches version the bindings
38
+ * were compiled to. Throws an exception if not.
39
+ */
40
+ static VALUE rxml_check_lib_versions(VALUE klass)
41
+ {
42
+ xmlCheckVersion(LIBXML_VERSION);
43
+ return (Qtrue);
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * XML.enabled_automata? -> (true|false)
49
+ *
50
+ * Determine whether libxml regexp automata support is enabled.
51
+ */
52
+ static VALUE rxml_enabled_automata_q(VALUE klass)
53
+ {
54
+ #ifdef LIBXML_AUTOMATA_ENABLED
55
+ return(Qtrue);
56
+ #else
57
+ return (Qfalse);
58
+ #endif
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * XML.enabled_c14n? -> (true|false)
64
+ *
65
+ * Determine whether libxml 'canonical XML' support is enabled.
66
+ * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
67
+ */
68
+ static VALUE rxml_enabled_c14n_q(VALUE klass)
69
+ {
70
+ #ifdef LIBXML_C14N_ENABLED
71
+ return(Qtrue);
72
+ #else
73
+ return (Qfalse);
74
+ #endif
75
+ }
76
+
77
+ /*
78
+ * call-seq:
79
+ * XML.enabled_catalog? -> (true|false)
80
+ *
81
+ * Determine whether libxml resource catalog support is enabled.
82
+ */
83
+ static VALUE rxml_enabled_catalog_q(VALUE klass)
84
+ {
85
+ #ifdef LIBXML_CATALOG_ENABLED
86
+ return(Qtrue);
87
+ #else
88
+ return (Qfalse);
89
+ #endif
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * XML.enabled_debug? -> (true|false)
95
+ *
96
+ * Determine whether libxml debugging support is enabled.
97
+ */
98
+ static VALUE rxml_enabled_debug_q(VALUE klass)
99
+ {
100
+ #ifdef LIBXML_DEBUG_ENABLED
101
+ return(Qtrue);
102
+ #else
103
+ return (Qfalse);
104
+ #endif
105
+ }
106
+
107
+ /*
108
+ * call-seq:
109
+ * XML.enabled_docbook? -> (true|false)
110
+ *
111
+ * Determine whether libxml docbook support is enabled.
112
+ */
113
+ static VALUE rxml_enabled_docbook_q(VALUE klass)
114
+ {
115
+ #ifdef LIBXML_DOCB_ENABLED
116
+ return(Qtrue);
117
+ #else
118
+ return (Qfalse);
119
+ #endif
120
+ }
121
+
122
+ /*
123
+ * call-seq:
124
+ * XML.enabled_ftp? -> (true|false)
125
+ *
126
+ * Determine whether libxml ftp client support is enabled.
127
+ */
128
+ static VALUE rxml_enabled_ftp_q(VALUE klass)
129
+ {
130
+ #ifdef LIBXML_FTP_ENABLED
131
+ return(Qtrue);
132
+ #else
133
+ return (Qfalse);
134
+ #endif
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * XML.enabled_http? -> (true|false)
140
+ *
141
+ * Determine whether libxml http client support is enabled.
142
+ */
143
+ static VALUE rxml_enabled_http_q(VALUE klass)
144
+ {
145
+ #ifdef LIBXML_HTTP_ENABLED
146
+ return(Qtrue);
147
+ #else
148
+ return (Qfalse);
149
+ #endif
150
+ }
151
+
152
+ /*
153
+ * call-seq:
154
+ * XML.enabled_html? -> (true|false)
155
+ *
156
+ * Determine whether libxml html support is enabled.
157
+ */
158
+ static VALUE rxml_enabled_html_q(VALUE klass)
159
+ {
160
+ #ifdef LIBXML_HTML_ENABLED
161
+ return(Qtrue);
162
+ #else
163
+ return (Qfalse);
164
+ #endif
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * XML.enabled_iconv? -> (true|false)
170
+ *
171
+ * Determine whether libxml iconv support is enabled.
172
+ */
173
+ static VALUE rxml_enabled_iconv_q(VALUE klass)
174
+ {
175
+ #ifdef LIBXML_ICONV_ENABLED
176
+ return(Qtrue);
177
+ #else
178
+ return (Qfalse);
179
+ #endif
180
+ }
181
+
182
+ /*
183
+ * call-seq:
184
+ * XML.enabled_memory_debug? -> (true|false)
185
+ *
186
+ * Determine whether libxml memory location debugging support
187
+ * is enabled.
188
+ */
189
+ static VALUE rxml_enabled_memory_debug_location_q(VALUE klass)
190
+ {
191
+ #ifdef DEBUG_MEMORY_LOCATION
192
+ return(Qtrue);
193
+ #else
194
+ return (Qfalse);
195
+ #endif
196
+ }
197
+
198
+ /*
199
+ * call-seq:
200
+ * XML.enabled_regexp? -> (true|false)
201
+ *
202
+ * Determine whether libxml regular expression support is enabled.
203
+ */
204
+ static VALUE rxml_enabled_regexp_q(VALUE klass)
205
+ {
206
+ #ifdef LIBXML_REGEXP_ENABLED
207
+ return(Qtrue);
208
+ #else
209
+ return (Qfalse);
210
+ #endif
211
+ }
212
+
213
+ /*
214
+ * call-seq:
215
+ * XML.enabled_schemas? -> (true|false)
216
+ *
217
+ * Determine whether libxml schema support is enabled.
218
+ */
219
+ static VALUE rxml_enabled_schemas_q(VALUE klass)
220
+ {
221
+ #ifdef LIBXML_SCHEMAS_ENABLED
222
+ return(Qtrue);
223
+ #else
224
+ return (Qfalse);
225
+ #endif
226
+ }
227
+
228
+ /*
229
+ * call-seq:
230
+ * XML.enabled_thread? -> (true|false)
231
+ *
232
+ * Determine whether thread-safe semantics support for libxml is enabled and
233
+ * is used by this ruby extension. Threading support in libxml uses pthread
234
+ * on Unix-like systems and Win32 threads on Windows.
235
+ */
236
+ static VALUE rxml_enabled_thread_q(VALUE klass)
237
+ {
238
+ /* This won't be defined unless this code is compiled with _REENTRANT or __MT__
239
+ * defined or the compiler is in C99 mode.
240
+ *
241
+ * Note the relevant portion libxml/xmlversion.h on a thread-enabled build:
242
+ *
243
+ * #if defined(_REENTRANT) || defined(__MT__) || \
244
+ * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L))
245
+ * #define LIBXML_THREAD_ENABLED
246
+ * #endif
247
+ *
248
+ */
249
+ #ifdef LIBXML_THREAD_ENABLED
250
+ return(Qtrue);
251
+ #else
252
+ return (Qfalse);
253
+ #endif
254
+ }
255
+
256
+ /*
257
+ * call-seq:
258
+ * XML.enabled_unicode? -> (true|false)
259
+ *
260
+ * Determine whether libxml unicode support is enabled.
261
+ */
262
+ static VALUE rxml_enabled_unicode_q(VALUE klass)
263
+ {
264
+ #ifdef LIBXML_UNICODE_ENABLED
265
+ return(Qtrue);
266
+ #else
267
+ return (Qfalse);
268
+ #endif
269
+ }
270
+
271
+ /*
272
+ * call-seq:
273
+ * XML.enabled_xinclude? -> (true|false)
274
+ *
275
+ * Determine whether libxml xinclude support is enabled.
276
+ */
277
+ static VALUE rxml_enabled_xinclude_q(VALUE klass)
278
+ {
279
+ #ifdef LIBXML_XINCLUDE_ENABLED
280
+ return(Qtrue);
281
+ #else
282
+ return (Qfalse);
283
+ #endif
284
+ }
285
+
286
+ /*
287
+ * call-seq:
288
+ * XML.enabled_xpath? -> (true|false)
289
+ *
290
+ * Determine whether libxml xpath support is enabled.
291
+ */
292
+ static VALUE rxml_enabled_xpath_q(VALUE klass)
293
+ {
294
+ #ifdef LIBXML_XPATH_ENABLED
295
+ return(Qtrue);
296
+ #else
297
+ return (Qfalse);
298
+ #endif
299
+ }
300
+
301
+ /*
302
+ * call-seq:
303
+ * XML.enabled_xpointer? -> (true|false)
304
+ *
305
+ * Determine whether libxml xpointer support is enabled.
306
+ */
307
+ static VALUE rxml_enabled_xpointer_q(VALUE klass)
308
+ {
309
+ #ifdef LIBXML_XPTR_ENABLED
310
+ return(Qtrue);
311
+ #else
312
+ return (Qfalse);
313
+ #endif
314
+ }
315
+
316
+ /*
317
+ * call-seq:
318
+ * XML.enabled_zlib? -> (true|false)
319
+ *
320
+ * Determine whether libxml zlib support is enabled.
321
+ */
322
+ static VALUE rxml_enabled_zlib_q(VALUE klass)
323
+ {
324
+ #ifdef HAVE_ZLIB_H
325
+ return(Qtrue);
326
+ #else
327
+ return (Qfalse);
328
+ #endif
329
+ }
330
+
331
+ /*
332
+ * call-seq:
333
+ * XML.default_tree_indent_string -> "string"
334
+ *
335
+ * Obtain the default string used by parsers to indent the XML tree
336
+ * for output.
337
+ */
338
+ static VALUE rxml_default_tree_indent_string_get(VALUE klass)
339
+ {
340
+ if (xmlTreeIndentString == NULL)
341
+ return (Qnil);
342
+ else
343
+ return (rb_str_new2(xmlTreeIndentString));
344
+ }
345
+
346
+ /*
347
+ * call-seq:
348
+ * XML.default_tree_indent_string = "string"
349
+ *
350
+ * Set the default string used by parsers to indent the XML tree
351
+ * for output.
352
+ */
353
+ static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
354
+ {
355
+ Check_Type(string, T_STRING);
356
+ xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string));
357
+ return (string);
358
+ }
359
+
360
+ /*
361
+ * call-seq:
362
+ * XML.default_compression -> (true|false)
363
+ *
364
+ * Determine whether parsers use Zlib compression by default
365
+ * (requires libxml to be compiled with Zlib support).
366
+ */
367
+ static VALUE rxml_default_compression_get(VALUE klass)
368
+ {
369
+ #ifdef HAVE_ZLIB_H
370
+ return(INT2FIX(xmlGetCompressMode()));
371
+ #else
372
+ rb_warn("libxml was compiled without zlib support");
373
+ return (Qfalse);
374
+ #endif
375
+ }
376
+
377
+ /*
378
+ * call-seq:
379
+ * XML.default_compression = true|false
380
+ *
381
+ * Controls whether parsers use Zlib compression by default
382
+ * (requires libxml to be compiled with Zlib support).
383
+ */
384
+ static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
385
+ {
386
+ #ifdef HAVE_ZLIB_H
387
+ Check_Type(num, T_FIXNUM);
388
+ xmlSetCompressMode(FIX2INT(num));
389
+ return(num);
390
+ #else
391
+ rb_warn("libxml was compiled without zlib support");
392
+ return (Qfalse);
393
+ #endif
394
+ }
395
+
396
+ /*
397
+ * call-seq:
398
+ * XML.default_save_no_empty_tags -> (true|false)
399
+ *
400
+ * Determine whether serializer outputs empty tags by default.
401
+ */
402
+ static VALUE rxml_default_save_no_empty_tags_get(VALUE klass)
403
+ {
404
+ if (xmlSaveNoEmptyTags)
405
+ return (Qtrue);
406
+ else
407
+ return (Qfalse);
408
+ }
409
+
410
+ /*
411
+ * call-seq:
412
+ * XML.default_save_no_empty_tags = true|false
413
+ *
414
+ * Controls whether serializer outputs empty tags by default.
415
+ */
416
+ static VALUE rxml_default_save_no_empty_tags_set(VALUE klass, VALUE value)
417
+ {
418
+ if (value == Qfalse)
419
+ {
420
+ xmlSaveNoEmptyTags = 0;
421
+ return (Qfalse);
422
+ }
423
+ else if (value == Qtrue)
424
+ {
425
+ xmlSaveNoEmptyTags = 1;
426
+ return (Qtrue);
427
+ }
428
+ else
429
+ {
430
+ rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
431
+ }
432
+ }
433
+
434
+ /*
435
+ * call-seq:
436
+ * XML.indent_tree_output -> (true|false)
437
+ *
438
+ * Determines whether XML output will be indented
439
+ * (using the string supplied to +default_indent_tree_string+)
440
+ */
441
+ static VALUE rxml_indent_tree_output_get(VALUE klass)
442
+ {
443
+ if (xmlIndentTreeOutput)
444
+ return (Qtrue);
445
+ else
446
+ return (Qfalse);
447
+ }
448
+
449
+ /*
450
+ * call-seq:
451
+ * XML.indent_tree_output = true|false
452
+ *
453
+ * Controls whether XML output will be indented
454
+ * (using the string supplied to +default_indent_tree_string+)
455
+ */
456
+ static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value)
457
+ {
458
+ if (value == Qtrue)
459
+ {
460
+ xmlIndentTreeOutput = 1;
461
+ return (Qtrue);
462
+ }
463
+ else if (value == Qfalse)
464
+ {
465
+ xmlIndentTreeOutput = 0;
466
+ return (Qfalse);
467
+ }
468
+ else
469
+ {
470
+ rb_raise(rb_eArgError, "Invalid argument, must be boolean");
471
+ }
472
+ }
473
+
474
+ /*
475
+ * call-seq:
476
+ * XML.memory_dump -> (true|false)
477
+ *
478
+ * Perform a parser memory dump (requires memory debugging
479
+ * support in libxml).
480
+ */
481
+ static VALUE rxml_memory_dump(VALUE self)
482
+ {
483
+ #ifdef DEBUG_MEMORY_LOCATION
484
+ xmlMemoryDump();
485
+ return(Qtrue);
486
+ #else
487
+ rb_warn("libxml was compiled without memory debugging support");
488
+ return (Qfalse);
489
+ #endif
490
+ }
491
+
492
+ /*
493
+ * call-seq:
494
+ * XML.memory_used -> num_bytes
495
+ *
496
+ * Perform a parser memory dump (requires memory debugging
497
+ * support in libxml).
498
+ */
499
+ static VALUE rxml_memory_used(VALUE self)
500
+ {
501
+ #ifdef DEBUG_MEMORY_LOCATION
502
+ return(INT2NUM(xmlMemUsed()));
503
+ #else
504
+ rb_warn("libxml was compiled without memory debugging support");
505
+ return (Qfalse);
506
+ #endif
507
+ }
508
+
509
+ /* The libxml gem provides Ruby language bindings for GNOME's Libxml2
510
+ * XML toolkit. Refer to the README file to get started
511
+ * and the LICENSE file for copyright and distribution information.
512
+ */
513
+
514
+ void rxml_init_xml(void)
515
+ {
516
+ mXML = rb_define_module_under(mLibXML, "XML");
517
+
518
+ /* Constants */
519
+ rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
520
+ rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
521
+ rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
522
+ rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE));
523
+
524
+ rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0);
525
+ rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0);
526
+ rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0);
527
+ rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0);
528
+ rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0);
529
+ rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0);
530
+ rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0);
531
+ rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0);
532
+ rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0);
533
+ rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0);
534
+ rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0);
535
+ rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0);
536
+ rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0);
537
+ rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0);
538
+ rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0);
539
+ rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0);
540
+ rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0);
541
+ rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0);
542
+
543
+ rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0);
544
+ rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1);
545
+ rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0);
546
+ rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0);
547
+ rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1);
548
+ rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0);
549
+ rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1);
550
+ rb_define_module_function(mXML, "default_save_no_empty_tags", rxml_default_save_no_empty_tags_get, 0);
551
+ rb_define_module_function(mXML, "default_save_no_empty_tags=", rxml_default_save_no_empty_tags_set, 1);
552
+ rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
553
+ rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
554
+ rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0);
555
+ rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0);
556
+ }