Mercurial > emacs
annotate lisp/url/url-parse.el @ 83376:de684325b343
Merged in changes from CVS trunk.
Patches applied:
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-6
Update from CVS
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-7
Sync with miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-539.
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--version-0
Branch closed. Use miles@gnu.org--gnu-2005/emacs--cvs-trunk--0 instead.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-475
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-476
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-477
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-478
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-479
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-480
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-481
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-482
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-483
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-484
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-485
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-486
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-487
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-488
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-489
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-490
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-491
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-492
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-493
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-494
Update from CVS: lisp/startup.el (command-line): Fix typo.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-495
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-496
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-497
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-498
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-499
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-500
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-501
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-502
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-503
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-504
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-505
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-506
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-507
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-508
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-509
Update from CVS: .cvsignore: Add `lock'.
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-510
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-511
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-512
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-513
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-514
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-515
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-516
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-517
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-518
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-519
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-520
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-521
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-522
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-523
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-524
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-525
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-526
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-527
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-528
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-529
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-530
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-531
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-532
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-533
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-534
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-535
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-536
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-537
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-538
Update from CVS
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-539
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-88
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-89
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-90
Update FSF's address in GPL notices
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-91
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-92
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-93
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-94
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-95
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-96
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-97
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-98
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-99
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-100
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-101
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-102
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-103
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-104
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-105
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-106
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-107
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-108
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-109
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-110
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-111
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-112
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-113
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-114
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-416
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 11 Sep 2005 08:23:50 +0000 |
parents | 532e0a9335a9 |
children | d04d8ccb3c41 |
rev | line source |
---|---|
54695 | 1 ;;; url-parse.el --- Uniform Resource Locator parser |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
2 |
64748
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, |
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
5 |
54695 | 6 ;; Keywords: comm, data, processes |
7 | |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
9 ;; |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
13 ;; any later version. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
14 ;; |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
18 ;; GNU General Public License for more details. |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
19 ;; |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64084 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
24 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
25 ;;; Commentary: |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
26 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
27 ;;; Code: |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
28 |
54695 | 29 (require 'url-vars) |
30 | |
31 (autoload 'url-scheme-get-property "url-methods") | |
32 | |
33 (defmacro url-type (urlobj) | |
34 `(aref ,urlobj 0)) | |
35 | |
36 (defmacro url-user (urlobj) | |
37 `(aref ,urlobj 1)) | |
38 | |
39 (defmacro url-password (urlobj) | |
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)) | |
64748
875dcc490074
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64084
diff
changeset
|
88 |
54695 | 89 ;;;###autoload |
90 (defun url-recreate-url (urlobj) | |
54802 | 91 "Recreate a URL string from the parsed URLOBJ." |
54695 | 92 (concat (url-type urlobj) ":" (if (url-host urlobj) "//" "") |
93 (if (url-user urlobj) | |
94 (concat (url-user urlobj) | |
95 (if (url-password urlobj) | |
96 (concat ":" (url-password urlobj))) | |
97 "@")) | |
98 (url-host urlobj) | |
99 (if (and (url-port urlobj) | |
100 (not (equal (url-port urlobj) | |
101 (url-scheme-get-property (url-type urlobj) 'default-port)))) | |
102 (format ":%d" (url-port urlobj))) | |
103 (or (url-filename urlobj) "/") | |
104 (if (url-target urlobj) | |
105 (concat "#" (url-target urlobj))) | |
106 (if (url-attributes urlobj) | |
107 (concat ";" | |
108 (mapconcat | |
109 (function | |
110 (lambda (x) | |
111 (if (cdr x) | |
112 (concat (car x) "=" (cdr x)) | |
113 (car x)))) (url-attributes urlobj) ";"))))) | |
114 | |
115 ;;;###autoload | |
116 (defun url-generic-parse-url (url) | |
117 "Return a vector of the parts of URL. | |
118 Format is: | |
54802 | 119 \[TYPE USER PASSWORD HOST PORT FILE TARGET ATTRIBUTES FULL\]" |
54695 | 120 (cond |
121 ((null url) | |
122 (make-vector 9 nil)) | |
123 ((or (not (string-match url-nonrelative-link url)) | |
124 (= ?/ (string-to-char url))) | |
125 (let ((retval (make-vector 9 nil))) | |
126 (url-set-filename retval url) | |
127 (url-set-full retval nil) | |
128 retval)) | |
129 (t | |
130 (save-excursion | |
131 (set-buffer (get-buffer-create " *urlparse*")) | |
132 (set-syntax-table url-parse-syntax-table) | |
133 (let ((save-pos nil) | |
134 (prot nil) | |
135 (user nil) | |
136 (pass nil) | |
137 (host nil) | |
138 (port nil) | |
139 (file nil) | |
140 (refs nil) | |
141 (attr nil) | |
142 (full nil) | |
143 (inhibit-read-only t)) | |
144 (erase-buffer) | |
145 (insert url) | |
146 (goto-char (point-min)) | |
147 (setq save-pos (point)) | |
148 (if (not (looking-at "//")) | |
149 (progn | |
150 (skip-chars-forward "a-zA-Z+.\\-") | |
151 (downcase-region save-pos (point)) | |
152 (setq prot (buffer-substring save-pos (point))) | |
153 (skip-chars-forward ":") | |
154 (setq save-pos (point)))) | |
155 | |
156 ;; We are doing a fully specified URL, with hostname and all | |
157 (if (looking-at "//") | |
158 (progn | |
159 (setq full t) | |
160 (forward-char 2) | |
161 (setq save-pos (point)) | |
162 (skip-chars-forward "^/") | |
163 (setq host (buffer-substring save-pos (point))) | |
164 (if (string-match "^\\([^@]+\\)@" host) | |
165 (setq user (match-string 1 host) | |
166 host (substring host (match-end 0) nil))) | |
167 (if (and user (string-match "\\([^:]+\\):\\(.*\\)" user)) | |
168 (setq pass (match-string 2 user) | |
169 user (match-string 1 user))) | |
170 (if (string-match ":\\([0-9+]+\\)" host) | |
62400
e30c08177a3b
Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents:
57427
diff
changeset
|
171 (setq port (string-to-number (match-string 1 host)) |
54695 | 172 host (substring host 0 (match-beginning 0)))) |
173 (if (string-match ":$" host) | |
174 (setq host (substring host 0 (match-beginning 0)))) | |
175 (setq host (downcase host) | |
176 save-pos (point)))) | |
177 | |
178 (if (not port) | |
179 (setq port (url-scheme-get-property prot 'default-port))) | |
180 | |
181 ;; Gross hack to preserve ';' in data URLs | |
182 | |
183 (setq save-pos (point)) | |
184 | |
185 (if (string= "data" prot) | |
186 (goto-char (point-max)) | |
187 ;; Now check for references | |
188 (skip-chars-forward "^#") | |
189 (if (eobp) | |
190 nil | |
191 (delete-region | |
192 (point) | |
193 (progn | |
194 (skip-chars-forward "#") | |
195 (setq refs (buffer-substring (point) (point-max))) | |
196 (point-max)))) | |
197 (goto-char save-pos) | |
198 (skip-chars-forward "^;") | |
199 (if (not (eobp)) | |
200 (setq attr (url-parse-args (buffer-substring (point) (point-max)) t) | |
201 attr (nreverse attr)))) | |
202 | |
203 (setq file (buffer-substring save-pos (point))) | |
204 (if (and host (string-match "%[0-9][0-9]" host)) | |
205 (setq host (url-unhex-string host))) | |
206 (vector prot user pass host port file refs attr full)))))) | |
207 | |
208 (provide 'url-parse) | |
54699 | 209 |
54831
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
210 ;; arch-tag: f338325f-71ab-4bee-93cc-78fb9a03d403 |
ca18766bb266
Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54802
diff
changeset
|
211 ;;; url-parse.el ends here |