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
24BEGIN {
25    @INC=(@INC, $ENV{'srcdir'}, '.');
26}
27
28use strict;
29use warnings;
30
31use serverhelp qw(
32    server_pidfilename
33    server_logfilename
34    );
35
36my $verbose = 0;     # set to 1 for debugging
37my $port = 8990;     # just a default
38my $ipvnum = 4;      # default IP version of http server
39my $idnum = 1;       # dafault http server instance number
40my $proto = 'http';  # protocol the http server speaks
41my $pidfile;         # http server pid file
42my $logfile;         # http server log file
43my $srcdir;
44my $fork;
45my $gopher = 0;
46
47my $flags  = "";
48my $path   = '.';
49my $logdir = $path .'/log';
50
51while(@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
103if(!$srcdir) {
104    $srcdir = $ENV{'srcdir'} || '.';
105}
106if(!$pidfile) {
107    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
108}
109if(!$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
118exec("server/sws $flags");
119