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