MT#62342 encode XMLRPC request body, decode XMLRPC response body (12.5)

prevent api 500 errors ie. from LibXML parsing because of
invalid chars.

Change-Id: I55ca6bb8931dab1fc1f611dd57a91978cb23b032
(cherry picked from commit 14caac386c)
mr12.5
Rene Krenn 2 months ago
parent 3936d21a12
commit 6a3fe3e9b6

@ -60,7 +60,9 @@ EOF
my @users = ();
my $usr = {};
for my $host (grep {$$_[1]} @$user_res) {
my $xmlDoc = $xml_parser->parse_string($host->[2]);
my $xml = $host->[2];
$xml =~ s/[\x00-\x08\x0b\x0c\x0e-\x1f]//g;
my $xmlDoc = $xml_parser->parse_string($xml);
my $username = '';
my $key = '';
foreach my $node ($xmlDoc->findnodes('//member')) {

@ -3,6 +3,7 @@ package NGCP::Panel::Utils::XMLDispatcher;
use Sipwise::Base;
use Net::HTTP;
use Errno;
use Encode qw/encode_utf8 decode_utf8/;
sub dispatch {
my ($c, $target, $all, $sync, $body, $schema) = @_;
@ -38,7 +39,7 @@ sub dispatch {
return [$hostid, -1, '']; # skip the host as it is not active
};
my $res = $s->write_request("POST", $path || "/", "User-Agent" => "Sipwise XML Dispatcher", "Content-Type" => "text/xml", $body);
my $res = $s->write_request($method, $path || "/", "User-Agent" => "Sipwise HTTP Dispatcher", "Content-Type" => $content_type, encode_utf8($body));
$res or die "did not get result";
my ($code, $mess, @headers) = $s->read_response_headers();
@ -59,6 +60,14 @@ sub dispatch {
# successful request
eval {
$body = decode_utf8($body, Encode::FB_CROAK);
};
if ($@) {
# If strict UTF-8 decoding fails, use lenient decoding
$body = decode_utf8($body, Encode::FB_QUIET);
}
return [$hostid, 1, $body]; # return from eval only
};

Loading…
Cancel
Save