version 1.2, 1999/12/13 02:27:15 |
version 1.12, 2000/03/10 12:24:38 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.1 1999/12/09 22:44:56 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.11 2000/02/04 08:01:30 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> |
#include <unistd.h> |
#include <unistd.h> |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <gmp.h> |
|
#include <unistd.h> |
|
#include <sys/file.h> |
#include <sys/file.h> |
|
|
#include "mysocket.h" |
#include "mysocket.h" |
#include "ox.h" |
#include "ox_toolkit.h" |
#include "parse.h" |
#include "parse.h" |
|
|
static int cmolen_cmo_int32(cmo_int32* c); |
static int cmolen_cmo_int32(cmo_int32* c); |
Line 60 static int dump_mpz(mpz_ptr mpz); |
|
Line 42 static int dump_mpz(mpz_ptr mpz); |
|
static int login_with_otp(int fd, char* passwd); |
static int login_with_otp(int fd, char* passwd); |
static char *create_otp(); |
static char *create_otp(); |
|
|
/* CMO_xxx の値順にならべること(デバッグのため) */ |
/* CMO_xxx の値の順にならべること(デバッグのため) */ |
static cmo_null* receive_cmo_null(int fd); |
static cmo_null* receive_cmo_null(int fd); |
static cmo_int32* receive_cmo_int32(int fd); |
static cmo_int32* receive_cmo_int32(int fd); |
static cmo_string* receive_cmo_string(int fd); |
static cmo_string* receive_cmo_string(int fd); |
Line 89 static int send_cmo_distributed_polynomial(in |
|
Line 71 static int send_cmo_distributed_polynomial(in |
|
|
|
static void resize_mpz(mpz_ptr mpz, int size); |
static void resize_mpz(mpz_ptr mpz, int size); |
|
|
|
static int print_cmo_int32(cmo_int32* c); |
|
static int print_cmo_list(cmo_list* li); |
|
static int print_cmo_mathcap(cmo_mathcap* c); |
|
static int print_cmo_string(cmo_string* c); |
|
|
|
static char* new_string_set_cmo_null(); |
|
static char* new_string_set_cmo_int32(int integer); |
|
static char* new_string_set_cmo_list(cmo_list *c); |
|
static char* new_string_set_cmo_zz(cmo_zz *c); |
|
|
|
int ssh_ox_server(char *, char *, char *, short, short); |
|
|
int current_fd = 0; |
int current_fd = 0; |
int set_current_fd(int fd) |
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 125 static cmo *call_hook_after_send_cmo(int fd, cmo *c) |
|
Line 119 static cmo *call_hook_after_send_cmo(int fd, cmo *c) |
|
return c; |
return c; |
} |
} |
|
|
/* エラーハンドリングのため */ |
/* Handling an error. */ |
static int current_received_serial = 0; |
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_error2* make_error_object(int err_code, cmo *ob) |
{ |
{ |
cmo_list* li = new_cmo_list(); |
cmo_list* li = new_cmo_list(); |
Line 139 cmo_error2* make_error_object(int err_code, cmo *ob) |
|
Line 133 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)) |
|
|
/* 新しいシリアル番号を得る */ |
/* getting a next serial number. */ |
int next_serial() |
int next_serial() |
{ |
{ |
static int serial_number = DEFAULT_SERIAL_NUMBER; |
static int serial_number = DEFAULT_SERIAL_NUMBER; |
return 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) |
int send_int32(int fd, int int32) |
{ |
{ |
int32 = htonl(int32); |
int32 = htonl(int32); |
return write(fd, &int32, sizeof(int)); |
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 receive_int32(int fd) |
{ |
{ |
int tag; |
int tag; |
Line 165 int receive_int32(int fd) |
|
Line 158 int receive_int32(int fd) |
|
return ntohl(tag); |
return ntohl(tag); |
} |
} |
|
|
/* (OX_tag, serial number) を受信する. */ |
/* receiving an (OX_tag, serial number) */ |
int receive_ox_tag(int fd) |
int receive_ox_tag(int fd) |
{ |
{ |
int serial; |
int serial; |
Line 174 int receive_ox_tag(int fd) |
|
Line 167 int receive_ox_tag(int fd) |
|
return tag; |
return tag; |
} |
} |
|
|
/* (OX_tag, serial number) を送信する. */ |
/* sending an (OX_tag, serial number) */ |
int send_ox_tag(int fd, int tag) |
int send_ox_tag(int fd, int tag) |
{ |
{ |
send_int32(fd, tag); |
send_int32(fd, tag); |
return send_int32(fd, next_serial()); |
return send_int32(fd, next_serial()); |
} |
} |
|
|
/* CMO_LIST 関係の関数群 */ |
/* functions for a cmo_list */ |
cell* new_cell() |
cell* new_cell() |
{ |
{ |
cell* h = malloc(sizeof(cell)); |
cell* h = malloc(sizeof(cell)); |
Line 212 int append_cmo_list(cmo_list* this, cmo* newcmo) |
|
Line 205 int append_cmo_list(cmo_list* this, cmo* newcmo) |
|
return 0; |
return 0; |
} |
} |
|
|
|
cmo *nth_cmo_list(cmo_list* this, int n) |
|
{ |
|
cell *cp = this->head; |
|
if(this->length <= n) { |
|
return NULL; |
|
} |
|
while(n-- > 0) { |
|
cp = cp->next; |
|
} |
|
return cp->cmo; |
|
} |
|
|
int length_cmo_list(cmo_list* this) |
int length_cmo_list(cmo_list* this) |
{ |
{ |
return this->length; |
return this->length; |
} |
} |
|
|
/** receive_cmo_XXX 関数群 **/ |
/* functions named receive_cmo_*. */ |
static cmo_null* receive_cmo_null(int fd) |
static cmo_null* receive_cmo_null(int fd) |
{ |
{ |
return new_cmo_null(); |
return new_cmo_null(); |
Line 293 static cmo_dms_generic* receive_cmo_dms_generic(int fd |
|
Line 298 static cmo_dms_generic* receive_cmo_dms_generic(int fd |
|
static cmo_ring_by_name* receive_cmo_ring_by_name(int fd) |
static cmo_ring_by_name* receive_cmo_ring_by_name(int fd) |
{ |
{ |
cmo* ob = receive_cmo(fd); |
cmo* ob = receive_cmo(fd); |
/* 意味的チェックが必要 */ |
/* We need to check semantics but yet ... */ |
return new_cmo_ring_by_name(ob); |
return new_cmo_ring_by_name(ob); |
} |
} |
|
|
Line 391 static void resize_mpz(mpz_ptr mpz, int size) |
|
Line 396 static void resize_mpz(mpz_ptr mpz, int size) |
|
mpz->_mp_size = size; |
mpz->_mp_size = size; |
} |
} |
|
|
/** new_cmo_XXX 関数群 **/ |
/* functions named new_cmo_*. */ |
cmo_null* new_cmo_null() |
cmo_null* new_cmo_null() |
{ |
{ |
cmo_null* m = malloc(sizeof(cmo_null)); |
cmo_null* m = malloc(sizeof(cmo_null)); |
Line 477 cmo_zz* new_cmo_zz_set_si(int i) |
|
Line 482 cmo_zz* new_cmo_zz_set_si(int i) |
|
return c; |
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 *new_cmo_zz_set_string(char *s) |
{ |
{ |
cmo_zz* c = new_cmo_zz_noinit(); |
cmo_zz* c = new_cmo_zz_noinit(); |
Line 549 int print_cmo(cmo* c) |
|
Line 561 int print_cmo(cmo* c) |
|
{ |
{ |
int tag = c->tag; |
int tag = c->tag; |
|
|
symbol* symp = lookup_by_tag(tag); |
symbol_t symp = lookup_by_tag(tag); |
if (symp != NULL) { |
if (symp != NULL) { |
fprintf(stderr, "(%s", symp->key); |
fprintf(stderr, "(%s", symp->key); |
}else { |
}else { |
Line 582 int print_cmo(cmo* c) |
|
Line 594 int print_cmo(cmo* c) |
|
} |
} |
} |
} |
|
|
int print_cmo_int32(cmo_int32* c) |
static int print_cmo_int32(cmo_int32* c) |
{ |
{ |
fprintf(stderr, ", %d)", c->i); |
fprintf(stderr, ", %d)", c->i); |
} |
} |
|
|
int print_cmo_list(cmo_list* li) |
static int print_cmo_list(cmo_list* li) |
{ |
{ |
cell* cp = li->head; |
cell* cp = li->head; |
while(cp->next != NULL) { |
while(cp->next != NULL) { |
Line 598 int print_cmo_list(cmo_list* li) |
|
Line 610 int print_cmo_list(cmo_list* li) |
|
fprintf(stderr, ")"); |
fprintf(stderr, ")"); |
} |
} |
|
|
int print_cmo_mathcap(cmo_mathcap* c) |
static int print_cmo_mathcap(cmo_mathcap* c) |
{ |
{ |
fprintf(stderr, ", "); |
fprintf(stderr, ", "); |
print_cmo(c->ob); |
print_cmo(c->ob); |
fprintf(stderr, ")"); |
fprintf(stderr, ")"); |
} |
} |
|
|
int print_cmo_string(cmo_string* c) |
static int print_cmo_string(cmo_string* c) |
{ |
{ |
fprintf(stderr, ", \"%s\")", c->s); |
fprintf(stderr, ", \"%s\")", c->s); |
} |
} |
Line 614 void ox_close(ox_file_t sv) |
|
Line 626 void ox_close(ox_file_t sv) |
|
{ |
{ |
send_ox_command(sv->control, SM_control_kill); |
send_ox_command(sv->control, SM_control_kill); |
#ifdef DEBUG |
#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"); |
fprintf(stderr, "I have closed the connection to an Open XM server.\n"); |
#endif |
#endif |
} |
} |
|
|
void ox_executeStringByLocalParser(ox_file_t sv, char* s) |
void ox_shutdown(ox_file_t sv) |
{ |
{ |
if (s != NULL) { |
/* We need to use SM_shutdown but yet ... */ |
/* 文字列ををスタックにプッシュ. */ |
ox_close(sv); |
send_ox_cmo(sv->stream, (cmo *)new_cmo_string(s)); |
|
/* サーバに実行させる. */ |
|
send_ox_command(sv->stream, SM_executeStringByLocalParser); |
|
} |
|
} |
} |
|
|
/* ox_mathcap() をコールする. */ |
int ox_cmo_rpc(ox_file_t sv, char *function, int argc, cmo *argv[]) |
|
{ |
|
int i = argc; |
|
while(i-- > 0) { |
|
send_ox_cmo(sv->stream, argv[i]); |
|
} |
|
send_ox_cmo(sv->stream, (cmo *)new_cmo_int32(argc)); |
|
send_ox_cmo(sv->stream, (cmo *)new_cmo_string(function)); |
|
send_ox_command(sv->stream, SM_executeFunction); |
|
} |
|
|
|
void ox_execute_string(ox_file_t sv, char* s) |
|
{ |
|
send_ox_cmo(sv->stream, (cmo *)new_cmo_string(s)); |
|
send_ox_command(sv->stream, SM_executeStringByLocalParser); |
|
} |
|
|
|
void ox_push_cmd(ox_file_t sv, int sm_code) |
|
{ |
|
send_ox_command(sv->stream, sm_code); |
|
} |
|
|
cmo_mathcap* ox_mathcap(ox_file_t sv) |
cmo_mathcap* ox_mathcap(ox_file_t sv) |
{ |
{ |
send_ox_command(sv->stream, SM_mathcap); |
send_ox_command(sv->stream, SM_mathcap); |
Line 638 cmo_mathcap* ox_mathcap(ox_file_t sv) |
|
Line 668 cmo_mathcap* ox_mathcap(ox_file_t sv) |
|
return (cmo_mathcap *)receive_cmo(sv->stream); |
return (cmo_mathcap *)receive_cmo(sv->stream); |
} |
} |
|
|
char* ox_popString(ox_file_t sv, int fd) |
char* ox_popString(ox_file_t sv) |
{ |
{ |
cmo_string* m = NULL; |
cmo_string* m = NULL; |
|
|
send_ox_command(fd, SM_popString); |
send_ox_command(sv->stream, SM_popString); |
receive_ox_tag(fd); /* OX_DATA */ |
receive_ox_tag(sv->stream); /* OX_DATA */ |
m = (cmo_string *)receive_cmo(fd); |
m = (cmo_string *)receive_cmo(sv->stream); |
return m->s; |
return m->s; |
} |
} |
|
|
cmo* ox_pop_cmo(ox_file_t sv, int fd) |
int ox_pops(ox_file_t sv, int num) |
{ |
{ |
send_ox_command(fd, SM_popCMO); |
send_ox_cmo(sv->stream, (cmo *)new_cmo_int32(num)); |
receive_ox_tag(fd); /* OX_DATA */ |
send_ox_command(sv->stream, SM_pops); |
return receive_cmo(fd); |
|
} |
} |
|
|
/* 手抜き. (後で改善しよう...) */ |
cmo* ox_pop_cmo(ox_file_t sv) |
|
{ |
|
send_ox_command(sv->stream, SM_popCMO); |
|
receive_ox_tag(sv->stream); /* OX_DATA */ |
|
return receive_cmo(sv->stream); |
|
} |
|
|
|
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 *create_otp() |
{ |
{ |
static char otp[] = "otpasswd"; |
static char otp[] = "otpasswd"; |
return otp; |
return otp; |
} |
} |
|
|
/* OneTimePassword の処理 */ |
/* proceeding an one time password. */ |
static int login_with_otp(int fd, char* passwd) |
static int login_with_otp(int fd, char* passwd) |
{ |
{ |
int len = strlen(passwd)+1; |
int len = strlen(passwd)+1; |
Line 684 static int login_with_otp(int fd, char* passwd) |
|
Line 731 static int login_with_otp(int fd, char* passwd) |
|
return ret; |
return ret; |
} |
} |
|
|
static int exists_ox(char *dir, char *prog) |
/* The environment variable OpenXM_HOME must be defined. */ |
|
static char *concat_openxm_home_bin(char *s) |
{ |
{ |
char *path = alloca(strlen(dir)+strlen(prog)+6); |
char *path; |
sprintf(path, "%s/%s", dir, prog); |
char *base; |
return access(path, X_OK|R_OK); |
|
|
/* if s includes '/' then it is not concaticated. */ |
|
if (strchr(s, '/') != NULL) { |
|
return s; |
|
} |
|
|
|
base = getenv("OpenXM_HOME"); |
|
path = malloc(strlen(base)+6+strlen(s)); |
|
sprintf(path, "%s/bin/%s", base, s); |
|
return path; |
} |
} |
|
|
static char *search_ox(char *prog) |
/* example: which("xterm", getenv("PATH")); */ |
|
static char *which(char *prog, char *path_env) |
{ |
{ |
char *env = getenv("OpenXM_HOME"); |
char *tok; |
char *dir; |
char *path; |
if (env != NULL) { |
char delim[] = ":"; |
dir = malloc(strlen(env)+5); |
char *e = alloca(strlen(path_env)+1); |
sprintf(dir, "%s/bin", env); |
strcpy(e, path_env); |
if (exists_ox(dir, prog) == 0) { |
tok = strtok(e, delim); |
return dir; |
while (tok != NULL) { |
} |
char *path = malloc(strlen(tok)+strlen(prog)+2); |
free(dir); |
sprintf(path, "%s/%s", tok, prog); |
} |
if (access(path, X_OK&R_OK) == 0) { |
dir = "/usr/local/OpenXM/bin"; |
return path; |
if (exists_ox(dir, prog) == 0) { |
} |
return dir; |
free(path); |
} |
tok = strtok(NULL, delim); |
dir = "."; |
} |
if (exists_ox(dir, prog) == 0) { |
return NULL; |
return dir; |
|
} |
|
return NULL; |
|
} |
} |
|
|
static int mysocketAccept2(int fd, char *pass) |
static int mysocketAccept2(int fd, char *pass) |
Line 725 static int mysocketAccept2(int fd, char *pass) |
|
Line 780 static int mysocketAccept2(int fd, char *pass) |
|
return -1; |
return -1; |
} |
} |
|
|
|
/* if it is not 0, then we use oxlog to execute ox. */ |
|
static int flag_ox_start_with_oxlog = 1; |
|
|
/* |
/* |
(-reverse 版の ox_start) |
(-reverse 版の ox_start) |
ox_start は クライアントが呼び出すための関数である. |
ox_start は クライアントが呼び出すための関数である. |
サーバでは使われない. ctl_prog は コントロールサーバであり, |
サーバでは使われない. ctl_prog はコントロールサーバであり, |
-ox, -reverse, -data, -control, -pass, -host |
-ox, -reverse, -data, -control, -pass, -host |
というオプションを理解することを仮定する. dat_prog は計算サーバである. |
というオプションを理解することを仮定する. dat_prog は計算サーバである. |
接続時には, sv->control を先にオープンする. |
接続時には, sv->control を先にオープンする. |
Line 736 static int mysocketAccept2(int fd, char *pass) |
|
Line 794 static int mysocketAccept2(int fd, char *pass) |
|
|
|
ox_file_t ox_start(char* host, char* ctl_prog, char* dat_prog) |
ox_file_t ox_start(char* host, char* ctl_prog, char* dat_prog) |
{ |
{ |
|
ox_file_t sv = NULL; |
char *pass; |
char *pass; |
char ctl[16], dat[16]; |
char ctl[128], dat[128]; |
short portControl = 0; /* short であることに注意 */ |
short portControl = 0; /* short! */ |
short portStream = 0; |
short portStream = 0; |
ox_file_t sv = NULL; |
char *oxlog; |
char *dir; |
|
|
|
if ((dir = search_ox(ctl_prog)) == NULL) { |
/* not overwrite */ |
fprintf(stderr, "client:: %s not found.\n", ctl_prog); |
#if 0 |
return NULL; |
setenv("OpenXM_HOME", "/usr/local/OpenXM", 0); |
} |
#endif |
|
if (getenv("OpenXM_HOME") == NULL) { |
|
putenv("OpenXM_HOME=/usr/local/OpenXM"); |
|
} |
|
|
|
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 756 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 822 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
pass = create_otp(); |
pass = create_otp(); |
|
|
if (fork() == 0) { |
if (fork() == 0) { |
dup2(2, 1); |
if (flag_ox_start_with_oxlog) { |
dup2(open(DEFAULT_LOGFILE, O_RDWR|O_CREAT|O_TRUNC, 0644), 2); |
execl(oxlog, oxlog, "xterm", "-icon", "-e", ctl_prog, |
chdir(dir); |
"-reverse", "-ox", dat_prog, |
execl(ctl_prog, ctl_prog, "-reverse", "-ox", dat_prog, |
"-data", dat, "-control", ctl, "-pass", pass, |
"-data", dat, "-control", ctl, "-pass", pass, |
"-host", host, NULL); |
"-host", host, NULL); |
}else { |
|
dup2(2, 1); |
|
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); |
|
} |
|
exit(1); |
} |
} |
|
|
if ((sv->control = mysocketAccept2(sv->control, pass)) == -1) { |
if ((sv->control = mysocketAccept2(sv->control, pass)) == -1) { |
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 776 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
Line 849 ox_file_t ox_start(char* host, char* ctl_prog, char* d |
|
return sv; |
return sv; |
} |
} |
|
|
|
ox_file_t ox_start_remote_with_ssh(char *dat_prog, char* host) |
|
{ |
|
ssh_ox_server(host, "ox", dat_prog, 1200, 1300); |
|
return ox_start_insecure_nonreverse(host, 1200, 1300); |
|
} |
|
|
|
/* 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", |
|
"-e", ctl_prog, "-insecure", "-ox", dat_prog, |
|
"-data", portStream, "-control", portControl, |
|
"-host", host, NULL); |
|
exit(1); |
|
} |
|
} |
|
|
/* |
/* |
(-insecure 版の ox_start) まだ、中身はありません。 |
(-insecure 版の ox_start) まだ、中身はありません。 |
ox_start_insecure_nonreverse は クライアントが呼び出すための関数である. |
ox_start_insecure_nonreverse は クライアントが呼び出すための関数である. |
Line 794 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
Line 894 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 818 void ox_reset(ox_file_t sv) |
|
Line 918 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 872 static int cmolen_cmo_distributed_polynomial(cmo_distr |
|
Line 972 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 983 static int dump_cmo_distributed_polynomial(cmo_distrib |
|
Line 1083 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 1058 int dump_ox_command(ox_command* m) |
|
Line 1158 int dump_ox_command(ox_command* m) |
|
dump_integer(m->command); |
dump_integer(m->command); |
} |
} |
|
|
int send_ox(ox_file_t s, ox *m) |
int send_ox(int fd, ox *m) |
{ |
{ |
int tag = m->tag; |
|
int code; |
int code; |
if (tag == OX_DATA) { |
switch(m->tag) { |
send_ox_cmo(s->stream, ((ox_data *)m)->cmo); |
case OX_DATA: |
}else if (tag == OX_COMMAND) { |
send_ox_cmo(fd, ((ox_data *)m)->cmo); |
code = ((ox_command *)m)->command; |
break; |
if (code >= 1024) { |
case OX_COMMAND: |
/* control command */ |
send_ox_command(fd, ((ox_command *)m)->command); |
send_ox_command(s->control, code); |
break; |
}else { |
default: |
send_ox_command(s->stream, code); |
#if 0 |
} |
|
}else { |
|
/* CMO?? */ |
/* CMO?? */ |
send_ox_cmo(s->stream, (cmo *)m); |
send_ox_cmo(s->stream, (cmo *)m); |
|
#endif |
} |
} |
} |
} |
|
|
Line 1084 int send_ox_cmo(int fd, cmo* m) |
|
Line 1182 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 1162 static int send_cmo_error2(int fd, cmo_error2* c) |
|
Line 1260 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 1174 int send_cmo(int fd, cmo* c) |
|
Line 1272 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 1246 static cmo_list* make_list_of_id(int ver, char* ver_s, |
|
Line 1344 static cmo_list* make_list_of_id(int ver, char* ver_s, |
|
cmo_list *cap; |
cmo_list *cap; |
char buff[512]; |
char buff[512]; |
|
|
setgetc(mygetc); |
|
sprintf(buff, ID_TEMP, ver, sysname, ver_s, getenv("HOSTTYPE")); |
sprintf(buff, ID_TEMP, ver, sysname, ver_s, getenv("HOSTTYPE")); |
setmode_mygetc(buff, 512); |
init_parser(buff); |
cap = (cmo_list *)parse(); |
cap = (cmo_list *)parse(); |
resetgetc(); |
|
|
|
return cap; |
return cap; |
} |
} |
Line 1258 static cmo_list* make_list_of_id(int ver, char* ver_s, |
|
Line 1354 static cmo_list* make_list_of_id(int ver, char* ver_s, |
|
static cmo_list *make_list_of_tag(int type) |
static cmo_list *make_list_of_tag(int type) |
{ |
{ |
cmo_list *li = new_cmo_list(); |
cmo_list *li = new_cmo_list(); |
symbol *symp; |
symbol_t symp; |
int i = 0; |
int i = 0; |
while((symp = lookup(i++))->key != NULL) { |
while((symp = lookup(i++))->key != NULL) { |
if (symp->type == type) { |
if (symp->type == type) { |
Line 1312 int decideByteOrderServer(oxfd fd, int order) |
|
Line 1408 int decideByteOrderServer(oxfd fd, int order) |
|
} |
} |
|
|
/* cmo と string (ここではC言語のstring) の変換関数群 */ |
/* cmo と string (ここではC言語のstring) の変換関数群 */ |
char *convert_zz_to_string(cmo_zz *c) |
static char *new_string_set_cmo_zz(cmo_zz *c) |
{ |
{ |
return mpz_get_str(NULL, 10, c->mpz); |
return mpz_get_str(NULL, 10, c->mpz); |
} |
} |
|
|
char *convert_null_to_string() |
static char *new_string_set_cmo_null() |
{ |
{ |
static char* null_string = ""; |
static char* null_string = ""; |
return null_string; |
return null_string; |
} |
} |
|
|
char *convert_int_to_string(int integer) |
static char *new_string_set_cmo_int32(int integer) |
{ |
{ |
char buff[1024]; |
char buff[1024]; |
char *s; |
char *s; |
Line 1335 char *convert_int_to_string(int integer) |
|
Line 1431 char *convert_int_to_string(int integer) |
|
return s; |
return s; |
} |
} |
|
|
char *convert_cmo_list_to_string(cmo_list *m) |
static char *new_string_set_cmo_list(cmo_list *m) |
{ |
{ |
char *s; |
char *s; |
int i; |
int i; |
Line 1345 char *convert_cmo_list_to_string(cmo_list *m) |
|
Line 1441 char *convert_cmo_list_to_string(cmo_list *m) |
|
|
|
cell *cp = m->head; |
cell *cp = m->head; |
for(i = 0; i < len; i++) { |
for(i = 0; i < len; i++) { |
sp[i] = convert_cmo_to_string(cp->cmo); |
sp[i] = new_string_set_cmo(cp->cmo); |
size += strlen(sp[i]) + 3; |
size += strlen(sp[i]) + 3; |
cp = cp->next; |
cp = cp->next; |
} |
} |
Line 1361 char *convert_cmo_list_to_string(cmo_list *m) |
|
Line 1457 char *convert_cmo_list_to_string(cmo_list *m) |
|
return s; |
return s; |
} |
} |
|
|
char *convert_cmo_to_string(cmo *m) |
char *new_string_set_cmo(cmo *m) |
{ |
{ |
symbol *symp; |
symbol_t symp; |
switch(m->tag) { |
switch(m->tag) { |
case CMO_ZZ: |
case CMO_ZZ: |
return convert_zz_to_string((cmo_zz *)m); |
return new_string_set_cmo_zz((cmo_zz *)m); |
case CMO_INT32: |
case CMO_INT32: |
return convert_int_to_string(((cmo_int32 *)m)->i); |
return new_string_set_cmo_int32(((cmo_int32 *)m)->i); |
case CMO_STRING: |
case CMO_STRING: |
return ((cmo_string *)m)->s; |
return ((cmo_string *)m)->s; |
case CMO_NULL: |
case CMO_NULL: |
return convert_null_to_string(); |
return new_string_set_cmo_null(); |
case CMO_LIST: |
case CMO_LIST: |
return convert_cmo_list_to_string((cmo_list *)m); |
return new_string_set_cmo_list((cmo_list *)m); |
default: |
default: |
#ifdef DEBUG |
#ifdef DEBUG |
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; |
} |
} |
} |
} |