user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/3] daemon: use ->can to check for IO::Socket::SSL
Date: Tue, 16 Jun 2020 22:31:20 +0000	[thread overview]
Message-ID: <20200616223122.7197-2-e@yhbt.net> (raw)
In-Reply-To: <20200616223122.7197-1-e@yhbt.net>

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   | 6 +++---
 lib/PublicInbox/HTTP.pm | 2 +-
 lib/PublicInbox/NNTP.pm | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 01c8917eafe..b7753e1a663 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -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;
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index b73ce2d7335..6ccf2059240 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -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 ];
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index bffd773cf9e..be3bddc3f5d 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -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');

  reply	other threads:[~2020-06-16 22:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-16 22:31 [PATCH 0/3] nntpd: updates from imapd Eric Wong
2020-06-16 22:31 ` Eric Wong [this message]
2020-06-16 22:31 ` [PATCH 2/3] nntp: event_step: prepare for async git reads Eric Wong
2020-06-16 22:31 ` [PATCH 3/3] nntp: support slow blob retrievals Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200616223122.7197-2-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).