diff --git a/perl-xCAT/xCAT/Client.pm b/perl-xCAT/xCAT/Client.pm index cea9d8b2d..fae3d4564 100644 --- a/perl-xCAT/xCAT/Client.pm +++ b/perl-xCAT/xCAT/Client.pm @@ -157,6 +157,9 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog } my $msg=XMLout($request,RootName=>'xcatrequest',NoAttr=>1,KeyAttr=>[]); if ($ENV{XCATXMLTRACE}) { print $msg; } + if($ENV{XCATXMLWARNING}) { + validateXML($msg); + } $SIG{TERM} = $SIG{INT} = sub { print $client XMLout({abortcommand=>1},RootName=>'xcatrequest',NoAttr=>1,KeyAttr=>[]); exit 0; }; print $client $msg; my $response; @@ -168,8 +171,11 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog #replace ESC with xxxxESCxxx because XMLin cannot handle it $response =~ s/\e/xxxxESCxxxx/g; - if ($ENV{XCATXMLTRACE}) { print $response; } + if ($ENV{XCATXMLTRACE}) { print $response; } $rsp = XMLin($response,SuppressEmpty=>undef,ForceArray=>1); + if($ENV{XCATXMLWARNING}) { + validateXML($response); + } #add ESC back foreach my $key (keys %$rsp) { @@ -196,6 +202,35 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog print STDERR "ERROR/WARNING: communication with the xCAT server seems to have been ended prematurely\n"; } +sub validateXML { + my $xml = shift; + my @lines = split /\n/, $xml; + my $invalidNewline = 0; + my $contentsColon = 0; + my $contentsLine; + + foreach (@lines) { + if(!$invalidNewline) { + if( ($_ =~ // && $_ !~ /<\/contents>/) || + ($_ =~ // && $_ !~ /<\/desc>/)) { + $invalidNewline = 1; + print "Possible invalid XML using newlines found: \n$xml\n"; + } + } + if($_ =~ /.+:.+<\/contents>/) { + $contentsColon = 1; + $contentsLine = $_; + } + if($_ =~ /.+<\/desc>/) { + $contentsColon = 0; + } + if($contentsColon && $_ =~ /<\/desc>/) { + print "Possible invalid XML found(data contents using colon and blank description): \n$contentsLine\n$_\n"; + $contentsColon = 0; + } + } +} + ################################### # scan_plugins # will load all plugin perl modules and build a list of supported