diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/iiimcf-comp.el IIIMECF-0.6-newproto/iiimcf-comp.el --- IIIMECF-0.6/iiimcf-comp.el 2002-07-08 18:45:48.000000000 +0900 +++ IIIMECF-0.6-newproto/iiimcf-comp.el 2007-12-09 14:03:02.000000000 +0900 @@ -34,7 +34,8 @@ ;; Check Mule-UCS -(while (null (locate-library "un-define")) +(while (and (null (locate-library "un-define")) + (not (eq (make-char 'latin-iso8859-1 160) 160))) (progn (message "I cannot find Mule-UCS.") (message "Please type the path where Mule-UCS is installed.") diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/lisp/EIMIL.el IIIMECF-0.6-newproto/lisp/EIMIL.el --- IIIMECF-0.6/lisp/EIMIL.el 2002-07-08 18:46:43.000000000 +0900 +++ IIIMECF-0.6-newproto/lisp/EIMIL.el 2007-12-09 13:54:36.000000000 +0900 @@ -48,7 +48,7 @@ ;;; Code: -(require 'un-define) +(require 'iiimp) (defvar EIMIL-cache-directory "~/.eimil") @@ -137,7 +137,7 @@ (EIMIL-check-symbol-syntax str) (if (or (intern-soft str (EIMIL-pubobarray eobj)) (intern-soft str (EIMIL-privobarray eobj))) - (error "Symbol:%s has already been registered.") + (error "Symbol:%s has already been registered." str) (if publicp (let ((sym (intern str (EIMIL-pubobarray eobj)))) (put sym 'EIMIL-category category) @@ -171,7 +171,7 @@ (if sym (if (not (eq (EIMIL-symbol-category sym) category)) (error "Symbol %s is already registered as different catgory. %S %S" - (EIMIL-symbol-category sym) category)) + sym (EIMIL-symbol-category sym) category)) (if publicp (progn (setq sym (intern str (EIMIL-pubobarray eobj))) @@ -351,7 +351,7 @@ (if (EIMIL-engine-name neobj) (symbol-value (or (EIMIL-intern-soft neobj (EIMIL-engine-name neobj)) - (error "Internal error(fail to find the corresponding engine." + (error "Internal error(fail to find the corresponding engine.): %s" (EIMIL-engine-name neobj)))) neobj))) diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/lisp/iiimcf.el IIIMECF-0.6-newproto/lisp/iiimcf.el --- IIIMECF-0.6/lisp/iiimcf.el 2002-07-15 20:18:05.000000000 +0900 +++ IIIMECF-0.6-newproto/lisp/iiimcf.el 2007-12-09 13:56:10.000000000 +0900 @@ -32,6 +32,7 @@ ;;; Code: +(eval-and-compile (require 'cl)) (require 'iiimp) ;;; version. @@ -1100,9 +1101,9 @@ ;;; create/delete handles ;;; -(defun iiimcf-connect-com (host port) +(defun iiimcf-connect-com (proto host port) (let ((com-id - (iiimp-create-network-channel host port))) + (iiimp-create-network-channel proto host port))) (iiimcf-register-com-id com-id) com-id)) @@ -1124,9 +1125,9 @@ (list 'iiimp-im-connect-reply com-id)))) (setq im-id (iiimp-message-im-id mes)) (iiimcf-register-im-id im-id) - (if client-descriptor - (iiimcf-send-client-descriptor - com-id im-id client-descriptor)) +; (if client-descriptor +; (iiimcf-send-client-descriptor +; com-id im-id client-descriptor)) im-id)) (defun iiimcf-disconnect-im (im-id) diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/lisp/iiimcf-sc.el IIIMECF-0.6-newproto/lisp/iiimcf-sc.el --- IIIMECF-0.6/lisp/iiimcf-sc.el 2002-07-15 20:18:05.000000000 +0900 +++ IIIMECF-0.6-newproto/lisp/iiimcf-sc.el 2007-12-09 13:44:50.000000000 +0900 @@ -46,7 +46,7 @@ :tag "Default port for IIIMCF Server Control" :group 'iiimcf-server-control :type 'integer) -(defcustom iiimcf-server-control-hostlist '("localhost") +(defcustom iiimcf-server-control-hostlist (list (concat "/tmp/.iiim-" (user-login-name) "/:1.0")) "*A list of IIIM Server hosts. If each hostname has the form of \"HOSTNAME:N\", use N-th port." :tag "Hostlist for IIIMCF Server Control" @@ -178,13 +178,21 @@ ;;; (defun iiimcf-server-control-parse-hostname (hostname) - (if (string-match ":" hostname) - (list - (substring hostname 0 (match-beginning 0)) - (string-to-number (substring hostname (match-end 0)))) - (list - hostname - iiimcf-server-control-default-port))) + (let (proto host port) + (if (string-match + (concat "^\\(?:\\(tcp:\\)?\\([a-zA-Z0-9\.-]+\\)\\(:[0-9]+\\)\\)\\|" + "\\(?:\\(unix:\\)?\\([a-zA-Z0-9\./:-]+\\)\\)$") hostname) + (progn + (if (match-string 2) + (setq proto "tcp" + host (match-string 2 hostname) + port (match-string 3 hostname) + port (if (null port) iiimcf-server-control-default-port + (string-to-number (substring port 1)))) + (setq proto "unix" + host (match-string 5 hostname))) + (list proto host port)) + (error "server name %s is not valid!" hostname)))) (defun iiimcf-server-control-setup-event-flow-mode (mes) (setq iiimcf-server-control-dynamic-event-flow-p t)) diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/lisp/iiimp.el IIIMECF-0.6-newproto/lisp/iiimp.el --- IIIMECF-0.6/lisp/iiimp.el 2002-07-15 20:18:13.000000000 +0900 +++ IIIMECF-0.6-newproto/lisp/iiimp.el 2007-12-09 14:06:29.000000000 +0900 @@ -68,6 +68,10 @@ (defvar iiimp-text-warning-char ?!) +(defvar iiimp-helper-path "udclient") + +(defvar iiimp-unixdomain-socket-path "/var/run/iiim/.iiimp-unix/") + (defconst iiimp-basic-opcode-spec-list '((iiimp-im-no-protocol 0 (nil . nil) @@ -301,15 +305,15 @@ ;; COM-ID := [ ] -(defun iiimp-construct-com-id (proc buf host port) +(defun iiimp-construct-com-id (proc buf proto host port) (let ((obuf (current-buffer))) (if (eq obuf buf) (setq iiimp-current-com-id - (vector proc buf host port (point-min))) + (vector proc buf proto host port (point-min))) (prog2 (set-buffer buf) (setq iiimp-current-com-id - (vector proc buf host port (point-min))) + (vector proc buf proto host port (point-min))) (set-buffer obuf))))) (defsubst iiimp-com-id-process (com-id) @@ -318,17 +322,20 @@ (defsubst iiimp-com-id-buffer (com-id) (aref com-id 1)) -(defsubst iiimp-com-id-host (com-id) +(defsubst iiimp-com-id-proto (com-id) (aref com-id 2)) -(defsubst iiimp-com-id-port (com-id) +(defsubst iiimp-com-id-host (com-id) (aref com-id 3)) -(defsubst iiimp-com-id-end-point (com-id) +(defsubst iiimp-com-id-port (com-id) (aref com-id 4)) +(defsubst iiimp-com-id-end-point (com-id) + (aref com-id 5)) + (defsubst iiimp-record-end-point (com-id pt) - (aset com-id 4 pt) + (aset com-id 5 pt) com-id) ;; IM-ID := (id._NUMBER_of_IM COM-ID) @@ -360,17 +367,17 @@ ;;; network I/O (defsubst iiimp-check-channel-connection (com-id) - (eq (process-status (iiimp-com-id-process com-id)) 'open)) - + (or (eq (process-status (iiimp-com-id-process com-id)) 'open) + (eq (process-status (iiimp-com-id-process com-id)) 'run))) + (defun iiimp-proc-to-com-id (proc) (let ((oldbuf (current-buffer)) (nbuf (process-buffer proc))) (if (not (eq oldbuf nbuf)) + (prog2 (set-buffer nbuf) - (prog1 iiimp-current-com-id - (if (not (eq oldbuf nbuf)) - (set-buffer nbuf))) + (set-buffer oldbuf)) iiimp-current-com-id))) (defun iiimp-network-sentinel (proc stat) @@ -381,7 +388,7 @@ (iiimp-disable-async-invocation com-id) (iiimp-connection-error "sentinel" com-id))))) -(defun iiimp-open-network-channel (host port buf) +(defun iiimp-open-network-channel (proto host port buf) (let ((coding-system-for-read nil) (coding-system-for-write nil) proc) @@ -391,23 +398,34 @@ (set-buffer-multibyte nil)) (buffer-disable-undo buf) (setq proc - (open-network-stream iiimp-process-name buf host port)) - (process-kill-without-query proc) + (cond ((string= proto "unix") + (if iiimp-helper-path + (let ((process-connection-type nil)) + (start-process + iiimp-process-name buf + iiimp-helper-path host)) + (make-network-process + :name iiimp-process-name :buffer buf :family 'local + :service host))) + (t (open-network-stream iiimp-process-name buf host port)))) + (process-kill-without-query proc) ;; obsolete since 21.1. + ;; (set-process-query-on-exit-flag proc nil) (set-process-coding-system proc 'binary 'binary) (set-process-sentinel proc (function iiimp-network-sentinel)) (set-marker-insertion-type (process-mark proc) t)) proc)) -(defun iiimp-create-network-channel (host port) +(defun iiimp-create-network-channel (proto host port) (let* ((buf (generate-new-buffer " *IIIMP*")) - (proc (iiimp-open-network-channel host port buf))) - (iiimp-construct-com-id proc buf host port))) + (proc (iiimp-open-network-channel proto host port buf))) + (iiimp-construct-com-id proc buf proto host port))) (defun iiimp-destroy-network-channel (com-id) (let* ((proc (iiimp-com-id-process com-id)) (stat (process-status proc))) - (while (not (or (eq stat 'closed) + (while (not (or (or (eq stat 'closed) + (eq stat 'exit)) (eq stat nil))) (set-process-sentinel proc nil) (delete-process proc) diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/util/Makefile IIIMECF-0.6-newproto/util/Makefile --- IIIMECF-0.6/util/Makefile 1970-01-01 09:00:00.000000000 +0900 +++ IIIMECF-0.6-newproto/util/Makefile 2007-12-09 13:41:24.000000000 +0900 @@ -0,0 +1,22 @@ +TARGET=udclient +SOURCE=udclient.c +INCLUDE=udclient.h + +prefix=/usr/local + +INSTALL=install +MKDIR=install -d + +all: build + +build:$(TARGET) + +$(TARGET): $(SOURCE) $(INCLUDE) + gcc -o $(TARGET) $(SOURCE) + +install: + $(MKDIR) ${prefix}/bin + $(INSTALL) -m 555 $(TARGET) ${prefix}/bin/${TARGET} + +clean: + $(RM) $(TARGET) diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/util/udclient.c IIIMECF-0.6-newproto/util/udclient.c --- IIIMECF-0.6/util/udclient.c 1970-01-01 09:00:00.000000000 +0900 +++ IIIMECF-0.6-newproto/util/udclient.c 2007-12-09 13:41:24.000000000 +0900 @@ -0,0 +1,150 @@ +/* udclient.c + * VERSION: 0.4 + * AUTHOR: miura@da-cha.org + * DATE: 2005.01.15 + * + * repeater to communicate with unix domain socket + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "udclient.h" + +#define BFSZ (4096) /* buffer size */ +#define DOMAIN "udclient" + +/* + * data transport routin + */ +static ssize_t ud_transport(int in, int out) +{ + char* buf = NULL; /* data buffer */ + ssize_t len = BFSZ; /* data length */ + int count = -1; /* read count */ + + /* read input */ + while (len == BFSZ) { + count++; + /* allocate data buffer */ + if ((buf = (char*)realloc(buf, (count + 1) * BFSZ)) == NULL) { + perror("realloc"); + exit(1); + } + /* read input to data buffer */ + if ((len = read(in, buf + count * BFSZ, BFSZ)) < 0) { + perror("read"); + exit(1); + } + } + len += count * BFSZ; + /* write output */ + if (len > 0 && write(out, buf, len) < 0) { + perror("write"); + exit(1); + } + /* destroy data buffer */ + free(buf); + return len; +} + +/* unix domain client routine */ +int ud_cli(FILE *in, FILE *out, int sockfd) +{ + int maxfd, in_eof; + fd_set rset; + + in_eof = 0; + FD_ZERO(&rset); + for ( ; ; ) { + if (in_eof == 0) { + FD_SET(fileno(in), &rset); + } + FD_SET(sockfd, &rset); + maxfd = max(fileno(in), sockfd) + 1; + select(maxfd, &rset, NULL, NULL, NULL); + + if (FD_ISSET(sockfd, &rset)) { /*socket is readable */ + if (ud_transport(sockfd, fileno(out)) == 0) { + if (in_eof == 1) { /* normal termination */ + return 0; + } else { + perror("ud_cli: server terminated prematurely"); + exit(1); + } + } + } + if (FD_ISSET(fileno(in), &rset)) { /* stdin is readable */ + if (ud_transport(fileno(in), sockfd) == 0) { + in_eof = 1; + shutdown(sockfd, SHUT_WR); /* send FIN */ + FD_CLR(fileno(in), &rset); + } + } + } + + /* NOREACH */ + return 1; +} + +static void print_help(void) +{ + printf("Usage: " DOMAIN " \n" + "Communication with server through unix domain socket.\n" + ); +} + +static int proc_opt(int argc, char *argv[]) +{ + if (argc != 2) + return 0; + + return 1; +} + +int main(int argc, char *argv[]) +{ + int sockfd; + int pathname; + struct sockaddr_un svaddr; + FILE *in, *out; + + if ((pathname = proc_opt(argc, argv)) == 0) { + print_help(); + exit(-1); + } + + in = stdin; out = stdout; + + /* create unix domain socket and connect server*/ + + bzero(&svaddr, sizeof(svaddr)); + svaddr.sun_family = AF_LOCAL; + strncpy(svaddr.sun_path, argv[pathname], sizeof(svaddr.sun_path) - 1); + + if ((sockfd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { + perror("socket"); + exit(-1); + } + if (connect(sockfd, (struct sockaddr*)&svaddr, SUN_LEN(&svaddr)) < 0) { + perror("connect"); + close(sockfd); + exit(-1); + } + + /* transport data */ + if (!ud_cli(in, out, sockfd)){ + close(sockfd); + exit(1); + } + + close(sockfd); + exit(0); +} diff -aurN -x '*~' -x '*.elc' IIIMECF-0.6/util/udclient.h IIIMECF-0.6-newproto/util/udclient.h --- IIIMECF-0.6/util/udclient.h 1970-01-01 09:00:00.000000000 +0900 +++ IIIMECF-0.6-newproto/util/udclient.h 2007-12-09 13:41:24.000000000 +0900 @@ -0,0 +1,23 @@ +#ifndef __UDCLIENT_H__ +#define __UDCLIENT_H__ + +int ud_conect(char* path); +int ud_cli(FILE *in, FILE *out, int sockfd); + +/* Posix.1g renames "Unix domain" as "local IPC". + But not all systems define AF_LOCAL and AF_LOCAL. */ +#ifndef AF_LOCAL +#define AF_LOCAL AF_UNIX +#endif +#ifndef PF_LOCAL +#define PF_LOCAL PF_UNIX +#endif +/* Posix.1g defines SHUT_* constants. + But not all systems define SHUT_* constants. */ +#ifndef SHUT_WR +#define SHUT_WR (1) +#endif + +#define max(a,b) ((a) > (b) ? (a) : (b)) + +#endif