Gnus development mailing list
 help / color / mirror / Atom feed
* Should open-tls-stream signal an error?
@ 2005-03-05 20:58 Magnus Henoch
  2005-04-08  0:54 ` Carl Henrik Lunde
  0 siblings, 1 reply; 2+ messages in thread
From: Magnus Henoch @ 2005-03-05 20:58 UTC (permalink / raw)


open-tls-stream in tls.el returns nil on failure (gnutls-cli binary
not found, connection refused, etc).  open-network-stream signals an
error when it can't connect.  Is there any reason open-tls-stream
shouldn't do the same, instead of just returning nil?

Magnus




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Should open-tls-stream signal an error?
  2005-03-05 20:58 Should open-tls-stream signal an error? Magnus Henoch
@ 2005-04-08  0:54 ` Carl Henrik Lunde
  0 siblings, 0 replies; 2+ messages in thread
From: Carl Henrik Lunde @ 2005-04-08  0:54 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

A long time ago Magnus Henoch <mange@freemail.hu> wrote:

> open-tls-stream in tls.el returns nil on failure (gnutls-cli binary
> not found, connection refused, etc).  open-network-stream signals an
> error when it can't connect.  Is there any reason open-tls-stream
> shouldn't do the same, instead of just returning nil?

As nobody answered Magnus I made a patch, it seems to work like
open-network-stream on errors, but it's hardly tested.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Make open-tls-stream behave like open-network-stream on error --]
[-- Type: text/x-patch, Size: 1904 bytes --]

Index: tls.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/tls.el,v
retrieving revision 7.5
diff -u -3 -b -r7.5 tls.el
--- tls.el	13 Feb 2005 04:44:40 -0000	7.5
+++ tls.el	8 Apr 2005 00:33:31 -0000
@@ -78,6 +78,20 @@
   :type 'regexp
   :group 'tls)
 
+(defcustom tls-refused "connect: Connection refused"
+  "*Regular expression indicating connection refused
+The default is what GNUTLS's \"gnutls-cli\" outputs."
+  :version "22.1"
+  :type 'regexp
+  :group 'tls)
+
+(defcustom tls-unresolvable "Cannot resolve "
+  "*Regular expression indicating unknown host name
+The default is what GNUTLS's \"gnutls-cli\" outputs."
+  :version "22.1"
+  :type 'regexp
+  :group 'tls)
+
 (defcustom tls-certtool-program (executable-find "certtool")
   "Name of  GnuTLS certtool.
 Used by `tls-certificate-information'."
@@ -138,11 +152,15 @@
 			      service)))))
 	     response)
 	(while (and process
-		    (memq (process-status process) '(open run))
 		    (save-excursion
 		      (set-buffer buffer) ;; XXX "blue moon" nntp.el bug
 		      (goto-char (point-min))
-		      (not (setq done (re-search-forward tls-success nil t)))))
+		      (when (re-search-forward tls-unresolvable nil t)
+			(error "Cannot resolve `%s'" host))
+		      (when (re-search-forward tls-refused nil t)
+			(error "Connection to `%s' refused" host))
+		      (not (setq done (re-search-forward tls-success nil t))))
+		    (memq (process-status process) '(open run)))
 	  (accept-process-output process 1)
 	  (sit-for 1))
 	(message "Opening TLS connection with `%s'...%s" cmd
@@ -152,6 +170,8 @@
 	  (delete-process process))))
     (message "Opening TLS connection to `%s'...%s"
 	     host (if done "done" "failed"))
+    (unless done
+      (error "Unknown error when connecting to `%s' -- is any `tls-program' installed?" host))
     done))
 
 (provide 'tls)

[-- Attachment #3: Type: text/plain, Size: 427 bytes --]


One problem with this code is that the caller must clean the buffer
before connection attempts, as messages matching tls-refused or
tls-unresolvable may stay there between connections.  I doubt
open-network-stream requires that.

If you don't think tls.el should have a patch like this, then the
comment claiming "Usage is the same as `open-network-stream'" should
be revised.

Thanks for looking at this again

  Carl Henrik

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-08  0:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-05 20:58 Should open-tls-stream signal an error? Magnus Henoch
2005-04-08  0:54 ` Carl Henrik Lunde

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 NNTP newsgroup(s).