1 ;;; riece-async.el --- connect to IRC server via asynchronous proxy
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
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)
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.
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.
26 ;; This program allows to connect to an IRC server via local proxy
27 ;; which responds to PING requests from server.
29 ;; To use, add the following line to your ~/.riece/init.el:
30 ;; (add-to-list 'riece-addons 'riece-async)
32 ;; If you want to enable this feature per server, write the server
34 ;; (add-to-list 'riece-server-alist
35 ;; '("async" :host "irc.tokyo.wide.ad.jp"
36 ;; :function riece-async-open-network-stream))
40 (defgroup riece-async nil
41 "Connect to IRC server via asynchronous proxy"
45 (defcustom riece-async-ruby-command "ruby"
46 "Command name for Ruby interpreter."
50 (defcustom riece-async-server-program
53 socket = TCPSocket.new(" host ", " service ")
54 $stdout.write(\"NOTICE CONNECTED #{$$}\\r\\n\")
56 $stdout.nonblock = true
57 trap('STOP', 'IGNORE')
58 trap('TSTP', 'IGNORE')
62 rfds, wfds, = select([socket, $stdin], wfds_in)
64 until buf.length <= " max-buffer-size "
65 i = buf.index(\"\\r\\n\")
67 buf.slice!(0 .. i + 1)
71 len = $stdout.syswrite(buf)
78 if rfds.include?(socket)
79 line = socket.gets(\"\\r\\n\")
81 if line =~ /^(?::[^ ]+ +)?PING +(.+)\\r\\n/i
82 socket.write(\"PONG #{$1}\\r\\n\")
89 if rfds.include?($stdin)
90 line = $stdin.gets(\"\\r\\n\")
98 "Ruby program of asynchronous proxy."
102 (defcustom riece-async-max-buffer-size 65535
103 "Maximum size of the write buffer."
107 (defun riece-async-substitute-variables (program variable value)
108 (setq program (copy-sequence program))
109 (let ((pointer program))
111 (setq pointer (memq variable program))
113 (setcar pointer value)))
117 (defun riece-async-open-network-stream (name buffer host service)
118 (let* ((process-connection-type nil)
119 (process (start-process name buffer "ruby" "-rsocket")))
120 (process-kill-without-query process)
121 (process-send-string process
123 (riece-async-substitute-variables
124 (riece-async-substitute-variables
125 (riece-async-substitute-variables
126 riece-async-server-program
128 (concat "'" host "'"))
130 (if (numberp service)
131 (number-to-string service)
132 (concat "'" service "'")))
135 riece-async-max-buffer-size))))
136 (process-send-string process "\0\n") ;input to process is needed
139 (set-buffer (process-buffer process))
140 (while (and (eq (process-status process) 'run)
142 (goto-char (point-min))
143 (not (looking-at (format "NOTICE CONNECTED %d"
144 (process-id process))))))
145 (accept-process-output process))))
148 (defun riece-async-insinuate ()
149 (setq riece-default-open-connection-function
150 #'riece-async-open-network-stream))
152 (provide 'riece-async)
154 ;;; riece-rdcc.el ends here