]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: use ->can to check for IO::Socket::SSL
authorEric Wong <e@yhbt.net>
Tue, 16 Jun 2020 22:31:20 +0000 (22:31 +0000)
committerEric Wong <e@yhbt.net>
Sun, 21 Jun 2020 00:42:32 +0000 (00:42 +0000)
Doing a ref($obj) string comparison ties us to IO::Socket::SSL
(and OpenSSL) In the future, we may support GnuTLS or other TLS
implementations.  This was already done in the IMAP code.

lib/PublicInbox/DS.pm
lib/PublicInbox/HTTP.pm
lib/PublicInbox/NNTP.pm

index 01c8917eafedb6f509b0953ddf59c192b61ab86a..b7753e1a663148320e798aa606bfe0af1e9d4f7d 100644 (file)
@@ -415,7 +415,7 @@ sub send_tmpio ($$) {
 }
 
 sub epbit ($$) { # (sock, default)
-    ref($_[0]) eq 'IO::Socket::SSL' ? PublicInbox::TLS::epollbit() : $_[1];
+       $_[0]->can('stop_SSL') ? PublicInbox::TLS::epollbit() : $_[1];
 }
 
 # returns 1 if done, 0 if incomplete
@@ -569,7 +569,7 @@ sub msg_more ($$) {
     my $wbuf = $self->{wbuf};
 
     if (MSG_MORE && (!defined($wbuf) || !scalar(@$wbuf)) &&
-               ref($sock) ne 'IO::Socket::SSL') {
+               !$sock->can('stop_SSL')) {
         my $n = send($sock, $_[1], MSG_MORE);
         if (defined $n) {
             my $nlen = bytes::length($_[1]) - $n;
@@ -619,7 +619,7 @@ sub shutdn_tls_step ($) {
 sub shutdn ($) {
     my ($self) = @_;
     my $sock = $self->{sock} or return;
-    if (ref($sock) eq 'IO::Socket::SSL') {
+    if ($sock->can('stop_SSL')) {
         shutdn_tls_step($self);
     } else {
        $self->close;
index b73ce2d733500f9f38a540806200183301d99079..6ccf20592405e2ee3732d79283b8ac262c26cd6f 100644 (file)
@@ -59,7 +59,7 @@ sub new ($$$) {
        my $self = fields::new($class);
        my $ev = EPOLLIN;
        my $wbuf;
-       if (ref($sock) eq 'IO::Socket::SSL' && !$sock->accept_SSL) {
+       if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
                $ev = PublicInbox::TLS::epollbit();
                $wbuf = [ \&PublicInbox::DS::accept_tls_step ];
index bffd773cf9eb087c5d990fed67db0da10e2ff345..be3bddc3f5d2a230642b4bf2dc878f7b6c5aec73 100644 (file)
@@ -47,7 +47,7 @@ sub new ($$$) {
        my $self = fields::new($class);
        my $ev = EPOLLIN;
        my $wbuf;
-       if (ref($sock) eq 'IO::Socket::SSL' && !$sock->accept_SSL) {
+       if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
                $ev = PublicInbox::TLS::epollbit();
                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
@@ -97,7 +97,7 @@ sub process_line ($$) {
 sub cmd_capabilities ($;$) {
        my ($self, undef) = @_;
        my $res = $CAPABILITIES;
-       if (ref($self->{sock}) ne 'IO::Socket::SSL' &&
+       if (!$self->{sock}->can('accept_SSL') &&
                        $self->{nntpd}->{accept_tls}) {
                $res .= "STARTTLS\r\n";
        }
@@ -896,7 +896,7 @@ sub cmd_starttls ($) {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
        # RFC 4642 2.2.1
-       return r502 if (ref($sock) eq 'IO::Socket::SSL' || $self->compressed);
+       return r502 if ($sock->can('accept_SSL') || $self->compressed);
        my $opt = $self->{nntpd}->{accept_tls} or
                return '580 can not initiate TLS negotiation';
        res($self, '382 Continue with TLS negotiation');