libxml-ruby 2.7.0 → 2.9.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 (85) hide show
  1. checksums.yaml +6 -14
  2. data/HISTORY +33 -11
  3. data/README.rdoc +7 -7
  4. data/Rakefile +80 -77
  5. data/ext/libxml/extconf.h +4 -5
  6. data/ext/libxml/extconf.rb +57 -118
  7. data/ext/libxml/libxml.c +4 -0
  8. data/ext/libxml/ruby_xml.c +977 -893
  9. data/ext/libxml/ruby_xml.h +20 -10
  10. data/ext/libxml/ruby_xml_attr.c +333 -333
  11. data/ext/libxml/ruby_xml_attr_decl.c +2 -2
  12. data/ext/libxml/ruby_xml_cbg.c +85 -85
  13. data/ext/libxml/ruby_xml_document.c +1133 -1147
  14. data/ext/libxml/ruby_xml_dtd.c +261 -268
  15. data/ext/libxml/ruby_xml_encoding.c +262 -260
  16. data/ext/libxml/ruby_xml_encoding.h +19 -19
  17. data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
  18. data/ext/libxml/ruby_xml_input_cbg.c +191 -191
  19. data/ext/libxml/ruby_xml_io.c +52 -50
  20. data/ext/libxml/ruby_xml_namespace.c +2 -2
  21. data/ext/libxml/ruby_xml_node.c +1446 -1452
  22. data/ext/libxml/ruby_xml_parser_context.c +999 -1001
  23. data/ext/libxml/ruby_xml_reader.c +1226 -1228
  24. data/ext/libxml/ruby_xml_relaxng.c +110 -111
  25. data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
  26. data/ext/libxml/ruby_xml_schema.c +300 -301
  27. data/ext/libxml/ruby_xml_version.h +3 -3
  28. data/ext/libxml/ruby_xml_writer.c +34 -16
  29. data/ext/libxml/ruby_xml_xpath.c +188 -187
  30. data/ext/libxml/ruby_xml_xpath_context.c +360 -361
  31. data/ext/libxml/ruby_xml_xpath_object.c +335 -335
  32. data/libxml-ruby.gemspec +47 -44
  33. data/test/tc_attr.rb +5 -7
  34. data/test/tc_attr_decl.rb +5 -6
  35. data/test/tc_attributes.rb +1 -2
  36. data/test/tc_canonicalize.rb +1 -2
  37. data/test/tc_deprecated_require.rb +1 -2
  38. data/test/tc_document.rb +4 -5
  39. data/test/tc_document_write.rb +2 -3
  40. data/test/tc_dtd.rb +4 -5
  41. data/test/tc_encoding.rb +126 -126
  42. data/test/tc_encoding_sax.rb +4 -3
  43. data/test/tc_error.rb +14 -15
  44. data/test/tc_html_parser.rb +15 -7
  45. data/test/tc_html_parser_context.rb +1 -2
  46. data/test/tc_namespace.rb +2 -3
  47. data/test/tc_namespaces.rb +5 -6
  48. data/test/tc_node.rb +2 -3
  49. data/test/tc_node_cdata.rb +2 -3
  50. data/test/tc_node_comment.rb +1 -2
  51. data/test/tc_node_copy.rb +1 -2
  52. data/test/tc_node_edit.rb +5 -7
  53. data/test/tc_node_pi.rb +1 -2
  54. data/test/tc_node_text.rb +2 -3
  55. data/test/tc_node_write.rb +2 -3
  56. data/test/tc_node_xlink.rb +1 -2
  57. data/test/tc_parser.rb +18 -24
  58. data/test/tc_parser_context.rb +6 -7
  59. data/test/tc_properties.rb +1 -2
  60. data/test/tc_reader.rb +9 -10
  61. data/test/tc_relaxng.rb +4 -5
  62. data/test/tc_sax_parser.rb +9 -10
  63. data/test/tc_schema.rb +4 -5
  64. data/test/tc_traversal.rb +1 -2
  65. data/test/tc_writer.rb +1 -2
  66. data/test/tc_xinclude.rb +1 -2
  67. data/test/tc_xml.rb +1 -2
  68. data/test/tc_xpath.rb +8 -9
  69. data/test/tc_xpath_context.rb +3 -4
  70. data/test/tc_xpath_expression.rb +3 -4
  71. data/test/tc_xpointer.rb +1 -3
  72. data/test/test_helper.rb +3 -1
  73. data/test/test_suite.rb +0 -1
  74. metadata +90 -72
  75. data/test/etc_doc_to_s.rb +0 -21
  76. data/test/ets_doc_file.rb +0 -17
  77. data/test/ets_doc_to_s.rb +0 -23
  78. data/test/ets_gpx.rb +0 -28
  79. data/test/ets_node_gc.rb +0 -23
  80. data/test/ets_test.xml +0 -2
  81. data/test/ets_tsr.rb +0 -11
  82. data/test/model/kml_sample.xml +0 -915
  83. data/test/remove_test.rb +0 -9
  84. data/test/tc_gc.rb +0 -86
  85. data/test/tc_parser.rb.orig +0 -384
@@ -1,893 +1,977 @@
1
- #include "ruby_libxml.h"
2
- #include "ruby_xml.h"
3
-
4
- VALUE mXML;
5
-
6
- /*
7
- * call-seq:
8
- * XML.catalog_dump -> true
9
- *
10
- * Dump all the global catalog content stdout.
11
- */
12
- static VALUE rxml_catalog_dump(VALUE self)
13
- {
14
- xmlCatalogDump(stdout);
15
- return (Qtrue);
16
- }
17
-
18
- /*
19
- * call-seq:
20
- * XML.catalog_remove(catalog) -> true
21
- *
22
- * Remove the specified resource catalog.
23
- */
24
- static VALUE rxml_catalog_remove(VALUE self, VALUE cat)
25
- {
26
- Check_Type(cat, T_STRING);
27
- xmlCatalogRemove((xmlChar *) StringValuePtr(cat));
28
- return (Qtrue);
29
- }
30
-
31
- /*
32
- * call-seq:
33
- * XML.check_lib_versions -> true
34
- *
35
- * Check LIBXML version matches version the bindings
36
- * were compiled to. Throws an exception if not.
37
- */
38
- static VALUE rxml_check_lib_versions(VALUE klass)
39
- {
40
- xmlCheckVersion(LIBXML_VERSION);
41
- return (Qtrue);
42
- }
43
-
44
- /*
45
- * call-seq:
46
- * XML.enabled_automata? -> (true|false)
47
- *
48
- * Determine whether libxml regexp automata support is enabled.
49
- */
50
- static VALUE rxml_enabled_automata_q(VALUE klass)
51
- {
52
- #ifdef LIBXML_AUTOMATA_ENABLED
53
- return(Qtrue);
54
- #else
55
- return (Qfalse);
56
- #endif
57
- }
58
-
59
- /*
60
- * call-seq:
61
- * XML.enabled_c14n? -> (true|false)
62
- *
63
- * Determine whether libxml 'canonical XML' support is enabled.
64
- * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
65
- */
66
- static VALUE rxml_enabled_c14n_q(VALUE klass)
67
- {
68
- #ifdef LIBXML_C14N_ENABLED
69
- return(Qtrue);
70
- #else
71
- return (Qfalse);
72
- #endif
73
- }
74
-
75
- /*
76
- * call-seq:
77
- * XML.enabled_catalog? -> (true|false)
78
- *
79
- * Determine whether libxml resource catalog support is enabled.
80
- */
81
- static VALUE rxml_enabled_catalog_q(VALUE klass)
82
- {
83
- #ifdef LIBXML_CATALOG_ENABLED
84
- return(Qtrue);
85
- #else
86
- return (Qfalse);
87
- #endif
88
- }
89
-
90
- /*
91
- * call-seq:
92
- * XML.enabled_debug? -> (true|false)
93
- *
94
- * Determine whether libxml debugging support is enabled.
95
- */
96
- static VALUE rxml_enabled_debug_q(VALUE klass)
97
- {
98
- #ifdef LIBXML_DEBUG_ENABLED
99
- return(Qtrue);
100
- #else
101
- return (Qfalse);
102
- #endif
103
- }
104
-
105
- /*
106
- * call-seq:
107
- * XML.enabled_docbook? -> (true|false)
108
- *
109
- * Determine whether libxml docbook support is enabled.
110
- */
111
- static VALUE rxml_enabled_docbook_q(VALUE klass)
112
- {
113
- #ifdef LIBXML_DOCB_ENABLED
114
- return(Qtrue);
115
- #else
116
- return (Qfalse);
117
- #endif
118
- }
119
-
120
- /*
121
- * call-seq:
122
- * XML.enabled_ftp? -> (true|false)
123
- *
124
- * Determine whether libxml ftp client support is enabled.
125
- */
126
- static VALUE rxml_enabled_ftp_q(VALUE klass)
127
- {
128
- #ifdef LIBXML_FTP_ENABLED
129
- return(Qtrue);
130
- #else
131
- return (Qfalse);
132
- #endif
133
- }
134
-
135
- /*
136
- * call-seq:
137
- * XML.enabled_http? -> (true|false)
138
- *
139
- * Determine whether libxml http client support is enabled.
140
- */
141
- static VALUE rxml_enabled_http_q(VALUE klass)
142
- {
143
- #ifdef LIBXML_HTTP_ENABLED
144
- return(Qtrue);
145
- #else
146
- return (Qfalse);
147
- #endif
148
- }
149
-
150
- /*
151
- * call-seq:
152
- * XML.enabled_html? -> (true|false)
153
- *
154
- * Determine whether libxml html support is enabled.
155
- */
156
- static VALUE rxml_enabled_html_q(VALUE klass)
157
- {
158
- #ifdef LIBXML_HTML_ENABLED
159
- return(Qtrue);
160
- #else
161
- return (Qfalse);
162
- #endif
163
- }
164
-
165
- /*
166
- * call-seq:
167
- * XML.enabled_iconv? -> (true|false)
168
- *
169
- * Determine whether libxml iconv support is enabled.
170
- */
171
- static VALUE rxml_enabled_iconv_q(VALUE klass)
172
- {
173
- #ifdef LIBXML_ICONV_ENABLED
174
- return(Qtrue);
175
- #else
176
- return (Qfalse);
177
- #endif
178
- }
179
-
180
- /*
181
- * call-seq:
182
- * XML.enabled_memory_debug? -> (true|false)
183
- *
184
- * Determine whether libxml memory location debugging support
185
- * is enabled.
186
- */
187
- static VALUE rxml_enabled_memory_debug_location_q(VALUE klass)
188
- {
189
- #ifdef DEBUG_MEMORY_LOCATION
190
- return(Qtrue);
191
- #else
192
- return (Qfalse);
193
- #endif
194
- }
195
-
196
- /*
197
- * call-seq:
198
- * XML.enabled_regexp? -> (true|false)
199
- *
200
- * Determine whether libxml regular expression support is enabled.
201
- */
202
- static VALUE rxml_enabled_regexp_q(VALUE klass)
203
- {
204
- #ifdef LIBXML_REGEXP_ENABLED
205
- return(Qtrue);
206
- #else
207
- return (Qfalse);
208
- #endif
209
- }
210
-
211
- /*
212
- * call-seq:
213
- * XML.enabled_schemas? -> (true|false)
214
- *
215
- * Determine whether libxml schema support is enabled.
216
- */
217
- static VALUE rxml_enabled_schemas_q(VALUE klass)
218
- {
219
- #ifdef LIBXML_SCHEMAS_ENABLED
220
- return(Qtrue);
221
- #else
222
- return (Qfalse);
223
- #endif
224
- }
225
-
226
- /*
227
- * call-seq:
228
- * XML.enabled_thread? -> (true|false)
229
- *
230
- * Determine whether thread-safe semantics support for libxml is enabled and
231
- * is used by this ruby extension. Threading support in libxml uses pthread
232
- * on Unix-like systems and Win32 threads on Windows.
233
- */
234
- static VALUE rxml_enabled_thread_q(VALUE klass)
235
- {
236
- /* This won't be defined unless this code is compiled with _REENTRANT or __MT__
237
- * defined or the compiler is in C99 mode.
238
- *
239
- * Note the relevant portion libxml/xmlversion.h on a thread-enabled build:
240
- *
241
- * #if defined(_REENTRANT) || defined(__MT__) || \
242
- * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L))
243
- * #define LIBXML_THREAD_ENABLED
244
- * #endif
245
- *
246
- */
247
- #ifdef LIBXML_THREAD_ENABLED
248
- return(Qtrue);
249
- #else
250
- return (Qfalse);
251
- #endif
252
- }
253
-
254
- /*
255
- * call-seq:
256
- * XML.enabled_unicode? -> (true|false)
257
- *
258
- * Determine whether libxml unicode support is enabled.
259
- */
260
- static VALUE rxml_enabled_unicode_q(VALUE klass)
261
- {
262
- #ifdef LIBXML_UNICODE_ENABLED
263
- return(Qtrue);
264
- #else
265
- return (Qfalse);
266
- #endif
267
- }
268
-
269
- /*
270
- * call-seq:
271
- * XML.enabled_xinclude? -> (true|false)
272
- *
273
- * Determine whether libxml xinclude support is enabled.
274
- */
275
- static VALUE rxml_enabled_xinclude_q(VALUE klass)
276
- {
277
- #ifdef LIBXML_XINCLUDE_ENABLED
278
- return(Qtrue);
279
- #else
280
- return (Qfalse);
281
- #endif
282
- }
283
-
284
- /*
285
- * call-seq:
286
- * XML.enabled_xpath? -> (true|false)
287
- *
288
- * Determine whether libxml xpath support is enabled.
289
- */
290
- static VALUE rxml_enabled_xpath_q(VALUE klass)
291
- {
292
- #ifdef LIBXML_XPATH_ENABLED
293
- return(Qtrue);
294
- #else
295
- return (Qfalse);
296
- #endif
297
- }
298
-
299
- /*
300
- * call-seq:
301
- * XML.enabled_xpointer? -> (true|false)
302
- *
303
- * Determine whether libxml xpointer support is enabled.
304
- */
305
- static VALUE rxml_enabled_xpointer_q(VALUE klass)
306
- {
307
- #ifdef LIBXML_XPTR_ENABLED
308
- return(Qtrue);
309
- #else
310
- return (Qfalse);
311
- #endif
312
- }
313
-
314
- /*
315
- * call-seq:
316
- * XML.enabled_zlib? -> (true|false)
317
- *
318
- * Determine whether libxml zlib support is enabled.
319
- */
320
- static VALUE rxml_enabled_zlib_q(VALUE klass)
321
- {
322
- #ifdef HAVE_ZLIB_H
323
- return(Qtrue);
324
- #else
325
- return (Qfalse);
326
- #endif
327
- }
328
-
329
- /*
330
- * call-seq:
331
- * XML.debug_entities -> (true|false)
332
- *
333
- * Determine whether included-entity debugging is enabled.
334
- * (Requires Libxml to be compiled with debugging support)
335
- */
336
- static VALUE rxml_debug_entities_get(VALUE klass)
337
- {
338
- #ifdef LIBXML_DEBUG_ENABLED
339
- if (xmlParserDebugEntities)
340
- return(Qtrue);
341
- else
342
- return(Qfalse);
343
- #else
344
- rb_warn("libxml was compiled with debugging turned off");
345
- return (Qfalse);
346
- #endif
347
- }
348
-
349
- /*
350
- * call-seq:
351
- * XML.debug_entities = true|false
352
- *
353
- * Enable or disable included-entity debugging.
354
- * (Requires Libxml to be compiled with debugging support)
355
- */
356
- static VALUE rxml_debug_entities_set(VALUE klass, VALUE bool)
357
- {
358
- #ifdef LIBXML_DEBUG_ENABLED
359
- if (TYPE(bool) == T_FALSE)
360
- {
361
- xmlParserDebugEntities = 0;
362
- return(Qfalse);
363
- }
364
- else
365
- {
366
- xmlParserDebugEntities = 1;
367
- return(Qtrue);
368
- }
369
- #else
370
- rb_warn("libxml was compiled with debugging turned off");
371
- #endif
372
- }
373
-
374
- /*
375
- * call-seq:
376
- * XML.default_keep_blanks -> (true|false)
377
- *
378
- * Determine whether parsers retain whitespace by default.
379
- */
380
- static VALUE rxml_default_keep_blanks_get(VALUE klass)
381
- {
382
- if (xmlKeepBlanksDefaultValue)
383
- return (Qtrue);
384
- else
385
- return (Qfalse);
386
- }
387
-
388
- /*
389
- * call-seq:
390
- * XML.default_keep_blanks = true|false
391
- *
392
- * Controls whether parsers retain whitespace by default.
393
- */
394
- static VALUE rxml_default_keep_blanks_set(VALUE klass, VALUE bool)
395
- {
396
- if (TYPE(bool) == T_FALSE)
397
- {
398
- xmlKeepBlanksDefaultValue = 0;
399
- return (Qfalse);
400
- }
401
- else if (TYPE(bool) == T_TRUE)
402
- {
403
- xmlKeepBlanksDefaultValue = 1;
404
- return (Qtrue);
405
- }
406
- else
407
- {
408
- rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
409
- }
410
- }
411
-
412
- /*
413
- * call-seq:
414
- * XML.default_load_external_dtd -> (true|false)
415
- *
416
- * Determine whether parsers load external DTDs by default.
417
- */
418
- static VALUE rxml_default_load_external_dtd_get(VALUE klass)
419
- {
420
- if (xmlLoadExtDtdDefaultValue)
421
- return (Qtrue);
422
- else
423
- return (Qfalse);
424
- }
425
-
426
- /*
427
- * call-seq:
428
- * XML.default_load_external_dtd = true|false
429
- *
430
- * Controls whether parsers load external DTDs by default.
431
- */
432
- static VALUE rxml_default_load_external_dtd_set(VALUE klass, VALUE bool)
433
- {
434
- if (bool == Qfalse)
435
- {
436
- xmlLoadExtDtdDefaultValue = 0;
437
- return (Qfalse);
438
- }
439
- else
440
- {
441
- xmlLoadExtDtdDefaultValue = 1;
442
- return (Qtrue);
443
- }
444
- }
445
-
446
- /*
447
- * call-seq:
448
- * XML.default_line_numbers -> (true|false)
449
- *
450
- * Determine whether parsers retain line-numbers by default.
451
- */
452
- static VALUE rxml_default_line_numbers_get(VALUE klass)
453
- {
454
- if (xmlLineNumbersDefaultValue)
455
- return (Qtrue);
456
- else
457
- return (Qfalse);
458
- }
459
-
460
- /*
461
- * call-seq:
462
- * XML.default_line_numbers = true|false
463
- *
464
- * Controls whether parsers retain line-numbers by default.
465
- */
466
- static VALUE rxml_default_line_numbers_set(VALUE klass, VALUE bool)
467
- {
468
- if (TYPE(bool) == T_FALSE)
469
- {
470
- xmlLineNumbersDefault(0);
471
- return (Qfalse);
472
- }
473
- else
474
- {
475
- xmlLineNumbersDefault(1);
476
- return (Qtrue);
477
- }
478
- }
479
-
480
- int rxml_libxml_default_options()
481
- {
482
- int options = 0;
483
-
484
- if (xmlLoadExtDtdDefaultValue)
485
- options |= XML_PARSE_DTDLOAD;
486
-
487
- if (xmlDoValidityCheckingDefaultValue)
488
- options |= XML_PARSE_DTDVALID;
489
-
490
- if (!xmlKeepBlanksDefaultValue)
491
- options |= XML_PARSE_NOBLANKS;
492
-
493
- if (xmlSubstituteEntitiesDefaultValue)
494
- options |= XML_PARSE_NOENT;
495
-
496
- if (!xmlGetWarningsDefaultValue)
497
- options |= XML_PARSE_NOWARNING;
498
-
499
- if (xmlPedanticParserDefaultValue)
500
- options |= XML_PARSE_PEDANTIC;
501
-
502
- return options;
503
- }
504
-
505
- /*
506
- * call-seq:
507
- * XML.default_options -> int
508
- *
509
- * Returns an integer that summarize libxml2's default options.
510
- */
511
- static VALUE rxml_default_options_get(VALUE klass)
512
- {
513
- int options = rxml_libxml_default_options();
514
- return INT2NUM(options);
515
- }
516
-
517
- /*
518
- * call-seq:
519
- * XML.default_pedantic_parser -> (true|false)
520
- *
521
- * Determine whether parsers are pedantic by default.
522
- */
523
- static VALUE rxml_default_pedantic_parser_get(VALUE klass)
524
- {
525
- if (xmlPedanticParserDefaultValue)
526
- return (Qtrue);
527
- else
528
- return (Qfalse);
529
- }
530
-
531
- /*
532
- * call-seq:
533
- * XML.default_pedantic_parser = true|false
534
- *
535
- * Controls whether parsers are pedantic by default.
536
- */
537
- static VALUE rxml_default_pedantic_parser_set(VALUE klass, VALUE bool)
538
- {
539
- if (TYPE(bool) == T_FALSE)
540
- {
541
- xmlPedanticParserDefault(0);
542
- return (Qfalse);
543
- }
544
- else
545
- {
546
- xmlPedanticParserDefault(1);
547
- return (Qtrue);
548
- }
549
- }
550
-
551
- /*
552
- * call-seq:
553
- * XML.default_substitute_entities -> (true|false)
554
- *
555
- * Determine whether parsers perform inline entity substitution
556
- * (for external entities) by default.
557
- */
558
- static VALUE rxml_default_substitute_entities_get(VALUE klass)
559
- {
560
- if (xmlSubstituteEntitiesDefaultValue)
561
- return (Qtrue);
562
- else
563
- return (Qfalse);
564
- }
565
-
566
- /*
567
- * call-seq:
568
- * XML.default_substitute_entities = true|false
569
- *
570
- * Controls whether parsers perform inline entity substitution
571
- * (for external entities) by default.
572
- */
573
- static VALUE rxml_default_substitute_entities_set(VALUE klass, VALUE bool)
574
- {
575
- if (bool == Qfalse)
576
- {
577
- xmlSubstituteEntitiesDefault(0);
578
- return (Qfalse);
579
- }
580
- else
581
- {
582
- xmlSubstituteEntitiesDefault(1);
583
- return (Qtrue);
584
- }
585
- }
586
-
587
- /*
588
- * call-seq:
589
- * XML.default_tree_indent_string -> "string"
590
- *
591
- * Obtain the default string used by parsers to indent the XML tree
592
- * for output.
593
- */
594
- static VALUE rxml_default_tree_indent_string_get(VALUE klass)
595
- {
596
- if (xmlTreeIndentString == NULL)
597
- return (Qnil);
598
- else
599
- return (rb_str_new2(xmlTreeIndentString));
600
- }
601
-
602
- /*
603
- * call-seq:
604
- * XML.default_tree_indent_string = "string"
605
- *
606
- * Set the default string used by parsers to indent the XML tree
607
- * for output.
608
- */
609
- static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
610
- {
611
- Check_Type(string, T_STRING);
612
- xmlTreeIndentString = xmlStrdup((xmlChar *)StringValuePtr(string));
613
- return (string);
614
- }
615
-
616
- /*
617
- * call-seq:
618
- * XML.default_validity_checking -> (true|false)
619
- *
620
- * Determine whether parsers perform XML validation by default.
621
- */
622
- static VALUE rxml_default_validity_checking_get(VALUE klass)
623
- {
624
- if (xmlDoValidityCheckingDefaultValue)
625
- return (Qtrue);
626
- else
627
- return (Qfalse);
628
- }
629
-
630
- /*
631
- * call-seq:
632
- * XML.default_validity_checking = true|false
633
- *
634
- * Controls whether parsers perform XML validation by default.
635
- */
636
- static VALUE rxml_default_validity_checking_set(VALUE klass, VALUE bool)
637
- {
638
- if (TYPE(bool) == T_FALSE)
639
- {
640
- xmlDoValidityCheckingDefaultValue = 0;
641
- return (Qfalse);
642
- }
643
- else
644
- {
645
- xmlDoValidityCheckingDefaultValue = 1;
646
- return (Qtrue);
647
- }
648
- }
649
-
650
- /*
651
- * call-seq:
652
- * XML.default_warnings -> (true|false)
653
- *
654
- * Determine whether parsers output warnings by default.
655
- */
656
- static VALUE rxml_default_warnings_get(VALUE klass)
657
- {
658
- if (xmlGetWarningsDefaultValue)
659
- return (Qtrue);
660
- else
661
- return (Qfalse);
662
- }
663
-
664
- /*
665
- * call-seq:
666
- * XML.default_warnings = true|false
667
- *
668
- * Controls whether parsers output warnings by default.
669
- */
670
- static VALUE rxml_default_warnings_set(VALUE klass, VALUE bool)
671
- {
672
- if (TYPE(bool) == T_FALSE)
673
- {
674
- xmlGetWarningsDefaultValue = 0;
675
- return (Qfalse);
676
- }
677
- else
678
- {
679
- xmlGetWarningsDefaultValue = 1;
680
- return (Qtrue);
681
- }
682
- }
683
-
684
- /*
685
- * call-seq:
686
- * XML.default_compression -> (true|false)
687
- *
688
- * Determine whether parsers use Zlib compression by default
689
- * (requires libxml to be compiled with Zlib support).
690
- */
691
- static VALUE rxml_default_compression_get(VALUE klass)
692
- {
693
- #ifdef HAVE_ZLIB_H
694
- return(INT2FIX(xmlGetCompressMode()));
695
- #else
696
- rb_warn("libxml was compiled without zlib support");
697
- return (Qfalse);
698
- #endif
699
- }
700
-
701
- /*
702
- * call-seq:
703
- * XML.default_compression = true|false
704
- *
705
- * Controls whether parsers use Zlib compression by default
706
- * (requires libxml to be compiled with Zlib support).
707
- */
708
- static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
709
- {
710
- #ifdef HAVE_ZLIB_H
711
- Check_Type(num, T_FIXNUM);
712
- xmlSetCompressMode(FIX2INT(num));
713
- return(num);
714
- #else
715
- rb_warn("libxml was compiled without zlib support");
716
- return (Qfalse);
717
- #endif
718
- }
719
-
720
- /*
721
- * call-seq:
722
- * XML.features -> ["feature", ..., "feature"]
723
- *
724
- * Obtains an array of strings representing features supported
725
- * (and enabled) by the installed libxml.
726
- */
727
- static VALUE rxml_features(VALUE klass)
728
- {
729
- VALUE arr, str;
730
- int i, len = MAX_LIBXML_FEATURES_LEN;
731
- char **list = NULL;
732
-
733
- list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
734
- MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
735
-
736
- arr = rb_ary_new();
737
- if (xmlGetFeaturesList(&len, (const char **) list) == -1)
738
- return Qnil;
739
-
740
- for (i = 0; i < len; i++)
741
- {
742
- str = rb_str_new2((const char *) list[i]);
743
- rb_gc_unregister_address(&str);
744
- rb_ary_push(arr, str);
745
- }
746
-
747
- if (len == MAX_LIBXML_FEATURES_LEN)
748
- rb_warn(
749
- "Please contact libxml-devel@rubyforge.org and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");
750
-
751
- ruby_xfree(list);
752
- return (arr);
753
- }
754
-
755
- /*
756
- * call-seq:
757
- * XML.indent_tree_output -> (true|false)
758
- *
759
- * Determines whether XML output will be indented
760
- * (using the string supplied to +default_indent_tree_string+)
761
- */
762
- static VALUE rxml_indent_tree_output_get(VALUE klass)
763
- {
764
- if (xmlIndentTreeOutput)
765
- return (Qtrue);
766
- else
767
- return (Qfalse);
768
- }
769
-
770
- /*
771
- * call-seq:
772
- * XML.indent_tree_output = true|false
773
- *
774
- * Controls whether XML output will be indented
775
- * (using the string supplied to +default_indent_tree_string+)
776
- */
777
- static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE bool)
778
- {
779
- if (TYPE(bool) == T_TRUE)
780
- {
781
- xmlIndentTreeOutput = 1;
782
- return (Qtrue);
783
- }
784
- else if (TYPE(bool) == T_FALSE)
785
- {
786
- xmlIndentTreeOutput = 0;
787
- return (Qfalse);
788
- }
789
- else
790
- {
791
- rb_raise(rb_eArgError, "Invalid argument, must be boolean");
792
- }
793
- }
794
-
795
- /*
796
- * call-seq:
797
- * XML.memory_dump -> (true|false)
798
- *
799
- * Perform a parser memory dump (requires memory debugging
800
- * support in libxml).
801
- */
802
- static VALUE rxml_memory_dump(VALUE self)
803
- {
804
- #ifdef DEBUG_MEMORY_LOCATION
805
- xmlMemoryDump();
806
- return(Qtrue);
807
- #else
808
- rb_warn("libxml was compiled without memory debugging support");
809
- return (Qfalse);
810
- #endif
811
- }
812
-
813
- /*
814
- * call-seq:
815
- * XML.memory_used -> num_bytes
816
- *
817
- * Perform a parser memory dump (requires memory debugging
818
- * support in libxml).
819
- */
820
- static VALUE rxml_memory_used(VALUE self)
821
- {
822
- #ifdef DEBUG_MEMORY_LOCATION
823
- return(INT2NUM(xmlMemUsed()));
824
- #else
825
- rb_warn("libxml was compiled without memory debugging support");
826
- return (Qfalse);
827
- #endif
828
- }
829
-
830
- /* The libxml gem provides Ruby language bindings for GNOME's Libxml2
831
- * XML toolkit. Refer to the README file to get started
832
- * and the LICENSE file for copyright and distribution information.
833
- */
834
-
835
- void rxml_init_xml(void)
836
- {
837
- mXML = rb_define_module_under(mLibXML, "XML");
838
-
839
- /* Constants */
840
- rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
841
- rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
842
- rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
843
- rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE));
844
-
845
- rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0);
846
- rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0);
847
- rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0);
848
- rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0);
849
- rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0);
850
- rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0);
851
- rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0);
852
- rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0);
853
- rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0);
854
- rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0);
855
- rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0);
856
- rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0);
857
- rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0);
858
- rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0);
859
- rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0);
860
- rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0);
861
- rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0);
862
- rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0);
863
-
864
- rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0);
865
- rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1);
866
- rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0);
867
- rb_define_module_function(mXML, "debug_entities", rxml_debug_entities_get, 0);
868
- rb_define_module_function(mXML, "debug_entities=", rxml_debug_entities_set, 1);
869
- rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0);
870
- rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1);
871
- rb_define_module_function(mXML, "default_keep_blanks", rxml_default_keep_blanks_get, 0);
872
- rb_define_module_function(mXML, "default_keep_blanks=", rxml_default_keep_blanks_set, 1);
873
- rb_define_module_function(mXML, "default_load_external_dtd", rxml_default_load_external_dtd_get, 0);
874
- rb_define_module_function(mXML, "default_load_external_dtd=", rxml_default_load_external_dtd_set, 1);
875
- rb_define_module_function(mXML, "default_line_numbers", rxml_default_line_numbers_get, 0);
876
- rb_define_module_function(mXML, "default_line_numbers=", rxml_default_line_numbers_set, 1);
877
- rb_define_module_function(mXML, "default_options", rxml_default_options_get, 0);
878
- rb_define_module_function(mXML, "default_pedantic_parser", rxml_default_pedantic_parser_get, 0);
879
- rb_define_module_function(mXML, "default_pedantic_parser=", rxml_default_pedantic_parser_set, 1);
880
- rb_define_module_function(mXML, "default_substitute_entities", rxml_default_substitute_entities_get, 0);
881
- rb_define_module_function(mXML, "default_substitute_entities=", rxml_default_substitute_entities_set, 1);
882
- rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0);
883
- rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1);
884
- rb_define_module_function(mXML, "default_validity_checking", rxml_default_validity_checking_get, 0);
885
- rb_define_module_function(mXML, "default_validity_checking=", rxml_default_validity_checking_set, 1);
886
- rb_define_module_function(mXML, "default_warnings", rxml_default_warnings_get, 0);
887
- rb_define_module_function(mXML, "default_warnings=", rxml_default_warnings_set, 1);
888
- rb_define_module_function(mXML, "features", rxml_features, 0);
889
- rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
890
- rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
891
- rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0);
892
- rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0);
893
- }
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml.h"
3
+
4
+ static struct st_table *private_pointers;
5
+
6
+ static int registered = 0; // Constant to track what nodes have been registered
7
+
8
+ void rxml_register(void *xnode, VALUE value) {
9
+ st_insert(private_pointers, (st_data_t)xnode, (st_data_t)value);
10
+ }
11
+
12
+ void rxml_register_node(xmlNodePtr xnode, VALUE value) {
13
+ if (rxml_lookup_node(xnode) == Qnil) {
14
+ xnode->_private = &registered;
15
+ rxml_register(xnode, value);
16
+ }
17
+ }
18
+
19
+ void rxml_register_doc(xmlDocPtr xdoc, VALUE value) {
20
+ if (rxml_lookup_doc(xdoc) == Qnil) {
21
+ xdoc->_private = &registered;
22
+ rxml_register(xdoc, value);
23
+ }
24
+ }
25
+
26
+ void rxml_register_dtd(xmlDtdPtr xdtd, VALUE value) {
27
+ if (rxml_lookup_dtd(xdtd) == Qnil) {
28
+ xdtd->_private = &registered;
29
+ rxml_register(xdtd, value);
30
+ }
31
+ }
32
+
33
+ void rxml_unregister(void *xnode) {
34
+ st_delete(private_pointers, (st_data_t*)&xnode, NULL);
35
+ }
36
+
37
+ void rxml_unregister_node(xmlNodePtr xnode) {
38
+ if (xnode->_private == &registered) {
39
+ xnode->_private = NULL;
40
+ rxml_unregister(xnode);
41
+ }
42
+ }
43
+
44
+ void rxml_unregister_doc(xmlDocPtr xdoc) {
45
+ if (xdoc->_private == &registered) {
46
+ xdoc->_private = NULL;
47
+ rxml_unregister(xdoc);
48
+ }
49
+ }
50
+
51
+ void rxml_unregister_dtd(xmlDtdPtr xdtd) {
52
+ if (xdtd->_private == &registered) {
53
+ xdtd->_private = NULL;
54
+ rxml_unregister(xdtd);
55
+ }
56
+ }
57
+
58
+ VALUE rxml_lookup(void *pointer) {
59
+ st_data_t result = 0;
60
+ int ret = st_lookup(private_pointers, (st_data_t)pointer, &result);
61
+ return ret ? (VALUE)result : Qnil;
62
+ }
63
+
64
+ VALUE rxml_lookup_node(xmlNodePtr xnode) {
65
+ if (!xnode || xnode->_private != &registered)
66
+ return Qnil;
67
+
68
+ return rxml_lookup(xnode);
69
+ }
70
+
71
+ VALUE rxml_lookup_doc(xmlDocPtr xdoc) {
72
+ if (!xdoc || xdoc->_private != &registered)
73
+ return Qnil;
74
+
75
+ return rxml_lookup(xdoc);
76
+ }
77
+
78
+ VALUE rxml_lookup_dtd(xmlDtdPtr xdtd) {
79
+ if (!xdtd || xdtd->_private != &registered)
80
+ return Qnil;
81
+
82
+ return rxml_lookup(xdtd);
83
+ }
84
+
85
+ VALUE mXML;
86
+
87
+ /*
88
+ * call-seq:
89
+ * XML.catalog_dump -> true
90
+ *
91
+ * Dump all the global catalog content stdout.
92
+ */
93
+ static VALUE rxml_catalog_dump(VALUE self)
94
+ {
95
+ xmlCatalogDump(stdout);
96
+ return (Qtrue);
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * XML.catalog_remove(catalog) -> true
102
+ *
103
+ * Remove the specified resource catalog.
104
+ */
105
+ static VALUE rxml_catalog_remove(VALUE self, VALUE cat)
106
+ {
107
+ Check_Type(cat, T_STRING);
108
+ xmlCatalogRemove((xmlChar *) StringValuePtr(cat));
109
+ return (Qtrue);
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * XML.check_lib_versions -> true
115
+ *
116
+ * Check LIBXML version matches version the bindings
117
+ * were compiled to. Throws an exception if not.
118
+ */
119
+ static VALUE rxml_check_lib_versions(VALUE klass)
120
+ {
121
+ xmlCheckVersion(LIBXML_VERSION);
122
+ return (Qtrue);
123
+ }
124
+
125
+ /*
126
+ * call-seq:
127
+ * XML.enabled_automata? -> (true|false)
128
+ *
129
+ * Determine whether libxml regexp automata support is enabled.
130
+ */
131
+ static VALUE rxml_enabled_automata_q(VALUE klass)
132
+ {
133
+ #ifdef LIBXML_AUTOMATA_ENABLED
134
+ return(Qtrue);
135
+ #else
136
+ return (Qfalse);
137
+ #endif
138
+ }
139
+
140
+ /*
141
+ * call-seq:
142
+ * XML.enabled_c14n? -> (true|false)
143
+ *
144
+ * Determine whether libxml 'canonical XML' support is enabled.
145
+ * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
146
+ */
147
+ static VALUE rxml_enabled_c14n_q(VALUE klass)
148
+ {
149
+ #ifdef LIBXML_C14N_ENABLED
150
+ return(Qtrue);
151
+ #else
152
+ return (Qfalse);
153
+ #endif
154
+ }
155
+
156
+ /*
157
+ * call-seq:
158
+ * XML.enabled_catalog? -> (true|false)
159
+ *
160
+ * Determine whether libxml resource catalog support is enabled.
161
+ */
162
+ static VALUE rxml_enabled_catalog_q(VALUE klass)
163
+ {
164
+ #ifdef LIBXML_CATALOG_ENABLED
165
+ return(Qtrue);
166
+ #else
167
+ return (Qfalse);
168
+ #endif
169
+ }
170
+
171
+ /*
172
+ * call-seq:
173
+ * XML.enabled_debug? -> (true|false)
174
+ *
175
+ * Determine whether libxml debugging support is enabled.
176
+ */
177
+ static VALUE rxml_enabled_debug_q(VALUE klass)
178
+ {
179
+ #ifdef LIBXML_DEBUG_ENABLED
180
+ return(Qtrue);
181
+ #else
182
+ return (Qfalse);
183
+ #endif
184
+ }
185
+
186
+ /*
187
+ * call-seq:
188
+ * XML.enabled_docbook? -> (true|false)
189
+ *
190
+ * Determine whether libxml docbook support is enabled.
191
+ */
192
+ static VALUE rxml_enabled_docbook_q(VALUE klass)
193
+ {
194
+ #ifdef LIBXML_DOCB_ENABLED
195
+ return(Qtrue);
196
+ #else
197
+ return (Qfalse);
198
+ #endif
199
+ }
200
+
201
+ /*
202
+ * call-seq:
203
+ * XML.enabled_ftp? -> (true|false)
204
+ *
205
+ * Determine whether libxml ftp client support is enabled.
206
+ */
207
+ static VALUE rxml_enabled_ftp_q(VALUE klass)
208
+ {
209
+ #ifdef LIBXML_FTP_ENABLED
210
+ return(Qtrue);
211
+ #else
212
+ return (Qfalse);
213
+ #endif
214
+ }
215
+
216
+ /*
217
+ * call-seq:
218
+ * XML.enabled_http? -> (true|false)
219
+ *
220
+ * Determine whether libxml http client support is enabled.
221
+ */
222
+ static VALUE rxml_enabled_http_q(VALUE klass)
223
+ {
224
+ #ifdef LIBXML_HTTP_ENABLED
225
+ return(Qtrue);
226
+ #else
227
+ return (Qfalse);
228
+ #endif
229
+ }
230
+
231
+ /*
232
+ * call-seq:
233
+ * XML.enabled_html? -> (true|false)
234
+ *
235
+ * Determine whether libxml html support is enabled.
236
+ */
237
+ static VALUE rxml_enabled_html_q(VALUE klass)
238
+ {
239
+ #ifdef LIBXML_HTML_ENABLED
240
+ return(Qtrue);
241
+ #else
242
+ return (Qfalse);
243
+ #endif
244
+ }
245
+
246
+ /*
247
+ * call-seq:
248
+ * XML.enabled_iconv? -> (true|false)
249
+ *
250
+ * Determine whether libxml iconv support is enabled.
251
+ */
252
+ static VALUE rxml_enabled_iconv_q(VALUE klass)
253
+ {
254
+ #ifdef LIBXML_ICONV_ENABLED
255
+ return(Qtrue);
256
+ #else
257
+ return (Qfalse);
258
+ #endif
259
+ }
260
+
261
+ /*
262
+ * call-seq:
263
+ * XML.enabled_memory_debug? -> (true|false)
264
+ *
265
+ * Determine whether libxml memory location debugging support
266
+ * is enabled.
267
+ */
268
+ static VALUE rxml_enabled_memory_debug_location_q(VALUE klass)
269
+ {
270
+ #ifdef DEBUG_MEMORY_LOCATION
271
+ return(Qtrue);
272
+ #else
273
+ return (Qfalse);
274
+ #endif
275
+ }
276
+
277
+ /*
278
+ * call-seq:
279
+ * XML.enabled_regexp? -> (true|false)
280
+ *
281
+ * Determine whether libxml regular expression support is enabled.
282
+ */
283
+ static VALUE rxml_enabled_regexp_q(VALUE klass)
284
+ {
285
+ #ifdef LIBXML_REGEXP_ENABLED
286
+ return(Qtrue);
287
+ #else
288
+ return (Qfalse);
289
+ #endif
290
+ }
291
+
292
+ /*
293
+ * call-seq:
294
+ * XML.enabled_schemas? -> (true|false)
295
+ *
296
+ * Determine whether libxml schema support is enabled.
297
+ */
298
+ static VALUE rxml_enabled_schemas_q(VALUE klass)
299
+ {
300
+ #ifdef LIBXML_SCHEMAS_ENABLED
301
+ return(Qtrue);
302
+ #else
303
+ return (Qfalse);
304
+ #endif
305
+ }
306
+
307
+ /*
308
+ * call-seq:
309
+ * XML.enabled_thread? -> (true|false)
310
+ *
311
+ * Determine whether thread-safe semantics support for libxml is enabled and
312
+ * is used by this ruby extension. Threading support in libxml uses pthread
313
+ * on Unix-like systems and Win32 threads on Windows.
314
+ */
315
+ static VALUE rxml_enabled_thread_q(VALUE klass)
316
+ {
317
+ /* This won't be defined unless this code is compiled with _REENTRANT or __MT__
318
+ * defined or the compiler is in C99 mode.
319
+ *
320
+ * Note the relevant portion libxml/xmlversion.h on a thread-enabled build:
321
+ *
322
+ * #if defined(_REENTRANT) || defined(__MT__) || \
323
+ * (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE - 0 >= 199506L))
324
+ * #define LIBXML_THREAD_ENABLED
325
+ * #endif
326
+ *
327
+ */
328
+ #ifdef LIBXML_THREAD_ENABLED
329
+ return(Qtrue);
330
+ #else
331
+ return (Qfalse);
332
+ #endif
333
+ }
334
+
335
+ /*
336
+ * call-seq:
337
+ * XML.enabled_unicode? -> (true|false)
338
+ *
339
+ * Determine whether libxml unicode support is enabled.
340
+ */
341
+ static VALUE rxml_enabled_unicode_q(VALUE klass)
342
+ {
343
+ #ifdef LIBXML_UNICODE_ENABLED
344
+ return(Qtrue);
345
+ #else
346
+ return (Qfalse);
347
+ #endif
348
+ }
349
+
350
+ /*
351
+ * call-seq:
352
+ * XML.enabled_xinclude? -> (true|false)
353
+ *
354
+ * Determine whether libxml xinclude support is enabled.
355
+ */
356
+ static VALUE rxml_enabled_xinclude_q(VALUE klass)
357
+ {
358
+ #ifdef LIBXML_XINCLUDE_ENABLED
359
+ return(Qtrue);
360
+ #else
361
+ return (Qfalse);
362
+ #endif
363
+ }
364
+
365
+ /*
366
+ * call-seq:
367
+ * XML.enabled_xpath? -> (true|false)
368
+ *
369
+ * Determine whether libxml xpath support is enabled.
370
+ */
371
+ static VALUE rxml_enabled_xpath_q(VALUE klass)
372
+ {
373
+ #ifdef LIBXML_XPATH_ENABLED
374
+ return(Qtrue);
375
+ #else
376
+ return (Qfalse);
377
+ #endif
378
+ }
379
+
380
+ /*
381
+ * call-seq:
382
+ * XML.enabled_xpointer? -> (true|false)
383
+ *
384
+ * Determine whether libxml xpointer support is enabled.
385
+ */
386
+ static VALUE rxml_enabled_xpointer_q(VALUE klass)
387
+ {
388
+ #ifdef LIBXML_XPTR_ENABLED
389
+ return(Qtrue);
390
+ #else
391
+ return (Qfalse);
392
+ #endif
393
+ }
394
+
395
+ /*
396
+ * call-seq:
397
+ * XML.enabled_zlib? -> (true|false)
398
+ *
399
+ * Determine whether libxml zlib support is enabled.
400
+ */
401
+ static VALUE rxml_enabled_zlib_q(VALUE klass)
402
+ {
403
+ #ifdef HAVE_ZLIB_H
404
+ return(Qtrue);
405
+ #else
406
+ return (Qfalse);
407
+ #endif
408
+ }
409
+
410
+ /*
411
+ * call-seq:
412
+ * XML.debug_entities -> (true|false)
413
+ *
414
+ * Determine whether included-entity debugging is enabled.
415
+ * (Requires Libxml to be compiled with debugging support)
416
+ */
417
+ static VALUE rxml_debug_entities_get(VALUE klass)
418
+ {
419
+ #ifdef LIBXML_DEBUG_ENABLED
420
+ if (xmlParserDebugEntities)
421
+ return(Qtrue);
422
+ else
423
+ return(Qfalse);
424
+ #else
425
+ rb_warn("libxml was compiled with debugging turned off");
426
+ return (Qfalse);
427
+ #endif
428
+ }
429
+
430
+ /*
431
+ * call-seq:
432
+ * XML.debug_entities = true|false
433
+ *
434
+ * Enable or disable included-entity debugging.
435
+ * (Requires Libxml to be compiled with debugging support)
436
+ */
437
+ static VALUE rxml_debug_entities_set(VALUE klass, VALUE value)
438
+ {
439
+ #ifdef LIBXML_DEBUG_ENABLED
440
+ if (value == Qfalse)
441
+ {
442
+ xmlParserDebugEntities = 0;
443
+ return(Qfalse);
444
+ }
445
+ else
446
+ {
447
+ xmlParserDebugEntities = 1;
448
+ return(Qtrue);
449
+ }
450
+ #else
451
+ rb_warn("libxml was compiled with debugging turned off");
452
+ #endif
453
+ }
454
+
455
+ /*
456
+ * call-seq:
457
+ * XML.default_keep_blanks -> (true|false)
458
+ *
459
+ * Determine whether parsers retain whitespace by default.
460
+ */
461
+ static VALUE rxml_default_keep_blanks_get(VALUE klass)
462
+ {
463
+ if (xmlKeepBlanksDefaultValue)
464
+ return (Qtrue);
465
+ else
466
+ return (Qfalse);
467
+ }
468
+
469
+ /*
470
+ * call-seq:
471
+ * XML.default_keep_blanks = true|false
472
+ *
473
+ * Controls whether parsers retain whitespace by default.
474
+ */
475
+ static VALUE rxml_default_keep_blanks_set(VALUE klass, VALUE value)
476
+ {
477
+ if (value == Qfalse)
478
+ {
479
+ xmlKeepBlanksDefaultValue = 0;
480
+ return (Qfalse);
481
+ }
482
+ else if (value == Qtrue)
483
+ {
484
+ xmlKeepBlanksDefaultValue = 1;
485
+ return (Qtrue);
486
+ }
487
+ else
488
+ {
489
+ rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
490
+ }
491
+ }
492
+
493
+ /*
494
+ * call-seq:
495
+ * XML.default_load_external_dtd -> (true|false)
496
+ *
497
+ * Determine whether parsers load external DTDs by default.
498
+ */
499
+ static VALUE rxml_default_load_external_dtd_get(VALUE klass)
500
+ {
501
+ if (xmlLoadExtDtdDefaultValue)
502
+ return (Qtrue);
503
+ else
504
+ return (Qfalse);
505
+ }
506
+
507
+ /*
508
+ * call-seq:
509
+ * XML.default_load_external_dtd = true|false
510
+ *
511
+ * Controls whether parsers load external DTDs by default.
512
+ */
513
+ static VALUE rxml_default_load_external_dtd_set(VALUE klass, VALUE value)
514
+ {
515
+ if (value == Qfalse)
516
+ {
517
+ xmlLoadExtDtdDefaultValue = 0;
518
+ return (Qfalse);
519
+ }
520
+ else
521
+ {
522
+ xmlLoadExtDtdDefaultValue = 1;
523
+ return (Qtrue);
524
+ }
525
+ }
526
+
527
+ /*
528
+ * call-seq:
529
+ * XML.default_line_numbers -> (true|false)
530
+ *
531
+ * Determine whether parsers retain line-numbers by default.
532
+ */
533
+ static VALUE rxml_default_line_numbers_get(VALUE klass)
534
+ {
535
+ if (xmlLineNumbersDefaultValue)
536
+ return (Qtrue);
537
+ else
538
+ return (Qfalse);
539
+ }
540
+
541
+ /*
542
+ * call-seq:
543
+ * XML.default_line_numbers = true|false
544
+ *
545
+ * Controls whether parsers retain line-numbers by default.
546
+ */
547
+ static VALUE rxml_default_line_numbers_set(VALUE klass, VALUE value)
548
+ {
549
+ if (value == Qfalse)
550
+ {
551
+ xmlLineNumbersDefault(0);
552
+ return (Qfalse);
553
+ }
554
+ else
555
+ {
556
+ xmlLineNumbersDefault(1);
557
+ return (Qtrue);
558
+ }
559
+ }
560
+
561
+ int rxml_libxml_default_options()
562
+ {
563
+ int options = 0;
564
+
565
+ if (xmlLoadExtDtdDefaultValue)
566
+ options |= XML_PARSE_DTDLOAD;
567
+
568
+ if (xmlDoValidityCheckingDefaultValue)
569
+ options |= XML_PARSE_DTDVALID;
570
+
571
+ if (!xmlKeepBlanksDefaultValue)
572
+ options |= XML_PARSE_NOBLANKS;
573
+
574
+ if (xmlSubstituteEntitiesDefaultValue)
575
+ options |= XML_PARSE_NOENT;
576
+
577
+ if (!xmlGetWarningsDefaultValue)
578
+ options |= XML_PARSE_NOWARNING;
579
+
580
+ if (xmlPedanticParserDefaultValue)
581
+ options |= XML_PARSE_PEDANTIC;
582
+
583
+ return options;
584
+ }
585
+
586
+ /*
587
+ * call-seq:
588
+ * XML.default_options -> int
589
+ *
590
+ * Returns an integer that summarize libxml2's default options.
591
+ */
592
+ static VALUE rxml_default_options_get(VALUE klass)
593
+ {
594
+ int options = rxml_libxml_default_options();
595
+ return INT2NUM(options);
596
+ }
597
+
598
+ /*
599
+ * call-seq:
600
+ * XML.default_pedantic_parser -> (true|false)
601
+ *
602
+ * Determine whether parsers are pedantic by default.
603
+ */
604
+ static VALUE rxml_default_pedantic_parser_get(VALUE klass)
605
+ {
606
+ if (xmlPedanticParserDefaultValue)
607
+ return (Qtrue);
608
+ else
609
+ return (Qfalse);
610
+ }
611
+
612
+ /*
613
+ * call-seq:
614
+ * XML.default_pedantic_parser = true|false
615
+ *
616
+ * Controls whether parsers are pedantic by default.
617
+ */
618
+ static VALUE rxml_default_pedantic_parser_set(VALUE klass, VALUE value)
619
+ {
620
+ if (value == Qfalse)
621
+ {
622
+ xmlPedanticParserDefault(0);
623
+ return (Qfalse);
624
+ }
625
+ else
626
+ {
627
+ xmlPedanticParserDefault(1);
628
+ return (Qtrue);
629
+ }
630
+ }
631
+
632
+ /*
633
+ * call-seq:
634
+ * XML.default_substitute_entities -> (true|false)
635
+ *
636
+ * Determine whether parsers perform inline entity substitution
637
+ * (for external entities) by default.
638
+ */
639
+ static VALUE rxml_default_substitute_entities_get(VALUE klass)
640
+ {
641
+ if (xmlSubstituteEntitiesDefaultValue)
642
+ return (Qtrue);
643
+ else
644
+ return (Qfalse);
645
+ }
646
+
647
+ /*
648
+ * call-seq:
649
+ * XML.default_substitute_entities = true|false
650
+ *
651
+ * Controls whether parsers perform inline entity substitution
652
+ * (for external entities) by default.
653
+ */
654
+ static VALUE rxml_default_substitute_entities_set(VALUE klass, VALUE value)
655
+ {
656
+ if (value == Qfalse)
657
+ {
658
+ xmlSubstituteEntitiesDefault(0);
659
+ return (Qfalse);
660
+ }
661
+ else
662
+ {
663
+ xmlSubstituteEntitiesDefault(1);
664
+ return (Qtrue);
665
+ }
666
+ }
667
+
668
+ /*
669
+ * call-seq:
670
+ * XML.default_tree_indent_string -> "string"
671
+ *
672
+ * Obtain the default string used by parsers to indent the XML tree
673
+ * for output.
674
+ */
675
+ static VALUE rxml_default_tree_indent_string_get(VALUE klass)
676
+ {
677
+ if (xmlTreeIndentString == NULL)
678
+ return (Qnil);
679
+ else
680
+ return (rb_str_new2(xmlTreeIndentString));
681
+ }
682
+
683
+ /*
684
+ * call-seq:
685
+ * XML.default_tree_indent_string = "string"
686
+ *
687
+ * Set the default string used by parsers to indent the XML tree
688
+ * for output.
689
+ */
690
+ static VALUE rxml_default_tree_indent_string_set(VALUE klass, VALUE string)
691
+ {
692
+ Check_Type(string, T_STRING);
693
+ xmlTreeIndentString = (const char *)xmlStrdup((xmlChar *)StringValuePtr(string));
694
+ return (string);
695
+ }
696
+
697
+ /*
698
+ * call-seq:
699
+ * XML.default_validity_checking -> (true|false)
700
+ *
701
+ * Determine whether parsers perform XML validation by default.
702
+ */
703
+ static VALUE rxml_default_validity_checking_get(VALUE klass)
704
+ {
705
+ if (xmlDoValidityCheckingDefaultValue)
706
+ return (Qtrue);
707
+ else
708
+ return (Qfalse);
709
+ }
710
+
711
+ /*
712
+ * call-seq:
713
+ * XML.default_validity_checking = true|false
714
+ *
715
+ * Controls whether parsers perform XML validation by default.
716
+ */
717
+ static VALUE rxml_default_validity_checking_set(VALUE klass, VALUE value)
718
+ {
719
+ if (value == Qfalse)
720
+ {
721
+ xmlDoValidityCheckingDefaultValue = 0;
722
+ return (Qfalse);
723
+ }
724
+ else
725
+ {
726
+ xmlDoValidityCheckingDefaultValue = 1;
727
+ return (Qtrue);
728
+ }
729
+ }
730
+
731
+ /*
732
+ * call-seq:
733
+ * XML.default_warnings -> (true|false)
734
+ *
735
+ * Determine whether parsers output warnings by default.
736
+ */
737
+ static VALUE rxml_default_warnings_get(VALUE klass)
738
+ {
739
+ if (xmlGetWarningsDefaultValue)
740
+ return (Qtrue);
741
+ else
742
+ return (Qfalse);
743
+ }
744
+
745
+ /*
746
+ * call-seq:
747
+ * XML.default_warnings = true|false
748
+ *
749
+ * Controls whether parsers output warnings by default.
750
+ */
751
+ static VALUE rxml_default_warnings_set(VALUE klass, VALUE value)
752
+ {
753
+ if (value == Qfalse)
754
+ {
755
+ xmlGetWarningsDefaultValue = 0;
756
+ return (Qfalse);
757
+ }
758
+ else
759
+ {
760
+ xmlGetWarningsDefaultValue = 1;
761
+ return (Qtrue);
762
+ }
763
+ }
764
+
765
+ /*
766
+ * call-seq:
767
+ * XML.default_compression -> (true|false)
768
+ *
769
+ * Determine whether parsers use Zlib compression by default
770
+ * (requires libxml to be compiled with Zlib support).
771
+ */
772
+ static VALUE rxml_default_compression_get(VALUE klass)
773
+ {
774
+ #ifdef HAVE_ZLIB_H
775
+ return(INT2FIX(xmlGetCompressMode()));
776
+ #else
777
+ rb_warn("libxml was compiled without zlib support");
778
+ return (Qfalse);
779
+ #endif
780
+ }
781
+
782
+ /*
783
+ * call-seq:
784
+ * XML.default_compression = true|false
785
+ *
786
+ * Controls whether parsers use Zlib compression by default
787
+ * (requires libxml to be compiled with Zlib support).
788
+ */
789
+ static VALUE rxml_default_compression_set(VALUE klass, VALUE num)
790
+ {
791
+ #ifdef HAVE_ZLIB_H
792
+ Check_Type(num, T_FIXNUM);
793
+ xmlSetCompressMode(FIX2INT(num));
794
+ return(num);
795
+ #else
796
+ rb_warn("libxml was compiled without zlib support");
797
+ return (Qfalse);
798
+ #endif
799
+ }
800
+
801
+ /*
802
+ * call-seq:
803
+ * XML.features -> ["feature", ..., "feature"]
804
+ *
805
+ * Obtains an array of strings representing features supported
806
+ * (and enabled) by the installed libxml.
807
+ */
808
+ static VALUE rxml_features(VALUE klass)
809
+ {
810
+ VALUE arr, str;
811
+ int i, len = MAX_LIBXML_FEATURES_LEN;
812
+ char **list = NULL;
813
+
814
+ list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
815
+ MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
816
+
817
+ arr = rb_ary_new();
818
+ if (xmlGetFeaturesList(&len, (const char **) list) == -1)
819
+ return Qnil;
820
+
821
+ for (i = 0; i < len; i++)
822
+ {
823
+ str = rb_str_new2((const char *) list[i]);
824
+ rb_gc_unregister_address(&str);
825
+ rb_ary_push(arr, str);
826
+ }
827
+
828
+ if (len == MAX_LIBXML_FEATURES_LEN)
829
+ rb_warn(
830
+ "Please contact libxml-devel@rubyforge.org and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");
831
+
832
+ ruby_xfree(list);
833
+ return (arr);
834
+ }
835
+
836
+ /*
837
+ * call-seq:
838
+ * XML.indent_tree_output -> (true|false)
839
+ *
840
+ * Determines whether XML output will be indented
841
+ * (using the string supplied to +default_indent_tree_string+)
842
+ */
843
+ static VALUE rxml_indent_tree_output_get(VALUE klass)
844
+ {
845
+ if (xmlIndentTreeOutput)
846
+ return (Qtrue);
847
+ else
848
+ return (Qfalse);
849
+ }
850
+
851
+ /*
852
+ * call-seq:
853
+ * XML.indent_tree_output = true|false
854
+ *
855
+ * Controls whether XML output will be indented
856
+ * (using the string supplied to +default_indent_tree_string+)
857
+ */
858
+ static VALUE rxml_indent_tree_output_set(VALUE klass, VALUE value)
859
+ {
860
+ if (value == Qtrue)
861
+ {
862
+ xmlIndentTreeOutput = 1;
863
+ return (Qtrue);
864
+ }
865
+ else if (value == Qfalse)
866
+ {
867
+ xmlIndentTreeOutput = 0;
868
+ return (Qfalse);
869
+ }
870
+ else
871
+ {
872
+ rb_raise(rb_eArgError, "Invalid argument, must be boolean");
873
+ }
874
+ }
875
+
876
+ /*
877
+ * call-seq:
878
+ * XML.memory_dump -> (true|false)
879
+ *
880
+ * Perform a parser memory dump (requires memory debugging
881
+ * support in libxml).
882
+ */
883
+ static VALUE rxml_memory_dump(VALUE self)
884
+ {
885
+ #ifdef DEBUG_MEMORY_LOCATION
886
+ xmlMemoryDump();
887
+ return(Qtrue);
888
+ #else
889
+ rb_warn("libxml was compiled without memory debugging support");
890
+ return (Qfalse);
891
+ #endif
892
+ }
893
+
894
+ /*
895
+ * call-seq:
896
+ * XML.memory_used -> num_bytes
897
+ *
898
+ * Perform a parser memory dump (requires memory debugging
899
+ * support in libxml).
900
+ */
901
+ static VALUE rxml_memory_used(VALUE self)
902
+ {
903
+ #ifdef DEBUG_MEMORY_LOCATION
904
+ return(INT2NUM(xmlMemUsed()));
905
+ #else
906
+ rb_warn("libxml was compiled without memory debugging support");
907
+ return (Qfalse);
908
+ #endif
909
+ }
910
+
911
+ /* The libxml gem provides Ruby language bindings for GNOME's Libxml2
912
+ * XML toolkit. Refer to the README file to get started
913
+ * and the LICENSE file for copyright and distribution information.
914
+ */
915
+
916
+ void rxml_init_xml(void)
917
+ {
918
+ /* Create a hashtable suitable for pointer keys */
919
+ private_pointers = st_init_numtable();
920
+
921
+ mXML = rb_define_module_under(mLibXML, "XML");
922
+
923
+ /* Constants */
924
+ rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
925
+ rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
926
+ rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
927
+ rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*) XML_XML_NAMESPACE));
928
+
929
+ rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0);
930
+ rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0);
931
+ rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0);
932
+ rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0);
933
+ rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0);
934
+ rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0);
935
+ rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0);
936
+ rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0);
937
+ rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0);
938
+ rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0);
939
+ rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0);
940
+ rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0);
941
+ rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0);
942
+ rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0);
943
+ rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0);
944
+ rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0);
945
+ rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0);
946
+ rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0);
947
+
948
+ rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0);
949
+ rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1);
950
+ rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0);
951
+ rb_define_module_function(mXML, "debug_entities", rxml_debug_entities_get, 0);
952
+ rb_define_module_function(mXML, "debug_entities=", rxml_debug_entities_set, 1);
953
+ rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0);
954
+ rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1);
955
+ rb_define_module_function(mXML, "default_keep_blanks", rxml_default_keep_blanks_get, 0);
956
+ rb_define_module_function(mXML, "default_keep_blanks=", rxml_default_keep_blanks_set, 1);
957
+ rb_define_module_function(mXML, "default_load_external_dtd", rxml_default_load_external_dtd_get, 0);
958
+ rb_define_module_function(mXML, "default_load_external_dtd=", rxml_default_load_external_dtd_set, 1);
959
+ rb_define_module_function(mXML, "default_line_numbers", rxml_default_line_numbers_get, 0);
960
+ rb_define_module_function(mXML, "default_line_numbers=", rxml_default_line_numbers_set, 1);
961
+ rb_define_module_function(mXML, "default_options", rxml_default_options_get, 0);
962
+ rb_define_module_function(mXML, "default_pedantic_parser", rxml_default_pedantic_parser_get, 0);
963
+ rb_define_module_function(mXML, "default_pedantic_parser=", rxml_default_pedantic_parser_set, 1);
964
+ rb_define_module_function(mXML, "default_substitute_entities", rxml_default_substitute_entities_get, 0);
965
+ rb_define_module_function(mXML, "default_substitute_entities=", rxml_default_substitute_entities_set, 1);
966
+ rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0);
967
+ rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1);
968
+ rb_define_module_function(mXML, "default_validity_checking", rxml_default_validity_checking_get, 0);
969
+ rb_define_module_function(mXML, "default_validity_checking=", rxml_default_validity_checking_set, 1);
970
+ rb_define_module_function(mXML, "default_warnings", rxml_default_warnings_get, 0);
971
+ rb_define_module_function(mXML, "default_warnings=", rxml_default_warnings_set, 1);
972
+ rb_define_module_function(mXML, "features", rxml_features, 0);
973
+ rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
974
+ rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
975
+ rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0);
976
+ rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0);
977
+ }