1#!/usr/bin/perl 2# $OpenBSD: httpd.pl,v 1.2 2016/05/03 19:13:04 bluhm Exp $ 3 4# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org> 5# Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> 6# 7# Permission to use, copy, modify, and distribute this software for any 8# purpose with or without fee is hereby granted, provided that the above 9# copyright notice and this permission notice appear in all copies. 10# 11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 19use strict; 20use warnings; 21use Socket; 22use Socket6; 23 24use Client; 25use Httpd; 26require 'funcs.pl'; 27 28sub usage { 29 die "usage: httpd.pl chroot [test-args.pl]\n"; 30} 31 32my $testfile; 33our %args; 34if (@ARGV and -f $ARGV[-1]) { 35 $testfile = pop; 36 do $testfile 37 or die "Do test file $testfile failed: ", $@ || $!; 38} 39@ARGV == 1 or usage(); 40 41my $redo = $args{lengths} && @{$args{lengths}}; 42$redo = 0 if $args{client}{http_vers}; # run only one persistent connection 43my($sport, $rport) = find_ports(num => 2); 44my($d, $c); 45$d = Httpd->new( 46 chroot => $ARGV[0], 47 listendomain => AF_INET, 48 listenaddr => "127.0.0.1", 49 listenport => $rport, 50 connectdomain => AF_INET, 51 connectaddr => "127.0.0.1", 52 connectport => $sport, 53 %{$args{httpd}}, 54 testfile => $testfile, 55); 56$c = Client->new( 57 chroot => $ARGV[0], 58 func => \&http_client, 59 connectdomain => AF_INET, 60 connectaddr => "127.0.0.1", 61 connectport => $rport, 62 %{$args{client}}, 63 testfile => $testfile, 64) unless $args{client}{noclient}; 65 66$d->run; 67$d->up; 68$c->run->up unless $args{client}{noclient}; 69 70$c->down unless $args{client}{noclient}; 71$d->kill_child; 72$d->down; 73 74check_logs($c, $d, %args); 75