diff options
Diffstat (limited to 'lisp/url/url-parse.el')
-rw-r--r-- | lisp/url/url-parse.el | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el index ee1df01e14a..2ac7685c6cc 100644 --- a/lisp/url/url-parse.el +++ b/lisp/url/url-parse.el @@ -25,6 +25,7 @@ ;;; Code: (require 'url-vars) +(require 'auth-source) (eval-when-compile (require 'cl)) (autoload 'url-scheme-get-property "url-methods") @@ -35,7 +36,7 @@ (&optional type user password host portspec filename target attributes fullness)) (:copier nil)) - type user password host portspec filename target attributes fullness) + type user password host portspec filename target attributes fullness silent) (defsubst url-port (urlobj) (or (url-portspec urlobj) @@ -174,6 +175,25 @@ TYPE USER PASSWORD HOST PORTSPEC FILENAME TARGET ATTRIBUTES FULLNESS." (url-parse-make-urlobj prot user pass host port file refs attr full))))))) +(defmacro url-bit-for-url (method lookfor url) + `(let* ((urlobj (url-generic-parse-url url)) + (bit (funcall ,method urlobj)) + (methods (list 'url-recreate-url + 'url-host))) + (while (and (not bit) (> (length methods) 0)) + (setq bit + (auth-source-user-or-password + ,lookfor (funcall (pop methods) urlobj) (url-type urlobj)))) + bit)) + +(defun url-user-for-url (url) + "Attempt to use .authinfo to find a user for this URL." + (url-bit-for-url 'url-user "login" url)) + +(defun url-password-for-url (url) + "Attempt to use .authinfo to find a password for this URL." + (url-bit-for-url 'url-password "password" url)) + (provide 'url-parse) ;; arch-tag: f338325f-71ab-4bee-93cc-78fb9a03d403 |