zoneminder/onvif/modules/lib/ONVIF/Deserializer/XSD.pm

87 lines
2.8 KiB
Perl
Raw Normal View History

2016-02-10 23:36:21 +08:00
# ==========================================================================
#
# ZoneMinder ONVIF Client module
# Copyright (C) 2014 Jan M. Hochstein
#
# 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
2016-12-27 00:33:03 +08:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2016-02-10 23:36:21 +08:00
#
# ==========================================================================
#
# This module contains the implementation of a SOAP deserializer
#
2014-08-18 03:24:27 +08:00
package ONVIF::Deserializer::XSD;
use strict;
use warnings;
use base qw(SOAP::WSDL::Deserializer::XSD);
use SOAP::WSDL::SOAP::Typelib::Fault11;
use ONVIF::Deserializer::MessageParser;
use SOAP::WSDL::Factory::Deserializer;
2020-05-13 03:47:44 +08:00
SOAP::WSDL::Factory::Deserializer->register('1.1', __PACKAGE__);
SOAP::WSDL::Factory::Deserializer->register('1.2', __PACKAGE__);
2014-08-18 03:24:27 +08:00
## we get the soap version from the message parser
my %soap_version_of :ATTR( :default<()>);
sub soap_version {
my ($self) = @_;
2020-05-13 03:47:44 +08:00
if ( $SOAP::WSDL::Deserializer::XSD::parser_of{ident $self} ) {
2014-08-18 03:24:27 +08:00
return $SOAP::WSDL::Deserializer::XSD::parser_of{ident $self}->soap_version();
}
return '';
}
sub deserialize {
my ($self, $content) = @_;
my $parser = $SOAP::WSDL::Deserializer::XSD::parser_of{ ${ $self } };
2020-05-13 03:47:44 +08:00
if ( not $parser ) {
2014-08-18 03:24:27 +08:00
$parser = ONVIF::Deserializer::MessageParser->new({
strict => $SOAP::WSDL::Deserializer::XSD::strict_of{ ${ $self } }
});
$SOAP::WSDL::Deserializer::XSD::parser_of{ ${ $self } } = $parser;
}
$parser->class_resolver(
$self->SOAP::WSDL::Deserializer::XSD::get_class_resolver() );
2020-05-13 03:47:44 +08:00
eval { $parser->parse_string($content) };
if ( $@ ) {
2014-08-18 03:24:27 +08:00
return $self->generate_fault({
code => 'SOAP-ENV:Server',
role => 'urn:localhost',
message => "Error deserializing message: $@. \n"
. "Message was: \n$content"
});
}
return ( $parser->get_data(),
$parser->get_header() );
}
sub generate_fault {
my ($self, $args_from_ref) = @_;
return SOAP::WSDL::SOAP::Typelib::Fault11->new({
faultcode => $args_from_ref->{ code } || 'SOAP-ENV:Client',
faultactor => $args_from_ref->{ role } || 'urn:localhost',
2020-05-13 03:47:44 +08:00
faultstring => $args_from_ref->{ message } || 'Unknown error'
2014-08-18 03:24:27 +08:00
});
}
1;
__END__