tests: support hex encoded data and mqtt server

The mqtt server is started using a "random" port.
This commit is contained in:
Daniel Stenberg 2020-04-14 11:19:12 +02:00
parent 2522903b79
commit 675f5fb66f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 132 additions and 8 deletions

View file

@ -35,6 +35,15 @@ sub decode_base64 {
return unpack("u", $len . $_); # uudecode and print
}
sub decode_hex {
my $s = $_;
# remove everything not hex
$s =~ s/[^A-Fa-f0-9]//g;
# encode everything
$s =~ s/([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/eg;
return $s;
}
sub getpartattr {
# if $part is undefined (ie only one argument) then
# return the attributes of the section
@ -81,6 +90,7 @@ sub getpart {
my @this;
my $inside=0;
my $base64=0;
my $hex=0;
my $line;
for(@xml) {
@ -96,6 +106,10 @@ sub getpart {
# attempt to detect our base64 encoded part
$base64=1;
}
elsif($_ =~ /$part [^>]*hex=/) {
# attempt to detect a hex-encoded part
$hex=1;
}
$inside++;
}
elsif(($inside >= 2) && ($_ =~ /^ *\<\/$part[ \>]/)) {
@ -122,6 +136,13 @@ sub getpart {
$_ = $decoded;
}
}
elsif($hex) {
# decode the whole array before returning it!
for(@this) {
my $decoded = decode_hex($_);
$_ = $decoded;
}
}
return @this;
}
elsif($inside >= 2) {