Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-57
[bpt/emacs.git] / lisp / url / url-irc.el
1 ;;; url-irc.el --- IRC URL interface
2 ;; Keywords: comm, data, processes
3
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
6 ;;;
7 ;;; This file is part of GNU Emacs.
8 ;;;
9 ;;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;;; it under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 2, or (at your option)
12 ;;; any later version.
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
20 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;;; Boston, MA 02111-1307, USA.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
25 ;;; IRC URLs are defined in http://www.w3.org/Addressing/draft-mirashi-url-irc-01.txt
26
27 (require 'url-vars)
28 (require 'url-parse)
29
30 (defconst url-irc-default-port 6667 "Default port for IRC connections")
31
32 (defcustom url-irc-function 'url-irc-zenirc
33 "*Function to actually open an IRC connection.
34 Should be a function that takes several argument:
35 HOST - the hostname of the IRC server to contact
36 PORT - the port number of the IRC server to contact
37 CHANNEL - What channel on the server to visit right away (can be nil)
38 USER - What username to use
39 PASSWORD - What password to use"
40 :type '(choice (const :tag "ZEN IRC" :value 'url-irc-zenirc)
41 (function :tag "Other"))
42 :group 'url)
43
44 (defun url-irc-zenirc (host port channel user password)
45 (let ((zenirc-buffer-name (if (and user host port)
46 (format "%s@%s:%d" user host port)
47 (format "%s:%d" host port)))
48 (zenirc-server-alist
49 (list
50 (list host port password nil user))))
51 (zenirc)
52 (goto-char (point-max))
53 (if (not channel)
54 nil
55 (insert "/join " channel)
56 (zenirc-send-line))))
57
58 ;;;###autoload
59 (defun url-irc (url)
60 (let* ((host (url-host url))
61 (port (string-to-int (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
74 (provide 'url-irc)
75
76 ;;; arch-tag: 2e5eecf8-9eb3-436b-9fbd-c26f2fb2bf3e