;;; pure-pr-server.el --- Peer-to-peer server process management for PURE ;; Copyright (C) 2000 Project Pure. ;; Author: SHIMADA Mitsunobu ;; Keywords: PURE, process, server, peer-to-peer, DCC CHAT ;; $Id: pure-pr-server.el,v 1.2 2001/04/30 15:08:56 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" ;; PR means "process" ;;; Code: (require 'pure-bl) (require 'pure-pr-filter) ;; now: for server only (defconst pure-pr-local-variables '([pure-pr-parser-function nil "Parser function for `pure-pr-filter-loop'."] [pure-pr-my-addr nil "IP address of mine."] [pure-pr-my-port nil "Port number of mine."] [pure-pr-listen-args nil "Received argument when listen."]) "List of buffer-local variables for PURE process management.") (defconst pure-pr-server-local-variables '([pure-pr-server-listen-function nil "Function called when server process is ready to listen to."] [pure-pr-server-connect-function nil "Function called when server process is ready to communicate with."]) "List of buffer-local variables for PURE server process.") (defvar pure-pr-server-exec-file "puresv" "Executable file name fore PURE server process.") (defun pure-pr-server-listen (name &optional buffer exec host bport eport) "Prepare TCP server connection." (let (proc (file (or exec pure-pr-server-exec-file))) (setq proc (cond (eport (start-process name buffer file host bport eport)) (bport (start-process name buffer file host bport bport)) (host (start-process name buffer file host)) (t (start-process name buffer file)))) (save-excursion (set-buffer (process-buffer proc)) (pure-bl-defvar pure-pr-local-variables) (pure-bl-defvar pure-pr-server-local-variables) (pure-bl-make-current pure-pr-local-variables) (pure-bl-make-current pure-pr-server-local-variables) (if proc (pure-pr-filter-set-filter proc 'pure-pr-server-parser))) proc)) (defun pure-pr-server-set-functions (proc listen connect parser) "Set functions for PURE server process. First argument `proc' is the target process. This function sets `listen' into `pure-pr-server-listen-function', `connect' into `pure-pr-server-connect-function', and `parser' into `pure-pr-parser-function'. Parser function is used after connection established. This function is called after `pure-pr-server-listen' is called." (save-excursion (set-buffer (process-buffer proc)) (setq pure-pr-server-listen-function listen pure-pr-server-connect-function connect pure-pr-parser-function parser))) (defun pure-pr-server-parser (proc) "Body of filter function for PURE server process." (cond ((looking-at "\\[INFO\\] Listen \\([^ ]+\\) \\([^ ]+\\)") (setq pure-pr-my-addr (buffer-substring (match-beginning 1) (match-end 1)) pure-pr-my-port (buffer-substring (match-beginning 2) (match-end 2))) (goto-char (match-end 0)) (if (eolp) nil (skip-chars-forward " ") (looking-at "[^ ]*") (setq pure-pr-listen-args (buffer-substring (match-beginning 0) (match-end 0)))) (if (fboundp pure-pr-server-listen-function) (funcall pure-pr-server-listen-function proc))) ((looking-at "\\[INFO\\] connected") (pure-pr-filter-set-parser proc pure-pr-parser-function) (if (fboundp pure-pr-server-connect-function) (funcall pure-pr-server-connect-function proc))))) ;; That's all (provide 'pure-pr-server) ;;; pure-pr-server.el ends here