-sub list_404 ($$) { [] }
-
-# TODO: +cgit
-my %VALID = (
- all => *list_all,
- 'match=domain' => *list_match_domain,
- 404 => *list_404,
-);
-
-sub new {
- my ($class, $www) = @_;
- my $k = 'publicinbox.wwwListing';
- my $pi_config = $www->{pi_config};
- my $v = $pi_config->{lc($k)} // 404;
- bless {
- pi_config => $pi_config,
- style => $www->style("\0"),
- list_cb => $VALID{$v} || do {
- warn <<"";
-`$v' is not a valid value for `$k'
-$k be one of `all', `match=domain', or `404'
-
- *list_404;
- },
- }, $class;
+sub url_regexp {
+ my ($ctx, $key, $default) = @_;
+ $key //= 'publicInbox.wwwListing';
+ $default //= '404';
+ my $v = $ctx->{www}->{pi_cfg}->{lc $key} // $default;
+again:
+ if ($v eq 'match=domain') {
+ my $h = $ctx->{env}->{HTTP_HOST} // $ctx->{env}->{SERVER_NAME};
+ $h =~ s/:[0-9]+\z//;
+ qr!\A(?:https?:)?//\Q$h\E(?::[0-9]+)?/!i;
+ } elsif ($v eq 'all') {
+ qr/./;
+ } elsif ($v eq '404') {
+ undef;
+ } else {
+ warn <<EOF;
+`$v' is not a valid value for `$key'
+$key be one of `all', `match=domain', or `404'
+EOF
+ $v = $default; # 'match=domain' or 'all'
+ goto again;
+ }