Mercurial > emacs
annotate lisp/url/url-gw.el @ 83513:966a40e7fb54
Merged from emacs@sv.gnu.org
Patches applied:
* emacs@sv.gnu.org/emacs--devo--0--patch-234
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-235
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-236
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-237
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-238
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-239
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-240
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-241
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-242
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-243
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-244
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-245
(Ffield_beginning, find_field): Undo change of 2006-04-23.
* emacs@sv.gnu.org/emacs--devo--0--patch-246
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-247
Rcirc patch from Ryan Yeske
* emacs@sv.gnu.org/emacs--devo--0--patch-248
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-249
Merge from gnus--rel--5.10
* emacs@sv.gnu.org/emacs--devo--0--patch-250
Update from CVS
* emacs@sv.gnu.org/emacs--devo--0--patch-251
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-87
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-88
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-89
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-90
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-91
Merge from emacs--devo--0
* emacs@sv.gnu.org/gnus--rel--5.10--patch-92
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-93
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-94
Update from CVS
* emacs@sv.gnu.org/gnus--rel--5.10--patch-95
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-553
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Fri, 28 Apr 2006 14:48:18 +0000 |
parents | d04d8ccb3c41 07c1b5999e53 |
children | 034f67f59091 |
rev | line source |
---|---|
54695 | 1 ;;; url-gw.el --- Gateway munging for URL loading |
57612 | 2 |
68640
e8a3fb527b77
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64748
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 2004, 2005, 2006 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 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
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 | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64084 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
57612 | 24 |
25 ;;; Code: | |
26 | |
54695 | 27 (eval-when-compile (require 'cl)) |
28 (require 'url-vars) | |
29 | |
30 ;; Fixme: support SSH explicitly or via a url-gateway-rlogin-program? | |
31 | |
32 (autoload 'socks-open-network-stream "socks") | |
33 (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
|
34 (autoload 'open-tls-stream "tls") |
54695 | 35 |
36 (defgroup url-gateway nil | |
63987
56d2561b1c9f
(url-gateway): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63618
diff
changeset
|
37 "URL gateway variables." |
54695 | 38 :group 'url) |
39 | |
40 (defcustom url-gateway-local-host-regexp nil | |
41 "*A regular expression specifying local hostnames/machines." | |
42 :type '(choice (const nil) regexp) | |
43 :group 'url-gateway) | |
44 | |
45 (defcustom url-gateway-prompt-pattern | |
46 "^[^#$%>;]*[#$%>;] *" ;; "bash\\|\$ *\r?$\\|> *\r?" | |
47 "*A regular expression matching a shell prompt." | |
48 :type 'regexp | |
49 :group 'url-gateway) | |
50 | |
51 (defcustom url-gateway-rlogin-host nil | |
52 "*What hostname to actually rlog into before doing a telnet." | |
53 :type '(choice (const nil) string) | |
54 :group 'url-gateway) | |
55 | |
56 (defcustom url-gateway-rlogin-user-name nil | |
57 "*Username to log into the remote machine with when using rlogin." | |
58 :type '(choice (const nil) string) | |
59 :group 'url-gateway) | |
60 | |
61 (defcustom url-gateway-rlogin-parameters '("telnet" "-8") | |
62 "*Parameters to `url-open-rlogin'. | |
63 This list will be used as the parameter list given to rsh." | |
64 :type '(repeat string) | |
65 :group 'url-gateway) | |
66 | |
67 (defcustom url-gateway-telnet-host nil | |
68 "*What hostname to actually login to before doing a telnet." | |
69 :type '(choice (const nil) string) | |
70 :group 'url-gateway) | |
71 | |
72 (defcustom url-gateway-telnet-parameters '("exec" "telnet" "-8") | |
73 "*Parameters to `url-open-telnet'. | |
74 This list will be executed as a command after logging in via telnet." | |
75 :type '(repeat string) | |
76 :group 'url-gateway) | |
77 | |
78 (defcustom url-gateway-telnet-login-prompt "^\r*.?login:" | |
79 "*Prompt that tells us we should send our username when loggin in w/telnet." | |
80 :type 'regexp | |
81 :group 'url-gateway) | |
82 | |
83 (defcustom url-gateway-telnet-password-prompt "^\r*.?password:" | |
84 "*Prompt that tells us we should send our password when loggin in w/telnet." | |
85 :type 'regexp | |
86 :group 'url-gateway) | |
87 | |
88 (defcustom url-gateway-telnet-user-name nil | |
89 "User name to log in via telnet with." | |
90 :type '(choice (const nil) string) | |
91 :group 'url-gateway) | |
92 | |
93 (defcustom url-gateway-telnet-password nil | |
94 "Password to use to log in via telnet with." | |
95 :type '(choice (const nil) string) | |
96 :group 'url-gateway) | |
97 | |
98 (defcustom url-gateway-broken-resolution nil | |
99 "*Whether to use nslookup to resolve hostnames. | |
100 This should be used when your version of Emacs cannot correctly use DNS, | |
101 but your machine can. This usually happens if you are running a statically | |
102 linked Emacs under SunOS 4.x" | |
103 :type 'boolean | |
104 :group 'url-gateway) | |
105 | |
106 (defcustom url-gateway-nslookup-program "nslookup" | |
107 "*If non-NIL then a string naming nslookup program." | |
108 :type '(choice (const :tag "None" :value nil) string) | |
109 :group 'url-gateway) | |
110 | |
111 ;; Stolen from ange-ftp | |
112 ;;;###autoload | |
113 (defun url-gateway-nslookup-host (host) | |
114 "Attempt to resolve the given HOST using nslookup if possible." | |
115 (interactive "sHost: ") | |
116 (if url-gateway-nslookup-program | |
117 (let ((proc (start-process " *nslookup*" " *nslookup*" | |
118 url-gateway-nslookup-program host)) | |
119 (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
|
120 (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
|
121 (with-current-buffer (process-buffer proc) |
54695 | 122 (while (memq (process-status proc) '(run open)) |
123 (accept-process-output proc)) | |
124 (goto-char (point-min)) | |
125 (if (re-search-forward "Name:.*\nAddress: *\\(.*\\)$" nil t) | |
126 (setq res (buffer-substring (match-beginning 1) | |
127 (match-end 1)))) | |
128 (kill-buffer (current-buffer))) | |
129 res) | |
130 host)) | |
131 | |
132 ;; Stolen from red gnus nntp.el | |
133 (defun url-wait-for-string (regexp proc) | |
134 "Wait until string matching REGEXP arrives in process PROC's buffer." | |
135 (let ((buf (current-buffer))) | |
136 (goto-char (point-min)) | |
137 (while (not (re-search-forward regexp nil t)) | |
138 (accept-process-output proc) | |
139 (set-buffer buf) | |
140 (goto-char (point-min))))) | |
141 | |
142 ;; Stolen from red gnus nntp.el | |
143 (defun url-open-rlogin (name buffer host service) | |
144 "Open a connection using rsh." | |
145 (if (not (stringp service)) | |
146 (setq service (int-to-string service))) | |
147 (let ((proc (if url-gateway-rlogin-user-name | |
148 (start-process | |
149 name buffer "rsh" | |
150 url-gateway-rlogin-host "-l" url-gateway-rlogin-user-name | |
151 (mapconcat 'identity | |
152 (append url-gateway-rlogin-parameters | |
153 (list host service)) " ")) | |
154 (start-process | |
155 name buffer "rsh" url-gateway-rlogin-host | |
156 (mapconcat 'identity | |
157 (append url-gateway-rlogin-parameters | |
158 (list host service)) | |
159 " "))))) | |
160 (set-buffer buffer) | |
161 (url-wait-for-string "^\r*200" proc) | |
162 (beginning-of-line) | |
163 (delete-region (point-min) (point)) | |
164 proc)) | |
165 | |
166 ;; Stolen from red gnus nntp.el | |
167 (defun url-open-telnet (name buffer host service) | |
168 (if (not (stringp service)) | |
169 (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
|
170 (with-current-buffer (get-buffer-create buffer) |
54695 | 171 (erase-buffer) |
172 (let ((proc (start-process name buffer "telnet" "-8")) | |
173 (case-fold-search t)) | |
174 (when (memq (process-status proc) '(open run)) | |
175 (process-send-string proc "set escape \^X\n") | |
176 (process-send-string proc (concat | |
177 "open " url-gateway-telnet-host "\n")) | |
178 (url-wait-for-string url-gateway-telnet-login-prompt proc) | |
179 (process-send-string | |
180 proc (concat | |
181 (or url-gateway-telnet-user-name | |
182 (setq url-gateway-telnet-user-name (read-string "login: "))) | |
183 "\n")) | |
184 (url-wait-for-string url-gateway-telnet-password-prompt proc) | |
185 (process-send-string | |
186 proc (concat | |
187 (or url-gateway-telnet-password | |
188 (setq url-gateway-telnet-password | |
57510
9f80571c6c3e
(url-open-telnet): Use read-passwd.
Richard M. Stallman <rms@gnu.org>
parents:
57449
diff
changeset
|
189 (read-passwd "Password: "))) |
54695 | 190 "\n")) |
191 (erase-buffer) | |
192 (url-wait-for-string url-gateway-prompt-pattern proc) | |
193 (process-send-string | |
194 proc (concat (mapconcat 'identity | |
195 (append url-gateway-telnet-parameters | |
196 (list host service)) " ") "\n")) | |
197 (url-wait-for-string "^\r*Escape character.*\r*\n+" proc) | |
198 (delete-region (point-min) (match-end 0)) | |
199 (process-send-string proc "\^]\n") | |
200 (url-wait-for-string "^telnet" proc) | |
201 (process-send-string proc "mode character\n") | |
202 (accept-process-output proc 1) | |
203 (sit-for 1) | |
204 (goto-char (point-min)) | |
205 (forward-line 1) | |
206 (delete-region (point) (point-max))) | |
207 proc))) | |
208 | |
209 ;;;###autoload | |
210 (defun url-open-stream (name buffer host service) | |
211 "Open a stream to HOST, possibly via a gateway. | |
212 Args per `open-network-stream'. | |
63618
95a1159c8f9e
(url-open-stream): Fix spellings.
Juanma Barranquero <lekktu@gmail.com>
parents:
57620
diff
changeset
|
213 Will not make a connection if `url-gateway-unplugged' is non-nil." |
54695 | 214 (unless url-gateway-unplugged |
215 (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
|
216 (not (eq 'tls url-gateway-method)) |
54695 | 217 (not (eq 'ssl url-gateway-method)) |
218 (string-match | |
219 url-gateway-local-host-regexp | |
220 host)) | |
221 'native | |
222 url-gateway-method)) | |
223 ;;; ;; This hack is for OS/2 Emacs so that it will not do bogus CRLF | |
224 ;;; ;; conversions while trying to be 'helpful' | |
225 ;;; (tcp-binary-process-output-services (if (stringp service) | |
226 ;;; (list service) | |
227 ;;; (list service | |
228 ;;; (int-to-string service)))) | |
229 | |
230 ;; An attempt to deal with denied connections, and attempt | |
231 ;; to reconnect | |
232 (cur-retries 0) | |
233 (retry t) | |
234 (errobj nil) | |
235 (conn nil)) | |
236 | |
237 ;; If the user told us to do DNS for them, do it. | |
238 (if url-gateway-broken-resolution | |
239 (setq host (url-gateway-nslookup-host host))) | |
240 | |
241 (condition-case errobj | |
242 ;; This is a clean way to ensure the new process inherits the | |
243 ;; right coding systems in both Emacs and XEmacs. | |
244 (let ((coding-system-for-read 'binary) | |
245 (coding-system-for-write 'binary)) | |
246 (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
|
247 (tls |
202c408c174b
url-vars.el (url-gateway-method): Add new method `tls'.
Simon Josefsson <jas@extundo.com>
parents:
54770
diff
changeset
|
248 (open-tls-stream name buffer host service)) |
54695 | 249 (ssl |
250 (open-ssl-stream name buffer host service)) | |
251 ((native) | |
252 (open-network-stream name buffer host service)) | |
253 (socks | |
254 (socks-open-network-stream name buffer host service)) | |
255 (telnet | |
256 (url-open-telnet name buffer host service)) | |
257 (rlogin | |
258 (url-open-rlogin name buffer host service)) | |
259 (otherwise | |
260 (error "Bad setting of url-gateway-method: %s" | |
261 url-gateway-method))))) | |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
262 ;; 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
|
263 ;; 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
|
264 ;; during debugging. |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
265 ;; (error |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
266 ;; (setq conn nil)) |
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
267 ) |
54695 | 268 conn))) |
269 | |
270 (provide 'url-gw) | |
54699 | 271 |
70241
07c1b5999e53
(url-open-stream): Don't hide errors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68640
diff
changeset
|
272 ;; arch-tag: 1c4c0317-6d03-45b8-b3f3-838bd8f9d838 |
57612 | 273 ;;; url-gw.el ends here |