14
|
1 ;;; url-misc.el --- Misc Uniform Resource Locator retrieval code
|
|
2 ;; Author: wmperry
|
|
3 ;; Created: 1996/10/09 19:00:59
|
|
4 ;; Version: 1.3
|
|
5 ;; Keywords: comm, data, processes
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
|
9 ;;;
|
|
10 ;;; This file is not part of GNU Emacs, but the same permissions apply.
|
|
11 ;;;
|
|
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;;; it under the terms of the GNU General Public License as published by
|
|
14 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;;; any later version.
|
|
16 ;;;
|
|
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;;; GNU General Public License for more details.
|
|
21 ;;;
|
|
22 ;;; You should have received a copy of the GNU General Public License
|
|
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
24 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;;; Boston, MA 02111-1307, USA.
|
|
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
27
|
|
28 (require 'url-vars)
|
|
29 (require 'url-parse)
|
|
30 (autoload 'Info-goto-node "info" "" t)
|
|
31
|
|
32 (defun url-info (url)
|
|
33 ;; Fetch an info node
|
|
34 (if (get-buffer url-working-buffer)
|
|
35 (kill-buffer url-working-buffer))
|
|
36 (let* ((data (url-generic-parse-url url))
|
|
37 (fname (url-filename data))
|
|
38 (node (or (url-target data) "Top")))
|
|
39 (if (and fname node)
|
|
40 (Info-goto-node (concat "(" fname ")" node))
|
|
41 (error "Malformed url: %s" url))))
|
|
42
|
|
43 (defun url-finger (url)
|
|
44 ;; Find a finger reference
|
|
45 (setq url-current-mime-headers '(("content-type" . "text/html"))
|
|
46 url-current-mime-type "text/html")
|
|
47 (set-buffer (get-buffer-create url-working-buffer))
|
|
48 (let* ((urlobj (if (vectorp url) url
|
|
49 (url-generic-parse-url url)))
|
|
50 (host (or (url-host urlobj) "localhost"))
|
|
51 (port (or (url-port urlobj)
|
|
52 (cdr-safe (assoc "finger" url-default-ports))))
|
|
53 (user (url-unhex-string (url-filename urlobj)))
|
|
54 (proc (url-open-stream "finger" url-working-buffer host
|
|
55 (string-to-int port))))
|
|
56 (if (stringp proc)
|
|
57 (message "%s" proc)
|
|
58 (process-kill-without-query proc)
|
|
59 (if (= (string-to-char user) ?/)
|
|
60 (setq user (substring user 1 nil)))
|
|
61 (goto-char (point-min))
|
|
62 (insert "<html>\n"
|
|
63 " <head>\n"
|
|
64 " <title>Finger information for " user "@" host "</title>\n"
|
|
65 " </head>\n"
|
|
66 " <body>\n"
|
|
67 " <h1>Finger information for " user "@" host "</h1>\n"
|
|
68 " <hr>\n"
|
|
69 " <pre>\n")
|
|
70 (process-send-string proc (concat user "\r\n"))
|
|
71 (while (memq (url-process-status proc) '(run open))
|
|
72 (url-after-change-function)
|
|
73 (url-accept-process-output proc))
|
|
74 (goto-char (point-min))
|
|
75 (url-replace-regexp "^Process .* exited .*code .*$" "")
|
|
76 (goto-char (point-max))
|
|
77 (insert " </pre>\n"
|
|
78 " </body>\n"
|
|
79 "</html>\n"))))
|
|
80
|
|
81 (defun url-rlogin (url)
|
|
82 ;; Open up an rlogin connection
|
|
83 (if (get-buffer url-working-buffer)
|
|
84 (kill-buffer url-working-buffer))
|
|
85 (or (string-match "rlogin:/*\\(.*@\\)*\\([^/]*\\)/*" url)
|
|
86 (error "Malformed RLOGIN URL."))
|
|
87 (let* ((server (substring url (match-beginning 2) (match-end 2)))
|
|
88 (name (if (match-beginning 1)
|
|
89 (substring url (match-beginning 1) (1- (match-end 1)))
|
|
90 nil))
|
|
91 (title (format "%s%s" (if name (concat name "@") "") server))
|
|
92 (thebuf (string-match ":" server))
|
|
93 (port (if thebuf
|
|
94 (prog1
|
|
95 (substring server (1+ thebuf) nil)
|
|
96 (setq server (substring server 0 thebuf))) "23")))
|
|
97 (cond
|
|
98 ((not (eq (device-type) 'tty))
|
|
99 (apply 'start-process
|
|
100 "htmlsub"
|
|
101 nil
|
|
102 (url-string-to-tokens
|
|
103 (format url-xterm-command title
|
|
104 (if (and url-gateway-local-host-regexp
|
|
105 (string-match url-gateway-local-host-regexp
|
|
106 server))
|
|
107 url-local-rlogin-prog
|
|
108 url-remote-rlogin-prog) server
|
|
109 (concat "-l " name)) ? )))
|
|
110 (url-use-transparent
|
|
111 (require 'transparent)
|
|
112 (sit-for 1)
|
|
113 (transparent-window (get-buffer-create
|
|
114 (format "%s%s:%s" (if name (concat name "@") "")
|
|
115 server port))
|
|
116 (if (and url-gateway-local-host-regexp
|
|
117 (string-match url-gateway-local-host-regexp
|
|
118 server))
|
|
119 url-local-rlogin-prog
|
|
120 url-remote-rlogin-prog)
|
|
121 (list server "-l" name) nil
|
|
122 "Press any key to return to emacs"))
|
|
123 (t
|
|
124 (terminal-emulator
|
|
125 (get-buffer-create (format "%s%s:%s" (if name (concat name "@") "")
|
|
126 server port))
|
|
127 (if (and url-gateway-local-host-regexp
|
|
128 (string-match url-gateway-local-host-regexp
|
|
129 server))
|
|
130 url-local-rlogin-prog
|
|
131 url-remote-rlogin-prog)
|
|
132 (list server "-l" name))))))
|
|
133
|
|
134 (defun url-telnet (url)
|
|
135 ;; Open up a telnet connection
|
|
136 (if (get-buffer url-working-buffer)
|
|
137 (kill-buffer url-working-buffer))
|
|
138 (or (string-match "telnet:/*\\(.*@\\)*\\([^/]*\\)/*" url)
|
|
139 (error "Malformed telnet URL: %s" url))
|
|
140 (let* ((server (substring url (match-beginning 2) (match-end 2)))
|
|
141 (name (if (match-beginning 1)
|
|
142 (substring url (match-beginning 1) (1- (match-end 1)))
|
|
143 nil))
|
|
144 (title (format "%s%s" (if name (concat name "@") "") server))
|
|
145 (thebuf (string-match ":" server))
|
|
146 (port (if thebuf
|
|
147 (prog1
|
|
148 (substring server (1+ thebuf) nil)
|
|
149 (setq server (substring server 0 thebuf))) "23")))
|
|
150 (cond
|
|
151 ((not (eq (device-type) 'tty))
|
|
152 (apply 'start-process
|
|
153 "htmlsub"
|
|
154 nil
|
|
155 (url-string-to-tokens
|
|
156 (format url-xterm-command title
|
|
157 (if (and url-gateway-local-host-regexp
|
|
158 (string-match url-gateway-local-host-regexp
|
|
159 server))
|
|
160 url-local-telnet-prog
|
|
161 url-remote-telnet-prog) server port) ? ))
|
|
162 (if name (message "Please log in as %s" name)))
|
|
163 (url-use-transparent
|
|
164 (require 'transparent)
|
|
165 (if name (message "Please log in as %s" name))
|
|
166 (sit-for 1)
|
|
167 (transparent-window (get-buffer-create
|
|
168 (format "%s%s:%s" (if name (concat name "@") "")
|
|
169 server port))
|
|
170 (if (and url-gateway-local-host-regexp
|
|
171 (string-match url-gateway-local-host-regexp
|
|
172 server))
|
|
173 url-local-telnet-prog
|
|
174 url-remote-telnet-prog)
|
|
175 (list server port) nil
|
|
176 "Press any key to return to emacs"))
|
|
177 (t
|
|
178 (terminal-emulator
|
|
179 (get-buffer-create (format "%s%s:%s" (if name (concat name "@") "")
|
|
180 server port))
|
|
181 (if (and url-gateway-local-host-regexp
|
|
182 (string-match url-gateway-local-host-regexp
|
|
183 server))
|
|
184 url-local-telnet-prog
|
|
185 url-remote-telnet-prog)
|
|
186 (list server port))
|
|
187 (if name (message "Please log in as %s" name))))))
|
|
188
|
|
189 (defun url-tn3270 (url)
|
|
190 ;; Open up a tn3270 connection
|
|
191 (if (get-buffer url-working-buffer)
|
|
192 (kill-buffer url-working-buffer))
|
|
193 (string-match "tn3270:/*\\(.*@\\)*\\([^/]*\\)/*" url)
|
|
194 (let* ((server (substring url (match-beginning 2) (match-end 2)))
|
|
195 (name (if (match-beginning 1)
|
|
196 (substring url (match-beginning 1) (1- (match-end 1)))
|
|
197 nil))
|
|
198 (thebuf (string-match ":" server))
|
|
199 (title (format "%s%s" (if name (concat name "@") "") server))
|
|
200 (port (if thebuf
|
|
201 (prog1
|
|
202 (substring server (1+ thebuf) nil)
|
|
203 (setq server (substring server 0 thebuf))) "23")))
|
|
204 (cond
|
|
205 ((not (eq (device-type) 'tty))
|
|
206 (start-process "htmlsub" nil url-xterm-command
|
|
207 "-title" title
|
|
208 "-ut" "-e" url-tn3270-emulator server port)
|
|
209 (if name (message "Please log in as %s" name)))
|
|
210 (url-use-transparent
|
|
211 (require 'transparent)
|
|
212 (if name (message "Please log in as %s" name))
|
|
213 (sit-for 1)
|
|
214 (transparent-window (get-buffer-create
|
|
215 (format "%s%s:%s" (if name (concat name "@") "")
|
|
216 server port))
|
|
217 url-tn3270-emulator
|
|
218 (list server port) nil
|
|
219 "Press any key to return to emacs"))
|
|
220 (t
|
|
221 (terminal-emulator
|
|
222 (get-buffer-create (format "%s%s:%s" (if name (concat name "@") "")
|
|
223 server port))
|
|
224 url-tn3270-emulator
|
|
225 (list server port))
|
|
226 (if name (message "Please log in as %s" name))))))
|
|
227
|
|
228 (defun url-proxy (url)
|
|
229 ;; Retrieve URL from a proxy.
|
|
230 ;; Expects `url-using-proxy' to be bound to the specific proxy to use."
|
|
231 (let (
|
|
232 (urlobj (url-generic-parse-url url))
|
|
233 (proxyobj (url-generic-parse-url url-using-proxy)))
|
|
234 (url-http url-using-proxy url)
|
|
235 (setq url-current-type (url-type urlobj)
|
|
236 url-current-user (url-user urlobj)
|
|
237 url-current-port (or (url-port urlobj)
|
|
238 (cdr-safe (assoc url-current-type
|
|
239 url-default-ports)))
|
|
240 url-current-server (url-host urlobj)
|
|
241 url-current-file (url-filename urlobj))))
|
|
242
|
|
243 (defun url-x-exec (url)
|
|
244 ;; Handle local execution of scripts.
|
|
245 (set-buffer (get-buffer-create url-working-buffer))
|
|
246 (erase-buffer)
|
|
247 (string-match "x-exec:/+\\([^/]+\\)\\(/.*\\)" url)
|
|
248 (let ((process-environment process-environment)
|
|
249 (executable (url-match url 1))
|
|
250 (path-info (url-match url 2))
|
|
251 (query-string nil)
|
|
252 (safe-paths url-local-exec-path)
|
|
253 (found nil)
|
|
254 (y nil)
|
|
255 )
|
|
256 (setq url-current-server executable
|
|
257 url-current-file path-info)
|
|
258 (if (string-match "\\(.*\\)\\?\\(.*\\)" path-info)
|
|
259 (setq query-string (url-match path-info 2)
|
|
260 path-info (url-match path-info 1)))
|
|
261 (while (and safe-paths (not found))
|
|
262 (setq y (expand-file-name executable (car safe-paths))
|
|
263 found (and (file-exists-p y) (file-executable-p y) y)
|
|
264 safe-paths (cdr safe-paths)))
|
|
265 (if (not found)
|
|
266 (url-retrieve (concat "www://error/nofile/" executable))
|
|
267 (setq process-environment
|
|
268 (append
|
|
269 (list
|
|
270 "SERVER_SOFTWARE=x-exec/1.0"
|
|
271 (concat "SERVER_NAME=" (system-name))
|
|
272 "GATEWAY_INTERFACE=CGI/1.1"
|
|
273 "SERVER_PROTOCOL=HTTP/1.0"
|
|
274 "SERVER_PORT="
|
|
275 (concat "REQUEST_METHOD=" url-request-method)
|
|
276 (concat "HTTP_ACCEPT="
|
|
277 (mapconcat
|
|
278 (function
|
|
279 (lambda (x)
|
|
280 (cond
|
|
281 ((= x ?\n) (setq y t) "")
|
|
282 ((= x ?:) (setq y nil) ",")
|
|
283 (t (char-to-string x))))) url-mime-accept-string
|
|
284 ""))
|
|
285 (concat "PATH_INFO=" (url-unhex-string path-info))
|
|
286 (concat "PATH_TRANSLATED=" (url-unhex-string path-info))
|
|
287 (concat "SCRIPT_NAME=" executable)
|
|
288 (concat "QUERY_STRING=" (url-unhex-string query-string))
|
|
289 (concat "REMOTE_HOST=" (system-name)))
|
|
290 (if (assoc "content-type" url-request-extra-headers)
|
|
291 (concat "CONTENT_TYPE=" (cdr
|
|
292 (assoc "content-type"
|
|
293 url-request-extra-headers))))
|
|
294 (if url-request-data
|
|
295 (concat "CONTENT_LENGTH=" (length url-request-data)))
|
|
296 process-environment))
|
|
297 (and url-request-data (insert url-request-data))
|
|
298 (setq y (call-process-region (point-min) (point-max) found t t))
|
|
299 (goto-char (point-min))
|
|
300 (delete-region (point) (progn (skip-chars-forward " \t\n") (point)))
|
|
301 (cond
|
|
302 ((url-mime-response-p) nil) ; Its already got an HTTP/1.0 header
|
|
303 ((null y) ; Weird exit status, whassup?
|
|
304 (insert "HTTP/1.0 404 Not Found\n"
|
|
305 "Server: " url-package-name "/x-exec\n"))
|
|
306 ((= 0 y) ; The shell command was successful
|
|
307 (insert "HTTP/1.0 200 Document follows\n"
|
|
308 "Server: " url-package-name "/x-exec\n"))
|
|
309 (t ; Non-zero exit status is bad bad bad
|
|
310 (insert "HTTP/1.0 404 Not Found\n"
|
|
311 "Server: " url-package-name "/x-exec\n"))))))
|
|
312
|
|
313 (provide 'url-misc)
|