url-about.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; url-about.el --- Show internal URLs
  2. ;; Copyright (C) 2001, 2004-2012 Free Software Foundation, Inc.
  3. ;; Keywords: comm, data, processes, hypermedia
  4. ;; This file is part of GNU Emacs.
  5. ;;
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. (require 'url-util)
  19. (require 'url-parse)
  20. (defun url-probe-protocols ()
  21. "Return a list of all potential URL schemes."
  22. (or (get 'url-extension-protocols 'probed)
  23. (mapc (lambda (s) (url-scheme-get-property s 'name))
  24. (or (get 'url-extension-protocols 'schemes)
  25. (let ((schemes '("info" "man" "rlogin" "telnet"
  26. "tn3270" "data" "snews")))
  27. (mapc (lambda (d)
  28. (mapc (lambda (f)
  29. (if (string-match "url-\\(.*\\).el$" f)
  30. (push (match-string 1 f) schemes)))
  31. (directory-files d nil "^url-.*\\.el$")))
  32. load-path)
  33. (put 'url-extension-protocols 'schemes schemes)
  34. schemes)))))
  35. (defvar url-scheme-registry)
  36. (defun url-about-protocols (url)
  37. (url-probe-protocols)
  38. (insert "<html>\n"
  39. " <head>\n"
  40. " <title>Supported Protocols</title>\n"
  41. " </head>\n"
  42. " <body>\n"
  43. " <h1>Supported Protocols - URL v" url-version "</h1>\n"
  44. " <table width='100%' border='1'>\n"
  45. " <tr>\n"
  46. " <td>Protocol\n"
  47. " <td>Properties\n"
  48. " <td>Description\n"
  49. " </tr>\n")
  50. (mapc (lambda (k)
  51. (if (string= k "proxy")
  52. ;; Ignore the proxy setting... its magic!
  53. nil
  54. (insert " <tr>\n")
  55. ;; The name of the protocol
  56. (insert " <td valign=top>" (or (url-scheme-get-property k 'name) k) "\n")
  57. ;; Now the properties. Currently just asynchronous
  58. ;; status, default port number, and proxy status.
  59. (insert " <td valign=top>"
  60. (if (url-scheme-get-property k 'asynchronous-p) "As" "S")
  61. "ynchronous<br>\n"
  62. (if (url-scheme-get-property k 'default-port)
  63. (format "Default Port: %d<br>\n"
  64. (url-scheme-get-property k 'default-port)) "")
  65. (if (assoc k url-proxy-services)
  66. (format "Proxy: %s<br>\n" (assoc k url-proxy-services)) ""))
  67. ;; Now the description...
  68. (insert " <td valign=top>"
  69. (or (url-scheme-get-property k 'description) "N/A"))))
  70. (sort (let (x) (maphash (lambda (k v) (push k x)) url-scheme-registry) x) 'string-lessp))
  71. (insert " </table>\n"
  72. " </body>\n"
  73. "</html>\n"))
  74. (defun url-about (url)
  75. "Show internal URLs."
  76. (let* ((item (downcase (url-filename url)))
  77. (func (intern (format "url-about-%s" item))))
  78. (if (fboundp func)
  79. (progn
  80. (set-buffer (generate-new-buffer " *about-data*"))
  81. (insert "Content-type: text/plain\n\n")
  82. (funcall func url)
  83. (current-buffer))
  84. (error "URL does not know about `%s'" item))))
  85. (provide 'url-about)
  86. ;;; url-about.el ends here