"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Ocsinventory/Agent/Common.pm" between
Ocsinventory-Unix-Agent-2.6.1.tar.gz and Ocsinventory-Unix-Agent-2.8.0.tar.gz

About: Ocsinventory-Agent is a Linux agent for OCS Inventory NG.

Common.pm  (Ocsinventory-Unix-Agent-2.6.1):Common.pm  (Ocsinventory-Unix-Agent-2.8.0)
skipping to change at line 17 skipping to change at line 17
## code is always made freely available. ## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt ## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################ ################################################################################
package Ocsinventory::Agent::Common; package Ocsinventory::Agent::Common;
use strict; use strict;
no strict 'refs'; no strict 'refs';
use warnings; use warnings;
use Encode qw(encode);
=head1 NAME =head1 NAME
Ocsinventory::Agent::Common - give common methods to other modules Ocsinventory::Agent::Common - give common methods to other modules
=over =over
=item addController() =item addController()
Add a controller in the inventory. Add a controller in the inventory.
skipping to change at line 102 skipping to change at line 104
Set BIOS information. Set BIOS information.
=item addCPU() =item addCPU()
Add a CPU in the inventory. Add a CPU in the inventory.
=item addUser() =item addUser()
Add an user in the list of logged user. Add an user in the list of logged user.
=item addLocalUser()
Add local users in the inventory.
=item addLocalGroup()
Add local groups in the inventory.
=item addPrinter() =item addPrinter()
Add a printer in the inventory. Add a printer in the inventory.
=item addVirtualMachine() =item addVirtualMachine()
Add a Virtual Machine in the inventory. Add a Virtual Machine in the inventory.
=item addProcess() =item addProcess()
skipping to change at line 474 skipping to change at line 484
$logger->debug("please rename addNetworks to addNetwork()"); $logger->debug("please rename addNetworks to addNetwork()");
$self->addNetwork(@_); $self->addNetwork(@_);
} }
sub addRepo { sub addRepo {
my ($self, $args) = @_; my ($self, $args) = @_;
my $xmltags = $self->{xmltags}; my $xmltags = $self->{xmltags};
my $content = {}; my $content = {};
foreach my $key (qw/BASEURL ENABLED FINGERPRINTS FILENAME MIRROR NAME PACKAG ES PRIORITY REVISION SIGNATURE SIZE TAG UPDATED/) { foreach my $key (qw/BASEURL ENABLED EXCLUDE EXPIRE EXPIRED FILENAME LASTUPDA TED MIRRORS NAME PKGS REVISION SIZE UPDATED/) {
if (exists $args->{$key}) { if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key}; $content->{$key}[0] = $args->{$key} if $args->{$key};
} }
} }
push @{$xmltags->{REPOSITORY}}, $content; push @{$xmltags->{REPOSITORY}}, $content;
} }
# For compatibility # For compatibility
sub addRepos { sub addRepos {
skipping to change at line 583 skipping to change at line 593
$userString .= '/' if $userString; $userString .= '/' if $userString;
$userString .= $login; $userString .= $login;
$self->setHardware ({ $self->setHardware ({
USERID => $userString, USERID => $userString,
}, 1); }, 1);
} }
sub addLocalUser {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/GID HOME ID LOGIN NAME SHELL/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{LOCAL_USERS}}, $content;
}
sub addLocalGroup {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/ID MEMBER NAME/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{LOCAL_GROUPS}}, $content;
}
sub addPrinter { sub addPrinter {
my ($self, $args) = @_; my ($self, $args) = @_;
my $xmltags = $self->{xmltags}; my $xmltags = $self->{xmltags};
my $content = {}; my $content = {};
foreach my $key (qw/DESCRIPTION DRIVER NAME PORT/) { foreach my $key (qw/DESCRIPTION DRIVER NAME PORT/) {
if (exists $args->{$key}) { if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key}; $content->{$key}[0] = $args->{$key} if $args->{$key};
} }
skipping to change at line 669 skipping to change at line 710
foreach my $key (qw/MODEL UUID/){ foreach my $key (qw/MODEL UUID/){
if (exists $args->{$key}) { if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key}; $content->{$key}[0] = $args->{$key} if $args->{$key};
} }
} }
push @{$xmltags->{RUNNING_PROCESSES}}, $content; push @{$xmltags->{RUNNING_PROCESSES}}, $content;
} }
sub addPSU {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/HOTREPLACEABLE LOCATION MANUFACTURER NAME PARTNUMBER PLU
GGED POWERMAX SERIALNUMBER STATUS/){
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{POWERSUPPLIES}}, $content;
}
sub addIpDiscoverEntry { sub addIpDiscoverEntry {
my ($self, $args) = @_; my ($self, $args) = @_;
my $xmltags = $self->{xmltags}; my $xmltags = $self->{xmltags};
my $ipaddress = $args->{IPADDRESS}; my $ipaddress = $args->{IPADDRESS};
my $macaddr = $args->{MACADDR}; my $macaddr = $args->{MACADDR};
my $name = $args->{NAME}; my $name = $args->{NAME};
if (!$xmltags->{IPDISCOVER}{H}) { if (!$xmltags->{IPDISCOVER}{H}) {
$xmltags->{IPDISCOVER}{H} = []; $xmltags->{IPDISCOVER}{H} = [];
skipping to change at line 988 skipping to change at line 1045
$mac=join (':', @splitedAddr); $mac=join (':', @splitedAddr);
return $mac; return $mac;
} }
sub cleanXml { sub cleanXml {
my ($self,$content) = @_; my ($self,$content) = @_;
my $logger = $self->{logger}; my $logger = $self->{logger};
my $clean_content; my $clean_content = encode('UTF-8', $content, Encode::FB_DEFAULT | Encode::L EAVE_SRC | Encode::FB_XMLCREF);
# To avoid strange breakage I remove the unprintable characters in the XML $logger->debug("cleanXml changed content") if ($content ne $clean_content);
foreach (split "\n", $content) {
if (! m/\A(
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*\z/x) {
s/[[:cntrl:]]//g;
$self->{logger}->debug("non utf-8 '".$_."'");
}
# Is that a good idea. Intent to drop some nasty char
# s/[A-z0-9_\-<>\/:\.,#\ \?="'\(\)]//g;
$clean_content .= $_."\n";
}
return $clean_content; return $clean_content."\n";
} }
#Subroutine to read XML structure (returned by XML::Simple::XMLin) and encode co ntent in utf8. #Subroutine to read XML structure (returned by XML::Simple::XMLin) and encode co ntent in utf8.
sub readXml { sub readXml {
my ($self, $xml, $forcearray) = @_; my ($self, $xml, $forcearray) = @_;
my $logger = $self->{logger}; my $logger = $self->{logger};
my $content = XML::Simple::XMLin($xml, ForceArray => [@{$forcearray}]); my $content = XML::Simple::XMLin($xml, ForceArray => [@{$forcearray}]);
foreach my $key (keys %$content) { foreach my $key (keys %$content) {
if (grep(/^$key$/, @{$forcearray})) { #Forced array in XML parsing if (grep(/^$key$/, @{$forcearray})) { #Forced array in XML parsing
$self->parseXmlArray($content->{$key},$forcearray); $self->parseXmlArray($content->{$key},$forcearray);
} else { #Not a forced array in XML parsing } else { #Not a forced array in XML parsing
if (ref ($content->{$key}) =~ /^HASH$/ && !keys %{$content->{$key}}) { # If empty hash from XMLin() if (ref ($content->{$key}) =~ /^HASH$/ && !keys %{$content->{$key}}) { # If empty hash from XMLin()
$content->{$key} = ''; $content->{$key} = '';
} else { utf8::encode($content->{$key}) }; } else { encode('UTF-8', $content->{$key}, Encode::FB_DEFAULT) };
} }
} }
return $content; return $content;
} }
#Subroutine to parse array in XML structure (returned by XML::Simple::XMLin) and encode it in utf8 #Subroutine to parse array in XML structure (returned by XML::Simple::XMLin) and encode it in utf8
sub parseXmlArray { sub parseXmlArray {
my ($self,$array,$forcearray) = @_; my ($self,$array,$forcearray) = @_;
foreach my $hash (@{$array}) { foreach my $hash (@{$array}) {
foreach my $key (keys %$hash) { foreach my $key (keys %$hash) {
if ( grep (/^$key$/,@$forcearray)) { #Forced array in XML parsing if ( grep (/^$key$/,@$forcearray)) { #Forced array in XML parsing
$self->parseXmlArray($hash->{$key},$forcearray); $self->parseXmlArray($hash->{$key},$forcearray);
} else { #Not a forced array in XML parsing } else { #Not a forced array in XML parsing
if (ref ($hash->{$key}) =~ /^HASH$/ && !keys %{$hash->{$key}}) { # If empty hash from XMLin() if (ref ($hash->{$key}) =~ /^HASH$/ && !keys %{$hash->{$key}}) { # If empty hash from XMLin()
$hash->{$key} = ''; $hash->{$key} = '';
} else { utf8::encode($hash->{$key}) }; } else { encode('UTF-8', $hash->{$key}, Encode::FB_DEFAULT) };
} }
} }
} }
} }
#Subroutine to convert versions to numbers (with icutting or right padding if ne eded) #Subroutine to convert versions to numbers (with icutting or right padding if ne eded)
# We create it because Perl 5.8 does not include version comparison modules or f unctions # We create it because Perl 5.8 does not include version comparison modules or f unctions
sub convertVersion { sub convertVersion {
my ($self,$version,$length) = @_; my ($self,$version,$length) = @_;
 End of changes. 10 change blocks. 
25 lines changed or deleted 64 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)