use DBI;
use Digest::SHA qw(sha256_hex);
use MIME::Base64;
+use POSIX;
###--------------------------------------------------------------------------
### Early utilities.
qr{^https?://}
);
+our $PASTEMAXLEN = 1024*1024;
+
our %COOKIE_DEFAULTS = (
-httponly => undef,
-max_age => 3600
return lc $s;
}
+sub print_columns (@) {
+ my @col = reverse @_;
+ my @fmt = ();
+ my @val = ();
+ while (@col && $col[1] eq "") { splice @col, 0, 2; }
+ my ($wd, $v) = splice @col, 0, 2;
+ push @fmt, "%s"; push @val, $v;
+ while (@col) {
+ my ($wd, $v) = splice @col, 0, 2;
+ push @fmt, "%-${wd}s";
+ push @val, $v;
+ }
+ printf join(" ", reverse @fmt) . "\n", reverse @val;
+}
+
+sub fmt_time ($) {
+ my ($t) = @_;
+ return $t == -1 ? "--" : strftime "%Y-%m-%d %H:%M:%S %z", localtime $t;
+}
+
###--------------------------------------------------------------------------
### Database utilities.
return undef unless defined $content;
$content =~ tr/\r//d;
$content =~ s/([^\n])\z/$1\n/;
+ length $content <= $PASTEMAXLEN or
+ fail "invalid paste content", ".badpaste";
return $content;
}