changeset 99402:d0dc678bbb96

Merge from gnus--devo--0 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1464
author Miles Bader <miles@gnu.org>
date Thu, 06 Nov 2008 00:49:23 +0000
parents 2ac19526bf39
children e0a169f45c0e
files lisp/gnus/ChangeLog lisp/gnus/auth-source.el lisp/gnus/starttls.el
diffstat 3 files changed, 75 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/gnus/ChangeLog	Wed Nov 05 22:12:21 2008 +0000
+++ b/lisp/gnus/ChangeLog	Thu Nov 06 00:49:23 2008 +0000
@@ -1,3 +1,21 @@
+2008-11-04  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+	* starttls.el (starttls-any-program-available): Rewritten so it doesn't
+	require itself and to remove `with-no-warnings'.
+
+2008-11-03  Teodor Zlatanov  <tzz@lifelogs.com>
+
+	* starttls.el (starttls-any-program-available): Get the name of the
+	available TLS layer program.
+	(starttls-open-steam-gnutls, starttls-open-stream): Put port number as
+	well as the host name in the "opening" message.
+
+	* auth-source.el (auth-source-cache, auth-source-do-cache)
+	(auth-source-user-or-password): Cache passwords and logins by default,
+	allow override with `auth-source-do-cache'.
+	(auth-source-forget-user-or-password): Allow users to remove cache
+	entries if needed.
+
 2008-10-31  Teodor Zlatanov  <tzz@lifelogs.com>
 
 	* ietf-drums.el (ietf-drums-remove-comments): Localize second
--- a/lisp/gnus/auth-source.el	Wed Nov 05 22:12:21 2008 +0000
+++ b/lisp/gnus/auth-source.el	Thu Nov 06 00:49:23 2008 +0000
@@ -91,6 +91,15 @@
 		    p)))
 	  auth-source-protocols))
 
+(defvar auth-source-cache (make-hash-table :test 'equal)
+  "Cache for auth-source data")
+
+(defcustom auth-source-do-cache t
+  "Whether auth-source should cache information."
+  :group 'auth-source
+  :version "23.1" ;; No Gnus
+  :type `boolean)
+
 (defcustom auth-sources '((:source "~/.authinfo.gpg" :host t :protocol t))
   "List of authentication sources.
 
@@ -150,26 +159,42 @@
       (unless fallback
 	(auth-source-pick host protocol t)))))
 
+(defun auth-source-forget-user-or-password (mode host protocol)
+  (interactive "slogin/password: \nsHost: \nsProtocol: \n") ;for testing
+  (remhash (format "%s %s:%s" mode host protocol) auth-source-cache))
+
 (defun auth-source-user-or-password (mode host protocol)
   "Find user or password (from the string MODE) matching HOST and PROTOCOL."
   (gnus-message 9
 		"auth-source-user-or-password: get %s for %s (%s)"
 		mode host protocol)
-  (let (found)
-    (dolist (choice (auth-source-pick host protocol))
-      (setq found (netrc-machine-user-or-password
-		   mode
-		   (plist-get choice :source)
-		   (list host)
-		   (list (format "%s" protocol))
-		   (auth-source-protocol-defaults protocol)))
-      (when found
-	(gnus-message 9
-		      "auth-source-user-or-password: found %s=%s for %s (%s)"
-		      mode
-		      ;; don't show the password
-		      (if (equal mode "password") "SECRET" found)
-		      host protocol)
+  (let* ((cname (format "%s %s:%s" mode host protocol))
+	 (found (gethash cname auth-source-cache)))
+    (if found
+	(progn
+	  (gnus-message 9
+			"auth-source-user-or-password: cached %s=%s for %s (%s)"
+			mode
+			;; don't show the password
+			(if (equal mode "password") "SECRET" found)
+			host protocol)
+	  found)
+      (dolist (choice (auth-source-pick host protocol))
+	(setq found (netrc-machine-user-or-password
+		     mode
+		     (plist-get choice :source)
+		     (list host)
+		     (list (format "%s" protocol))
+		     (auth-source-protocol-defaults protocol)))
+	(when found
+	  (gnus-message 9
+			"auth-source-user-or-password: found %s=%s for %s (%s)"
+			mode
+			;; don't show the password
+			(if (equal mode "password") "SECRET" found)
+			host protocol)
+	  (when auth-source-do-cache
+	    (puthash cname found auth-source-cache)))
 	(return found)))))
 
 (defun auth-source-protocol-defaults (protocol)
--- a/lisp/gnus/starttls.el	Wed Nov 05 22:12:21 2008 +0000
+++ b/lisp/gnus/starttls.el	Thu Nov 06 00:49:23 2008 +0000
@@ -241,7 +241,7 @@
       'process-kill-without-query)))
 
 (defun starttls-open-stream-gnutls (name buffer host port)
-  (message "Opening STARTTLS connection to `%s'..." host)
+  (message "Opening STARTTLS connection to `%s:%s'..." host port)
   (let* (done
 	 (old-max (with-current-buffer buffer (point-max)))
 	 (process-connection-type starttls-process-connection-type)
@@ -266,8 +266,8 @@
 	  (delete-region old-max done))
       (delete-process process)
       (setq process nil))
-    (message "Opening STARTTLS connection to `%s'...%s"
-	     host (if done "done" "failed"))
+    (message "Opening STARTTLS connection to `%s:%s'...%s"
+	     host port (if done "done" "failed"))
     process))
 
 (defun starttls-open-stream (name buffer host port)
@@ -287,6 +287,7 @@
 GNUTLS requires a port number."
   (if starttls-use-gnutls
       (starttls-open-stream-gnutls name buffer host port)
+    (message "Opening STARTTLS connection to `%s:%s'" host (format "%s" port))
     (let* ((process-connection-type starttls-process-connection-type)
 	   (process (apply #'start-process
 			   name buffer starttls-program
@@ -295,6 +296,19 @@
       (starttls-set-process-query-on-exit-flag process nil)
       process)))
 
+(defun starttls-any-program-available ()
+  (let ((program (if starttls-use-gnutls
+		     starttls-gnutls-program
+		   starttls-program)))
+    (condition-case ()
+	(progn
+	  (call-process program)
+	  program)
+      (error (progn
+	       (message "No STARTTLS program was available (tried '%s')"
+			program)
+	       nil)))))
+
 (provide 'starttls)
 
 ;; arch-tag: 648b3bd8-63bd-47f5-904c-7c819aea2297