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