url-irc.el 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ;;; url-irc.el --- IRC URL interface
  2. ;; Copyright (C) 1996-1999, 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. ;;; Commentary:
  16. ;; IRC URLs are defined in
  17. ;; http://www.w3.org/Addressing/draft-mirashi-url-irc-01.txt
  18. ;;; Code:
  19. (require 'url-vars)
  20. (require 'url-parse)
  21. (defconst url-irc-default-port 6667 "Default port for IRC connections.")
  22. (defcustom url-irc-function 'url-irc-rcirc
  23. "Function to actually open an IRC connection.
  24. The function should take the following arguments:
  25. HOST - the hostname of the IRC server to contact
  26. PORT - the port number of the IRC server to contact
  27. CHANNEL - What channel on the server to visit right away (can be nil)
  28. USER - What username to use
  29. PASSWORD - What password to use"
  30. :type '(choice (const :tag "rcirc" :value url-irc-rcirc)
  31. (const :tag "ERC" :value url-irc-erc)
  32. (const :tag "ZEN IRC" :value url-irc-zenirc)
  33. (function :tag "Other"))
  34. :group 'url)
  35. ;; External.
  36. (declare-function zenirc "ext:zenirc" (&optional prefix))
  37. (declare-function zenirc-send-line "ext:zenirc" ())
  38. (defun url-irc-zenirc (host port channel user password)
  39. (let ((zenirc-buffer-name (if (and user host port)
  40. (format "%s@%s:%d" user host port)
  41. (format "%s:%d" host port)))
  42. (zenirc-server-alist
  43. (list
  44. (list host port password nil user))))
  45. (zenirc)
  46. (goto-char (point-max))
  47. (if (not channel)
  48. nil
  49. (insert "/join " channel)
  50. (zenirc-send-line))))
  51. (defun url-irc-rcirc (host port channel user password)
  52. (let ((chan (when channel (concat "#" channel))))
  53. (rcirc-connect host port user nil nil (when chan (list chan)))
  54. (when chan
  55. (switch-to-buffer (concat chan "@" host)))))
  56. (defun url-irc-erc (host port channel user password)
  57. (erc-handle-irc-url host port channel user password))
  58. ;;;###autoload
  59. (defun url-irc (url)
  60. (let* ((host (url-host url))
  61. (port (url-port url))
  62. (pass (url-password url))
  63. (user (url-user url))
  64. (chan (url-filename url)))
  65. (if (url-target url)
  66. (setq chan (concat chan "#" (url-target url))))
  67. (if (string-match "^/" chan)
  68. (setq chan (substring chan 1 nil)))
  69. (if (= (length chan) 0)
  70. (setq chan nil))
  71. (funcall url-irc-function host port chan user pass)
  72. nil))
  73. (provide 'url-irc)
  74. ;;; url-irc.el ends here