annotate lisp/url/url-parse.el @ 111684:280ee0988e1a

* lisp/shell.el (shell): Use current-buffer by default if it's already a shell mode buffer and its process is dead. Suggested by <jemarch@gnu.org>.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 23 Nov 2010 09:19:54 -0500
parents 754df5a0efe9
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
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,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106281
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
54831
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
5
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: comm, data, processes
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
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 ;;
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
54831
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
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
13 ;; (at your option) any later version.
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
14
54831
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.
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
19
54831
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
94668
8259d0d8e107 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 88005
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
54831
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
22
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
23 ;;; Commentary:
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 ;;; Code:
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
26
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27 (require 'url-vars)
109038
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
28 (require 'auth-source)
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
29 (eval-when-compile (require 'cl))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 (autoload 'url-scheme-get-property "url-methods")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
33 (defstruct (url
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
34 (:constructor nil)
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
35 (:constructor url-parse-make-urlobj
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
36 (&optional type user password host portspec filename
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
37 target attributes fullness))
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
38 (:copier nil))
110693
754df5a0efe9 Modify url-retrieve and related functions and structures to respect a
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 109038
diff changeset
39 type user password host portspec filename target attributes fullness silent)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
41 (defsubst url-port (urlobj)
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
42 (or (url-portspec urlobj)
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
43 (if (url-fullness urlobj)
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
44 (url-scheme-get-property (url-type urlobj) 'default-port))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
46 (defsetf url-port (urlobj) (port) `(setf (url-portspec ,urlobj) ,port))
64748
875dcc490074 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
47
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 (defun url-recreate-url (urlobj)
54802
15a07e792605 Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54770
diff changeset
50 "Recreate a URL string from the parsed URLOBJ."
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 (concat (url-type urlobj) ":" (if (url-host urlobj) "//" "")
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 (if (url-user urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 (concat (url-user urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 (if (url-password urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 (concat ":" (url-password urlobj)))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 "@"))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 (url-host urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (if (and (url-port urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 (not (equal (url-port urlobj)
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 (url-scheme-get-property (url-type urlobj) 'default-port))))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 (format ":%d" (url-port urlobj)))
72589
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
62 (or (url-filename urlobj) "/")
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
63 (url-recreate-url-attributes urlobj)
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 (if (url-target urlobj)
72589
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
65 (concat "#" (url-target urlobj)))))
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
66
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
67 (defun url-recreate-url-attributes (urlobj)
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
68 "Recreate the attributes of an URL string from the parsed URLOBJ."
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
69 (when (url-attributes urlobj)
77220
4368e2079b5c (url-generic-parse-url): Revert 2006-10-09 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
70 (concat ";"
72589
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
71 (mapconcat (lambda (x)
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
72 (if (cdr x)
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
73 (concat (car x) "=" (cdr x))
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
74 (car x)))
f6c1ac4c14c7 (url-recreate-url-attributes): New function, code moved from `url-recreate-url'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
75 (url-attributes urlobj) ";"))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 ;;;###autoload
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 (defun url-generic-parse-url (url)
88005
858074177461 (url-generic-parse-url): Fix docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
79 "Return an URL-struct of the parts of URL.
858074177461 (url-generic-parse-url): Fix docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
80 The CL-style struct contains the following fields:
858074177461 (url-generic-parse-url): Fix docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
81 TYPE USER PASSWORD HOST PORTSPEC FILENAME TARGET ATTRIBUTES FULLNESS."
73313
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
82 ;; See RFC 3986.
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 (cond
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 ((null url)
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
85 (url-parse-make-urlobj))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 ((or (not (string-match url-nonrelative-link url))
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87 (= ?/ (string-to-char url)))
73313
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
88 ;; This isn't correct, as a relative URL can be a fragment link
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
89 ;; (e.g. "#foo") and many other things (see section 4.2).
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
90 ;; However, let's not fix something that isn't broken, especially
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
91 ;; when close to a release.
83823
dd2bcc6758a0 * url-parse.el (url): Use defstruct rather than macros. Update all callers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78222
diff changeset
92 (url-parse-make-urlobj nil nil nil nil nil url))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (t
74014
fd0232950658 (url-generic-parse-url): Use with-temp-buffer.
Magnus Henoch <mange@freemail.hu>
parents: 73313
diff changeset
94 (with-temp-buffer
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
95 ;; Don't let those temp-buffer modifications accidentally
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
96 ;; deactivate the mark of the current-buffer.
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
97 (let ((deactivate-mark nil))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
98 (set-syntax-table url-parse-syntax-table)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
99 (let ((save-pos nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
100 (prot nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
101 (user nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
102 (pass nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
103 (host nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
104 (port nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
105 (file nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
106 (refs nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
107 (attr nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
108 (full nil)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
109 (inhibit-read-only t))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
110 (erase-buffer)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
111 (insert url)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
112 (goto-char (point-min))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
113 (setq save-pos (point))
73313
8c2a0bfc98b0 (url-generic-parse-url): Handle URLs with empty path component and
Magnus Henoch <mange@freemail.hu>
parents: 72589
diff changeset
114
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
115 ;; 3.1. Scheme
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
116 (unless (looking-at "//")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
117 (skip-chars-forward "a-zA-Z+.\\-")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
118 (downcase-region save-pos (point))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
119 (setq prot (buffer-substring save-pos (point)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
120 (skip-chars-forward ":")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
121 (setq save-pos (point)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
123 ;; 3.2. Authority
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
124 (when (looking-at "//")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
125 (setq full t)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
126 (forward-char 2)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
127 (setq save-pos (point))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
128 (skip-chars-forward "^/")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
129 (setq host (buffer-substring save-pos (point)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
130 (if (string-match "^\\([^@]+\\)@" host)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
131 (setq user (match-string 1 host)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
132 host (substring host (match-end 0) nil)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
133 (if (and user (string-match "\\([^:]+\\):\\(.*\\)" user))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
134 (setq pass (match-string 2 user)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
135 user (match-string 1 user)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
136 ;; This gives wrong results for IPv6 literal addresses.
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
137 (if (string-match ":\\([0-9+]+\\)" host)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
138 (setq port (string-to-number (match-string 1 host))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
139 host (substring host 0 (match-beginning 0))))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
140 (if (string-match ":$" host)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
141 (setq host (substring host 0 (match-beginning 0))))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
142 (setq host (downcase host)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
143 save-pos (point)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
145 (if (not port)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
146 (setq port (url-scheme-get-property prot 'default-port)))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
148 ;; 3.3. Path
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
149 ;; Gross hack to preserve ';' in data URLs
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
150 (setq save-pos (point))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
152 ;; 3.4. Query
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
153 (if (string= "data" prot)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
154 (goto-char (point-max))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
155 ;; Now check for references
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
156 (skip-chars-forward "^#")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
157 (if (eobp)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
158 nil
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
159 (delete-region
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
160 (point)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
161 (progn
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
162 (skip-chars-forward "#")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
163 (setq refs (buffer-substring (point) (point-max)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
164 (point-max))))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
165 (goto-char save-pos)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
166 (skip-chars-forward "^;")
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
167 (unless (eobp)
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
168 (setq attr (url-parse-args (buffer-substring (point) (point-max))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
169 t)
77220
4368e2079b5c (url-generic-parse-url): Revert 2006-10-09 changes.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
170 attr (nreverse attr))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171
106281
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
172 (setq file (buffer-substring save-pos (point)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
173 (if (and host (string-match "%[0-9][0-9]" host))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
174 (setq host (url-unhex-string host)))
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
175 (url-parse-make-urlobj
b240f123834a (url-generic-parse-url): Bind deactivate-mark.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 100908
diff changeset
176 prot user pass host port file refs attr full)))))))
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177
109038
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
178 (defmacro url-bit-for-url (method lookfor url)
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
179 `(let* ((urlobj (url-generic-parse-url url))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
180 (bit (funcall ,method urlobj))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
181 (methods (list 'url-recreate-url
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
182 'url-host)))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
183 (while (and (not bit) (> (length methods) 0))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
184 (setq bit
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
185 (auth-source-user-or-password
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
186 ,lookfor (funcall (pop methods) urlobj) (url-type urlobj))))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
187 bit))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
188
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
189 (defun url-user-for-url (url)
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
190 "Attempt to use .authinfo to find a user for this URL."
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
191 (url-bit-for-url 'url-user "login" url))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
192
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
193 (defun url-password-for-url (url)
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
194 "Attempt to use .authinfo to find a password for this URL."
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
195 (url-bit-for-url 'url-password "password" url))
fc2c0625a14a Add in some useful convenience functions for handling HTTP.
Mark A. Hershberger <mah@everybody.org>
parents: 106815
diff changeset
196
54695
3fb37923e567 Initial revision
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (provide 'url-parse)
54699
7784ae10206d Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 54698
diff changeset
198
54831
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
199 ;; arch-tag: f338325f-71ab-4bee-93cc-78fb9a03d403
ca18766bb266 Comment fixups.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54802
diff changeset
200 ;;; url-parse.el ends here