Debian Codegraph @

deps/curl/tests/httpserver.pl

raw
1 #!/usr/bin/env perl
2 #***************************************************************************
3 # _ _ ____ _
4 # Project ___| | | | _ \| |
5 # / __| | | | |_) | |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2012, Daniel Stenberg, <[email protected]>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 #***************************************************************************
23
24 BEGIN {
25 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
26 push(@INC, ".");
27 }
28
29 use strict;
30 use warnings;
31
32 use serverhelp qw(
33 server_pidfilename
34 server_logfilename
35 );
36
37 use sshhelp qw(
38 exe_ext
39 );
40
41 my $verbose = 0; # set to 1 for debugging
42 my $port = 8990; # just a default
43 my $unix_socket; # location to place a listening Unix socket
44 my $ipvnum = 4; # default IP version of http server
45 my $idnum = 1; # default http server instance number
46 my $proto = 'http'; # protocol the http server speaks
47 my $pidfile; # http server pid file
48 my $logfile; # http server log file
49 my $connect; # IP to connect to on CONNECT
50 my $srcdir;
51 my $gopher = 0;
52
53 my $flags = "";
54 my $path = '.';
55 my $logdir = $path .'/log';
56
57 while(@ARGV) {
58 if($ARGV[0] eq '--pidfile') {
59 if($ARGV[1]) {
60 $pidfile = $ARGV[1];
61 shift @ARGV;
62 }
63 }
64 elsif($ARGV[0] eq '--logfile') {
65 if($ARGV[1]) {
66 $logfile = $ARGV[1];
67 shift @ARGV;
68 }
69 }
70 elsif($ARGV[0] eq '--srcdir') {
71 if($ARGV[1]) {
72 $srcdir = $ARGV[1];
73 shift @ARGV;
74 }
75 }
76 elsif($ARGV[0] eq '--ipv4') {
77 $ipvnum = 4;
78 }
79 elsif($ARGV[0] eq '--ipv6') {
80 $ipvnum = 6;
81 }
82 elsif($ARGV[0] eq '--unix-socket') {
83 $ipvnum = 'unix';
84 if($ARGV[1]) {
85 $unix_socket = $ARGV[1];
86 shift @ARGV;
87 }
88 }
89 elsif($ARGV[0] eq '--gopher') {
90 $gopher = 1;
91 }
92 elsif($ARGV[0] eq '--port') {
93 if($ARGV[1] =~ /^(\d+)$/) {
94 $port = $1;
95 shift @ARGV;
96 }
97 }
98 elsif($ARGV[0] eq '--connect') {
99 if($ARGV[1]) {
100 $connect = $ARGV[1];
101 shift @ARGV;
102 }
103 }
104 elsif($ARGV[0] eq '--id') {
105 if($ARGV[1] =~ /^(\d+)$/) {
106 $idnum = $1 if($1 > 0);
107 shift @ARGV;
108 }
109 }
110 elsif($ARGV[0] eq '--verbose') {
111 $verbose = 1;
112 }
113 else {
114 print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
115 }
116 shift @ARGV;
117 }
118
119 if(!$srcdir) {
120 $srcdir = $ENV{'srcdir'} || '.';
121 }
122 if(!$pidfile) {
123 $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
124 }
125 if(!$logfile) {
126 $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
127 }
128
129 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
130 $flags .= "--gopher " if($gopher);
131 $flags .= "--connect $connect " if($connect);
132 if($ipvnum eq 'unix') {
133 $flags .= "--unix-socket '$unix_socket' ";
134 } else {
135 $flags .= "--ipv$ipvnum --port $port ";
136 }
137 $flags .= "--srcdir \"$srcdir\"";
138
139 if($verbose) {
140 print STDERR "RUN: server/sws".exe_ext('SRV')." $flags\n";
141 }
142
143 exec("server/sws".exe_ext('SRV')." $flags");