begin
-- TODO improve this regular expression
- NEW.expires = regexp_replace(header_value(header, 'Expires'),E'\\([^\\)]*\\)', ' ')::timestamptz;
+ NEW.expires = regexp_replace(header_value(NEW.header, 'Expires'),E'\\([^\\)]*\\)', ' ')::timestamptz;
exception
when OTHERS then NEW.expires = NULL;
end;
+ -- TODO if date is null?
+ begin
+ -- TODO improve this regular expression
+ NEW.date = regexp_replace(header_value(NEW.header, 'Date'),E'\\([^\\)]*\\)', ' ')::timestamptz;
+ exception
+ when OTHERS then NEW.date = NULL;
+ end;
+
if NEW.header is null then
raise exception 'null header b';
end if;
declare
hiwater integer;
begin
- select high + 1 from newsgroups where newsgroup = NEW.newsgroup
- for update into hiwater;
+ update newsgroups set high = high + 1
+ where newsgroup = NEW.newsgroup returning high into hiwater;
+
NEW.number := hiwater;
- update newsgroups set high = high + 1 where newsgroup = NEW.newsgroup;
return NEW;
end;
$$ language 'plpgsql';
+
create trigger highwater before insert on xpost
for each row execute procedure xpost_trigger();
--- /dev/null
+#!/usr/bin/perl
+
+use Test::More tests => 14;
+
+BEGIN { use_ok('Net::Cmd') }
+BEGIN { use_ok('Net::NNTP') }
+
+my $c = Net::NNTP->new(Host => '127.0.0.1', Port => 20203, Reader => 0);
+
+ok(defined $c, 'connected to localhost');
+
+BAIL_OUT(q{can't connect to test server'}) unless $c;
+
+sub Net::NNTP::issue {
+ my ($c, @cmd) = @_;
+ $c->command(@cmd);
+ $c->response();
+ return $c->code();
+}
+
+sub Net::NNTP::test {
+ my ($c, $valid, @cmd) = @_;
+ $c->response();
+ ok(grep {$c->code == $_} @$valid, "valid response for @$cmd = @$valid");
+ return $c->code;
+}
+
+# 3977:5.1.1 initial greeting must be 200 201 400 502
+my @valid = (200, 201, 400, 502);
+my $greeting = $c->code;
+
+ok(grep {$c->code == $_} @valid, 'correct initial response from server');
+
+unless ($greeting == 200 or $greeting = 201) {
+ goto done;
+}
+
+$c->command('CAPABILITIES');
+$c->response();
+is($c->code, 101, 'correct response to capabilities');
+$c->read_until_dot() if ($c->code == 101);
+
+$c->command('capabilities');
+$c->response();
+is($c->code, 101, 'lower case capabilities ok');
+my $capabilities = $c->read_until_dot() if ($c->code == 101);
+
+my %cap = ();
+my $twice = 0;
+foreach my $line (@$capabilities) {
+ my ($capability, @arg) = split(/\s+/, $line);
+ if (exists($cap{$capability})) {
+ $twice = 1;
+ }
+ $cap{$cap} = \@arg;
+}
+
+ok($twice == 0, 'Capability listed twice (3977:5.2.2)');
+
+$capabilities->[0] =~ /(VERSION) (\d+)(\r?)(\n)/;
+
+is($1, 'VERSION', 'VERSION capability first');
+is($2, 2, 'Version 2 server');
+
+unless ($2==2) {
+ diag('can only test version 2 servers');
+ goto quit;
+}
+
+SKIP: {
+ skip 'Net::Cmd strips \r, skipping \r\n testing', 2;
+ is($3, "\r", 'Server terminated line with \r');
+ is($4, "\n", 'Server terminated line with \n');
+}
+
+is($c->issue('aninvalidcommand'), 500, 'responds with 500 to unknown command');
+
+SKIP: {
+ skip 'No LIST capability, skipping list tests', 1 unless $cap{'LIST'};
+ is($c->issue('list aninvalidlist'), 501, 'responds with 501 to unknown list');
+}
+
+# RFC 4644
+if ($cap{'STREAMING'}) {
+ # check mode stream
+}
+
+quit:
+
+$c->command('QUIT');
+$c->response;
+is($c->code, 205, 'correct response to quit');
+
+done:
+done_testing();
+exit 0;
+
+sub checkcmd {
+ my ($cmd, $args, $valid) = @_;
+}