/usr/lib/perl5/XML/SAX/ExpatXS.pm is in libxml-sax-expatxs-perl 1.33-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | package XML::SAX::ExpatXS;
use strict;
use vars qw($VERSION @ISA);
use XML::SAX::ExpatXS::Encoding;
use XML::SAX::ExpatXS::Preload;
use XML::SAX::Base;
use DynaLoader ();
use Carp;
use IO::File;
$VERSION = '1.33';
@ISA = qw(DynaLoader XML::SAX::Base XML::SAX::ExpatXS::Preload);
XML::SAX::ExpatXS->bootstrap($VERSION);
my @features = (
['http://xml.org/sax/features/namespaces', 1],
['http://xml.org/sax/features/external-general-entities', 1],
['http://xml.org/sax/features/external-parameter-entities', 0],
['http://xml.org/sax/features/xmlns-uris', 0],
['http://xmlns.perl.org/sax/xmlns-uris', 1],
['http://xmlns.perl.org/sax/version-2.1', 1],
['http://xmlns.perl.org/sax/join-character-data', 1],
['http://xmlns.perl.org/sax/ns-attributes', 1],
['http://xmlns.perl.org/sax/locator', 1],
['http://xmlns.perl.org/sax/recstring', 0]
);
my @supported_features = map($_->[0], @features);
#------------------------------------------------------------
# API methods
#------------------------------------------------------------
sub new {
my $proto = shift;
my $options = ($#_ == 0) ? shift : { @_ };
foreach (@features) {
$options->{Features}->{$_->[0]} = $_->[1];
}
$options->{ExpatVersion} = ExpatVersion();
return $proto->SUPER::new($options);
}
sub get_feature {
my ($self, $feat) = @_;
if (exists $self->{Features}->{$feat}) {
return $self->{Features}->{$feat};
}
else {
return $self->SUPER::get_feature($feat);
}
}
sub set_feature {
my ($self, $feat, $val) = @_;
if (exists $self->{Features}->{$feat}) {
return $self->{Features}->{$feat} = $val;
}
else {
return $self->SUPER::set_feature($feat, $val);
}
}
sub get_features {
my $self = shift;
return %{$self->{Features}};
}
sub supported_features {
my $self = shift;
return @supported_features;
}
#------------------------------------------------------------
# internal methods
#------------------------------------------------------------
sub _parse_characterstream {
my ($self, $fh) = @_;
$self->{ParseOptions}->{ParseFunc} = \&ParseStream;
$self->{ParseOptions}->{ParseFuncParam} = $fh;
$self->_parse;
}
sub _parse_bytestream {
my ($self, $fh) = @_;
$self->{ParseOptions}->{ParseFunc} = \&ParseStream;
$self->{ParseOptions}->{ParseFuncParam} = $fh;
$self->_parse;
}
sub _parse_string {
my ($self, $str) = @_;
$self->{ParseOptions}->{ParseFunc} = \&ParseString;
$self->{ParseOptions}->{ParseFuncParam} = $str;
$self->_parse;
}
sub _parse_systemid {
my ($self, $uri) = @_;
my $fh = IO::File->new($uri) or croak "ExpatXS: Can't open $uri ($!)";
$self->{ParseOptions}->{ParseFunc} = \&ParseStream;
$self->{ParseOptions}->{ParseFuncParam} = $fh;
$self->_parse;
}
sub _parse {
my $self = shift;
my $args = bless $self->{ParseOptions}, ref($self);
delete $args->{ParseOptions};
# copy handlers over
$args->{Handler} = $self->{Handler};
$args->{DocumentHandler} = $self->{DocumentHandler};
$args->{ContentHandler} = $self->{ContentHandler};
$args->{DTDHandler} = $self->{DTDHandler};
$args->{LexicalHandler} = $self->{LexicalHandler};
$args->{DeclHandler} = $self->{DeclHandler};
$args->{ErrorHandler} = $self->{ErrorHandler};
$args->{EntityResolver} = $self->{EntityResolver};
$args->{_State_} = 0;
$args->{Context} = [];
$args->{ErrorMessage} ||= '';
$args->{Namespace_Stack} = [[ xml => 'http://www.w3.org/XML/1998/namespace' ]];
$args->{Parser} = ParserCreate($args,
$args->{Source}{Encoding}
|| $args->{ProtocolEncoding},
1);
$args->{Locator} = GetLocator($args->{Parser},
$args->{Source}{PublicId} || '',
$args->{Source}{SystemId} || '',
$args->{Source}{Encoding} || '',
);
$args->{RecognizedString} = GetRecognizedString($args->{Parser});
$args->{ExternEnt} = GetExternEnt($args->{Parser});
$args->{Methods} = {};
$args->get_start_element();
$args->get_end_element();
$args->get_characters();
$args->get_comment();
# the most common handlers are available as refs
SetCallbacks($args->{Parser},
$args->{Methods}->{start_element},
$args->{Methods}->{end_element},
$args->{Methods}->{characters},
$args->{Methods}->{comment},
);
$args->set_document_locator($args->{Locator});
$args->start_document({});
my $result;
$result = $args->{ParseFunc}->($args->{Parser}, $args->{ParseFuncParam});
ParserFree($args->{Parser});
my $rv = $args->end_document({}); # end_document is still called on error
croak($args->{ErrorMessage}) unless $result;
return $rv;
}
sub _get_external_entity {
my ($self, $base, $sysid, $pubid) = @_;
# resolving with the base URI
if ($base and $sysid and $sysid !~ /^[a-zA-Z]+[a-zA-Z\d\+\-\.]*:/) {
$base =~ s/[^\/]+$//;
$sysid = $base . $sysid;
}
# user defined resolution
my $src = $self->resolve_entity({PublicId => $pubid,
SystemId => $sysid});
my $fh;
my $result;
my $string;
if (ref($src) eq 'CODE') {
$fh = IO::File->new($sysid)
or croak("Can't open external entity: $sysid\n");
} elsif (ref($src) eq 'HASH') {
if (defined $src->{CharacterStream}) {
$fh = $src->{CharacterStream};
} elsif (defined $src->{ByteStream}) {
$fh = $src->{ByteStream};
} elsif (defined $src->{String}) {
$result = $src->{String};
$string = 1;
} else {
$fh = IO::File->new($src->{SystemId})
or croak("Can't open external entity: $src->{SystemId}\n");
}
} else {
croak ("Invalid object returned by EntityResolver: $src\n");
}
unless ($string) {
local $/;
undef $/;
$result = <$fh>;
close($fh);
}
return $result;
}
sub _get_handler_methods {
my $self = shift;
}
1;
__END__
=head1 NAME
XML::SAX::ExpatXS - Perl SAX 2 XS extension to Expat parser
=head1 SYNOPSIS
use XML::SAX::ExpatXS;
$handler = MyHandler->new();
$parser = XML::SAX::ExpatXS->new( Handler => $handler );
$parser->parse_uri($uri);
#or
$parser->parse_string($xml);
=head1 DESCRIPTION
XML::SAX::ExpatXS is a direct XS extension to Expat XML parser. It implements
Perl SAX 2.1 interface. See http://perl-xml.sourceforge.net/perl-sax/ for
Perl SAX API description. Any deviations from the Perl SAX 2.1 specification
are considered as bugs.
=head2 Features
The parser behavior can be changed by setting features.
$parser->set_feature(FEATURE, VALUE);
XML::SAX::ExpatXS provides these adjustable features:
=over
=item C<http://xmlns.perl.org/sax/join-character-data>
Consequent character data are joined (1, default) or not (0).
=item C<http://xmlns.perl.org/sax/ns-attributes>
Namespace attributes are reported as common attributes (1, default) or not (0).
=item C<http://xmlns.perl.org/sax/xmlns-uris>
When set on, xmlns and xmlns:* attributes are put into namespaces in a Perl SAX
traditional way; xmlns attributes are in no namespace while xmlns:* attributes
are in the C<http://www.w3.org/2000/xmlns/> namespace. This feature is set to 1
by default.
=item C<http://xml.org/sax/features/xmlns-uris>
This feature applies if and only if the C<http://xmlns.perl.org/sax/xmlns-uris>
feature is off. Then, xmlns and xmlns:* attributes are both put into no namespace
(0, default) or into C<http://www.w3.org/2000/xmlns/> namespace (1).
=item C<http://xmlns.perl.org/sax/locator>
The document locator is updated (1, default) for ContentHadler events or not (0).
=item C<http://xmlns.perl.org/sax/recstring>
A recognized string (the text string currently processed by this XML parser)
is either maintained as $parser->{ParseOptions}{RecognizedString} (1) or not
(0, default).
=item C<http://xml.org/sax/features/external-general-entities>
Controls whether this parser processes external general entities (1, default)
or not (0).
=item C<http://xml.org/sax/features/external-parameter-entities>
Controls whether this parser processes external parameter entities including
an external DTD subset (1) or not (0, default).
=back
=head2 Constructor Options
Apart from features, the behavior of this parser can also be changed with
options to the constructor.
=over
=item ParseParamEnt
ParseParamEnt => 1
This option meaning is exactly the same as
the C<http://xml.org/sax/features/external-parameter-entities> feature.
The option is supported only because of the compatibility with older versions
of this module. Turned off by default.
=item NoExpand
NoExpand => 1
No internal entities are expanded if this option is turned on.
Turned off by default.
=back
=head2 Read-only Properties
=over
=item ExpatVersion
This property returns a version of linked Expat library, for example
expat_1.95.7.
=back
=head1 AUTHORS
Petr Cimprich <pcimprich AT gmail DOT com> (maintainer)
Matt Sergeant <matt AT sergeant DOT org>
=head1 COPYRIGHT
2002-2004 Matt Sergeant, 2004-2011 Petr Cimprich. All rights reserved.
=head1 LICENSE
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut
|