annotate lisp/url/url.el @ 0:376386a54a3c r19-14

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