]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/NNTPD.pm
split out NNTPD and HTTPD* modules
[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                 if (defined $ngname) {
34                         next if ($ngname eq ''); # disabled
35                         $g = $ngname;
36                 }
37                 my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr);
38                 my $old_ng = $self->{groups}->{$g};
39
40                 # Reuse the old one if possible since it can hold
41                 # references to valid mm and gcf objects
42                 if ($old_ng) {
43                         $old_ng->update($ng);
44                         $ng = $old_ng;
45                 }
46
47                 # Only valid if msgmap and search works
48                 if ($ng->usable) {
49                         $new->{$g} = $ng;
50                         push @list, $ng;
51                 }
52         }
53         @list = sort { $a->{name} cmp $b->{name} } @list;
54         $self->{grouplist} = \@list;
55         # this will destroy old groups that got deleted
56         %{$self->{groups}} = %$new;
57 }
58
59 1;