Add in some useful convenience functions for handling HTTP.

This commit is contained in:
Mark A. Hershberger 2010-06-22 12:48:53 -04:00
parent bc869eca8c
commit 04c2373982
4 changed files with 73 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2010-06-22 Mark A. Hershberger <mah@everybody.org>
* url-parse.el (url-user-for-url, url-password-for-url):
Convenience functions that get usernames and passwords for urls
from auth-source functions.
2010-06-12 Štěpán Němec <stepnem@gmail.com> (tiny change)
* url-vars.el (url-privacy-level): Fix doc typo. (Bug#6406)

View file

@ -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