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