/usr/share/perl5/XML/SAX/RPMHandler.pm is in argonaut-common 0.9.2-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 | #######################################################################
#
# XML::SAX::RPMHandler -- get and parse RPM Packages.
#
# Copyright (C) 2015 FusionDirectory project
#
# Author: Côme BERNIGAUD
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
#######################################################################
package XML::SAX::RPMHandler;
use base qw(XML::SAX::Base);
sub new {
my $type = shift;
$self = {
'packages' => shift,
'package' => undef,
'key' => undef,
'fields' => shift,
'regexps' => shift,
'from' => shift,
'to' => shift,
'indice' => shift || 0,
};
return bless $self, $type;
}
sub start_document {
my ($self, $doc) = @_;
$self->{package} = undef;
$self->{key} = undef;
}
sub start_element {
my ($self, $el) = @_;
if ($el->{LocalName} eq 'package') {
$self->{package} = {};
$self->{key} = undef;
} elsif ((defined $self->{package}) && (defined $self->{fields}->{$el->{LocalName}})) {
$self->{key} = $el->{LocalName};
$self->{attrs} = $el->{Attributes};
$self->{data} = '';
}
}
sub characters {
my ($self, $data) = @_;
if ((defined $self->{package}) && (defined $self->{key})) {
if ($self->{key} eq 'name') {
if ((ref($self->{packages}) eq 'HASH') && (defined $self->{packages}->{$data->{Data}})) {
$self->{package} = undef;
return;
}
if (defined $self->{regexps}) {
my $match = 0;
foreach my $regexp (@{$self->{regexps}}) {
if ($data->{Data} =~ /$regexp/) {
$match = 1;
last;
}
}
if($match == 0) {
$self->{package} = undef;
return;
}
}
}
$self->{data} .= $data->{Data};
}
}
sub end_element {
my ($self, $el) = @_;
if (defined $self->{package}) {
if ($el->{LocalName} eq 'package') {
if (ref($self->{packages}) eq 'ARRAY') {
push @{$self->{packages}}, $self->{package};
} elsif (ref($self->{packages}) eq 'HASH') {
$self->{packages}->{$self->{package}->{$self->{fields}->{'name'}}} = $self->{package};
}
$self->{package} = undef;
$self->{indice}++;
if ((defined $self->{to}) && ($self->{indice} >= $self->{to})) {
die 'LIMIT_REACHED';
}
} elsif (defined $self->{fields}->{$el->{LocalName}}) {
if (ref($self->{fields}->{$el->{LocalName}}) eq 'CODE') {
$self->{fields}->{$el->{LocalName}}($self->{package}, $self->{key}, $self->{data}, $self->{attrs});
} else {
$self->{package}->{$self->{fields}->{$el->{LocalName}}} = $self->{data};
}
$self->{key} = undef;
}
}
}
1;
=pod
Example:
my $packages = [];
my $parser = XML::SAX::ParserFactory->parser(
Handler => XML::SAX::RPMHandler->new(
$packages,
{
'name' => 'PACKAGE',
'description' => sub {
my ($package, undef, $data) = @_;
$package->{'DESCRIPTION'} = $data;
},
'version' => sub {
my ($package, undef, $data, $attrs) = @_;
$package->{'VERSION'} = $attrs->{'{}ver'}->{'Value'}.'-'.$attrs->{'{}rel'}->{'Value'};
},
},
[
'^kernel',
],
)
);
$parser->parse_uri("Centos/6/os/x86_64/primary.xml");
=cut
|