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