unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/7] miscellaneous cleanups
@ 2016-05-28  1:57 Eric Wong
  2016-05-28  1:57 ` [PATCH 1/7] t/plack: ensure we can cascade on common endpoints Eric Wong
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

Only the last one (NewsGroup class removal for ::Inbox) is
likely to cause problems but I'll be checking logs for
errors.

Eric Wong (7):
      t/plack: ensure we can cascade on common endpoints
      http: clarify comments about layering violation
      Makefile.PL: allow N to be overridden
      examples: config no longer supports atomUrl
      www: remove footer_html support
      config: remove try_cat
      remove redundant NewsGroup class

 MANIFEST                     |  1 -
 Makefile.PL                  |  2 +-
 examples/public-inbox-config |  1 -
 lib/PublicInbox/Config.pm    | 49 +++++++++++++++-----------
 lib/PublicInbox/HTTP.pm      |  6 ++--
 lib/PublicInbox/Inbox.pm     | 17 ++++-----
 lib/PublicInbox/NNTP.pm      |  9 ++---
 lib/PublicInbox/NNTPD.pm     | 27 ++++----------
 lib/PublicInbox/NewsGroup.pm | 84 --------------------------------------------
 lib/PublicInbox/NewsWWW.pm   | 38 ++------------------
 lib/PublicInbox/WWW.pm       |  6 ++--
 t/config.t                   |  2 ++
 t/nntp.t                     | 15 +++++---
 t/nntpd.t                    |  4 ++-
 t/plack.t                    | 12 +++++--
 15 files changed, 83 insertions(+), 190 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] t/plack: ensure we can cascade on common endpoints
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 2/7] http: clarify comments about layering violation Eric Wong
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

We don't serve things like robots.txt, favicon.ico, or
.well-known/ endpoints ourselves, but ensure we can be
used with Plack::App::Cascade for others.
---
 t/plack.t | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/t/plack.t b/t/plack.t
index 04680b2..a4f3245 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -62,16 +62,24 @@ EOF
 		require $psgi;
 	};
 
+	test_psgi($app, sub {
+		my ($cb) = @_;
+		foreach my $u (qw(robots.txt favicon.ico .well-known/foo)) {
+			my $res = $cb->(GET("http://example.com/$u"));
+			is($res->code, 404, "$u is missing");
+		}
+	});
+
 	# redirect with newsgroup
 	test_psgi($app, sub {
 		my ($cb) = @_;
 		my $from = 'http://example.com/inbox.test';
 		my $to = 'http://example.com/test/';
 		my $res = $cb->(GET($from));
-		is($res->code, 301, 'is permanent redirect');
+		is($res->code, 301, 'newsgroup name is permanent redirect');
 		is($to, $res->header('Location'), 'redirect location matches');
 		$from .= '/';
-		is($res->code, 301, 'is permanent redirect');
+		is($res->code, 301, 'newsgroup name/ is permanent redirect');
 		is($to, $res->header('Location'), 'redirect location matches');
 	});
 
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] http: clarify comments about layering violation
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
  2016-05-28  1:57 ` [PATCH 1/7] t/plack: ensure we can cascade on common endpoints Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 3/7] Makefile.PL: allow N to be overridden Eric Wong
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

It's a low priority, but acknowledge it.
---
 lib/PublicInbox/HTTP.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 0454f60..fcbd758 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -4,7 +4,7 @@
 # Generic PSGI server for convenience.  It aims to provide
 # a consistent experience for public-inbox admins so they don't have
 # to learn different ways to admin both NNTP and HTTP components.
-# There's nothing public-inbox-specific, here.
+# There's nothing which depends on public-inbox, here.
 # Each instance of this class represents a HTTP client socket
 
 package PublicInbox::HTTP;
@@ -25,7 +25,7 @@ use constant {
 	CHUNK_MAX_HDR => 256,
 };
 
-# FIXME: duplicated code with NNTP.pm
+# FIXME: duplicated code with NNTP.pm, layering violation
 my $WEAKEN = {}; # string(inbox) -> inbox
 my $weakt;
 sub weaken_task () {
@@ -249,6 +249,8 @@ sub response_done ($$) {
 	$self->{env} = undef;
 	$self->write("0\r\n\r\n") if $alive == 2;
 	$self->write(sub { $alive ? next_request($self) : $self->close });
+
+	# FIXME: layering violation
 	if (my $obj = $env->{'pi-httpd.inbox'}) {
 		# grace period for reaping resources
 		$WEAKEN->{"$obj"} = $obj;
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] Makefile.PL: allow N to be overridden
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
  2016-05-28  1:57 ` [PATCH 1/7] t/plack: ensure we can cascade on common endpoints Eric Wong
  2016-05-28  1:57 ` [PATCH 2/7] http: clarify comments about layering violation Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 4/7] examples: config no longer supports atomUrl Eric Wong
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

Relying on the number of processors isn't a great idea
since some of our tests rely on delays to test blocking
and slow client behavior.
---
 Makefile.PL | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.PL b/Makefile.PL
index 3cffe13..61cb77b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -40,10 +40,10 @@ sub MY::postamble {
 EATMYDATA =
 -include config.mak
 -include Documentation/include.mk
+N ?= \$(shell echo \$\$(( \$\$(nproc 2>/dev/null || echo 2) + 1)))
 SCRIPTS := scripts/ssoma-replay
 my_syntax := \$(addsuffix .syntax, $PM_FILES \$(EXE_FILES) \$(SCRIPTS))
 
-N := \$(shell echo \$\$(( \$\$(nproc 2>/dev/null || echo 2) + 1)))
 
 %.syntax ::
 	@\$(PERL) -I lib -c \$(subst .syntax,,\$@)
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] examples: config no longer supports atomUrl
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
                   ` (2 preceding siblings ...)
  2016-05-28  1:57 ` [PATCH 3/7] Makefile.PL: allow N to be overridden Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 5/7] www: remove footer_html support Eric Wong
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

We build the atomUrl from url, which can change
dynamically depending on what PSGI environment it
is called under.
---
 examples/public-inbox-config | 1 -
 1 file changed, 1 deletion(-)

diff --git a/examples/public-inbox-config b/examples/public-inbox-config
index 0c1db11..7fcbe0b 100644
--- a/examples/public-inbox-config
+++ b/examples/public-inbox-config
@@ -10,4 +10,3 @@
 	address = meta@public-inbox.org
 	mainrepo = /home/pi/meta-main.git
 	url = http://example.com/meta
-	atomUrl = http://example.com/meta
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] www: remove footer_html support
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
                   ` (3 preceding siblings ...)
  2016-05-28  1:57 ` [PATCH 4/7] examples: config no longer supports atomUrl Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 6/7] config: remove try_cat Eric Wong
  2016-05-28  1:57 ` [PATCH 7/7] remove redundant NewsGroup class Eric Wong
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

I haven't used it in a while and the existing "description"
is probably good enough.

If we support it again, it should be plain-text + auto-linkified
for ease-of-maintenance and consistency.
---
 lib/PublicInbox/Inbox.pm | 10 ----------
 lib/PublicInbox/WWW.pm   |  2 --
 2 files changed, 12 deletions(-)

diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 4bcab96..c07aaa9 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -64,16 +64,6 @@ sub cloneurl {
 	$self->{cloneurl} = \@url;
 }
 
-# TODO: can we remove this?
-sub footer_html {
-	my ($self) = @_;
-	my $footer = $self->{footer};
-	return $footer if defined $footer;
-	$footer = try_cat("$self->{mainrepo}/public-inbox/footer.html");
-	chomp $footer;
-	$self->{footer} = $footer;
-}
-
 sub base_url {
 	my ($self, $prq) = @_; # Plack::Request
 	if (defined $prq) {
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 5b4d6c1..e8f1fbf 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -252,8 +252,6 @@ sub footer {
 	my ($ctx) = @_;
 	return '' unless $ctx;
 	my $obj = $ctx->{-inbox} or return '';
-	my $footer = $obj->footer_html;
-	return $ctx->{footer} = $footer if $footer;
 
 	# auto-generate a footer
 	chomp(my $desc = $obj->description);
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] config: remove try_cat
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
                   ` (4 preceding siblings ...)
  2016-05-28  1:57 ` [PATCH 5/7] www: remove footer_html support Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  2016-05-28  1:57 ` [PATCH 7/7] remove redundant NewsGroup class Eric Wong
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

It's moved into the Inbox module and we no longer use it
in WWW
---
 lib/PublicInbox/Config.pm | 12 ------------
 lib/PublicInbox/WWW.pm    |  2 +-
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 35b24af..317d290 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -5,8 +5,6 @@
 package PublicInbox::Config;
 use strict;
 use warnings;
-use base qw/Exporter/;
-our @EXPORT_OK = qw/try_cat/;
 require PublicInbox::Inbox;
 use PublicInbox::Spawn qw(popen_rd);
 use File::Path::Expand qw/expand_filename/;
@@ -101,16 +99,6 @@ sub git_config_dump {
 	\%rv;
 }
 
-sub try_cat {
-	my ($path) = @_;
-	my $rv;
-	if (open(my $fh, '<', $path)) {
-		local $/;
-		$rv = <$fh>;
-	}
-	$rv;
-}
-
 sub _fill {
 	my ($self, $pfx) = @_;
 	my $rv = {};
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index e8f1fbf..ab3cd5d 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -14,7 +14,7 @@ use 5.008;
 use strict;
 use warnings;
 use Plack::Request;
-use PublicInbox::Config qw(try_cat);
+use PublicInbox::Config;
 use URI::Escape qw(uri_escape_utf8 uri_unescape);
 use constant SSOMA_URL => '//ssoma.public-inbox.org/';
 use constant PI_URL => '//public-inbox.org/';
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] remove redundant NewsGroup class
  2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
                   ` (5 preceding siblings ...)
  2016-05-28  1:57 ` [PATCH 6/7] config: remove try_cat Eric Wong
@ 2016-05-28  1:57 ` Eric Wong
  6 siblings, 0 replies; 8+ messages in thread
From: Eric Wong @ 2016-05-28  1:57 UTC (permalink / raw)
  To: meta

Most of its functionality is in the PublicInbox::Inbox class.

While we're at it, we no longer auto-create newsgroup names
based on the inbox name, since newsgroup names probably deserve
some thought when it comes to hierarchy.
---
 MANIFEST                     |  1 -
 lib/PublicInbox/Config.pm    | 37 ++++++++++++++-----
 lib/PublicInbox/Inbox.pm     |  7 ++++
 lib/PublicInbox/NNTP.pm      |  9 ++---
 lib/PublicInbox/NNTPD.pm     | 27 ++++----------
 lib/PublicInbox/NewsGroup.pm | 84 --------------------------------------------
 lib/PublicInbox/NewsWWW.pm   | 38 ++------------------
 lib/PublicInbox/WWW.pm       |  2 +-
 t/config.t                   |  2 ++
 t/nntp.t                     | 15 +++++---
 t/nntpd.t                    |  4 ++-
 11 files changed, 67 insertions(+), 159 deletions(-)
 delete mode 100644 lib/PublicInbox/NewsGroup.pm

diff --git a/MANIFEST b/MANIFEST
index 259f42c..370eac9 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -37,7 +37,6 @@ lib/PublicInbox/MID.pm
 lib/PublicInbox/Mbox.pm
 lib/PublicInbox/Msgmap.pm
 lib/PublicInbox/NNTP.pm
-lib/PublicInbox/NewsGroup.pm
 lib/PublicInbox/NewsWWW.pm
 lib/PublicInbox/ProcessPipe.pm
 lib/PublicInbox/Search.pm
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 317d290..a8c5105 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -20,6 +20,7 @@ sub new {
 	# caches
 	$self->{-by_addr} ||= {};
 	$self->{-by_name} ||= {};
+	$self->{-by_newsgroup} ||= {};
 	$self;
 }
 
@@ -55,7 +56,24 @@ sub lookup_name {
 	my $rv = $self->{-by_name}->{$name};
 	return $rv if $rv;
 	$rv = _fill($self, "publicinbox.$name") or return;
-	$self->{-by_name}->{$name} = $rv;
+}
+
+sub lookup_newsgroup {
+	my ($self, $ng) = @_;
+	$ng = lc($ng);
+	my $rv = $self->{-by_newsgroup}->{$ng};
+	return $rv if $rv;
+
+	foreach my $k (keys %$self) {
+		$k =~ /\A(publicinbox\.[\w-]+)\.newsgroup\z/ or next;
+		my $v = $self->{$k};
+		my $pfx = $1;
+		if ($v eq $ng) {
+			$rv = _fill($self, $pfx);
+			return $rv;
+		}
+	}
+	undef;
 }
 
 sub get {
@@ -103,24 +121,27 @@ sub _fill {
 	my ($self, $pfx) = @_;
 	my $rv = {};
 
-	foreach my $k (qw(mainrepo address filter url)) {
+	foreach my $k (qw(mainrepo address filter url newsgroup)) {
 		my $v = $self->{"$pfx.$k"};
 		$rv->{$k} = $v if defined $v;
 	}
 	return unless $rv->{mainrepo};
-	my $inbox = $pfx;
-	$inbox =~ s/\Apublicinbox\.//;
-	$rv->{name} = $inbox;
+	my $name = $pfx;
+	$name =~ s/\Apublicinbox\.//;
+	$rv->{name} = $name;
 	my $v = $rv->{address} ||= 'public-inbox@example.com';
-	$rv->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
+	my $p = $rv->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
+	$rv->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
 	$rv = PublicInbox::Inbox->new($rv);
 	if (ref($v) eq 'ARRAY') {
 		$self->{-by_addr}->{lc($_)} = $rv foreach @$v;
 	} else {
 		$self->{-by_addr}->{lc($v)} = $rv;
 	}
-	$rv;
+	if (my $ng = $rv->{newsgroup}) {
+		$self->{-by_newsgroup}->{$ng} = $rv;
+	}
+	$self->{-by_name}->{$name} = $rv;
 }
 
-
 1;
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index c07aaa9..d050dc8 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -83,4 +83,11 @@ sub base_url {
 	}
 }
 
+sub nntp_usable {
+	my ($self) = @_;
+	my $ret = $self->mm && $self->search;
+	weaken_all();
+	$ret;
+}
+
 1;
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index f3de4b1..58b86a8 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -195,7 +195,7 @@ sub list_active_times ($;$) {
 	foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
 		$ng->{newsgroup} =~ $wildmat or next;
 		my $c = eval { $ng->mm->created_at } || time;
-		more($self, "$ng->{newsgroup} $c $ng->{address}");
+		more($self, "$ng->{newsgroup} $c $ng->{-primary_address}");
 	}
 }
 
@@ -413,7 +413,8 @@ sub cmd_last ($) { article_adj($_[0], -1) }
 sub cmd_post ($) {
 	my ($self) = @_;
 	my $ng = $self->{ng};
-	$ng ? "440 mailto:$ng->{address} to post" : '440 posting not allowed'
+	$ng ? "440 mailto:$ng->{-primary_address} to post"
+		: '440 posting not allowed'
 }
 
 sub cmd_quit ($) {
@@ -438,8 +439,8 @@ sub set_nntp_headers {
 	# clobber some
 	$hdr->header_set('Newsgroups', $ng->{newsgroup});
 	$hdr->header_set('Xref', xref($ng, $n));
-	header_append($hdr, 'List-Post', "<mailto:$ng->{address}>");
-	if (my $url = $ng->{url}) {
+	header_append($hdr, 'List-Post', "<mailto:$ng->{-primary_address}>");
+	if (my $url = $ng->base_url) {
 		$mid = uri_escape_utf8($mid);
 		header_append($hdr, 'Archived-At', "<$url$mid/>");
 		header_append($hdr, 'List-Archive', "<$url>");
diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm
index fc26c5c..50d022b 100644
--- a/lib/PublicInbox/NNTPD.pm
+++ b/lib/PublicInbox/NNTPD.pm
@@ -6,7 +6,6 @@
 package PublicInbox::NNTPD;
 use strict;
 use warnings;
-require PublicInbox::NewsGroup;
 require PublicInbox::Config;
 
 sub new {
@@ -26,28 +25,16 @@ sub refresh_groups () {
 	my @list;
 	foreach my $k (keys %$pi_config) {
 		$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-		my $g = $1;
+		my $name = $1;
 		my $git_dir = $pi_config->{$k};
-		my $addr = $pi_config->{"publicinbox.$g.address"};
-		my $ngname = $pi_config->{"publicinbox.$g.newsgroup"};
-		my $url = $pi_config->{"publicinbox.$g.url"};
-		if (defined $ngname) {
-			next if ($ngname eq ''); # disabled
-			$g = $ngname;
-		}
-		my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr, $url);
-		my $old_ng = $self->{groups}->{$g};
-
-		# Reuse the old one if possible since it can hold
-		# references to valid mm and gcf objects
-		if ($old_ng) {
-			$old_ng->update($ng);
-			$ng = $old_ng;
-		}
+		my $ngname = $pi_config->{"publicinbox.$name.newsgroup"};
+		next unless defined $ngname;
+		next if ($ngname eq ''); # disabled
+		my $ng = $pi_config->lookup_newsgroup($ngname) or next;
 
 		# Only valid if msgmap and search works
-		if ($ng->usable) {
-			$new->{$g} = $ng;
+		if ($ng->nntp_usable) {
+			$new->{$ngname} = $ng;
 			push @list, $ng;
 		}
 	}
diff --git a/lib/PublicInbox/NewsGroup.pm b/lib/PublicInbox/NewsGroup.pm
deleted file mode 100644
index 500f61e..0000000
--- a/lib/PublicInbox/NewsGroup.pm
+++ /dev/null
@@ -1,84 +0,0 @@
-# Copyright (C) 2015 all contributors <meta@public-inbox.org>
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
-#
-# Used only by the NNTP server to represent a public-inbox git repository
-# as a newsgroup
-package PublicInbox::NewsGroup;
-use strict;
-use warnings;
-use Scalar::Util qw(weaken);
-require Danga::Socket;
-require PublicInbox::Msgmap;
-require PublicInbox::Search;
-require PublicInbox::Git;
-
-sub new {
-	my ($class, $newsgroup, $git_dir, $address, $url) = @_;
-
-	# first email address is preferred
-	$address = $address->[0] if ref($address);
-	if ($url) {
-		# assume protocol-relative URLs which start with '//' means
-		# the server supports both HTTP and HTTPS, favor HTTPS.
-		$url = "https:$url" if $url =~ m!\A//!;
-		$url .= '/' if $url !~ m!/\z!;
-	}
-	my $self = bless {
-		newsgroup => $newsgroup,
-		git_dir => $git_dir,
-		address => $address,
-		url => $url,
-	}, $class;
-	$self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
-	$self;
-}
-
-sub weaken_all {
-	my ($self) = @_;
-	weaken($self->{$_}) foreach qw(gcf mm search);
-}
-
-sub gcf {
-	my ($self) = @_;
-	$self->{gcf} ||= eval { PublicInbox::Git->new($self->{git_dir}) };
-}
-
-sub usable {
-	my ($self) = @_;
-	eval {
-		PublicInbox::Msgmap->new($self->{git_dir});
-		PublicInbox::Search->new($self->{git_dir});
-	};
-}
-
-sub mm {
-	my ($self) = @_;
-	$self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{git_dir}) };
-}
-
-sub search {
-	my ($self) = @_;
-	$self->{search} ||= eval { PublicInbox::Search->new($self->{git_dir}) };
-}
-
-sub description {
-	my ($self) = @_;
-	open my $fh, '<', "$self->{git_dir}/description" or return '';
-	my $desc = eval { local $/; <$fh> };
-	chomp $desc;
-	$desc =~ s/\s+/ /smg;
-	$desc;
-}
-
-sub update {
-	my ($self, $new) = @_;
-	$self->{address} = $new->{address};
-	$self->{domain} = $new->{domain};
-	if ($self->{git_dir} ne $new->{git_dir}) {
-		# new git_dir requires a new mm and gcf
-		$self->{mm} = $self->{gcf} = undef;
-		$self->{git_dir} = $new->{git_dir};
-	}
-}
-
-1;
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index 5357059..908c435 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -19,7 +19,6 @@ sub new {
 
 sub call {
 	my ($self, $env) = @_;
-	my $ng_map = $self->newsgroup_map;
 	my $path = $env->{PATH_INFO};
 	$path =~ s!\A/+!!;
 	$path =~ s!/+\z!!;
@@ -27,11 +26,11 @@ sub call {
 	# some links may have the article number in them:
 	# /inbox.foo.bar/123456
 	my ($ng, $article) = split(m!/+!, $path, 2);
-	if (my $info = $ng_map->{$ng}) {
-		my $url = PublicInbox::Hval::prurl($env, $info->{url});
+	if (my $inbox = $self->{pi_config}->lookup_newsgroup($ng)) {
+		my $url = PublicInbox::Hval::prurl($env, $inbox->{url});
 		my $code = 301;
 		if (defined $article && $article =~ /\A\d+\z/) {
-			my $mid = eval { ng_mid_for($ng, $info, $article) };
+			my $mid = eval { $inbox->mm->mid_for($article) };
 			if (defined $mid) {
 				# article IDs are not stable across clones,
 				# do not encourage caching/bookmarking them
@@ -47,35 +46,4 @@ sub call {
 	[ 404, [ 'Content-Type' => 'text/plain' ], [] ];
 }
 
-sub ng_mid_for {
-	my ($ng, $info, $article) = @_;
-	# may fail due to lack of Danga::Socket
-	# for defer_weaken:
-	require PublicInbox::NewsGroup;
-	$ng = $info->{ng} ||=
-		PublicInbox::NewsGroup->new($ng, $info->{git_dir}, '');
-	$ng->mm->mid_for($article);
-}
-
-sub newsgroup_map {
-	my ($self) = @_;
-	my $rv;
-	$rv = $self->{ng_map} and return $rv;
-	my $pi_config = $self->{pi_config};
-	my %ng_map;
-	foreach my $k (keys %$pi_config) {
-		$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-		my $inbox = $1;
-		my $git_dir = $pi_config->{"publicinbox.$inbox.mainrepo"};
-		my $url = $pi_config->{"publicinbox.$inbox.url"};
-		defined $url or next;
-		my $ng = $pi_config->{"publicinbox.$inbox.newsgroup"};
-		next if (!defined $ng) || ($ng eq ''); # disabled
-
-		$url =~ m!/\z! or $url .= '/';
-		$ng_map{$ng} = { url => $url, git_dir => $git_dir };
-	}
-	$self->{ng_map} = \%ng_map;
-}
-
 1;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index ab3cd5d..cf370af 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -107,7 +107,7 @@ sub preload {
 
 	foreach (qw(PublicInbox::Search PublicInbox::SearchView
 			PublicInbox::Mbox IO::Compress::Gzip
-			PublicInbox::NewsWWW PublicInbox::NewsGroup)) {
+			PublicInbox::NewsWWW)) {
 		eval "require $_;";
 	}
 }
diff --git a/t/config.t b/t/config.t
index 78971a2..dc448cd 100644
--- a/t/config.t
+++ b/t/config.t
@@ -26,6 +26,7 @@ my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 	is_deeply($cfg->lookup('meta@public-inbox.org'), {
 		'mainrepo' => '/home/pi/meta-main.git',
 		'address' => 'meta@public-inbox.org',
+		'domain' => 'public-inbox.org',
 		'url' => 'http://example.com/meta',
 		-primary_address => 'meta@public-inbox.org',
 		'name' => 'meta',
@@ -41,6 +42,7 @@ my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 			      'test@public-inbox.org'],
 		-primary_address => 'try@public-inbox.org',
 		'mainrepo' => '/home/pi/test-main.git',
+		'domain' => 'public-inbox.org',
 		'name' => 'test',
 		'url' => 'http://example.com/test',
 	}, "lookup matches expected output for test");
diff --git a/t/nntp.t b/t/nntp.t
index 5513c7b..de07abb 100644
--- a/t/nntp.t
+++ b/t/nntp.t
@@ -11,7 +11,7 @@ foreach my $mod (qw(DBD::SQLite Search::Xapian Danga::Socket)) {
 }
 
 use_ok 'PublicInbox::NNTP';
-use_ok 'PublicInbox::NewsGroup';
+use_ok 'PublicInbox::Inbox';
 
 {
 	sub quote_str {
@@ -99,9 +99,14 @@ use_ok 'PublicInbox::NewsGroup';
 { # test setting NNTP headers in HEAD and ARTICLE requests
 	require Email::MIME;
 	my $u = 'https://example.com/a/';
-	my $ng = PublicInbox::NewsGroup->new('test', 'test.git',
-				'a@example.com', '//example.com/a');
-	is($ng->{url}, $u, 'URL expanded');
+	my $ng = PublicInbox::Inbox->new({ name => 'test',
+					mainrepo => 'test.git',
+					address => 'a@example.com',
+					-primary_address => 'a@example.com',
+					newsgroup => 'test',
+					domain => 'example.com',
+					url => '//example.com/a'});
+	is($ng->base_url, $u, 'URL expanded');
 	my $mid = 'a@b';
 	my $mime = Email::MIME->new("Message-ID: <$mid>\r\n\r\n");
 	PublicInbox::NNTP::set_nntp_headers($mime->header_obj, $ng, 1, $mid);
@@ -118,7 +123,7 @@ use_ok 'PublicInbox::NewsGroup';
 	is_deeply([ $mime->header('Xref') ], [ 'example.com test:1' ],
 		'Xref: set');
 
-	$ng->{url} = 'http://mirror.example.com/m/';
+	$ng->{-base_url} = 'http://mirror.example.com/m/';
 	PublicInbox::NNTP::set_nntp_headers($mime->header_obj, $ng, 2, $mid);
 	is_deeply([ $mime->header('Message-ID') ], [ "<$mid>" ],
 		'Message-ID unchanged');
diff --git a/t/nntpd.t b/t/nntpd.t
index 837b9d4..c5bc0b5 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -24,7 +24,6 @@ my $out = "$tmpdir/stdout.log";
 my $maindir = "$tmpdir/main.git";
 my $group = 'test-nntpd';
 my $addr = $group . '@example.com';
-my $cfgpfx = "publicinbox.$group";
 my $nntpd = 'blib/script/public-inbox-nntpd';
 my $init = 'blib/script/public-inbox-init';
 use_ok 'PublicInbox::Import';
@@ -44,6 +43,9 @@ END { kill 'TERM', $pid if defined $pid };
 {
 	local $ENV{HOME} = $home;
 	system($init, $group, $maindir, 'http://example.com/', $addr);
+	is(system(qw(git config), "--file=$home/.public-inbox/config",
+			"publicinbox.$group.newsgroup", $group),
+		0, 'enabled newsgroup');
 	my $len;
 
 	# ensure successful message delivery
-- 
EW


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-28  1:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-28  1:57 [PATCH 0/7] miscellaneous cleanups Eric Wong
2016-05-28  1:57 ` [PATCH 1/7] t/plack: ensure we can cascade on common endpoints Eric Wong
2016-05-28  1:57 ` [PATCH 2/7] http: clarify comments about layering violation Eric Wong
2016-05-28  1:57 ` [PATCH 3/7] Makefile.PL: allow N to be overridden Eric Wong
2016-05-28  1:57 ` [PATCH 4/7] examples: config no longer supports atomUrl Eric Wong
2016-05-28  1:57 ` [PATCH 5/7] www: remove footer_html support Eric Wong
2016-05-28  1:57 ` [PATCH 6/7] config: remove try_cat Eric Wong
2016-05-28  1:57 ` [PATCH 7/7] remove redundant NewsGroup class Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).