| 1 | ;;; url-about.el --- Show internal URLs |
| 2 | |
| 3 | ;; Copyright (C) 2001, 2004-2012 Free Software Foundation, Inc. |
| 4 | |
| 5 | ;; Keywords: comm, data, processes, hypermedia |
| 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 | ;;; Commentary: |
| 23 | |
| 24 | ;;; Code: |
| 25 | |
| 26 | (require 'url-util) |
| 27 | (require 'url-parse) |
| 28 | |
| 29 | (defun url-probe-protocols () |
| 30 | "Return a list of all potential URL schemes." |
| 31 | (or (get 'url-extension-protocols 'probed) |
| 32 | (mapc (lambda (s) (url-scheme-get-property s 'name)) |
| 33 | (or (get 'url-extension-protocols 'schemes) |
| 34 | (let ((schemes '("info" "man" "rlogin" "telnet" |
| 35 | "tn3270" "data" "snews"))) |
| 36 | (mapc (lambda (d) |
| 37 | (mapc (lambda (f) |
| 38 | (if (string-match "url-\\(.*\\).el$" f) |
| 39 | (push (match-string 1 f) schemes))) |
| 40 | (directory-files d nil "^url-.*\\.el$"))) |
| 41 | load-path) |
| 42 | (put 'url-extension-protocols 'schemes schemes) |
| 43 | schemes))))) |
| 44 | |
| 45 | (defvar url-scheme-registry) |
| 46 | |
| 47 | (defun url-about-protocols (url) |
| 48 | (url-probe-protocols) |
| 49 | (insert "<html>\n" |
| 50 | " <head>\n" |
| 51 | " <title>Supported Protocols</title>\n" |
| 52 | " </head>\n" |
| 53 | " <body>\n" |
| 54 | " <h1>Supported Protocols - URL v" url-version "</h1>\n" |
| 55 | " <table width='100%' border='1'>\n" |
| 56 | " <tr>\n" |
| 57 | " <td>Protocol\n" |
| 58 | " <td>Properties\n" |
| 59 | " <td>Description\n" |
| 60 | " </tr>\n") |
| 61 | (mapc (lambda (k) |
| 62 | (if (string= k "proxy") |
| 63 | ;; Ignore the proxy setting... its magic! |
| 64 | nil |
| 65 | (insert " <tr>\n") |
| 66 | ;; The name of the protocol |
| 67 | (insert " <td valign=top>" (or (url-scheme-get-property k 'name) k) "\n") |
| 68 | |
| 69 | ;; Now the properties. Currently just asynchronous |
| 70 | ;; status, default port number, and proxy status. |
| 71 | (insert " <td valign=top>" |
| 72 | (if (url-scheme-get-property k 'asynchronous-p) "As" "S") |
| 73 | "ynchronous<br>\n" |
| 74 | (if (url-scheme-get-property k 'default-port) |
| 75 | (format "Default Port: %d<br>\n" |
| 76 | (url-scheme-get-property k 'default-port)) "") |
| 77 | (if (assoc k url-proxy-services) |
| 78 | (format "Proxy: %s<br>\n" (assoc k url-proxy-services)) "")) |
| 79 | ;; Now the description... |
| 80 | (insert " <td valign=top>" |
| 81 | (or (url-scheme-get-property k 'description) "N/A")))) |
| 82 | (sort (let (x) (maphash (lambda (k v) (push k x)) url-scheme-registry) x) 'string-lessp)) |
| 83 | (insert " </table>\n" |
| 84 | " </body>\n" |
| 85 | "</html>\n")) |
| 86 | |
| 87 | (defun url-about (url) |
| 88 | "Show internal URLs." |
| 89 | (let* ((item (downcase (url-filename url))) |
| 90 | (func (intern (format "url-about-%s" item)))) |
| 91 | (if (fboundp func) |
| 92 | (progn |
| 93 | (set-buffer (generate-new-buffer " *about-data*")) |
| 94 | (insert "Content-type: text/plain\n\n") |
| 95 | (funcall func url) |
| 96 | (current-buffer)) |
| 97 | (error "URL does not know about `%s'" item)))) |
| 98 | |
| 99 | (provide 'url-about) |
| 100 | |
| 101 | ;;; url-about.el ends here |