]> code.delx.au - gnu-emacs/blob - lisp/url/url-irc.el
30ab437d5c192271db778256fc0c689a32cc6697
[gnu-emacs] / lisp / url / url-irc.el
1 ;;; url-irc.el --- IRC URL interface
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009, 2010, 2011 Free Software Foundation, Inc.
5
6 ;; Keywords: comm, data, processes
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; IRC URLs are defined in
26 ;; http://www.w3.org/Addressing/draft-mirashi-url-irc-01.txt
27
28 ;;; Code:
29
30 (require 'url-vars)
31 (require 'url-parse)
32
33 (defconst url-irc-default-port 6667 "Default port for IRC connections.")
34
35 (defcustom url-irc-function 'url-irc-rcirc
36 "Function to actually open an IRC connection.
37 The function should take the following arguments:
38 HOST - the hostname of the IRC server to contact
39 PORT - the port number of the IRC server to contact
40 CHANNEL - What channel on the server to visit right away (can be nil)
41 USER - What username to use
42 PASSWORD - What password to use"
43 :type '(choice (const :tag "rcirc" :value url-irc-rcirc)
44 (const :tag "ERC" :value url-irc-erc)
45 (const :tag "ZEN IRC" :value url-irc-zenirc)
46 (function :tag "Other"))
47 :group 'url)
48
49 ;; External.
50 (declare-function zenirc "ext:zenirc" (&optional prefix))
51 (declare-function zenirc-send-line "ext:zenirc" ())
52
53 (defun url-irc-zenirc (host port channel user password)
54 (let ((zenirc-buffer-name (if (and user host port)
55 (format "%s@%s:%d" user host port)
56 (format "%s:%d" host port)))
57 (zenirc-server-alist
58 (list
59 (list host port password nil user))))
60 (zenirc)
61 (goto-char (point-max))
62 (if (not channel)
63 nil
64 (insert "/join " channel)
65 (zenirc-send-line))))
66
67 (defun url-irc-rcirc (host port channel user password)
68 (let ((chan (when channel (concat "#" channel))))
69 (rcirc-connect host port user nil nil (when chan (list chan)))
70 (when chan
71 (switch-to-buffer (concat chan "@" host)))))
72
73 (defun url-irc-erc (host port channel user password)
74 (erc-handle-irc-url host port channel user password))
75
76 ;;;###autoload
77 (defun url-irc (url)
78 (let* ((host (url-host url))
79 (port (url-port url))
80 (pass (url-password url))
81 (user (url-user url))
82 (chan (url-filename url)))
83 (if (url-target url)
84 (setq chan (concat chan "#" (url-target url))))
85 (if (string-match "^/" chan)
86 (setq chan (substring chan 1 nil)))
87 (if (= (length chan) 0)
88 (setq chan nil))
89 (funcall url-irc-function host port chan user pass)
90 nil))
91
92 (provide 'url-irc)
93
94 ;;; url-irc.el ends here