* riece-async.el (riece-async-open-network-stream): Locate Ruby
[riece] / lisp / riece-async.el
1 ;;; riece-async.el --- connect to IRC server via async proxy
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
9 ;; This program 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 ;; This program 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 ;;; Commentary:
25
26 ;; This program allows to connect to an IRC server via local proxy
27 ;; which responds to PING requests from server.
28
29 ;; To use, add the following line to your ~/.riece/init.el:
30 ;; (add-to-list 'riece-addons 'riece-async)
31
32 ;; If you want to enable this feature per server, write the server
33 ;; spec like this:
34 ;; (add-to-list 'riece-server-alist
35 ;;              '("async" :host "irc.tokyo.wide.ad.jp"
36 ;;                :function riece-async-open-network-stream))
37
38 ;;; Code:
39
40 (require 'riece-options)
41
42 (defgroup riece-async nil
43   "Connect to IRC server via asynchronous proxy"
44   :prefix "riece-"
45   :group 'riece)
46
47 (defcustom riece-async-buffer-size 65535
48   "Maximum size of the write buffer."
49   :type 'integer
50   :group 'riece-async)
51
52 (defcustom riece-async-backup-file (expand-file-name "riece-async.bak"
53                                                      riece-directory)
54   "A file which contains outdated messages."
55   :type 'string
56   :group 'riece-async)
57
58 (defvar riece-async-server-program "aproxy.rb"
59   "The server program file.  If the filename is not absolute, it is
60 assumed that the file is in the same directory of this file.")
61
62 (defvar riece-async-server-program-arguments
63   (list "-s" riece-async-buffer-size
64         "-b" riece-async-backup-file)
65   "Command line arguments passed to `riece-async-server-program'.")
66
67 (defconst riece-async-description
68   "Keep IRC connection with external process")
69
70 ;;;###autoload
71 (defun riece-async-open-network-stream (name buffer host service)
72   (let* (process-connection-type
73          (process
74           (apply #'start-process name buffer riece-ruby-command
75                  (expand-file-name riece-async-server-program
76                                    riece-data-directory)
77                  riece-async-server-program-arguments)))
78     (if buffer
79         (save-excursion
80           (set-buffer (process-buffer process))
81           (while (and (eq (process-status process) 'run)
82                       (progn
83                         (goto-char (point-min))
84                         (not (looking-at (format "NOTICE CONNECTED %d"
85                                                  (process-id process))))))
86             (accept-process-output process))))
87     (process-kill-without-query process)
88     process))
89
90 (defun riece-async-insinuate ()
91   (setq riece-default-open-connection-function
92         #'riece-async-open-network-stream))
93
94 (provide 'riece-async)
95
96 ;;; riece-async.el ends here