chiark / gitweb /
wip commod-update-receiver
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 24 Jul 2009 16:23:01 +0000 (17:23 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 24 Jul 2009 16:23:01 +0000 (17:23 +0100)
pctb/Commods.pm
pctb/commod-update-receiver
pctb/master-master.txt

index d59529b0a6b1eb0121d3761e45a5a34c42686993..e695f15a5efe27afefba5ecdec381f1d87900e4e 100644 (file)
@@ -11,7 +11,8 @@ BEGIN {
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&parse_masters %oceans %commods %clients
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
     @EXPORT      = qw(&parse_masters %oceans %commods %clients
-                     &parse_pctb_commodmap %pctb_commodmap @pctb_commodmap);
+                     &parse_pctb_commodmap %pctb_commodmap @pctb_commodmap
+                     &get_our_version);
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
@@ -51,7 +52,7 @@ sub parse_master_master1 ($$) {
                    $oceans{$ocean}{$arch}{$_} .= $src;
                };
            });
                    $oceans{$ocean}{$arch}{$_} .= $src;
                };
            });
-       } elsif (m/^client (\S+)$/) {
+       } elsif (m/^client (\S+.*\S)$/) {
            my $client= $1;
            $clients{$client}= [ ];
            @ctx= (sub {
            my $client= $1;
            $clients{$client}= [ ];
            @ctx= (sub {
@@ -108,4 +109,15 @@ sub parse_pctb_commodmap () {
     return 1;
 }
 
     return 1;
 }
 
+sub get_our_version ($) {
+    my ($prefix);
+    {
+       no strict (qw(refs));
+       ${ "${prefix}name"  }= 'ypp-sc-tools yarrg';
+        ${ "${prefix}fixes" }= 'lastpage';
+        ${ "${prefix}version" }= `git-describe --tags HEAD`;
+        $? and die $?;
+    }
+}
+
 1;
 1;
index 2c409f48d4b4ce7557d85a9380a25a6ead30a24a..90c9c4beb01e8896bc93d41502e1eeb564baa906 100755 (executable)
@@ -63,13 +63,13 @@ sub must_param ($$) {
     my ($n,$re)= @_;
     my $v= param($n);
     fail("missing form parameter $n") unless defined $v;
     my ($n,$re)= @_;
     my $v= param($n);
     fail("missing form parameter $n") unless defined $v;
-    fail("invalid form parameter $n") unless $v =~ m/$re/;
+    fail("invalid form parameter $n ($re)") unless $v =~ m/$re/;
     return $1;
 }
 
 my $clientname= must_param('clientname',$re_any);
 my $clientinfo= $clients{$clientname};
     return $1;
 }
 
 my $clientname= must_param('clientname',$re_any);
 my $clientinfo= $clients{$clientname};
-fail('unknown client') unless defined $client;
+fail('unknown client') unless defined $clientinfo;
 
 my $clientfixes= must_param('clientfixes', "^([-0-9a-z ]*)\$");
 my @clientfixes= sort grep { m/./ } split /\s+/, $clientfixes;
 
 my $clientfixes= must_param('clientfixes', "^([-0-9a-z ]*)\$");
 my @clientfixes= sort grep { m/./ } split /\s+/, $clientfixes;
@@ -79,7 +79,7 @@ foreach my $bug (@$clientinfo) {
        unless grep { $_ eq $bug } @clientfixes;
 }
 
        unless grep { $_ eq $bug } @clientfixes;
 }
 
-my $cversion= must_param('clientversion', "^(\\d[-+._0-9a-zA-Z]+)\$");
+my $clientversion= must_param('clientversion', "^(\\d[-+._0-9a-zA-Z]+)\$");
 
 my $ocean= must_param('ocean', $re_any);
 my $island= must_param('island', $re_any);
 
 my $ocean= must_param('ocean', $re_any);
 my $island= must_param('island', $re_any);
@@ -96,25 +96,49 @@ foreach my $islands (values %$arches) {
 }
 fail("unknown island") unless $island_found;
 
 }
 fail("unknown island") unless $island_found;
 
+my $timestamp= must_param('timestamp', "^([1-9]\\d{1,20})\$");
+my $now= time;  defined $now or die $!;
+fail("clock skew") if $timestamp >= $now;
+
 die if $ocean =~ m/\=/;
 die if $island =~ m/\=/;
 
 die if $ocean =~ m/\=/;
 die if $island =~ m/\=/;
 
-$datafile= must_param('data',"^(deduped\\.tsv\\.gz)\$");
-$indatafh= upload('data');  fail("data is not a file") unless defined $datafh;
+my $indatafh= upload('data');
+defined $indatafh or fail("data is not a file");
+my $datafile= must_param('data',"^(deduped\\.tsv\\.gz)\$");
 
 our %done;
 
 
 our %done;
 
-my $content= MIME::Entity->build(Type => 'multipart/mixed',
-                                Boundary => '=',
-                                Charset => 'utf-8');
+my $mcontent= MIME::Entity->build(To => 'yarrg-commod-updates',
+                                 Type => 'multipart/mixed',
+                                 Boundary => '=',
+                                 Charset => 'utf-8');
+
+our ($servername,$serverversion,$serverfixes);
+get_our_version('::server');
 
 my $clientspec= "$clientname $clientversion $clientfixes";
 
 my $clientspec= "$clientname $clientversion $clientfixes";
-foreach $vn (qw(ocean island
-               clientspec
-               clientname clientversion clientfixes)) {
+my $serverspec= "$servername $serverversion $serverfixes";
+
+foreach my $vn (qw(ocean island timestamp
+                  clientspec clientname clientversion clientfixes
+                  serverspec servername serverversion serverfixes)) {
+    my $mpart= MIME::Entity->build(Type => 'text/plain',
+                                  Charset => 'utf-8',
+                                  Disposition => 'inline',
+                                  Data => $$vn);
+    $mcontent->add_part($mpart);
+}
 
 
-while (<$datafh>) {
+my $gunzchild= open(GZ, "-|") or die $!;
+if (!$gunzchild) {
+    open STDIN, "<&=", $indatafh or die $!;
+    execlp 'gunzip'; die $!;
+}
+
+while (<GZ>) {
     !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
     !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
+    !m/\\/ or bad_data('data contains backslashes');
     my @v= split /\t/;
     @v==6 or bad_data('wrong number of fields');
     my ($commod,$stall) = @v;
     my @v= split /\t/;
     @v==6 or bad_data('wrong number of fields');
     my ($commod,$stall) = @v;
@@ -122,17 +146,24 @@ while (<$datafh>) {
     $stall =~ m/^\p{IsUpper}/ or bad_data("stall not capitalised");
     !exists $done{$commod,$stall} or bad_data("repeated data");
     $done{$commod,$stall}= 1;
     $stall =~ m/^\p{IsUpper}/ or bad_data("stall not capitalised");
     !exists $done{$commod,$stall} or bad_data("repeated data");
     $done{$commod,$stall}= 1;
-    foreach my $f (@v[2..5]) {
+    foreach my $i (2..5) {
+       my $f= $v[$i];
        $f =~ m/^(0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field");
        $f =~ m/^(0|[1-9][0-9]{0,5}|\>1000)$/ or bad_data("bad field");
-       ($v % 1) or ($v !~ m/\>/) or bad_data("> in price");
+       ($i % 1) or ($f !~ m/\>/) or bad_data("> in price");
     }
 }
     }
 }
+GZ->error and die $!;
+$?=0; close GZ; $? and fail("gunzip for check failed code $?");
 
 
+my $mdatafile= MIME::Entity->build(Type => 'application/octet-streak',
+                                  Disposition => 'attachment',
+                                  Encoding => 'base64',
+                                  File => $datafile);
+$mcontent->add_part($mdatafile);
 
 
+open M, "|/usr/sbin/sendmail -t -oi -oee -odq"
+    or fail("fork sendmail failed! ($!)");
+$mcontent->print(\*M);
 
 
-
-#foreach my $commod (sort keys %commods) {
-#    print "$commod\n";
-#}
-#STDOUT->error and die $!;
-#close STDOUT or die $!;
+M->error and fail("write sendmail failed! ($!)");
+$?=0; close M; $? and fail("sendmail failed code $?");
index f5087ca91b1b315d7f501417a99b30ae281ee023..3753a43822f93690a3db6fb29905c60be295ef64 100644 (file)
@@ -164,5 +164,5 @@ ocean Midnight
   Remora Island
   Vernal Equinox
 
   Remora Island
   Vernal Equinox
 
-client ypp-sc-tools
+client ypp-sc-tools yarr
  lastpage
  lastpage