54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-misc.el --- Misc Uniform Resource Locator retrieval code
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 ;; Keywords: comm, data, processes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
57427
|
5 ;;; Copyright (c) 1996,1997,1998,1999,2002 Free Software Foundation, Inc.
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;;; This file is part of GNU Emacs.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;;; it under the terms of the GNU General Public License as published by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;;; the Free Software Foundation; either version 2, or (at your option)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;;; any later version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;;; GNU General Public License for more details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;;; You should have received a copy of the GNU General Public License
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;;; Boston, MA 02111-1307, USA.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 (require 'url-vars)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 (require 'url-parse)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 (autoload 'Info-goto-node "info" "" t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 (autoload 'man "man" nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 (defun url-man (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 "Fetch a Unix manual page URL."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 (man (url-filename url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (defun url-info (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 "Fetch a GNU Info URL."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 ;; Fetch an info node
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (let* ((fname (url-filename url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 (node (url-unhex-string (or (url-target url) "Top"))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (if (and fname node)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 (Info-goto-node (concat "(" fname ")" node))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (error "Malformed url: %s" (url-recreate-url url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (defun url-do-terminal-emulator (type server port user)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (terminal-emulator
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (generate-new-buffer (format "%s%s" (if user (concat user "@") "") server))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (case type
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (rlogin "rlogin")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (telnet "telnet")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (tn3270 "tn3270")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 (otherwise
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (error "Unknown terminal emulator required: %s" type)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (case type
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (rlogin
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (if user
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (list server "-l" user)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (list server)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (telnet
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (if user (message "Please log in as user: %s" user))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (if port
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (list server port)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 (list server)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (tn3270
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (if user (message "Please log in as user: %s" user))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (list server)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (defun url-generic-emulator-loader (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 (let* ((type (intern (downcase (url-type url))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 (server (url-host url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (name (url-user url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 (port (url-port url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (url-do-terminal-emulator type server port name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (defalias 'url-rlogin 'url-generic-emulator-loader)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (defalias 'url-telnet 'url-generic-emulator-loader)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 (defalias 'url-tn3270 'url-generic-emulator-loader)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 ;; RFC 2397
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 (defun url-data (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 "Fetch a data URL (RFC 2397)."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (let ((mediatype nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 ;; The mediatype may need to be hex-encoded too -- see the RFC.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (desc (url-unhex-string (url-filename url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 (encoding "8bit")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (data nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (if (not (string-match "\\([^,]*\\)?," desc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (error "Malformed data URL: %s" desc)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 (setq mediatype (match-string 1 desc))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 (if (and mediatype (string-match ";base64\\'" mediatype))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 (setq mediatype (substring mediatype 0 (match-beginning 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 encoding "base64"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (if (or (null mediatype)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (eq ?\; (aref mediatype 0)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (setq mediatype (concat "text/plain" mediatype)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 (setq data (url-unhex-string (substring desc (match-end 0)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 (set-buffer (generate-new-buffer " *url-data*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (mm-disable-multibyte)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 (insert (format "Content-Length: %d\n" (length data))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 "Content-Type: " mediatype "\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 "Content-Encoding: " encoding "\n"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 "\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (if data (insert data))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 (current-buffer))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 (provide 'url-misc)
|
54699
|
116
|
|
117 ;;; arch-tag: 8c544e1b-d8bc-40a6-b319-f1f37fef65a0
|