libxml-ruby 5.0.4 → 5.0.5

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +10 -6
  3. data/README.rdoc +1 -1
  4. data/ext/libxml/extconf.rb +5 -0
  5. data/ext/libxml/ruby_xml.c +556 -556
  6. data/ext/libxml/ruby_xml_attributes.h +17 -17
  7. data/ext/libxml/ruby_xml_document.c +1129 -1129
  8. data/ext/libxml/ruby_xml_dtd.c +257 -257
  9. data/ext/libxml/ruby_xml_encoding.c +250 -250
  10. data/ext/libxml/ruby_xml_error.c +1003 -1003
  11. data/ext/libxml/ruby_xml_error.h +14 -14
  12. data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
  13. data/ext/libxml/ruby_xml_input_cbg.c +188 -188
  14. data/ext/libxml/ruby_xml_namespace.c +151 -151
  15. data/ext/libxml/ruby_xml_parser.h +10 -10
  16. data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
  17. data/ext/libxml/ruby_xml_parser_options.c +74 -74
  18. data/ext/libxml/ruby_xml_parser_options.h +10 -10
  19. data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
  20. data/ext/libxml/ruby_xml_sax_parser.c +108 -108
  21. data/ext/libxml/ruby_xml_version.h +9 -9
  22. data/lib/libxml/attr.rb +122 -122
  23. data/lib/libxml/attr_decl.rb +80 -80
  24. data/lib/libxml/attributes.rb +13 -13
  25. data/lib/libxml/document.rb +194 -194
  26. data/lib/libxml/error.rb +95 -95
  27. data/lib/libxml/hpricot.rb +77 -77
  28. data/lib/libxml/html_parser.rb +96 -96
  29. data/lib/libxml/namespace.rb +61 -61
  30. data/lib/libxml/namespaces.rb +37 -37
  31. data/lib/libxml/node.rb +323 -323
  32. data/lib/libxml/parser.rb +102 -102
  33. data/lib/libxml/sax_callbacks.rb +179 -179
  34. data/lib/libxml/sax_parser.rb +40 -40
  35. data/lib/libxml/tree.rb +28 -28
  36. data/lib/libxml.rb +4 -4
  37. data/lib/xml/libxml.rb +10 -10
  38. data/lib/xml.rb +13 -13
  39. data/libxml-ruby.gemspec +50 -49
  40. data/test/test_document.rb +140 -140
  41. data/test/test_document_write.rb +142 -142
  42. data/test/test_dtd.rb +126 -126
  43. data/test/test_encoding.rb +126 -126
  44. data/test/test_error.rb +194 -194
  45. data/test/test_helper.rb +20 -20
  46. data/test/test_namespace.rb +58 -58
  47. data/test/test_node.rb +235 -235
  48. data/test/test_node_write.rb +93 -93
  49. data/test/test_parser.rb +333 -333
  50. data/test/test_reader.rb +364 -364
  51. data/test/test_xml.rb +168 -168
  52. metadata +5 -4
@@ -1,556 +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.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
- }
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
+ }