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