14
|
1 ;;; url-misc.el --- Misc Uniform Resource Locator retrieval code
|
|
2 ;; Author: wmperry
|
44
|
3 ;; Created: 1997/03/24 23:59:37
|
|
4 ;; Version: 1.13
|
14
|
5 ;; Keywords: comm, data, processes
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
16
|
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
|
14
|
10 ;;;
|
|
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
|
|
12 ;;;
|
|
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
14 ;;; it under the terms of the GNU General Public License as published by
|
|
15 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;;; any later version.
|
|
17 ;;;
|
|
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;;; GNU General Public License for more details.
|
|
22 ;;;
|
|
23 ;;; You should have received a copy of the GNU General Public License
|
|
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;;; Boston, MA 02111-1307, USA.
|
|
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
28
|
|
29 (require 'url-vars)
|
|
30 (require 'url-parse)
|
|
31 (autoload 'Info-goto-node "info" "" t)
|
|
32
|
44
|
33 (defun url-netrek (url)
|
|
34 ;; Start a netrek client
|
|
35 (if (get-buffer url-working-buffer)
|
|
36 (kill-buffer url-working-buffer))
|
|
37 (let ((data (url-generic-parse-url url)))
|
|
38 (error
|
|
39 "I should launch netrek on: %s %s" (url-host data) (url-port data))))
|
|
40
|
14
|
41 (defun url-info (url)
|
|
42 ;; Fetch an info node
|
|
43 (if (get-buffer url-working-buffer)
|
|
44 (kill-buffer url-working-buffer))
|
|
45 (let* ((data (url-generic-parse-url url))
|
|
46 (fname (url-filename data))
|
26
|
47 (node (url-unhex-string (or (url-target data) "Top"))))
|
14
|
48 (if (and fname node)
|
|
49 (Info-goto-node (concat "(" fname ")" node))
|
|
50 (error "Malformed url: %s" url))))
|
|
51
|
|
52 (defun url-finger (url)
|
|
53 ;; Find a finger reference
|
|
54 (setq url-current-mime-headers '(("content-type" . "text/html"))
|
|
55 url-current-mime-type "text/html")
|
|
56 (set-buffer (get-buffer-create url-working-buffer))
|
|
57 (let* ((urlobj (if (vectorp url) url
|
|
58 (url-generic-parse-url url)))
|
|
59 (host (or (url-host urlobj) "localhost"))
|
|
60 (port (or (url-port urlobj)
|
|
61 (cdr-safe (assoc "finger" url-default-ports))))
|
|
62 (user (url-unhex-string (url-filename urlobj)))
|
|
63 (proc (url-open-stream "finger" url-working-buffer host
|
|
64 (string-to-int port))))
|
20
|
65 (if (not (processp proc))
|
|
66 nil
|
14
|
67 (process-kill-without-query proc)
|
|
68 (if (= (string-to-char user) ?/)
|
|
69 (setq user (substring user 1 nil)))
|
|
70 (goto-char (point-min))
|
|
71 (insert "<html>\n"
|
|
72 " <head>\n"
|
|
73 " <title>Finger information for " user "@" host "</title>\n"
|
|
74 " </head>\n"
|
|
75 " <body>\n"
|
|
76 " <h1>Finger information for " user "@" host "</h1>\n"
|
|
77 " <hr>\n"
|
|
78 " <pre>\n")
|
|
79 (process-send-string proc (concat user "\r\n"))
|
|
80 (while (memq (url-process-status proc) '(run open))
|
|
81 (url-after-change-function)
|
|
82 (url-accept-process-output proc))
|
|
83 (goto-char (point-min))
|
|
84 (url-replace-regexp "^Process .* exited .*code .*$" "")
|
|
85 (goto-char (point-max))
|
|
86 (insert " </pre>\n"
|
|
87 " </body>\n"
|
|
88 "</html>\n"))))
|
|
89
|
16
|
90 (defun url-do-terminal-emulator (type server port user)
|
|
91 (terminal-emulator
|
|
92 (generate-new-buffer (format "%s%s" (if user (concat user "@") "") server))
|
|
93 (case type
|
|
94 (rlogin "rlogin")
|
|
95 (telnet "telnet")
|
|
96 (tn3270 "tn3270")
|
|
97 (otherwise
|
|
98 (error "Unknown terminal emulator required: %s" type)))
|
|
99 (if user
|
|
100 (case type
|
|
101 (rlogin
|
|
102 (list server "-l" user))
|
|
103 (telnet
|
|
104 (if user (message "Please log in as user: %s" user))
|
|
105 (if port
|
|
106 (list server port)
|
|
107 (list server)))
|
|
108 (tn3270
|
|
109 (if user (message "Please log in as user: %s" user))
|
|
110 (list server))))))
|
14
|
111
|
16
|
112 (defun url-generic-emulator-loader (url)
|
14
|
113 (if (get-buffer url-working-buffer)
|
|
114 (kill-buffer url-working-buffer))
|
16
|
115 (or (string-match "^\\([^:]+\\):/*\\(.*@\\)*\\([^/]*\\)/*" url)
|
|
116 (error "Invalid URL: %s" url))
|
|
117 (let* ((type (intern (downcase (match-string 1 url))))
|
|
118 (server (match-string 3 url))
|
|
119 (name (if (match-beginning 2)
|
|
120 (substring url (match-beginning 2) (1- (match-end 2)))))
|
|
121 (port (if (string-match ":" server)
|
14
|
122 (prog1
|
16
|
123 (substring server (match-end 0))
|
|
124 (setq server (substring server 0 (match-beginning 0)))))))
|
|
125 (url-do-terminal-emulator type server port name)))
|
14
|
126
|
16
|
127 (fset 'url-rlogin 'url-generic-emulator-loader)
|
|
128 (fset 'url-telnet 'url-generic-emulator-loader)
|
|
129 (fset 'url-tn3270 'url-generic-emulator-loader)
|
14
|
130
|
|
131 (defun url-proxy (url)
|
|
132 ;; Retrieve URL from a proxy.
|
|
133 ;; Expects `url-using-proxy' to be bound to the specific proxy to use."
|
|
134 (let (
|
|
135 (urlobj (url-generic-parse-url url))
|
|
136 (proxyobj (url-generic-parse-url url-using-proxy)))
|
26
|
137 (url-http url-using-proxy url)))
|
14
|
138
|
16
|
139 ;; ftp://ietf.org/internet-drafts/draft-masinter-url-data-02.txt
|
|
140 (defun url-data (url)
|
|
141 (set-buffer (get-buffer-create url-working-buffer))
|
|
142 (let ((content-type nil)
|
|
143 (encoding nil)
|
|
144 (data nil))
|
|
145 (cond
|
|
146 ((string-match "^data:\\([^;,]*\\);*\\([^,]*\\)," url)
|
|
147 (setq content-type (match-string 1 url)
|
|
148 encoding (match-string 2 url)
|
|
149 data (url-unhex-string (substring url (match-end 0))))
|
|
150 (if (= 0 (length content-type)) (setq content-type "text/plain"))
|
|
151 (if (= 0 (length encoding)) (setq encoding "8bit")))
|
|
152 (t nil))
|
|
153 (setq url-current-content-length (length data)
|
|
154 url-current-mime-type content-type
|
|
155 url-current-mime-encoding encoding
|
|
156 url-current-mime-headers (list (cons "content-type" content-type)
|
|
157 (cons "content-encoding" encoding)))
|
|
158 (and data (insert data))))
|
|
159
|
14
|
160 (provide 'url-misc)
|