libxml-ruby 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGES +13 -0
  2. data/ext/libxml/libxml.c +885 -886
  3. data/ext/libxml/ruby_libxml.h +70 -72
  4. data/ext/libxml/ruby_xml_attr.c +76 -76
  5. data/ext/libxml/ruby_xml_attr.h +8 -8
  6. data/ext/libxml/ruby_xml_attributes.c +36 -36
  7. data/ext/libxml/ruby_xml_attributes.h +6 -6
  8. data/ext/libxml/ruby_xml_document.c +133 -220
  9. data/ext/libxml/ruby_xml_document.h +4 -7
  10. data/ext/libxml/ruby_xml_dtd.c +30 -109
  11. data/ext/libxml/ruby_xml_dtd.h +2 -11
  12. data/ext/libxml/ruby_xml_error.c +10 -10
  13. data/ext/libxml/ruby_xml_error.h +4 -4
  14. data/ext/libxml/ruby_xml_html_parser.c +28 -40
  15. data/ext/libxml/ruby_xml_html_parser.h +4 -4
  16. data/ext/libxml/ruby_xml_input.c +208 -32
  17. data/ext/libxml/ruby_xml_input.h +7 -5
  18. data/ext/libxml/ruby_xml_input_cbg.c +3 -3
  19. data/ext/libxml/ruby_xml_node.c +217 -217
  20. data/ext/libxml/ruby_xml_node.h +5 -5
  21. data/ext/libxml/ruby_xml_ns.c +26 -26
  22. data/ext/libxml/ruby_xml_ns.h +4 -4
  23. data/ext/libxml/ruby_xml_parser.c +151 -164
  24. data/ext/libxml/ruby_xml_parser.h +3 -8
  25. data/ext/libxml/ruby_xml_parser_context.c +105 -105
  26. data/ext/libxml/ruby_xml_parser_context.h +4 -4
  27. data/ext/libxml/ruby_xml_reader.c +145 -162
  28. data/ext/libxml/ruby_xml_reader.h +4 -4
  29. data/ext/libxml/ruby_xml_relaxng.c +30 -43
  30. data/ext/libxml/ruby_xml_relaxng.h +2 -7
  31. data/ext/libxml/ruby_xml_sax_parser.c +174 -228
  32. data/ext/libxml/ruby_xml_sax_parser.h +12 -20
  33. data/ext/libxml/ruby_xml_schema.c +31 -44
  34. data/ext/libxml/ruby_xml_schema.h +2 -7
  35. data/ext/libxml/ruby_xml_state.c +6 -6
  36. data/ext/libxml/ruby_xml_state.h +2 -2
  37. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  38. data/ext/libxml/ruby_xml_xinclude.h +3 -3
  39. data/ext/libxml/ruby_xml_xpath.c +1 -1
  40. data/ext/libxml/ruby_xml_xpath.h +3 -12
  41. data/ext/libxml/ruby_xml_xpath_context.c +293 -294
  42. data/ext/libxml/ruby_xml_xpath_context.h +3 -7
  43. data/ext/libxml/ruby_xml_xpath_expression.c +11 -11
  44. data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
  45. data/ext/libxml/ruby_xml_xpath_object.c +52 -66
  46. data/ext/libxml/ruby_xml_xpath_object.h +3 -14
  47. data/ext/libxml/ruby_xml_xpointer.c +11 -12
  48. data/ext/libxml/ruby_xml_xpointer.h +5 -7
  49. data/ext/libxml/sax_parser_callbacks.inc +53 -36
  50. data/ext/libxml/version.h +2 -2
  51. data/ext/vc/libxml_ruby.vcproj +1 -9
  52. data/lib/libxml/html_parser.rb +5 -5
  53. data/lib/libxml/parser.rb +4 -4
  54. data/lib/libxml/sax_parser.rb +24 -0
  55. data/test/tc_document_write.rb +2 -16
  56. data/test/tc_html_parser.rb +57 -5
  57. data/test/tc_input.rb +13 -0
  58. data/test/tc_parser.rb +11 -3
  59. data/test/tc_reader.rb +53 -34
  60. data/test/tc_sax_parser.rb +30 -8
  61. data/test/test.rb +8 -0
  62. data/test/test_suite.rb +1 -1
  63. metadata +5 -6
  64. data/ext/libxml/ruby_xml_encoding.c +0 -164
  65. data/ext/libxml/ruby_xml_encoding.h +0 -13
  66. data/test/tc_encoding.rb +0 -13
data/CHANGES CHANGED
@@ -1,5 +1,18 @@
1
1
  (See log/ChangeLog for more detailed changes derived directly from source control.)
2
2
 
3
+ == 0.9.3 / 2008-11-22 Charlie Savage
4
+
5
+ * Fixed segementation fault caused by documents being freed
6
+ before xpath results that referenced the document (take 2).
7
+
8
+ * Allowed sax parser to use io stream
9
+
10
+ * Combined encoding and input classes
11
+
12
+ * Cleaned up C code - removed remaining legacy structures,
13
+ added static to most methods, changed C namespace from ruby_xml
14
+ to rxml
15
+
3
16
  == 0.9.2 / 2008-11-19 Charlie Savage
4
17
 
5
18
  * Add support for compiled XPath expressions (donated by Pavel Valodzka)
@@ -1,886 +1,885 @@
1
- /* $Id: libxml.c 600 2008-11-19 07:39:29Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
-
7
- VALUE mLibXML;
8
- VALUE mXML;
9
-
10
-
11
- /*
12
- * call-seq:
13
- * XML.catalog_dump -> true
14
- *
15
- * Dump all the global catalog content stdout.
16
- */
17
- VALUE
18
- ruby_xml_catalog_dump(VALUE self) {
19
- xmlCatalogDump(stdout);
20
- return(Qtrue);
21
- }
22
-
23
-
24
- /*
25
- * call-seq:
26
- * XML.catalog_remove(catalog) -> true
27
- *
28
- * Remove the specified resource catalog.
29
- */
30
- VALUE
31
- ruby_xml_catalog_remove(VALUE self, VALUE cat) {
32
- Check_Type(cat, T_STRING);
33
- xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
34
- return(Qtrue);
35
- }
36
-
37
-
38
- /*
39
- * call-seq:
40
- * XML.check_lib_versions -> true
41
- *
42
- * Check LIBXML version matches version the bindings
43
- * were compiled to. Throws an exception if not.
44
- */
45
- VALUE
46
- ruby_xml_check_lib_versions(VALUE class) {
47
- xmlCheckVersion(LIBXML_VERSION);
48
- return(Qtrue);
49
- }
50
-
51
-
52
- /*
53
- * call-seq:
54
- * XML.enabled_automata? -> (true|false)
55
- *
56
- * Determine whether libxml regexp automata support is enabled.
57
- */
58
- VALUE
59
- ruby_xml_enabled_automata_q(VALUE class) {
60
- #ifdef LIBXML_AUTOMATA_ENABLED
61
- return(Qtrue);
62
- #else
63
- return(Qfalse);
64
- #endif
65
- }
66
-
67
-
68
- /*
69
- * call-seq:
70
- * XML.enabled_c14n? -> (true|false)
71
- *
72
- * Determine whether libxml 'canonical XML' support is enabled.
73
- * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
74
- */
75
- VALUE
76
- ruby_xml_enabled_c14n_q(VALUE class) {
77
- #ifdef LIBXML_C14N_ENABLED
78
- return(Qtrue);
79
- #else
80
- return(Qfalse);
81
- #endif
82
- }
83
-
84
-
85
- /*
86
- * call-seq:
87
- * XML.enabled_catalog? -> (true|false)
88
- *
89
- * Determine whether libxml resource catalog support is enabled.
90
- */
91
- VALUE
92
- ruby_xml_enabled_catalog_q(VALUE class) {
93
- #ifdef LIBXML_CATALOG_ENABLED
94
- return(Qtrue);
95
- #else
96
- return(Qfalse);
97
- #endif
98
- }
99
-
100
-
101
- /*
102
- * call-seq:
103
- * XML.enabled_debug? -> (true|false)
104
- *
105
- * Determine whether libxml debugging support is enabled.
106
- */
107
- VALUE
108
- ruby_xml_enabled_debug_q(VALUE class) {
109
- #ifdef LIBXML_DEBUG_ENABLED
110
- return(Qtrue);
111
- #else
112
- return(Qfalse);
113
- #endif
114
- }
115
-
116
-
117
- /*
118
- * call-seq:
119
- * XML.enabled_docbook? -> (true|false)
120
- *
121
- * Determine whether libxml docbook support is enabled.
122
- */
123
- VALUE
124
- ruby_xml_enabled_docbook_q(VALUE class) {
125
- #ifdef LIBXML_DOCB_ENABLED
126
- return(Qtrue);
127
- #else
128
- return(Qfalse);
129
- #endif
130
- }
131
-
132
-
133
- /*
134
- * call-seq:
135
- * XML.enabled_ftp? -> (true|false)
136
- *
137
- * Determine whether libxml ftp client support is enabled.
138
- */
139
- VALUE
140
- ruby_xml_enabled_ftp_q(VALUE class) {
141
- #ifdef LIBXML_FTP_ENABLED
142
- return(Qtrue);
143
- #else
144
- return(Qfalse);
145
- #endif
146
- }
147
-
148
-
149
- /*
150
- * call-seq:
151
- * XML.enabled_http? -> (true|false)
152
- *
153
- * Determine whether libxml http client support is enabled.
154
- */
155
- VALUE
156
- ruby_xml_enabled_http_q(VALUE class) {
157
- #ifdef LIBXML_HTTP_ENABLED
158
- return(Qtrue);
159
- #else
160
- return(Qfalse);
161
- #endif
162
- }
163
-
164
-
165
- /*
166
- * call-seq:
167
- * XML.enabled_html? -> (true|false)
168
- *
169
- * Determine whether libxml html support is enabled.
170
- */
171
- VALUE
172
- ruby_xml_enabled_html_q(VALUE class) {
173
- #ifdef LIBXML_HTML_ENABLED
174
- return(Qtrue);
175
- #else
176
- return(Qfalse);
177
- #endif
178
- }
179
-
180
-
181
- /*
182
- * call-seq:
183
- * XML.enabled_iconv? -> (true|false)
184
- *
185
- * Determine whether libxml iconv support is enabled.
186
- */
187
- VALUE
188
- ruby_xml_enabled_iconv_q(VALUE class) {
189
- #ifdef LIBXML_ICONV_ENABLED
190
- return(Qtrue);
191
- #else
192
- return(Qfalse);
193
- #endif
194
- }
195
-
196
-
197
- /*
198
- * call-seq:
199
- * XML.enabled_memory_debug? -> (true|false)
200
- *
201
- * Determine whether libxml memory location debugging support
202
- * is enabled.
203
- */
204
- VALUE
205
- ruby_xml_enabled_memory_debug_location_q(VALUE class) {
206
- #ifdef DEBUG_MEMORY_LOCATION
207
- return(Qtrue);
208
- #else
209
- return(Qfalse);
210
- #endif
211
- }
212
-
213
-
214
- /*
215
- * call-seq:
216
- * XML.enabled_regexp? -> (true|false)
217
- *
218
- * Determine whether libxml regular expression support is enabled.
219
- */
220
- VALUE
221
- ruby_xml_enabled_regexp_q(VALUE class) {
222
- #ifdef LIBXML_REGEXP_ENABLED
223
- return(Qtrue);
224
- #else
225
- return(Qfalse);
226
- #endif
227
- }
228
-
229
-
230
- /*
231
- * call-seq:
232
- * XML.enabled_schemas? -> (true|false)
233
- *
234
- * Determine whether libxml schema support is enabled.
235
- */
236
- VALUE
237
- ruby_xml_enabled_schemas_q(VALUE class) {
238
- #ifdef LIBXML_SCHEMAS_ENABLED
239
- return(Qtrue);
240
- #else
241
- return(Qfalse);
242
- #endif
243
- }
244
-
245
-
246
- /*
247
- * call-seq:
248
- * XML.enabled_thread? -> (true|false)
249
- *
250
- * Determine whether libxml thread-safe semantics support
251
- * is enabled (I think?).
252
- */
253
- VALUE
254
- ruby_xml_enabled_thread_q(VALUE class) {
255
- #ifdef LIBXML_THREAD_ENABLED
256
- return(Qtrue);
257
- #else
258
- return(Qfalse);
259
- #endif
260
- }
261
-
262
-
263
- /*
264
- * call-seq:
265
- * XML.enabled_unicode? -> (true|false)
266
- *
267
- * Determine whether libxml unicode support is enabled.
268
- */
269
- VALUE
270
- ruby_xml_enabled_unicode_q(VALUE class) {
271
- #ifdef LIBXML_UNICODE_ENABLED
272
- return(Qtrue);
273
- #else
274
- return(Qfalse);
275
- #endif
276
- }
277
-
278
-
279
- /*
280
- * call-seq:
281
- * XML.enabled_xinclude? -> (true|false)
282
- *
283
- * Determine whether libxml xinclude support is enabled.
284
- */
285
- VALUE
286
- ruby_xml_enabled_xinclude_q(VALUE class) {
287
- #ifdef LIBXML_XINCLUDE_ENABLED
288
- return(Qtrue);
289
- #else
290
- return(Qfalse);
291
- #endif
292
- }
293
-
294
-
295
- /*
296
- * call-seq:
297
- * XML.enabled_xpath? -> (true|false)
298
- *
299
- * Determine whether libxml xpath support is enabled.
300
- */
301
- VALUE
302
- ruby_xml_enabled_xpath_q(VALUE class) {
303
- #ifdef LIBXML_XPATH_ENABLED
304
- return(Qtrue);
305
- #else
306
- return(Qfalse);
307
- #endif
308
- }
309
-
310
-
311
- /*
312
- * call-seq:
313
- * XML.enabled_xpointer? -> (true|false)
314
- *
315
- * Determine whether libxml xpointer support is enabled.
316
- */
317
- VALUE
318
- ruby_xml_enabled_xpointer_q(VALUE class) {
319
- #ifdef LIBXML_XPTR_ENABLED
320
- return(Qtrue);
321
- #else
322
- return(Qfalse);
323
- #endif
324
- }
325
-
326
-
327
- /*
328
- * call-seq:
329
- * XML.enabled_zlib? -> (true|false)
330
- *
331
- * Determine whether libxml zlib support is enabled.
332
- */
333
- VALUE
334
- ruby_xml_enabled_zlib_q(VALUE class) {
335
- #ifdef HAVE_ZLIB_H
336
- return(Qtrue);
337
- #else
338
- return(Qfalse);
339
- #endif
340
- }
341
-
342
-
343
- /*
344
- * call-seq:
345
- * XML.debug_entities -> (true|false)
346
- *
347
- * Determine whether included-entity debugging is enabled.
348
- * (Requires Libxml to be compiled with debugging support)
349
- */
350
- VALUE
351
- ruby_xml_debug_entities_get(VALUE class) {
352
- #ifdef LIBXML_DEBUG_ENABLED
353
- if (xmlParserDebugEntities)
354
- return(Qtrue);
355
- else
356
- return(Qfalse);
357
- #else
358
- rb_warn("libxml was compiled with debugging turned off");
359
- return(Qfalse);
360
- #endif
361
- }
362
-
363
-
364
- /*
365
- * call-seq:
366
- * XML.debug_entities = true|false
367
- *
368
- * Enable or disable included-entity debugging.
369
- * (Requires Libxml to be compiled with debugging support)
370
- */
371
- VALUE
372
- ruby_xml_debug_entities_set(VALUE class, VALUE bool) {
373
- #ifdef LIBXML_DEBUG_ENABLED
374
- if (TYPE(bool) == T_FALSE) {
375
- xmlParserDebugEntities = 0;
376
- return(Qfalse);
377
- } else {
378
- xmlParserDebugEntities = 1;
379
- return(Qtrue);
380
- }
381
- #else
382
- rb_warn("libxml was compiled with debugging turned off");
383
- #endif
384
- }
385
-
386
-
387
- /*
388
- * call-seq:
389
- * XML.default_keep_blanks -> (true|false)
390
- *
391
- * Determine whether parsers retain whitespace by default.
392
- */
393
- VALUE
394
- ruby_xml_default_keep_blanks_get(VALUE class) {
395
- if (xmlKeepBlanksDefaultValue)
396
- return(Qtrue);
397
- else
398
- return(Qfalse);
399
- }
400
-
401
-
402
- /*
403
- * call-seq:
404
- * XML.default_keep_blanks = true|false
405
- *
406
- * Controls whether parsers retain whitespace by default.
407
- */
408
- VALUE
409
- ruby_xml_default_keep_blanks_set(VALUE class, VALUE bool) {
410
- if (TYPE(bool) == T_FALSE) {
411
- xmlKeepBlanksDefaultValue = 0;
412
- return(Qfalse);
413
- } else if (TYPE(bool) == T_TRUE) {
414
- xmlKeepBlanksDefaultValue = 1;
415
- return(Qtrue);
416
- } else {
417
- rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
418
- }
419
- }
420
-
421
-
422
- /*
423
- * call-seq:
424
- * XML.default_load_external_dtd -> (true|false)
425
- *
426
- * Determine whether parsers load external DTDs by default.
427
- */
428
- VALUE
429
- ruby_xml_default_load_external_dtd_get(VALUE class) {
430
- if (xmlLoadExtDtdDefaultValue)
431
- return(Qtrue);
432
- else
433
- return(Qfalse);
434
- }
435
-
436
-
437
- /*
438
- * call-seq:
439
- * XML.default_load_external_dtd = true|false
440
- *
441
- * Controls whether parsers load external DTDs by default.
442
- */
443
- VALUE
444
- ruby_xml_default_load_external_dtd_set(VALUE class, VALUE bool) {
445
- if (TYPE(bool) == T_FALSE) {
446
- xmlLoadExtDtdDefaultValue = 0;
447
- return(Qfalse);
448
- } else {
449
- xmlLoadExtDtdDefaultValue = 1;
450
- return(Qtrue);
451
- }
452
- }
453
-
454
-
455
- /*
456
- * call-seq:
457
- * XML.default_line_numbers -> (true|false)
458
- *
459
- * Determine whether parsers retain line-numbers by default.
460
- */
461
- VALUE
462
- ruby_xml_default_line_numbers_get(VALUE class) {
463
- if (xmlLineNumbersDefaultValue)
464
- return(Qtrue);
465
- else
466
- return(Qfalse);
467
- }
468
-
469
-
470
- /*
471
- * call-seq:
472
- * XML.default_line_numbers = true|false
473
- *
474
- * Controls whether parsers retain line-numbers by default.
475
- */
476
- VALUE
477
- ruby_xml_default_line_numbers_set(VALUE class, VALUE bool) {
478
- if (TYPE(bool) == T_FALSE) {
479
- xmlLineNumbersDefault(0);
480
- return(Qfalse);
481
- } else {
482
- xmlLineNumbersDefault(1);
483
- return(Qtrue);
484
- }
485
- }
486
-
487
-
488
- /*
489
- * call-seq:
490
- * XML.default_pedantic_parser -> (true|false)
491
- *
492
- * Determine whether parsers are pedantic by default.
493
- */
494
- VALUE
495
- ruby_xml_default_pedantic_parser_get(VALUE class) {
496
- if (xmlPedanticParserDefaultValue)
497
- return(Qtrue);
498
- else
499
- return(Qfalse);
500
- }
501
-
502
-
503
- /*
504
- * call-seq:
505
- * XML.default_pedantic_parser = true|false
506
- *
507
- * Controls whether parsers are pedantic by default.
508
- */
509
- VALUE
510
- ruby_xml_default_pedantic_parser_set(VALUE class, VALUE bool) {
511
- if (TYPE(bool) == T_FALSE) {
512
- xmlPedanticParserDefault(0);
513
- return(Qfalse);
514
- } else {
515
- xmlPedanticParserDefault(1);
516
- return(Qtrue);
517
- }
518
- }
519
-
520
-
521
- /*
522
- * call-seq:
523
- * XML.default_substitute_entities -> (true|false)
524
- *
525
- * Determine whether parsers perform inline entity substitution
526
- * (for external entities) by default.
527
- */
528
- VALUE
529
- ruby_xml_default_substitute_entities_get(VALUE class) {
530
- if (xmlSubstituteEntitiesDefaultValue)
531
- return(Qtrue);
532
- else
533
- return(Qfalse);
534
- }
535
-
536
-
537
- /*
538
- * call-seq:
539
- * XML.default_substitute_entities = true|false
540
- *
541
- * Controls whether parsers perform inline entity substitution
542
- * (for external entities) by default.
543
- */
544
- VALUE
545
- ruby_xml_default_substitute_entities_set(VALUE class, VALUE bool) {
546
- if (TYPE(bool) == T_FALSE) {
547
- xmlSubstituteEntitiesDefault(0);
548
- return(Qfalse);
549
- } else {
550
- xmlSubstituteEntitiesDefault(1);
551
- return(Qtrue);
552
- }
553
- }
554
-
555
-
556
- /*
557
- * call-seq:
558
- * XML.default_tree_indent_string -> "string"
559
- *
560
- * Obtain the default string used by parsers to indent the XML tree
561
- * for output.
562
- */
563
- VALUE
564
- ruby_xml_default_tree_indent_string_get(VALUE class) {
565
- if (xmlTreeIndentString == NULL)
566
- return(Qnil);
567
- else
568
- return(rb_str_new2(xmlTreeIndentString));
569
- }
570
-
571
-
572
- /*
573
- * call-seq:
574
- * XML.default_tree_indent_string = "string"
575
- *
576
- * Set the default string used by parsers to indent the XML tree
577
- * for output.
578
- */
579
- VALUE
580
- ruby_xml_default_tree_indent_string_set(VALUE class, VALUE string) {
581
- Check_Type(string, T_STRING);
582
- xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
583
- return(string);
584
- }
585
-
586
-
587
- /*
588
- * call-seq:
589
- * XML.default_validity_checking -> (true|false)
590
- *
591
- * Determine whether parsers perform XML validation by default.
592
- */
593
- VALUE
594
- ruby_xml_default_validity_checking_get(VALUE class) {
595
- if (xmlDoValidityCheckingDefaultValue)
596
- return(Qtrue);
597
- else
598
- return(Qfalse);
599
- }
600
-
601
-
602
- /*
603
- * call-seq:
604
- * XML.default_validity_checking = true|false
605
- *
606
- * Controls whether parsers perform XML validation by default.
607
- */
608
- VALUE
609
- ruby_xml_default_validity_checking_set(VALUE class, VALUE bool) {
610
- if (TYPE(bool) == T_FALSE) {
611
- xmlDoValidityCheckingDefaultValue = 0;
612
- return(Qfalse);
613
- } else {
614
- xmlDoValidityCheckingDefaultValue = 1;
615
- return(Qtrue);
616
- }
617
- }
618
-
619
-
620
- /*
621
- * call-seq:
622
- * XML.default_warnings -> (true|false)
623
- *
624
- * Determine whether parsers output warnings by default.
625
- */
626
- VALUE
627
- ruby_xml_default_warnings_get(VALUE class) {
628
- if (xmlGetWarningsDefaultValue)
629
- return(Qtrue);
630
- else
631
- return(Qfalse);
632
- }
633
-
634
-
635
- /*
636
- * call-seq:
637
- * XML.default_warnings = true|false
638
- *
639
- * Controls whether parsers output warnings by default.
640
- */
641
- VALUE
642
- ruby_xml_default_warnings_set(VALUE class, VALUE bool) {
643
- if (TYPE(bool) == T_FALSE) {
644
- xmlGetWarningsDefaultValue = 0;
645
- return(Qfalse);
646
- } else {
647
- xmlGetWarningsDefaultValue = 1;
648
- return(Qtrue);
649
- }
650
- }
651
-
652
-
653
- /*
654
- * call-seq:
655
- * XML.default_compression -> (true|false)
656
- *
657
- * Determine whether parsers use Zlib compression by default
658
- * (requires libxml to be compiled with Zlib support).
659
- */
660
- VALUE
661
- ruby_xml_default_compression_get(VALUE class) {
662
- #ifdef HAVE_ZLIB_H
663
- return(INT2FIX(xmlGetCompressMode()));
664
- #else
665
- rb_warn("libxml was compiled without zlib support");
666
- return(Qfalse);
667
- #endif
668
- }
669
-
670
-
671
- /*
672
- * call-seq:
673
- * XML.default_compression = true|false
674
- *
675
- * Controls whether parsers use Zlib compression by default
676
- * (requires libxml to be compiled with Zlib support).
677
- */
678
- VALUE
679
- ruby_xml_default_compression_set(VALUE class, VALUE num) {
680
- #ifdef HAVE_ZLIB_H
681
- Check_Type(num, T_FIXNUM);
682
- xmlSetCompressMode(FIX2INT(num));
683
- return(num);
684
- #else
685
- rb_warn("libxml was compiled without zlib support");
686
- return(Qfalse);
687
- #endif
688
- }
689
-
690
-
691
- /*
692
- * call-seq:
693
- * XML.features -> ["feature", ..., "feature"]
694
- *
695
- * Obtains an array of strings representing features supported
696
- * (and enabled) by the installed libxml.
697
- */
698
- VALUE
699
- ruby_xml_features(VALUE class) {
700
- VALUE arr, str;
701
- int i, len = MAX_LIBXML_FEATURES_LEN;
702
- char **list = NULL;
703
-
704
- list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
705
- MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
706
-
707
- arr = rb_ary_new();
708
- if (xmlGetFeaturesList(&len, (const char **)list) == -1)
709
- return Qnil;
710
-
711
- for (i = 0; i < len; i++) {
712
- str = rb_str_new2((const char *)list[i]);
713
- rb_gc_unregister_address(&str);
714
- rb_ary_push(arr, str);
715
- }
716
-
717
- if (len == MAX_LIBXML_FEATURES_LEN)
718
- rb_warn("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");
719
-
720
- ruby_xfree(list);
721
- return(arr);
722
- }
723
-
724
-
725
- /*
726
- * call-seq:
727
- * XML.indent_tree_output -> (true|false)
728
- *
729
- * Determines whether XML output will be indented
730
- * (using the string supplied to +default_indent_tree_string+)
731
- */
732
- VALUE
733
- ruby_xml_indent_tree_output_get(VALUE class) {
734
- if (xmlIndentTreeOutput)
735
- return(Qtrue);
736
- else
737
- return(Qfalse);
738
- }
739
-
740
-
741
- /*
742
- * call-seq:
743
- * XML.indent_tree_output = true|false
744
- *
745
- * Controls whether XML output will be indented
746
- * (using the string supplied to +default_indent_tree_string+)
747
- */
748
- VALUE
749
- ruby_xml_indent_tree_output_set(VALUE class, VALUE bool) {
750
- if (TYPE(bool) == T_TRUE) {
751
- xmlIndentTreeOutput = 1;
752
- return(Qtrue);
753
- } else if (TYPE(bool) == T_FALSE) {
754
- xmlIndentTreeOutput = 0;
755
- return(Qfalse);
756
- } else {
757
- rb_raise(rb_eArgError, "Invalid argument, must be boolean");
758
- }
759
- }
760
-
761
- /*
762
- * call-seq:
763
- * XML.memory_dump -> (true|false)
764
- *
765
- * Perform a parser memory dump (requires memory debugging
766
- * support in libxml).
767
- */
768
- VALUE
769
- ruby_xml_memory_dump(VALUE self) {
770
- #ifdef DEBUG_MEMORY_LOCATION
771
- xmlMemoryDump();
772
- return(Qtrue);
773
- #else
774
- rb_warn("libxml was compiled without memory debugging support");
775
- return(Qfalse);
776
- #endif
777
- }
778
-
779
-
780
- /*
781
- * call-seq:
782
- * XML.memory_used -> num_bytes
783
- *
784
- * Perform a parser memory dump (requires memory debugging
785
- * support in libxml).
786
- */
787
- VALUE
788
- ruby_xml_memory_used(VALUE self) {
789
- #ifdef DEBUG_MEMORY_LOCATION
790
- return(INT2NUM(xmlMemUsed()));
791
- #else
792
- rb_warn("libxml was compiled without memory debugging support");
793
- return(Qfalse);
794
- #endif
795
- }
796
-
797
- #if defined(_WIN32)
798
- __declspec(dllexport)
799
- #endif
800
- void
801
- Init_libxml_ruby(void) {
802
- mLibXML = rb_define_module("LibXML");
803
- mXML = rb_define_module_under(mLibXML, "XML");
804
-
805
- /* Constants */
806
- rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
807
- rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
808
- rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
809
- rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*)XML_XML_NAMESPACE));
810
-
811
- rb_define_module_function(mXML, "enabled_automata?", ruby_xml_enabled_automata_q, 0);
812
- rb_define_module_function(mXML, "enabled_c14n?", ruby_xml_enabled_c14n_q, 0);
813
- rb_define_module_function(mXML, "enabled_catalog?", ruby_xml_enabled_catalog_q, 0);
814
- rb_define_module_function(mXML, "enabled_debug?", ruby_xml_enabled_debug_q, 0);
815
- rb_define_module_function(mXML, "enabled_docbook?", ruby_xml_enabled_docbook_q, 0);
816
- rb_define_module_function(mXML, "enabled_ftp?", ruby_xml_enabled_ftp_q, 0);
817
- rb_define_module_function(mXML, "enabled_http?", ruby_xml_enabled_http_q, 0);
818
- rb_define_module_function(mXML, "enabled_html?", ruby_xml_enabled_html_q, 0);
819
- rb_define_module_function(mXML, "enabled_iconv?", ruby_xml_enabled_iconv_q, 0);
820
- rb_define_module_function(mXML, "enabled_memory_debug?", ruby_xml_enabled_memory_debug_location_q, 0);
821
- rb_define_module_function(mXML, "enabled_regexp?", ruby_xml_enabled_regexp_q, 0);
822
- rb_define_module_function(mXML, "enabled_schemas?", ruby_xml_enabled_schemas_q, 0);
823
- rb_define_module_function(mXML, "enabled_thread?", ruby_xml_enabled_thread_q, 0);
824
- rb_define_module_function(mXML, "enabled_unicode?", ruby_xml_enabled_unicode_q, 0);
825
- rb_define_module_function(mXML, "enabled_xinclude?", ruby_xml_enabled_xinclude_q, 0);
826
- rb_define_module_function(mXML, "enabled_xpath?", ruby_xml_enabled_xpath_q, 0);
827
- rb_define_module_function(mXML, "enabled_xpointer?", ruby_xml_enabled_xpointer_q, 0);
828
- rb_define_module_function(mXML, "enabled_zlib?", ruby_xml_enabled_zlib_q, 0);
829
-
830
- rb_define_module_function(mXML, "catalog_dump", ruby_xml_catalog_dump, 0);
831
- rb_define_module_function(mXML, "catalog_remove", ruby_xml_catalog_remove, 1);
832
- rb_define_module_function(mXML, "check_lib_versions", ruby_xml_check_lib_versions, 0);
833
- rb_define_module_function(mXML, "debug_entities", ruby_xml_debug_entities_get, 0);
834
- rb_define_module_function(mXML, "debug_entities=", ruby_xml_debug_entities_set, 1);
835
- rb_define_module_function(mXML, "default_compression", ruby_xml_default_compression_get, 0);
836
- rb_define_module_function(mXML, "default_compression=", ruby_xml_default_compression_set, 1);
837
- rb_define_module_function(mXML, "default_keep_blanks", ruby_xml_default_keep_blanks_get, 0);
838
- rb_define_module_function(mXML, "default_keep_blanks=", ruby_xml_default_keep_blanks_set, 1);
839
- rb_define_module_function(mXML, "default_load_external_dtd", ruby_xml_default_load_external_dtd_get, 0);
840
- rb_define_module_function(mXML, "default_load_external_dtd=", ruby_xml_default_load_external_dtd_set, 1);
841
- rb_define_module_function(mXML, "default_line_numbers", ruby_xml_default_line_numbers_get, 0);
842
- rb_define_module_function(mXML, "default_line_numbers=", ruby_xml_default_line_numbers_set, 1);
843
- rb_define_module_function(mXML, "default_pedantic_parser", ruby_xml_default_pedantic_parser_get, 0);
844
- rb_define_module_function(mXML, "default_pedantic_parser=", ruby_xml_default_pedantic_parser_set, 1);
845
- rb_define_module_function(mXML, "default_substitute_entities", ruby_xml_default_substitute_entities_get, 0);
846
- rb_define_module_function(mXML, "default_substitute_entities=", ruby_xml_default_substitute_entities_set, 1);
847
- rb_define_module_function(mXML, "default_tree_indent_string", ruby_xml_default_tree_indent_string_get, 0);
848
- rb_define_module_function(mXML, "default_tree_indent_string=", ruby_xml_default_tree_indent_string_set, 1);
849
- rb_define_module_function(mXML, "default_validity_checking", ruby_xml_default_validity_checking_get, 0);
850
- rb_define_module_function(mXML, "default_validity_checking=", ruby_xml_default_validity_checking_set, 1);
851
- rb_define_module_function(mXML, "default_warnings", ruby_xml_default_warnings_get, 0);
852
- rb_define_module_function(mXML, "default_warnings=", ruby_xml_default_warnings_set, 1);
853
- rb_define_module_function(mXML, "features", ruby_xml_features, 0);
854
- rb_define_module_function(mXML, "indent_tree_output", ruby_xml_indent_tree_output_get, 0);
855
- rb_define_module_function(mXML, "indent_tree_output=", ruby_xml_indent_tree_output_set, 1);
856
- rb_define_module_function(mXML, "memory_dump", ruby_xml_memory_dump, 0);
857
- rb_define_module_function(mXML, "memory_used", ruby_xml_memory_used, 0);
858
-
859
- /* Now initialize all the other modules */
860
- ruby_init_xml_encoding();
861
- ruby_init_xml_error();
862
- ruby_init_xml_input();
863
- ruby_init_state();
864
- ruby_init_parser();
865
- ruby_init_xml_parser_context();
866
- ruby_init_xml_node();
867
- ruby_init_xml_attributes();
868
- ruby_init_xml_attr();
869
- ruby_init_xml_document();
870
- ruby_init_xml_ns();
871
- ruby_init_xml_sax_parser();
872
- ruby_init_xml_xinclude();
873
- ruby_init_xml_xpath();
874
- ruby_init_xml_xpath_context();
875
- ruby_init_xml_xpath_expression();
876
- ruby_init_xml_xpointer();
877
- ruby_init_html_parser();
878
- ruby_init_input_callbacks();
879
- ruby_init_xml_dtd();
880
- ruby_init_xml_schema();
881
- ruby_init_xml_relaxng();
882
- ruby_init_xml_reader();
883
-
884
- ruby_xml_default_substitute_entities_set(mXML, Qtrue);
885
- ruby_xml_default_load_external_dtd_set(mXML, Qtrue);
886
- }
1
+ /* $Id: libxml.c 615 2008-11-22 08:36:27Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+
7
+ VALUE mLibXML;
8
+ VALUE mXML;
9
+
10
+
11
+ /*
12
+ * call-seq:
13
+ * XML.catalog_dump -> true
14
+ *
15
+ * Dump all the global catalog content stdout.
16
+ */
17
+ static VALUE
18
+ rxml_catalog_dump(VALUE self) {
19
+ xmlCatalogDump(stdout);
20
+ return(Qtrue);
21
+ }
22
+
23
+
24
+ /*
25
+ * call-seq:
26
+ * XML.catalog_remove(catalog) -> true
27
+ *
28
+ * Remove the specified resource catalog.
29
+ */
30
+ static VALUE
31
+ rxml_catalog_remove(VALUE self, VALUE cat) {
32
+ Check_Type(cat, T_STRING);
33
+ xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
34
+ return(Qtrue);
35
+ }
36
+
37
+
38
+ /*
39
+ * call-seq:
40
+ * XML.check_lib_versions -> true
41
+ *
42
+ * Check LIBXML version matches version the bindings
43
+ * were compiled to. Throws an exception if not.
44
+ */
45
+ static VALUE
46
+ rxml_check_lib_versions(VALUE class) {
47
+ xmlCheckVersion(LIBXML_VERSION);
48
+ return(Qtrue);
49
+ }
50
+
51
+
52
+ /*
53
+ * call-seq:
54
+ * XML.enabled_automata? -> (true|false)
55
+ *
56
+ * Determine whether libxml regexp automata support is enabled.
57
+ */
58
+ static VALUE
59
+ rxml_enabled_automata_q(VALUE class) {
60
+ #ifdef LIBXML_AUTOMATA_ENABLED
61
+ return(Qtrue);
62
+ #else
63
+ return(Qfalse);
64
+ #endif
65
+ }
66
+
67
+
68
+ /*
69
+ * call-seq:
70
+ * XML.enabled_c14n? -> (true|false)
71
+ *
72
+ * Determine whether libxml 'canonical XML' support is enabled.
73
+ * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
74
+ */
75
+ static VALUE
76
+ rxml_enabled_c14n_q(VALUE class) {
77
+ #ifdef LIBXML_C14N_ENABLED
78
+ return(Qtrue);
79
+ #else
80
+ return(Qfalse);
81
+ #endif
82
+ }
83
+
84
+
85
+ /*
86
+ * call-seq:
87
+ * XML.enabled_catalog? -> (true|false)
88
+ *
89
+ * Determine whether libxml resource catalog support is enabled.
90
+ */
91
+ static VALUE
92
+ rxml_enabled_catalog_q(VALUE class) {
93
+ #ifdef LIBXML_CATALOG_ENABLED
94
+ return(Qtrue);
95
+ #else
96
+ return(Qfalse);
97
+ #endif
98
+ }
99
+
100
+
101
+ /*
102
+ * call-seq:
103
+ * XML.enabled_debug? -> (true|false)
104
+ *
105
+ * Determine whether libxml debugging support is enabled.
106
+ */
107
+ static VALUE
108
+ rxml_enabled_debug_q(VALUE class) {
109
+ #ifdef LIBXML_DEBUG_ENABLED
110
+ return(Qtrue);
111
+ #else
112
+ return(Qfalse);
113
+ #endif
114
+ }
115
+
116
+
117
+ /*
118
+ * call-seq:
119
+ * XML.enabled_docbook? -> (true|false)
120
+ *
121
+ * Determine whether libxml docbook support is enabled.
122
+ */
123
+ static VALUE
124
+ rxml_enabled_docbook_q(VALUE class) {
125
+ #ifdef LIBXML_DOCB_ENABLED
126
+ return(Qtrue);
127
+ #else
128
+ return(Qfalse);
129
+ #endif
130
+ }
131
+
132
+
133
+ /*
134
+ * call-seq:
135
+ * XML.enabled_ftp? -> (true|false)
136
+ *
137
+ * Determine whether libxml ftp client support is enabled.
138
+ */
139
+ static VALUE
140
+ rxml_enabled_ftp_q(VALUE class) {
141
+ #ifdef LIBXML_FTP_ENABLED
142
+ return(Qtrue);
143
+ #else
144
+ return(Qfalse);
145
+ #endif
146
+ }
147
+
148
+
149
+ /*
150
+ * call-seq:
151
+ * XML.enabled_http? -> (true|false)
152
+ *
153
+ * Determine whether libxml http client support is enabled.
154
+ */
155
+ static VALUE
156
+ rxml_enabled_http_q(VALUE class) {
157
+ #ifdef LIBXML_HTTP_ENABLED
158
+ return(Qtrue);
159
+ #else
160
+ return(Qfalse);
161
+ #endif
162
+ }
163
+
164
+
165
+ /*
166
+ * call-seq:
167
+ * XML.enabled_html? -> (true|false)
168
+ *
169
+ * Determine whether libxml html support is enabled.
170
+ */
171
+ static VALUE
172
+ rxml_enabled_html_q(VALUE class) {
173
+ #ifdef LIBXML_HTML_ENABLED
174
+ return(Qtrue);
175
+ #else
176
+ return(Qfalse);
177
+ #endif
178
+ }
179
+
180
+
181
+ /*
182
+ * call-seq:
183
+ * XML.enabled_iconv? -> (true|false)
184
+ *
185
+ * Determine whether libxml iconv support is enabled.
186
+ */
187
+ static VALUE
188
+ rxml_enabled_iconv_q(VALUE class) {
189
+ #ifdef LIBXML_ICONV_ENABLED
190
+ return(Qtrue);
191
+ #else
192
+ return(Qfalse);
193
+ #endif
194
+ }
195
+
196
+
197
+ /*
198
+ * call-seq:
199
+ * XML.enabled_memory_debug? -> (true|false)
200
+ *
201
+ * Determine whether libxml memory location debugging support
202
+ * is enabled.
203
+ */
204
+ static VALUE
205
+ rxml_enabled_memory_debug_location_q(VALUE class) {
206
+ #ifdef DEBUG_MEMORY_LOCATION
207
+ return(Qtrue);
208
+ #else
209
+ return(Qfalse);
210
+ #endif
211
+ }
212
+
213
+
214
+ /*
215
+ * call-seq:
216
+ * XML.enabled_regexp? -> (true|false)
217
+ *
218
+ * Determine whether libxml regular expression support is enabled.
219
+ */
220
+ static VALUE
221
+ rxml_enabled_regexp_q(VALUE class) {
222
+ #ifdef LIBXML_REGEXP_ENABLED
223
+ return(Qtrue);
224
+ #else
225
+ return(Qfalse);
226
+ #endif
227
+ }
228
+
229
+
230
+ /*
231
+ * call-seq:
232
+ * XML.enabled_schemas? -> (true|false)
233
+ *
234
+ * Determine whether libxml schema support is enabled.
235
+ */
236
+ static VALUE
237
+ rxml_enabled_schemas_q(VALUE class) {
238
+ #ifdef LIBXML_SCHEMAS_ENABLED
239
+ return(Qtrue);
240
+ #else
241
+ return(Qfalse);
242
+ #endif
243
+ }
244
+
245
+
246
+ /*
247
+ * call-seq:
248
+ * XML.enabled_thread? -> (true|false)
249
+ *
250
+ * Determine whether libxml thread-safe semantics support
251
+ * is enabled (I think?).
252
+ */
253
+ static VALUE
254
+ rxml_enabled_thread_q(VALUE class) {
255
+ #ifdef LIBXML_THREAD_ENABLED
256
+ return(Qtrue);
257
+ #else
258
+ return(Qfalse);
259
+ #endif
260
+ }
261
+
262
+
263
+ /*
264
+ * call-seq:
265
+ * XML.enabled_unicode? -> (true|false)
266
+ *
267
+ * Determine whether libxml unicode support is enabled.
268
+ */
269
+ static VALUE
270
+ rxml_enabled_unicode_q(VALUE class) {
271
+ #ifdef LIBXML_UNICODE_ENABLED
272
+ return(Qtrue);
273
+ #else
274
+ return(Qfalse);
275
+ #endif
276
+ }
277
+
278
+
279
+ /*
280
+ * call-seq:
281
+ * XML.enabled_xinclude? -> (true|false)
282
+ *
283
+ * Determine whether libxml xinclude support is enabled.
284
+ */
285
+ static VALUE
286
+ rxml_enabled_xinclude_q(VALUE class) {
287
+ #ifdef LIBXML_XINCLUDE_ENABLED
288
+ return(Qtrue);
289
+ #else
290
+ return(Qfalse);
291
+ #endif
292
+ }
293
+
294
+
295
+ /*
296
+ * call-seq:
297
+ * XML.enabled_xpath? -> (true|false)
298
+ *
299
+ * Determine whether libxml xpath support is enabled.
300
+ */
301
+ static VALUE
302
+ rxml_enabled_xpath_q(VALUE class) {
303
+ #ifdef LIBXML_XPATH_ENABLED
304
+ return(Qtrue);
305
+ #else
306
+ return(Qfalse);
307
+ #endif
308
+ }
309
+
310
+
311
+ /*
312
+ * call-seq:
313
+ * XML.enabled_xpointer? -> (true|false)
314
+ *
315
+ * Determine whether libxml xpointer support is enabled.
316
+ */
317
+ static VALUE
318
+ rxml_enabled_xpointer_q(VALUE class) {
319
+ #ifdef LIBXML_XPTR_ENABLED
320
+ return(Qtrue);
321
+ #else
322
+ return(Qfalse);
323
+ #endif
324
+ }
325
+
326
+
327
+ /*
328
+ * call-seq:
329
+ * XML.enabled_zlib? -> (true|false)
330
+ *
331
+ * Determine whether libxml zlib support is enabled.
332
+ */
333
+ static VALUE
334
+ rxml_enabled_zlib_q(VALUE class) {
335
+ #ifdef HAVE_ZLIB_H
336
+ return(Qtrue);
337
+ #else
338
+ return(Qfalse);
339
+ #endif
340
+ }
341
+
342
+
343
+ /*
344
+ * call-seq:
345
+ * XML.debug_entities -> (true|false)
346
+ *
347
+ * Determine whether included-entity debugging is enabled.
348
+ * (Requires Libxml to be compiled with debugging support)
349
+ */
350
+ static VALUE
351
+ rxml_debug_entities_get(VALUE class) {
352
+ #ifdef LIBXML_DEBUG_ENABLED
353
+ if (xmlParserDebugEntities)
354
+ return(Qtrue);
355
+ else
356
+ return(Qfalse);
357
+ #else
358
+ rb_warn("libxml was compiled with debugging turned off");
359
+ return(Qfalse);
360
+ #endif
361
+ }
362
+
363
+
364
+ /*
365
+ * call-seq:
366
+ * XML.debug_entities = true|false
367
+ *
368
+ * Enable or disable included-entity debugging.
369
+ * (Requires Libxml to be compiled with debugging support)
370
+ */
371
+ static VALUE
372
+ rxml_debug_entities_set(VALUE class, VALUE bool) {
373
+ #ifdef LIBXML_DEBUG_ENABLED
374
+ if (TYPE(bool) == T_FALSE) {
375
+ xmlParserDebugEntities = 0;
376
+ return(Qfalse);
377
+ } else {
378
+ xmlParserDebugEntities = 1;
379
+ return(Qtrue);
380
+ }
381
+ #else
382
+ rb_warn("libxml was compiled with debugging turned off");
383
+ #endif
384
+ }
385
+
386
+
387
+ /*
388
+ * call-seq:
389
+ * XML.default_keep_blanks -> (true|false)
390
+ *
391
+ * Determine whether parsers retain whitespace by default.
392
+ */
393
+ static VALUE
394
+ rxml_default_keep_blanks_get(VALUE class) {
395
+ if (xmlKeepBlanksDefaultValue)
396
+ return(Qtrue);
397
+ else
398
+ return(Qfalse);
399
+ }
400
+
401
+
402
+ /*
403
+ * call-seq:
404
+ * XML.default_keep_blanks = true|false
405
+ *
406
+ * Controls whether parsers retain whitespace by default.
407
+ */
408
+ static VALUE
409
+ rxml_default_keep_blanks_set(VALUE class, VALUE bool) {
410
+ if (TYPE(bool) == T_FALSE) {
411
+ xmlKeepBlanksDefaultValue = 0;
412
+ return(Qfalse);
413
+ } else if (TYPE(bool) == T_TRUE) {
414
+ xmlKeepBlanksDefaultValue = 1;
415
+ return(Qtrue);
416
+ } else {
417
+ rb_raise(rb_eArgError, "Invalid argument, must be a boolean");
418
+ }
419
+ }
420
+
421
+
422
+ /*
423
+ * call-seq:
424
+ * XML.default_load_external_dtd -> (true|false)
425
+ *
426
+ * Determine whether parsers load external DTDs by default.
427
+ */
428
+ static VALUE
429
+ rxml_default_load_external_dtd_get(VALUE class) {
430
+ if (xmlLoadExtDtdDefaultValue)
431
+ return(Qtrue);
432
+ else
433
+ return(Qfalse);
434
+ }
435
+
436
+
437
+ /*
438
+ * call-seq:
439
+ * XML.default_load_external_dtd = true|false
440
+ *
441
+ * Controls whether parsers load external DTDs by default.
442
+ */
443
+ static VALUE
444
+ rxml_default_load_external_dtd_set(VALUE class, VALUE bool) {
445
+ if (TYPE(bool) == T_FALSE) {
446
+ xmlLoadExtDtdDefaultValue = 0;
447
+ return(Qfalse);
448
+ } else {
449
+ xmlLoadExtDtdDefaultValue = 1;
450
+ return(Qtrue);
451
+ }
452
+ }
453
+
454
+
455
+ /*
456
+ * call-seq:
457
+ * XML.default_line_numbers -> (true|false)
458
+ *
459
+ * Determine whether parsers retain line-numbers by default.
460
+ */
461
+ static VALUE
462
+ rxml_default_line_numbers_get(VALUE class) {
463
+ if (xmlLineNumbersDefaultValue)
464
+ return(Qtrue);
465
+ else
466
+ return(Qfalse);
467
+ }
468
+
469
+
470
+ /*
471
+ * call-seq:
472
+ * XML.default_line_numbers = true|false
473
+ *
474
+ * Controls whether parsers retain line-numbers by default.
475
+ */
476
+ static VALUE
477
+ rxml_default_line_numbers_set(VALUE class, VALUE bool) {
478
+ if (TYPE(bool) == T_FALSE) {
479
+ xmlLineNumbersDefault(0);
480
+ return(Qfalse);
481
+ } else {
482
+ xmlLineNumbersDefault(1);
483
+ return(Qtrue);
484
+ }
485
+ }
486
+
487
+
488
+ /*
489
+ * call-seq:
490
+ * XML.default_pedantic_parser -> (true|false)
491
+ *
492
+ * Determine whether parsers are pedantic by default.
493
+ */
494
+ static VALUE
495
+ rxml_default_pedantic_parser_get(VALUE class) {
496
+ if (xmlPedanticParserDefaultValue)
497
+ return(Qtrue);
498
+ else
499
+ return(Qfalse);
500
+ }
501
+
502
+
503
+ /*
504
+ * call-seq:
505
+ * XML.default_pedantic_parser = true|false
506
+ *
507
+ * Controls whether parsers are pedantic by default.
508
+ */
509
+ static VALUE
510
+ rxml_default_pedantic_parser_set(VALUE class, VALUE bool) {
511
+ if (TYPE(bool) == T_FALSE) {
512
+ xmlPedanticParserDefault(0);
513
+ return(Qfalse);
514
+ } else {
515
+ xmlPedanticParserDefault(1);
516
+ return(Qtrue);
517
+ }
518
+ }
519
+
520
+
521
+ /*
522
+ * call-seq:
523
+ * XML.default_substitute_entities -> (true|false)
524
+ *
525
+ * Determine whether parsers perform inline entity substitution
526
+ * (for external entities) by default.
527
+ */
528
+ static VALUE
529
+ rxml_default_substitute_entities_get(VALUE class) {
530
+ if (xmlSubstituteEntitiesDefaultValue)
531
+ return(Qtrue);
532
+ else
533
+ return(Qfalse);
534
+ }
535
+
536
+
537
+ /*
538
+ * call-seq:
539
+ * XML.default_substitute_entities = true|false
540
+ *
541
+ * Controls whether parsers perform inline entity substitution
542
+ * (for external entities) by default.
543
+ */
544
+ static VALUE
545
+ rxml_default_substitute_entities_set(VALUE class, VALUE bool) {
546
+ if (TYPE(bool) == T_FALSE) {
547
+ xmlSubstituteEntitiesDefault(0);
548
+ return(Qfalse);
549
+ } else {
550
+ xmlSubstituteEntitiesDefault(1);
551
+ return(Qtrue);
552
+ }
553
+ }
554
+
555
+
556
+ /*
557
+ * call-seq:
558
+ * XML.default_tree_indent_string -> "string"
559
+ *
560
+ * Obtain the default string used by parsers to indent the XML tree
561
+ * for output.
562
+ */
563
+ static VALUE
564
+ rxml_default_tree_indent_string_get(VALUE class) {
565
+ if (xmlTreeIndentString == NULL)
566
+ return(Qnil);
567
+ else
568
+ return(rb_str_new2(xmlTreeIndentString));
569
+ }
570
+
571
+
572
+ /*
573
+ * call-seq:
574
+ * XML.default_tree_indent_string = "string"
575
+ *
576
+ * Set the default string used by parsers to indent the XML tree
577
+ * for output.
578
+ */
579
+ static VALUE
580
+ rxml_default_tree_indent_string_set(VALUE class, VALUE string) {
581
+ Check_Type(string, T_STRING);
582
+ xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
583
+ return(string);
584
+ }
585
+
586
+
587
+ /*
588
+ * call-seq:
589
+ * XML.default_validity_checking -> (true|false)
590
+ *
591
+ * Determine whether parsers perform XML validation by default.
592
+ */
593
+ static VALUE
594
+ rxml_default_validity_checking_get(VALUE class) {
595
+ if (xmlDoValidityCheckingDefaultValue)
596
+ return(Qtrue);
597
+ else
598
+ return(Qfalse);
599
+ }
600
+
601
+
602
+ /*
603
+ * call-seq:
604
+ * XML.default_validity_checking = true|false
605
+ *
606
+ * Controls whether parsers perform XML validation by default.
607
+ */
608
+ static VALUE
609
+ rxml_default_validity_checking_set(VALUE class, VALUE bool) {
610
+ if (TYPE(bool) == T_FALSE) {
611
+ xmlDoValidityCheckingDefaultValue = 0;
612
+ return(Qfalse);
613
+ } else {
614
+ xmlDoValidityCheckingDefaultValue = 1;
615
+ return(Qtrue);
616
+ }
617
+ }
618
+
619
+
620
+ /*
621
+ * call-seq:
622
+ * XML.default_warnings -> (true|false)
623
+ *
624
+ * Determine whether parsers output warnings by default.
625
+ */
626
+ static VALUE
627
+ rxml_default_warnings_get(VALUE class) {
628
+ if (xmlGetWarningsDefaultValue)
629
+ return(Qtrue);
630
+ else
631
+ return(Qfalse);
632
+ }
633
+
634
+
635
+ /*
636
+ * call-seq:
637
+ * XML.default_warnings = true|false
638
+ *
639
+ * Controls whether parsers output warnings by default.
640
+ */
641
+ static VALUE
642
+ rxml_default_warnings_set(VALUE class, VALUE bool) {
643
+ if (TYPE(bool) == T_FALSE) {
644
+ xmlGetWarningsDefaultValue = 0;
645
+ return(Qfalse);
646
+ } else {
647
+ xmlGetWarningsDefaultValue = 1;
648
+ return(Qtrue);
649
+ }
650
+ }
651
+
652
+
653
+ /*
654
+ * call-seq:
655
+ * XML.default_compression -> (true|false)
656
+ *
657
+ * Determine whether parsers use Zlib compression by default
658
+ * (requires libxml to be compiled with Zlib support).
659
+ */
660
+ static VALUE
661
+ rxml_default_compression_get(VALUE class) {
662
+ #ifdef HAVE_ZLIB_H
663
+ return(INT2FIX(xmlGetCompressMode()));
664
+ #else
665
+ rb_warn("libxml was compiled without zlib support");
666
+ return(Qfalse);
667
+ #endif
668
+ }
669
+
670
+
671
+ /*
672
+ * call-seq:
673
+ * XML.default_compression = true|false
674
+ *
675
+ * Controls whether parsers use Zlib compression by default
676
+ * (requires libxml to be compiled with Zlib support).
677
+ */
678
+ static VALUE
679
+ rxml_default_compression_set(VALUE class, VALUE num) {
680
+ #ifdef HAVE_ZLIB_H
681
+ Check_Type(num, T_FIXNUM);
682
+ xmlSetCompressMode(FIX2INT(num));
683
+ return(num);
684
+ #else
685
+ rb_warn("libxml was compiled without zlib support");
686
+ return(Qfalse);
687
+ #endif
688
+ }
689
+
690
+
691
+ /*
692
+ * call-seq:
693
+ * XML.features -> ["feature", ..., "feature"]
694
+ *
695
+ * Obtains an array of strings representing features supported
696
+ * (and enabled) by the installed libxml.
697
+ */
698
+ static VALUE
699
+ rxml_features(VALUE class) {
700
+ VALUE arr, str;
701
+ int i, len = MAX_LIBXML_FEATURES_LEN;
702
+ char **list = NULL;
703
+
704
+ list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
705
+ MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
706
+
707
+ arr = rb_ary_new();
708
+ if (xmlGetFeaturesList(&len, (const char **)list) == -1)
709
+ return Qnil;
710
+
711
+ for (i = 0; i < len; i++) {
712
+ str = rb_str_new2((const char *)list[i]);
713
+ rb_gc_unregister_address(&str);
714
+ rb_ary_push(arr, str);
715
+ }
716
+
717
+ if (len == MAX_LIBXML_FEATURES_LEN)
718
+ rb_warn("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");
719
+
720
+ ruby_xfree(list);
721
+ return(arr);
722
+ }
723
+
724
+
725
+ /*
726
+ * call-seq:
727
+ * XML.indent_tree_output -> (true|false)
728
+ *
729
+ * Determines whether XML output will be indented
730
+ * (using the string supplied to +default_indent_tree_string+)
731
+ */
732
+ static VALUE
733
+ rxml_indent_tree_output_get(VALUE class) {
734
+ if (xmlIndentTreeOutput)
735
+ return(Qtrue);
736
+ else
737
+ return(Qfalse);
738
+ }
739
+
740
+
741
+ /*
742
+ * call-seq:
743
+ * XML.indent_tree_output = true|false
744
+ *
745
+ * Controls whether XML output will be indented
746
+ * (using the string supplied to +default_indent_tree_string+)
747
+ */
748
+ static VALUE
749
+ rxml_indent_tree_output_set(VALUE class, VALUE bool) {
750
+ if (TYPE(bool) == T_TRUE) {
751
+ xmlIndentTreeOutput = 1;
752
+ return(Qtrue);
753
+ } else if (TYPE(bool) == T_FALSE) {
754
+ xmlIndentTreeOutput = 0;
755
+ return(Qfalse);
756
+ } else {
757
+ rb_raise(rb_eArgError, "Invalid argument, must be boolean");
758
+ }
759
+ }
760
+
761
+ /*
762
+ * call-seq:
763
+ * XML.memory_dump -> (true|false)
764
+ *
765
+ * Perform a parser memory dump (requires memory debugging
766
+ * support in libxml).
767
+ */
768
+ static VALUE
769
+ rxml_memory_dump(VALUE self) {
770
+ #ifdef DEBUG_MEMORY_LOCATION
771
+ xmlMemoryDump();
772
+ return(Qtrue);
773
+ #else
774
+ rb_warn("libxml was compiled without memory debugging support");
775
+ return(Qfalse);
776
+ #endif
777
+ }
778
+
779
+
780
+ /*
781
+ * call-seq:
782
+ * XML.memory_used -> num_bytes
783
+ *
784
+ * Perform a parser memory dump (requires memory debugging
785
+ * support in libxml).
786
+ */
787
+ static VALUE
788
+ rxml_memory_used(VALUE self) {
789
+ #ifdef DEBUG_MEMORY_LOCATION
790
+ return(INT2NUM(xmlMemUsed()));
791
+ #else
792
+ rb_warn("libxml was compiled without memory debugging support");
793
+ return(Qfalse);
794
+ #endif
795
+ }
796
+
797
+ #if defined(_WIN32)
798
+ __declspec(dllexport)
799
+ #endif
800
+ void
801
+ Init_libxml_ruby(void) {
802
+ mLibXML = rb_define_module("LibXML");
803
+ mXML = rb_define_module_under(mLibXML, "XML");
804
+
805
+ /* Constants */
806
+ rb_define_const(mXML, "LIBXML_VERSION", rb_str_new2(LIBXML_DOTTED_VERSION));
807
+ rb_define_const(mXML, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
808
+ rb_define_const(mXML, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
809
+ rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*)XML_XML_NAMESPACE));
810
+
811
+ rb_define_module_function(mXML, "enabled_automata?", rxml_enabled_automata_q, 0);
812
+ rb_define_module_function(mXML, "enabled_c14n?", rxml_enabled_c14n_q, 0);
813
+ rb_define_module_function(mXML, "enabled_catalog?", rxml_enabled_catalog_q, 0);
814
+ rb_define_module_function(mXML, "enabled_debug?", rxml_enabled_debug_q, 0);
815
+ rb_define_module_function(mXML, "enabled_docbook?", rxml_enabled_docbook_q, 0);
816
+ rb_define_module_function(mXML, "enabled_ftp?", rxml_enabled_ftp_q, 0);
817
+ rb_define_module_function(mXML, "enabled_http?", rxml_enabled_http_q, 0);
818
+ rb_define_module_function(mXML, "enabled_html?", rxml_enabled_html_q, 0);
819
+ rb_define_module_function(mXML, "enabled_iconv?", rxml_enabled_iconv_q, 0);
820
+ rb_define_module_function(mXML, "enabled_memory_debug?", rxml_enabled_memory_debug_location_q, 0);
821
+ rb_define_module_function(mXML, "enabled_regexp?", rxml_enabled_regexp_q, 0);
822
+ rb_define_module_function(mXML, "enabled_schemas?", rxml_enabled_schemas_q, 0);
823
+ rb_define_module_function(mXML, "enabled_thread?", rxml_enabled_thread_q, 0);
824
+ rb_define_module_function(mXML, "enabled_unicode?", rxml_enabled_unicode_q, 0);
825
+ rb_define_module_function(mXML, "enabled_xinclude?", rxml_enabled_xinclude_q, 0);
826
+ rb_define_module_function(mXML, "enabled_xpath?", rxml_enabled_xpath_q, 0);
827
+ rb_define_module_function(mXML, "enabled_xpointer?", rxml_enabled_xpointer_q, 0);
828
+ rb_define_module_function(mXML, "enabled_zlib?", rxml_enabled_zlib_q, 0);
829
+
830
+ rb_define_module_function(mXML, "catalog_dump", rxml_catalog_dump, 0);
831
+ rb_define_module_function(mXML, "catalog_remove", rxml_catalog_remove, 1);
832
+ rb_define_module_function(mXML, "check_lib_versions", rxml_check_lib_versions, 0);
833
+ rb_define_module_function(mXML, "debug_entities", rxml_debug_entities_get, 0);
834
+ rb_define_module_function(mXML, "debug_entities=", rxml_debug_entities_set, 1);
835
+ rb_define_module_function(mXML, "default_compression", rxml_default_compression_get, 0);
836
+ rb_define_module_function(mXML, "default_compression=", rxml_default_compression_set, 1);
837
+ rb_define_module_function(mXML, "default_keep_blanks", rxml_default_keep_blanks_get, 0);
838
+ rb_define_module_function(mXML, "default_keep_blanks=", rxml_default_keep_blanks_set, 1);
839
+ rb_define_module_function(mXML, "default_load_external_dtd", rxml_default_load_external_dtd_get, 0);
840
+ rb_define_module_function(mXML, "default_load_external_dtd=", rxml_default_load_external_dtd_set, 1);
841
+ rb_define_module_function(mXML, "default_line_numbers", rxml_default_line_numbers_get, 0);
842
+ rb_define_module_function(mXML, "default_line_numbers=", rxml_default_line_numbers_set, 1);
843
+ rb_define_module_function(mXML, "default_pedantic_parser", rxml_default_pedantic_parser_get, 0);
844
+ rb_define_module_function(mXML, "default_pedantic_parser=", rxml_default_pedantic_parser_set, 1);
845
+ rb_define_module_function(mXML, "default_substitute_entities", rxml_default_substitute_entities_get, 0);
846
+ rb_define_module_function(mXML, "default_substitute_entities=", rxml_default_substitute_entities_set, 1);
847
+ rb_define_module_function(mXML, "default_tree_indent_string", rxml_default_tree_indent_string_get, 0);
848
+ rb_define_module_function(mXML, "default_tree_indent_string=", rxml_default_tree_indent_string_set, 1);
849
+ rb_define_module_function(mXML, "default_validity_checking", rxml_default_validity_checking_get, 0);
850
+ rb_define_module_function(mXML, "default_validity_checking=", rxml_default_validity_checking_set, 1);
851
+ rb_define_module_function(mXML, "default_warnings", rxml_default_warnings_get, 0);
852
+ rb_define_module_function(mXML, "default_warnings=", rxml_default_warnings_set, 1);
853
+ rb_define_module_function(mXML, "features", rxml_features, 0);
854
+ rb_define_module_function(mXML, "indent_tree_output", rxml_indent_tree_output_get, 0);
855
+ rb_define_module_function(mXML, "indent_tree_output=", rxml_indent_tree_output_set, 1);
856
+ rb_define_module_function(mXML, "memory_dump", rxml_memory_dump, 0);
857
+ rb_define_module_function(mXML, "memory_used", rxml_memory_used, 0);
858
+
859
+ /* Now initialize all the other modules */
860
+ ruby_init_xml_error();
861
+ ruby_init_xml_input();
862
+ ruby_init_state();
863
+ ruby_init_parser();
864
+ ruby_init_xml_parser_context();
865
+ ruby_init_xml_node();
866
+ ruby_init_xml_attributes();
867
+ ruby_init_xml_attr();
868
+ ruby_init_xml_document();
869
+ ruby_init_xml_ns();
870
+ ruby_init_xml_sax_parser();
871
+ ruby_init_xml_xinclude();
872
+ ruby_init_xml_xpath();
873
+ ruby_init_xml_xpath_context();
874
+ ruby_init_xml_xpath_expression();
875
+ ruby_init_xml_xpointer();
876
+ ruby_init_html_parser();
877
+ ruby_init_input_callbacks();
878
+ ruby_init_xml_dtd();
879
+ ruby_init_xml_schema();
880
+ ruby_init_xml_relaxng();
881
+ ruby_init_xml_reader();
882
+
883
+ rxml_default_substitute_entities_set(mXML, Qtrue);
884
+ rxml_default_load_external_dtd_set(mXML, Qtrue);
885
+ }