1 package EximBuild::WebTxn;
5 Copyright (c) 2003-2013, Andrew Dunstan
7 See accompanying License file for license details
10 Most of this code is imported from the older standalone script run_web_txn.pl
11 which is now just a shell that calls the function below. It is now only
12 needed on older Msys installations (i.e. things running perl < 5.8).
18 use vars qw($VERSION); $VERSION = 'REL_0.1';
20 use vars qw($changed_this_run $changed_since_success $branch $status $stage
21 $animal $ts $log_data $confsum $target $verbose $secret);
26 my $lrname = shift || 'lastrun-logs';
28 # make these runtime imports so they are loaded by the perl that's running
29 # the procedure. On older Msys it won't be the same as the one that's
30 # running run_build.pl.
34 require HTTP::Request::Common;
35 import HTTP::Request::Common;
39 import Digest::SHA qw(sha1_hex);
41 import Storable qw(nfreeze);
43 my $txfname = "$lrname/web-txn.data";
46 open($txdhandle,"$txfname") or die "opening $txfname: $!";
47 my $txdata = <$txdhandle>;
57 my $tarname = "$lrname/runlogs.tgz";
59 if (open($txdhandle,$tarname))
61 # This creates the tarball to send to the buildfarm server
63 $tardata=<$txdhandle>;
67 # add our own version string and time
68 my $current_ts = time;
69 my $webscriptversion = "'web_script_version' => '$VERSION',\n";
70 my $cts = "'current_ts' => $current_ts,\n";
72 # $2 here helps us to preserve the nice spacing from Data::Dumper
73 my $scriptline = "((.*)'script_version' => '(REL_)?\\d+\\.\\d+',\n)";
74 $confsum =~ s/$scriptline/$1$2$webscriptversion$2$cts/;
76 $sconf =~ s/.*(\$Script_Config)/$1/ms;
80 # very modern Storable modules choke on regexes
81 # the server has no need of them anyway, so just chop them out
82 # they are still there in the text version used for reporting
83 foreach my $k ( keys %$Script_Config )
85 delete $Script_Config->{$k}
86 if ref($Script_Config->{$k}) eq q(Regexp);
88 my $frozen_sconf = nfreeze($Script_Config);
90 # make the base64 data escape-proof; = is probably ok but no harm done
91 # this ensures that what is seen at the other end is EXACTLY what we
92 # see when we calculate the signature
94 map{ $_=encode_base64($_,""); tr/+=/$@/; }(
95 $log_data,$confsum,$changed_this_run,$changed_since_success,$tardata,
100 "changed_files=$changed_this_run&"
101 . "changed_since_success=$changed_since_success&"
102 ."branch=$branch&res=$status&stage=$stage&animal=$animal&ts=$ts"
103 ."&log=$log_data&conf=$confsum";
104 my $sig= sha1_hex($content,$secret);
106 $content .= "&frozen_sconf=$frozen_sconf";
110 $content .= "&logtar=$tardata";
113 my $ua = new LWP::UserAgent;
114 $ua->agent("Exim Build Farm Reporter");
115 if (my $proxy = $ENV{BF_PROXY})
117 $ua->proxy('http',$proxy);
120 my $request=HTTP::Request->new(POST => "$target/$sig");
121 $request->content_type("application/x-www-form-urlencoded");
122 $request->content($content);
124 my $response=$ua->request($request);
126 unless ($response->is_success)
129 "Query for: stage=$stage&animal=$animal&ts=$ts\n",
130 "Target: $target/$sig\n";
131 print "Status Line: ",$response->status_line,"\n";
132 print "Content: \n", $response->content,"\n"
133 if ($verbose && $response->content);