libxml-ruby 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +23 -23
  2. data/README +144 -144
  3. data/ext/libxml/extconf.rb +26 -27
  4. data/ext/libxml/libxml.c +7 -37
  5. data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
  6. data/ext/libxml/ruby_xml_attr.c +405 -387
  7. data/ext/libxml/ruby_xml_attr.h +19 -18
  8. data/ext/libxml/ruby_xml_document.c +1111 -1115
  9. data/ext/libxml/ruby_xml_document.h +27 -24
  10. data/ext/libxml/ruby_xml_dtd.c +168 -168
  11. data/ext/libxml/ruby_xml_html_parser.c +449 -450
  12. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  13. data/ext/libxml/ruby_xml_input_cbg.c +158 -158
  14. data/ext/libxml/ruby_xml_node.c +2410 -2395
  15. data/ext/libxml/ruby_xml_node.h +1 -1
  16. data/ext/libxml/ruby_xml_node_set.c +170 -170
  17. data/ext/libxml/ruby_xml_node_set.h +1 -1
  18. data/ext/libxml/ruby_xml_ns.c +153 -153
  19. data/ext/libxml/ruby_xml_ns.h +1 -1
  20. data/ext/libxml/ruby_xml_parser.c +1425 -1422
  21. data/ext/libxml/ruby_xml_parser.h +1 -1
  22. data/ext/libxml/ruby_xml_parser_context.c +750 -716
  23. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  24. data/ext/libxml/ruby_xml_reader.c +900 -896
  25. data/ext/libxml/ruby_xml_sax_parser.c +485 -485
  26. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_schema.c +146 -142
  28. data/ext/libxml/ruby_xml_state.c +5 -6
  29. data/ext/libxml/ruby_xml_state.h +1 -0
  30. data/ext/libxml/ruby_xml_tree.c +43 -43
  31. data/ext/libxml/ruby_xml_tree.h +1 -1
  32. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  33. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  34. data/ext/libxml/ruby_xml_xpath.c +243 -252
  35. data/ext/libxml/ruby_xml_xpath.h +1 -1
  36. data/ext/libxml/ruby_xml_xpath_context.c +118 -118
  37. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  38. data/ext/libxml/ruby_xml_xpath_object.c +43 -29
  39. data/ext/libxml/ruby_xml_xpath_object.h +0 -1
  40. data/ext/libxml/ruby_xml_xpointer.c +100 -100
  41. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  42. data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
  43. data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
  44. data/ext/libxml/sax_parser_callbacks.inc +213 -213
  45. data/ext/libxml/version.h +9 -9
  46. data/lib/libxml.rb +24 -3
  47. data/mingw/libiconv-2.dll +0 -0
  48. data/mingw/libxml2-2.dll +0 -0
  49. data/mingw/libxml_ruby.so +0 -0
  50. data/mingw/mingw.rake +36 -0
  51. data/test/dtd-test.rb +24 -24
  52. data/test/etc_doc_to_s.rb +1 -3
  53. data/test/ets_copy_bug.rb +21 -21
  54. data/test/ets_copy_bug2.rb +32 -32
  55. data/test/ets_copy_bug3.rb +38 -0
  56. data/test/ets_doc_file.rb +1 -0
  57. data/test/{model/default_validation_bug.rb → gc.log} +0 -0
  58. data/test/merge_bug.rb +55 -55
  59. data/test/schema-test.rb +74 -74
  60. data/test/tc_well_formed.rb +11 -0
  61. data/test/tc_xml_document.rb +52 -52
  62. data/test/tc_xml_document_write.rb +24 -24
  63. data/test/tc_xml_document_write2.rb +54 -54
  64. data/test/tc_xml_document_write3.rb +96 -96
  65. data/test/tc_xml_html_parser.rb +63 -63
  66. data/test/tc_xml_node.rb +59 -59
  67. data/test/tc_xml_node2.rb +25 -25
  68. data/test/tc_xml_node3.rb +27 -27
  69. data/test/tc_xml_node4.rb +86 -86
  70. data/test/tc_xml_node5.rb +52 -52
  71. data/test/tc_xml_node6.rb +27 -27
  72. data/test/tc_xml_node7.rb +35 -35
  73. data/test/tc_xml_node8.rb +32 -32
  74. data/test/tc_xml_node9.rb +32 -32
  75. data/test/tc_xml_node_set.rb +24 -24
  76. data/test/tc_xml_node_set2.rb +37 -37
  77. data/test/tc_xml_node_xlink.rb +28 -28
  78. data/test/tc_xml_parser.rb +190 -178
  79. data/test/tc_xml_parser2.rb +16 -17
  80. data/test/tc_xml_parser3.rb +23 -23
  81. data/test/tc_xml_parser4.rb +33 -33
  82. data/test/tc_xml_parser5.rb +27 -27
  83. data/test/tc_xml_parser6.rb +23 -23
  84. data/test/tc_xml_parser7.rb +28 -28
  85. data/test/tc_xml_parser8.rb +32 -32
  86. data/test/tc_xml_parser9.rb +11 -0
  87. data/test/tc_xml_parser_context.rb +88 -88
  88. data/test/tc_xml_reader.rb +112 -109
  89. data/test/tc_xml_sax_parser.rb +104 -94
  90. data/test/tc_xml_sax_parser2.rb +51 -0
  91. data/test/tc_xml_xinclude.rb +30 -30
  92. data/test/tc_xml_xpath.rb +38 -38
  93. data/test/tc_xml_xpath2.rb +14 -0
  94. data/test/tc_xml_xpointer.rb +78 -78
  95. data/vc/libxml.sln +20 -0
  96. data/vc/libxml.vcproj +389 -0
  97. data/work/Rakefile +247 -0
  98. data/work/task/make +26 -0
  99. data/work/task/memory +37 -0
  100. data/work/task/rdoc +39 -0
  101. data/work/task/setup +1616 -0
  102. data/work/task/test +29 -0
  103. data/work/test/ets_runner.rb +33 -0
  104. data/work/test/libxml_test.rb +3 -0
  105. data/work/test/runner.rb +0 -0
  106. data/work/test/runner_ets.rb +33 -0
  107. data/work/vc/debug/libxml.exp +0 -0
  108. data/work/vc/debug/libxml.ilk +0 -0
  109. data/work/vc/debug/libxml.lib +0 -0
  110. data/work/vc/debug/libxml.pdb +0 -0
  111. data/work/vc/debug/libxml.so +0 -0
  112. metadata +158 -189
  113. data/MANIFEST +0 -138
  114. data/NOTES +0 -9
  115. data/Rakefile +0 -38
  116. data/TODO +0 -75
  117. data/VERSION +0 -1
  118. data/log/Changelog-0.txt +0 -426
  119. data/log/Changelog.txt +0 -435
  120. data/meta/project.yaml +0 -27
  121. data/meta/unixname +0 -1
  122. data/setup.rb +0 -1472
  123. data/site/css/normal.css +0 -182
  124. data/site/img/raze-tiny.png +0 -0
  125. data/site/img/red-cube.jpg +0 -0
  126. data/site/img/xml-ruby.png +0 -0
  127. data/site/index.xml +0 -43
  128. data/site/install.xml +0 -77
  129. data/site/layout.rhtml +0 -38
  130. data/site/layout.xsl +0 -67
  131. data/site/license.xml +0 -32
  132. data/site/log/changelog.xml +0 -1324
  133. data/site/log/changelog.xsl +0 -42
  134. data/test/model/merge_bug_data.xml +0 -58
  135. data/test/model/rubynet.xml +0 -78
  136. data/test/model/rubynet_project +0 -13
  137. data/test/model/saxtest.xml +0 -5
  138. data/test/model/simple.xml +0 -7
  139. data/test/model/xinclude.xml +0 -5
@@ -1,1422 +1,1425 @@
1
- /* $Id: ruby_xml_parser.c 225 2007-12-07 04:58:09Z transami $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include <stdarg.h>
6
- #include "libxml.h"
7
-
8
- static VALUE libxml_xmlRubyErrorProc = Qnil;
9
- static int id_call;
10
-
11
- VALUE cXMLParser;
12
- VALUE eXMLParserParseError;
13
-
14
- static int
15
- ctxtRead(FILE *f, char * buf, int len) {
16
- return(fread(buf, 1, len, f));
17
- }
18
-
19
- /*
20
- * call-seq:
21
- * XML::Parser.catalog_dump => true
22
- *
23
- * Dump the parser resource catalogs to stdout.
24
- */
25
- VALUE
26
- ruby_xml_parser_catalog_dump(VALUE self) {
27
- xmlCatalogDump(stdout);
28
- return(Qtrue);
29
- }
30
-
31
-
32
- /*
33
- * call-seq:
34
- * XML::Parser.catalog_remove(catalog) => true
35
- *
36
- * Remove the specified resource catalog.
37
- */
38
- VALUE
39
- ruby_xml_parser_catalog_remove(VALUE self, VALUE cat) {
40
- Check_Type(cat, T_STRING);
41
- xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
42
- return(Qtrue);
43
- }
44
-
45
-
46
- /*
47
- * call-seq:
48
- * XML::Parser.check_lib_versions => true
49
- *
50
- * Check LIBXML version matches version the bindings
51
- * were compiled to. Throws an exception if not.
52
- */
53
- VALUE
54
- ruby_xml_parser_check_lib_versions(VALUE class) {
55
- xmlCheckVersion(LIBXML_VERSION);
56
- return(Qtrue);
57
- }
58
-
59
-
60
- /*
61
- * call-seq:
62
- * XML::Parser.enabled_automata? => (true|false)
63
- *
64
- * Determine whether libxml regexp automata support is enabled.
65
- */
66
- VALUE
67
- ruby_xml_parser_enabled_automata_q(VALUE class) {
68
- #ifdef LIBXML_AUTOMATA_ENABLED
69
- return(Qtrue);
70
- #else
71
- return(Qfalse);
72
- #endif
73
- }
74
-
75
-
76
- /*
77
- * call-seq:
78
- * XML::Parser.enabled_c14n? => (true|false)
79
- *
80
- * Determine whether libxml 'canonical XML' support is enabled.
81
- * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
82
- */
83
- VALUE
84
- ruby_xml_parser_enabled_c14n_q(VALUE class) {
85
- #ifdef LIBXML_C14N_ENABLED
86
- return(Qtrue);
87
- #else
88
- return(Qfalse);
89
- #endif
90
- }
91
-
92
-
93
- /*
94
- * call-seq:
95
- * XML::Parser.enabled_catalog? => (true|false)
96
- *
97
- * Determine whether libxml resource catalog support is enabled.
98
- */
99
- VALUE
100
- ruby_xml_parser_enabled_catalog_q(VALUE class) {
101
- #ifdef LIBXML_CATALOG_ENABLED
102
- return(Qtrue);
103
- #else
104
- return(Qfalse);
105
- #endif
106
- }
107
-
108
-
109
- /*
110
- * call-seq:
111
- * XML::Parser.enabled_debug? => (true|false)
112
- *
113
- * Determine whether libxml debugging support is enabled.
114
- */
115
- VALUE
116
- ruby_xml_parser_enabled_debug_q(VALUE class) {
117
- #ifdef LIBXML_DEBUG_ENABLED
118
- return(Qtrue);
119
- #else
120
- return(Qfalse);
121
- #endif
122
- }
123
-
124
-
125
- /*
126
- * call-seq:
127
- * XML::Parser.enabled_docbook? => (true|false)
128
- *
129
- * Determine whether libxml docbook support is enabled.
130
- */
131
- VALUE
132
- ruby_xml_parser_enabled_docbook_q(VALUE class) {
133
- #ifdef LIBXML_DOCB_ENABLED
134
- return(Qtrue);
135
- #else
136
- return(Qfalse);
137
- #endif
138
- }
139
-
140
-
141
- /*
142
- * call-seq:
143
- * XML::Parser.enabled_ftp? => (true|false)
144
- *
145
- * Determine whether libxml ftp client support is enabled.
146
- */
147
- VALUE
148
- ruby_xml_parser_enabled_ftp_q(VALUE class) {
149
- #ifdef LIBXML_FTP_ENABLED
150
- return(Qtrue);
151
- #else
152
- return(Qfalse);
153
- #endif
154
- }
155
-
156
-
157
- /*
158
- * call-seq:
159
- * XML::Parser.enabled_http? => (true|false)
160
- *
161
- * Determine whether libxml http client support is enabled.
162
- */
163
- VALUE
164
- ruby_xml_parser_enabled_http_q(VALUE class) {
165
- #ifdef LIBXML_HTTP_ENABLED
166
- return(Qtrue);
167
- #else
168
- return(Qfalse);
169
- #endif
170
- }
171
-
172
-
173
- /*
174
- * call-seq:
175
- * XML::Parser.enabled_html? => (true|false)
176
- *
177
- * Determine whether libxml html support is enabled.
178
- */
179
- VALUE
180
- ruby_xml_parser_enabled_html_q(VALUE class) {
181
- #ifdef LIBXML_HTML_ENABLED
182
- return(Qtrue);
183
- #else
184
- return(Qfalse);
185
- #endif
186
- }
187
-
188
-
189
- /*
190
- * call-seq:
191
- * XML::Parser.enabled_iconv? => (true|false)
192
- *
193
- * Determine whether libxml iconv support is enabled.
194
- */
195
- VALUE
196
- ruby_xml_parser_enabled_iconv_q(VALUE class) {
197
- #ifdef LIBXML_ICONV_ENABLED
198
- return(Qtrue);
199
- #else
200
- return(Qfalse);
201
- #endif
202
- }
203
-
204
-
205
- /*
206
- * call-seq:
207
- * XML::Parser.enabled_memory_debug? => (true|false)
208
- *
209
- * Determine whether libxml memory location debugging support
210
- * is enabled.
211
- */
212
- VALUE
213
- ruby_xml_parser_enabled_memory_debug_location_q(VALUE class) {
214
- #ifdef DEBUG_MEMORY_LOCATION
215
- return(Qtrue);
216
- #else
217
- return(Qfalse);
218
- #endif
219
- }
220
-
221
-
222
- /*
223
- * call-seq:
224
- * XML::Parser.enabled_regexp? => (true|false)
225
- *
226
- * Determine whether libxml regular expression support is enabled.
227
- */
228
- VALUE
229
- ruby_xml_parser_enabled_regexp_q(VALUE class) {
230
- #ifdef LIBXML_REGEXP_ENABLED
231
- return(Qtrue);
232
- #else
233
- return(Qfalse);
234
- #endif
235
- }
236
-
237
-
238
- /*
239
- * call-seq:
240
- * XML::Parser.enabled_schemas? => (true|false)
241
- *
242
- * Determine whether libxml schema support is enabled.
243
- */
244
- VALUE
245
- ruby_xml_parser_enabled_schemas_q(VALUE class) {
246
- #ifdef LIBXML_SCHEMAS_ENABLED
247
- return(Qtrue);
248
- #else
249
- return(Qfalse);
250
- #endif
251
- }
252
-
253
-
254
- /*
255
- * call-seq:
256
- * XML::Parser.enabled_thread? => (true|false)
257
- *
258
- * Determine whether libxml thread-safe semantics support
259
- * is enabled (I think?).
260
- */
261
- VALUE
262
- ruby_xml_parser_enabled_thread_q(VALUE class) {
263
- #ifdef LIBXML_THREAD_ENABLED
264
- return(Qtrue);
265
- #else
266
- return(Qfalse);
267
- #endif
268
- }
269
-
270
-
271
- /*
272
- * call-seq:
273
- * XML::Parser.enabled_unicode? => (true|false)
274
- *
275
- * Determine whether libxml unicode support is enabled.
276
- */
277
- VALUE
278
- ruby_xml_parser_enabled_unicode_q(VALUE class) {
279
- #ifdef LIBXML_UNICODE_ENABLED
280
- return(Qtrue);
281
- #else
282
- return(Qfalse);
283
- #endif
284
- }
285
-
286
-
287
- /*
288
- * call-seq:
289
- * XML::Parser.enabled_xinclude? => (true|false)
290
- *
291
- * Determine whether libxml xinclude support is enabled.
292
- */
293
- VALUE
294
- ruby_xml_parser_enabled_xinclude_q(VALUE class) {
295
- #ifdef LIBXML_XINCLUDE_ENABLED
296
- return(Qtrue);
297
- #else
298
- return(Qfalse);
299
- #endif
300
- }
301
-
302
-
303
- /*
304
- * call-seq:
305
- * XML::Parser.enabled_xpath? => (true|false)
306
- *
307
- * Determine whether libxml xpath support is enabled.
308
- */
309
- VALUE
310
- ruby_xml_parser_enabled_xpath_q(VALUE class) {
311
- #ifdef LIBXML_XPATH_ENABLED
312
- return(Qtrue);
313
- #else
314
- return(Qfalse);
315
- #endif
316
- }
317
-
318
-
319
- /*
320
- * call-seq:
321
- * XML::Parser.enabled_xpointer? => (true|false)
322
- *
323
- * Determine whether libxml xpointer support is enabled.
324
- */
325
- VALUE
326
- ruby_xml_parser_enabled_xpointer_q(VALUE class) {
327
- #ifdef LIBXML_XPTR_ENABLED
328
- return(Qtrue);
329
- #else
330
- return(Qfalse);
331
- #endif
332
- }
333
-
334
-
335
- /*
336
- * call-seq:
337
- * XML::Parser.enabled_zlib? => (true|false)
338
- *
339
- * Determine whether libxml zlib support is enabled.
340
- */
341
- VALUE
342
- ruby_xml_parser_enabled_zlib_q(VALUE class) {
343
- #ifdef HAVE_ZLIB_H
344
- return(Qtrue);
345
- #else
346
- return(Qfalse);
347
- #endif
348
- }
349
-
350
-
351
- /*
352
- * call-seq:
353
- * XML::Parser.debug_entities => (true|false)
354
- *
355
- * Determine whether included-entity debugging is enabled.
356
- * (Requires Libxml to be compiled with debugging support)
357
- */
358
- VALUE
359
- ruby_xml_parser_debug_entities_get(VALUE class) {
360
- #ifdef LIBXML_DEBUG_ENABLED
361
- if (xmlParserDebugEntities)
362
- return(Qtrue);
363
- else
364
- return(Qfalse);
365
- #else
366
- rb_warn("libxml was compiled with debugging turned off");
367
- return(Qfalse);
368
- #endif
369
- }
370
-
371
-
372
- /*
373
- * call-seq:
374
- * XML::Parser.debug_entities = true|false
375
- *
376
- * Enable or disable included-entity debugging.
377
- * (Requires Libxml to be compiled with debugging support)
378
- */
379
- VALUE
380
- ruby_xml_parser_debug_entities_set(VALUE class, VALUE bool) {
381
- #ifdef LIBXML_DEBUG_ENABLED
382
- if (TYPE(bool) == T_FALSE) {
383
- xmlParserDebugEntities = 0;
384
- return(Qfalse);
385
- } else {
386
- xmlParserDebugEntities = 1;
387
- return(Qtrue);
388
- }
389
- #else
390
- rb_warn("libxml was compiled with debugging turned off");
391
- #endif
392
- }
393
-
394
-
395
- /*
396
- * call-seq:
397
- * XML::Parser.default_keep_blanks => (true|false)
398
- *
399
- * Determine whether parsers retain whitespace by default.
400
- */
401
- VALUE
402
- ruby_xml_parser_default_keep_blanks_get(VALUE class) {
403
- if (xmlKeepBlanksDefaultValue)
404
- return(Qtrue);
405
- else
406
- return(Qfalse);
407
- }
408
-
409
-
410
- /*
411
- * call-seq:
412
- * XML::Parser.default_keep_blanks = true|false
413
- *
414
- * Controls whether parsers retain whitespace by default.
415
- */
416
- VALUE
417
- ruby_xml_parser_default_keep_blanks_set(VALUE class, VALUE bool) {
418
- if (TYPE(bool) == T_FALSE) {
419
- xmlKeepBlanksDefaultValue = 0;
420
- return(Qfalse);
421
- } else if (TYPE(bool) == T_TRUE) {
422
- xmlKeepBlanksDefaultValue = 1;
423
- return(Qtrue);
424
- } else {
425
- rb_raise(rb_eArgError, "invalid argument, must be a boolean");
426
- }
427
- }
428
-
429
-
430
- /*
431
- * call-seq:
432
- * XML::Parser.default_load_external_dtd => (true|false)
433
- *
434
- * Determine whether parsers load external DTDs by default.
435
- */
436
- VALUE
437
- ruby_xml_parser_default_load_external_dtd_get(VALUE class) {
438
- if (xmlLoadExtDtdDefaultValue)
439
- return(Qtrue);
440
- else
441
- return(Qfalse);
442
- }
443
-
444
-
445
- /*
446
- * call-seq:
447
- * XML::Parser.default_load_external_dtd = true|false
448
- *
449
- * Controls whether parsers load external DTDs by default.
450
- */
451
- VALUE
452
- ruby_xml_parser_default_load_external_dtd_set(VALUE class, VALUE bool) {
453
- if (TYPE(bool) == T_FALSE) {
454
- xmlLoadExtDtdDefaultValue = 0;
455
- return(Qfalse);
456
- } else {
457
- xmlLoadExtDtdDefaultValue = 1;
458
- return(Qtrue);
459
- }
460
- }
461
-
462
-
463
- /*
464
- * call-seq:
465
- * XML::Parser.default_line_numbers => (true|false)
466
- *
467
- * Determine whether parsers retain line-numbers by default.
468
- */
469
- VALUE
470
- ruby_xml_parser_default_line_numbers_get(VALUE class) {
471
- if (xmlLineNumbersDefaultValue)
472
- return(Qtrue);
473
- else
474
- return(Qfalse);
475
- }
476
-
477
-
478
- /*
479
- * call-seq:
480
- * XML::Parser.default_line_numbers = true|false
481
- *
482
- * Controls whether parsers retain line-numbers by default.
483
- */
484
- VALUE
485
- ruby_xml_parser_default_line_numbers_set(VALUE class, VALUE bool) {
486
- if (TYPE(bool) == T_FALSE) {
487
- xmlLineNumbersDefault(0);
488
- return(Qfalse);
489
- } else {
490
- xmlLineNumbersDefault(1);
491
- return(Qtrue);
492
- }
493
- }
494
-
495
-
496
- /*
497
- * call-seq:
498
- * XML::Parser.default_pedantic_parser => (true|false)
499
- *
500
- * Determine whether parsers are pedantic by default.
501
- */
502
- VALUE
503
- ruby_xml_parser_default_pedantic_parser_get(VALUE class) {
504
- if (xmlPedanticParserDefaultValue)
505
- return(Qtrue);
506
- else
507
- return(Qfalse);
508
- }
509
-
510
-
511
- /*
512
- * call-seq:
513
- * XML::Parser.default_pedantic_parser = true|false
514
- *
515
- * Controls whether parsers are pedantic by default.
516
- */
517
- VALUE
518
- ruby_xml_parser_default_pedantic_parser_set(VALUE class, VALUE bool) {
519
- if (TYPE(bool) == T_FALSE) {
520
- xmlPedanticParserDefault(0);
521
- return(Qfalse);
522
- } else {
523
- xmlPedanticParserDefault(1);
524
- return(Qtrue);
525
- }
526
- }
527
-
528
-
529
- /*
530
- * call-seq:
531
- * XML::Parser.default_substitute_entities => (true|false)
532
- *
533
- * Determine whether parsers perform inline entity substitution
534
- * (for external entities) by default.
535
- */
536
- VALUE
537
- ruby_xml_parser_default_substitute_entities_get(VALUE class) {
538
- if (xmlSubstituteEntitiesDefaultValue)
539
- return(Qtrue);
540
- else
541
- return(Qfalse);
542
- }
543
-
544
-
545
- /*
546
- * call-seq:
547
- * XML::Parser.default_substitute_entities = true|false
548
- *
549
- * Controls whether parsers perform inline entity substitution
550
- * (for external entities) by default.
551
- */
552
- VALUE
553
- ruby_xml_parser_default_substitute_entities_set(VALUE class, VALUE bool) {
554
- if (TYPE(bool) == T_FALSE) {
555
- xmlSubstituteEntitiesDefault(0);
556
- return(Qfalse);
557
- } else {
558
- xmlSubstituteEntitiesDefault(1);
559
- return(Qtrue);
560
- }
561
- }
562
-
563
-
564
- /*
565
- * call-seq:
566
- * XML::Parser.default_tree_indent_string => "string"
567
- *
568
- * Obtain the default string used by parsers to indent the XML tree
569
- * for output.
570
- */
571
- VALUE
572
- ruby_xml_parser_default_tree_indent_string_get(VALUE class) {
573
- if (xmlTreeIndentString == NULL)
574
- return(Qnil);
575
- else
576
- return(rb_str_new2(xmlTreeIndentString));
577
- }
578
-
579
-
580
- /*
581
- * call-seq:
582
- * XML::Parser.default_tree_indent_string = "string"
583
- *
584
- * Set the default string used by parsers to indent the XML tree
585
- * for output.
586
- */
587
- VALUE
588
- ruby_xml_parser_default_tree_indent_string_set(VALUE class, VALUE string) {
589
- Check_Type(string, T_STRING);
590
- xmlTreeIndentString = ruby_strdup(StringValuePtr(string));
591
- return(string);
592
- }
593
-
594
-
595
- /*
596
- * call-seq:
597
- * XML::Parser.default_validity_checking => (true|false)
598
- *
599
- * Determine whether parsers perform XML validation by default.
600
- */
601
- VALUE
602
- ruby_xml_parser_default_validity_checking_get(VALUE class) {
603
- if (xmlDoValidityCheckingDefaultValue)
604
- return(Qtrue);
605
- else
606
- return(Qfalse);
607
- }
608
-
609
-
610
- /*
611
- * call-seq:
612
- * XML::Parser.default_validity_checking = true|false
613
- *
614
- * Controls whether parsers perform XML validation by default.
615
- */
616
- VALUE
617
- ruby_xml_parser_default_validity_checking_set(VALUE class, VALUE bool) {
618
- if (TYPE(bool) == T_FALSE) {
619
- xmlDoValidityCheckingDefaultValue = 0;
620
- return(Qfalse);
621
- } else {
622
- xmlDoValidityCheckingDefaultValue = 1;
623
- return(Qtrue);
624
- }
625
- }
626
-
627
-
628
- /*
629
- * call-seq:
630
- * XML::Parser.default_warnings => (true|false)
631
- *
632
- * Determine whether parsers output warnings by default.
633
- */
634
- VALUE
635
- ruby_xml_parser_default_warnings_get(VALUE class) {
636
- if (xmlGetWarningsDefaultValue)
637
- return(Qtrue);
638
- else
639
- return(Qfalse);
640
- }
641
-
642
-
643
- /*
644
- * call-seq:
645
- * XML::Parser.default_warnings = true|false
646
- *
647
- * Controls whether parsers output warnings by default.
648
- */
649
- VALUE
650
- ruby_xml_parser_default_warnings_set(VALUE class, VALUE bool) {
651
- if (TYPE(bool) == T_FALSE) {
652
- xmlGetWarningsDefaultValue = 0;
653
- return(Qfalse);
654
- } else {
655
- xmlGetWarningsDefaultValue = 1;
656
- return(Qtrue);
657
- }
658
- }
659
-
660
-
661
- /*
662
- * call-seq:
663
- * XML::Parser.default_compression => (true|false)
664
- *
665
- * Determine whether parsers use Zlib compression by default
666
- * (requires libxml to be compiled with Zlib support).
667
- */
668
- VALUE
669
- ruby_xml_parser_default_compression_get(VALUE class) {
670
- #ifdef HAVE_ZLIB_H
671
- return(INT2FIX(xmlGetCompressMode()));
672
- #else
673
- rb_warn("libxml was compiled without zlib support");
674
- return(Qfalse);
675
- #endif
676
- }
677
-
678
-
679
- /*
680
- * call-seq:
681
- * XML::Parser.default_compression = true|false
682
- *
683
- * Controls whether parsers use Zlib compression by default
684
- * (requires libxml to be compiled with Zlib support).
685
- */
686
- VALUE
687
- ruby_xml_parser_default_compression_set(VALUE class, VALUE num) {
688
- #ifdef HAVE_ZLIB_H
689
- Check_Type(num, T_FIXNUM);
690
- xmlSetCompressMode(FIX2INT(num));
691
- return(num);
692
- #else
693
- rb_warn("libxml was compiled without zlib support");
694
- return(Qfalse);
695
- #endif
696
- }
697
-
698
-
699
- /*
700
- * call-seq:
701
- * XML::Parser.features => ["feature", ..., "feature"]
702
- *
703
- * Obtains an array of strings representing features supported
704
- * (and enabled) by the installed libxml.
705
- */
706
- VALUE
707
- ruby_xml_parser_features(VALUE class) {
708
- VALUE arr, str;
709
- int i, len = MAX_LIBXML_FEATURES_LEN;
710
- char **list = NULL;
711
-
712
- list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
713
- MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
714
-
715
- arr = rb_ary_new();
716
- if (xmlGetFeaturesList(&len, (const char **)list) == -1)
717
- return Qnil;
718
-
719
- for (i = 0; i < len; i++) {
720
- str = rb_str_new2((const char *)list[i]);
721
- rb_gc_unregister_address(&str);
722
- rb_ary_push(arr, str);
723
- }
724
-
725
- if (len == MAX_LIBXML_FEATURES_LEN)
726
- 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");
727
-
728
- ruby_xfree(list);
729
- return(arr);
730
- }
731
-
732
-
733
- /*
734
- * call-seq:
735
- * parser.filename => "filename"
736
- *
737
- * Obtain the filename this parser will read from.
738
- */
739
- VALUE
740
- ruby_xml_parser_filename_get(VALUE self) {
741
- ruby_xml_parser *rxp;
742
- rx_file_data *data;
743
-
744
- Data_Get_Struct(self, ruby_xml_parser, rxp);
745
- if (rxp->data == NULL)
746
- return(Qnil);
747
-
748
- if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE)
749
- return(Qnil);
750
-
751
- data = (rx_file_data *)rxp->data;
752
- return(data->filename);
753
- }
754
-
755
-
756
- /*
757
- * call-seq:
758
- * parser.filename = "filename"
759
- *
760
- * Set the filename this parser will read from.
761
- */
762
- VALUE
763
- ruby_xml_parser_filename_set(VALUE self, VALUE filename) {
764
- ruby_xml_parser *rxp;
765
- ruby_xml_parser_context *rxpc;
766
- rx_file_data *data;
767
-
768
- Check_Type(filename, T_STRING);
769
- Data_Get_Struct(self, ruby_xml_parser, rxp);
770
-
771
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
772
- if (rxp->data != NULL)
773
- rb_fatal("crap, this should be null");
774
-
775
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
776
- data = ALLOC(rx_file_data);
777
- rxp->data = data;
778
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE) {
779
- return(Qnil);
780
- }
781
-
782
- rxp->ctxt = ruby_xml_parser_context_new3();
783
- data = (rx_file_data *)rxp->data;
784
- data->filename = filename;
785
-
786
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
787
- rxpc->ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
788
- if (rxpc->ctxt == NULL)
789
- rb_sys_fail(StringValuePtr(filename));
790
-
791
- return(data->filename);
792
- }
793
-
794
-
795
- void
796
- ruby_xml_parser_free(ruby_xml_parser *rxp) {
797
- void *data;
798
-
799
- switch(rxp->data_type) {
800
- case RUBY_LIBXML_SRC_TYPE_NULL:
801
- break;
802
- case RUBY_LIBXML_SRC_TYPE_FILE:
803
- data = (void *)(rx_file_data *)rxp->data;
804
- free((rx_file_data *)data);
805
- break;
806
- case RUBY_LIBXML_SRC_TYPE_STRING:
807
- data = (void *)(rx_string_data *)rxp->data;
808
- free((rx_string_data *)data);
809
- break;
810
- case RUBY_LIBXML_SRC_TYPE_IO:
811
- data = (void *)(rx_io_data *)rxp->data;
812
- free((rx_io_data *)data);
813
- break;
814
- default:
815
- rb_fatal("Unknown data type, %d", rxp->data_type);
816
- }
817
-
818
- free(rxp);
819
- }
820
-
821
-
822
- /*
823
- * call-seq:
824
- * XML::Parser.indent_tree_output => (true|false)
825
- *
826
- * Determines whether XML output will be indented
827
- * (using the string supplied to +default_indent_tree_string+)
828
- */
829
- VALUE
830
- ruby_xml_parser_indent_tree_output_get(VALUE class) {
831
- if (xmlIndentTreeOutput)
832
- return(Qtrue);
833
- else
834
- return(Qfalse);
835
- }
836
-
837
-
838
- /*
839
- * call-seq:
840
- * XML::Parser.indent_tree_output = true|false
841
- *
842
- * Controls whether XML output will be indented
843
- * (using the string supplied to +default_indent_tree_string+)
844
- */
845
- VALUE
846
- ruby_xml_parser_indent_tree_output_set(VALUE class, VALUE bool) {
847
- if (TYPE(bool) == T_TRUE) {
848
- xmlIndentTreeOutput = 1;
849
- return(Qtrue);
850
- } else if (TYPE(bool) == T_FALSE) {
851
- xmlIndentTreeOutput = 0;
852
- return(Qfalse);
853
- } else {
854
- rb_raise(rb_eArgError, "invalid argument, must be boolean");
855
- }
856
- }
857
-
858
-
859
- /*
860
- * call-seq:
861
- * parser.io => IO
862
- *
863
- * Obtain the IO instance this parser works with.
864
- */
865
- VALUE
866
- ruby_xml_parser_io_get(VALUE self, VALUE io) {
867
- ruby_xml_parser *rxp;
868
- rx_io_data *data;
869
-
870
- Data_Get_Struct(self, ruby_xml_parser, rxp);
871
-
872
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL ||
873
- rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO ||
874
- rxp->data == NULL)
875
- return(Qnil);
876
-
877
- data = (rx_io_data *)rxp->data;
878
-
879
- return(data->io);
880
- }
881
-
882
-
883
- /*
884
- * call-seq:
885
- * parser.io = IO
886
- *
887
- * Set the IO instance this parser works with.
888
- */
889
- VALUE
890
- ruby_xml_parser_io_set(VALUE self, VALUE io) {
891
- ruby_xml_parser *rxp;
892
- ruby_xml_parser_context *rxpc;
893
- rx_io_data *data;
894
- OpenFile *fptr;
895
- FILE *f;
896
-
897
- if (!rb_obj_is_kind_of(io, rb_cIO))
898
- rb_raise(rb_eTypeError, "need an IO object");
899
-
900
- Data_Get_Struct(self, ruby_xml_parser, rxp);
901
-
902
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
903
- if (rxp->data != NULL)
904
- rb_fatal("crap, this should be null");
905
-
906
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
907
- data = ALLOC(rx_io_data);
908
- rxp->data = data;
909
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO) {
910
- return(Qnil);
911
- }
912
-
913
- rxp->ctxt = ruby_xml_parser_context_new3();
914
- data = (rx_io_data *)rxp->data;
915
- data->io = io;
916
-
917
- GetOpenFile(io, fptr);
918
- rb_io_check_readable(fptr);
919
- f = GetWriteFile(fptr);
920
-
921
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
922
- rxpc->ctxt = xmlCreateIOParserCtxt(NULL, NULL,
923
- (xmlInputReadCallback) ctxtRead,
924
- NULL, f, XML_CHAR_ENCODING_NONE);
925
- if (NIL_P(rxpc->ctxt))
926
- rb_sys_fail(0);
927
-
928
- return(data->io);
929
- }
930
-
931
-
932
- void
933
- ruby_xml_parser_mark(ruby_xml_parser *rxp) {
934
- if (rxp == NULL) return;
935
- if (!NIL_P(rxp->ctxt)) rb_gc_mark(rxp->ctxt);
936
-
937
- ruby_xml_state_marker();
938
-
939
- switch(rxp->data_type) {
940
- case RUBY_LIBXML_SRC_TYPE_NULL:
941
- break;
942
- case RUBY_LIBXML_SRC_TYPE_FILE:
943
- if (!NIL_P(((rx_file_data *)rxp->data)->filename))
944
- rb_gc_mark(((rx_file_data *)rxp->data)->filename);
945
- break;
946
- case RUBY_LIBXML_SRC_TYPE_STRING:
947
- if (!NIL_P(((rx_string_data *)rxp->data)->str))
948
- rb_gc_mark(((rx_string_data *)rxp->data)->str);
949
- break;
950
- case RUBY_LIBXML_SRC_TYPE_IO:
951
- if (!NIL_P(((rx_io_data *)rxp->data)->io))
952
- rb_gc_mark(((rx_io_data *)rxp->data)->io);
953
- break;
954
- default:
955
- rb_fatal("unknown datatype: %d", rxp->data_type);
956
- }
957
- }
958
-
959
-
960
- /*
961
- * call-seq:
962
- * XML::Parser.memory_dump => (true|false)
963
- *
964
- * Perform a parser memory dump (requires memory debugging
965
- * support in libxml).
966
- */
967
- VALUE
968
- ruby_xml_parser_memory_dump(VALUE self) {
969
- #ifdef DEBUG_MEMORY_LOCATION
970
- xmlMemoryDump();
971
- return(Qtrue);
972
- #else
973
- rb_warn("libxml was compiled without memory debugging support");
974
- return(Qfalse);
975
- #endif
976
- }
977
-
978
-
979
- /*
980
- * call-seq:
981
- * XML::Parser.memory_used => num_bytes
982
- *
983
- * Perform a parser memory dump (requires memory debugging
984
- * support in libxml).
985
- */
986
- VALUE
987
- ruby_xml_parser_memory_used(VALUE self) {
988
- #ifdef DEBUG_MEMORY_LOCATION
989
- return(INT2NUM(xmlMemUsed()));
990
- #else
991
- rb_warn("libxml was compiled without memory debugging support");
992
- return(Qfalse);
993
- #endif
994
- }
995
-
996
-
997
- /*
998
- * call-seq:
999
- * XML::Parser.new => parser
1000
- *
1001
- * Create a new parser instance with no pre-determined source.
1002
- */
1003
- VALUE
1004
- ruby_xml_parser_new(VALUE class) {
1005
- ruby_xml_parser *rxp;
1006
- VALUE r;
1007
-
1008
- r=Data_Make_Struct(class,
1009
- ruby_xml_parser,
1010
- ruby_xml_parser_mark,
1011
- ruby_xml_parser_free,
1012
- rxp);
1013
-
1014
- rxp->ctxt = Qnil;
1015
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
1016
- rxp->data = NULL;
1017
- rxp->parsed = 0;
1018
-
1019
- return r;
1020
- }
1021
-
1022
-
1023
- /*
1024
- * call-seq:
1025
- * XML::Parser.file => parser
1026
- *
1027
- * Create a new parser instance that will read the specified file.
1028
- */
1029
- VALUE
1030
- ruby_xml_parser_new_file(VALUE class, VALUE filename) {
1031
- VALUE obj;
1032
- ruby_xml_parser *rxp;
1033
- rx_file_data *data;
1034
-
1035
- obj = ruby_xml_parser_new(class);
1036
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1037
-
1038
- data = ALLOC(rx_file_data);
1039
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
1040
- rxp->data = data;
1041
-
1042
- ruby_xml_parser_filename_set(obj, filename);
1043
-
1044
- return(obj);
1045
- }
1046
-
1047
-
1048
- /*
1049
- * call-seq:
1050
- * XML::Parser.io => parser
1051
- *
1052
- * Create a new parser instance that will read from the
1053
- * specified IO object.
1054
- */
1055
- VALUE
1056
- ruby_xml_parser_new_io(VALUE class, VALUE io) {
1057
- VALUE obj;
1058
- ruby_xml_parser *rxp;
1059
- rx_io_data *data;
1060
-
1061
- obj = ruby_xml_parser_new(class);
1062
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1063
-
1064
- data = ALLOC(rx_io_data);
1065
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
1066
- rxp->data = data;
1067
-
1068
- ruby_xml_parser_io_set(obj, io);
1069
-
1070
- return(obj);
1071
- }
1072
-
1073
-
1074
- /*
1075
- * call-seq:
1076
- * XML::Parser.string => parser
1077
- *
1078
- * Create a new parser instance that will parse the given
1079
- * string.
1080
- */
1081
- VALUE
1082
- ruby_xml_parser_new_string(VALUE class, VALUE str) {
1083
- VALUE obj;
1084
- ruby_xml_parser *rxp;
1085
- rx_string_data *data;
1086
-
1087
- obj = ruby_xml_parser_new(class);
1088
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1089
-
1090
- data = ALLOC(rx_string_data);
1091
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1092
- rxp->data = data;
1093
-
1094
- ruby_xml_parser_str_set(obj, str);
1095
-
1096
- return(obj);
1097
- }
1098
-
1099
-
1100
- /*
1101
- * call-seq:
1102
- * parser.parse => document
1103
- *
1104
- * Parse the input XML and create an XML::Document with
1105
- * it's content. If an error occurs, XML::Parser::ParseError
1106
- * is thrown.
1107
- */
1108
- VALUE
1109
- ruby_xml_parser_parse(VALUE self) {
1110
- ruby_xml_document_t *rxd;
1111
- ruby_xml_parser *rxp;
1112
- ruby_xml_parser_context *rxpc;
1113
- xmlDocPtr xdp;
1114
- VALUE doc;
1115
-
1116
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1117
-
1118
- switch (rxp->data_type) {
1119
- case RUBY_LIBXML_SRC_TYPE_NULL:
1120
- return(Qnil);
1121
- case RUBY_LIBXML_SRC_TYPE_STRING:
1122
- case RUBY_LIBXML_SRC_TYPE_FILE:
1123
- case RUBY_LIBXML_SRC_TYPE_IO:
1124
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1125
- if (xmlParseDocument(rxpc->ctxt) == -1) {
1126
- xmlFreeDoc(rxpc->ctxt->myDoc);
1127
- rb_raise(eXMLParserParseError, "Document didn't parse");
1128
- }
1129
-
1130
- xdp = rxpc->ctxt->myDoc;
1131
- if (!rxpc->ctxt->wellFormed) {
1132
- xmlFreeDoc(xdp);
1133
- xdp = NULL;
1134
- rb_raise(eXMLParserParseError, "Document did not contain well-formed XML");
1135
- } else {
1136
- rxp->parsed = 1;
1137
- }
1138
-
1139
- doc = ruby_xml_document_wrap(cXMLDocument, xdp);
1140
- break;
1141
- default:
1142
- rb_fatal("Unknown data type, %d", rxp->data_type);
1143
- }
1144
-
1145
- return(doc);
1146
- }
1147
-
1148
-
1149
- /*
1150
- * call-seq:
1151
- * parser.context => context
1152
- *
1153
- * Obtain the XML::Parser::Context associated with this
1154
- * parser.
1155
- */
1156
- VALUE
1157
- ruby_xml_parser_parser_context_get(VALUE self) {
1158
- ruby_xml_parser *rxp;
1159
-
1160
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1161
- if (rxp->ctxt == Qnil)
1162
- return(Qnil);
1163
- else
1164
- return(rxp->ctxt);
1165
- }
1166
-
1167
-
1168
- /*
1169
- * call-seq:
1170
- * parser.string => "string"
1171
- *
1172
- * Obtain the string this parser works with.
1173
- */
1174
- VALUE
1175
- ruby_xml_parser_str_get(VALUE self) {
1176
- ruby_xml_parser *rxp;
1177
- rx_string_data *data;
1178
-
1179
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1180
- if (rxp->data == NULL || rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING)
1181
- return(Qnil);
1182
-
1183
- data = (rx_string_data *)rxp->data;
1184
- return(data->str);
1185
- }
1186
-
1187
-
1188
- /*
1189
- * call-seq:
1190
- * parser.string = "string"
1191
- *
1192
- * Set the string this parser works with.
1193
- */
1194
- VALUE
1195
- ruby_xml_parser_str_set(VALUE self, VALUE str) {
1196
- ruby_xml_parser *rxp;
1197
- ruby_xml_parser_context *rxpc;
1198
- rx_string_data *data;
1199
-
1200
- Check_Type(str, T_STRING);
1201
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1202
-
1203
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
1204
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1205
- data = ALLOC(rx_string_data);
1206
- rxp->data = data;
1207
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING) {
1208
- return(Qnil);
1209
- }
1210
-
1211
- rxp->ctxt = ruby_xml_parser_context_new3();
1212
- data = (rx_string_data *)rxp->data;
1213
- data->str = str;
1214
-
1215
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1216
- rxpc->ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data->str), RSTRING_LEN(data->str));
1217
- if ( rxpc->ctxt == NULL )
1218
- rb_raise(eXMLParserParseError,"Cannot initialize parser with given string (maybe empty?)");
1219
-
1220
- return(data->str);
1221
- }
1222
-
1223
- /*
1224
- * call-seq:
1225
- * XML::Parser.register_error_handler(lambda { |msg| ... }) => old_handler
1226
- * XML::Parser.register_error_handler(nil) => old_handler
1227
- *
1228
- * Register the attached block as the handler for parser errors.
1229
- * A message describing parse errors is passed to the block.
1230
- * Libxml passes error messages to the handler in parts, one per call.
1231
- * A typical error results in six calls to this proc, with arguments:
1232
- *
1233
- * "Entity: line 1: ",
1234
- * "parser ",
1235
- * "error : ",
1236
- * "Opening and ending tag mismatch: foo line 1 and foz\n",
1237
- * "<foo><bar/></foz>\n",
1238
- * " ^\n"
1239
- *
1240
- * Note that the error handler is shared by all threads.
1241
- */
1242
- VALUE
1243
- ruby_xml_parser_registerErrorHandler(VALUE self, VALUE proc) {
1244
- VALUE old_block = libxml_xmlRubyErrorProc;
1245
- libxml_xmlRubyErrorProc = proc;
1246
- return(old_block);
1247
- }
1248
-
1249
- static void
1250
- libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
1251
- {
1252
- va_list ap;
1253
- char str[1000];
1254
- VALUE rstr;
1255
-
1256
- if (libxml_xmlRubyErrorProc == Qnil) {
1257
- va_start(ap, msg);
1258
- vfprintf(stderr, msg, ap);
1259
- va_end(ap);
1260
- } else {
1261
- va_start(ap, msg);
1262
- if (vsnprintf(str, 999, msg, ap) >= 998) str[999] = 0;
1263
- va_end(ap);
1264
-
1265
- rstr = rb_str_new2(str);
1266
- rb_funcall2(libxml_xmlRubyErrorProc, id_call, 1, &rstr);
1267
- }
1268
- }
1269
-
1270
- /* #define RUBY_XML_PARSER_ENABLED_INIT(func, method) \
1271
- rb_define_singleton_method(cXMLParser, method, \
1272
- ruby_xml_parser_enabled_##func##_q, 0); */
1273
-
1274
- ///#include "cbg.c"
1275
- ///
1276
- ///VALUE ruby_register_deb(VALUE self) {
1277
- /// deb_register_cbg();
1278
- /// return(Qtrue);
1279
- ///}
1280
-
1281
- // Rdoc needs to know
1282
- #ifdef RDOC_NEVER_DEFINED
1283
- mXML = rb_define_module("XML");
1284
- #endif
1285
-
1286
- void
1287
- ruby_init_parser(void) {
1288
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
1289
- eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
1290
- rb_eRuntimeError);
1291
-
1292
- /* Constants */
1293
- rb_define_const(cXMLParser, "LIBXML_VERSION",
1294
- rb_str_new2(LIBXML_DOTTED_VERSION));
1295
- rb_define_const(cXMLParser, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
1296
- rb_define_const(cXMLParser, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
1297
-
1298
- /* Question-esqe Class Methods */
1299
- /* RDoc won't have them defined by a macro... */
1300
- rb_define_singleton_method(cXMLParser, "enabled_automata?",
1301
- ruby_xml_parser_enabled_automata_q, 0);
1302
- rb_define_singleton_method(cXMLParser, "enabled_c14n?",
1303
- ruby_xml_parser_enabled_c14n_q, 0);
1304
- rb_define_singleton_method(cXMLParser, "enabled_catalog?",
1305
- ruby_xml_parser_enabled_catalog_q, 0);
1306
- rb_define_singleton_method(cXMLParser, "enabled_debug?",
1307
- ruby_xml_parser_enabled_debug_q, 0);
1308
- rb_define_singleton_method(cXMLParser, "enabled_docbook?",
1309
- ruby_xml_parser_enabled_docbook_q, 0);
1310
- rb_define_singleton_method(cXMLParser, "enabled_ftp?",
1311
- ruby_xml_parser_enabled_ftp_q, 0);
1312
- rb_define_singleton_method(cXMLParser, "enabled_http?",
1313
- ruby_xml_parser_enabled_http_q, 0);
1314
- rb_define_singleton_method(cXMLParser, "enabled_html?",
1315
- ruby_xml_parser_enabled_html_q, 0);
1316
- rb_define_singleton_method(cXMLParser, "enabled_iconv?",
1317
- ruby_xml_parser_enabled_iconv_q, 0);
1318
- rb_define_singleton_method(cXMLParser, "enabled_memory_debug?",
1319
- ruby_xml_parser_enabled_memory_debug_location_q, 0);
1320
- rb_define_singleton_method(cXMLParser, "enabled_regexp?",
1321
- ruby_xml_parser_enabled_regexp_q, 0);
1322
- rb_define_singleton_method(cXMLParser, "enabled_schemas?",
1323
- ruby_xml_parser_enabled_schemas_q, 0);
1324
- rb_define_singleton_method(cXMLParser, "enabled_thread?",
1325
- ruby_xml_parser_enabled_thread_q, 0);
1326
- rb_define_singleton_method(cXMLParser, "enabled_unicode?",
1327
- ruby_xml_parser_enabled_unicode_q, 0);
1328
- rb_define_singleton_method(cXMLParser, "enabled_xinclude?",
1329
- ruby_xml_parser_enabled_xinclude_q, 0);
1330
- rb_define_singleton_method(cXMLParser, "enabled_xpath?",
1331
- ruby_xml_parser_enabled_xpath_q, 0);
1332
- rb_define_singleton_method(cXMLParser, "enabled_xpointer?",
1333
- ruby_xml_parser_enabled_xpointer_q, 0);
1334
- rb_define_singleton_method(cXMLParser, "enabled_zlib?",
1335
- ruby_xml_parser_enabled_zlib_q, 0);
1336
-
1337
- /* Other Class Methods */
1338
- /// rb_define_singleton_method(cXMLParser, "register_deb",
1339
- /// ruby_register_deb, 0);
1340
-
1341
- // TODO Maybe a set of 'xxxx_catalog' aliases might be more Ruby?
1342
- rb_define_singleton_method(cXMLParser, "catalog_dump",
1343
- ruby_xml_parser_catalog_dump, 0);
1344
- rb_define_singleton_method(cXMLParser, "catalog_remove",
1345
- ruby_xml_parser_catalog_remove, 1);
1346
- rb_define_singleton_method(cXMLParser, "check_lib_versions",
1347
- ruby_xml_parser_check_lib_versions, 0);
1348
-
1349
- // TODO should this be debug_entities_q / debug_entities_set?
1350
- // should all these default attribute pairs work that way?
1351
- rb_define_singleton_method(cXMLParser, "debug_entities",
1352
- ruby_xml_parser_debug_entities_get, 0);
1353
- rb_define_singleton_method(cXMLParser, "debug_entities=",
1354
- ruby_xml_parser_debug_entities_set, 1);
1355
- rb_define_singleton_method(cXMLParser, "default_compression",
1356
- ruby_xml_parser_default_compression_get, 0);
1357
- rb_define_singleton_method(cXMLParser, "default_compression=",
1358
- ruby_xml_parser_default_compression_set, 1);
1359
- rb_define_singleton_method(cXMLParser, "default_keep_blanks",
1360
- ruby_xml_parser_default_keep_blanks_get, 0);
1361
- rb_define_singleton_method(cXMLParser, "default_keep_blanks=",
1362
- ruby_xml_parser_default_keep_blanks_set, 1);
1363
- rb_define_singleton_method(cXMLParser, "default_load_external_dtd",
1364
- ruby_xml_parser_default_load_external_dtd_get, 0);
1365
- rb_define_singleton_method(cXMLParser, "default_load_external_dtd=",
1366
- ruby_xml_parser_default_load_external_dtd_set, 1);
1367
- rb_define_singleton_method(cXMLParser, "default_line_numbers",
1368
- ruby_xml_parser_default_line_numbers_get, 0);
1369
- rb_define_singleton_method(cXMLParser, "default_line_numbers=",
1370
- ruby_xml_parser_default_line_numbers_set, 1);
1371
- rb_define_singleton_method(cXMLParser, "default_pedantic_parser",
1372
- ruby_xml_parser_default_pedantic_parser_get, 0);
1373
- rb_define_singleton_method(cXMLParser, "default_pedantic_parser=",
1374
- ruby_xml_parser_default_pedantic_parser_set, 1);
1375
- rb_define_singleton_method(cXMLParser, "default_substitute_entities",
1376
- ruby_xml_parser_default_substitute_entities_get, 0);
1377
- rb_define_singleton_method(cXMLParser, "default_substitute_entities=",
1378
- ruby_xml_parser_default_substitute_entities_set, 1);
1379
- rb_define_singleton_method(cXMLParser, "default_tree_indent_string",
1380
- ruby_xml_parser_default_tree_indent_string_get, 0);
1381
- rb_define_singleton_method(cXMLParser, "default_tree_indent_string=",
1382
- ruby_xml_parser_default_tree_indent_string_set, 1);
1383
- rb_define_singleton_method(cXMLParser, "default_validity_checking",
1384
- ruby_xml_parser_default_validity_checking_get, 0);
1385
- rb_define_singleton_method(cXMLParser, "default_validity_checking=",
1386
- ruby_xml_parser_default_validity_checking_set, 1);
1387
- rb_define_singleton_method(cXMLParser, "default_warnings",
1388
- ruby_xml_parser_default_warnings_get, 0);
1389
- rb_define_singleton_method(cXMLParser, "default_warnings=",
1390
- ruby_xml_parser_default_warnings_set, 1);
1391
-
1392
- rb_define_singleton_method(cXMLParser, "features", ruby_xml_parser_features, 0);
1393
- rb_define_singleton_method(cXMLParser, "file", ruby_xml_parser_new_file, 1);
1394
- rb_define_singleton_method(cXMLParser, "indent_tree_output", ruby_xml_parser_indent_tree_output_get, 0);
1395
- rb_define_singleton_method(cXMLParser, "indent_tree_output=", ruby_xml_parser_indent_tree_output_set, 1);
1396
- rb_define_singleton_method(cXMLParser, "io", ruby_xml_parser_new_io, 1);
1397
- rb_define_singleton_method(cXMLParser, "memory_dump",
1398
- ruby_xml_parser_memory_dump, 0);
1399
- rb_define_singleton_method(cXMLParser, "memory_used",
1400
- ruby_xml_parser_memory_used, 0);
1401
- rb_define_singleton_method(cXMLParser, "new", ruby_xml_parser_new, 0);
1402
- rb_define_singleton_method(cXMLParser, "string", ruby_xml_parser_new_string, 1);
1403
- rb_define_singleton_method(cXMLParser, "register_error_handler", ruby_xml_parser_registerErrorHandler, 1);
1404
- rb_define_method(cXMLParser, "filename", ruby_xml_parser_filename_get, 0);
1405
- rb_define_method(cXMLParser, "filename=", ruby_xml_parser_filename_set, 1);
1406
- rb_define_method(cXMLParser, "io", ruby_xml_parser_io_get, 0);
1407
- rb_define_method(cXMLParser, "io=", ruby_xml_parser_io_set, 1);
1408
- rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
1409
- rb_define_method(cXMLParser, "parser_context", ruby_xml_parser_parser_context_get, 0);
1410
- rb_define_method(cXMLParser, "string", ruby_xml_parser_str_get, 0);
1411
- rb_define_method(cXMLParser, "string=", ruby_xml_parser_str_set, 1);
1412
-
1413
- // set up error handling
1414
- xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1415
- xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1416
-
1417
- // Ruby needs to know about this even though it's not exported, otherwise
1418
- // our error proc might get garbage collected.
1419
- rb_global_variable(&libxml_xmlRubyErrorProc);
1420
-
1421
- id_call = rb_intern("call");
1422
- }
1
+ /* $Id: ruby_xml_parser.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include <stdarg.h>
6
+ #include "ruby_libxml.h"
7
+
8
+ static VALUE libxml_xmlRubyErrorProc = Qnil;
9
+ static int id_call;
10
+
11
+ VALUE cXMLParser;
12
+ VALUE eXMLParserParseError;
13
+
14
+ static int
15
+ ctxtRead(FILE *f, char * buf, size_t len) {
16
+ return(fread(buf, 1, len, f));
17
+ }
18
+
19
+ /*
20
+ * call-seq:
21
+ * XML::Parser.catalog_dump => true
22
+ *
23
+ * Dump the parser resource catalogs to stdout.
24
+ */
25
+ VALUE
26
+ ruby_xml_parser_catalog_dump(VALUE self) {
27
+ xmlCatalogDump(stdout);
28
+ return(Qtrue);
29
+ }
30
+
31
+
32
+ /*
33
+ * call-seq:
34
+ * XML::Parser.catalog_remove(catalog) => true
35
+ *
36
+ * Remove the specified resource catalog.
37
+ */
38
+ VALUE
39
+ ruby_xml_parser_catalog_remove(VALUE self, VALUE cat) {
40
+ Check_Type(cat, T_STRING);
41
+ xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
42
+ return(Qtrue);
43
+ }
44
+
45
+
46
+ /*
47
+ * call-seq:
48
+ * XML::Parser.check_lib_versions => true
49
+ *
50
+ * Check LIBXML version matches version the bindings
51
+ * were compiled to. Throws an exception if not.
52
+ */
53
+ VALUE
54
+ ruby_xml_parser_check_lib_versions(VALUE class) {
55
+ xmlCheckVersion(LIBXML_VERSION);
56
+ return(Qtrue);
57
+ }
58
+
59
+
60
+ /*
61
+ * call-seq:
62
+ * XML::Parser.enabled_automata? => (true|false)
63
+ *
64
+ * Determine whether libxml regexp automata support is enabled.
65
+ */
66
+ VALUE
67
+ ruby_xml_parser_enabled_automata_q(VALUE class) {
68
+ #ifdef LIBXML_AUTOMATA_ENABLED
69
+ return(Qtrue);
70
+ #else
71
+ return(Qfalse);
72
+ #endif
73
+ }
74
+
75
+
76
+ /*
77
+ * call-seq:
78
+ * XML::Parser.enabled_c14n? => (true|false)
79
+ *
80
+ * Determine whether libxml 'canonical XML' support is enabled.
81
+ * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
82
+ */
83
+ VALUE
84
+ ruby_xml_parser_enabled_c14n_q(VALUE class) {
85
+ #ifdef LIBXML_C14N_ENABLED
86
+ return(Qtrue);
87
+ #else
88
+ return(Qfalse);
89
+ #endif
90
+ }
91
+
92
+
93
+ /*
94
+ * call-seq:
95
+ * XML::Parser.enabled_catalog? => (true|false)
96
+ *
97
+ * Determine whether libxml resource catalog support is enabled.
98
+ */
99
+ VALUE
100
+ ruby_xml_parser_enabled_catalog_q(VALUE class) {
101
+ #ifdef LIBXML_CATALOG_ENABLED
102
+ return(Qtrue);
103
+ #else
104
+ return(Qfalse);
105
+ #endif
106
+ }
107
+
108
+
109
+ /*
110
+ * call-seq:
111
+ * XML::Parser.enabled_debug? => (true|false)
112
+ *
113
+ * Determine whether libxml debugging support is enabled.
114
+ */
115
+ VALUE
116
+ ruby_xml_parser_enabled_debug_q(VALUE class) {
117
+ #ifdef LIBXML_DEBUG_ENABLED
118
+ return(Qtrue);
119
+ #else
120
+ return(Qfalse);
121
+ #endif
122
+ }
123
+
124
+
125
+ /*
126
+ * call-seq:
127
+ * XML::Parser.enabled_docbook? => (true|false)
128
+ *
129
+ * Determine whether libxml docbook support is enabled.
130
+ */
131
+ VALUE
132
+ ruby_xml_parser_enabled_docbook_q(VALUE class) {
133
+ #ifdef LIBXML_DOCB_ENABLED
134
+ return(Qtrue);
135
+ #else
136
+ return(Qfalse);
137
+ #endif
138
+ }
139
+
140
+
141
+ /*
142
+ * call-seq:
143
+ * XML::Parser.enabled_ftp? => (true|false)
144
+ *
145
+ * Determine whether libxml ftp client support is enabled.
146
+ */
147
+ VALUE
148
+ ruby_xml_parser_enabled_ftp_q(VALUE class) {
149
+ #ifdef LIBXML_FTP_ENABLED
150
+ return(Qtrue);
151
+ #else
152
+ return(Qfalse);
153
+ #endif
154
+ }
155
+
156
+
157
+ /*
158
+ * call-seq:
159
+ * XML::Parser.enabled_http? => (true|false)
160
+ *
161
+ * Determine whether libxml http client support is enabled.
162
+ */
163
+ VALUE
164
+ ruby_xml_parser_enabled_http_q(VALUE class) {
165
+ #ifdef LIBXML_HTTP_ENABLED
166
+ return(Qtrue);
167
+ #else
168
+ return(Qfalse);
169
+ #endif
170
+ }
171
+
172
+
173
+ /*
174
+ * call-seq:
175
+ * XML::Parser.enabled_html? => (true|false)
176
+ *
177
+ * Determine whether libxml html support is enabled.
178
+ */
179
+ VALUE
180
+ ruby_xml_parser_enabled_html_q(VALUE class) {
181
+ #ifdef LIBXML_HTML_ENABLED
182
+ return(Qtrue);
183
+ #else
184
+ return(Qfalse);
185
+ #endif
186
+ }
187
+
188
+
189
+ /*
190
+ * call-seq:
191
+ * XML::Parser.enabled_iconv? => (true|false)
192
+ *
193
+ * Determine whether libxml iconv support is enabled.
194
+ */
195
+ VALUE
196
+ ruby_xml_parser_enabled_iconv_q(VALUE class) {
197
+ #ifdef LIBXML_ICONV_ENABLED
198
+ return(Qtrue);
199
+ #else
200
+ return(Qfalse);
201
+ #endif
202
+ }
203
+
204
+
205
+ /*
206
+ * call-seq:
207
+ * XML::Parser.enabled_memory_debug? => (true|false)
208
+ *
209
+ * Determine whether libxml memory location debugging support
210
+ * is enabled.
211
+ */
212
+ VALUE
213
+ ruby_xml_parser_enabled_memory_debug_location_q(VALUE class) {
214
+ #ifdef DEBUG_MEMORY_LOCATION
215
+ return(Qtrue);
216
+ #else
217
+ return(Qfalse);
218
+ #endif
219
+ }
220
+
221
+
222
+ /*
223
+ * call-seq:
224
+ * XML::Parser.enabled_regexp? => (true|false)
225
+ *
226
+ * Determine whether libxml regular expression support is enabled.
227
+ */
228
+ VALUE
229
+ ruby_xml_parser_enabled_regexp_q(VALUE class) {
230
+ #ifdef LIBXML_REGEXP_ENABLED
231
+ return(Qtrue);
232
+ #else
233
+ return(Qfalse);
234
+ #endif
235
+ }
236
+
237
+
238
+ /*
239
+ * call-seq:
240
+ * XML::Parser.enabled_schemas? => (true|false)
241
+ *
242
+ * Determine whether libxml schema support is enabled.
243
+ */
244
+ VALUE
245
+ ruby_xml_parser_enabled_schemas_q(VALUE class) {
246
+ #ifdef LIBXML_SCHEMAS_ENABLED
247
+ return(Qtrue);
248
+ #else
249
+ return(Qfalse);
250
+ #endif
251
+ }
252
+
253
+
254
+ /*
255
+ * call-seq:
256
+ * XML::Parser.enabled_thread? => (true|false)
257
+ *
258
+ * Determine whether libxml thread-safe semantics support
259
+ * is enabled (I think?).
260
+ */
261
+ VALUE
262
+ ruby_xml_parser_enabled_thread_q(VALUE class) {
263
+ #ifdef LIBXML_THREAD_ENABLED
264
+ return(Qtrue);
265
+ #else
266
+ return(Qfalse);
267
+ #endif
268
+ }
269
+
270
+
271
+ /*
272
+ * call-seq:
273
+ * XML::Parser.enabled_unicode? => (true|false)
274
+ *
275
+ * Determine whether libxml unicode support is enabled.
276
+ */
277
+ VALUE
278
+ ruby_xml_parser_enabled_unicode_q(VALUE class) {
279
+ #ifdef LIBXML_UNICODE_ENABLED
280
+ return(Qtrue);
281
+ #else
282
+ return(Qfalse);
283
+ #endif
284
+ }
285
+
286
+
287
+ /*
288
+ * call-seq:
289
+ * XML::Parser.enabled_xinclude? => (true|false)
290
+ *
291
+ * Determine whether libxml xinclude support is enabled.
292
+ */
293
+ VALUE
294
+ ruby_xml_parser_enabled_xinclude_q(VALUE class) {
295
+ #ifdef LIBXML_XINCLUDE_ENABLED
296
+ return(Qtrue);
297
+ #else
298
+ return(Qfalse);
299
+ #endif
300
+ }
301
+
302
+
303
+ /*
304
+ * call-seq:
305
+ * XML::Parser.enabled_xpath? => (true|false)
306
+ *
307
+ * Determine whether libxml xpath support is enabled.
308
+ */
309
+ VALUE
310
+ ruby_xml_parser_enabled_xpath_q(VALUE class) {
311
+ #ifdef LIBXML_XPATH_ENABLED
312
+ return(Qtrue);
313
+ #else
314
+ return(Qfalse);
315
+ #endif
316
+ }
317
+
318
+
319
+ /*
320
+ * call-seq:
321
+ * XML::Parser.enabled_xpointer? => (true|false)
322
+ *
323
+ * Determine whether libxml xpointer support is enabled.
324
+ */
325
+ VALUE
326
+ ruby_xml_parser_enabled_xpointer_q(VALUE class) {
327
+ #ifdef LIBXML_XPTR_ENABLED
328
+ return(Qtrue);
329
+ #else
330
+ return(Qfalse);
331
+ #endif
332
+ }
333
+
334
+
335
+ /*
336
+ * call-seq:
337
+ * XML::Parser.enabled_zlib? => (true|false)
338
+ *
339
+ * Determine whether libxml zlib support is enabled.
340
+ */
341
+ VALUE
342
+ ruby_xml_parser_enabled_zlib_q(VALUE class) {
343
+ #ifdef HAVE_ZLIB_H
344
+ return(Qtrue);
345
+ #else
346
+ return(Qfalse);
347
+ #endif
348
+ }
349
+
350
+
351
+ /*
352
+ * call-seq:
353
+ * XML::Parser.debug_entities => (true|false)
354
+ *
355
+ * Determine whether included-entity debugging is enabled.
356
+ * (Requires Libxml to be compiled with debugging support)
357
+ */
358
+ VALUE
359
+ ruby_xml_parser_debug_entities_get(VALUE class) {
360
+ #ifdef LIBXML_DEBUG_ENABLED
361
+ if (xmlParserDebugEntities)
362
+ return(Qtrue);
363
+ else
364
+ return(Qfalse);
365
+ #else
366
+ rb_warn("libxml was compiled with debugging turned off");
367
+ return(Qfalse);
368
+ #endif
369
+ }
370
+
371
+
372
+ /*
373
+ * call-seq:
374
+ * XML::Parser.debug_entities = true|false
375
+ *
376
+ * Enable or disable included-entity debugging.
377
+ * (Requires Libxml to be compiled with debugging support)
378
+ */
379
+ VALUE
380
+ ruby_xml_parser_debug_entities_set(VALUE class, VALUE bool) {
381
+ #ifdef LIBXML_DEBUG_ENABLED
382
+ if (TYPE(bool) == T_FALSE) {
383
+ xmlParserDebugEntities = 0;
384
+ return(Qfalse);
385
+ } else {
386
+ xmlParserDebugEntities = 1;
387
+ return(Qtrue);
388
+ }
389
+ #else
390
+ rb_warn("libxml was compiled with debugging turned off");
391
+ #endif
392
+ }
393
+
394
+
395
+ /*
396
+ * call-seq:
397
+ * XML::Parser.default_keep_blanks => (true|false)
398
+ *
399
+ * Determine whether parsers retain whitespace by default.
400
+ */
401
+ VALUE
402
+ ruby_xml_parser_default_keep_blanks_get(VALUE class) {
403
+ if (xmlKeepBlanksDefaultValue)
404
+ return(Qtrue);
405
+ else
406
+ return(Qfalse);
407
+ }
408
+
409
+
410
+ /*
411
+ * call-seq:
412
+ * XML::Parser.default_keep_blanks = true|false
413
+ *
414
+ * Controls whether parsers retain whitespace by default.
415
+ */
416
+ VALUE
417
+ ruby_xml_parser_default_keep_blanks_set(VALUE class, VALUE bool) {
418
+ if (TYPE(bool) == T_FALSE) {
419
+ xmlKeepBlanksDefaultValue = 0;
420
+ return(Qfalse);
421
+ } else if (TYPE(bool) == T_TRUE) {
422
+ xmlKeepBlanksDefaultValue = 1;
423
+ return(Qtrue);
424
+ } else {
425
+ rb_raise(rb_eArgError, "invalid argument, must be a boolean");
426
+ }
427
+ }
428
+
429
+
430
+ /*
431
+ * call-seq:
432
+ * XML::Parser.default_load_external_dtd => (true|false)
433
+ *
434
+ * Determine whether parsers load external DTDs by default.
435
+ */
436
+ VALUE
437
+ ruby_xml_parser_default_load_external_dtd_get(VALUE class) {
438
+ if (xmlLoadExtDtdDefaultValue)
439
+ return(Qtrue);
440
+ else
441
+ return(Qfalse);
442
+ }
443
+
444
+
445
+ /*
446
+ * call-seq:
447
+ * XML::Parser.default_load_external_dtd = true|false
448
+ *
449
+ * Controls whether parsers load external DTDs by default.
450
+ */
451
+ VALUE
452
+ ruby_xml_parser_default_load_external_dtd_set(VALUE class, VALUE bool) {
453
+ if (TYPE(bool) == T_FALSE) {
454
+ xmlLoadExtDtdDefaultValue = 0;
455
+ return(Qfalse);
456
+ } else {
457
+ xmlLoadExtDtdDefaultValue = 1;
458
+ return(Qtrue);
459
+ }
460
+ }
461
+
462
+
463
+ /*
464
+ * call-seq:
465
+ * XML::Parser.default_line_numbers => (true|false)
466
+ *
467
+ * Determine whether parsers retain line-numbers by default.
468
+ */
469
+ VALUE
470
+ ruby_xml_parser_default_line_numbers_get(VALUE class) {
471
+ if (xmlLineNumbersDefaultValue)
472
+ return(Qtrue);
473
+ else
474
+ return(Qfalse);
475
+ }
476
+
477
+
478
+ /*
479
+ * call-seq:
480
+ * XML::Parser.default_line_numbers = true|false
481
+ *
482
+ * Controls whether parsers retain line-numbers by default.
483
+ */
484
+ VALUE
485
+ ruby_xml_parser_default_line_numbers_set(VALUE class, VALUE bool) {
486
+ if (TYPE(bool) == T_FALSE) {
487
+ xmlLineNumbersDefault(0);
488
+ return(Qfalse);
489
+ } else {
490
+ xmlLineNumbersDefault(1);
491
+ return(Qtrue);
492
+ }
493
+ }
494
+
495
+
496
+ /*
497
+ * call-seq:
498
+ * XML::Parser.default_pedantic_parser => (true|false)
499
+ *
500
+ * Determine whether parsers are pedantic by default.
501
+ */
502
+ VALUE
503
+ ruby_xml_parser_default_pedantic_parser_get(VALUE class) {
504
+ if (xmlPedanticParserDefaultValue)
505
+ return(Qtrue);
506
+ else
507
+ return(Qfalse);
508
+ }
509
+
510
+
511
+ /*
512
+ * call-seq:
513
+ * XML::Parser.default_pedantic_parser = true|false
514
+ *
515
+ * Controls whether parsers are pedantic by default.
516
+ */
517
+ VALUE
518
+ ruby_xml_parser_default_pedantic_parser_set(VALUE class, VALUE bool) {
519
+ if (TYPE(bool) == T_FALSE) {
520
+ xmlPedanticParserDefault(0);
521
+ return(Qfalse);
522
+ } else {
523
+ xmlPedanticParserDefault(1);
524
+ return(Qtrue);
525
+ }
526
+ }
527
+
528
+
529
+ /*
530
+ * call-seq:
531
+ * XML::Parser.default_substitute_entities => (true|false)
532
+ *
533
+ * Determine whether parsers perform inline entity substitution
534
+ * (for external entities) by default.
535
+ */
536
+ VALUE
537
+ ruby_xml_parser_default_substitute_entities_get(VALUE class) {
538
+ if (xmlSubstituteEntitiesDefaultValue)
539
+ return(Qtrue);
540
+ else
541
+ return(Qfalse);
542
+ }
543
+
544
+
545
+ /*
546
+ * call-seq:
547
+ * XML::Parser.default_substitute_entities = true|false
548
+ *
549
+ * Controls whether parsers perform inline entity substitution
550
+ * (for external entities) by default.
551
+ */
552
+ VALUE
553
+ ruby_xml_parser_default_substitute_entities_set(VALUE class, VALUE bool) {
554
+ if (TYPE(bool) == T_FALSE) {
555
+ xmlSubstituteEntitiesDefault(0);
556
+ return(Qfalse);
557
+ } else {
558
+ xmlSubstituteEntitiesDefault(1);
559
+ return(Qtrue);
560
+ }
561
+ }
562
+
563
+
564
+ /*
565
+ * call-seq:
566
+ * XML::Parser.default_tree_indent_string => "string"
567
+ *
568
+ * Obtain the default string used by parsers to indent the XML tree
569
+ * for output.
570
+ */
571
+ VALUE
572
+ ruby_xml_parser_default_tree_indent_string_get(VALUE class) {
573
+ if (xmlTreeIndentString == NULL)
574
+ return(Qnil);
575
+ else
576
+ return(rb_str_new2(xmlTreeIndentString));
577
+ }
578
+
579
+
580
+ /*
581
+ * call-seq:
582
+ * XML::Parser.default_tree_indent_string = "string"
583
+ *
584
+ * Set the default string used by parsers to indent the XML tree
585
+ * for output.
586
+ */
587
+ VALUE
588
+ ruby_xml_parser_default_tree_indent_string_set(VALUE class, VALUE string) {
589
+ Check_Type(string, T_STRING);
590
+ xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
591
+ return(string);
592
+ }
593
+
594
+
595
+ /*
596
+ * call-seq:
597
+ * XML::Parser.default_validity_checking => (true|false)
598
+ *
599
+ * Determine whether parsers perform XML validation by default.
600
+ */
601
+ VALUE
602
+ ruby_xml_parser_default_validity_checking_get(VALUE class) {
603
+ if (xmlDoValidityCheckingDefaultValue)
604
+ return(Qtrue);
605
+ else
606
+ return(Qfalse);
607
+ }
608
+
609
+
610
+ /*
611
+ * call-seq:
612
+ * XML::Parser.default_validity_checking = true|false
613
+ *
614
+ * Controls whether parsers perform XML validation by default.
615
+ */
616
+ VALUE
617
+ ruby_xml_parser_default_validity_checking_set(VALUE class, VALUE bool) {
618
+ if (TYPE(bool) == T_FALSE) {
619
+ xmlDoValidityCheckingDefaultValue = 0;
620
+ return(Qfalse);
621
+ } else {
622
+ xmlDoValidityCheckingDefaultValue = 1;
623
+ return(Qtrue);
624
+ }
625
+ }
626
+
627
+
628
+ /*
629
+ * call-seq:
630
+ * XML::Parser.default_warnings => (true|false)
631
+ *
632
+ * Determine whether parsers output warnings by default.
633
+ */
634
+ VALUE
635
+ ruby_xml_parser_default_warnings_get(VALUE class) {
636
+ if (xmlGetWarningsDefaultValue)
637
+ return(Qtrue);
638
+ else
639
+ return(Qfalse);
640
+ }
641
+
642
+
643
+ /*
644
+ * call-seq:
645
+ * XML::Parser.default_warnings = true|false
646
+ *
647
+ * Controls whether parsers output warnings by default.
648
+ */
649
+ VALUE
650
+ ruby_xml_parser_default_warnings_set(VALUE class, VALUE bool) {
651
+ if (TYPE(bool) == T_FALSE) {
652
+ xmlGetWarningsDefaultValue = 0;
653
+ return(Qfalse);
654
+ } else {
655
+ xmlGetWarningsDefaultValue = 1;
656
+ return(Qtrue);
657
+ }
658
+ }
659
+
660
+
661
+ /*
662
+ * call-seq:
663
+ * XML::Parser.default_compression => (true|false)
664
+ *
665
+ * Determine whether parsers use Zlib compression by default
666
+ * (requires libxml to be compiled with Zlib support).
667
+ */
668
+ VALUE
669
+ ruby_xml_parser_default_compression_get(VALUE class) {
670
+ #ifdef HAVE_ZLIB_H
671
+ return(INT2FIX(xmlGetCompressMode()));
672
+ #else
673
+ rb_warn("libxml was compiled without zlib support");
674
+ return(Qfalse);
675
+ #endif
676
+ }
677
+
678
+
679
+ /*
680
+ * call-seq:
681
+ * XML::Parser.default_compression = true|false
682
+ *
683
+ * Controls whether parsers use Zlib compression by default
684
+ * (requires libxml to be compiled with Zlib support).
685
+ */
686
+ VALUE
687
+ ruby_xml_parser_default_compression_set(VALUE class, VALUE num) {
688
+ #ifdef HAVE_ZLIB_H
689
+ Check_Type(num, T_FIXNUM);
690
+ xmlSetCompressMode(FIX2INT(num));
691
+ return(num);
692
+ #else
693
+ rb_warn("libxml was compiled without zlib support");
694
+ return(Qfalse);
695
+ #endif
696
+ }
697
+
698
+
699
+ /*
700
+ * call-seq:
701
+ * XML::Parser.features => ["feature", ..., "feature"]
702
+ *
703
+ * Obtains an array of strings representing features supported
704
+ * (and enabled) by the installed libxml.
705
+ */
706
+ VALUE
707
+ ruby_xml_parser_features(VALUE class) {
708
+ VALUE arr, str;
709
+ int i, len = MAX_LIBXML_FEATURES_LEN;
710
+ char **list = NULL;
711
+
712
+ list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
713
+ MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
714
+
715
+ arr = rb_ary_new();
716
+ if (xmlGetFeaturesList(&len, (const char **)list) == -1)
717
+ return Qnil;
718
+
719
+ for (i = 0; i < len; i++) {
720
+ str = rb_str_new2((const char *)list[i]);
721
+ rb_gc_unregister_address(&str);
722
+ rb_ary_push(arr, str);
723
+ }
724
+
725
+ if (len == MAX_LIBXML_FEATURES_LEN)
726
+ 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");
727
+
728
+ ruby_xfree(list);
729
+ return(arr);
730
+ }
731
+
732
+
733
+ /*
734
+ * call-seq:
735
+ * parser.filename => "filename"
736
+ *
737
+ * Obtain the filename this parser will read from.
738
+ */
739
+ VALUE
740
+ ruby_xml_parser_filename_get(VALUE self) {
741
+ ruby_xml_parser *rxp;
742
+ rx_file_data *data;
743
+
744
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
745
+ if (rxp->data == NULL)
746
+ return(Qnil);
747
+
748
+ if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE)
749
+ return(Qnil);
750
+
751
+ data = (rx_file_data *)rxp->data;
752
+ return(data->filename);
753
+ }
754
+
755
+
756
+ /*
757
+ * call-seq:
758
+ * parser.filename = "filename"
759
+ *
760
+ * Set the filename this parser will read from.
761
+ */
762
+ VALUE
763
+ ruby_xml_parser_filename_set(VALUE self, VALUE filename) {
764
+ ruby_xml_parser *rxp;
765
+ ruby_xml_parser_context *rxpc;
766
+ rx_file_data *data;
767
+
768
+ Check_Type(filename, T_STRING);
769
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
770
+
771
+ if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
772
+ if (rxp->data != NULL)
773
+ rb_fatal("crap, this should be null");
774
+
775
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
776
+ data = ALLOC(rx_file_data);
777
+ rxp->data = data;
778
+ } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE) {
779
+ return(Qnil);
780
+ }
781
+
782
+ rxp->ctxt = ruby_xml_parser_context_new3();
783
+ data = (rx_file_data *)rxp->data;
784
+ data->filename = filename;
785
+
786
+ Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
787
+ rxpc->ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
788
+ if (rxpc->ctxt == NULL)
789
+ rb_raise(rb_eIOError, filename);
790
+
791
+ return(data->filename);
792
+ }
793
+
794
+
795
+ void
796
+ ruby_xml_parser_free(ruby_xml_parser *rxp) {
797
+ void *data;
798
+
799
+ switch(rxp->data_type) {
800
+ case RUBY_LIBXML_SRC_TYPE_NULL:
801
+ break;
802
+ case RUBY_LIBXML_SRC_TYPE_FILE:
803
+ data = (void *)(rx_file_data *)rxp->data;
804
+ ruby_xfree((rx_file_data *)data);
805
+ break;
806
+ case RUBY_LIBXML_SRC_TYPE_STRING:
807
+ data = (void *)(rx_string_data *)rxp->data;
808
+ ruby_xfree((rx_string_data *)data);
809
+ break;
810
+ case RUBY_LIBXML_SRC_TYPE_IO:
811
+ data = (void *)(rx_io_data *)rxp->data;
812
+ ruby_xfree((rx_io_data *)data);
813
+ break;
814
+ default:
815
+ rb_fatal("Unknown data type, %d", rxp->data_type);
816
+ }
817
+
818
+ ruby_xfree(rxp);
819
+ }
820
+
821
+
822
+ /*
823
+ * call-seq:
824
+ * XML::Parser.indent_tree_output => (true|false)
825
+ *
826
+ * Determines whether XML output will be indented
827
+ * (using the string supplied to +default_indent_tree_string+)
828
+ */
829
+ VALUE
830
+ ruby_xml_parser_indent_tree_output_get(VALUE class) {
831
+ if (xmlIndentTreeOutput)
832
+ return(Qtrue);
833
+ else
834
+ return(Qfalse);
835
+ }
836
+
837
+
838
+ /*
839
+ * call-seq:
840
+ * XML::Parser.indent_tree_output = true|false
841
+ *
842
+ * Controls whether XML output will be indented
843
+ * (using the string supplied to +default_indent_tree_string+)
844
+ */
845
+ VALUE
846
+ ruby_xml_parser_indent_tree_output_set(VALUE class, VALUE bool) {
847
+ if (TYPE(bool) == T_TRUE) {
848
+ xmlIndentTreeOutput = 1;
849
+ return(Qtrue);
850
+ } else if (TYPE(bool) == T_FALSE) {
851
+ xmlIndentTreeOutput = 0;
852
+ return(Qfalse);
853
+ } else {
854
+ rb_raise(rb_eArgError, "invalid argument, must be boolean");
855
+ }
856
+ }
857
+
858
+
859
+ /*
860
+ * call-seq:
861
+ * parser.io => IO
862
+ *
863
+ * Obtain the IO instance this parser works with.
864
+ */
865
+ VALUE
866
+ ruby_xml_parser_io_get(VALUE self, VALUE io) {
867
+ ruby_xml_parser *rxp;
868
+ rx_io_data *data;
869
+
870
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
871
+
872
+ if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL ||
873
+ rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO ||
874
+ rxp->data == NULL)
875
+ return(Qnil);
876
+
877
+ data = (rx_io_data *)rxp->data;
878
+
879
+ return(data->io);
880
+ }
881
+
882
+
883
+ /*
884
+ * call-seq:
885
+ * parser.io = IO
886
+ *
887
+ * Set the IO instance this parser works with.
888
+ */
889
+ VALUE
890
+ ruby_xml_parser_io_set(VALUE self, VALUE io) {
891
+ ruby_xml_parser *rxp;
892
+ ruby_xml_parser_context *rxpc;
893
+ rx_io_data *data;
894
+ OpenFile *fptr;
895
+ FILE *f;
896
+
897
+ #ifdef _WIN32
898
+ rb_raise(rb_eRuntimeError, "Setting an io buffer is not supported on Windows");
899
+ #endif
900
+
901
+ if (!rb_obj_is_kind_of(io, rb_cIO))
902
+ rb_raise(rb_eTypeError, "need an IO object");
903
+
904
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
905
+
906
+ if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
907
+ if (rxp->data != NULL)
908
+ rb_fatal("crap, this should be null");
909
+
910
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
911
+ data = ALLOC(rx_io_data);
912
+ rxp->data = data;
913
+ } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO) {
914
+ return(Qnil);
915
+ }
916
+
917
+ rxp->ctxt = ruby_xml_parser_context_new3();
918
+ data = (rx_io_data *)rxp->data;
919
+ data->io = io;
920
+
921
+ GetOpenFile(io, fptr);
922
+ rb_io_check_readable(fptr);
923
+ f = GetWriteFile(fptr);
924
+
925
+ Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
926
+ rxpc->ctxt = xmlCreateIOParserCtxt(NULL, NULL,
927
+ (xmlInputReadCallback) ctxtRead,
928
+ NULL, f, XML_CHAR_ENCODING_NONE);
929
+ if (!rxpc->ctxt)
930
+ rb_sys_fail(0);
931
+
932
+ return(data->io);
933
+ }
934
+
935
+
936
+ void
937
+ ruby_xml_parser_mark(ruby_xml_parser *rxp) {
938
+ if (rxp == NULL) return;
939
+ if (!NIL_P(rxp->ctxt)) rb_gc_mark(rxp->ctxt);
940
+
941
+ ruby_xml_state_marker();
942
+
943
+ switch(rxp->data_type) {
944
+ case RUBY_LIBXML_SRC_TYPE_NULL:
945
+ break;
946
+ case RUBY_LIBXML_SRC_TYPE_FILE:
947
+ if (!NIL_P(((rx_file_data *)rxp->data)->filename))
948
+ rb_gc_mark(((rx_file_data *)rxp->data)->filename);
949
+ break;
950
+ case RUBY_LIBXML_SRC_TYPE_STRING:
951
+ if (!NIL_P(((rx_string_data *)rxp->data)->str))
952
+ rb_gc_mark(((rx_string_data *)rxp->data)->str);
953
+ break;
954
+ case RUBY_LIBXML_SRC_TYPE_IO:
955
+ if (!NIL_P(((rx_io_data *)rxp->data)->io))
956
+ rb_gc_mark(((rx_io_data *)rxp->data)->io);
957
+ break;
958
+ default:
959
+ rb_fatal("unknown datatype: %d", rxp->data_type);
960
+ }
961
+ }
962
+
963
+
964
+ /*
965
+ * call-seq:
966
+ * XML::Parser.memory_dump => (true|false)
967
+ *
968
+ * Perform a parser memory dump (requires memory debugging
969
+ * support in libxml).
970
+ */
971
+ VALUE
972
+ ruby_xml_parser_memory_dump(VALUE self) {
973
+ #ifdef DEBUG_MEMORY_LOCATION
974
+ xmlMemoryDump();
975
+ return(Qtrue);
976
+ #else
977
+ rb_warn("libxml was compiled without memory debugging support");
978
+ return(Qfalse);
979
+ #endif
980
+ }
981
+
982
+
983
+ /*
984
+ * call-seq:
985
+ * XML::Parser.memory_used => num_bytes
986
+ *
987
+ * Perform a parser memory dump (requires memory debugging
988
+ * support in libxml).
989
+ */
990
+ VALUE
991
+ ruby_xml_parser_memory_used(VALUE self) {
992
+ #ifdef DEBUG_MEMORY_LOCATION
993
+ return(INT2NUM(xmlMemUsed()));
994
+ #else
995
+ rb_warn("libxml was compiled without memory debugging support");
996
+ return(Qfalse);
997
+ #endif
998
+ }
999
+
1000
+
1001
+ /*
1002
+ * call-seq:
1003
+ * XML::Parser.new => parser
1004
+ *
1005
+ * Create a new parser instance with no pre-determined source.
1006
+ */
1007
+ VALUE
1008
+ ruby_xml_parser_new(VALUE class) {
1009
+ ruby_xml_parser *rxp;
1010
+ VALUE r;
1011
+
1012
+ r=Data_Make_Struct(class,
1013
+ ruby_xml_parser,
1014
+ ruby_xml_parser_mark,
1015
+ ruby_xml_parser_free,
1016
+ rxp);
1017
+
1018
+ rxp->ctxt = Qnil;
1019
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
1020
+ rxp->data = NULL;
1021
+ rxp->parsed = 0;
1022
+
1023
+ return r;
1024
+ }
1025
+
1026
+
1027
+ /*
1028
+ * call-seq:
1029
+ * XML::Parser.file => parser
1030
+ *
1031
+ * Create a new parser instance that will read the specified file.
1032
+ */
1033
+ VALUE
1034
+ ruby_xml_parser_new_file(VALUE class, VALUE filename) {
1035
+ VALUE obj;
1036
+ ruby_xml_parser *rxp;
1037
+ rx_file_data *data;
1038
+
1039
+ obj = ruby_xml_parser_new(class);
1040
+ Data_Get_Struct(obj, ruby_xml_parser, rxp);
1041
+
1042
+ data = ALLOC(rx_file_data);
1043
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
1044
+ rxp->data = data;
1045
+
1046
+ ruby_xml_parser_filename_set(obj, filename);
1047
+
1048
+ return(obj);
1049
+ }
1050
+
1051
+
1052
+ /*
1053
+ * call-seq:
1054
+ * XML::Parser.io => parser
1055
+ *
1056
+ * Create a new parser instance that will read from the
1057
+ * specified IO object.
1058
+ */
1059
+ VALUE
1060
+ ruby_xml_parser_new_io(VALUE class, VALUE io) {
1061
+ VALUE obj;
1062
+ ruby_xml_parser *rxp;
1063
+ rx_io_data *data;
1064
+
1065
+ obj = ruby_xml_parser_new(class);
1066
+ Data_Get_Struct(obj, ruby_xml_parser, rxp);
1067
+
1068
+ data = ALLOC(rx_io_data);
1069
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
1070
+ rxp->data = data;
1071
+
1072
+ ruby_xml_parser_io_set(obj, io);
1073
+
1074
+ return(obj);
1075
+ }
1076
+
1077
+
1078
+ /*
1079
+ * call-seq:
1080
+ * XML::Parser.string => parser
1081
+ *
1082
+ * Create a new parser instance that will parse the given
1083
+ * string.
1084
+ */
1085
+ VALUE
1086
+ ruby_xml_parser_new_string(VALUE class, VALUE str) {
1087
+ VALUE obj;
1088
+ ruby_xml_parser *rxp;
1089
+ rx_string_data *data;
1090
+
1091
+ obj = ruby_xml_parser_new(class);
1092
+ Data_Get_Struct(obj, ruby_xml_parser, rxp);
1093
+
1094
+ data = ALLOC(rx_string_data);
1095
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1096
+ rxp->data = data;
1097
+
1098
+ ruby_xml_parser_str_set(obj, str);
1099
+
1100
+ return(obj);
1101
+ }
1102
+
1103
+
1104
+ /*
1105
+ * call-seq:
1106
+ * parser.parse => document
1107
+ *
1108
+ * Parse the input XML and create an XML::Document with
1109
+ * it's content. If an error occurs, XML::Parser::ParseError
1110
+ * is thrown.
1111
+ */
1112
+ VALUE
1113
+ ruby_xml_parser_parse(VALUE self) {
1114
+ ruby_xml_parser *rxp;
1115
+ ruby_xml_parser_context *rxpc;
1116
+ xmlDocPtr xdp;
1117
+ VALUE doc;
1118
+
1119
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
1120
+
1121
+ switch (rxp->data_type) {
1122
+ case RUBY_LIBXML_SRC_TYPE_NULL:
1123
+ return(Qnil);
1124
+ case RUBY_LIBXML_SRC_TYPE_STRING:
1125
+ case RUBY_LIBXML_SRC_TYPE_FILE:
1126
+ case RUBY_LIBXML_SRC_TYPE_IO:
1127
+ Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1128
+ if (xmlParseDocument(rxpc->ctxt) == -1) {
1129
+ xmlFreeDoc(rxpc->ctxt->myDoc);
1130
+ rb_raise(eXMLParserParseError, "Document didn't parse");
1131
+ }
1132
+
1133
+ xdp = rxpc->ctxt->myDoc;
1134
+ if (!rxpc->ctxt->wellFormed) {
1135
+ xmlFreeDoc(xdp);
1136
+ xdp = NULL;
1137
+ rb_raise(eXMLParserParseError, "Document did not contain well-formed XML");
1138
+ } else {
1139
+ rxp->parsed = 1;
1140
+ }
1141
+
1142
+ doc = ruby_xml_document_wrap(xdp);
1143
+ break;
1144
+ default:
1145
+ rb_fatal("Unknown data type, %d", rxp->data_type);
1146
+ }
1147
+
1148
+ return(doc);
1149
+ }
1150
+
1151
+
1152
+ /*
1153
+ * call-seq:
1154
+ * parser.context => context
1155
+ *
1156
+ * Obtain the XML::Parser::Context associated with this
1157
+ * parser.
1158
+ */
1159
+ VALUE
1160
+ ruby_xml_parser_context_get(VALUE self) {
1161
+ ruby_xml_parser *rxp;
1162
+
1163
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
1164
+ if (rxp->ctxt == Qnil)
1165
+ return(Qnil);
1166
+ else
1167
+ return(rxp->ctxt);
1168
+ }
1169
+
1170
+
1171
+ /*
1172
+ * call-seq:
1173
+ * parser.string => "string"
1174
+ *
1175
+ * Obtain the string this parser works with.
1176
+ */
1177
+ VALUE
1178
+ ruby_xml_parser_str_get(VALUE self) {
1179
+ ruby_xml_parser *rxp;
1180
+ rx_string_data *data;
1181
+
1182
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
1183
+ if (rxp->data == NULL || rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING)
1184
+ return(Qnil);
1185
+
1186
+ data = (rx_string_data *)rxp->data;
1187
+ return(data->str);
1188
+ }
1189
+
1190
+
1191
+ /*
1192
+ * call-seq:
1193
+ * parser.string = "string"
1194
+ *
1195
+ * Set the string this parser works with.
1196
+ */
1197
+ VALUE
1198
+ ruby_xml_parser_str_set(VALUE self, VALUE str) {
1199
+ ruby_xml_parser *rxp;
1200
+ ruby_xml_parser_context *rxpc;
1201
+ rx_string_data *data;
1202
+
1203
+ Check_Type(str, T_STRING);
1204
+ Data_Get_Struct(self, ruby_xml_parser, rxp);
1205
+
1206
+ if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
1207
+ rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1208
+ data = ALLOC(rx_string_data);
1209
+ rxp->data = data;
1210
+ } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING) {
1211
+ return(Qnil);
1212
+ }
1213
+
1214
+ rxp->ctxt = ruby_xml_parser_context_new3();
1215
+ data = (rx_string_data *)rxp->data;
1216
+ data->str = str;
1217
+
1218
+ Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1219
+ rxpc->ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data->str), RSTRING_LEN(data->str));
1220
+ if ( rxpc->ctxt == NULL )
1221
+ rb_raise(eXMLParserParseError,"Cannot initialize parser with given string (maybe empty?)");
1222
+
1223
+ return(data->str);
1224
+ }
1225
+
1226
+ /*
1227
+ * call-seq:
1228
+ * XML::Parser.register_error_handler(lambda { |msg| ... }) => old_handler
1229
+ * XML::Parser.register_error_handler(nil) => old_handler
1230
+ *
1231
+ * Register the attached block as the handler for parser errors.
1232
+ * A message describing parse errors is passed to the block.
1233
+ * Libxml passes error messages to the handler in parts, one per call.
1234
+ * A typical error results in six calls to this proc, with arguments:
1235
+ *
1236
+ * "Entity: line 1: ",
1237
+ * "parser ",
1238
+ * "error : ",
1239
+ * "Opening and ending tag mismatch: foo line 1 and foz\n",
1240
+ * "<foo><bar/></foz>\n",
1241
+ * " ^\n"
1242
+ *
1243
+ * Note that the error handler is shared by all threads.
1244
+ */
1245
+ VALUE
1246
+ ruby_xml_parser_registerErrorHandler(VALUE self, VALUE proc) {
1247
+ VALUE old_block = libxml_xmlRubyErrorProc;
1248
+ libxml_xmlRubyErrorProc = proc;
1249
+ return(old_block);
1250
+ }
1251
+
1252
+ static void
1253
+ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
1254
+ {
1255
+ va_list ap;
1256
+ char str[1000];
1257
+ VALUE rstr;
1258
+
1259
+ if (libxml_xmlRubyErrorProc == Qnil) {
1260
+ va_start(ap, msg);
1261
+ vfprintf(stderr, msg, ap);
1262
+ va_end(ap);
1263
+ } else {
1264
+ va_start(ap, msg);
1265
+ if (vsnprintf(str, 999, msg, ap) >= 998) str[999] = 0;
1266
+ va_end(ap);
1267
+
1268
+ rstr = rb_str_new2(str);
1269
+ rb_funcall2(libxml_xmlRubyErrorProc, id_call, 1, &rstr);
1270
+ }
1271
+ }
1272
+
1273
+ /* #define RUBY_XML_PARSER_ENABLED_INIT(func, method) \
1274
+ rb_define_singleton_method(cXMLParser, method, \
1275
+ ruby_xml_parser_enabled_##func##_q, 0); */
1276
+
1277
+ ///#include "cbg.c"
1278
+ ///
1279
+ ///VALUE ruby_register_deb(VALUE self) {
1280
+ /// deb_register_cbg();
1281
+ /// return(Qtrue);
1282
+ ///}
1283
+
1284
+ // Rdoc needs to know
1285
+ #ifdef RDOC_NEVER_DEFINED
1286
+ mXML = rb_define_module("XML");
1287
+ #endif
1288
+
1289
+ void
1290
+ ruby_init_parser(void) {
1291
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
1292
+ eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
1293
+ rb_eRuntimeError);
1294
+
1295
+ /* Constants */
1296
+ rb_define_const(cXMLParser, "LIBXML_VERSION",
1297
+ rb_str_new2(LIBXML_DOTTED_VERSION));
1298
+ rb_define_const(cXMLParser, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
1299
+ rb_define_const(cXMLParser, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
1300
+
1301
+ /* Question-esqe Class Methods */
1302
+ /* RDoc won't have them defined by a macro... */
1303
+ rb_define_singleton_method(cXMLParser, "enabled_automata?",
1304
+ ruby_xml_parser_enabled_automata_q, 0);
1305
+ rb_define_singleton_method(cXMLParser, "enabled_c14n?",
1306
+ ruby_xml_parser_enabled_c14n_q, 0);
1307
+ rb_define_singleton_method(cXMLParser, "enabled_catalog?",
1308
+ ruby_xml_parser_enabled_catalog_q, 0);
1309
+ rb_define_singleton_method(cXMLParser, "enabled_debug?",
1310
+ ruby_xml_parser_enabled_debug_q, 0);
1311
+ rb_define_singleton_method(cXMLParser, "enabled_docbook?",
1312
+ ruby_xml_parser_enabled_docbook_q, 0);
1313
+ rb_define_singleton_method(cXMLParser, "enabled_ftp?",
1314
+ ruby_xml_parser_enabled_ftp_q, 0);
1315
+ rb_define_singleton_method(cXMLParser, "enabled_http?",
1316
+ ruby_xml_parser_enabled_http_q, 0);
1317
+ rb_define_singleton_method(cXMLParser, "enabled_html?",
1318
+ ruby_xml_parser_enabled_html_q, 0);
1319
+ rb_define_singleton_method(cXMLParser, "enabled_iconv?",
1320
+ ruby_xml_parser_enabled_iconv_q, 0);
1321
+ rb_define_singleton_method(cXMLParser, "enabled_memory_debug?",
1322
+ ruby_xml_parser_enabled_memory_debug_location_q, 0);
1323
+ rb_define_singleton_method(cXMLParser, "enabled_regexp?",
1324
+ ruby_xml_parser_enabled_regexp_q, 0);
1325
+ rb_define_singleton_method(cXMLParser, "enabled_schemas?",
1326
+ ruby_xml_parser_enabled_schemas_q, 0);
1327
+ rb_define_singleton_method(cXMLParser, "enabled_thread?",
1328
+ ruby_xml_parser_enabled_thread_q, 0);
1329
+ rb_define_singleton_method(cXMLParser, "enabled_unicode?",
1330
+ ruby_xml_parser_enabled_unicode_q, 0);
1331
+ rb_define_singleton_method(cXMLParser, "enabled_xinclude?",
1332
+ ruby_xml_parser_enabled_xinclude_q, 0);
1333
+ rb_define_singleton_method(cXMLParser, "enabled_xpath?",
1334
+ ruby_xml_parser_enabled_xpath_q, 0);
1335
+ rb_define_singleton_method(cXMLParser, "enabled_xpointer?",
1336
+ ruby_xml_parser_enabled_xpointer_q, 0);
1337
+ rb_define_singleton_method(cXMLParser, "enabled_zlib?",
1338
+ ruby_xml_parser_enabled_zlib_q, 0);
1339
+
1340
+ /* Other Class Methods */
1341
+ /// rb_define_singleton_method(cXMLParser, "register_deb",
1342
+ /// ruby_register_deb, 0);
1343
+
1344
+ // TODO Maybe a set of 'xxxx_catalog' aliases might be more Ruby?
1345
+ rb_define_singleton_method(cXMLParser, "catalog_dump",
1346
+ ruby_xml_parser_catalog_dump, 0);
1347
+ rb_define_singleton_method(cXMLParser, "catalog_remove",
1348
+ ruby_xml_parser_catalog_remove, 1);
1349
+ rb_define_singleton_method(cXMLParser, "check_lib_versions",
1350
+ ruby_xml_parser_check_lib_versions, 0);
1351
+
1352
+ // TODO should this be debug_entities_q / debug_entities_set?
1353
+ // should all these default attribute pairs work that way?
1354
+ rb_define_singleton_method(cXMLParser, "debug_entities",
1355
+ ruby_xml_parser_debug_entities_get, 0);
1356
+ rb_define_singleton_method(cXMLParser, "debug_entities=",
1357
+ ruby_xml_parser_debug_entities_set, 1);
1358
+ rb_define_singleton_method(cXMLParser, "default_compression",
1359
+ ruby_xml_parser_default_compression_get, 0);
1360
+ rb_define_singleton_method(cXMLParser, "default_compression=",
1361
+ ruby_xml_parser_default_compression_set, 1);
1362
+ rb_define_singleton_method(cXMLParser, "default_keep_blanks",
1363
+ ruby_xml_parser_default_keep_blanks_get, 0);
1364
+ rb_define_singleton_method(cXMLParser, "default_keep_blanks=",
1365
+ ruby_xml_parser_default_keep_blanks_set, 1);
1366
+ rb_define_singleton_method(cXMLParser, "default_load_external_dtd",
1367
+ ruby_xml_parser_default_load_external_dtd_get, 0);
1368
+ rb_define_singleton_method(cXMLParser, "default_load_external_dtd=",
1369
+ ruby_xml_parser_default_load_external_dtd_set, 1);
1370
+ rb_define_singleton_method(cXMLParser, "default_line_numbers",
1371
+ ruby_xml_parser_default_line_numbers_get, 0);
1372
+ rb_define_singleton_method(cXMLParser, "default_line_numbers=",
1373
+ ruby_xml_parser_default_line_numbers_set, 1);
1374
+ rb_define_singleton_method(cXMLParser, "default_pedantic_parser",
1375
+ ruby_xml_parser_default_pedantic_parser_get, 0);
1376
+ rb_define_singleton_method(cXMLParser, "default_pedantic_parser=",
1377
+ ruby_xml_parser_default_pedantic_parser_set, 1);
1378
+ rb_define_singleton_method(cXMLParser, "default_substitute_entities",
1379
+ ruby_xml_parser_default_substitute_entities_get, 0);
1380
+ rb_define_singleton_method(cXMLParser, "default_substitute_entities=",
1381
+ ruby_xml_parser_default_substitute_entities_set, 1);
1382
+ rb_define_singleton_method(cXMLParser, "default_tree_indent_string",
1383
+ ruby_xml_parser_default_tree_indent_string_get, 0);
1384
+ rb_define_singleton_method(cXMLParser, "default_tree_indent_string=",
1385
+ ruby_xml_parser_default_tree_indent_string_set, 1);
1386
+ rb_define_singleton_method(cXMLParser, "default_validity_checking",
1387
+ ruby_xml_parser_default_validity_checking_get, 0);
1388
+ rb_define_singleton_method(cXMLParser, "default_validity_checking=",
1389
+ ruby_xml_parser_default_validity_checking_set, 1);
1390
+ rb_define_singleton_method(cXMLParser, "default_warnings",
1391
+ ruby_xml_parser_default_warnings_get, 0);
1392
+ rb_define_singleton_method(cXMLParser, "default_warnings=",
1393
+ ruby_xml_parser_default_warnings_set, 1);
1394
+
1395
+ rb_define_singleton_method(cXMLParser, "features", ruby_xml_parser_features, 0);
1396
+ rb_define_singleton_method(cXMLParser, "file", ruby_xml_parser_new_file, 1);
1397
+ rb_define_singleton_method(cXMLParser, "indent_tree_output", ruby_xml_parser_indent_tree_output_get, 0);
1398
+ rb_define_singleton_method(cXMLParser, "indent_tree_output=", ruby_xml_parser_indent_tree_output_set, 1);
1399
+ rb_define_singleton_method(cXMLParser, "io", ruby_xml_parser_new_io, 1);
1400
+ rb_define_singleton_method(cXMLParser, "memory_dump",
1401
+ ruby_xml_parser_memory_dump, 0);
1402
+ rb_define_singleton_method(cXMLParser, "memory_used",
1403
+ ruby_xml_parser_memory_used, 0);
1404
+ rb_define_singleton_method(cXMLParser, "new", ruby_xml_parser_new, 0);
1405
+ rb_define_singleton_method(cXMLParser, "string", ruby_xml_parser_new_string, 1);
1406
+ rb_define_singleton_method(cXMLParser, "register_error_handler", ruby_xml_parser_registerErrorHandler, 1);
1407
+ rb_define_method(cXMLParser, "filename", ruby_xml_parser_filename_get, 0);
1408
+ rb_define_method(cXMLParser, "filename=", ruby_xml_parser_filename_set, 1);
1409
+ rb_define_method(cXMLParser, "io", ruby_xml_parser_io_get, 0);
1410
+ rb_define_method(cXMLParser, "io=", ruby_xml_parser_io_set, 1);
1411
+ rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
1412
+ rb_define_method(cXMLParser, "context", ruby_xml_parser_context_get, 0);
1413
+ rb_define_method(cXMLParser, "string", ruby_xml_parser_str_get, 0);
1414
+ rb_define_method(cXMLParser, "string=", ruby_xml_parser_str_set, 1);
1415
+
1416
+ // set up error handling
1417
+ xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1418
+ xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1419
+
1420
+ // Ruby needs to know about this even though it's not exported, otherwise
1421
+ // our error proc might get garbage collected.
1422
+ rb_global_variable(&libxml_xmlRubyErrorProc);
1423
+
1424
+ id_call = rb_intern("call");
1425
+ }