version 1.7, 2000/01/17 19:55:55 |
version 1.9, 2000/01/20 08:46:44 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.6 1999/12/22 11:26:37 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.8 2000/01/19 19:46:42 ohara Exp $ */ |
|
|
/* |
/* |
関数の名前付け規約(その2): |
This module includes functions for sending/receiveng CMO's. |
(1) receive_cmo 関数はCMOタグとデータ本体を受信する. この関数は CMOタグの |
Some commnets is written in Japanese by the EUC-JP coded |
値が事前に分からないときに使用する. 返り値として、cmo へのポインタを返す. |
character set. |
(2) receive_cmo_XXX 関数は, CMOタグを親の関数で受信してから呼び出される関 |
|
数で、データ本体のみを受信し、cmo_XXX へのポインタを返す. しかも、 |
|
関数内部で new_cmo_XXX 関数を呼び出す. |
|
(3) send_cmo 関数はCMOタグとデータ本体を送信する. |
|
(4) send_cmo_XXX 関数はCMOタグを親の関数で送信してから呼び出される関数で、 |
|
データ本体のみを送信する. |
|
|
|
---- |
|
(5) receive_ox_XXX 関数は存在しない(作らない). receive_cmo を利用する. |
|
(6) send_ox_XXX 関数は OX タグを含めて送信する. |
|
(7) ox_XXX 関数は一連の送受信を含むより抽象的な操作を表現する. |
|
ox_XXX 関数は、第一引数として、ox_file_t型の変数 sv をとる. |
|
|
|
(8) YYY_cmo 関数と YYY_cmo_XXX 関数の関係は次の通り: |
|
まず YYY_cmo 関数で cmo のタグを処理し、タグを除いた残りの部分を |
|
YYY_cmo_XXX 関数が処理する. cmo の内部に cmo_ZZZ へのポインタが |
|
あるときには、その種類によらずに YYY_cmo 関数を呼び出す. |
|
*/ |
*/ |
|
|
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
Line 104 int set_current_fd(int fd) |
|
Line 88 int set_current_fd(int fd) |
|
current_fd = fd; |
current_fd = fd; |
} |
} |
|
|
/* hook 関数 */ |
/* hook functions. (yet not implemented) */ |
static hook_t hook_before_send_cmo = NULL; |
static hook_t hook_before_send_cmo = NULL; |
static hook_t hook_after_send_cmo = NULL; |
static hook_t hook_after_send_cmo = NULL; |
|
|
Line 148 cmo_error2* make_error_object(int err_code, cmo *ob) |
|
Line 132 cmo_error2* make_error_object(int err_code, cmo *ob) |
|
return new_cmo_error2((cmo *)li); |
return new_cmo_error2((cmo *)li); |
} |
} |
|
|
/* add at Mon Sep 7 15:51:28 JST 1998 */ |
|
#define DEFAULT_SERIAL_NUMBER 0x0000ffff |
#define DEFAULT_SERIAL_NUMBER 0x0000ffff |
#define receive_serial_number(x) (receive_int32(x)) |
#define receive_serial_number(x) (receive_int32(x)) |
|
|
Line 747 static int login_with_otp(int fd, char* passwd) |
|
Line 730 static int login_with_otp(int fd, char* passwd) |
|
return ret; |
return ret; |
} |
} |
|
|
static int chdir_openxm_home_bin() |
/* The environment variable OpenXM_HOME must be defined. */ |
|
static char *concat_openxm_home_bin(char *s) |
{ |
{ |
char *dir; |
char *path; |
char *base = getenv("OpenXM_HOME"); |
char *base; |
|
|
if (base != NULL) { |
/* if s includes '/' then it is not concaticated. */ |
dir = alloca(strlen(base)+5); |
if (strchr(s, '/') != NULL) { |
sprintf(dir, "%s/bin", base); |
return s; |
}else { |
|
dir = "/usr/local/OpenXM/bin"; |
|
} |
} |
return chdir(dir); |
|
|
base = getenv("OpenXM_HOME"); |
|
path = malloc(strlen(base)+5+strlen(s)); |
|
sprintf(path, "%s/bin/%s", base, s); |
|
return path; |
} |
} |
|
|
/* example: which("xterm", getenv("PATH")); */ |
/* example: which("xterm", getenv("PATH")); */ |
Line 793 static int mysocketAccept2(int fd, char *pass) |
|
Line 779 static int mysocketAccept2(int fd, char *pass) |
|
return -1; |
return -1; |
} |
} |
|
|
/* 0 でなければ、oxlog を介して ox を起動する。*/ |
/* if it is not 0, then we use oxlog to execute ox. */ |
static int flag_ox_start_with_oxlog = 1; |
static int flag_ox_start_with_oxlog = 1; |
|
|
/* |
/* |
Line 810 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 796 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
ox_file_t sv = NULL; |
ox_file_t sv = NULL; |
char *pass; |
char *pass; |
char ctl[128], dat[128]; |
char ctl[128], dat[128]; |
short portControl = 0; /* short であることに注意 */ |
short portControl = 0; /* short! */ |
short portStream = 0; |
short portStream = 0; |
char *dir; |
char *oxlog; |
char *oxlog = "oxlog"; |
|
|
|
|
/* not overwrite */ |
|
setenv("OpenXM_HOME", "/usr/local/OpenXM", 0); |
|
|
|
oxlog = concat_openxm_home_bin("oxlog"); |
|
ctl_prog = concat_openxm_home_bin(ctl_prog); |
|
dat_prog = concat_openxm_home_bin(dat_prog); |
|
|
sv = malloc(sizeof(__ox_file_struct)); |
sv = malloc(sizeof(__ox_file_struct)); |
sv->control = mysocketListen(host, &portControl); |
sv->control = mysocketListen(host, &portControl); |
sv->stream = mysocketListen(host, &portStream); |
sv->stream = mysocketListen(host, &portStream); |
Line 824 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 816 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
pass = create_otp(); |
pass = create_otp(); |
|
|
if (fork() == 0) { |
if (fork() == 0) { |
chdir_openxm_home_bin(); |
|
if (flag_ox_start_with_oxlog) { |
if (flag_ox_start_with_oxlog) { |
execl(oxlog, oxlog, "xterm", "-icon", "-e", ctl_prog, |
execl(oxlog, oxlog, "xterm", "-icon", "-e", ctl_prog, |
"-reverse", "-ox", dat_prog, |
"-reverse", "-ox", dat_prog, |
Line 844 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 835 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
close(sv->stream); |
close(sv->stream); |
return NULL; |
return NULL; |
} |
} |
/* 10マイクロ秒, 時間稼ぎする. */ |
/* waiting 10 micro second. */ |
usleep(10); |
usleep(10); |
if((sv->stream = mysocketAccept2(sv->stream, pass)) == -1) { |
if((sv->stream = mysocketAccept2(sv->stream, pass)) == -1) { |
return NULL; |
return NULL; |
Line 855 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 846 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
/* ssh -f host oxlog xterm -e ox -ox ox_asir ... */ |
/* ssh -f host oxlog xterm -e ox -ox ox_asir ... */ |
int ssh_ox_server(char *host, char *ctl_prog, char *dat_prog, short portControl, short portStream) |
int ssh_ox_server(char *host, char *ctl_prog, char *dat_prog, short portControl, short portStream) |
{ |
{ |
|
char *oxlog; |
|
char *ssh; |
|
oxlog = concat_openxm_home_bin("oxlog"); |
|
ctl_prog = concat_openxm_home_bin(ctl_prog); |
|
dat_prog = concat_openxm_home_bin(dat_prog); |
|
|
|
ssh = which("ssh", getenv("PATH")); |
|
|
if (fork() == 0) { |
if (fork() == 0) { |
execl("ssh", "ssh", "-f", host, "oxlog", "xterm", "-icon", |
execl(ssh, ssh, "-f", host, oxlog, "xterm", "-icon", |
"-e", ctl_prog, "-insecure", "-ox", dat_prog, |
"-e", ctl_prog, "-insecure", "-ox", dat_prog, |
"-data", portStream, "-control", portControl, "-host", host, NULL); |
"-data", portStream, "-control", portControl, "-host", host, NULL); |
exit(1); |
exit(1); |
Line 881 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
Line 880 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
/* ox は insecure のとき byte order の決定が正しくできないようだ... */ |
/* ox は insecure のとき byte order の決定が正しくできないようだ... */ |
decideByteOrderClient(sv->control, 0); |
decideByteOrderClient(sv->control, 0); |
#endif |
#endif |
/* 10マイクロ秒, 時間稼ぎする. */ |
/* wainting 10 micro second. */ |
usleep(10); |
usleep(10); |
sv->stream = mysocketOpen(host, portStream); |
sv->stream = mysocketOpen(host, portStream); |
decideByteOrderClient(sv->stream, 0); |
decideByteOrderClient(sv->stream, 0); |
Line 890 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
Line 889 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
|
|
ox_file_t ox_start_insecure_nonreverse2(char* host, char *ctl_prog, char *dat_prog) |
ox_file_t ox_start_insecure_nonreverse2(char* host, char *ctl_prog, char *dat_prog) |
{ |
{ |
short portControl= 1200; /* 自動生成させよう... */ |
short portControl= 1200; /* 自動生成させよう... */ |
short portStream = 1300; |
short portStream = 1300; |
|
|
ssh_ox_server(host, ctl_prog, dat_prog, portControl, portStream); |
ssh_ox_server(host, ctl_prog, dat_prog, portControl, portStream); |
Line 914 void ox_reset(ox_file_t sv) |
|
Line 913 void ox_reset(ox_file_t sv) |
|
#endif |
#endif |
} |
} |
|
|
/* 以下は bconv.c で必要とする関数群である. */ |
/* the following functions are needed by bconv.c */ |
|
|
/* cmolen 関数は cmo の(送信時の)バイト長を返す. */ |
/* cmolen 関数は cmo の(送信時の)バイト長を返す. */ |
/* cmolen_XXX 関数は cmo_XXX の tag を除いたバイト長を返す. */ |
/* cmolen_XXX 関数は cmo_XXX の tag を除いたバイト長を返す. */ |
Line 968 static int cmolen_cmo_distributed_polynomial(cmo_distr |
|
Line 967 static int cmolen_cmo_distributed_polynomial(cmo_distr |
|
return cmolen_cmo_list((cmo_list *)c) + cmolen_cmo(c->ringdef); |
return cmolen_cmo_list((cmo_list *)c) + cmolen_cmo(c->ringdef); |
} |
} |
|
|
/* CMO がバイトエンコードされた場合のバイト列の長さを求める */ |
/* calculating the length of the byte stream of given CMO. */ |
int cmolen_cmo(cmo* c) |
int cmolen_cmo(cmo* c) |
{ |
{ |
int size = sizeof(int); |
int size = sizeof(int); |
Line 1079 static int dump_cmo_distributed_polynomial(cmo_distrib |
|
Line 1078 static int dump_cmo_distributed_polynomial(cmo_distrib |
|
} |
} |
} |
} |
|
|
/* タグを書き出してから、各関数を呼び出す */ |
/* after its tag is sent, we invoke each functions. */ |
int dump_cmo(cmo* m) |
int dump_cmo(cmo* m) |
{ |
{ |
dump_integer(m->tag); |
dump_integer(m->tag); |
Line 1178 int send_ox_cmo(int fd, cmo* m) |
|
Line 1177 int send_ox_cmo(int fd, cmo* m) |
|
send_cmo(fd, m); |
send_cmo(fd, m); |
} |
} |
|
|
/* send_cmo_xxx 関数群 */ |
/* send_cmo_* functions */ |
static int send_cmo_null(int fd, cmo_null* c) |
static int send_cmo_null(int fd, cmo_null* c) |
{ |
{ |
return 0; |
return 0; |
Line 1256 static int send_cmo_error2(int fd, cmo_error2* c) |
|
Line 1255 static int send_cmo_error2(int fd, cmo_error2* c) |
|
return 0; |
return 0; |
} |
} |
|
|
/* CMOを送る. OX_tag は送信済*/ |
/* sending a CMO. (Remarks: OX_tag is already sent.) */ |
int send_cmo(int fd, cmo* c) |
int send_cmo(int fd, cmo* c) |
{ |
{ |
int tag = c->tag; |
int tag = c->tag; |
Line 1268 int send_cmo(int fd, cmo* c) |
|
Line 1267 int send_cmo(int fd, cmo* c) |
|
case CMO_NULL: |
case CMO_NULL: |
case CMO_ZERO: |
case CMO_ZERO: |
case CMO_DMS_GENERIC: |
case CMO_DMS_GENERIC: |
send_cmo_null(fd, c); /* 空の関数 */ |
send_cmo_null(fd, c); /* empty function. */ |
break; |
break; |
case CMO_INT32: |
case CMO_INT32: |
send_cmo_int32(fd, (cmo_int32 *)c); |
send_cmo_int32(fd, (cmo_int32 *)c); |
Line 1472 char *new_string_set_cmo(cmo *m) |
|
Line 1471 char *new_string_set_cmo(cmo *m) |
|
symp = lookup_by_tag(m->tag); |
symp = lookup_by_tag(m->tag); |
fprintf(stderr, "I do not know how to convert %s to a string.\n", symp->key); |
fprintf(stderr, "I do not know how to convert %s to a string.\n", symp->key); |
#endif |
#endif |
/* まだ実装していません. */ |
/* yet not implemented. */ |
return NULL; |
return NULL; |
} |
} |
} |
} |