diff options
| author | Stefan Monnier | 2007-08-31 16:40:05 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-08-31 16:40:05 +0000 |
| commit | d18ec89f1c7043f65913752aae40ec109624f8ef (patch) | |
| tree | ea27a7a77b36e119da0d1c450615e3e76f149501 | |
| parent | 7c1bfeccb0d3c330fee1a3628784da157f5e75c2 (diff) | |
| download | emacs-d18ec89f1c7043f65913752aae40ec109624f8ef.tar.gz emacs-d18ec89f1c7043f65913752aae40ec109624f8ef.zip | |
* url-parse.el (url): Use defstruct rather than macros. Update all callers.
| -rw-r--r-- | lisp/url/ChangeLog | 11 | ||||
| -rw-r--r-- | lisp/url/url-expand.el | 23 | ||||
| -rw-r--r-- | lisp/url/url-file.el | 5 | ||||
| -rw-r--r-- | lisp/url/url-mailto.el | 2 | ||||
| -rw-r--r-- | lisp/url/url-methods.el | 14 | ||||
| -rw-r--r-- | lisp/url/url-parse.el | 76 | ||||
| -rw-r--r-- | lisp/url/url-util.el | 6 |
7 files changed, 54 insertions, 83 deletions
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 46a2bb62a75..7c03877a161 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2007-08-31 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * url-parse.el (url): Use defstruct rather than macros. | ||
| 4 | (url-generic-parse-url): | ||
| 5 | * url-util.el (url-normalize-url, url-truncate-url-for-viewing): | ||
| 6 | * url-methods.el (url-scheme-register-proxy): | ||
| 7 | * url-mailto.el (url-mailto): | ||
| 8 | * url-file.el (url-file-build-filename): | ||
| 9 | * url-expand.el (url-identity-expander, url-default-expander): | ||
| 10 | Update all callers. | ||
| 11 | |||
| 1 | 2007-08-08 Glenn Morris <rgm@gnu.org> | 12 | 2007-08-08 Glenn Morris <rgm@gnu.org> |
| 2 | 13 | ||
| 3 | * url-auth.el, url-cache.el, url-dav.el, url-file.el, vc-dav.el: | 14 | * url-auth.el, url-cache.el, url-dav.el, url-file.el, vc-dav.el: |
diff --git a/lisp/url/url-expand.el b/lisp/url/url-expand.el index 7b3b105d951..df4de29a619 100644 --- a/lisp/url/url-expand.el +++ b/lisp/url/url-expand.el | |||
| @@ -106,24 +106,24 @@ path components followed by `..' are removed, along with the `..' itself." | |||
| 106 | (url-recreate-url urlobj))))) | 106 | (url-recreate-url urlobj))))) |
| 107 | 107 | ||
| 108 | (defun url-identity-expander (urlobj defobj) | 108 | (defun url-identity-expander (urlobj defobj) |
| 109 | (url-set-type urlobj (or (url-type urlobj) (url-type defobj)))) | 109 | (setf (url-type urlobj) (or (url-type urlobj) (url-type defobj)))) |
| 110 | 110 | ||
| 111 | (defun url-default-expander (urlobj defobj) | 111 | (defun url-default-expander (urlobj defobj) |
| 112 | ;; The default expansion routine - urlobj is modified by side effect! | 112 | ;; The default expansion routine - urlobj is modified by side effect! |
| 113 | (if (url-type urlobj) | 113 | (if (url-type urlobj) |
| 114 | ;; Well, they told us the scheme, let's just go with it. | 114 | ;; Well, they told us the scheme, let's just go with it. |
| 115 | nil | 115 | nil |
| 116 | (url-set-type urlobj (or (url-type urlobj) (url-type defobj))) | 116 | (setf (url-type urlobj) (or (url-type urlobj) (url-type defobj))) |
| 117 | (url-set-port urlobj (or (url-port urlobj) | 117 | (setf (url-port urlobj) (or (url-port urlobj) |
| 118 | (and (string= (url-type urlobj) | 118 | (and (string= (url-type urlobj) |
| 119 | (url-type defobj)) | 119 | (url-type defobj)) |
| 120 | (url-port defobj)))) | 120 | (url-port defobj)))) |
| 121 | (if (not (string= "file" (url-type urlobj))) | 121 | (if (not (string= "file" (url-type urlobj))) |
| 122 | (url-set-host urlobj (or (url-host urlobj) (url-host defobj)))) | 122 | (setf (url-host urlobj) (or (url-host urlobj) (url-host defobj)))) |
| 123 | (if (string= "ftp" (url-type urlobj)) | 123 | (if (string= "ftp" (url-type urlobj)) |
| 124 | (url-set-user urlobj (or (url-user urlobj) (url-user defobj)))) | 124 | (setf (url-user urlobj) (or (url-user urlobj) (url-user defobj)))) |
| 125 | (if (string= (url-filename urlobj) "") | 125 | (if (string= (url-filename urlobj) "") |
| 126 | (url-set-filename urlobj "/")) | 126 | (setf (url-filename urlobj) "/")) |
| 127 | (if (string-match "^/" (url-filename urlobj)) | 127 | (if (string-match "^/" (url-filename urlobj)) |
| 128 | nil | 128 | nil |
| 129 | (let ((query nil) | 129 | (let ((query nil) |
| @@ -136,9 +136,10 @@ path components followed by `..' are removed, along with the `..' itself." | |||
| 136 | (setq file (url-filename urlobj))) | 136 | (setq file (url-filename urlobj))) |
| 137 | (setq file (url-expander-remove-relative-links | 137 | (setq file (url-expander-remove-relative-links |
| 138 | (concat (url-basepath (url-filename defobj)) file))) | 138 | (concat (url-basepath (url-filename defobj)) file))) |
| 139 | (url-set-filename urlobj (if query (concat file sepchar query) file)))))) | 139 | (setf (url-filename urlobj) |
| 140 | (if query (concat file sepchar query) file)))))) | ||
| 140 | 141 | ||
| 141 | (provide 'url-expand) | 142 | (provide 'url-expand) |
| 142 | 143 | ||
| 143 | ;;; arch-tag: 7b5f744b-b721-49da-be47-484631680a5a | 144 | ;; arch-tag: 7b5f744b-b721-49da-be47-484631680a5a |
| 144 | ;;; url-expand.el ends here | 145 | ;;; url-expand.el ends here |
diff --git a/lisp/url/url-file.el b/lisp/url/url-file.el index 6e771c9cd69..c361016856b 100644 --- a/lisp/url/url-file.el +++ b/lisp/url/url-file.el | |||
| @@ -127,10 +127,11 @@ to them." | |||
| 127 | ;; straighten it out for us? | 127 | ;; straighten it out for us? |
| 128 | ;; (if (and (file-directory-p filename) | 128 | ;; (if (and (file-directory-p filename) |
| 129 | ;; (not (string-match (format "%c$" directory-sep-char) filename))) | 129 | ;; (not (string-match (format "%c$" directory-sep-char) filename))) |
| 130 | ;; (url-set-filename url (format "%s%c" filename directory-sep-char))) | 130 | ;; (setf (url-filename url) |
| 131 | ;; (format "%s%c" filename directory-sep-char))) | ||
| 131 | (if (and (file-directory-p filename) | 132 | (if (and (file-directory-p filename) |
| 132 | (not (string-match "/\\'" filename))) | 133 | (not (string-match "/\\'" filename))) |
| 133 | (url-set-filename url (format "%s/" filename))) | 134 | (setf (url-filename url) (format "%s/" filename))) |
| 134 | 135 | ||
| 135 | 136 | ||
| 136 | ;; If it is a directory, look for an index file first. | 137 | ;; If it is a directory, look for an index file first. |
diff --git a/lisp/url/url-mailto.el b/lisp/url/url-mailto.el index 10d08b9633f..4b15d07245b 100644 --- a/lisp/url/url-mailto.el +++ b/lisp/url/url-mailto.el | |||
| @@ -66,7 +66,7 @@ | |||
| 66 | (if (url-user url) | 66 | (if (url-user url) |
| 67 | ;; malformed mailto URL (mailto://wmperry@gnu.org) instead of | 67 | ;; malformed mailto URL (mailto://wmperry@gnu.org) instead of |
| 68 | ;; mailto:wmperry@gnu.org | 68 | ;; mailto:wmperry@gnu.org |
| 69 | (url-set-filename url (concat (url-user url) "@" (url-filename url)))) | 69 | (setf (url-filename url) (concat (url-user url) "@" (url-filename url)))) |
| 70 | (setq url (url-filename url)) | 70 | (setq url (url-filename url)) |
| 71 | (let (to args source-url subject func headers-start) | 71 | (let (to args source-url subject func headers-start) |
| 72 | (if (string-match (regexp-quote "?") url) | 72 | (if (string-match (regexp-quote "?") url) |
diff --git a/lisp/url/url-methods.el b/lisp/url/url-methods.el index 89c36bec737..94dcd49f00d 100644 --- a/lisp/url/url-methods.el +++ b/lisp/url/url-methods.el | |||
| @@ -89,19 +89,19 @@ | |||
| 89 | ;; First check if its something like hostname:port | 89 | ;; First check if its something like hostname:port |
| 90 | ((string-match "^\\([^:]+\\):\\([0-9]+\\)$" env-proxy) | 90 | ((string-match "^\\([^:]+\\):\\([0-9]+\\)$" env-proxy) |
| 91 | (setq urlobj (url-generic-parse-url nil)) ; Get a blank object | 91 | (setq urlobj (url-generic-parse-url nil)) ; Get a blank object |
| 92 | (url-set-type urlobj "http") | 92 | (setf (url-type urlobj) "http") |
| 93 | (url-set-host urlobj (match-string 1 env-proxy)) | 93 | (setf (url-host urlobj) (match-string 1 env-proxy)) |
| 94 | (url-set-port urlobj (string-to-number (match-string 2 env-proxy)))) | 94 | (setf (url-port urlobj) (string-to-number (match-string 2 env-proxy)))) |
| 95 | ;; Then check if its a fully specified URL | 95 | ;; Then check if its a fully specified URL |
| 96 | ((string-match url-nonrelative-link env-proxy) | 96 | ((string-match url-nonrelative-link env-proxy) |
| 97 | (setq urlobj (url-generic-parse-url env-proxy)) | 97 | (setq urlobj (url-generic-parse-url env-proxy)) |
| 98 | (url-set-type urlobj "http") | 98 | (setf (url-type urlobj) "http") |
| 99 | (url-set-target urlobj nil)) | 99 | (setf (url-target urlobj) nil)) |
| 100 | ;; Finally, fall back on the assumption that its just a hostname | 100 | ;; Finally, fall back on the assumption that its just a hostname |
| 101 | (t | 101 | (t |
| 102 | (setq urlobj (url-generic-parse-url nil)) ; Get a blank object | 102 | (setq urlobj (url-generic-parse-url nil)) ; Get a blank object |
| 103 | (url-set-type urlobj "http") | 103 | (setf (url-type urlobj) "http") |
| 104 | (url-set-host urlobj env-proxy))) | 104 | (setf (url-host urlobj) env-proxy))) |
| 105 | 105 | ||
| 106 | (if (and (not cur-proxy) urlobj) | 106 | (if (and (not cur-proxy) urlobj) |
| 107 | (progn | 107 | (progn |
diff --git a/lisp/url/url-parse.el b/lisp/url/url-parse.el index 3dfc7ac86a2..9f3437f401c 100644 --- a/lisp/url/url-parse.el +++ b/lisp/url/url-parse.el | |||
| @@ -27,64 +27,24 @@ | |||
| 27 | ;;; Code: | 27 | ;;; Code: |
| 28 | 28 | ||
| 29 | (require 'url-vars) | 29 | (require 'url-vars) |
| 30 | (eval-when-compile (require 'cl)) | ||
| 30 | 31 | ||
| 31 | (autoload 'url-scheme-get-property "url-methods") | 32 | (autoload 'url-scheme-get-property "url-methods") |
| 32 | 33 | ||
| 33 | (defmacro url-type (urlobj) | 34 | (defstruct (url |
| 34 | `(aref ,urlobj 0)) | 35 | (:constructor nil) |
| 36 | (:constructor url-parse-make-urlobj | ||
| 37 | (&optional type user password host portspec filename | ||
| 38 | target attributes fullness)) | ||
| 39 | (:copier nil)) | ||
| 40 | type user password host portspec filename target attributes fullness) | ||
| 35 | 41 | ||
| 36 | (defmacro url-user (urlobj) | 42 | (defsubst url-port (urlobj) |
| 37 | `(aref ,urlobj 1)) | 43 | (or (url-portspec urlobj) |
| 44 | (if (url-fullness urlobj) | ||
| 45 | (url-scheme-get-property (url-type urlobj) 'default-port)))) | ||
| 38 | 46 | ||
| 39 | (defmacro url-password (urlobj) | 47 | (defsetf url-port (urlobj) (port) `(setf (url-portspec ,urlobj) ,port)) |
| 40 | `(aref ,urlobj 2)) | ||
| 41 | |||
| 42 | (defmacro url-host (urlobj) | ||
| 43 | `(aref ,urlobj 3)) | ||
| 44 | |||
| 45 | (defmacro url-port (urlobj) | ||
| 46 | `(or (aref ,urlobj 4) | ||
| 47 | (if (url-fullness ,urlobj) | ||
| 48 | (url-scheme-get-property (url-type ,urlobj) 'default-port)))) | ||
| 49 | |||
| 50 | (defmacro url-filename (urlobj) | ||
| 51 | `(aref ,urlobj 5)) | ||
| 52 | |||
| 53 | (defmacro url-target (urlobj) | ||
| 54 | `(aref ,urlobj 6)) | ||
| 55 | |||
| 56 | (defmacro url-attributes (urlobj) | ||
| 57 | `(aref ,urlobj 7)) | ||
| 58 | |||
| 59 | (defmacro url-fullness (urlobj) | ||
| 60 | `(aref ,urlobj 8)) | ||
| 61 | |||
| 62 | (defmacro url-set-type (urlobj type) | ||
| 63 | `(aset ,urlobj 0 ,type)) | ||
| 64 | |||
| 65 | (defmacro url-set-user (urlobj user) | ||
| 66 | `(aset ,urlobj 1 ,user)) | ||
| 67 | |||
| 68 | (defmacro url-set-password (urlobj pass) | ||
| 69 | `(aset ,urlobj 2 ,pass)) | ||
| 70 | |||
| 71 | (defmacro url-set-host (urlobj host) | ||
| 72 | `(aset ,urlobj 3 ,host)) | ||
| 73 | |||
| 74 | (defmacro url-set-port (urlobj port) | ||
| 75 | `(aset ,urlobj 4 ,port)) | ||
| 76 | |||
| 77 | (defmacro url-set-filename (urlobj file) | ||
| 78 | `(aset ,urlobj 5 ,file)) | ||
| 79 | |||
| 80 | (defmacro url-set-target (urlobj targ) | ||
| 81 | `(aset ,urlobj 6 ,targ)) | ||
| 82 | |||
| 83 | (defmacro url-set-attributes (urlobj targ) | ||
| 84 | `(aset ,urlobj 7 ,targ)) | ||
| 85 | |||
| 86 | (defmacro url-set-full (urlobj val) | ||
| 87 | `(aset ,urlobj 8 ,val)) | ||
| 88 | 48 | ||
| 89 | ;;;###autoload | 49 | ;;;###autoload |
| 90 | (defun url-recreate-url (urlobj) | 50 | (defun url-recreate-url (urlobj) |
| @@ -123,17 +83,14 @@ Format is: | |||
| 123 | ;; See RFC 3986. | 83 | ;; See RFC 3986. |
| 124 | (cond | 84 | (cond |
| 125 | ((null url) | 85 | ((null url) |
| 126 | (make-vector 9 nil)) | 86 | (url-parse-make-urlobj)) |
| 127 | ((or (not (string-match url-nonrelative-link url)) | 87 | ((or (not (string-match url-nonrelative-link url)) |
| 128 | (= ?/ (string-to-char url))) | 88 | (= ?/ (string-to-char url))) |
| 129 | ;; This isn't correct, as a relative URL can be a fragment link | 89 | ;; This isn't correct, as a relative URL can be a fragment link |
| 130 | ;; (e.g. "#foo") and many other things (see section 4.2). | 90 | ;; (e.g. "#foo") and many other things (see section 4.2). |
| 131 | ;; However, let's not fix something that isn't broken, especially | 91 | ;; However, let's not fix something that isn't broken, especially |
| 132 | ;; when close to a release. | 92 | ;; when close to a release. |
| 133 | (let ((retval (make-vector 9 nil))) | 93 | (url-parse-make-urlobj nil nil nil nil nil url)) |
| 134 | (url-set-filename retval url) | ||
| 135 | (url-set-full retval nil) | ||
| 136 | retval)) | ||
| 137 | (t | 94 | (t |
| 138 | (with-temp-buffer | 95 | (with-temp-buffer |
| 139 | (set-syntax-table url-parse-syntax-table) | 96 | (set-syntax-table url-parse-syntax-table) |
| @@ -214,7 +171,8 @@ Format is: | |||
| 214 | (setq file (buffer-substring save-pos (point))) | 171 | (setq file (buffer-substring save-pos (point))) |
| 215 | (if (and host (string-match "%[0-9][0-9]" host)) | 172 | (if (and host (string-match "%[0-9][0-9]" host)) |
| 216 | (setq host (url-unhex-string host))) | 173 | (setq host (url-unhex-string host))) |
| 217 | (vector prot user pass host port file refs attr full)))))) | 174 | (url-parse-make-urlobj |
| 175 | prot user pass host port file refs attr full)))))) | ||
| 218 | 176 | ||
| 219 | (provide 'url-parse) | 177 | (provide 'url-parse) |
| 220 | 178 | ||
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el index fa971da5d17..5b5b43a7db7 100644 --- a/lisp/url/url-util.el +++ b/lisp/url/url-util.el | |||
| @@ -168,7 +168,7 @@ Strips out default port numbers, etc." | |||
| 168 | type (url-type data)) | 168 | type (url-type data)) |
| 169 | (if (member type '("www" "about" "mailto" "info")) | 169 | (if (member type '("www" "about" "mailto" "info")) |
| 170 | (setq retval url) | 170 | (setq retval url) |
| 171 | (url-set-target data nil) | 171 | (setf (url-target data) nil) |
| 172 | (setq retval (url-recreate-url data))) | 172 | (setq retval (url-recreate-url data))) |
| 173 | retval)) | 173 | retval)) |
| 174 | 174 | ||
| @@ -421,13 +421,13 @@ WIDTH defaults to the current frame width." | |||
| 421 | (string-match "/" fname)) | 421 | (string-match "/" fname)) |
| 422 | (setq fname (substring fname (match-end 0) nil) | 422 | (setq fname (substring fname (match-end 0) nil) |
| 423 | modified (1+ modified)) | 423 | modified (1+ modified)) |
| 424 | (url-set-filename urlobj fname) | 424 | (setf (url-filename urlobj) fname) |
| 425 | (setq url (url-recreate-url urlobj) | 425 | (setq url (url-recreate-url urlobj) |
| 426 | str-width (length url))) | 426 | str-width (length url))) |
| 427 | (if (> modified 1) | 427 | (if (> modified 1) |
| 428 | (setq fname (concat "/.../" fname)) | 428 | (setq fname (concat "/.../" fname)) |
| 429 | (setq fname (concat "/" fname))) | 429 | (setq fname (concat "/" fname))) |
| 430 | (url-set-filename urlobj fname) | 430 | (setf (url-filename urlobj) fname) |
| 431 | (setq url (url-recreate-url urlobj))) | 431 | (setq url (url-recreate-url urlobj))) |
| 432 | url)) | 432 | url)) |
| 433 | 433 | ||