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