5b4e891e522079b00eac99140b28db1f6509d97d
[riece] / lisp / riece-rdcc.el
1 ;;; riece-rdcc.el --- ruby implementation of DCC add-on
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 ;;; Code:
25
26 (require 'riece-globals)
27 (require 'riece-misc)
28 (require 'riece-channel)
29 (require 'riece-identity)
30 (require 'riece-ctcp)                   ;for riece-ctcp-additional-clientinfo
31
32 (defgroup riece-rdcc nil
33   "DCC implementation using ruby"
34   :prefix "riece-"
35   :group 'riece)
36
37 (defcustom riece-rdcc-server-address nil
38   "Local address of the DCC server.
39 Only used for sending files."
40   :type 'string
41   :group 'riece-rdcc)
42
43 (defcustom riece-rdcc-ruby-command "ruby"
44   "Command name for Ruby interpreter."
45   :type 'string
46   :group 'riece-rdcc)
47
48 (defcustom riece-rdcc-send-program
49   '("\
50 address = " address "
51 unless address
52   sock = UDPSocket.new
53   sock.connect('164.46.176.4', 7)               # www.unixuser.org/echo
54   address = sock.getsockname[4 .. 7].unpack('CCCC').join('.')
55 end
56 server = TCPServer.new(address, 0)
57 puts(\"#{server.addr[3].split(/\\./).collect{|c| c.to_i}.pack('CCCC').unpack('N')[0]} #{server.addr[1]}\")
58 session = server.accept
59 if session
60   total = 0
61   File.open(" file ") {|file|
62     while (bytes = file.read(4096))
63       total += bytes.length
64       puts(\"#{total}\")
65       session.write(bytes)
66     end
67   }
68   session.close
69 end
70 ")
71   "Ruby program to send file with DCC."
72   :type 'list
73   :group 'riece-rdcc)
74
75 (defcustom riece-rdcc-decode-address-program
76   '("\
77 puts(\"#{" address " >> 24 & 0xFF}.#{" address " >> 16 & 0xFF}.#{"
78     address " >> 8 & 0xFF}.#{" address " & 0xFF}\")")
79   "Ruby program to numeric IP address."
80   :type 'list
81   :group 'riece-rdcc)
82
83 (defvar riece-rdcc-requests nil)
84
85 (defvar riece-rdcc-request-user nil)
86 (defvar riece-rdcc-request-file nil)
87 (defvar riece-rdcc-request-size nil)
88
89 (defvar jka-compr-compression-info-list)
90 (defvar jam-zcat-filename-list)
91 (defun riece-rdcc-substitute-variables (program variable value)
92   (setq program (copy-sequence program))
93   (let ((pointer program))
94     (while pointer
95       (setq pointer (memq variable program))
96       (if pointer
97 &