annotate lisp/w3/url.el @ 27:0a3286277d9b

Added tag r19-15b96 for changeset 441bb1e64a06
author cvs
date Mon, 13 Aug 2007 08:51:34 +0200
parents 441bb1e64a06
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; url.el --- Uniform Resource Locator retrieval tool
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
3 ;; Created: 1997/02/20 15:34:07
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4 ;; Version: 1.57
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: comm, data, processes, hypermedia
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;; LCD Archive Entry:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; url|William M. Perry|wmperry@cs.indiana.edu|
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Functions for retrieving/manipulating URLs|
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
10 ;;; 1997/02/20 15:34:07|1.57|Location Undetermined
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; Copyright (c) 1993-1996 by William M. Perry (wmperry@cs.indiana.edu)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
15 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 (require 'cl)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 (require 'url-vars)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 (require 'url-parse)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 (require 'mm)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 (require 'mule-sysdp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 (or (featurep 'efs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 (featurep 'efs-auto)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 (require 'ange-ftp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 (error nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
47 (eval-and-compile
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
48 (if (not (and (string-match "XEmacs" emacs-version)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
49 (or (> emacs-major-version 19)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
50 (>= emacs-minor-version 14))))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
51 (require 'w3-sysdp)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 ;;; Functions that might not exist in old versions of emacs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 (defun url-save-error (errobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 (set-buffer (get-buffer-create " *url-error*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 (erase-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 (display-error errobj (get-buffer-create " *url-error*")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 ((fboundp 'display-warning)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 (fset 'url-warn 'display-warning))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 ((fboundp 'w3-warn)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 (fset 'url-warn 'w3-warn))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 ((fboundp 'warn)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 (defun url-warn (class message &optional level)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 (warn "(%s/%s) %s" class (or level 'warning) message)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 (defun url-warn (class message &optional level)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 (set-buffer (get-buffer-create "*W3-WARNINGS*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76 (insert (format "(%s/%s) %s\n" class (or level 'warning) message)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 (display-buffer (current-buffer))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 ;;; Autoload all the URL loaders
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 (autoload 'url-file "url-file")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 (autoload 'url-ftp "url-file")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 (autoload 'url-gopher "url-gopher")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 (autoload 'url-irc "url-irc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 (autoload 'url-http "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 (autoload 'url-nfs "url-nfs")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 (autoload 'url-mailserver "url-mail")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 (autoload 'url-mailto "url-mail")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 (autoload 'url-info "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 (autoload 'url-shttp "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 (autoload 'url-https "url-http")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
94 (autoload 'url-data "url-misc")
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 (autoload 'url-finger "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (autoload 'url-rlogin "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 (autoload 'url-telnet "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98 (autoload 'url-tn3270 "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 (autoload 'url-proxy "url-misc")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 (autoload 'url-news "url-news")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 (autoload 'url-nntp "url-news")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
103 (autoload 'url-open-stream "url-gw")
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104 (autoload 'url-mime-response-p "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 (autoload 'url-parse-mime-headers "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (autoload 'url-handle-refresh-header "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 (autoload 'url-create-mime-request "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108 (autoload 'url-create-message-id "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 (autoload 'url-create-multipart-request "url-http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 (autoload 'url-parse-viewer-types "url-http")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
111
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
112 (autoload 'url-get-authentication "url-auth")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
113 (autoload 'url-register-auth-scheme "url-auth")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
114 (autoload 'url-cookie-write-file "url-cookie")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
115 (autoload 'url-cookie-retrieve "url-cookie")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
116 (autoload 'url-cookie-generate-header-lines "url-cookie")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
117 (autoload 'url-cookie-handle-set-cookie "url-cookie")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
118
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
119 (autoload 'url-is-cached "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
120 (autoload 'url-store-in-cache "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
121 (autoload 'url-is-cached "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
122 (autoload 'url-create-cached-filename "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
123 (autoload 'url-extract-from-cache "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
124 (autoload 'url-cache-expired "url-cache")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
125
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
126 (require 'md5)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
127 (require 'base64)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
128
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
130 ;;; File-name-handler-alist functions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 (defun url-setup-file-name-handlers ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 ;; Setup file-name handlers.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 '(cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 ((not (boundp 'file-name-handler-alist))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 nil) ; Don't load if no alist
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 ((rassq 'url-file-handler file-name-handler-alist)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 nil) ; Don't load twice
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 (setq file-name-handler-alist
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 (let ((new-handler (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 (concat "^/*"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 (substring url-nonrelative-link1 nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 'url-file-handler)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 (if file-name-handler-alist
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 (append (list new-handler) file-name-handler-alist)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 (list new-handler)))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 (defun url-file-handler (operation &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 ;; Function called from the file-name-handler-alist routines. OPERATION
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 ;; is what needs to be done ('file-exists-p, etc). args are the arguments
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 ;; that would have been passed to OPERATION."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 (let ((fn (get operation 'url-file-handlers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 (url (car args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 (myargs (cdr args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 (if (= (string-to-char url) ?/)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 (setq url (substring url 1 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 (if fn (apply fn url myargs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 (let (file-name-handler-alist)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 (apply operation url myargs)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 (defun url-file-handler-identity (&rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 (car args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 (defun url-file-handler-null (&rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 (put 'file-directory-p 'url-file-handlers 'url-file-handler-null)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 (put 'substitute-in-file-name 'url-file-handlers 'url-file-handler-identity)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 (put 'file-writable-p 'url-file-handlers 'url-file-handler-null)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 (put 'file-truename 'url-file-handlers 'url-file-handler-identity)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 (put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 (put 'expand-file-name 'url-file-handlers 'url-expand-file-name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 (put 'directory-files 'url-file-handlers 'url-directory-files)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 (put 'file-directory-p 'url-file-handlers 'url-file-directory-p)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 (put 'file-writable-p 'url-file-handlers 'url-file-writable-p)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 (put 'file-readable-p 'url-file-handlers 'url-file-exists)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 (put 'file-executable-p 'url-file-handlers 'null)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 (put 'file-symlink-p 'url-file-handlers 'null)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 (put 'file-exists-p 'url-file-handlers 'url-file-exists)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 (put 'copy-file 'url-file-handlers 'url-copy-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 (put 'file-attributes 'url-file-handlers 'url-file-attributes)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 (put 'file-name-all-completions 'url-file-handlers
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 'url-file-name-all-completions)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 (put 'file-name-completion 'url-file-handlers 'url-file-name-completion)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 (put 'file-local-copy 'url-file-handlers 'url-file-local-copy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 ;;; Utility functions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 ;;; -----------------
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 ;;; Various functions used around the url code.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 ;;; Some of these qualify as hacks, but hey, this is elisp.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 (if (fboundp 'mm-string-to-tokens)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 (fset 'url-string-to-tokens 'mm-string-to-tokens)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 (defun url-string-to-tokens (str &optional delim)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 "Return a list of words from the string STR"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 (setq delim (or delim ? ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 (let (results y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 (mapcar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 ((and (= x delim) y) (setq results (cons y results) y nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 ((/= x delim) (setq y (concat y (char-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 (t nil)))) str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209 (nreverse (cons y results)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 (defun url-days-between (date1 date2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 ;; Return the number of days between date1 and date2.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 (- (url-day-number date1) (url-day-number date2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 (defun url-day-number (date)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 (let ((dat (mapcar (function (lambda (s) (and s (string-to-int s)) ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 (timezone-parse-date date))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 (timezone-absolute-from-gregorian
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 (nth 1 dat) (nth 2 dat) (car dat))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 (defun url-seconds-since-epoch (date)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 ;; Returns a number that says how many seconds have
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 ;; lapsed between Jan 1 12:00:00 1970 and DATE."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 (let* ((tdate (mapcar (function (lambda (ti) (and ti (string-to-int ti))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 (timezone-parse-date date)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 (ttime (mapcar (function (lambda (ti) (and ti (string-to-int ti))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 (timezone-parse-time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 (aref (timezone-parse-date date) 3))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 (edate (mapcar (function (lambda (ti) (and ti (string-to-int ti))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 (timezone-parse-date "Jan 1 12:00:00 1970")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 (tday (- (timezone-absolute-from-gregorian
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 (timezone-absolute-from-gregorian
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 (+ (nth 2 ttime)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236 (* (nth 1 ttime) 60)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 (* (nth 0 ttime) 60 60)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 (* tday 60 60 24))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 (defun url-match (s x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241 ;; Return regexp match x in s.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 (substring s (match-beginning x) (match-end x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 (defun url-split (str del)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 ;; Split the string STR, with DEL (a regular expression) as the delimiter.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 ;; Returns an assoc list that you can use with completing-read."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 (let (x y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 (while (string-match del str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 (setq y (substring str 0 (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 str (substring str (match-end 0) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 (if (not (string-match "^[ \t]+$" y))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 (setq x (cons (list y y) x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 (if (not (equal str ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 (setq x (cons (list str str) x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 (defun url-replace-regexp (regexp to-string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 (while (re-search-forward regexp nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 (replace-match to-string t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262 (defun url-clear-tmp-buffer ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 (if buffer-read-only (toggle-read-only))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 (erase-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267 (defun url-maybe-relative (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 (url-retrieve (url-expand-file-name url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 (defun url-buffer-is-hypertext (&optional buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 "Return t if a buffer contains HTML, as near as we can guess."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (setq buff (or buff (current-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 (set-buffer buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (let ((case-fold-search t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 (re-search-forward
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278 "<\\(TITLE\\|HEAD\\|BASE\\|H[0-9]\\|ISINDEX\\|P\\)>" nil t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 (defun url-percentage (x y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281 (if (fboundp 'float)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 (round (* 100 (/ x (float y))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 (/ (* x 100) y)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
285 (defun url-pretty-length (n)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
286 (cond
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
287 ((< n 1024)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
288 (format "%d bytes" n))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
289 ((< n (* 1024 1024))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
290 (format "%dk" (/ n 1024.0)))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
291 (t
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
292 (format "%2.2fM" (/ n (* 1024 1024.0))))))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
293
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 (defun url-after-change-function (&rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295 ;; The nitty gritty details of messaging the HTTP/1.0 status messages
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296 ;; in the minibuffer."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (or url-current-content-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
298 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
299 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 (if (not (looking-at "HTTP/[0-9]\.[0-9]"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 (setq url-current-content-length 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 (setq url-current-isindex
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
304 (and (re-search-forward "$\r*$" nil t) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305 (if (re-search-forward
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
306 "^content-type:[ \t]*\\([^\r\n]+\\)\r*$"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
307 url-current-isindex t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
308 (setq url-current-mime-type (downcase
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
309 (url-eat-trailing-space
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
310 (buffer-substring
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
311 (match-beginning 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
312 (match-end 1))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
313 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
314 (if (re-search-forward "^content-length:\\([^\r\n]+\\)\r*$"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
315 url-current-isindex t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
316 (setq url-current-content-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
317 (string-to-int (buffer-substring (match-beginning 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
318 (match-end 1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
319 (setq url-current-content-length nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
320 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
321 (let ((current-length (max (point-max)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
322 (if url-current-isindex
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
323 (- (point-max) url-current-isindex)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
324 (point-max)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
325 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
326 ((and url-current-content-length (> url-current-content-length 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
327 url-current-mime-type)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
328 (url-lazy-message "Reading [%s]... %s of %s (%d%%)"
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
329 url-current-mime-type
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
330 (url-pretty-length current-length)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
331 (url-pretty-length url-current-content-length)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
332 (url-percentage current-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
333 url-current-content-length)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
334 ((and url-current-content-length (> url-current-content-length 1))
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
335 (url-lazy-message "Reading... %s of %s (%d%%)"
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
336 (url-pretty-length current-length)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
337 (url-pretty-length url-current-content-length)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
338 (url-percentage current-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
339 url-current-content-length)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
340 ((and (/= 1 current-length) url-current-mime-type)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
341 (url-lazy-message "Reading [%s]... %s"
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
342 url-current-mime-type
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
343 (url-pretty-length current-length)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
344 ((/= 1 current-length)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
345 (url-lazy-message "Reading... %s."
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
346 (url-pretty-length current-length)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
347 (t (url-lazy-message "Waiting for response...")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
348
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
349 (defun url-insert-entities-in-string (string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
350 "Convert HTML markup-start characters to entity references in STRING.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
351 Also replaces the \" character, so that the result may be safely used as
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
352 an attribute value in a tag. Returns a new string with the result of the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
353 conversion. Replaces these characters as follows:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
354 & ==> &amp;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
355 < ==> &lt;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
356 > ==> &gt;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
357 \" ==> &quot;"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
358 (if (string-match "[&<>\"]" string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
359 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
360 (set-buffer (get-buffer-create " *entity*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
361 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
362 (buffer-disable-undo (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
363 (insert string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
364 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
365 (while (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
366 (skip-chars-forward "^&<>\"")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
367 (not (eobp)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
368 (insert (cdr (assq (char-after (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
369 '((?\" . "&quot;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
370 (?& . "&amp;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
371 (?< . "&lt;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
372 (?> . "&gt;")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
373 (delete-char 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
374 (buffer-string))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
375 string))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
376
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
378 ;;; Information information
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
380 (defvar url-process-lookup-table nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
381
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
382 (defun url-process-get (proc prop &optional default)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
383 "Get a value associated to PROC as property PROP
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
384 in plist stored in `url-process-lookup-table'"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
385 (or (plist-get (cdr-safe (assq proc url-process-lookup-table)) prop)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
386 default))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
387
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
388 (defun url-process-put (proc prop val)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
389 "Associate to PROC as property PROP the value VAL
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
390 in plist stored in `url-process-lookup-table'"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
391 (let ((node (assq proc url-process-lookup-table)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
392 (if (not node)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
393 (setq url-process-lookup-table (cons (cons proc (list prop val))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
394 url-process-lookup-table))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
395 (setcdr node (plist-put (cdr node) prop val)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
396
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
397 (defun url-gc-process-lookup-table ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
398 (let (new)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
399 (while url-process-lookup-table
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
400 (if (not (memq (process-status (caar url-process-lookup-table))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
401 '(stop closed nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
402 (setq new (cons (car url-process-lookup-table) new)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
403 (setq url-process-lookup-table (cdr url-process-lookup-table)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
404 (setq url-process-lookup-table new)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
405
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
406 (defun url-process-list ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
407 (url-gc-process-lookup-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
408 (let ((processes (process-list))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
409 (retval nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
410 (while processes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
411 (if (url-process-get (car processes) 'url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
412 (setq retval (cons (car processes) retval)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
413 (setq processes (cdr processes)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
414 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
415
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
416 (defun url-list-processes ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
417 (interactive)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
418 (let ((processes (url-process-list))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
419 proc total-len len type url
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
420 (url-status-buf (get-buffer-create "URL Status Display")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
421 (set-buffer url-status-buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
422 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
423 (display-buffer url-status-buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
424 (insert
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
425 (eval-when-compile (format "%-40s %-20s %-15s" "URL" "Size" "Type")) "\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
426 (eval-when-compile (make-string 77 ?-)) "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
427 (while processes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
428 (setq proc (car processes)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
429 processes (cdr processes))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
430 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
431 (set-buffer (process-buffer proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
432 (setq total-len url-current-content-length
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
433 len (max (point-max)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
434 (if url-current-isindex
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
435 (- (point-max) url-current-isindex)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
436 (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
437 type url-current-mime-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
438 url (url-process-get proc 'url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
439 (set-buffer url-status-buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
440 (insert
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
441 (format "%-40s%s%-20s %-15s\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
442 (url-process-get proc 'url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
443 (if (> (length url) 40)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
444 (format "\n%-40s " " ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
445 " ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
446 (if total-len
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
447 (format "%d of %d" len total-len)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
448 (format "%d" len))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
449 (or type "unknown")))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
450
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
451
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
453 ;;; file-name-handler stuff calls this
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
454 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
455
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
456 (defun url-have-visited-url (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
457 "Return non-nil iff the user has visited URL before.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
458 The return value is a cons of the url and the date last accessed as a string"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
459 (cl-gethash url url-global-history-hash-table))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
460
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
461 (defun url-directory-files (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
462 "Return a list of files on a server."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
463 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
464
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
465 (defun url-file-writable-p (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
466 "Return t iff a url is writable by this user"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
467 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
468
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
469 (defun url-copy-file (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
470 "Copy a url to the specified filename."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
471 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
472
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
473 (defun url-file-directly-accessible-p (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
474 "Returns t iff the specified URL is directly accessible
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
475 on your filesystem. (nfs, local file, etc)."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
476 (let* ((urlobj (if (vectorp url) url (url-generic-parse-url url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
477 (type (url-type urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
478 (and (member type '("file" "ftp"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
479 (not (url-host urlobj)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
480
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
481 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
482 (defun url-file-attributes (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
483 "Return a list of attributes of URL.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
484 Value is nil if specified file cannot be opened.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
485 Otherwise, list elements are:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
486 0. t for directory, string (name linked to) for symbolic link, or nil.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
487 1. Number of links to file.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
488 2. File uid.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
489 3. File gid.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
490 4. Last access time, as a list of two integers.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
491 First integer has high-order 16 bits of time, second has low 16 bits.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
492 5. Last modification time, likewise.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
493 6. Last status change time, likewise.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
494 7. Size in bytes. (-1, if number is out of range).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
495 8. File modes, as a string of ten letters or dashes as in ls -l.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
496 If URL is on an http server, this will return the content-type if possible.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
497 9. t iff file's gid would change if file were deleted and recreated.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
498 10. inode number.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
499 11. Device number.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
500
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
501 If file does not exist, returns nil."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
502 (and url
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
503 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
504 (type (url-type urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
505 (url-automatic-caching nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
506 (data nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
507 (exists nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
508 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
509 ((equal type "http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
510 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
511 ((not url-be-anal-about-file-attributes)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
512 (setq data (list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
513 (url-file-directory-p url) ; Directory
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
514 1 ; number of links to it
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
515 0 ; UID
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
516 0 ; GID
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
517 (cons 0 0) ; Last access time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
518 (cons 0 0) ; Last mod. time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
519 (cons 0 0) ; Last status time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
520 -1 ; file size
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
521 (mm-extension-to-mime
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
522 (url-file-extension (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
523 nil ; gid would change
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
524 0 ; inode number
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
525 0 ; device number
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
526 )))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
527 (t ; HTTP/1.0, use HEAD
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
528 (let ((url-request-method "HEAD")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
529 (url-request-data nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
530 (url-working-buffer " *url-temp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
531 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
532 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
533 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
534 (url-retrieve url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
535 (setq data (and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
536 (setq exists
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
537 (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
538 (assoc "status"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
539 url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
540 (>= exists 200)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
541 (< exists 300)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
542 (list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
543 (url-file-directory-p url) ; Directory
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
544 1 ; links to
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
545 0 ; UID
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
546 0 ; GID
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
547 (cons 0 0) ; Last access time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
548 (cons 0 0) ; Last mod. time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
549 (cons 0 0) ; Last status time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
550 (or ; Size in bytes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
551 (cdr (assoc "content-length"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
552 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
553 -1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
554 (or
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
555 (cdr (assoc "content-type"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
556 url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
557 (mm-extension-to-mime
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
558 (url-file-extension
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
559 (url-filename urlobj)))) ; content-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
560 nil ; gid would change
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
561 0 ; inode number
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
562 0 ; device number
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
563 ))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
564 (error nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
565 (and (not data)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
566 (setq data (list (url-file-directory-p url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
567 1 0 0 (cons 0 0) (cons 0 0) (cons 0 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
568 -1 (mm-extension-to-mime
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
569 (url-file-extension
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
570 (url-filename
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
571 url-current-object)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
572 nil 0 0)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
573 (kill-buffer " *url-temp*"))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
574 ((member type '("ftp" "file"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
575 (let ((fname (if (url-host urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
576 (concat "/"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
577 (if (url-user urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
578 (concat (url-user urlobj) "@")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
579 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
580 (url-host urlobj) ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
581 (url-filename urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
582 (url-filename urlobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
583 (setq data (or (file-attributes fname) (make-list 12 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
584 (setcar (cdr (cdr (cdr (cdr (cdr (cdr (cdr (cdr data))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
585 (mm-extension-to-mime (url-file-extension fname)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
586 (t nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
587 data)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
588
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
589 (defun url-file-name-all-completions (file dirname &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
590 "Return a list of all completions of file name FILE in directory DIR.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
591 These are all file names in directory DIR which begin with FILE."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
592 ;; need to rewrite
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
593 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
594
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
595 (defun url-file-name-completion (file dirname &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
596 "Complete file name FILE in directory DIR.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
597 Returns the longest string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
598 common to all filenames in DIR that start with FILE.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
599 If there is only one and FILE matches it exactly, returns t.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
600 Returns nil if DIR contains no name starting with FILE."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
601 (apply 'url-file-name-all-completions file dirname args))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
602
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
603 (defun url-file-local-copy (file &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
604 "Copy the file FILE into a temporary file on this machine.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
605 Returns the name of the local copy, or nil, if FILE is directly
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
606 accessible."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
607 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
608
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
609 (defun url-insert-file-contents (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
610 "Insert the contents of the URL in this buffer."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
611 (interactive "sURL: ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
612 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
613 (let ((old-asynch url-be-asynchronous))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
614 (setq-default url-be-asynchronous nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
615 (let ((buf (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
616 (url-working-buffer (cdr (url-retrieve url))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
617 (setq-default url-be-asynchronous old-asynch)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
618 (set-buffer url-working-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
619 (url-uncompress)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
620 (set-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
621 (insert-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
622 (setq buffer-file-name url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
623 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
624 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
625 (set-buffer-modified-p nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
626 (kill-buffer url-working-buffer)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
627
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
628 (defun url-file-directory-p (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
629 "Return t iff a url points to a directory"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
630 (equal (substring url -1 nil) "/"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
631
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
632 (defun url-file-exists (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
633 "Return t iff a file exists."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
634 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
635 (type (url-type urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
636 (exists nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
637 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
638 ((equal type "http") ; use head
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
639 (let ((url-request-method "HEAD")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
640 (url-request-data nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
641 (url-working-buffer " *url-temp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
642 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
643 (url-retrieve url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
644 (setq exists (or (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
645 (assoc "status" url-current-mime-headers)) 500))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
646 (kill-buffer " *url-temp*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
647 (setq exists (and (>= exists 200) (< exists 300))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
648 ((member type '("ftp" "file")) ; file-attributes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
649 (let ((fname (if (url-host urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
650 (concat "/"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
651 (if (url-user urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
652 (concat (url-user urlobj) "@")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
653 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
654 (url-host urlobj) ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
655 (url-filename urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
656 (url-filename urlobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
657 (setq exists (file-exists-p fname))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
658 (t nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
659 exists))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
660
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
661 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
662 (defun url-normalize-url (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
663 "Return a 'normalized' version of URL. This strips out default port
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
664 numbers, etc."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
665 (let (type data grok retval)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
666 (setq data (url-generic-parse-url url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
667 type (url-type data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
668 (if (member type '("www" "about" "mailto" "mailserver" "info"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
669 (setq retval url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
670 (setq retval (url-recreate-url data)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
671 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
672
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
673 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
674 (defun url-buffer-visiting (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
675 "Return the name of a buffer (if any) that is visiting URL."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
676 (setq url (url-normalize-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
677 (let ((bufs (buffer-list))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
678 (found nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
679 (if (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
680 (string-match "\\(.*\\)#" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
681 (error nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
682 (setq url (url-match url 1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
683 (while (and bufs (not found))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
684 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
685 (set-buffer (car bufs))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
686 (setq found (if (and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
687 (not (string-match " \\*URL-?[0-9]*\\*" (buffer-name (car bufs))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
688 (memq major-mode '(url-mode w3-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
689 (equal (url-view-url t) url)) (car bufs) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
690 bufs (cdr bufs))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
691 found))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
692
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
693 (defun url-file-size (url &rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
694 "Return the size of a file in bytes, or -1 if can't be determined."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
695 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
696 (type (url-type urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
697 (size -1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
698 (data nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
699 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
700 ((equal type "http") ; use head
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
701 (let ((url-request-method "HEAD")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
702 (url-request-data nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
703 (url-working-buffer " *url-temp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
704 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
705 (url-retrieve url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
706 (setq size (or (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
707 (assoc "content-length" url-current-mime-headers))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
708 -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
709 (kill-buffer " *url-temp*"))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
710 ((member type '("ftp" "file")) ; file-attributes
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
711 (let ((fname (if (url-host urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
712 (concat "/"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
713 (if (url-user urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
714 (concat (url-user urlobj) "@")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
715 "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
716 (url-host urlobj) ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
717 (url-filename urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
718 (url-filename urlobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
719 (setq data (file-attributes fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
720 size (nth 7 data))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
721 (t nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
722 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
723 ((stringp size) (string-to-int size))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
724 ((integerp size) size)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
725 ((null size) -1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
726 (t -1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
727
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
728 (defun url-generate-new-buffer-name (start)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
729 "Create a new buffer name based on START."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
730 (let ((x 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
731 name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
732 (if (not (get-buffer start))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
733 start
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
734 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
735 (setq name (format "%s<%d>" start x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
736 (while (get-buffer name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
737 (setq x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
738 name (format "%s<%d>" start x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
739 name))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
740
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
741 (defun url-generate-unique-filename (&optional fmt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
742 "Generate a unique filename in url-temporary-directory"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
743 (if (not fmt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
744 (let ((base (format "url-tmp.%d" (user-real-uid)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
745 (fname "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
746 (x 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
747 (setq fname (format "%s%d" base x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
748 (while (file-exists-p (expand-file-name fname url-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
749 (setq x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
750 fname (concat base (int-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
751 (expand-file-name fname url-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
752 (let ((base (concat "url" (int-to-string (user-real-uid))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
753 (fname "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
754 (x 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
755 (setq fname (format fmt (concat base (int-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
756 (while (file-exists-p (expand-file-name fname url-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
757 (setq x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
758 fname (format fmt (concat base (int-to-string x)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
759 (expand-file-name fname url-temporary-directory))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
760
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
761 (defun url-lazy-message (&rest args)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
762 "Just like `message', but is a no-op if called more than once a second.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
763 Will not do anything if url-show-status is nil."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
764 (if (or (null url-show-status)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
765 (= url-lazy-message-time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
766 (setq url-lazy-message-time (nth 1 (current-time)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
767 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
768 (apply 'message args)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
769
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
770
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
771 (defun url-kill-process (proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
772 "Kill the process PROC - knows about all the various gateway types,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
773 and acts accordingly."
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
774 (delete-process proc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
775
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
776 (defun url-accept-process-output (proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
777 "Allow any pending output from subprocesses to be read by Emacs.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
778 It is read into the process' buffers or given to their filter functions.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
779 Where possible, this will not exit until some output is received from PROC,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
780 or 1 second has elapsed."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
781 (accept-process-output proc 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
782
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
783 (defun url-process-status (proc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
784 "Return the process status of a url buffer"
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
785 (process-status proc))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
786
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
787
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
789 ;;; Miscellaneous functions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
791 (defun url-setup-privacy-info ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
792 (interactive)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
793 (setq url-system-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
794 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
795 ((or (eq url-privacy-level 'paranoid)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
796 (and (listp url-privacy-level)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
797 (memq 'os url-privacy-level)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
798 nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
799 ((eq system-type 'Apple-Macintosh) "Macintosh")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
800 ((eq system-type 'next-mach) "NeXT")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
801 ((eq system-type 'windows-nt) "Windows-NT; 32bit")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
802 ((eq system-type 'ms-windows) "Windows; 16bit")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
803 ((eq system-type 'ms-dos) "MS-DOS; 32bit")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
804 ((and (eq system-type 'vax-vms) (device-type))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
805 "VMS; X11")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
806 ((eq system-type 'vax-vms) "VMS; TTY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
807 ((eq (device-type) 'x) "X11")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
808 ((eq (device-type) 'ns) "NeXTStep")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
809 ((eq (device-type) 'pm) "OS/2")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
810 ((eq (device-type) 'win32) "Windows; 32bit")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
811 ((eq (device-type) 'tty) "(Unix?); TTY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
812 (t "UnkownPlatform")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
813
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
814 (setq url-personal-mail-address (or url-personal-mail-address
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
815 user-mail-address
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
816 (format "%s@%s" (user-real-login-name)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
817 (system-name))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
818
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
819 (if (or (memq url-privacy-level '(paranoid high))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
820 (and (listp url-privacy-level)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
821 (memq 'email url-privacy-level)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
822 (setq url-personal-mail-address nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
823
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
824 (if (or (eq url-privacy-level 'paranoid)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
825 (and (listp url-privacy-level)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
826 (memq 'os url-privacy-level)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
827 (setq url-os-type nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
828 (let ((vers (emacs-version)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
829 (if (string-match "(\\([^, )]+\\))$" vers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
830 (setq url-os-type (url-match vers 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
831 (setq url-os-type (symbol-name system-type))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
832
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
833 (defun url-handle-no-scheme (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
834 (let ((temp url-registered-protocols)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
835 (found nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
836 (while (and temp (not found))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
837 (if (and (not (member (car (car temp)) '("auto" "www")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
838 (string-match (concat "^" (car (car temp)) "\\.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
839 url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
840 (setq found t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
841 (setq temp (cdr temp))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
842 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
843 (found ; Found something like ftp.spry.com
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
844 (url-retrieve (concat (car (car temp)) "://" url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
845 ((string-match "^www\\." url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
846 (url-retrieve (concat "http://" url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
847 ((string-match "\\(\\.[^\\.]+\\)\\(\\.[^\\.]+\\)" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
848 ;; Ok, we have at least two dots in the filename, just stick http on it
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
849 (url-retrieve (concat "http://" url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
850 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
851 (url-retrieve (concat "http://www." url ".com"))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
852
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
853 (defun url-setup-save-timer ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
854 "Reset the history list timer."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
855 (interactive)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
856 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
857 ((featurep 'itimer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
858 (if (get-itimer "url-history-saver")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
859 (delete-itimer (get-itimer "url-history-saver")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
860 (start-itimer "url-history-saver" 'url-write-global-history
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
861 url-global-history-save-interval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
862 url-global-history-save-interval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
863 ((fboundp 'run-at-time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
864 (run-at-time url-global-history-save-interval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
865 url-global-history-save-interval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
866 'url-write-global-history))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
867 (t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
868
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
869 (defvar url-download-minor-mode nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
870
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
871 (defun url-download-minor-mode (on)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
872 (setq url-download-minor-mode (if on
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
873 (1+ (or url-download-minor-mode 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
874 (1- (or url-download-minor-mode 1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
875 (if (<= url-download-minor-mode 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
876 (setq url-download-minor-mode nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
877
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
878 (defun url-do-setup ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
879 "Do setup - this is to avoid conflict with user settings when URL is
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
880 dumped with emacs."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
881 (if url-setup-done
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
882 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
883
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
884 (add-minor-mode 'url-download-minor-mode " Webbing" nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
885
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
886 ;; Make OS/2 happy
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
887 (setq tcp-binary-process-input-services
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
888 (append '("http" "80")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
889 tcp-binary-process-input-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
890
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
891 ;; Register all the protocols we can handle
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
892 (url-register-protocol 'file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
893 (url-register-protocol 'ftp nil nil "21")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
894 (url-register-protocol 'gopher nil nil "70")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
895 (url-register-protocol 'http nil nil "80")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
896 (url-register-protocol 'https nil nil "443")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
897 (url-register-protocol 'nfs nil nil "2049")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
898 (url-register-protocol 'info nil 'url-identity-expander)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
899 (url-register-protocol 'mailserver nil 'url-identity-expander)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
900 (url-register-protocol 'finger nil 'url-identity-expander "79")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
901 (url-register-protocol 'mailto nil 'url-identity-expander)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
902 (url-register-protocol 'news nil 'url-identity-expander "119")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
903 (url-register-protocol 'nntp nil 'url-identity-expander "119")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
904 (url-register-protocol 'irc nil 'url-identity-expander "6667")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
905 (url-register-protocol 'data nil 'url-identity-expander)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
906 (url-register-protocol 'rlogin)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
907 (url-register-protocol 'telnet)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
908 (url-register-protocol 'tn3270)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
909 (url-register-protocol 'proxy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
910 (url-register-protocol 'auto 'url-handle-no-scheme)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
911
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
912 ;; Register all the authentication schemes we can handle
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
913 (url-register-auth-scheme "basic" nil 4)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
914 (url-register-auth-scheme "digest" nil 7)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
915
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
916 ;; Filename handler stuff for emacsen that support it
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
917 (url-setup-file-name-handlers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
918
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
919 (setq url-cookie-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
920 (or url-cookie-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
921 (expand-file-name "~/.w3cookies")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
922
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
923 (setq url-global-history-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
924 (or url-global-history-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
925 (and (memq system-type '(ms-dos ms-windows))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
926 (expand-file-name "~/mosaic.hst"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
927 (and (memq system-type '(axp-vms vax-vms))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
928 (expand-file-name "~/mosaic.global-history"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
929 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
930 (expand-file-name "~/.mosaic-global-history")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
931 (error nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
932
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
933 ;; Parse the global history file if it exists, so that it can be used
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
934 ;; for URL completion, etc.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
935 (if (and url-global-history-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
936 (file-exists-p url-global-history-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
937 (url-parse-global-history))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
938
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
939 ;; Setup save timer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
940 (and url-global-history-save-interval (url-setup-save-timer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
941
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
942 (if (and url-cookie-file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
943 (file-exists-p url-cookie-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
944 (url-cookie-parse-file url-cookie-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
945
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
946 ;; Read in proxy gateways
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
947 (let ((noproxy (and (not (assoc "no_proxy" url-proxy-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
948 (or (getenv "NO_PROXY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
949 (getenv "no_PROXY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
950 (getenv "no_proxy")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
951 (if noproxy
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
952 (setq url-proxy-services
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
953 (cons (cons "no_proxy"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
954 (concat "\\("
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
955 (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
956 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
957 (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
958 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
959 ((= x ?,) "\\|")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
960 ((= x ? ) "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
961 ((= x ?.) (regexp-quote "."))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
962 ((= x ?*) ".*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
963 ((= x ??) ".")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
964 (t (char-to-string x)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
965 noproxy "") "\\)"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
966 url-proxy-services))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
967
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
968 ;; Set the password entry funtion based on user defaults or guess
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
969 ;; based on which remote-file-access package they are using.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
970 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
971 (url-passwd-entry-func nil) ; Already been set
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
972 ((fboundp 'read-passwd) ; Use secure password if available
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
973 (setq url-passwd-entry-func 'read-passwd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
974 ((or (featurep 'efs) ; Using EFS
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
975 (featurep 'efs-auto)) ; or autoloading efs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
976 (if (not (fboundp 'read-passwd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
977 (autoload 'read-passwd "passwd" "Read in a password" nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
978 (setq url-passwd-entry-func 'read-passwd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
979 ((or (featurep 'ange-ftp) ; Using ange-ftp
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
980 (and (boundp 'file-name-handler-alist)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
981 (not (string-match "Lucid" (emacs-version)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
982 (setq url-passwd-entry-func 'ange-ftp-read-passwd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
983 (t
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
984 (url-warn
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
985 'security
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
986 "(url-setup): Can't determine how to read passwords, winging it.")))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
987
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
988 ;; Set up the news service if they haven't done so
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
989 (setq url-news-server
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
990 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
991 (url-news-server url-news-server)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
992 ((and (boundp 'gnus-default-nntp-server)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
993 (not (equal "" gnus-default-nntp-server)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
994 gnus-default-nntp-server)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
995 ((and (boundp 'gnus-nntp-server)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
996 (not (null gnus-nntp-server))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
997 (not (equal "" gnus-nntp-server)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
998 gnus-nntp-server)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
999 ((and (boundp 'nntp-server-name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1000 (not (null nntp-server-name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1001 (not (equal "" nntp-server-name)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1002 nntp-server-name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1003 ((getenv "NNTPSERVER") (getenv "NNTPSERVER"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1004 (t "news")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1005
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1006 ;; Set up the MIME accept string if they haven't got it hardcoded yet
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1007 (or url-mime-accept-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1008 (setq url-mime-accept-string (url-parse-viewer-types)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1009 (or url-mime-encoding-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1010 (setq url-mime-encoding-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1011 (mapconcat 'car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1012 mm-content-transfer-encodings
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1013 ", ")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1014
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1015 (url-setup-privacy-info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1016 (run-hooks 'url-load-hook)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1017 (setq url-setup-done t)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1018
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1019 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1020 (defun url-get-url-at-point (&optional pt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1021 "Get the URL closest to point, but don't change your
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1022 position. Has a preference for looking backward when not
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1023 directly on a symbol."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1024 ;; Not at all perfect - point must be right in the name.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1025 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1026 (if pt (goto-char pt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1027 (let ((filename-chars "%.?@a-zA-Z0-9---()_/:~=&") start url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1028 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1029 ;; first see if you're just past a filename
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1030 (if (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1031 (if (looking-at "[] \t\n[{}()]") ; whitespace or some parens
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1032 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1033 (skip-chars-backward " \n\t\r({[]})")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1034 (if (not (bobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1035 (backward-char 1)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1036 (if (string-match (concat "[" filename-chars "]")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1037 (char-to-string (following-char)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1038 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1039 (skip-chars-backward filename-chars)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1040 (setq start (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1041 (skip-chars-forward filename-chars))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1042 (setq start (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1043 (setq url (if (fboundp 'buffer-substring-no-properties)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1044 (buffer-substring-no-properties start (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1045 (buffer-substring start (point)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1046 (if (string-match "^URL:" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1047 (setq url (substring url 4 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1048 (if (string-match "\\.$" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1049 (setq url (substring url 0 -1)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1050 (if (not (string-match url-nonrelative-link url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1051 (setq url nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1052 url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1053
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1054 (defun url-eat-trailing-space (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1055 ;; Remove spaces/tabs at the end of a string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1056 (let ((y (1- (length x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1057 (skip-chars (list ? ?\t ?\n)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1058 (while (and (>= y 0) (memq (aref x y) skip-chars))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1059 (setq y (1- y)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1060 (substring x 0 (1+ y))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1061
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1062 (defun url-strip-leading-spaces (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1063 ;; Remove spaces at the front of a string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1064 (let ((y (1- (length x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1065 (z 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1066 (skip-chars (list ? ?\t ?\n)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1067 (while (and (<= z y) (memq (aref x z) skip-chars))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1068 (setq z (1+ z)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1069 (substring x z nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1070
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1071 (defun url-convert-newlines-to-spaces (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1072 "Convert newlines and carriage returns embedded in a string into spaces,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1073 and swallow following whitespace.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1074 The argument is not side-effected, but may be returned by this function."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1075 (if (string-match "[\n\r]+\\s-*" x) ; [\\n\\r\\t ]
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1076 (concat (substring x 0 (match-beginning 0)) " "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1077 (url-convert-newlines-to-spaces
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1078 (substring x (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1079 x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1080
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1081 ;; Test cases
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1082 ;; (url-convert-newlines-to-spaces "foo bar") ; nothing happens
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1083 ;; (url-convert-newlines-to-spaces "foo\n \t bar") ; whitespace converted
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1084 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1085 ;; This implementation doesn't mangle the match-data, is fast, and doesn't
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1086 ;; create garbage, but it leaves whitespace.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1087 ;; (defun url-convert-newlines-to-spaces (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1088 ;; "Convert newlines and carriage returns embedded in a string into spaces.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1089 ;; The string is side-effected, then returned."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1090 ;; (let ((i 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1091 ;; (limit (length x)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1092 ;; (while (< i limit)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1093 ;; (if (or (= ?\n (aref x i))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1094 ;; (= ?\r (aref x i)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1095 ;; (aset x i ? ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1096 ;; (setq i (1+ i)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1097 ;; x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1098
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1099 (defun url-expand-file-name (url &optional default)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1100 "Convert URL to a fully specified URL, and canonicalize it.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1101 Second arg DEFAULT is a URL to start with if URL is relative.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1102 If DEFAULT is nil or missing, the current buffer's URL is used.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1103 Path components that are `.' are removed, and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1104 path components followed by `..' are removed, along with the `..' itself."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1105 (if url
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1106 (setq url (mapconcat (function (lambda (x)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1107 (if (memq x '(? ?\n ?\r))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1108 ""
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
1109 (char-to-string x))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1110 (url-strip-leading-spaces
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1111 (url-eat-trailing-space url)) "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1112 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1113 ((null url) nil) ; Something hosed! Be graceful
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1114 ((string-match "^#" url) ; Offset link, use it raw
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1115 url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1116 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1117 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1118 (inhibit-file-name-handlers t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1119 (defobj (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1120 ((vectorp default) default)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1121 (default (url-generic-parse-url default))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1122 (url-current-object url-current-object)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1123 (t (url-generic-parse-url (url-view-url t)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1124 (expander (cdr-safe
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1125 (cdr-safe
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1126 (assoc (or (url-type urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1127 (url-type defobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1128 url-registered-protocols)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1129 (if (string-match "^//" url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1130 (setq urlobj (url-generic-parse-url (concat (url-type defobj) ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1131 url))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1132 (if (fboundp expander)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1133 (funcall expander urlobj defobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1134 (message "Unknown URL scheme: %s" (or (url-type urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1135 (url-type defobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1136 (url-identity-expander urlobj defobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1137 (url-recreate-url urlobj)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1138
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1139 (defun url-default-expander (urlobj defobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1140 ;; The default expansion routine - urlobj is modified by side effect!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1141 (url-set-type urlobj (or (url-type urlobj) (url-type defobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1142 (url-set-port urlobj (or (url-port urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1143 (and (string= (url-type urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1144 (url-type defobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1145 (url-port defobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1146 (if (not (string= "file" (url-type urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1147 (url-set-host urlobj (or (url-host urlobj) (url-host defobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1148 (if (string= "ftp" (url-type urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1149 (url-set-user urlobj (or (url-user urlobj) (url-user defobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1150 (if (string= (url-filename urlobj) "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1151 (url-set-filename urlobj "/"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1152 (if (string-match "^/" (url-filename urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1153 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1154 (url-set-filename urlobj
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1155 (url-remove-relative-links
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1156 (concat (url-basepath (url-filename defobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1157 (url-filename urlobj))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1158
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1159 (defun url-identity-expander (urlobj defobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1160 (url-set-type urlobj (or (url-type urlobj) (url-type defobj))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1161
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1162 (defconst url-unreserved-chars
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1163 '(
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1164 ?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1165 ?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1166 ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1167 ?$ ?- ?_ ?. ?! ?~ ?* ?' ?\( ?\) ?,)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1168 "A list of characters that are _NOT_ reserve in the URL spec.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1169 This is taken from draft-fielding-url-syntax-02.txt - check your local
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1170 internet drafts directory for a copy.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1171
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1172 (defun url-hexify-string (str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1173 "Escape characters in a string"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1174 (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1175 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1176 (lambda (char)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1177 (if (not (memq char url-unreserved-chars))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1178 (if (< char 16)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1179 (upcase (format "%%0%x" char))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1180 (upcase (format "%%%x" char)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1181 (char-to-string char))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1182 (mule-decode-string str) ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1183
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1184 (defun url-make-sequence (start end)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1185 "Make a sequence (list) of numbers from START to END"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1186 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1187 ((= start end) '())
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1188 ((> start end) '())
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1189 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1190 (let ((sqnc '()))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1191 (while (<= start end)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1192 (setq sqnc (cons end sqnc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1193 end (1- end)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1194 sqnc))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1195
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1196 (defun url-file-extension (fname &optional x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1197 "Return the filename extension of FNAME. If optional variable X is t,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1198 then return the basename of the file with the extension stripped off."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1199 (if (and fname (string-match "\\.[^./]+$" fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1200 (if x (substring fname 0 (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1201 (substring fname (match-beginning 0) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1202 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1203 ;; If fname has no extension, and x then return fname itself instead of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1204 ;; nothing. When caching it allows the correct .hdr file to be produced
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1205 ;; for filenames without extension.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1206 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1207 (if x
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1208 fname
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1209 "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1210
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1211 (defun url-basepath (file &optional x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1212 "Return the base pathname of FILE, or the actual filename if X is true"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1213 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1214 ((null file) "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1215 (x (file-name-nondirectory file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1216 (t (file-name-directory file))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1217
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1218 (defun url-parse-query-string (query &optional downcase)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1219 (let (retval pairs cur key val)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1220 (setq pairs (split-string query "&"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1221 (while pairs
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1222 (setq cur (car pairs)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1223 pairs (cdr pairs))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1224 (if (not (string-match "=" cur))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1225 nil ; Grace
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1226 (setq key (url-unhex-string (substring cur 0 (match-beginning 0)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1227 val (url-unhex-string (substring cur (match-end 0) nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1228 (if downcase
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1229 (setq key (downcase key)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1230 (setq cur (assoc key retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1231 (if cur
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1232 (setcdr cur (cons val (cdr cur)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1233 (setq retval (cons (list key val) retval)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1234 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1235
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1236 (defun url-unhex (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1237 (if (> x ?9)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1238 (if (>= x ?a)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1239 (+ 10 (- x ?a))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1240 (+ 10 (- x ?A)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1241 (- x ?0)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1242
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1243 (defun url-unhex-string (str &optional allow-newlines)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1244 "Remove %XXX embedded spaces, etc in a url.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1245 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1246 decoding of carriage returns and line feeds in the string, which is normally
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1247 forbidden in URL encoding."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1248 (setq str (or str ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1249 (let ((tmp "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1250 (case-fold-search t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1251 (while (string-match "%[0-9a-f][0-9a-f]" str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1252 (let* ((start (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1253 (ch1 (url-unhex (elt str (+ start 1))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1254 (code (+ (* 16 ch1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1255 (url-unhex (elt str (+ start 2))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1256 (setq tmp (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1257 tmp (substring str 0 start)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1258 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1259 (allow-newlines
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1260 (char-to-string code))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1261 ((or (= code ?\n) (= code ?\r))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1262 " ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1263 (t (char-to-string code))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1264 str (substring str (match-end 0)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1265 (setq tmp (concat tmp str))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1266 tmp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1267
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1268 (defun url-clean-text ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1269 "Clean up a buffer, removing any excess garbage from a gateway mechanism,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1270 and decoding any MIME content-transfer-encoding used."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1271 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1272 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1273 (url-replace-regexp "Connection closed by.*" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1274 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1275 (url-replace-regexp "Process WWW.*" ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1276
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1277 (defun url-remove-compressed-extensions (filename)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1278 (while (assoc (url-file-extension filename) url-uncompressor-alist)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1279 (setq filename (url-file-extension filename t)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1280 filename)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1281
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1282 (defun url-uncompress ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1283 "Do any necessary uncompression on `url-working-buffer'"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1284 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1285 (if (not url-inhibit-uncompression)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1286 (let* ((decoder nil)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1287 (code-1 (cdr-safe
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1288 (assoc "content-transfer-encoding"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1289 url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1290 (code-2 (cdr-safe
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1291 (assoc "content-encoding" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1292 (done nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1293 (default-process-coding-system
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1294 (cons mule-no-coding-system mule-no-coding-system)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1295 (mapcar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1296 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1297 (lambda (code)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1298 (setq decoder (and (not (member code done))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1299 (cdr-safe
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1300 (assoc code mm-content-transfer-encodings)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1301 done (cons code done))
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1302 (if (not decoder)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1303 nil
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1304 (message "Decoding (%s)..." code)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1305 (cond
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1306 ((stringp decoder)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1307 (call-process-region (point-min) (point-max) decoder t t nil))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1308 ((listp decoder)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1309 (apply 'call-process-region (point-min) (point-max)
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1310 (car decoder) t t nil (cdr decoder)))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1311 ((and (symbolp decoder) (fboundp decoder))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1312 (funcall decoder (point-min) (point-max)))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1313 (t
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1314 (error "Bad entry for %s in `mm-content-transfer-encodings'"
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1315 code)))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1316 (message "Decoding (%s)... done." code))))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1317 (list code-1 code-2))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1318 (set-buffer-modified-p nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1319
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1320 (defun url-filter (proc string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1321 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1322 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1323 (insert string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1324 (if (string-match "\nConnection closed by" string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1325 (progn (set-process-filter proc nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1326 (url-sentinel proc string))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1327 string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1328
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1329 (defun url-default-callback (buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1330 (url-download-minor-mode nil)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1331 (url-store-in-cache)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1332 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1333 ((save-excursion (set-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1334 (and url-current-callback-func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1335 (fboundp url-current-callback-func)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1336 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1337 (save-window-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1338 (set-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1339 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1340 ((listp url-current-callback-data)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1341 (apply url-current-callback-func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1342 url-current-callback-data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1343 (url-current-callback-data
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1344 (funcall url-current-callback-func
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1345 url-current-callback-data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1346 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1347 (funcall url-current-callback-func))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1348 ((fboundp 'w3-sentinel)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1349 (set-variable 'w3-working-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1350 (w3-sentinel))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1351 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1352 (message "Retrieval for %s complete." buf))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1353
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1354 (defun url-sentinel (proc string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1355 (let* ((buf (process-buffer proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1356 (url-working-buffer (and buf (get-buffer buf)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1357 status)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1358 (if (not url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1359 (url-warn 'url (format "Process %s completed with no buffer!" proc))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1360 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1361 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1362 (remove-hook 'after-change-functions 'url-after-change-function)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1363 (if url-be-asynchronous
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1364 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1365 (widen)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1366 (url-clean-text)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1367 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1368 ((and (null proc) (not url-working-buffer)) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1369 ((url-mime-response-p)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1370 (setq status (url-parse-mime-headers))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1371 (if (not url-current-mime-type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1372 (setq url-current-mime-type (mm-extension-to-mime
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1373 (url-file-extension
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1374 (url-filename
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1375 url-current-object)))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1376 (if (member status '(401 301 302 303 204))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1377 nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1378 (funcall url-default-retrieval-proc (buffer-name url-working-buffer)))))))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1379
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1380 (defun url-remove-relative-links (name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1381 ;; Strip . and .. from pathnames
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1382 (let ((new (if (not (string-match "^/" name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1383 (concat "/" name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1384 name)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1385 (while (string-match "/\\(\\./\\)" new)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1386 (setq new (concat (substring new 0 (match-beginning 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1387 (substring new (match-end 1)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1388 (while (string-match "/\\([^/]*/\\.\\./\\)" new)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1389 (setq new (concat (substring new 0 (match-beginning 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1390 (substring new (match-end 1)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1391 (while (string-match "^/\\.\\.\\(/\\)" new)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1392 (setq new (substring new (match-beginning 1) nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1393 new))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1394
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1395 (defun url-truncate-url-for-viewing (url &optional width)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1396 "Return a shortened version of URL that is WIDTH characters or less wide.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1397 WIDTH defaults to the current frame width."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1398 (let* ((fr-width (or width (frame-width)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1399 (str-width (length url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1400 (tail (file-name-nondirectory url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1401 (fname nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1402 (modified 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1403 (urlobj nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1404 ;; The first thing that can go are the search strings
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1405 (if (and (>= str-width fr-width)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1406 (string-match "?" url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1407 (setq url (concat (substring url 0 (match-beginning 0)) "?...")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1408 str-width (length url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1409 tail (file-name-nondirectory url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1410 (if (< str-width fr-width)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1411 nil ; Hey, we are done!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1412 (setq urlobj (url-generic-parse-url url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1413 fname (url-filename urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1414 fr-width (- fr-width 4))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1415 (while (and (>= str-width fr-width)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1416 (string-match "/" fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1417 (setq fname (substring fname (match-end 0) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1418 modified (1+ modified))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1419 (url-set-filename urlobj fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1420 (setq url (url-recreate-url urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1421 str-width (length url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1422 (if (> modified 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1423 (setq fname (concat "/.../" fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1424 (setq fname (concat "/" fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1425 (url-set-filename urlobj fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1426 (setq url (url-recreate-url urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1427 url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1428
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1429 (defun url-view-url (&optional no-show)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1430 "View the current document's URL. Optional argument NO-SHOW means
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1431 just return the URL, don't show it in the minibuffer."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1432 (interactive)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1433 (if (not url-current-object)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1434 nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1435 (if no-show
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1436 (url-recreate-url url-current-object)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1437 (message "%s" (url-recreate-url url-current-object)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1438
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1439 (defun url-parse-Netscape-history (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1440 ;; Parse a Netscape/X style global history list.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1441 (let (pos ; Position holder
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1442 url ; The URL
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1443 time) ; Last time accessed
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1444 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1445 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1446 (skip-chars-forward "\n \t") ; Skip past the tag line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1447 (setq url-global-history-hash-table (make-hash-table :size 131
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1448 :test 'equal))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1449 ;; Here we will go to the end of the line and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1450 ;; skip back over a token, since we might run
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1451 ;; into spaces in URLs, depending on how much
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1452 ;; smarter netscape is than the old XMosaic :)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1453 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1454 (setq pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1455 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1456 (skip-chars-backward "^ \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1457 (skip-chars-backward " \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1458 (setq url (buffer-substring pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1459 pos (1+ (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1460 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1461 (setq time (buffer-substring pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1462 (skip-chars-forward "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1463 (setq url-history-changed-since-last-save t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1464 (cl-puthash url time url-global-history-hash-table))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1465
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1466 (defun url-parse-Mosaic-history-v1 (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1467 ;; Parse an NCSA Mosaic/X style global history list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1468 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1469 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1470 (skip-chars-forward "\n \t") ; Skip past the tag line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1471 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1472 (skip-chars-forward "\n \t") ; Skip past the second tag line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1473 (setq url-global-history-hash-table (make-hash-table :size 131
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1474 :test 'equal))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1475 (let (pos ; Temporary position holder
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1476 bol ; Beginning-of-line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1477 url ; URL
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1478 time ; Time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1479 last-end ; Last ending point
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1480 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1481 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1482 (setq bol (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1483 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1484 (setq pos (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1485 last-end (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1486 (skip-chars-backward "^ \t" bol) ; Skip over year
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1487 (skip-chars-backward " \t" bol)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1488 (skip-chars-backward "^ \t" bol) ; Skip over time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1489 (skip-chars-backward " \t" bol)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1490 (skip-chars-backward "^ \t" bol) ; Skip over day #
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1491 (skip-chars-backward " \t" bol)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1492 (skip-chars-backward "^ \t" bol) ; Skip over month
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1493 (skip-chars-backward " \t" bol)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1494 (skip-chars-backward "^ \t" bol) ; Skip over day abbrev.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1495 (if (bolp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1496 nil ; Malformed entry!!! Ack! Bailout!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1497 (setq time (buffer-substring pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1498 (skip-chars-backward " \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1499 (setq pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1500 (beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1501 (setq url (buffer-substring (point) pos))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1502 (goto-char (min (1+ last-end) (point-max))) ; Goto next line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1503 (if (/= (length url) 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1504 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1505 (setq url-history-changed-since-last-save t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1506 (cl-puthash url time url-global-history-hash-table))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1507
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1508 (defun url-parse-Mosaic-history-v2 (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1509 ;; Parse an NCSA Mosaic/X style global history list (version 2)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1510 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1511 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1512 (skip-chars-forward "\n \t") ; Skip past the tag line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1513 (skip-chars-forward "^\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1514 (skip-chars-forward "\n \t") ; Skip past the second tag line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1515 (setq url-global-history-hash-table (make-hash-table :size 131
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1516 :test 'equal))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1517 (let (pos ; Temporary position holder
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1518 bol ; Beginning-of-line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1519 url ; URL
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1520 time ; Time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1521 last-end ; Last ending point
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1522 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1523 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1524 (setq bol (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1525 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1526 (setq pos (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1527 last-end (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1528 (skip-chars-backward "^ \t" bol) ; Skip over time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1529 (if (bolp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1530 nil ; Malformed entry!!! Ack! Bailout!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1531 (setq time (buffer-substring pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1532 (skip-chars-backward " \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1533 (setq pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1534 (beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1535 (setq url (buffer-substring (point) pos))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1536 (goto-char (min (1+ last-end) (point-max))) ; Goto next line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1537 (if (/= (length url) 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1538 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1539 (setq url-history-changed-since-last-save t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1540 (cl-puthash url time url-global-history-hash-table))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1541
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1542 (defun url-parse-Emacs-history (&optional fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1543 ;; Parse out the Emacs-w3 global history file for completion, etc.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1544 (or fname (setq fname (expand-file-name url-global-history-file)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1545 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1546 ((not (file-exists-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1547 (message "%s does not exist." fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1548 ((not (file-readable-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1549 (message "%s is unreadable." fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1550 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1551 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1552 (load fname nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1553 (error (message "Could not load %s" fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1554 (if (boundp 'url-global-history-completion-list)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1555 ;; Hey! Automatic conversion of old format!
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1556 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1557 (setq url-global-history-hash-table (make-hash-table :size 131
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1558 :test 'equal)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1559 url-history-changed-since-last-save t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1560 (mapcar (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1561 (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1562 (cl-puthash (car x) (cdr x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1563 url-global-history-hash-table)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1564 (symbol-value 'url-global-history-completion-list)))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1565
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1566 (defun url-parse-global-history (&optional fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1567 ;; Parse out the mosaic global history file for completions, etc.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1568 (or fname (setq fname (expand-file-name url-global-history-file)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1569 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1570 ((not (file-exists-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1571 (message "%s does not exist." fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1572 ((not (file-readable-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1573 (message "%s is unreadable." fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1574 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1575 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1576 (set-buffer (get-buffer-create " *url-tmp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1577 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1578 (insert-file-contents-literally fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1579 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1580 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1581 ((looking-at "(setq") (url-parse-Emacs-history fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1582 ((looking-at "ncsa-mosaic-.*-1$") (url-parse-Mosaic-history-v1 fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1583 ((looking-at "ncsa-mosaic-.*-2$") (url-parse-Mosaic-history-v2 fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1584 ((or (looking-at "MCOM-") (looking-at "netscape"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1585 (url-parse-Netscape-history fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1586 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1587 (url-warn 'url (format "Cannot deduce type of history file: %s"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1588 fname))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1589
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1590 (defun url-write-Emacs-history (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1591 ;; Write an Emacs-w3 style global history list into FNAME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1592 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1593 (let ((count 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1594 (cl-maphash (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1595 (lambda (key value)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1596 (setq count (1+ count))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1597 (insert "(cl-puthash \"" key "\""
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1598 (if (not (stringp value)) " '" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1599 (prin1-to-string value)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1600 " url-global-history-hash-table)\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1601 url-global-history-hash-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1602 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1603 (insert (format
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1604 "(setq url-global-history-hash-table (make-hash-table :size %d :test 'equal))\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1605 (/ count 4)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1606 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1607 (insert "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1608 (write-file fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1609
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1610 (defun url-write-Netscape-history (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1611 ;; Write a Netscape-style global history list into FNAME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1612 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1613 (let ((last-valid-time "785305714")) ; Picked out of thin air,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1614 ; in case first in assoc list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1615 ; doesn't have a valid time
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1616 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1617 (insert "MCOM-Global-history-file-1\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1618 (cl-maphash (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1619 (lambda (url time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1620 (if (or (not (stringp time)) (string-match " \t" time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1621 (setq time last-valid-time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1622 (setq last-valid-time time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1623 (insert url " " time "\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1624 url-global-history-hash-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1625 (write-file fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1626
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1627 (defun url-write-Mosaic-history-v1 (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1628 ;; Write a Mosaic/X-style global history list into FNAME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1629 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1630 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1631 (insert "ncsa-mosaic-history-format-1\nGlobal\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1632 (cl-maphash (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1633 (lambda (url time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1634 (if (listp time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1635 (setq time (current-time-string time)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1636 (if (or (not (stringp time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1637 (not (string-match " " time)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1638 (setq time (current-time-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1639 (insert url " " time "\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1640 url-global-history-hash-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1641 (write-file fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1642
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1643 (defun url-write-Mosaic-history-v2 (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1644 ;; Write a Mosaic/X-style global history list into FNAME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1645 (let ((last-valid-time "827250806"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1646 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1647 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1648 (insert "ncsa-mosaic-history-format-2\nGlobal\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1649 (cl-maphash (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1650 (lambda (url time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1651 (if (listp time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1652 (setq time last-valid-time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1653 (setq last-valid-time time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1654 (if (not (stringp time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1655 (setq time last-valid-time))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1656 (insert url " " time "\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1657 url-global-history-hash-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1658 (write-file fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1659
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1660 (defun url-write-global-history (&optional fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1661 "Write the global history file into `url-global-history-file'.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1662 The type of data written is determined by what is in the file to begin
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1663 with. If the type of storage cannot be determined, then prompt the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1664 user for what type to save as."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1665 (interactive)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1666 (or fname (setq fname (expand-file-name url-global-history-file)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1667 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1668 ((not url-history-changed-since-last-save) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1669 ((not (file-writable-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1670 (message "%s is unwritable." fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1671 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1672 (let ((make-backup-files nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1673 (version-control nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1674 (require-final-newline t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1675 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1676 (set-buffer (get-buffer-create " *url-tmp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1677 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1678 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1679 (insert-file-contents-literally fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1680 (error nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1681 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1682 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1683 ((looking-at "ncsa-mosaic-.*-1$") (url-write-Mosaic-history-v1 fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1684 ((looking-at "ncsa-mosaic-.*-2$") (url-write-Mosaic-history-v2 fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1685 ((looking-at "MCOM-") (url-write-Netscape-history fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1686 ((looking-at "netscape") (url-write-Netscape-history fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1687 ((looking-at "(setq") (url-write-Emacs-history fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1688 (t (url-write-Emacs-history fname)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1689 (kill-buffer (current-buffer))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1690 (setq url-history-changed-since-last-save nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1691
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1692
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1694 ;;; The main URL fetching interface
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1695 ;;; -------------------------------
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1697
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1698 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1699 (defun url-popup-info (url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1700 "Retrieve the HTTP/1.0 headers and display them in a temp buffer."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1701 (let* ((urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1702 (type (url-type urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1703 data)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1704 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1705 ((string= type "http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1706 (let ((url-request-method "HEAD")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1707 (url-automatic-caching nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1708 (url-inhibit-mime-parsing t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1709 (url-working-buffer " *popup*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1710 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1711 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1712 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1713 (setq url-be-asynchronous nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1714 (url-retrieve url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1715 (subst-char-in-region (point-min) (point-max) ?\r ? )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1716 (buffer-string))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1717 ((or (string= type "file") (string= type "ftp"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1718 (setq data (url-file-attributes url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1719 (set-buffer (get-buffer-create
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1720 (url-generate-new-buffer-name "*Header Info*")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1721 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1722 (if data
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1723 (concat (if (stringp (nth 0 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1724 (concat " Linked to: " (nth 0 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1725 (concat " Directory: " (if (nth 0 data) "Yes" "No")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1726 "\n Links: " (int-to-string (nth 1 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1727 "\n File UID: " (int-to-string (nth 2 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1728 "\n File GID: " (int-to-string (nth 3 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1729 "\n Last Access: " (current-time-string (nth 4 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1730 "\nLast Modified: " (current-time-string (nth 5 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1731 "\n Last Changed: " (current-time-string (nth 6 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1732 "\n Size (bytes): " (int-to-string (nth 7 data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1733 "\n File Type: " (or (nth 8 data) "text/plain"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1734 (concat "No info found for " url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1735 ((and (string= type "news") (string-match "@" url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1736 (let ((art (url-filename urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1737 (if (not (string= (substring art -1 nil) ">"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1738 (setq art (concat "<" art ">")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1739 (url-get-headers-from-article-id art)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1740 (t (concat "Don't know how to find information on " url)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1741
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1742 (defun url-decode-text ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1743 ;; Decode text transmitted by NNTP.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1744 ;; 0. Delete status line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1745 ;; 1. Delete `^M' at end of line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1746 ;; 2. Delete `.' at end of buffer (end of text mark).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1747 ;; 3. Delete `.' at beginning of line."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1748 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1749 (set-buffer nntp-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1750 ;; Insert newline at end of buffer.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1751 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1752 (if (not (bolp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1753 (insert "\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1754 ;; Delete status line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1755 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1756 (delete-region (point) (progn (forward-line 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1757 ;; Delete `^M' at end of line.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1758 ;; (replace-regexp "\r$" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1759 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1760 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1761 (if (= (preceding-char) ?\r)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1762 (delete-char -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1763 (forward-line 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1764 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1765 ;; Delete `.' at end of buffer (end of text mark).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1766 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1767 (forward-line -1) ;(beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1768 (if (looking-at "^\\.$")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1769 (delete-region (point) (progn (forward-line 1) (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1770 ;; Replace `..' at beginning of line with `.'.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1771 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1772 ;; (replace-regexp "^\\.\\." ".")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1773 (while (search-forward "\n.." nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1774 (delete-char -1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1775 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1776
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1777 (defun url-get-headers-from-article-id (art)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1778 ;; Return the HEAD of ART (a usenet news article)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1779 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1780 ((string-match "flee" nntp-version)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1781 (nntp/command "HEAD" art)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1782 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1783 (set-buffer nntp-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1784 (while (progn (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1785 (not (re-search-forward "^.\r*$" nil t)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1786 (url-accept-process-output nntp/connection))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1787 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1788 (nntp-send-command "^\\.\r$" "HEAD" art)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1789 (url-decode-text)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1790 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1791 (set-buffer nntp-server-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1792 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1793
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1794 (defvar url-external-retrieval-program "www"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1795 "*Name of the external executable to run to retrieve URLs.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1796
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1797 (defvar url-external-retrieval-args '("-source")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1798 "*A list of arguments to pass to `url-external-retrieval-program' to
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1799 retrieve a URL by its HTML source.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1800
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1801 (defun url-retrieve-externally (url &optional no-cache)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1802 (let ((url-working-buffer (if (and url-multiple-p
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1803 (string-equal url-working-buffer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1804 url-default-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1805 (url-get-working-buffer-name)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1806 url-working-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1807 (if (get-buffer-create url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1808 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1809 (set-buffer url-working-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1810 (set-buffer-modified-p nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1811 (kill-buffer url-working-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1812 (set-buffer (get-buffer-create url-working-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1813 (let* ((args (append url-external-retrieval-args (list url)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1814 (urlobj (url-generic-parse-url url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1815 (type (url-type urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1816 (if (or (member type '("www" "about" "mailto" "mailserver"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1817 (url-file-directly-accessible-p urlobj))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1818 (url-retrieve-internally url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1819 (url-lazy-message "Retrieving %s..." url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1820 (apply 'call-process url-external-retrieval-program
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1821 nil t nil args)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1822 (url-lazy-message "Retrieving %s... done" url)))))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1823
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1824 (defun url-get-normalized-date (&optional specified-time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1825 ;; Return a 'real' date string that most HTTP servers can understand.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1826 (require 'timezone)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1827 (let* ((raw (if specified-time (current-time-string specified-time)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1828 (current-time-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1829 (gmt (timezone-make-date-arpa-standard raw
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1830 (nth 1 (current-time-zone))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1831 "GMT"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1832 (parsed (timezone-parse-date gmt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1833 (day (cdr-safe (assoc (substring raw 0 3) weekday-alist)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1834 (year nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1835 (month (car
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1836 (rassoc
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1837 (string-to-int (aref parsed 1)) monthabbrev-alist)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1838 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1839 (setq day (or (car-safe (rassoc day weekday-alist))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1840 (substring raw 0 3))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1841 year (aref parsed 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1842 ;; This is needed for plexus servers, or the server will hang trying to
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1843 ;; parse the if-modified-since header. Hopefully, I can take this out
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1844 ;; soon.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1845 (if (and year (> (length year) 2))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1846 (setq year (substring year -2 nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1847
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1848 (concat day ", " (aref parsed 2) "-" month "-" year " "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1849 (aref parsed 3) " " (or (aref parsed 4)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1850 (concat "[" (nth 1 (current-time-zone))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1851 "]")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1852
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1853 (defun url-get-working-buffer-name ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1854 "Get a working buffer name such as ` *URL-<i>*' without a live process and empty"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1855 (let ((num 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1856 name buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1857 (while (progn (setq name (format " *URL-%d*" num))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1858 (setq buf (get-buffer name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1859 (and buf (or (get-buffer-process buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1860 (save-excursion (set-buffer buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1861 (> (point-max) 1)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1862 (setq num (1+ num)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1863 name))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1864
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1865 (defun url-default-find-proxy-for-url (urlobj host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1866 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1867 ((or (and (assoc "no_proxy" url-proxy-services)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1868 (string-match
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1869 (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1870 (assoc "no_proxy" url-proxy-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1871 host))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1872 (equal "www" (url-type urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1873 "DIRECT")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1874 ((cdr (assoc (url-type urlobj) url-proxy-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1875 (concat "PROXY " (cdr (assoc (url-type urlobj) url-proxy-services))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1876 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1877 ;; Should check for socks
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1878 ;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1879 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1880 "DIRECT")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1881
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1882 (defvar url-proxy-locator 'url-default-find-proxy-for-url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1883
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1884 (defun url-find-proxy-for-url (url host)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1885 (let ((proxies (split-string (funcall url-proxy-locator url host) " *; *"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1886 (proxy nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1887 (case-fold-search t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1888 ;; Not sure how I should handle gracefully degrading from one proxy to
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1889 ;; another, so for now just deal with the first one
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1890 ;; (while proxies
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1891 (setq proxy (pop proxies))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1892 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1893 ((string-match "^direct" proxy) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1894 ((string-match "^proxy +" proxy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1895 (concat "http://" (substring proxy (match-end 0)) "/"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1896 ((string-match "^socks +" proxy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1897 (concat "socks://" (substring proxy (match-end 0))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1898 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1899 (url-warn 'url (format "Unknown proxy directive: %s" proxy) 'critical)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1900 nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1901
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1902 (defun url-retrieve-internally (url &optional no-cache)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1903 (let* ((url-working-buffer (if (and url-multiple-p
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1904 (string-equal
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1905 (if (bufferp url-working-buffer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1906 (buffer-name url-working-buffer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1907 url-working-buffer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1908 url-default-working-buffer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1909 (url-get-working-buffer-name)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1910 url-working-buffer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1911 (urlobj (url-generic-parse-url url))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1912 (type (url-type urlobj))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1913 (url-using-proxy (if (url-host urlobj)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1914 (url-find-proxy-for-url urlobj
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1915 (url-host urlobj))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1916 nil))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1917 (handler nil)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1918 (original-url url)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1919 (cached nil))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1920 (if url-using-proxy (setq type "proxy"))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1921 (setq cached (url-is-cached url)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1922 cached (and cached (not (url-cache-expired url cached)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1923 handler (if cached
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1924 'url-extract-from-cache
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1925 (car-safe
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1926 (cdr-safe (assoc (or type "auto")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1927 url-registered-protocols))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1928 url (if cached (url-create-cached-filename url) url))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1929 (save-excursion
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1930 (set-buffer (get-buffer-create url-working-buffer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1931 (setq url-current-can-be-cached (not no-cache)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1932 url-current-object urlobj))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1933 (if (and handler (fboundp handler))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1934 (funcall handler url)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1935 (set-buffer (get-buffer-create url-working-buffer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1936 (erase-buffer)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1937 (setq url-current-mime-type "text/html")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1938 (insert "<title> Link Error! </title>\n"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1939 "<h1> An error has occurred... </h1>\n"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1940 (format "The link type `<code>%s</code>'" type)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1941 " is unrecognized or unsupported at this time.<p>\n"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1942 "If you feel this is an error in Emacs-W3, please "
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1943 "<a href=\"mailto://" url-bug-address "\">send me mail.</a>"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1944 "<p><address>William Perry</address><br>"
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1945 "<address>" url-bug-address "</address>"))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1946 (cond
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1947 ((and url-be-asynchronous (not cached) (member type '("http" "proxy")))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1948 nil)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1949 (url-be-asynchronous
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1950 (funcall url-default-retrieval-proc (buffer-name)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1951 ((not (get-buffer url-working-buffer)) nil)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1952 ((and (not url-inhibit-mime-parsing)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1953 (or cached (url-mime-response-p t)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1954 (or cached (url-parse-mime-headers nil t))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1955 (if (and (or (not url-be-asynchronous)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1956 (not (equal type "http")))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1957 url-current-object
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1958 (not url-current-mime-type))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1959 (if (url-buffer-is-hypertext)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1960 (setq url-current-mime-type "text/html")
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1961 (setq url-current-mime-type (mm-extension-to-mime
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1962 (url-file-extension
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1963 (url-filename
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1964 url-current-object))))))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1965 (if (not url-be-asynchronous)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1966 (url-store-in-cache url-working-buffer))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1967 (if (not url-global-history-hash-table)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1968 (setq url-global-history-hash-table (make-hash-table :size 131
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1969 :test 'equal)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1970 (if (not (string-match "^\\(about\\|www\\):" original-url))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1971 (progn
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1972 (setq url-history-changed-since-last-save t)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1973 (cl-puthash original-url (current-time)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1974 url-global-history-hash-table)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
1975 (cons cached url-working-buffer)))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1976
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1977 ;;;###autoload
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1978 (defun url-retrieve (url &optional no-cache expected-md5)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1979 "Retrieve a document over the World Wide Web.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1980 The document should be specified by its fully specified
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1981 Uniform Resource Locator. No parsing is done, just return the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1982 document as the server sent it. The document is left in the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1983 buffer specified by url-working-buffer. url-working-buffer is killed
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1984 immediately before starting the transfer, so that no buffer-local
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1985 variables interfere with the retrieval. HTTP/1.0 redirection will
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1986 be honored before this function exits."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1987 (url-do-setup)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1988 (if (and (fboundp 'set-text-properties)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1989 (subrp (symbol-function 'set-text-properties)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1990 (set-text-properties 0 (length url) nil url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1991 (if (and url (string-match "^url:" url))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1992 (setq url (substring url (match-end 0) nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1993 (let ((status (url-retrieve-internally url no-cache)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1994 status))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1995
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1996 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1997 ;;; How to register a protocol
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1999 (defun url-register-protocol (protocol &optional retrieve expander defport)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2000 "Register a protocol with the URL retrieval package.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2001 PROTOCOL is the type of protocol being registers (http, nntp, etc),
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2002 and is the first chunk of the URL. ie: http:// URLs will be
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2003 handled by the protocol registered as 'http'. PROTOCOL can
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2004 be either a symbol or a string - it is converted to a string,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2005 and lowercased before being registered.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2006 RETRIEVE (optional) is the function to be called with a url as its
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2007 only argument. If this argument is omitted, then this looks
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2008 for a function called 'url-PROTOCOL'. A warning is shown if
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2009 the function is undefined, but the protocol is still
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2010 registered.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2011 EXPANDER (optional) is the function to call to expand a relative link
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2012 of type PROTOCOL. If omitted, this defaults to
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2013 `url-default-expander'
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2014
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2015 Any proxy information is read in from environment variables at this
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2016 time, so this function should only be called after dumping emacs."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2017 (let* ((protocol (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2018 ((stringp protocol) (downcase protocol))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2019 ((symbolp protocol) (downcase (symbol-name protocol)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2020 (t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2021
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2022 (retrieve (or retrieve (intern (concat "url-" protocol))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2023 (expander (or expander 'url-default-expander))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2024 (cur-protocol (assoc protocol url-registered-protocols))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2025 (urlobj nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2026 (cur-proxy (assoc protocol url-proxy-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2027 (env-proxy (or (getenv (concat protocol "_proxy"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2028 (getenv (concat protocol "_PROXY"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2029 (getenv (upcase (concat protocol "_PROXY"))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2030
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2031 (if (not protocol)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2032 (error "Invalid data to url-register-protocol."))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2033
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2034 (if (not (fboundp retrieve))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2035 (message "Warning: %s registered, but no function found." protocol))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2036
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2037 ;; Store the default port, if none previously specified and
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2038 ;; defport given
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2039 (if (and defport (not (assoc protocol url-default-ports)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2040 (setq url-default-ports (cons (cons protocol defport)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2041 url-default-ports)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2042
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2043 ;; Store the appropriate information for later
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2044 (if cur-protocol
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2045 (setcdr cur-protocol (cons retrieve expander))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2046 (setq url-registered-protocols (cons (cons protocol
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2047 (cons retrieve expander))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2048 url-registered-protocols)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2049
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2050 ;; Store any proxying information - this will not overwrite an old
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2051 ;; entry, so that people can still set this information in their
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2052 ;; .emacs file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2053 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2054 (cur-proxy nil) ; Keep their old settings
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2055 ((null env-proxy) nil) ; No proxy setup
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2056 ;; First check if its something like hostname:port
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2057 ((string-match "^\\([^:]+\\):\\([0-9]+\\)$" env-proxy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2058 (setq urlobj (url-generic-parse-url nil)) ; Get a blank object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2059 (url-set-type urlobj "http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2060 (url-set-host urlobj (url-match env-proxy 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2061 (url-set-port urlobj (url-match env-proxy 2)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2062 ;; Then check if its a fully specified URL
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2063 ((string-match url-nonrelative-link env-proxy)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2064 (setq urlobj (url-generic-parse-url env-proxy))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2065 (url-set-type urlobj "http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2066 (url-set-target urlobj nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2067 ;; Finally, fall back on the assumption that its just a hostname
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2068 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2069 (setq urlobj (url-generic-parse-url nil)) ; Get a blank object
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2070 (url-set-type urlobj "http")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2071 (url-set-host urlobj env-proxy)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2072
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2073 (if (and (not cur-proxy) urlobj)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2074 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2075 (setq url-proxy-services
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2076 (cons (cons protocol (concat (url-host urlobj) ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2077 (url-port urlobj)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2078 url-proxy-services))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2079 (message "Using a proxy for %s..." protocol)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2080
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2081 (provide 'url)