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