]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
daemon: use per-listener SIG{__WARN__} callbacks
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 8ad7adc1fd0a3ca49a5635dc19c8b4c7c95b6c01..ef01f44886203abdeaa3b07dad35226a9e7d6770 100644 (file)
@@ -85,7 +85,7 @@ sub cmd_capabilities ($;$) {
        my ($self, undef) = @_;
        my $res = $CAPABILITIES;
        if (!$self->{sock}->can('accept_SSL') &&
-                       $self->{nntpd}->{accept_tls}) {
+                       $self->{nntpd}->{ssl_ctx_opt}) {
                $res .= "STARTTLS\r\n";
        }
        $res .= ".\r\n";
@@ -123,7 +123,7 @@ sub names2ibx ($;$) {
 sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args)
        my ($self, $ibxs) = @_;
        my @window = splice(@$ibxs, 0, 1000);
-       $self->msg_more(join('', map { group_line($_) } @window));
+       emit_group_lines($self, \@window);
        scalar @$ibxs; # continue if there's more
 }
 
@@ -244,19 +244,27 @@ sub parse_time ($$;$) {
        }
 }
 
-sub group_line ($) {
-       my ($ibx) = @_;
-       my ($min, $max) = $ibx->mm(1)->minmax;
-       "$ibx->{newsgroup} $max $min n\r\n";
+sub emit_group_lines {
+       my ($self, $ibxs) = @_;
+       my ($min, $max);
+       my $ALL = $self->{nntpd}->{pi_cfg}->ALL;
+       my $misc = $ALL->misc if $ALL;
+       my $buf = '';
+       for my $ibx (@$ibxs) {
+               $misc ? $misc->inbox_data($ibx) :
+                       delete(@$ibx{qw(-art_min -art_max)});
+               ($min, $max) = ($ibx->art_min, $ibx->art_max);
+               $buf .= "$ibx->{newsgroup} $max $min n\r\n";
+       }
+       $self->msg_more($buf);
 }
 
 sub newgroups_i {
        my ($self, $ts, $ibxs) = @_;
        my @window = splice(@$ibxs, 0, 1000);
-       $self->msg_more(join('', map { group_line($_) } grep {
-                (eval { $_->uidvalidity } // 0) > $ts
-       } @window));
-       scalar @$ibxs;
+       @window = grep { (eval { $_->uidvalidity } // 0) > $ts } @window;
+       emit_group_lines($self, \@window);
+       scalar @$ibxs; # any more?
 }
 
 sub cmd_newgroups ($$$;$$) {
@@ -502,7 +510,7 @@ sub msg_body_write ($$) {
        # these can momentarily double the memory consumption :<
        $$msg =~ s/^\./../smg;
        $$msg =~ s/(?<!\r)\n/\r\n/sg; # Alpine barfs without this
-       $$msg .= "\r\n" unless $$msg =~ /\r\n\z/s;
+       $$msg .= "\r\n" unless substr($$msg, -2, 2) eq "\r\n";
        $self->msg_more($$msg);
 }
 
@@ -556,7 +564,7 @@ sub blob_cb { # called by git->cat_async via ibx_async_cat
                $self->close;
                die "BUG: bad code: $r";
        }
-       $self->write(\".\r\n"); # flushes (includes ->zflush)
+       $self->write(\".\r\n"); # flushes (includes ->dflush)
        $self->requeue;
 }
 
@@ -885,13 +893,13 @@ sub cmd_xover ($;$) {
 
 sub cmd_starttls ($) {
        my ($self) = @_;
-       my $sock = $self->{sock} or return;
        # RFC 4642 2.2.1
-       return r502 if ($sock->can('accept_SSL') || $self->compressed);
-       my $opt = $self->{nntpd}->{accept_tls} or
+       (($self->{sock} // return)->can('stop_SSL') || $self->compressed) and
+               return r502;
+       $self->{nntpd}->{ssl_ctx_opt} or
                return \"580 can not initiate TLS negotiation\r\n";
        $self->write(\"382 Continue with TLS negotiation\r\n");
-       $self->{sock} = IO::Socket::SSL->start_SSL($sock, %$opt);
+       PublicInbox::TLS::start($self->{sock}, $self->{nntpd});
        $self->requeue if PublicInbox::DS::accept_tls_step($self);
        undef;
 }
@@ -950,7 +958,7 @@ sub out ($$;@) {
 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
 sub event_step {
        my ($self) = @_;
-
+       local $SIG{__WARN__} = $self->{nntpd}->{warn_cb};
        return unless $self->flush_write && $self->{sock} && !$self->{long_cb};
 
        # only read more requests if we've drained the write buffer,