chiark / gitweb /
WIP update processor, generating outgoing email
authorIan Jackson <ian@liberator.(none)>
Wed, 22 Jul 2009 14:40:56 +0000 (15:40 +0100)
committerIan Jackson <ian@liberator.(none)>
Wed, 22 Jul 2009 14:40:56 +0000 (15:40 +0100)
pctb/commod-update-receiver

index ff28fbb019ad54d9c0b6a9c923114e4f9bcf067b..2c409f48d4b4ce7557d85a9380a25a6ead30a24a 100755 (executable)
@@ -32,7 +32,7 @@
 #  clientname                  "ypp-sc-tools"
 #  clientversion               2.1-g2e06a26  [from git-describe --tags HEAD]
 #  clientfixes                 "lastpage"  [space separated list]
-#  deduped.tsv.gz              output of ypp-commodities --tsv
+#  data filename=deduped.tsv.gz        output of ypp-commodities --tsv
 
 use strict (qw(vars));
 use POSIX;
@@ -68,13 +68,15 @@ sub must_param ($$) {
 }
 
 my $clientname= must_param('clientname',$re_any);
-my $client= $clients{$clientname};
+my $clientinfo= $clients{$clientname};
 fail('unknown client') unless defined $client;
 
-my $clientfixes= must_param('clientfixes', $re_any);
-foreach my $bug (@$client) {
+my $clientfixes= must_param('clientfixes', "^([-0-9a-z ]*)\$");
+my @clientfixes= sort grep { m/./ } split /\s+/, $clientfixes;
+$clientfixes= "@clientfixes";
+foreach my $bug (@$clientinfo) {
     fail("client out of date - missing bugfix \`$bug'")
-       unless grep { $_ eq $bug } split /\s+/, $clientfixes;
+       unless grep { $_ eq $bug } @clientfixes;
 }
 
 my $cversion= must_param('clientversion', "^(\\d[-+._0-9a-zA-Z]+)\$");
@@ -94,6 +96,41 @@ foreach my $islands (values %$arches) {
 }
 fail("unknown island") unless $island_found;
 
+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;
+
+our %done;
+
+my $content= MIME::Entity->build(Type => 'multipart/mixed',
+                                Boundary => '=',
+                                Charset => 'utf-8');
+
+my $clientspec= "$clientname $clientversion $clientfixes";
+foreach $vn (qw(ocean island
+               clientspec
+               clientname clientversion clientfixes)) {
+
+while (<$datafh>) {
+    !m/\P{IsPrint}/ or die bad_data('nonprinting char(s)');
+    my @v= split /\t/;
+    @v==6 or bad_data('wrong number of fields');
+    my ($commod,$stall) = @v;
+    defined $commods{$commod} or bad_data("unknown commodity \`$commod'");
+    $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]) {
+       $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");
+    }
+}
+
+
+
+
 #foreach my $commod (sort keys %commods) {
 #    print "$commod\n";
 #}