diff options
| author | Mark A. Hershberger | 2010-06-22 12:48:53 -0400 |
|---|---|---|
| committer | Mark A. Hershberger | 2010-06-22 12:48:53 -0400 |
| commit | 04c23739823fecd98cbc06ad627b36e5bd8e482e (patch) | |
| tree | 743c052ea388d68d0ed259cf1e4fee7c94b6fbbe | |
| parent | bc869eca8c91810c66ead464b57630ccebabaf29 (diff) | |
| download | emacs-04c23739823fecd98cbc06ad627b36e5bd8e482e.tar.gz emacs-04c23739823fecd98cbc06ad627b36e5bd8e482e.zip | |
Add in some useful convenience functions for handling HTTP.
| -rw-r--r-- | lisp/gnus/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/gnus/mm-url.el | 42 | ||||
| -rw-r--r-- | lisp/url/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/url/url-parse.el | 20 |
4 files changed, 73 insertions, 0 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index e50bdb58575..d25caf70347 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2010-06-22 Mark A. Hershberger <mah@everybody.org> | ||
| 2 | |||
| 3 | * mm-url.el (mm-url-encode-multipart-form-data): New function to handle | ||
| 4 | the *other* type of HTML form submission. | ||
| 5 | |||
| 1 | 2010-06-15 Michael Albinus <michael.albinus@gmx.de> | 6 | 2010-06-15 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 7 | ||
| 3 | * auth-source.el (auth-source-pick): If choice does not contain a | 8 | * auth-source.el (auth-source-pick): If choice does not contain a |
diff --git a/lisp/gnus/mm-url.el b/lisp/gnus/mm-url.el index c5a8d9f7fdc..c72f520d60a 100644 --- a/lisp/gnus/mm-url.el +++ b/lisp/gnus/mm-url.el | |||
| @@ -418,6 +418,48 @@ spaces. Die Die Die." | |||
| 418 | (mm-url-form-encode-xwfu (cdr data)))) | 418 | (mm-url-form-encode-xwfu (cdr data)))) |
| 419 | pairs "&")) | 419 | pairs "&")) |
| 420 | 420 | ||
| 421 | (defun mm-url-encode-multipart-form-data (pairs &optional boundary) | ||
| 422 | "Return PAIRS encoded in multipart/form-data." | ||
| 423 | ;; RFC1867 | ||
| 424 | |||
| 425 | ;; Get a good boundary | ||
| 426 | (unless boundary | ||
| 427 | (setq boundary (mml-compute-boundary '()))) | ||
| 428 | |||
| 429 | (concat | ||
| 430 | |||
| 431 | ;; Start with the boundary | ||
| 432 | "--" boundary "\r\n" | ||
| 433 | |||
| 434 | ;; Create name value pairs | ||
| 435 | (mapconcat | ||
| 436 | 'identity | ||
| 437 | ;; Delete any returned items that are empty | ||
| 438 | (delq nil | ||
| 439 | (mapcar (lambda (data) | ||
| 440 | (when (car data) | ||
| 441 | ;; For each pair | ||
| 442 | (concat | ||
| 443 | |||
| 444 | ;; Encode the name | ||
| 445 | "Content-Disposition: form-data; name=\"" | ||
| 446 | (car data) "\"\r\n" | ||
| 447 | "Content-Type: text/plain; charset=utf-8\r\n" | ||
| 448 | "Content-Transfer-Encoding: binary\r\n\r\n" | ||
| 449 | |||
| 450 | (cond ((stringp (cdr data)) | ||
| 451 | (cdr data)) | ||
| 452 | ((integerp (cdr data)) | ||
| 453 | (int-to-string (cdr data)))) | ||
| 454 | |||
| 455 | "\r\n"))) | ||
| 456 | pairs)) | ||
| 457 | ;; use the boundary as a separator | ||
| 458 | (concat "--" boundary "\r\n")) | ||
| 459 | |||
| 460 | ;; put a boundary at the end. | ||
| 461 | "--" boundary "--\r\n")) | ||
| 462 | |||
| 421 | (defun mm-url-fetch-form (url pairs) | 463 | (defun mm-url-fetch-form (url pairs) |
| 422 | "Fetch a form from URL with PAIRS as the data using the POST method." | 464 | "Fetch a form from URL with PAIRS as the data using the POST method." |
| 423 | (mm-url-load-url) | 465 | (mm-url-load-url) |
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 374333150c8..4499ea5ff52 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-06-22 Mark A. Hershberger <mah@everybody.org> | ||
| 2 | |||
| 3 | * url-parse.el (url-user-for-url, url-password-for-url): | ||
| 4 | Convenience functions that get usernames and passwords for urls | ||
| 5 | from auth-source functions. | ||
| 6 | |||
| 1 | 2010-06-12 Štěpán Němec <stepnem@gmail.com> (tiny change) | 7 | 2010-06-12 Štěpán Němec <stepnem@gmail.com> (tiny change) |
| 2 | 8 | ||
| 3 | * url-vars.el (url-privacy-level): Fix doc typo. (Bug#6406) | 9 | * url-vars.el (url-privacy-level): Fix doc typo. (Bug#6406) |
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 @@ | |||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | (require 'url-vars) | 27 | (require 'url-vars) |
| 28 | (require 'auth-source) | ||
| 28 | (eval-when-compile (require 'cl)) | 29 | (eval-when-compile (require 'cl)) |
| 29 | 30 | ||
| 30 | (autoload 'url-scheme-get-property "url-methods") | 31 | (autoload 'url-scheme-get-property "url-methods") |
| @@ -174,6 +175,25 @@ TYPE USER PASSWORD HOST PORTSPEC FILENAME TARGET ATTRIBUTES FULLNESS." | |||
| 174 | (url-parse-make-urlobj | 175 | (url-parse-make-urlobj |
| 175 | prot user pass host port file refs attr full))))))) | 176 | prot user pass host port file refs attr full))))))) |
| 176 | 177 | ||
| 178 | (defmacro url-bit-for-url (method lookfor url) | ||
| 179 | `(let* ((urlobj (url-generic-parse-url url)) | ||
| 180 | (bit (funcall ,method urlobj)) | ||
| 181 | (methods (list 'url-recreate-url | ||
| 182 | 'url-host))) | ||
| 183 | (while (and (not bit) (> (length methods) 0)) | ||
| 184 | (setq bit | ||
| 185 | (auth-source-user-or-password | ||
| 186 | ,lookfor (funcall (pop methods) urlobj) (url-type urlobj)))) | ||
| 187 | bit)) | ||
| 188 | |||
| 189 | (defun url-user-for-url (url) | ||
| 190 | "Attempt to use .authinfo to find a user for this URL." | ||
| 191 | (url-bit-for-url 'url-user "login" url)) | ||
| 192 | |||
| 193 | (defun url-password-for-url (url) | ||
| 194 | "Attempt to use .authinfo to find a password for this URL." | ||
| 195 | (url-bit-for-url 'url-password "password" url)) | ||
| 196 | |||
| 177 | (provide 'url-parse) | 197 | (provide 'url-parse) |
| 178 | 198 | ||
| 179 | ;; arch-tag: f338325f-71ab-4bee-93cc-78fb9a03d403 | 199 | ;; arch-tag: f338325f-71ab-4bee-93cc-78fb9a03d403 |