libxml-ruby 2.8.0 → 2.9.0

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