Merge from emacs-23; up to 2010-06-12T17:12:15Z!cyd@stupidchicken.com.
[bpt/emacs.git] / lisp / url / url-vars.el
1 ;;; url-vars.el --- Variables for Uniform Resource Locator tool
2
3 ;; Copyright (C) 1996-1999, 2001, 2004-2011 Free Software Foundation, Inc.
4
5 ;; Keywords: comm, data, processes, hypermedia
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Code:
23
24 (require 'mm-util)
25
26 (defconst url-version "Emacs"
27 "Version number of URL package.")
28
29 (defgroup url nil
30 "Uniform Resource Locator tool."
31 :version "22.1"
32 :group 'comm)
33
34 (defgroup url-file nil
35 "URL storage."
36 :prefix "url-"
37 :group 'url)
38
39 (defgroup url-cache nil
40 "URL cache."
41 :prefix "url-"
42 :prefix "url-cache-"
43 :group 'url)
44
45 (defgroup url-mime nil
46 "MIME options of URL."
47 :prefix "url-"
48 :group 'url)
49
50 (defgroup url-hairy nil
51 "Hairy options of URL."
52 :prefix "url-"
53 :group 'url)
54
55
56 (defvar url-current-object nil
57 "A parsed representation of the current URL.")
58
59 (defvar url-current-mime-headers nil
60 "A parsed representation of the MIME headers for the current URL.")
61
62 (mapc 'make-variable-buffer-local
63 '(
64 url-current-object
65 url-current-referer
66 url-current-mime-headers
67 ))
68
69 (defcustom url-honor-refresh-requests t
70 "Whether to do automatic page reloads.
71 These are done at the request of the document author or the server via
72 the `Refresh' header in an HTTP response. If nil, no refresh
73 requests will be honored. If t, all refresh requests will be honored.
74 If non-nil and not t, the user will be asked for each refresh request."
75 :type '(choice (const :tag "off" nil)
76 (const :tag "on" t)
77 (const :tag "ask" 'ask))
78 :group 'url-hairy)
79
80 (defcustom url-automatic-caching nil
81 "If non-nil, all documents will be automatically cached to the local disk."
82 :type 'boolean
83 :group 'url-cache)
84
85 (defconst url-bug-address "bug-gnu-emacs@gnu.org"
86 "Where to send bug reports.")
87
88 (defcustom url-personal-mail-address nil
89 "Your full email address.
90 This is what is sent to HTTP servers as the FROM field in an HTTP
91 request."
92 :type '(choice (const :tag "Unspecified" nil) string)
93 :group 'url)
94
95 (defcustom url-directory-index-file "index.html"
96 "The filename to look for when indexing a directory.
97 If this file exists, and is readable, then it will be viewed instead of
98 using `dired' to view the directory."
99 :type 'string
100 :group 'url-file)
101
102 (defcustom url-privacy-level '(email)
103 "How private you want your requests to be.
104 HTTP has header fields for various information about the user, including
105 operating system information, email addresses, the last page you visited, etc.
106 This variable controls how much of this information is sent.
107
108 This should a symbol or a list.
109 Valid values if a symbol are:
110 none -- send all information
111 low -- don't send the last location
112 high -- don't send the email address or last location
113 paranoid -- don't send anything
114
115 If a list, this should be a list of symbols of what NOT to send.
116 Valid symbols are:
117 email -- the email address
118 os -- the operating system info
119 lastloc -- the last location
120 agent -- do not send the User-Agent string
121 cookies -- never accept HTTP cookies
122
123 Samples:
124
125 (setq url-privacy-level 'high)
126 (setq url-privacy-level '(email lastloc)) ;; equivalent to 'high
127 (setq url-privacy-level '(os))
128
129 ::NOTE::
130 This variable controls several other variables and is _NOT_ automatically
131 updated. Call the function `url-setup-privacy-info' after modifying this
132 variable."
133 :initialize 'custom-initialize-default
134 :set (lambda (sym val) (set-default sym val) (url-setup-privacy-info))
135 :type '(radio (const :tag "None (you believe in the basic goodness of humanity)"
136 :value none)
137 (const :tag "Low (do not reveal last location)"
138 :value low)
139 (const :tag "High (no email address or last location)"
140 :value high)
141 (const :tag "Paranoid (reveal nothing!)"
142 :value paranoid)
143 (checklist :tag "Custom"
144 (const :tag "Email address" :value email)
145 (const :tag "Operating system" :value os)
146 (const :tag "Last location" :value lastloc)
147 (const :tag "Browser identification" :value agent)
148 (const :tag "No cookies" :value cookie)))
149 :group 'url)
150
151 (defvar url-inhibit-uncompression nil "Do not do decompression if non-nil.")
152
153 (defcustom url-uncompressor-alist '((".z" . "x-gzip")
154 (".gz" . "x-gzip")
155 (".uue" . "x-uuencoded")
156 (".hqx" . "x-hqx")
157 (".Z" . "x-compress")
158 (".bz2" . "x-bzip2"))
159 "An alist of file extensions and appropriate content-transfer-encodings."
160 :type '(repeat (cons :format "%v"
161 (string :tag "Extension")
162 (string :tag "Encoding")))
163 :group 'url-mime)
164
165 (defcustom url-mail-command 'compose-mail
166 "This function will be called whenever URL needs to send mail.
167 It should enter a mail-mode-like buffer in the current window.
168 The commands `mail-to' and `mail-subject' should still work in this
169 buffer, and it should use `mail-header-separator' if possible."
170 :type 'function
171 :group 'url)
172
173 (defcustom url-proxy-services nil
174 "An alist of schemes and proxy servers that gateway them.
175 Looks like ((\"http\" . \"hostname:portnumber\") ...). This is set up
176 from the ACCESS_proxy environment variables."
177 :type '(repeat (cons :format "%v"
178 (string :tag "Protocol")
179 (string :tag "Proxy")))
180 :group 'url)
181
182 (defcustom url-standalone-mode nil
183 "Rely solely on the cache?"
184 :type 'boolean
185 :group 'url-cache)
186
187 (defvar url-mime-separator-chars (mapcar 'identity
188 (concat "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
189 "abcdefghijklmnopqrstuvwxyz"
190 "0123456789'()+_,-./=?"))
191 "Characters allowable in a MIME multipart separator.")
192
193 (defcustom url-bad-port-list
194 '("25" "119" "19")
195 "List of ports to warn the user about connecting to.
196 Defaults to just the mail, chargen, and NNTP ports so you cannot be
197 tricked into sending fake mail or forging messages by a malicious HTML
198 document."
199 :type '(repeat (string :tag "Port"))
200 :group 'url-hairy)
201
202 (defvar url-mime-content-type-charset-regexp
203 ";[ \t]*charset=\"?\\([^\"]+\\)\"?"
204 "Regexp used in parsing `Content-Type' for a charset indication.")
205
206 (defvar url-request-data nil "Any data to send with the next request.")
207
208 (defvar url-request-extra-headers nil
209 "A list of extra headers to send with the next request.
210 Should be an assoc list of headers/contents.")
211
212 (defvar url-request-method nil "The method to use for the next request.")
213
214 ;; FIXME!! (RFC 2616 gives examples like `compress, gzip'.)
215 (defvar url-mime-encoding-string nil
216 "*String to send in the Accept-encoding: field in HTTP requests.")
217
218 ;; Perhaps the first few should actually be given decreasing `q's and
219 ;; the list should be trimmed significantly.
220 ;; Fixme: do something sane if we don't have `sort-coding-systems'
221 ;; (Emacs 20, XEmacs).
222 (defun url-mime-charset-string ()
223 "Generate a list of preferred MIME charsets for HTTP requests.
224 Generated according to current coding system priorities."
225 (if (fboundp 'sort-coding-systems)
226 (let ((ordered (sort-coding-systems
227 (let (accum)
228 (dolist (elt mm-mime-mule-charset-alist)
229 (if (mm-coding-system-p (car elt))
230 (push (car elt) accum)))
231 (nreverse accum)))))
232 (concat (format "%s;q=1, " (pop ordered))
233 (mapconcat 'symbol-name ordered ";q=0.5, ")
234 ";q=0.5"))))
235
236 (defvar url-mime-charset-string nil
237 "*String to send in the Accept-charset: field in HTTP requests.
238 The MIME charset corresponding to the most preferred coding system is
239 given priority 1 and the rest are given priority 0.5.")
240
241 (defun url-set-mime-charset-string ()
242 (setq url-mime-charset-string (url-mime-charset-string)))
243 ;; Regenerate if the language environment changes.
244 (add-hook 'set-language-environment-hook 'url-set-mime-charset-string)
245
246 ;; Fixme: set from the locale.
247 (defcustom url-mime-language-string nil
248 "String to send in the Accept-language: field in HTTP requests.
249
250 Specifies the preferred language when servers can serve documents in
251 several languages. Use RFC 1766 abbreviations, e.g.: `en' for
252 English, `de' for German. A comma-separated specifies descending
253 order of preference. The ordering can be made explicit using `q'
254 factors defined by HTTP, e.g. `de,en-gb;q=0.8,en;q=0.7'. `*' means
255 get the first available language (as opposed to the default)."
256 :type '(radio
257 (const :tag "None (get default language version)" :value nil)
258 (const :tag "Any (get first available language version)" :value "*")
259 (string :tag "Other"))
260 :group 'url-mime
261 :group 'i18n)
262
263 (defvar url-mime-accept-string nil
264 "String to send to the server in the Accept: field in HTTP requests.")
265
266 (defvar url-package-version nil
267 "Version number of package using URL.")
268
269 (defvar url-package-name nil "Name of package using URL.")
270
271 (defvar url-system-type nil
272 "What type of system we are on.")
273 (defvar url-os-type nil
274 "What OS we are on.")
275
276 (defcustom url-max-password-attempts 5
277 "Maximum number of times a password will be prompted for.
278 Applies when a protected document is denied by the server."
279 :type 'integer
280 :group 'url)
281
282 (defcustom url-temporary-directory (or (getenv "TMPDIR") "/tmp")
283 "Where temporary files go."
284 :type 'directory
285 :group 'url-file)
286 (make-obsolete-variable 'url-temporary-directory
287 'temporary-file-directory "23.1")
288
289 (defcustom url-show-status t
290 "Whether to show a running total of bytes transferred.
291 Can cause a large hit if using a remote X display over a slow link, or
292 a terminal with a slow modem."
293 :type 'boolean
294 :group 'url)
295
296 (defvar url-using-proxy nil
297 "Either nil or the fully qualified proxy URL in use, e.g.
298 http://www.example.com/")
299
300 (defcustom url-news-server nil
301 "The default news server from which to get newsgroups/articles.
302 Applies if no server is specified in the URL. Defaults to the
303 environment variable NNTPSERVER or \"news\" if NNTPSERVER is
304 undefined."
305 :type '(choice (const :tag "None" :value nil) string)
306 :group 'url)
307
308 (defvar url-nonrelative-link
309 "\\`\\([-a-zA-Z0-9+.]+:\\)"
310 "A regular expression that will match an absolute URL.")
311
312 (defcustom url-max-redirections 30
313 "The maximum number of redirection requests to honor in a HTTP connection.
314 A negative number means to honor an unlimited number of redirection requests."
315 :type 'integer
316 :group 'url)
317
318 (defcustom url-confirmation-func 'y-or-n-p
319 "What function to use for asking yes or no functions.
320 Possible values are `yes-or-no-p' or `y-or-n-p', or any function that
321 takes a single argument (the prompt), and returns t only if a positive
322 answer is given."
323 :type '(choice (const :tag "Short (y or n)" :value y-or-n-p)
324 (const :tag "Long (yes or no)" :value yes-or-no-p)
325 (function :tag "Other"))
326 :group 'url-hairy)
327
328 (defcustom url-gateway-method 'native
329 "The type of gateway support to use.
330 Should be a symbol specifying how to get a connection from the local machine.
331
332 Currently supported methods:
333 `telnet': Run telnet in a subprocess to connect;
334 `rlogin': Rlogin to another machine to connect;
335 `socks': Connect through a socks server;
336 `tls': Connect with TLS;
337 `ssl': Connect with SSL (deprecated, use `tls' instead);
338 `native': Connect directy."
339 :type '(radio (const :tag "Telnet to gateway host" :value telnet)
340 (const :tag "Rlogin to gateway host" :value rlogin)
341 (const :tag "Use SOCKS proxy" :value socks)
342 (const :tag "Use SSL/TLS for all connections" :value tls)
343 (const :tag "Use SSL for all connections (obsolete)" :value ssl)
344 (const :tag "Direct connection" :value native))
345 :group 'url-hairy)
346
347 (defvar url-setup-done nil "Has setup configuration been done?")
348
349 (defconst url-weekday-alist
350 '(("Sunday" . 0) ("Monday" . 1) ("Tuesday" . 2) ("Wednesday" . 3)
351 ("Thursday" . 4) ("Friday" . 5) ("Saturday" . 6)
352 ("Tues" . 2) ("Thurs" . 4)
353 ("Sun" . 0) ("Mon" . 1) ("Tue" . 2) ("Wed" . 3)
354 ("Thu" . 4) ("Fri" . 5) ("Sat" . 6)))
355
356 (defconst url-monthabbrev-alist
357 '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3) ("Apr" . 4) ("May" . 5) ("Jun" . 6)
358 ("Jul" . 7) ("Aug" . 8) ("Sep" . 9) ("Oct" . 10) ("Nov" . 11)
359 ("Dec" . 12)))
360
361 (defvar url-lazy-message-time 0)
362
363 ;; Fixme: We may not be able to run SSL.
364 (defvar url-extensions-header "Security/Digest Security/SSL")
365
366 (defvar url-parse-syntax-table
367 (copy-syntax-table emacs-lisp-mode-syntax-table)
368 "*A syntax table for parsing URLs.")
369
370 (modify-syntax-entry ?' "\"" url-parse-syntax-table)
371 (modify-syntax-entry ?` "\"" url-parse-syntax-table)
372 (modify-syntax-entry ?< "(>" url-parse-syntax-table)
373 (modify-syntax-entry ?> ")<" url-parse-syntax-table)
374 (modify-syntax-entry ?/ " " url-parse-syntax-table)
375
376 (defvar url-load-hook nil
377 "*Hooks to be run after initializing the URL library.")
378
379 ;;; Make OS/2 happy - yeeks
380 ;; (defvar tcp-binary-process-input-services nil
381 ;; "*Make OS/2 happy with our CRLF pairs...")
382
383 (defconst url-working-buffer " *url-work")
384
385 (defvar url-gateway-unplugged nil
386 "Non-nil means don't open new network connections.
387 This should be set, e.g. by mail user agents rendering HTML to avoid
388 `bugs' which call home.")
389
390 (provide 'url-vars)
391
392 ;;; url-vars.el ends here