From: Yang Tse Date: Mon, 18 Jan 2010 02:32:48 +0000 (+0000) Subject: add serverfactors() sub which returns server characterization factors X-Git-Tag: curl-7_20_0~136 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0375f70b5c0ca41dcf3d1fe2261170adf695fc47;p=thirdparty%2Fcurl.git add serverfactors() sub which returns server characterization factors --- diff --git a/tests/serverhelp.pm b/tests/serverhelp.pm index 53aeb79cbe..d34a821a1a 100644 --- a/tests/serverhelp.pm +++ b/tests/serverhelp.pm @@ -47,6 +47,7 @@ use vars qw( # Global symbols this module will export upon request # @EXPORT_OK = qw( + serverfactors servername_id servername_str servername_canon @@ -62,6 +63,32 @@ use vars qw( ); +#*************************************************************************** +# Return server characterization factors given a server id string. +# +sub serverfactors { + my $server = $_[0]; + my $proto; + my $ipvnum; + my $idnum; + + if($server =~ /^((ftp|http|imap|pop3|smtp)s?)(\d*)(-ipv6|)$/) { + $proto = $1; + $idnum = ($3 && ($3 > 1)) ? $3 : 1; + $ipvnum = ($4 && ($4 =~ /6$/)) ? 6 : 4; + } + elsif($server =~ /^(tftp|sftp|socks|ssh)(\d*)(-ipv6|)$/) { + $proto = $1; + $idnum = ($2 && ($2 > 1)) ? $2 : 1; + $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4; + } + else { + die "invalid server id: $server" + } + return($proto, $ipvnum, $idnum); +} + + #*************************************************************************** # Return server name string formatted for presentation purposes #