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 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 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 $ipvnum = 4; # default IP version of http server 40my $idnum = 1; # dafault http server instance number 41my $proto = 'http'; # protocol the http server speaks 42my $pidfile; # http server pid file 43my $logfile; # http server log file 44my $connect; # IP to connect to on CONNECT 45my $srcdir; 46my $gopher = 0; 47 48my $flags = ""; 49my $path = '.'; 50my $logdir = $path .'/log'; 51 52while(@ARGV) { 53 if($ARGV[0] eq '--pidfile') { 54 if($ARGV[1]) { 55 $pidfile = $ARGV[1]; 56 shift @ARGV; 57 } 58 } 59 elsif($ARGV[0] eq '--logfile') { 60 if($ARGV[1]) { 61 $logfile = $ARGV[1]; 62 shift @ARGV; 63 } 64 } 65 elsif($ARGV[0] eq '--srcdir') { 66 if($ARGV[1]) { 67 $srcdir = $ARGV[1]; 68 shift @ARGV; 69 } 70 } 71 elsif($ARGV[0] eq '--ipv4') { 72 $ipvnum = 4; 73 } 74 elsif($ARGV[0] eq '--ipv6') { 75 $ipvnum = 6; 76 } 77 elsif($ARGV[0] eq '--gopher') { 78 $gopher = 1; 79 } 80 elsif($ARGV[0] eq '--port') { 81 if($ARGV[1] =~ /^(\d+)$/) { 82 $port = $1; 83 shift @ARGV; 84 } 85 } 86 elsif($ARGV[0] eq '--connect') { 87 if($ARGV[1]) { 88 $connect = $ARGV[1]; 89 shift @ARGV; 90 } 91 } 92 elsif($ARGV[0] eq '--id') { 93 if($ARGV[1] =~ /^(\d+)$/) { 94 $idnum = $1 if($1 > 0); 95 shift @ARGV; 96 } 97 } 98 elsif($ARGV[0] eq '--verbose') { 99 $verbose = 1; 100 } 101 else { 102 print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n"; 103 } 104 shift @ARGV; 105} 106 107if(!$srcdir) { 108 $srcdir = $ENV{'srcdir'} || '.'; 109} 110if(!$pidfile) { 111 $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum); 112} 113if(!$logfile) { 114 $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum); 115} 116 117$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; 118$flags .= "--gopher " if($gopher); 119$flags .= "--connect $connect " if($connect); 120$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\""; 121 122if($verbose) { 123 print STDERR "RUN: server/sws $flags\n"; 124} 125 126exec("server/sws $flags"); 127