annotate lisp/url/url.el @ 7:c153ca296910

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