Changes committed gnus/lisp (ChangeLog auth-source.el)

"Ted Zlatanov" <[email protected]> Mon, 03 Nov 2008 16:21:31 +0100
Newsgroups gmane.emacs.gnus.commits
Message-ID <[email protected]>
Modified: ChangeLog 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.


Index: ChangeLog
diff -u gnus/lisp/ChangeLog:7.1926 gnus/lisp/ChangeLog:7.1927
--- ChangeLog:7.1926	Fri Oct 31 18:33:32 2008
+++ ChangeLog	Mon Nov  3 16:21:31 2008
@@ -1,3 +1,11 @@
+2008-11-03  Teodor Zlatanov  <[email protected]>
+
+	* 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  <[email protected]>
 
 	* ietf-drums.el (ietf-drums-remove-comments): Localize second
Index: auth-source.el
diff -u gnus/lisp/auth-source.el:7.12 gnus/lisp/auth-source.el:7.13
--- auth-source.el:7.12	Wed Jun 11 16:19:44 2008
+++ auth-source.el	Mon Nov  3 16:21:31 2008
@@ -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)