summaryrefslogtreecommitdiff
path: root/lisp/url/url-parse.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/url/url-parse.el')
-rw-r--r--lisp/url/url-parse.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el
index e68e0791558..20432dcf7e5 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")
@@ -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