Git init
[external/curl.git] / tests / httpserver.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, 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 http://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     @INC=(@INC, $ENV{'srcdir'}, '.');
26 }
27
28 use strict;
29 use warnings;
30
31 use serverhelp qw(
32     server_pidfilename
33     server_logfilename
34     );
35
36 my $verbose = 0;     # set to 1 for debugging
37 my $port = 8990;     # just a default
38 my $ipvnum = 4;      # default IP version of http server
39 my $idnum = 1;       # dafault http server instance number
40 my $proto = 'http';  # protocol the http server speaks
41 my $pidfile;         # http server pid file
42 my $logfile;         # http server log file
43 my $srcdir;
44 my $fork;
45 my $gopher = 0;
46
47 my $flags  = "";
48 my $path   = '.';
49 my $logdir = $path .'/log';
50
51 while(@ARGV) {
52     if($ARGV[0] eq '--pidfile') {
53         if($ARGV[1]) {
54             $pidfile = $ARGV[1];
55             shift @ARGV;
56         }
57     }
58     elsif($ARGV[0] eq '--logfile') {
59         if($ARGV[1]) {
60             $logfile = $ARGV[1];
61             shift @ARGV;
62         }
63     }
64     elsif($ARGV[0] eq '--srcdir') {
65         if($ARGV[1]) {
66             $srcdir = $ARGV[1];
67             shift @ARGV;
68         }
69     }
70     elsif($ARGV[0] eq '--ipv4') {
71         $ipvnum = 4;
72     }
73     elsif($ARGV[0] eq '--ipv6') {
74         $ipvnum = 6;
75     }
76     elsif($ARGV[0] eq '--gopher') {
77         $gopher = 1;
78     }
79     elsif($ARGV[0] eq '--port') {
80         if($ARGV[1] =~ /^(\d+)$/) {
81             $port = $1;
82             shift @ARGV;
83         }
84     }
85     elsif($ARGV[0] eq '--id') {
86         if($ARGV[1] =~ /^(\d+)$/) {
87             $idnum = $1 if($1 > 0);
88             shift @ARGV;
89         }
90     }
91     elsif($ARGV[0] eq '--verbose') {
92         $verbose = 1;
93     }
94     elsif($ARGV[0] eq '--fork') {
95         $fork = $ARGV[0];
96     }
97     else {
98         print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
99     }
100     shift @ARGV;
101 }
102
103 if(!$srcdir) {
104     $srcdir = $ENV{'srcdir'} || '.';
105 }
106 if(!$pidfile) {
107     $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
108 }
109 if(!$logfile) {
110     $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
111 }
112
113 $flags .= "--gopher " if($gopher);
114 $flags .= "--fork " if(defined($fork));
115 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
116 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
117
118 exec("server/sws $flags");