;;; pure-pr-dcc-pure.el --- Interface for dccget/dccput/puresv for PURE-IRC ;; Copyright (C) 2001 Project Pure. ;; Author: SHIMADA Mitsunobu ;; Keywords: PURE, IRC, process, DCC, puresv, dccget, dccput ;; $Id: pure-pr-dcc-pure.el,v 1.1 2001/04/30 15:12:36 simm Exp $ ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; PURE means "Primitive Universal Relay-chat Environment" ;;; Code: (require 'pure-generic) (require 'pure-pr-ipaddr) (require 'pure-pr-filter) (require 'pure-pr-server) (require 'pure-irc-dcc-info) (defvar pure-pr-dcc-pure-dccput-program "dccput" "Filename of DCC file put program.") (defvar pure-pr-dcc-pure-dccget-program "dccget" "Filename of DCC file get program.") ;; start DCC CHAT server process (defun pure-pr-dcc-pure-start-chat-server (dinfo &optional resume) "Start DCC CHAT server via PURESV binary." (let ((proc (pure-pr-server-listen pure-pr-server-exec-file (pure-irc-dcc-info-get-buffer dinfo) pure-pr-server-exec-file (pure-irc-dcc-info-get-host dinfo) (pure-irc-dcc-info-get-port dinfo)))) (if proc (pure-pr-server-set-functions proc 'pure-irc-dcc-chat-listen 'pure-irc-dcc-chat-connect 'pure-irc-dcc-chat-parser)) proc)) ;; start DCC CHAT client process (defun pure-pr-dcc-pure-start-chat-client (dinfo &optional resume) "Start DCC CHAT client via `open-network-stream'" (let ((proc (open-network-stream "dccchat" (pure-irc-dcc-info-get-buffer dinfo) (pure-pr-ipaddr-decode (pure-irc-dcc-info-get-host dinfo)) (string-to-number (pure-irc-dcc-info-get-port dinfo))))) (when proc (pure-ds-del-list dinfo pure-irc-dcc-offer-list) (pure-cs-set-noconv-process proc) (pure-pr-filter-set-filter proc 'pure-irc-dcc-chat-parser)) proc)) ;; start DCC SEND server process (defun pure-pr-dcc-pure-start-file-server (dinfo &optional resume) "Start DCCPUT process." (let ((proc (start-process pure-pr-dcc-pure-dccput-program (pure-irc-dcc-info-get-buffer dinfo) pure-pr-dcc-pure-dccput-program (pure-irc-dcc-info-get-file dinfo)))) (if proc (pure-pr-filter-set-filter proc 'pure-pr-dcc-pure-parser-dccput)) proc)) ;; start DCC FILE get process (defun pure-pr-dcc-pure-start-file-client (dinfo &optional resume) "Start DCCGET process." (let ((proc (start-process pure-pr-dcc-pure-dccget-program (pure-irc-dcc-info-get-buffer dinfo) pure-pr-dcc-pure-dccget-program (pure-irc-dcc-info-get-file dinfo) (pure-irc-dcc-info-get-host dinfo) (pure-irc-dcc-info-get-port dinfo) (pure-irc-dcc-info-get-size dinfo) (prin1-to-string resume)))) (if proc (pure-pr-filter-set-filter proc 'pure-pr-dcc-pure-parser-dccget)) proc)) ;; ;; DCC RESUME operation ;; ;; check whether DCC RESUME enable: when method is 'pure, always returns t (defun pure-pr-dcc-pure-resumep (dinfo) "Check DCC RESUME feature (always t)" t) ;; Accept DCC RESUME request (defun pure-pr-dcc-pure-resume-accept (dinfo) "Accept DCC RESUME request" (pure-irc-dcc-info-resume-accept dinfo)) ;; Start DCC RESUME client process (defun pure-pr-dcc-pure-resume-start (dinfo) "Start DCC RESUME client process" (process-send-string (pure-irc-dcc-info-get-proc dinfo) "t\n")) ;; ;; Parser functions ;; ;; parser for dccget (defun pure-pr-dcc-pure-parser-dccget (proc) "DCC parser function for dccget process." (cond ((looking-at "\\[INFO\\] OFFSET \\([^ ]+\\)") (let ((pos (buffer-substring (match-beginning 1) (match-end 1)))) (if (string= "0" pos) (process-send-string proc "t\n") (pure-irc-dcc-info-put-xpos pure-irc-dcc-info pos) (pure-irc-dcc-info-resume-request pure-irc-dcc-info)))) ((looking-at "\\[INFO\\] Connected") (funcall pure-irc-dcc-log-interface "dccget from %s established (%s, %s bytes)" (pure-irc-dcc-info-get-nick pure-irc-dcc-info) (pure-irc-dcc-info-get-file pure-irc-dcc-info) (pure-irc-dcc-info-get-size pure-irc-dcc-info)) (pure-irc-dcc-info-put-status pure-irc-dcc-info 'client)) ((looking-at "\\[REPORT\\] \\([^ ]+\\) \\([^ ]+\\)") (message "[DCC REPORT] %s / %s bytes (%s%%)" (buffer-substring (match-beginning 2) (match-end 2)) (pure-irc-dcc-info-get-size pure-irc-dcc-info) (buffer-substring (match-beginning 1) (match-end 1)))) ((looking-at "\\[ERROR\\] ") (funcall pure-irc-dcc-log-interface "%s ERROR: %s" pure-pr-dcc-pure-dccget-program (buffer-substring (match-end 0) (point-max)))) (t (funcall pure-irc-dcc-log-interface "%s UNKNOWN MESSAGE: %s" pure-pr-dcc-pure-dccget-program (buffer-substring (point-min) (point-max)))))) ;; parser for dccput (defun pure-pr-dcc-pure-parser-dccput (proc) "DCC parser function for dccput process." (cond ((looking-at "\\[INFO\\] Listen \\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\)") (pure-irc-dcc-info-send-server-info pure-irc-dcc-info (pure-pr-ipaddr-encode (buffer-substring (match-beginning 1) (match-end 1))) (buffer-substring (match-beginning 2) (match-end 2)) (buffer-substring (match-beginning 3) (match-end 3)))) ((looking-at "\\[INFO\\] Connected") (process-send-string proc (format "OFFSET %s\n" (or (pure-irc-dcc-info-get-xpos pure-irc-dcc-info) "0"))) (funcall pure-irc-dcc-log-interface "dccput to %s established (%s, %s bytes)" (pure-irc-dcc-info-get-nick pure-irc-dcc-info) (pure-irc-dcc-info-get-file pure-irc-dcc-info) (pure-irc-dcc-info-get-size pure-irc-dcc-info)) (pure-irc-dcc-info-put-status pure-irc-dcc-info 'server)) ((looking-at "\\[INFO\\] Offset \\([^ ]+\\)")) ((looking-at "\\[REPORT\\] \\([^ ]+\\) \\([^ ]+\\)") (message "[DCC REPORT] %s / %s bytes (%s%%)" (buffer-substring (match-beginning 2) (match-end 2)) (pure-irc-dcc-info-get-size pure-irc-dcc-info) (buffer-substring (match-beginning 1) (match-end 1)))) ((looking-at "\\[ERROR\\] ") (funcall pure-irc-dcc-log-interface "%s ERROR: %s" pure-pr-dcc-pure-dccput-program (buffer-substring (match-end 0) (point-max)))) (t (funcall pure-irc-dcc-log-interface "%s UNKNOWN MESSAGE: %s" pure-pr-dcc-pure-dccput-program (buffer-substring (point-min) (point-max)))))) ;; That's all (provide 'pure-pr-dcc-pure) ;;; pure-pr-dcc-pure.el ends here