#!/usr/bin/perl # # Netprog spring 2004 # # test client used for grading proxy web servers # give this perl script the address of the server as a hostname and port number # # This client reads a script that contains commands used to test # project 1 submissions. Supported commands are: # # CONNECT : establish a connection to the proxy server # (forces a close as well) # SEND string : send the specified string # CLOSE : close the TCP socket the proxy # READLINE : read one line from proxy and toss away # READALL : read from proxy until EOF (tossing away) # SAVEALL file : read from proxy until EOF and save in file # SAVECONTENT : skip headers and save content in file # ECHOLINE : read one line from proxy and print # ECHOALL : read from proxy until EOF and print # EXPECT file : read from proxy until EOF and compare to a file # EXPECTCONTENT file : read from proxy, until EOF and compare to a file # tosses headers before comparing # PRINT string : print the string to STDOUT # EVAL string : eval the perl commandprint the string to STDOUT # QUEUE : add string to send queue # SENDQUEUE : send entire send queue require 5.002; use strict; #use sigtrap; use Socket; $SIG{'PIPE'} = 'IGNORE'; # location of documents directory #my $docdir = "/cs/hollingd/netprog/submissions/hw2/testcode/docs"; #my $docdir = "/Users/hollingd/Desktop/Netprog/proj2/testcode/testcode/docs"; my $docdir = "/cs/hollingd/netprog/hw2/testcode/docs"; my %commands = ( "close",1, "connect",1, "echoall",1, "echoline",1, "expect",1, "expectcontent",1, "expecterror",1, "print",1, "queue",1, "readall",1, "readline",1, "send",1, "sendqueue",1, "saveall",1, "savecontent",1, "eval",1, "sleep",1); select STDOUT; $|=1; # send queue initially empty my $queue = ""; # collect command line parameters my $hostname = shift || die "No host specified!"; my $port = shift || die "No port specified!"; my $script = shift || die "No script specified"; my($command,@tmp,$perlcom); my @sc; my $sname; @sc = split("\/",$script); $sname = pop @sc; printf("Script is $sname\n"); open(SCRIPT,"$script") || die $!; # process commands from the script file while (