url-misc.el 3.5 KB

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