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