Mercurial > emacs
annotate lisp/url/url-gw.el @ 95613:7e79847f2451
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 07 Jun 2008 02:34:01 +0000 |
parents | 8259d0d8e107 |
children | a99299e4d2de |
rev | line source |
---|---|
54695 | 1 ;;; url-gw.el --- Gateway munging for URL loading |
57612 | 2 |
79720 | 3 ;; Copyright (C) 1997, 1998, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
57612 | 4 |
54695 | 5 ;; Author: Bill Perry <wmperry@gnu.org> |
6 ;; Keywords: comm, data, processes | |
7 | |
57612 | 8 ;; This file is part of GNU Emacs. |
9 | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79720
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
57612 | 11 ;; it under the terms of the GNU General Public License as published by |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79720
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79720
diff
changeset
|
13 ;; (at your option) any later version. |
57612 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94668
8259d0d8e107
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79720
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
57612 | 22 |
23 ;;; Code: | |
24 | |
54695 | 25 (eval-when-compile (require 'cl)) |
26 (require 'url-vars) | |
27 | |
28 ;; Fixme: support SSH explicitly or via a url-gateway-rlogin-program? | |
29 | |
30 (autoload 'socks-open-network-stream "socks") | |
31 (autoload 'open-ssl-stream "ssl") | |
57449
202c408c174b
url-vars.el (url-gateway-method): Add new method `tls'.
Simon Josefsson <jas@extundo.com>
parents:
54770
diff
changeset
|
32 (autoload 'open-tls-stream "tls") |
54695 | 33 |
34 (defgroup url-gateway nil | |
63987
56d2561b1c9f
(url-gateway): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63618
diff
changeset
|
35 "URL gateway variables." |
54695 | 36 :group 'url) |
37 | |
38 (defcustom url-gateway-local-host-regexp nil | |
39 "*A regular expression specifying local hostnames/machines." | |
40 :type '(choice (const nil) regexp) | |
41 :group 'url-gateway) | |
42 | |
43 (defcustom url-gateway-prompt-pattern | |
44 "^[^#$%>;]*[#$%>;] *" ;; "bash\\|\$ *\r?$\\|> *\r?" | |
45 "*A regular expression matching a shell prompt." | |
46 :type 'regexp | |
47 :group 'url-gateway) | |
48 | |
49 (defcustom url-gateway-rlogin-host nil | |
50 "*What hostname to actually rlog into before doing a telnet." | |
51 :type '(choice (const nil) string) | |
52 :group 'url-gateway) | |
53 | |
54 (defcustom url-gateway-rlogin-user-name nil | |
55 "*Username to log into the remote machine with when using rlogin." | |
56 :type '(choice (const nil) string) | |
57 :group 'url-gateway) | |
58 | |
59 (defcustom url-gateway-rlogin-parameters '("telnet" "-8") | |
60 "*Parameters to `url-open-rlogin'. | |
61 This list will be used as the parameter list given to rsh." | |
62 :type '(repeat string) | |
63 :group 'url-gateway) | |
64 | |
65 (defcustom url-gateway-telnet-host nil | |
66 "*What hostname to actually login to before doing a telnet." | |
67 :type '(choice (const nil) string) | |
68 :group 'url-gateway) | |
69 | |
70 (defcustom url-gateway-telnet-parameters '("exec" "telnet" "-8") | |
71 "*Parameters to `url-open-telnet'. | |
72 This list will be executed as a command after logging in via telnet." | |
73 :type '(repeat string) | |
74 :group 'url-gateway) | |
75 | |
76 (defcustom url-gateway-telnet-login-prompt "^\r*.?login:" | |
77 "*Prompt that tells us we should send our username when loggin in w/telnet." | |
78 :type 'regexp | |
79 :group 'url-gateway) | |
80 | |
81 (defcustom url-gateway-telnet-password-prompt "^\r*.?password:" | |
82 "*Prompt that tells us we should send our password when loggin in w/telnet." | |
83 :type 'regexp | |
84 :group 'url-gateway) | |
85 | |
86 (defcustom url-gateway-telnet-user-name nil | |
87 "User name to log in via telnet with." | |
88 :type '(choice (const nil) string) | |
89 :group 'url-gateway) | |
90 | |
91 (defcustom url-gateway-telnet-password nil | |
92 "Password to use to log in via telnet with." | |
93 :type '(choice (const nil) string) | |
94 :group 'url-gateway) | |
95 | |
96 (defcustom url-gateway-broken-resolution nil | |
97 "*Whether to use nslookup to resolve hostnames. | |
98 This should be used when your version of Emacs cannot correctly use DNS, | |
99 but your machine can. This usually happens if you are running a statically | |
100 linked Emacs under SunOS 4.x" | |
101 :type 'boolean | |
102 :group 'url-gateway) | |
103 | |
104 (defcustom url-gateway-nslookup-program "nslookup" | |
74575
34a1ff09106b
(url-gateway-nslookup-program): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
73533
diff
changeset
|
105 "*If non-nil then a string naming nslookup program." |
54695 | 106 :type '(choice (const :tag "None" :value nil) string) |
107 :group 'url-gateway) | |
108 | |
109 ;; Stolen from ange-ftp | |
110 ;;;###autoload | |
111 (defun url-gateway-nslookup-host (host) | |
112 "Attempt to resolve the given HOST using nslookup if possible." | |
113 (interactive "sHost: ") | |
114 (if url-gateway-nslookup-program | |
115 (let ((proc (start-process " *nslookup*" " *nslookup*" | |
116 url-gateway-nslookup-program host)) | |
117 (res host)) | |
57620
462b0b8865f7
(url-gateway-nslookup-host): Use `set-process-query-on-exit-flag'.
John Paul Wallington <jpw@pobox.com>
parents:
57612
diff
changeset
|
118 (set-process-query-on-exit-flag proc nil) |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
119 (with-current-buffer (process-buffer proc) |
54695 | 120 (while (memq (process-status proc) '(run open)) |
121 (accept-process-output proc)) | |
122 (goto-char (point-min)) | |
123 (if (re-search-forward "Name:.*\nAddress: *\\(.*\\)$" nil t) | |
124 (setq res (buffer-substring (match-beginning 1) | |
125 (match-end 1)))) | |
126 (kill-buffer (current-buffer))) | |
127 res) | |
128 host)) | |
129 | |
130 ;; Stolen from red gnus nntp.el | |
131 (defun url-wait-for-string (regexp proc) | |
132 "Wait until string matching REGEXP arrives in process PROC's buffer." | |
133 (let ((buf (current-buffer))) | |
134 (goto-char (point-min)) | |
135 (while (not (re-search-forward regexp nil t)) | |
136 (accept-process-output proc) | |
137 (set-buffer buf) | |
138 (goto-char (point-min))))) | |
139 | |
140 ;; Stolen from red gnus nntp.el | |
141 (defun url-open-rlogin (name buffer host service) | |
142 "Open a connection using rsh." | |
143 (if (not (stringp service)) | |
144 (setq service (int-to-string service))) | |
145 (let ((proc (if url-gateway-rlogin-user-name | |
146 (start-process | |
147 name buffer "rsh" | |
148 url-gateway-rlogin-host "-l" url-gateway-rlogin-user-name | |
149 (mapconcat 'identity | |
150 (append url-gateway-rlogin-parameters | |
151 (list host service)) " ")) | |
152 (start-process | |
153 name buffer "rsh" url-gateway-rlogin-host | |
154 (mapconcat 'identity | |
155 (append url-gateway-rlogin-parameters | |
156 (list host service)) | |
157 " "))))) | |
158 (set-buffer buffer) | |
159 (url-wait-for-string "^\r*200" proc) | |
160 (beginning-of-line) | |
161 (delete-region (point-min) (point)) | |
162 proc)) | |
163 | |
164 ;; Stolen from red gnus nntp.el | |
165 (defun url-open-telnet (name buffer host service) | |
166 (if (not (stringp service)) | |
167 (setq service (int-to-string service))) | |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
168 (with-current-buffer (get-buffer-create buffer) |
54695 | 169 (erase-buffer) |
170 (let ((proc (start-process name buffer "telnet" "-8")) | |
171 (case-fold-search t)) | |
172 (when (memq (process-status proc) '(open run)) | |
173 (process-send-string proc "set escape \^X\n") | |
174 (process-send-string proc (concat | |
175 "open " url-gateway-telnet-host "\n")) | |
176 (url-wait-for-string url-gateway-telnet-login-prompt proc) | |
177 (process-send-string | |
178 proc (concat | |
179 (or url-gateway-telnet-user-name | |
180 (setq url-gateway-telnet-user-name (read-string "login: "))) | |
181 "\n")) | |
182 (url-wait-for-string url-gateway-telnet-password-prompt proc) | |
183 (process-send-string | |
184 proc (concat | |
185 (or url-gateway-telnet-password | |
186 (setq url-gateway-telnet-password | |
57510
9f80571c6c3e
(url-open-telnet): Use read-passwd.
Richard M. Stallman <rms@gnu.org>
parents:
57449
diff
changeset
|
187 (read-passwd "Password: "))) |
54695 | 188 "\n")) |
189 (erase-buffer) | |
190 (url-wait-for-string url-gateway-prompt-pattern proc) | |
191 (process-send-string | |
192 proc (concat (mapconcat 'identity | |
193 (append url-gateway-telnet-parameters | |
194 (list host service)) " ") "\n")) | |
195 (url-wait-for-string "^\r*Escape character.*\r*\n+" proc) | |
196 (delete-region (point-min) (match-end 0)) | |
197 (process-send-string proc "\^]\n") | |
198 (url-wait-for-string "^telnet" proc) | |
199 (process-send-string proc "mode character\n") | |
200 (accept-process-output proc 1) | |
201 (sit-for 1) | |
202 (goto-char (point-min)) | |
203 (forward-line 1) | |
204 (delete-region (point) (point-max))) | |
205 proc))) | |
206 | |
207 ;;;###autoload | |
208 (defun url-open-stream (name buffer host service) | |
209 "Open a stream to HOST, possibly via a gateway. | |
210 Args per `open-network-stream'. | |
73501
437fb645afb4
* url-http.el (url-http-mark-connection-as-free): Verify that
Chong Yidong <cyd@stupidchicken.com>
parents:
70241
diff
changeset
|
211 Will not make a connection if `url-gateway-unplugged' is non-nil. |
437fb645afb4
* url-http.el (url-http-mark-connection-as-free): Verify that
Chong Yidong <cyd@stupidchicken.com>
parents:
70241
diff
changeset
|
212 Might do a non-blocking connection; use `process-status' to check." |
54695 | 213 (unless url-gateway-unplugged |
214 (let ((gw-method (if (and url-gateway-local-host-regexp | |
57449
202c408c174b
url-vars.el (url-gateway-method): Add new method `tls'.
Simon Josefsson <jas@extundo.com>
parents:
54770
diff
changeset
|
215 (not (eq 'tls url-gateway-method)) |
54695 | 216 (not (eq 'ssl url-gateway-method)) |
217 (string-match | |
218 url-gateway-local-host-regexp | |
219 host)) | |
220 'native | |
221 url-gateway-method)) | |
222 ;;; ;; This hack is for OS/2 Emacs so that it will not do bogus CRLF | |
223 ;;; ;; conversions while trying to be 'helpful' | |
224 ;;; (tcp-binary-process-output-services (if (stringp service) | |
225 ;;; (list service) | |
226 ;;; (list service | |
227 ;;; (int-to-string service)))) | |
228 | |
229 ;; An attempt to deal with denied connections, and attempt | |
230 ;; to reconnect | |
231 (cur-retries 0) | |
232 (retry t) | |
233 (errobj nil) | |
234 (conn nil)) | |
235 | |
236 ;; If the user told us to do DNS for them, do it. | |
237 (if url-gateway-broken-resolution | |
238 (setq host (url-gateway-nslookup-host host))) | |
239 | |
240 (condition-case errobj | |
241 ;; This is a clean way to ensure the new process inherits the | |
242 ;; right coding systems in both Emacs and XEmacs. | |
243 (let ((coding-system-for-read 'binary) | |
244 (coding-system-for-write 'binary)) | |
245 (setq conn (case gw-method | |
57449
202c408c174b
url-vars.el (url-gateway-method): Add new method `tls'.
Simon Josefsson <jas@extundo.com>
parents:
54770
diff
changeset
|
246 (tls |
202c408c174b
url-vars.el (url-gateway-method): Add new method `tls'.
Simon Josefsson <jas@extundo.com>
parents:
54770
diff
changeset
|
247 (open-tls-stream name buffer host service)) |
54695 | 248 (ssl |
249 (open-ssl-stream name buffer host service)) | |
250 ((native) | |
73501
437fb645afb4
* url-http.el (url-http-mark-connection-as-free): Verify that
Chong Yidong <cyd@stupidchicken.com>
parents:
70241
diff
changeset
|
251 ;; Use non-blocking socket if we can. |
437fb645afb4
* url-http.el (url-http-mark-connection-as-free): Verify that
Chong Yidong <cyd@stupidchicken.com>
parents:
70241
diff
changeset
|
252 (make-network-process :name name :buffer buffer |
437fb645afb4
* url-http.el (url-http-mark-connection-as-free): Verify that
Chong Yidong <cyd@stupidchicken.com>
parents:
70241
diff
changeset
|
253 :host host :service service |
74575
34a1ff09106b
(url-gateway-nslookup-program): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
73533
diff
changeset
|
254 :nowait |
73533
61352a6a6dcf
(url-open-stream): Really use asynchronous connections (accidentally
Magnus Henoch <mange@freemail.hu>
parents:
73501
diff
changeset
|
255 (featurep 'make-network-process '(:nowait t)))) |
54695 | 256 (socks |
257 (socks-open-network-stream name buffer host service)) | |
258 (telnet | |
259 (url-open-telnet name buffer host service)) | |
260 (rlogin | |
261 (url-open-rlogin name buffer host service)) | |
262 (otherwise | |
263 (error "Bad setting of url-gateway-method: %s" | |
264 url-gateway-method))))) | |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
265 ;; Ignoring errors here seems wrong. E.g. it'll throw away the |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
266 ;; error signalled two lines above. It was also found inconvenient |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
267 ;; during debugging. |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
268 ;; (error |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
269 ;; (setq conn nil)) |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
270 ) |
54695 | 271 conn))) |
272 | |
273 (provide 'url-gw) | |
54699 | 274 |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
275 ;; arch-tag: 1c4c0317-6d03-45b8-b3f3-838bd8f9d838 |
57612 | 276 ;;; url-gw.el ends here |