Skip to content

Commit d0f6bde

Browse files
committed
Initial refactoring step for server name strings centralized generation
1 parent 1bd5784 commit d0f6bde

File tree

3 files changed

+180
-32
lines changed

3 files changed

+180
-32
lines changed

tests/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ PDFPAGES = testcurl.pdf runtests.pdf
2727
EXTRA_DIST = ftpserver.pl httpserver.pl httpsserver.pl runtests.pl getpart.pm \
2828
FILEFORMAT README stunnel.pem memanalyze.pl testcurl.pl valgrind.pm ftp.pm \
2929
sshserver.pl sshhelp.pm testcurl.1 runtests.1 $(HTMLPAGES) $(PDFPAGES) \
30-
CMakeLists.txt certs/scripts/*.sh certs/Server* certs/EdelCurlRoot*
30+
CMakeLists.txt certs/scripts/*.sh certs/Server* certs/EdelCurlRoot* \
31+
serverhelp.pm
3132

3233
SUBDIRS = data server libtest
3334

tests/runtests.pl

+75-31
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ BEGIN
7070
#use warnings;
7171
use Cwd;
7272

73+
# Subs imported from serverhelp module
74+
use serverhelp qw(
75+
servername_str
76+
);
77+
7378
# Variables and subs imported from sshhelp module
7479
use sshhelp qw(
7580
$sshdexe
@@ -802,22 +807,27 @@ sub runhttpserver {
802807
my $pidfile = $HTTPPIDFILE;
803808
my $port = $HTTPPORT;
804809
my $ip = $HOSTIP;
805-
my $nameext;
810+
my $proto = 'http';
811+
my $ipvnum = 4;
812+
my $idnum = 1;
813+
my $srvrname;
806814
my $fork = $forkserver?"--fork":"";
807815

808816
if($ipv6) {
809817
# if IPv6, use a different setup
818+
$ipvnum = 6;
810819
$pidfile = $HTTP6PIDFILE;
811820
$port = $HTTP6PORT;
812821
$ip = $HOST6IP;
813-
$nameext="-ipv6";
814822
}
815823

816824
# don't retry if the server doesn't work
817825
if ($doesntrun{$pidfile}) {
818826
return (0,0);
819827
}
820828

829+
$srvrname = servername_str($proto, $ipvnum, $idnum);
830+
821831
my $pid = processexists($pidfile);
822832
if($pid > 0) {
823833
stopserver($pid);
@@ -836,7 +846,7 @@ sub runhttpserver {
836846

837847
if($httppid <= 0 || !kill(0, $httppid)) {
838848
# it is NOT alive
839-
logmsg "RUN: failed to start the HTTP$nameext server\n";
849+
logmsg "RUN: failed to start the $srvrname server\n";
840850
stopserver("$pid2");
841851
displaylogs($testnumcheck);
842852
$doesntrun{$pidfile} = 1;
@@ -846,7 +856,7 @@ sub runhttpserver {
846856
# Server is up. Verify that we can speak to it.
847857
my $pid3 = verifyserver("http", $ip, $port);
848858
if(!$pid3) {
849-
logmsg "RUN: HTTP$nameext server failed verification\n";
859+
logmsg "RUN: $srvrname server failed verification\n";
850860
# failed to talk to it properly. Kill the server and return failure
851861
stopserver("$httppid $pid2");
852862
displaylogs($testnumcheck);
@@ -856,7 +866,7 @@ sub runhttpserver {
856866
$pid2 = $pid3;
857867

858868
if($verbose) {
859-
logmsg "RUN: HTTP$nameext server is now running PID $httppid\n";
869+
logmsg "RUN: $srvrname server is now running PID $httppid\n";
860870
}
861871

862872
sleep(1);
@@ -873,13 +883,18 @@ sub runhttpsserver {
873883
my $RUNNING;
874884
my $ip = $HOSTIP;
875885
my $pidfile = $HTTPSPIDFILE;
886+
my $proto = 'https';
887+
my $ipvnum = 4;
888+
my $idnum = 1;
889+
my $srvrname;
876890

877891
if(!$stunnel) {
878892
return 0;
879893
}
880894

881895
if($ipv6) {
882896
# not complete yet
897+
$ipvnum = 6;
883898
$ip = $HOST6IP;
884899
}
885900

@@ -888,6 +903,8 @@ sub runhttpsserver {
888903
return (0,0);
889904
}
890905

906+
$srvrname = servername_str($proto, $ipvnum, $idnum);
907+
891908
my $pid = processexists($pidfile);
892909
if($pid > 0) {
893910
# kill previous stunnel!
@@ -903,7 +920,7 @@ sub runhttpsserver {
903920

904921
if($httpspid <= 0 || !kill(0, $httpspid)) {
905922
# it is NOT alive
906-
logmsg "RUN: failed to start the HTTPS server\n";
923+
logmsg "RUN: failed to start the $srvrname server\n";
907924
stopservers($verbose);
908925
displaylogs($testnumcheck);
909926
$doesntrun{$pidfile} = 1;
@@ -913,7 +930,7 @@ sub runhttpsserver {
913930
# Server is up. Verify that we can speak to it.
914931
my $pid3 = verifyserver("https", $ip, $HTTPSPORT);
915932
if(!$pid3) {
916-
logmsg "RUN: HTTPS server failed verification\n";
933+
logmsg "RUN: $srvrname server failed verification\n";
917934
# failed to talk to it properly. Kill the server and return failure
918935
stopserver("$httpspid $pid2");
919936
displaylogs($testnumcheck);
@@ -923,7 +940,7 @@ sub runhttpsserver {
923940
# Here pid3 is actually the pid returned by the unsecure-http server.
924941

925942
if($verbose) {
926-
logmsg "RUN: HTTPS server is now running PID $httpspid\n";
943+
logmsg "RUN: $srvrname server is now running PID $httpspid\n";
927944
}
928945

929946
sleep(1);
@@ -941,20 +958,22 @@ sub runpingpongserver {
941958
my $port;
942959
my $pidfile;
943960
my $ip=$HOSTIP;
944-
my $nameext;
945961
my $cmd;
946962
my $flag;
963+
my $ipvnum = 4;
964+
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
965+
my $srvrname;
947966

948967
if($proto eq "ftp") {
949-
$port = $id?$FTP2PORT:$FTPPORT;
950-
$pidfile = $id?$FTP2PIDFILE:$FTPPIDFILE;
968+
$port = ($idnum>1)?$FTP2PORT:$FTPPORT;
969+
$pidfile = ($idnum>1)?$FTP2PIDFILE:$FTPPIDFILE;
951970

952971
if($ipv6) {
953972
# if IPv6, use a different setup
973+
$ipvnum = 6;
954974
$pidfile = $FTP6PIDFILE;
955975
$port = $FTP6PORT;
956976
$ip = $HOST6IP;
957-
$nameext="-ipv6";
958977
}
959978
}
960979
elsif($proto eq "pop3") {
@@ -980,6 +999,8 @@ sub runpingpongserver {
980999
return (0,0);
9811000
}
9821001

1002+
$srvrname = servername_str($proto, $ipvnum, $idnum);
1003+
9831004
my $pid = processexists($pidfile);
9841005
if($pid > 0) {
9851006
stopserver($pid);
@@ -990,8 +1011,8 @@ sub runpingpongserver {
9901011
$flag .= $debugprotocol?"-v ":"";
9911012
$flag .= "-s \"$srcdir\" ";
9921013
my $addr;
993-
if($id) {
994-
$flag .="--id $id ";
1014+
if($idnum > 1) {
1015+
$flag .="--id $idnum ";
9951016
}
9961017
if($ipv6) {
9971018
$flag .="--ipv6 ";
@@ -1005,7 +1026,7 @@ sub runpingpongserver {
10051026

10061027
if($ftppid <= 0 || !kill(0, $ftppid)) {
10071028
# it is NOT alive
1008-
logmsg "RUN: failed to start the ". uc($proto) ."$id$nameext server\n";
1029+
logmsg "RUN: failed to start the $srvrname server\n";
10091030
stopserver("$pid2");
10101031
displaylogs($testnumcheck);
10111032
$doesntrun{$pidfile} = 1;
@@ -1015,7 +1036,7 @@ sub runpingpongserver {
10151036
# Server is up. Verify that we can speak to it.
10161037
my $pid3 = verifyserver($proto, $ip, $port);
10171038
if(!$pid3) {
1018-
logmsg "RUN: ". uc($proto) ."$id$nameext server failed verification\n";
1039+
logmsg "RUN: $srvrname server failed verification\n";
10191040
# failed to talk to it properly. Kill the server and return failure
10201041
stopserver("$ftppid $pid2");
10211042
displaylogs($testnumcheck);
@@ -1025,8 +1046,7 @@ sub runpingpongserver {
10251046
$pid2 = $pid3;
10261047

10271048
if($verbose) {
1028-
logmsg "RUN: ". uc($proto) ."$id$nameext server is now running".
1029-
" PID $ftppid\n";
1049+
logmsg "RUN: $srvrname server is now running PID $ftppid\n";
10301050
}
10311051

10321052
sleep(1);
@@ -1043,13 +1063,18 @@ sub runftpsserver {
10431063
my $RUNNING;
10441064
my $ip = $HOSTIP;
10451065
my $pidfile = $FTPSPIDFILE;
1066+
my $proto = 'ftps';
1067+
my $ipvnum = 4;
1068+
my $idnum = 1;
1069+
my $srvrname;
10461070

10471071
if(!$stunnel) {
10481072
return 0;
10491073
}
10501074

10511075
if($ipv6) {
10521076
# not complete yet
1077+
$ipvnum = 6;
10531078
$ip = $HOST6IP;
10541079
}
10551080

@@ -1058,6 +1083,8 @@ sub runftpsserver {
10581083
return (0,0);
10591084
}
10601085

1086+
$srvrname = servername_str($proto, $ipvnum, $idnum);
1087+
10611088
my $pid = processexists($pidfile);
10621089
if($pid > 0) {
10631090
# kill previous stunnel!
@@ -1072,7 +1099,7 @@ sub runftpsserver {
10721099

10731100
if($ftpspid <= 0 || !kill(0, $ftpspid)) {
10741101
# it is NOT alive
1075-
logmsg "RUN: failed to start the FTPS server\n";
1102+
logmsg "RUN: failed to start the $srvrname server\n";
10761103
stopservers($verbose);
10771104
displaylogs($testnumcheck);
10781105
$doesntrun{$pidfile} = 1;
@@ -1082,7 +1109,7 @@ sub runftpsserver {
10821109
# Server is up. Verify that we can speak to it.
10831110
my $pid3 = verifyserver("ftps", $ip, $FTPSPORT);
10841111
if(!$pid3) {
1085-
logmsg "RUN: FTPS server failed verification\n";
1112+
logmsg "RUN: $srvrname server failed verification\n";
10861113
# failed to talk to it properly. Kill the server and return failure
10871114
stopserver("$ftpspid $pid2");
10881115
displaylogs($testnumcheck);
@@ -1092,7 +1119,7 @@ sub runftpsserver {
10921119
# Here pid3 is actually the pid returned by the unsecure-ftp server.
10931120

10941121
if($verbose) {
1095-
logmsg "RUN: FTPS server is now running PID $ftpspid\n";
1122+
logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
10961123
}
10971124

10981125
sleep(1);
@@ -1111,22 +1138,27 @@ sub runtftpserver {
11111138
# check for pidfile
11121139
my $pidfile = $TFTPPIDFILE;
11131140
my $ip=$HOSTIP;
1114-
my $nameext;
11151141
my $cmd;
1142+
my $proto = 'tftp';
1143+
my $ipvnum = 4;
1144+
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1145+
my $srvrname;
11161146

11171147
if($ipv6) {
11181148
# if IPv6, use a different setup
1149+
$ipvnum = 6;
11191150
$pidfile = $TFTP6PIDFILE;
11201151
$port = $TFTP6PORT;
11211152
$ip = $HOST6IP;
1122-
$nameext="-ipv6";
11231153
}
11241154

11251155
# don't retry if the server doesn't work
11261156
if ($doesntrun{$pidfile}) {
11271157
return (0,0);
11281158
}
11291159

1160+
$srvrname = servername_str($proto, $ipvnum, $idnum);
1161+
11301162
my $pid = processexists($pidfile);
11311163
if($pid > 0) {
11321164
stopserver($pid);
@@ -1136,8 +1168,8 @@ sub runtftpserver {
11361168
# start our server:
11371169
my $flag=$debugprotocol?"-v ":"";
11381170
$flag .= "-s \"$srcdir\" ";
1139-
if($id) {
1140-
$flag .="--id $id ";
1171+
if($idnum > 1) {
1172+
$flag .="--id $idnum ";
11411173
}
11421174
if($ipv6) {
11431175
$flag .="--ipv6 ";
@@ -1148,7 +1180,7 @@ sub runtftpserver {
11481180

11491181
if($tftppid <= 0 || !kill(0, $tftppid)) {
11501182
# it is NOT alive
1151-
logmsg "RUN: failed to start the TFTP$id$nameext server\n";
1183+
logmsg "RUN: failed to start the $srvrname server\n";
11521184
stopserver("$pid2");
11531185
displaylogs($testnumcheck);
11541186
$doesntrun{$pidfile} = 1;
@@ -1158,7 +1190,7 @@ sub runtftpserver {
11581190
# Server is up. Verify that we can speak to it.
11591191
my $pid3 = verifyserver("tftp", $ip, $port);
11601192
if(!$pid3) {
1161-
logmsg "RUN: TFTP$id$nameext server failed verification\n";
1193+
logmsg "RUN: $srvrname server failed verification\n";
11621194
# failed to talk to it properly. Kill the server and return failure
11631195
stopserver("$tftppid $pid2");
11641196
displaylogs($testnumcheck);
@@ -1168,7 +1200,7 @@ sub runtftpserver {
11681200
$pid2 = $pid3;
11691201

11701202
if($verbose) {
1171-
logmsg "RUN: TFTP$id$nameext server is now running PID $tftppid\n";
1203+
logmsg "RUN: $srvrname server is now running PID $tftppid\n";
11721204
}
11731205

11741206
sleep(1);
@@ -1186,12 +1218,18 @@ sub runsshserver {
11861218
my $port = $SSHPORT;
11871219
my $socksport = $SOCKSPORT;
11881220
my $pidfile = $SSHPIDFILE;
1221+
my $proto = 'ssh';
1222+
my $ipvnum = 4;
1223+
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1224+
my $srvrname;
11891225

11901226
# don't retry if the server doesn't work
11911227
if ($doesntrun{$pidfile}) {
11921228
return (0,0);
11931229
}
11941230

1231+
$srvrname = servername_str($proto, $ipvnum, $idnum);
1232+
11951233
my $pid = processexists($pidfile);
11961234
if($pid > 0) {
11971235
stopserver($pid);
@@ -1210,7 +1248,7 @@ sub runsshserver {
12101248

12111249
if($sshpid <= 0 || !kill(0, $sshpid)) {
12121250
# it is NOT alive
1213-
logmsg "RUN: failed to start the SSH server\n";
1251+
logmsg "RUN: failed to start the $srvrname server\n";
12141252
stopserver("$pid2");
12151253
$doesntrun{$pidfile} = 1;
12161254
return (0,0);
@@ -1222,7 +1260,7 @@ sub runsshserver {
12221260

12231261
my $pid3 = verifyserver("ssh",$ip,$port);
12241262
if(!$pid3) {
1225-
logmsg "RUN: SSH server failed verification\n";
1263+
logmsg "RUN: $srvrname server failed verification\n";
12261264
# failed to fetch server pid. Kill the server and return failure
12271265
stopserver("$sshpid $pid2");
12281266
$doesntrun{$pidfile} = 1;
@@ -1247,7 +1285,7 @@ sub runsshserver {
12471285
}
12481286

12491287
if($verbose) {
1250-
logmsg "RUN: SSH server is now running PID $pid2\n";
1288+
logmsg "RUN: $srvrname server is now running PID $pid2\n";
12511289
}
12521290

12531291
return ($pid2, $sshpid);
@@ -1261,12 +1299,18 @@ sub runsocksserver {
12611299
my $ip=$HOSTIP;
12621300
my $port = $SOCKSPORT;
12631301
my $pidfile = $SOCKSPIDFILE;
1302+
my $proto = 'socks';
1303+
my $ipvnum = 4;
1304+
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1305+
my $srvrname;
12641306

12651307
# don't retry if the server doesn't work
12661308
if ($doesntrun{$pidfile}) {
12671309
return (0,0);
12681310
}
12691311

1312+
$srvrname = servername_str($proto, $ipvnum, $idnum);
1313+
12701314
my $pid = processexists($pidfile);
12711315
if($pid > 0) {
12721316
stopserver($pid);

0 commit comments

Comments
 (0)