aboutsummaryrefslogtreecommitdiff
path: root/tests/getpart.pm
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-04-14 11:19:12 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-04-14 13:04:10 +0200
commit675f5fb66fd30ff2ea0bfdf455430fe1f76e42a6 (patch)
tree3b5ff74eace00df8906edba62965d104555b96a4 /tests/getpart.pm
parent2522903b792ac5a802f780df60dc4647c58e2477 (diff)
tests: support hex encoded data and mqtt server
The mqtt server is started using a "random" port.
Diffstat (limited to 'tests/getpart.pm')
-rw-r--r--tests/getpart.pm21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/getpart.pm b/tests/getpart.pm
index cd3b9e556..35ab30cb5 100644
--- a/tests/getpart.pm
+++ b/tests/getpart.pm
@@ -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) {