]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/NNTPD.pm
Put the NNTP server name into Xref lines
[public-inbox.git] / lib / PublicInbox / NNTPD.pm
1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # represents an NNTPD (currently a singleton),
5 # see script/public-inbox-nntpd for how it is used
6 package PublicInbox::NNTPD;
7 use strict;
8 use warnings;
9 use Sys::Hostname;
10 require PublicInbox::Config;
11
12 sub new {
13         my ($class) = @_;
14         my $pi_config = PublicInbox::Config->new;
15         my $name = $pi_config->{'publicinbox.nntpserver'};
16         if (!defined($name) or $name eq '') {
17                 $name = hostname;
18         } elsif (ref($name) eq 'ARRAY') {
19                 $name = $name->[0];
20         }
21
22         bless {
23                 groups => {},
24                 err => \*STDERR,
25                 out => \*STDOUT,
26                 grouplist => [],
27                 servername => $name,
28         }, $class;
29 }
30
31 sub refresh_groups () {
32         my ($self) = @_;
33         my $pi_config = PublicInbox::Config->new;
34         my $new = {};
35         my @list;
36         $pi_config->each_inbox(sub {
37                 my ($ng) = @_;
38                 my $ngname = $ng->{newsgroup} or return;
39                 if (ref $ngname) {
40                         warn 'multiple newsgroups not supported: '.
41                                 join(', ', @$ngname). "\n";
42                 } elsif ($ng->nntp_usable) {
43                         # Only valid if msgmap and search works
44                         $new->{$ngname} = $ng;
45                         push @list, $ng;
46                 }
47         });
48         @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
49         $self->{grouplist} = \@list;
50         # this will destroy old groups that got deleted
51         %{$self->{groups}} = %$new;
52 }
53
54 1;