=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/ox.c,v retrieving revision 1.5 retrieving revision 1.9 diff -u -p -r1.5 -r1.9 --- OpenXM/src/ox_toolkit/ox.c 1999/12/16 06:58:01 1.5 +++ OpenXM/src/ox_toolkit/ox.c 2000/01/20 08:46:44 1.9 @@ -1,29 +1,13 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.4 1999/12/15 05:57:35 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.8 2000/01/19 19:46:42 ohara Exp $ */ -/* -関数の名前付け規約(その2): -(1) receive_cmo 関数はCMOタグとデータ本体を受信する. この関数は CMOタグの -値が事前に分からないときに使用する. 返り値として、cmo へのポインタを返す. -(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 関数を呼び出す. +/* + This module includes functions for sending/receiveng CMO's. + Some commnets is written in Japanese by the EUC-JP coded + character set. */ + #include #include #include @@ -104,7 +88,7 @@ int set_current_fd(int fd) current_fd = fd; } -/* hook 関数 */ +/* hook functions. (yet not implemented) */ static hook_t hook_before_send_cmo = NULL; static hook_t hook_after_send_cmo = NULL; @@ -134,10 +118,10 @@ static cmo *call_hook_after_send_cmo(int fd, cmo *c) return c; } -/* エラーハンドリングのため */ +/* Handling an error. */ static int current_received_serial = 0; -/* エラーを起こしたときにサーバは次を呼び出す. */ +/* If an error object be needed, then a server call the following function. */ cmo_error2* make_error_object(int err_code, cmo *ob) { cmo_list* li = new_cmo_list(); @@ -148,25 +132,24 @@ cmo_error2* make_error_object(int err_code, cmo *ob) return new_cmo_error2((cmo *)li); } -/* add at Mon Sep 7 15:51:28 JST 1998 */ #define DEFAULT_SERIAL_NUMBER 0x0000ffff #define receive_serial_number(x) (receive_int32(x)) -/* 新しいシリアル番号を得る */ +/* getting a next serial number. */ int next_serial() { static int serial_number = DEFAULT_SERIAL_NUMBER; return serial_number++; } -/* int32 型のオブジェクトを送信する. */ +/* sending an object of int32 type. (not equal to cmo_int32 type) */ int send_int32(int fd, int int32) { int32 = htonl(int32); return write(fd, &int32, sizeof(int)); } -/* int32 型のオブジェクトを受信する. */ +/* receiving an object of int32 type. (not equal to cmo_int32 type) */ int receive_int32(int fd) { int tag; @@ -174,7 +157,7 @@ int receive_int32(int fd) return ntohl(tag); } -/* (OX_tag, serial number) を受信する. */ +/* receiving an (OX_tag, serial number) */ int receive_ox_tag(int fd) { int serial; @@ -183,14 +166,14 @@ int receive_ox_tag(int fd) return tag; } -/* (OX_tag, serial number) を送信する. */ +/* sending an (OX_tag, serial number) */ int send_ox_tag(int fd, int tag) { send_int32(fd, tag); return send_int32(fd, next_serial()); } -/* CMO_LIST 関係の関数群 */ +/* functions for a cmo_list */ cell* new_cell() { cell* h = malloc(sizeof(cell)); @@ -238,7 +221,7 @@ int length_cmo_list(cmo_list* this) return this->length; } -/** receive_cmo_XXX 関数群 **/ +/* functions named receive_cmo_*. */ static cmo_null* receive_cmo_null(int fd) { return new_cmo_null(); @@ -314,7 +297,7 @@ static cmo_dms_generic* receive_cmo_dms_generic(int fd static cmo_ring_by_name* receive_cmo_ring_by_name(int fd) { cmo* ob = receive_cmo(fd); - /* 意味的チェックが必要 */ + /* We need to check semantics but yet ... */ return new_cmo_ring_by_name(ob); } @@ -412,7 +395,7 @@ static void resize_mpz(mpz_ptr mpz, int size) mpz->_mp_size = size; } -/** new_cmo_XXX 関数群 **/ +/* functions named new_cmo_*. */ cmo_null* new_cmo_null() { cmo_null* m = malloc(sizeof(cmo_null)); @@ -498,6 +481,13 @@ cmo_zz* new_cmo_zz_set_si(int i) return c; } +cmo_zz* new_cmo_zz_set_mpz(mpz_ptr z) +{ + cmo_zz* c = new_cmo_zz(); + mpz_set(c->mpz, z); + return c; +} + cmo_zz *new_cmo_zz_set_string(char *s) { cmo_zz* c = new_cmo_zz_noinit(); @@ -635,14 +625,15 @@ void ox_close(ox_file_t sv) { send_ox_command(sv->control, SM_control_kill); #ifdef DEBUG - sleep(2); /* OpenXM server の終了を待つ. あまり意味はない. */ + sleep(2); + /* We wait thar an OpenXM server terminates. */ fprintf(stderr, "I have closed the connection to an Open XM server.\n"); #endif } void ox_shutdown(ox_file_t sv) { - /* 後で SM_shutdown を用いるものに書き換える予定. */ + /* We need to use SM_shutdown but yet ... */ ox_close(sv); } @@ -668,7 +659,6 @@ void ox_push_cmd(ox_file_t sv, int sm_code) send_ox_command(sv->stream, sm_code); } -/* ox_mathcap() をコールする. */ cmo_mathcap* ox_mathcap(ox_file_t sv) { send_ox_command(sv->stream, SM_mathcap); @@ -705,20 +695,20 @@ void ox_push_cmo(ox_file_t sv, cmo *c) send_ox_cmo(sv->stream, c); } -/* バッファのフラッシュの振りをする. */ +/* a dummy function for flushing a connection. */ int ox_flush(ox_file_t sv) { return 1; } -/* 手抜き. (後で改善しよう...) */ +/* a dummy password function. */ static char *create_otp() { static char otp[] = "otpasswd"; return otp; } -/* OneTimePassword の処理 */ +/* proceeding an one time password. */ static int login_with_otp(int fd, char* passwd) { int len = strlen(passwd)+1; @@ -740,18 +730,21 @@ static int login_with_otp(int fd, char* passwd) 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 *base = getenv("OpenXM_HOME"); + char *path; + char *base; - if (base != NULL) { - dir = alloca(strlen(base)+5); - sprintf(dir, "%s/bin", base); - }else { - dir = "/usr/local/OpenXM/bin"; + /* if s includes '/' then it is not concaticated. */ + if (strchr(s, '/') != NULL) { + return s; } - 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")); */ @@ -786,7 +779,7 @@ static int mysocketAccept2(int fd, char *pass) 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; /* @@ -803,11 +796,17 @@ ox_file_t ox_start(char* host, char* ctl_prog, char* d ox_file_t sv = NULL; char *pass; char ctl[128], dat[128]; - short portControl = 0; /* short であることに注意 */ + short portControl = 0; /* short! */ short portStream = 0; - char *dir; - char *oxlog = "oxlog"; + char *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->control = mysocketListen(host, &portControl); sv->stream = mysocketListen(host, &portStream); @@ -817,7 +816,6 @@ ox_file_t ox_start(char* host, char* ctl_prog, char* d pass = create_otp(); if (fork() == 0) { - chdir_openxm_home_bin(); if (flag_ox_start_with_oxlog) { execl(oxlog, oxlog, "xterm", "-icon", "-e", ctl_prog, "-reverse", "-ox", dat_prog, @@ -825,7 +823,7 @@ ox_file_t ox_start(char* host, char* ctl_prog, char* d "-host", host, NULL); }else { dup2(2, 1); - dup2(open(mkstemp(LOGFILE), O_RDWR|O_CREAT|O_TRUNC, 0644), 2); + dup2(open(tempnam("/tmp", "ox."), O_RDWR|O_CREAT|O_TRUNC, 0644), 2); execl(ctl_prog, ctl_prog, "-reverse", "-ox", dat_prog, "-data", dat, "-control", ctl, "-pass", pass, "-host", host, NULL); @@ -837,7 +835,7 @@ ox_file_t ox_start(char* host, char* ctl_prog, char* d close(sv->stream); return NULL; } - /* 10マイクロ秒, 時間稼ぎする. */ + /* waiting 10 micro second. */ usleep(10); if((sv->stream = mysocketAccept2(sv->stream, pass)) == -1) { return NULL; @@ -848,8 +846,16 @@ ox_file_t ox_start(char* host, char* ctl_prog, char* d /* 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) { + 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) { - execl("ssh", "ssh", "-f", host, "oxlog", "xterm", "-icon", + execl(ssh, ssh, "-f", host, oxlog, "xterm", "-icon", "-e", ctl_prog, "-insecure", "-ox", dat_prog, "-data", portStream, "-control", portControl, "-host", host, NULL); exit(1); @@ -874,7 +880,7 @@ ox_file_t ox_start_insecure_nonreverse(char* host, sho /* ox は insecure のとき byte order の決定が正しくできないようだ... */ decideByteOrderClient(sv->control, 0); #endif - /* 10マイクロ秒, 時間稼ぎする. */ + /* wainting 10 micro second. */ usleep(10); sv->stream = mysocketOpen(host, portStream); decideByteOrderClient(sv->stream, 0); @@ -883,7 +889,7 @@ 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) { - short portControl= 1200; /* 自動生成させよう... */ + short portControl= 1200; /* 自動生成させよう... */ short portStream = 1300; ssh_ox_server(host, ctl_prog, dat_prog, portControl, portStream); @@ -907,7 +913,7 @@ void ox_reset(ox_file_t sv) #endif } -/* 以下は bconv.c で必要とする関数群である. */ +/* the following functions are needed by bconv.c */ /* cmolen 関数は cmo の(送信時の)バイト長を返す. */ /* cmolen_XXX 関数は cmo_XXX の tag を除いたバイト長を返す. */ @@ -961,7 +967,7 @@ static int cmolen_cmo_distributed_polynomial(cmo_distr 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 size = sizeof(int); @@ -1072,7 +1078,7 @@ static int dump_cmo_distributed_polynomial(cmo_distrib } } -/* タグを書き出してから、各関数を呼び出す */ +/* after its tag is sent, we invoke each functions. */ int dump_cmo(cmo* m) { dump_integer(m->tag); @@ -1171,7 +1177,7 @@ int send_ox_cmo(int fd, cmo* m) send_cmo(fd, m); } -/* send_cmo_xxx 関数群 */ +/* send_cmo_* functions */ static int send_cmo_null(int fd, cmo_null* c) { return 0; @@ -1249,7 +1255,7 @@ static int send_cmo_error2(int fd, cmo_error2* c) return 0; } -/* CMOを送る. OX_tag は送信済*/ +/* sending a CMO. (Remarks: OX_tag is already sent.) */ int send_cmo(int fd, cmo* c) { int tag = c->tag; @@ -1261,7 +1267,7 @@ int send_cmo(int fd, cmo* c) case CMO_NULL: case CMO_ZERO: case CMO_DMS_GENERIC: - send_cmo_null(fd, c); /* 空の関数 */ + send_cmo_null(fd, c); /* empty function. */ break; case CMO_INT32: send_cmo_int32(fd, (cmo_int32 *)c); @@ -1333,11 +1339,9 @@ static cmo_list* make_list_of_id(int ver, char* ver_s, cmo_list *cap; char buff[512]; - setgetc(mygetc); sprintf(buff, ID_TEMP, ver, sysname, ver_s, getenv("HOSTTYPE")); - setmode_mygetc(buff, 512); + init_parser(buff); cap = (cmo_list *)parse(); - resetgetc(); return cap; } @@ -1467,7 +1471,7 @@ char *new_string_set_cmo(cmo *m) symp = lookup_by_tag(m->tag); fprintf(stderr, "I do not know how to convert %s to a string.\n", symp->key); #endif - /* まだ実装していません. */ + /* yet not implemented. */ return NULL; } }