annotate lisp/w3/url.el @ 14:9ee227acff29 r19-15b90

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