Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / httpsserver.pl
blob78855d70a4f1959d401ff79ddeb0fef86400f543
1 #!/usr/bin/env perl
3 # $Id: httpsserver.pl,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
4 # This is the HTTPS and FTPS server designed for the curl test suite.
6 # It is actually just a layer that runs stunnel properly.
8 use strict;
9 use Cwd;
11 my $stunnel = "stunnel";
14 # -p pemfile
15 # -P pid dir
16 # -d listen port
17 # -r target port
18 # -s stunnel path
20 my $verbose=0; # set to 1 for debugging
22 my $port = 8991; # just our default, weird enough
23 my $target_port = 8999; # default test http-server port
25 my $path = getcwd();
27 my $srcdir=$path;
29 my $proto='https';
31 do {
32 if($ARGV[0] eq "-v") {
33 $verbose=1;
35 if($ARGV[0] eq "-w") {
36 return 0; # return success, means we have stunnel working!
38 elsif($ARGV[0] eq "-p") {
39 $proto=$ARGV[1];
40 shift @ARGV;
42 elsif($ARGV[0] eq "-r") {
43 $target_port=$ARGV[1];
44 shift @ARGV;
46 elsif($ARGV[0] eq "-s") {
47 $stunnel=$ARGV[1];
48 shift @ARGV;
50 elsif($ARGV[0] eq "-d") {
51 $srcdir=$ARGV[1];
52 shift @ARGV;
54 elsif($ARGV[0] =~ /^(\d+)$/) {
55 $port = $1;
57 } while(shift @ARGV);
59 my $conffile="$path/stunnel.conf"; # stunnel configuration data
60 my $certfile="$srcdir/stunnel.pem"; # stunnel server certificate
61 my $pidfile="$path/.$proto.pid"; # stunnel process pid file
63 open(CONF, ">$conffile") || exit 1;
64 print CONF "
65 CApath=$path
66 cert = $certfile
67 pid = $pidfile
68 debug = 0
69 output = /dev/null
70 foreground = yes
72 [curltest]
73 accept = $port
74 connect = $target_port
76 close CONF;
77 #system("chmod go-rwx $conffile $certfile"); # secure permissions
79 # works only with stunnel versions < 4.00
80 my $cmd="$stunnel -p $certfile -P $pidfile -d $port -r $target_port 2>/dev/null";
82 # use some heuristics to determine stunnel version
83 my $version_ge_4=system("$stunnel -V 2>&1|grep '^stunnel.* on '>/dev/null 2>&1");
84 # works only with stunnel versions >= 4.00
85 if ($version_ge_4) { $cmd="$stunnel $conffile"; }
87 if($verbose) {
88 print uc($proto)." server: $cmd\n";
91 my $rc = system($cmd);
93 $rc >>= 8;
94 if($rc) {
95 print STDERR "stunnel exited with $rc!\n";
98 unlink $conffile;
100 exit $rc;