From 0d38f65c490466837ae091afa7a7b6f59d04ce7c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 8 Dec 2020 21:21:27 +0000 Subject: rename {pi_config} fields to {pi_cfg} {pi_config} may be confused with the documented `PI_CONFIG' environment variable, and we'll favor vowel-removal to be consistent with our usage of object references. The `pi_' prefix may stay in some places, for now; since a separate namespace may come into this codebase for local/private client-tooling. For InboxIdle, we'll also remove an invalid comment about holding a reference to the PublicInbox::Config object, too. --- lib/PublicInbox/Cgit.pm | 24 ++++++++++++------------ lib/PublicInbox/Config.pm | 2 +- lib/PublicInbox/ExtMsg.pm | 8 ++++---- lib/PublicInbox/IMAPD.pm | 28 ++++++++++++++-------------- lib/PublicInbox/Inbox.pm | 10 +++++----- lib/PublicInbox/InboxIdle.pm | 9 ++++----- lib/PublicInbox/MDA.pm | 4 ++-- lib/PublicInbox/ManifestJsGz.pm | 2 +- lib/PublicInbox/NNTP.pm | 22 +++++++++++----------- lib/PublicInbox/NNTPD.pm | 16 ++++++++-------- lib/PublicInbox/NewsWWW.pm | 15 +++++++-------- lib/PublicInbox/Qspawn.pm | 4 ++-- lib/PublicInbox/Spamcheck.pm | 4 ++-- lib/PublicInbox/Unsubscribe.pm | 6 +++--- lib/PublicInbox/WWW.pm | 27 +++++++++++++-------------- lib/PublicInbox/Watch.pm | 20 ++++++++++---------- lib/PublicInbox/WwwListing.pm | 4 ++-- lib/PublicInbox/WwwStream.pm | 2 +- lib/PublicInbox/WwwText.pm | 4 ++-- 19 files changed, 104 insertions(+), 107 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm index fb0d0e60..472509a8 100644 --- a/lib/PublicInbox/Cgit.pm +++ b/lib/PublicInbox/Cgit.pm @@ -16,9 +16,9 @@ use PublicInbox::Qspawn; use PublicInbox::WwwStatic qw(r); sub locate_cgit ($) { - my ($pi_config) = @_; - my $cgit_bin = $pi_config->{'publicinbox.cgitbin'}; - my $cgit_data = $pi_config->{'publicinbox.cgitdata'}; + my ($pi_cfg) = @_; + my $cgit_bin = $pi_cfg->{'publicinbox.cgitbin'}; + my $cgit_data = $pi_cfg->{'publicinbox.cgitdata'}; # /var/www/htdocs/cgit is the default install path from cgit.git # /usr/{lib,share}/cgit is where Debian puts cgit @@ -51,28 +51,28 @@ sub locate_cgit ($) { } sub new { - my ($class, $pi_config) = @_; - my ($cgit_bin, $cgit_data) = locate_cgit($pi_config); + my ($class, $pi_cfg) = @_; + my ($cgit_bin, $cgit_data) = locate_cgit($pi_cfg); my $self = bless { cmd => [ $cgit_bin ], cgit_data => $cgit_data, - pi_config => $pi_config, + pi_cfg => $pi_cfg, }, $class; - $pi_config->fill_all; # fill in -code_repos mapped to inboxes + $pi_cfg->fill_all; # fill in -code_repos mapped to inboxes # some cgit repos may not be mapped to inboxes, so ensure those exist: - my $code_repos = $pi_config->{-code_repos}; - foreach my $k (keys %$pi_config) { + my $code_repos = $pi_cfg->{-code_repos}; + foreach my $k (keys %$pi_cfg) { $k =~ /\Acoderepo\.(.+)\.dir\z/ or next; - my $dir = $pi_config->{$k}; + my $dir = $pi_cfg->{$k}; $code_repos->{$1} ||= PublicInbox::Git->new($dir); } while (my ($nick, $repo) = each %$code_repos) { $self->{"\0$nick"} = $repo; } - my $cgit_static = $pi_config->{-cgit_static}; + my $cgit_static = $pi_cfg->{-cgit_static}; my $static = join('|', map { quotemeta $_ } keys %$cgit_static); $self->{static} = qr/\A($static)\z/; $self; @@ -120,7 +120,7 @@ sub call { my $rdr = input_prepare($env) or return r(500); my $qsp = PublicInbox::Qspawn->new($self->{cmd}, $cgi_env, $rdr); - my $limiter = $self->{pi_config}->limiter('-cgit'); + my $limiter = $self->{pi_cfg}->limiter('-cgit'); $qsp->psgi_return($env, $limiter, $parse_cgi_headers); } diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 1844f8b2..cafd9c3b 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -425,7 +425,7 @@ EOF } $ibx->{name} = $name; - $ibx->{-pi_config} = $self; + $ibx->{-pi_cfg} = $self; $ibx = PublicInbox::Inbox->new($ibx); foreach (@{$ibx->{address}}) { my $lc_addr = lc($_); diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm index 43acfb53..8da96df6 100644 --- a/lib/PublicInbox/ExtMsg.pm +++ b/lib/PublicInbox/ExtMsg.pm @@ -105,8 +105,8 @@ sub ext_msg_step { sub ext_msg_ALL ($) { my ($ctx) = @_; - my $ALL = $ctx->{www}->{pi_config}->ALL or return; - my $by_eidx_key = $ctx->{www}->{pi_config}->{-by_eidx_key}; + my $ALL = $ctx->{www}->{pi_cfg}->ALL or return; + my $by_eidx_key = $ctx->{www}->{pi_cfg}->{-by_eidx_key}; my $cur_key = $ctx->{ibx}->eidx_key; my %seen = ($cur_key => 1); my ($id, $prev); @@ -139,11 +139,11 @@ sub ext_msg { if ($ctx->{env}->{'pi-httpd.async'}) { require PublicInbox::ConfigIter; my $iter = PublicInbox::ConfigIter->new( - $ctx->{www}->{pi_config}, + $ctx->{www}->{pi_cfg}, \&ext_msg_step, $ctx); $iter->event_step; } else { - $ctx->{www}->{pi_config}->each_inbox(\&ext_msg_i, $ctx); + $ctx->{www}->{pi_cfg}->each_inbox(\&ext_msg_i, $ctx); finalize_exact($ctx); } }; diff --git a/lib/PublicInbox/IMAPD.pm b/lib/PublicInbox/IMAPD.pm index 4a37734e..fb945847 100644 --- a/lib/PublicInbox/IMAPD.pm +++ b/lib/PublicInbox/IMAPD.pm @@ -19,12 +19,12 @@ sub new { err => \*STDERR, out => \*STDOUT, # accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... } - # pi_config => PublicInbox::Config + # pi_cfg => PublicInbox::Config # idler => PublicInbox::InboxIdle }, $class; } -sub imapd_refresh_ibx { # pi_config->each_inbox cb +sub imapd_refresh_ibx { # pi_cfg->each_inbox cb my ($ibx, $imapd) = @_; my $ngname = $ibx->{newsgroup} or return; @@ -60,7 +60,7 @@ sub imapd_refresh_ibx { # pi_config->each_inbox cb } sub imapd_refresh_finalize { - my ($imapd, $pi_config) = @_; + my ($imapd, $pi_cfg) = @_; my $mailboxes; if (my $next = delete $imapd->{imapd_next}) { $imapd->{mailboxes} = delete $next->{mailboxes}; @@ -78,40 +78,40 @@ sub imapd_refresh_finalize { qq[* LIST (\\Has${no}Children) "." $u\r\n] } keys %$mailboxes ]; - $imapd->{pi_config} = $pi_config; + $imapd->{pi_cfg} = $pi_cfg; if (my $idler = $imapd->{idler}) { - $idler->refresh($pi_config); + $idler->refresh($pi_cfg); } } -sub imapd_refresh_step { # pi_config->iterate_start cb - my ($pi_config, $section, $imapd) = @_; +sub imapd_refresh_step { # pi_cfg->iterate_start cb + my ($pi_cfg, $section, $imapd) = @_; if (defined($section)) { return if $section !~ m!\Apublicinbox\.([^/]+)\z!; - my $ibx = $pi_config->lookup_name($1) or return; + my $ibx = $pi_cfg->lookup_name($1) or return; imapd_refresh_ibx($ibx, $imapd->{imapd_next}); } else { # undef == "EOF" - imapd_refresh_finalize($imapd, $pi_config); + imapd_refresh_finalize($imapd, $pi_cfg); } } sub refresh_groups { my ($self, $sig) = @_; - my $pi_config = PublicInbox::Config->new; + my $pi_cfg = PublicInbox::Config->new; if ($sig) { # SIGHUP is handled through the event loop $self->{imapd_next} = { dummies => {}, mailboxes => {} }; - my $iter = PublicInbox::ConfigIter->new($pi_config, + my $iter = PublicInbox::ConfigIter->new($pi_cfg, \&imapd_refresh_step, $self); $iter->event_step; } else { # initial start is synchronous $self->{dummies} = {}; - $pi_config->each_inbox(\&imapd_refresh_ibx, $self); - imapd_refresh_finalize($self, $pi_config); + $pi_cfg->each_inbox(\&imapd_refresh_ibx, $self); + imapd_refresh_finalize($self, $pi_cfg); } } sub idler_start { - $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_config}); + $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg}); } 1; diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 52aece7c..586bd561 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -85,7 +85,7 @@ sub _set_uint ($$$) { } sub _set_limiter ($$$) { - my ($self, $pi_config, $pfx) = @_; + my ($self, $pi_cfg, $pfx) = @_; my $lkey = "-${pfx}_limiter"; $self->{$lkey} ||= do { # full key is: publicinbox.$NAME.httpbackendmax @@ -96,7 +96,7 @@ sub _set_limiter ($$$) { require PublicInbox::Qspawn; $lim = PublicInbox::Qspawn::Limiter->new($val); } elsif ($val =~ /\A[a-z][a-z0-9]*\z/) { - $lim = $pi_config->limiter($val); + $lim = $pi_cfg->limiter($val); warn "$mkey limiter=$val not found\n" if !$lim; } else { warn "$mkey limiter=$val not understood\n"; @@ -110,10 +110,10 @@ sub new { my $v = $opts->{address} ||= [ 'public-inbox@example.com' ]; my $p = $opts->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v; $opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost'; - my $pi_config = delete $opts->{-pi_config}; - _set_limiter($opts, $pi_config, 'httpbackend'); + my $pi_cfg = delete $opts->{-pi_cfg}; + _set_limiter($opts, $pi_cfg, 'httpbackend'); _set_uint($opts, 'feedmax', 25); - $opts->{nntpserver} ||= $pi_config->{'publicinbox.nntpserver'}; + $opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'}; my $dir = $opts->{inboxdir}; if (defined $dir && -f "$dir/inbox.lock") { $opts->{version} = 2; diff --git a/lib/PublicInbox/InboxIdle.pm b/lib/PublicInbox/InboxIdle.pm index 0cdd2e2a..2737bbbd 100644 --- a/lib/PublicInbox/InboxIdle.pm +++ b/lib/PublicInbox/InboxIdle.pm @@ -2,7 +2,6 @@ # License: AGPL-3.0+ # fields: -# pi_config: PublicInbox::Config ref # inot: Linux::Inotify2-like object # pathmap => { inboxdir => [ ibx, watch1, watch2, watch3... ] } mapping package PublicInbox::InboxIdle; @@ -51,12 +50,12 @@ sub in2_arm ($$) { # PublicInbox::Config::each_inbox callback } sub refresh { - my ($self, $pi_config) = @_; - $pi_config->each_inbox(\&in2_arm, $self); + my ($self, $pi_cfg) = @_; + $pi_cfg->each_inbox(\&in2_arm, $self); } sub new { - my ($class, $pi_config) = @_; + my ($class, $pi_cfg) = @_; my $self = bless {}, $class; my $inot; if ($ino_cls) { @@ -70,7 +69,7 @@ sub new { $self->{inot} = $inot; $self->{pathmap} = {}; # inboxdir => [ ibx, watch1, watch2, watch3...] $self->{on_unlock} = {}; # lock path => ibx - refresh($self, $pi_config); + refresh($self, $pi_cfg); PublicInbox::FakeInotify::poll_once($self) if !$ino_cls; $self; } diff --git a/lib/PublicInbox/MDA.pm b/lib/PublicInbox/MDA.pm index fa4a2ad8..0377a877 100644 --- a/lib/PublicInbox/MDA.pm +++ b/lib/PublicInbox/MDA.pm @@ -83,7 +83,7 @@ sub set_list_headers { } sub inboxes_for_list_id ($$) { - my ($klass, $config, $simple) = @_; + my ($klass, $pi_cfg, $simple) = @_; # newer Email::Simple allows header_raw, as does Email::MIME: my @list_ids = $simple->can('header_raw') ? @@ -92,7 +92,7 @@ sub inboxes_for_list_id ($$) { my @dests; for my $list_id (@list_ids) { $list_id =~ /<[ \t]*(.+)?[ \t]*>/ or next; - if (my $ibx = $config->lookup_list_id($1)) { + if (my $ibx = $pi_cfg->lookup_list_id($1)) { push @dests, $ibx; } } diff --git a/lib/PublicInbox/ManifestJsGz.pm b/lib/PublicInbox/ManifestJsGz.pm index 2c4a231d..fb7a45e7 100644 --- a/lib/PublicInbox/ManifestJsGz.pm +++ b/lib/PublicInbox/ManifestJsGz.pm @@ -71,7 +71,7 @@ sub eidx_manifest_add ($$$) { sub ibx_entry { my ($ctx, $ibx) = @_; - my $ALL = $ctx->{www}->{pi_config}->ALL; + my $ALL = $ctx->{www}->{pi_cfg}->ALL; if ($ALL) { eidx_manifest_add($ctx, $ALL, $ibx); } else { diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 766ea89e..0b43cdbc 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -129,7 +129,7 @@ sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) my ($self, $groupnames) = @_; my @window = splice(@$groupnames, 0, 100) or return 0; my $ibx; - my $groups = $self->{nntpd}->{pi_config}->{-by_newsgroup}; + my $groups = $self->{nntpd}->{pi_cfg}->{-by_newsgroup}; for my $ngname (@window) { $ibx = $groups->{$ngname} and group_line($self, $ibx); } @@ -146,7 +146,7 @@ sub list_active ($;$) { # called by cmd_list sub list_active_times_i { my ($self, $groupnames) = @_; my @window = splice(@$groupnames, 0, 100) or return 0; - my $groups = $self->{nntpd}->{pi_config}->{-by_newsgroup}; + my $groups = $self->{nntpd}->{pi_cfg}->{-by_newsgroup}; for my $ngname (@window) { my $ibx = $groups->{$ngname} or next; my $c = eval { $ibx->uidvalidity } // time; @@ -165,7 +165,7 @@ sub list_active_times ($;$) { # called by cmd_list sub list_newsgroups_i { my ($self, $groupnames) = @_; my @window = splice(@$groupnames, 0, 100) or return 0; - my $groups = $self->{nntpd}->{pi_config}->{-by_newsgroup}; + my $groups = $self->{nntpd}->{pi_cfg}->{-by_newsgroup}; my $ibx; for my $ngname (@window) { $ibx = $groups->{$ngname} and @@ -268,7 +268,7 @@ sub group_line ($$) { sub newgroups_i { my ($self, $ts, $i, $groupnames) = @_; my $end = $$i + 100; - my $groups = $self->{nntpd}->{pi_config}->{-by_newsgroup}; + my $groups = $self->{nntpd}->{pi_cfg}->{-by_newsgroup}; while ($$i < $end) { my $ngname = $groupnames->[$$i++] // return; my $ibx = $groups->{$ngname} or next; # expired on reload @@ -323,7 +323,7 @@ sub ngpat2re (;$) { sub newnews_i { my ($self, $names, $ts, $prev) = @_; my $ngname = $names->[0]; - if (my $ibx = $self->{nntpd}->{pi_config}->{-by_newsgroup}->{$ngname}) { + if (my $ibx = $self->{nntpd}->{pi_cfg}->{-by_newsgroup}->{$ngname}) { if (my $over = $ibx->over) { my $msgs = $over->query_ts($ts, $$prev); if (scalar @$msgs) { @@ -362,7 +362,7 @@ sub cmd_newnews ($$$$;$$) { sub cmd_group ($$) { my ($self, $group) = @_; my $nntpd = $self->{nntpd}; - my $ibx = $nntpd->{pi_config}->{-by_newsgroup}->{$group} or + my $ibx = $nntpd->{pi_cfg}->{-by_newsgroup}->{$group} or return '411 no such news group'; $nntpd->idler_start; @@ -439,13 +439,13 @@ sub xref ($$$) { my $nntpd = $self->{nntpd}; my $cur_ng = $cur_ibx->{newsgroup}; my $xref; - if (my $ALL = $nntpd->{pi_config}->ALL) { + if (my $ALL = $nntpd->{pi_cfg}->ALL) { $xref = $ALL->nntp_xref_for($cur_ibx, $smsg); - xref_by_tc($xref, $nntpd->{pi_config}, $smsg); + xref_by_tc($xref, $nntpd->{pi_cfg}, $smsg); } else { # slow path $xref = { $cur_ng => $smsg->{num} }; my $mid = $smsg->{mid}; - for my $ibx (values %{$nntpd->{pi_config}->{-by_newsgroup}}) { + for my $ibx (values %{$nntpd->{pi_cfg}->{-by_newsgroup}}) { next if defined($xref->{$ibx->{newsgroup}}); my $num = eval { $ibx->mm->num_for($mid) } // next; $xref->{$ibx->{newsgroup}} = $num; @@ -733,7 +733,7 @@ sub mid_lookup ($$) { my $n = $cur_ibx->mm->num_for($mid); return ($cur_ibx, $n) if defined $n; } - my $pi_cfg = $self->{nntpd}->{pi_config}; + my $pi_cfg = $self->{nntpd}->{pi_cfg}; if (my $ALL = $pi_cfg->ALL) { my ($id, $prev); while (my $smsg = $ALL->over->next_by_mid($mid, \$id, \$prev)) { @@ -1014,7 +1014,7 @@ sub cmd_xpath ($$) { return r501 unless $mid =~ $ONE_MSGID; $mid = $1; my @paths; - my $pi_cfg = $self->{nntpd}->{pi_config}; + my $pi_cfg = $self->{nntpd}->{pi_cfg}; my $groups = $pi_cfg->{-by_newsgroup}; if (my $ALL = $pi_cfg->ALL) { my ($id, $prev, %seen); diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm index 03c56db3..953228d0 100644 --- a/lib/PublicInbox/NNTPD.pm +++ b/lib/PublicInbox/NNTPD.pm @@ -12,8 +12,8 @@ use PublicInbox::InboxIdle; sub new { my ($class) = @_; - my $pi_config = PublicInbox::Config->new; - my $name = $pi_config->{'publicinbox.nntpserver'}; + my $pi_cfg = PublicInbox::Config->new; + my $name = $pi_cfg->{'publicinbox.nntpserver'}; if (!defined($name) or $name eq '') { $name = hostname; } elsif (ref($name) eq 'ARRAY') { @@ -24,7 +24,7 @@ sub new { groups => {}, err => \*STDERR, out => \*STDOUT, - pi_config => $pi_config, + pi_cfg => $pi_cfg, servername => $name, greet => \"201 $name ready - post via email\r\n", # accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... } @@ -34,9 +34,9 @@ sub new { sub refresh_groups { my ($self, $sig) = @_; - my $pi_config = $sig ? PublicInbox::Config->new : $self->{pi_config}; - my $groups = $pi_config->{-by_newsgroup}; # filled during each_inbox - $pi_config->each_inbox(sub { + my $pi_cfg = $sig ? PublicInbox::Config->new : $self->{pi_cfg}; + my $groups = $pi_cfg->{-by_newsgroup}; # filled during each_inbox + $pi_cfg->each_inbox(sub { my ($ibx) = @_; my $ngname = $ibx->{newsgroup}; if (defined($ngname) && $ibx->nntp_usable) { @@ -54,11 +54,11 @@ sub refresh_groups { }); $self->{groupnames} = [ sort(keys %$groups) ]; # this will destroy old groups that got deleted - $self->{pi_config} = $pi_config; + $self->{pi_cfg} = $pi_cfg; } sub idler_start { - $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_config}); + $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_cfg}); } 1; diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm index ade8dfd1..61d9ae7c 100644 --- a/lib/PublicInbox/NewsWWW.pm +++ b/lib/PublicInbox/NewsWWW.pm @@ -13,9 +13,8 @@ use PublicInbox::MID qw(mid_escape); use PublicInbox::Hval qw(prurl); sub new { - my ($class, $pi_config) = @_; - $pi_config ||= PublicInbox::Config->new; - bless { pi_config => $pi_config }, $class; + my ($class, $pi_cfg) = @_; + bless { pi_cfg => $pi_cfg // PublicInbox::Config->new }, $class; } sub redirect ($$) { @@ -47,8 +46,8 @@ sub call { # /inbox.foo.bar/123456 my (undef, @parts) = split(m!/!, $env->{PATH_INFO}); my ($ng, $article) = @parts; - my $pi_config = $self->{pi_config}; - if (my $ibx = $pi_config->lookup_newsgroup($ng)) { + my $pi_cfg = $self->{pi_cfg}; + if (my $ibx = $pi_cfg->lookup_newsgroup($ng)) { my $url = prurl($env, $ibx->{url}); my $code = 301; if (defined $article && $article =~ /\A[0-9]+\z/) { @@ -71,9 +70,9 @@ sub call { pop @parts; push @try, join('/', @parts); } - my $ALL = $pi_config->ALL; + my $ALL = $pi_cfg->ALL; if (my $over = $ALL ? $ALL->over : undef) { - my $by_eidx_key = $pi_config->{-by_eidx_key}; + my $by_eidx_key = $pi_cfg->{-by_eidx_key}; for my $mid (@try) { my ($id, $prev); while (my $x = $over->next_by_mid($mid, \$id, \$prev)) { @@ -90,7 +89,7 @@ sub call { } else { # slow path, scan every inbox for my $mid (@try) { my $arg = [ $mid ]; # [1] => result - $pi_config->each_inbox(\&try_inbox, $arg); + $pi_cfg->each_inbox(\&try_inbox, $arg); return $arg->[1] if $arg->[1]; } } diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index 88b6d390..2aa2042a 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -359,12 +359,12 @@ sub new { } sub setup_rlimit { - my ($self, $name, $config) = @_; + my ($self, $name, $cfg) = @_; foreach my $rlim (@PublicInbox::Spawn::RLIMITS) { my $k = lc($rlim); $k =~ tr/_//d; $k = "publicinboxlimiter.$name.$k"; - defined(my $v = $config->{$k}) or next; + defined(my $v = $cfg->{$k}) or next; my @rlimit = split(/\s*,\s*/, $v); if (scalar(@rlimit) == 1) { push @rlimit, $rlimit[0]; diff --git a/lib/PublicInbox/Spamcheck.pm b/lib/PublicInbox/Spamcheck.pm index ffebb3cf..218fcc01 100644 --- a/lib/PublicInbox/Spamcheck.pm +++ b/lib/PublicInbox/Spamcheck.pm @@ -7,8 +7,8 @@ use strict; use warnings; sub get { - my ($config, $key, $default) = @_; - my $spamcheck = $config->{$key}; + my ($cfg, $key, $default) = @_; + my $spamcheck = $cfg->{$key}; $spamcheck = $default unless $spamcheck; return if !$spamcheck || $spamcheck eq 'none'; diff --git a/lib/PublicInbox/Unsubscribe.pm b/lib/PublicInbox/Unsubscribe.pm index 945e7ae7..b0d3220c 100644 --- a/lib/PublicInbox/Unsubscribe.pm +++ b/lib/PublicInbox/Unsubscribe.pm @@ -39,7 +39,7 @@ sub new { die "`unsubscribe' callback not given\n"; bless { - pi_config => $opt{pi_config}, # PublicInbox::Config + pi_cfg => $opt{pi_config}, # PublicInbox::Config owner_email => $opt{owner_email}, cipher => $cipher, unsubscribe => $unsubscribe, @@ -149,9 +149,9 @@ sub archive_info { my $archive_url = $self->{archive_urls}->{$list_addr}; unless ($archive_url) { - if (my $config = $self->{pi_config}) { + if (my $cfg = $self->{pi_cfg}) { # PublicInbox::Config::lookup - my $ibx = $config->lookup($list_addr); + my $ibx = $cfg->lookup($list_addr); # PublicInbox::Inbox::base_url $archive_url = $ibx->base_url if $ibx; } diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 6bae2190..a33d25ab 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -32,9 +32,8 @@ our $ATTACH_RE = qr!([0-9][0-9\.]*)-($PublicInbox::Hval::FN)!; our $OID_RE = qr![a-f0-9]{7,}!; sub new { - my ($class, $pi_config) = @_; - $pi_config ||= PublicInbox::Config->new; - bless { pi_config => $pi_config }, $class; + my ($class, $pi_cfg) = @_; + bless { pi_cfg => $pi_cfg // PublicInbox::Config->new }, $class; } # backwards compatibility, do not use @@ -169,14 +168,14 @@ sub preload { eval "require PublicInbox::$_;"; } if (ref($self)) { - my $pi_config = $self->{pi_config}; - if (defined($pi_config->{'publicinbox.cgitrc'})) { - $pi_config->limiter('-cgit'); + my $pi_cfg = $self->{pi_cfg}; + if (defined($pi_cfg->{'publicinbox.cgitrc'})) { + $pi_cfg->limiter('-cgit'); } $self->cgit; $self->stylesheets_prepare($_) for ('', '../', '../../'); $self->news_www; - $pi_config->each_inbox(\&preload_inbox); + $pi_cfg->each_inbox(\&preload_inbox); } } @@ -210,8 +209,8 @@ sub news_cgit_fallback ($) { # returns undef if valid, array ref response if invalid sub invalid_inbox ($$) { my ($ctx, $inbox) = @_; - my $ibx = $ctx->{www}->{pi_config}->lookup_name($inbox) // - $ctx->{www}->{pi_config}->lookup_ei($inbox); + my $ibx = $ctx->{www}->{pi_cfg}->lookup_name($inbox) // + $ctx->{www}->{pi_cfg}->lookup_ei($inbox); if (defined $ibx) { $ctx->{ibx} = $ibx; return; @@ -481,18 +480,18 @@ sub news_www { my ($self) = @_; $self->{news_www} ||= do { require PublicInbox::NewsWWW; - PublicInbox::NewsWWW->new($self->{pi_config}); + PublicInbox::NewsWWW->new($self->{pi_cfg}); } } sub cgit { my ($self) = @_; $self->{cgit} ||= do { - my $pi_config = $self->{pi_config}; + my $pi_cfg = $self->{pi_cfg}; - if (defined($pi_config->{'publicinbox.cgitrc'})) { + if (defined($pi_cfg->{'publicinbox.cgitrc'})) { require PublicInbox::Cgit; - PublicInbox::Cgit->new($pi_config); + PublicInbox::Cgit->new($pi_cfg); } else { require Plack::Util; Plack::Util::inline_object(call => sub { r404() }); @@ -538,7 +537,7 @@ sub stylesheets_prepare ($$) { } || sub { $_[0] }; my $css_map = {}; - my $stylesheets = $self->{pi_config}->{css} || []; + my $stylesheets = $self->{pi_cfg}->{css} || []; my $links = []; my $inline_ok = 1; diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index 8bbce929..e1246096 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -41,7 +41,7 @@ sub compile_watchheaders ($) { } sub new { - my ($class, $config) = @_; + my ($class, $cfg) = @_; my (%mdmap, $spamc); my (%imap, %nntp); # url => [inbox objects] or 'watchspam' @@ -50,7 +50,7 @@ sub new { # indefinitely... foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) { my $k = "$pfx.watchspam"; - defined(my $dirs = $config->{$k}) or next; + defined(my $dirs = $cfg->{$k}) or next; $dirs = PublicInbox::Config::_array($dirs); for my $dir (@$dirs) { my $url; @@ -69,10 +69,10 @@ sub new { my $k = 'publicinboxwatch.spamcheck'; my $default = undef; - my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default); + my $spamcheck = PublicInbox::Spamcheck::get($cfg, $k, $default); $spamcheck = _spamcheck_cb($spamcheck) if $spamcheck; - $config->each_inbox(sub { + $cfg->each_inbox(sub { # need to make all inboxes writable for spam removal: my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]); @@ -113,7 +113,7 @@ sub new { spamcheck => $spamcheck, mdmap => \%mdmap, mdre => $mdre, - config => $config, + pi_cfg => $cfg, imap => scalar keys %imap ? \%imap : undef, nntp => scalar keys %nntp? \%nntp : undef, importers => {}, @@ -175,7 +175,7 @@ sub _remove_spam { $path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return; my $eml = eml_from_path($path) or return; local $SIG{__WARN__} = warn_ignore_cb(); - $self->{config}->each_inbox(\&remove_eml_i, $self, $eml, $path); + $self->{pi_cfg}->each_inbox(\&remove_eml_i, $self, $eml, $path); } sub import_eml ($$$) { @@ -316,7 +316,7 @@ sub cfg_bool ($$$) { # flesh out common IMAP-specific data structures sub imap_common_init ($) { my ($self) = @_; - my $cfg = $self->{config}; + my $cfg = $self->{pi_cfg}; my $mic_args = {}; # scheme://authority => Mail:IMAPClient arg for my $url (sort keys %{$self->{imap}}) { my $uri = PublicInbox::URIimap->new($url); @@ -418,7 +418,7 @@ sub imap_import_msg ($$$$$) { if ($flags =~ /\\Seen\b/) { local $SIG{__WARN__} = warn_ignore_cb(); my $eml = PublicInbox::Eml->new($raw); - $self->{config}->each_inbox(\&remove_eml_i, + $self->{pi_cfg}->each_inbox(\&remove_eml_i, $self, $eml, "$url UID:$uid"); } } else { @@ -775,7 +775,7 @@ sub watch_imap_init ($$) { # flesh out common NNTP-specific data structures sub nntp_common_init ($) { my ($self) = @_; - my $cfg = $self->{config}; + my $cfg = $self->{pi_cfg}; my $nn_args = {}; # scheme://authority => Net::NNTP->new arg for my $url (sort keys %{$self->{nntp}}) { my $sec = uri_section(uri_new($url)); @@ -966,7 +966,7 @@ sub nntp_fetch_all ($$$) { } } elsif ($inboxes eq 'watchspam') { my $eml = PublicInbox::Eml->new(\$raw); - $self->{config}->each_inbox(\&remove_eml_i, + $self->{pi_cfg}->each_inbox(\&remove_eml_i, $self, $eml, "$url ARTICLE $art"); } else { die "BUG: destination unknown $inboxes"; diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index bda2761c..fce0e530 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -44,7 +44,7 @@ sub url_regexp { my ($ctx, $key, $default) = @_; $key //= 'publicInbox.wwwListing'; $default //= '404'; - my $v = $ctx->{www}->{pi_config}->{lc $key} // $default; + 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}; @@ -70,7 +70,7 @@ sub response { my ($class, $ctx) = @_; bless $ctx, $class; my $re = $ctx->url_regexp or return $ctx->psgi_triple; - my $iter = PublicInbox::ConfigIter->new($ctx->{www}->{pi_config}, + my $iter = PublicInbox::ConfigIter->new($ctx->{www}->{pi_cfg}, \&list_match_i, $re, $ctx); sub { $ctx->{-wcb} = $_[0]; # HTTP server callback diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index 849831a6..34e12435 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -81,7 +81,7 @@ sub coderepos ($) { my $ibx = $ctx->{ibx}; my @ret; if (defined(my $cr = $ibx->{coderepo})) { - my $cfg = $ctx->{www}->{pi_config}; + my $cfg = $ctx->{www}->{pi_cfg}; my $env = $ctx->{env}; for my $cr_name (@$cr) { my $urls = $cfg->{"coderepo.$cr_name.cgiturl"}; diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 53e15e45..a8560916 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -189,9 +189,9 @@ EOF ; line number ranges in `[PATCH]' emails link to /$INBOX_NAME/$OID/s/, ; an HTTP endpoint which reconstructs git blobs via git-apply(1). EOF - my $pi_config = $ctx->{www}->{pi_config}; + my $pi_cfg = $ctx->{www}->{pi_cfg}; for my $cr_name (@$cr) { - my $urls = $pi_config->{"coderepo.$cr_name.cgiturl"}; + my $urls = $pi_cfg->{"coderepo.$cr_name.cgiturl"}; my $path = "/path/to/$cr_name"; $cr_name = dq_escape($cr_name); -- cgit v1.2.3-24-ge0c7