]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/NNTPD.pm
nntpd: avoid uninitialized warning
[public-inbox.git] / lib / PublicInbox / NNTPD.pm
1 # Copyright (C) 2016 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 require PublicInbox::NewsGroup;
10 require PublicInbox::Config;
11
12 sub new {
13         my ($class) = @_;
14         bless {
15                 groups => {},
16                 err => \*STDERR,
17                 out => \*STDOUT,
18                 grouplist => [],
19         }, $class;
20 }
21
22 sub refresh_groups () {
23         my ($self) = @_;
24         my $pi_config = PublicInbox::Config->new;
25         my $new = {};
26         my @list;
27         foreach my $k (keys %$pi_config) {
28                 $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
29                 my $g = $1;
30                 my $git_dir = $pi_config->{$k};
31                 my $addr = $pi_config->{"publicinbox.$g.address"};
32                 my $ngname = $pi_config->{"publicinbox.$g.newsgroup"};
33                 my $url = $pi_config->{"publicinbox.$g.url"};
34                 if (defined $ngname) {
35                         next if ($ngname eq ''); # disabled
36                         $g = $ngname;
37                 }
38                 my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr, $url);
39                 my $old_ng = $self->{groups}->{$g};
40
41                 # Reuse the old one if possible since it can hold
42                 # references to valid mm and gcf objects
43                 if ($old_ng) {
44                         $old_ng->update($ng);
45                         $ng = $old_ng;
46                 }
47
48                 # Only valid if msgmap and search works
49                 if ($ng->usable) {
50                         $new->{$g} = $ng;
51                         push @list, $ng;
52                 }
53         }
54         @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
55         $self->{grouplist} = \@list;
56         # this will destroy old groups that got deleted
57         %{$self->{groups}} = %$new;
58 }
59
60 1;