14
|
1 ;;; url-misc.el --- Misc Uniform Resource Locator retrieval code
|
|
2 ;; Author: wmperry
|
26
|
3 ;; Created: 1997/02/19 00:52:07
|
|
4 ;; Version: 1.12
|
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
|
|
33 (defun url-info (url)
|
|
34 ;; Fetch an info node
|
|
35 (if (get-buffer url-working-buffer)
|
|
36 (kill-buffer url-working-buffer))
|
|
37 (let* ((data (url-generic-parse-url url))
|
|
38 (fname (url-filename data))
|
26
|
39 (node (url-unhex-string (or (url-target data) "Top"))))
|
14
|
40 (if (and fname node)
|
|
41 (Info-goto-node (concat "(" fname ")" node))
|
|
42 (error "Malformed url: %s" url))))
|
|
43
|
|
44 (defun url-finger (url)
|
|
45 ;; Find a finger reference
|
|
46 (setq url-current-mime-headers '(("content-type" . "text/html"))
|
|
47 url-current-mime-type "text/html")
|
|
48 (set-buffer (get-buffer-create url-working-buffer))
|
|
49 (let* ((urlobj (if (vectorp url) url
|
|
50 (url-generic-parse-url url)))
|
|
51 (host (or (url-host urlobj) "localhost"))
|
|
52 (port (or (url-port urlobj)
|
|
53 (cdr-safe (assoc "finger" url-default-ports))))
|
|
54 (user (url-unhex-string (url-filename urlobj)))
|
|
55 (proc (url-open-stream "finger" url-working-buffer host
|
|
56 (string-to-int port))))
|
20
|
57 (if (not (processp proc))
|
|
58 nil
|
14
|
59 (process-kill-without-query proc)
|
|
60 (if (= (string-to-char user) ?/)
|
|
61 (setq user (substring user 1 nil)))
|
|
62 (goto-char (point-min))
|
|
63 (insert "<html>\n"
|
|
64 " <head>\n"
|
|
65 " <title>Finger information for " user "@" host "</title>\n"
|
|
66 " </head>\n"
|
|
67 " <body>\n"
|
|
68 " <h1>Finger information for " user "@" host "</h1>\n"
|
|
69 " <hr>\n"
|
|
70 " <pre>\n")
|
|
71 (process-send-string proc (concat user "\r\n"))
|
|
72 (while (memq (url-process-status proc) '(run open))
|
|
73 (url-after-change-function)
|
|
74 (url-accept-process-output proc))
|
|
75 (goto-char (point-min))
|
|
76 (url-replace-regexp "^Process .* exited .*code .*$" "")
|
|
77 (goto-char (point-max))
|
|
78 (insert " </pre>\n"
|
|
79 " </body>\n"
|
|
80 "</html>\n"))))
|
|
81
|
16
|
82 (defun url-do-terminal-emulator (type server port user)
|
|
83 (terminal-emulator
|
|
84 (generate-new-buffer (format "%s%s" (if user (concat user "@") "") server))
|
|
85 (case type
|
|
86 (rlogin "rlogin")
|
|
87 (telnet "telnet")
|
|
88 (tn3270 "tn3270")
|
|
89 (otherwise
|
|
90 (error "Unknown terminal emulator required: %s" type)))
|
|
91 (if user
|
|
92 (case type
|
|
93 (rlogin
|
|
94 (list server "-l" user))
|
|
95 (telnet
|
|
96 (if user (message "Please log in as user: %s" user))
|
|
97 (if port
|
|
98 (list server port)
|
|
99 (list server)))
|
|
100 (tn3270
|
|
101 (if user (message "Please log in as user: %s" user))
|
|
102 (list server))))))
|
14
|
103
|
16
|
104 (defun url-generic-emulator-loader (url)
|
14
|
105 (if (get-buffer url-working-buffer)
|
|
106 (kill-buffer url-working-buffer))
|
16
|
107 (or (string-match "^\\([^:]+\\):/*\\(.*@\\)*\\([^/]*\\)/*" url)
|
|
108 (error "Invalid URL: %s" url))
|
|
109 (let* ((type (intern (downcase (match-string 1 url))))
|
|
110 (server (match-string 3 url))
|
|
111 (name (if (match-beginning 2)
|
|
112 (substring url (match-beginning 2) (1- (match-end 2)))))
|
|
113 (port (if (string-match ":" server)
|
14
|
114 (prog1
|
16
|
115 (substring server (match-end 0))
|
|
116 (setq server (substring server 0 (match-beginning 0)))))))
|
|
117 (url-do-terminal-emulator type server port name)))
|
14
|
118
|
16
|
119 (fset 'url-rlogin 'url-generic-emulator-loader)
|
|
120 (fset 'url-telnet 'url-generic-emulator-loader)
|
|
121 (fset 'url-tn3270 'url-generic-emulator-loader)
|
14
|
122
|
|
123 (defun url-proxy (url)
|
|
124 ;; Retrieve URL from a proxy.
|
|
125 ;; Expects `url-using-proxy' to be bound to the specific proxy to use."
|
|
126 (let (
|
|
127 (urlobj (url-generic-parse-url url))
|
|
128 (proxyobj (url-generic-parse-url url-using-proxy)))
|
26
|
129 (url-http url-using-proxy url)))
|
14
|
130
|
16
|
131 ;; ftp://ietf.org/internet-drafts/draft-masinter-url-data-02.txt
|
|
132 (defun url-data (url)
|
|
133 (set-buffer (get-buffer-create url-working-buffer))
|
|
134 (let ((content-type nil)
|
|
135 (encoding nil)
|
|
136 (data nil))
|
|
137 (cond
|
|
138 ((string-match "^data:\\([^;,]*\\);*\\([^,]*\\)," url)
|
|
139 (setq content-type (match-string 1 url)
|
|
140 encoding (match-string 2 url)
|
|
141 data (url-unhex-string (substring url (match-end 0))))
|
|
142 (if (= 0 (length content-type)) (setq content-type "text/plain"))
|
|
143 (if (= 0 (length encoding)) (setq encoding "8bit")))
|
|
144 (t nil))
|
|
145 (setq url-current-content-length (length data)
|
|
146 url-current-mime-type content-type
|
|
147 url-current-mime-encoding encoding
|
|
148 url-current-mime-headers (list (cons "content-type" content-type)
|
|
149 (cons "content-encoding" encoding)))
|
|
150 (and data (insert data))))
|
|
151
|
14
|
152 (provide 'url-misc)
|