[LOSTWAGES] service.cgi, cleanup
Brian Vincent
vinn at theshell.com
Fri Mar 19 16:00:19 CST 2004
Mostly just some cleanups based on some things we found when testing.
Still need to put a small function in to read a "cookie.mask" file.
Changelog:
Make opening files more generic.
Make it possible to debug remotely by adding debug=1 to url.
Index: winetest/service.cgi
===================================================================
RCS file: /home/wine/tools/winetest/service.cgi,v
retrieving revision 1.4
diff -u -r1.4 service.cgi
--- winetest/service.cgi 18 Mar 2004 20:32:09 -0000 1.4
+++ winetest/service.cgi 19 Mar 2004 21:53:56 -0000
@@ -45,6 +45,7 @@
&main;
sub main {
+ print "Content-type: text/plain\n\n";
%data_received = &User_Data;
&get_all_cookies;
@@ -54,7 +55,6 @@
# Cookies should never be the same. Some day we could return an error
if ($cookie_to_save eq $cookie_current) {
- print "Content-type: text/plain\n\n";
print "OK\n";
}
else {
@@ -64,8 +64,6 @@
exit;
}
- print "Content-type: text/plain\n\n";
-
if ($data_received{"winrash"} ne $cookie{"winrash"}) {
send_upgrade("winrash",$cookie{"winrash"});
exit;
@@ -106,23 +104,15 @@
my $url_mask = "";
my $this_cookie = "";
- open(URL_MASK_FH, "< $path_to_mask")
- or die "Can't open $path_to_mask for reading.\n \
- See comments at top of service.cgi for directory layout. \n";
- do { $url_mask = <URL_MASK_FH> } until $. == 1;
- close(URL_MASK_FH);
+ $url_mask = getoneline("< $path_to_mask");
- chomp $url_mask;
if (!($data_received{"url"} =~ $url_mask)) {
- die "URL mask unmatched, dying.\n";
+ debug("URL mask unmatched, dying.");
+ die;
}
- open(LYNX_OUTPUT, "$path_to_lynx -source $cookie_url |")
- or die "Unable to run lynx to find cookie at $cookie_url.\n";
- do { $this_cookie = <LYNX_OUTPUT> } until $. == 1;
- close(LYNX_OUTPUT);
+ $this_cookie = getoneline("$path_to_lynx -source $cookie_url |");
- chomp $this_cookie;
return $this_cookie;
}
@@ -133,19 +123,20 @@
. "/cookie";
if(length($cookie) != 32) {
- die "MD5sum is " . length($cookie) . ", not 32 characters long? \n";
+ debug("MD5sum is " . length($cookie) . ", not 32 characters long? ");
+ die;
}
if($cookie =~ /[^0-9^A-Z^a-z]/) {
- die "Why do we have non-alpha characters in the MD5sum?\n";
+ debug("Why do we have non-alpha characters in the MD5sum?");
+ die;
}
open(COOKIE_FH, "> $path_to_cookie")
- or die "Can't open $path_to_cookie for writing.\n";
+ or ( debug("Can't open $path_to_cookie for writing.") && die );
print COOKIE_FH "$cookie";
close(COOKIE_FH);
- print "Content-type: text/plain\n\n";
print "OK\n";
}
@@ -155,7 +146,7 @@
. "/url";
open(URL_FH, "> $path_to_url")
- or die "Can't open $path_to_url for writing.\n";
+ or ( debug("Can't open $path_to_url for writing.") && die );
print URL_FH "$data_received{\"url\"}";
close(URL_FH);
}
@@ -175,11 +166,7 @@
my $this_cookie = $_[1];
my $sleeptime = &ret_random_wait;
- open(URL_FH, "< $path_to_url")
- or die "Can't open $path_to_url for reading.\n";
- do { $this_url = <URL_FH> } until $. == 1;
- close(URL_FH);
- chomp $this_url;
+ $this_url = getoneline("< $path_to_url");
if (substr($this_url, -4, 4) =~ ".zip") {
$local_filename = $_[0] . "-". $this_cookie . ".zip";
@@ -233,11 +220,11 @@
# if the hour value is less than the build time, we know that at some
# point today we'll have a build coming up
- # otherwise, we know the next build will happen tomorrow = $nowday + i1
+ # otherwise, we know the next build will happen tomorrow = $nowday + 1
if($nowhour < $hour_we_do_build) {
- ($diffdays, $diffhour, $diffmin, $diffsec) =
- Delta_DHMS( $nowyear, $nowmonth, $nowday, $nowhour, $nowmin, $nowsec,
- $nowyear, $nowmonth, $nowday, $hour_we_do_build, "0", "0");
+ ($diffdays, $diffhour, $diffmin, $diffsec) =
+ Delta_DHMS( $nowyear, $nowmonth, $nowday, $nowhour, $nowmin, $nowsec,
+ $nowyear, $nowmonth, $nowday, $hour_we_do_build, "0", "0");
}
else {
($diffdays, $diffhour, $diffmin, $diffsec) =
@@ -254,8 +241,10 @@
##########################################################################
#
-# We just split the name/value pairs into a hash here. Works for GET or POST.
-# Makes testing from commandline easy if you set $QUERY_STRING
+# Some convenience functions. User_Data splits our name/value pairs
+# by taking GET or POST for input. Useful for running on the commandline
+# by setting QUERY_STRING. Debug gives us output if debug=1. Getoneline
+# just opens files and returns one line, with trailing new lines removed.
#
##########################################################################
@@ -289,6 +278,24 @@
return %user_data;
}
+sub debug {
+ if ($data_received{"debug"}) {
+ print "$_[0]\n";
+ }
+}
+
+sub getoneline {
+
+ open(GENERIC_FH, $_[0])
+ or ( debug("Can't open $_[0].") && die );
+ do { $this_line = <GENERIC_FH> } until $. == 1;
+ close(GENERIC_FH);
+ chomp $this_line;
+
+ return $this_line;
+}
+
+
##########################################################################
#
# Read the cookie files to determine the versions of winrash and tests.
@@ -298,7 +305,7 @@
sub get_all_cookies {
foreach $key (keys %data_received) {
- next if ($key eq "publish" or $key eq "url");
+ next if ($key eq "publish" or $key eq "url" or $key eq "debug");
$cookie{$key} = read_cookie($key);
}
}
@@ -306,13 +313,7 @@
sub read_cookie {
my $path_to_cookie = $path_to_test_directories . $_[0] . "/cookie";
-
- open(COOKIE_FH, "$path_to_cookie")
- or die "Can't open $path_to_cookie.\n";
- do { $this_cookie = <COOKIE_FH> } until $. == 1;
- close(COOKIE_FH);
+ $this_cookie = getoneline($path_to_cookie);
- chomp $this_cookie;
return $this_cookie;
}
-
More information about the wine-patches
mailing list