version 1.7, 1999/11/04 06:21:58 |
version 1.10, 1999/11/05 12:34:25 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM: OpenXM/src/ox_math/ox.c,v 1.6 1999/11/04 03:05:50 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_math/ox.c,v 1.9 1999/11/04 19:33:17 ohara Exp $ */ |
|
|
/* |
/* |
関数の名前付け規約(その2): |
関数の名前付け規約(その2): |
Line 87 static int send_cmo_error2(int fd, cmo_error2 |
|
Line 87 static int send_cmo_error2(int fd, cmo_error2 |
|
static int send_mpz(int fd, mpz_ptr mpz); |
static int send_mpz(int fd, mpz_ptr mpz); |
static int send_cmo_distributed_polynomial(int fd, cmo_distributed_polynomial* c); |
static int send_cmo_distributed_polynomial(int fd, cmo_distributed_polynomial* c); |
|
|
|
|
/* エラーハンドリングのため */ |
/* エラーハンドリングのため */ |
static int current_received_serial = 0; |
static int current_received_serial = 0; |
|
|
Line 143 int send_ox_tag(int fd, int tag) |
|
Line 142 int send_ox_tag(int fd, int tag) |
|
return send_int32(fd, next_serial()); |
return send_int32(fd, next_serial()); |
} |
} |
|
|
|
|
/* CMO_LIST 関係の関数群 */ |
/* CMO_LIST 関係の関数群 */ |
cell* new_cell(cmo* newcmo) |
cell* new_cell() |
{ |
{ |
cell* h = malloc(sizeof(cell)); |
cell* h = malloc(sizeof(cell)); |
h->next = NULL; |
h->next = NULL; |
h->cmo = newcmo; |
h->cmo = NULL; |
return h; |
return h; |
} |
} |
|
|
Line 158 cell* next_cell(cell* this) |
|
Line 156 cell* next_cell(cell* this) |
|
return this->next; |
return this->next; |
} |
} |
|
|
static cell* *tailp(cmo_list* this) { |
static cell *tail(cmo_list* this) { |
cell **cp = &this->head; |
cell *cp = this->head; |
while (*cp != NULL) { |
while (cp->next != NULL) { |
cp = &((*cp)->next); |
cp = cp->next; |
} |
} |
return cp; |
return cp; |
} |
} |
|
|
int length_cmo_list(cmo_list* this) |
|
{ |
|
return this->length; |
|
} |
|
|
|
int append_cmo_list(cmo_list* this, cmo* newcmo) |
int append_cmo_list(cmo_list* this, cmo* newcmo) |
{ |
{ |
/* リストの最後尾のNULLを保持している変数へのポインタ */ |
cell *cp = tail(this); |
cell **cp = tailp(this); |
cp->cmo = newcmo; |
*cp = new_cell(newcmo); |
cp->next = new_cell(); |
this->length++; |
this->length++; |
return 0; |
return 0; |
} |
} |
|
|
|
int length_cmo_list(cmo_list* this) |
|
{ |
|
return this->length; |
|
} |
|
|
/** receive_cmo_XXX 関数群 **/ |
/** receive_cmo_XXX 関数群 **/ |
static cmo_null* receive_cmo_null(int fd) |
static cmo_null* receive_cmo_null(int fd) |
{ |
{ |
Line 397 cmo_list* new_cmo_list() |
|
Line 395 cmo_list* new_cmo_list() |
|
cmo_list* c = malloc(sizeof(cmo_list)); |
cmo_list* c = malloc(sizeof(cmo_list)); |
c->tag = CMO_LIST; |
c->tag = CMO_LIST; |
c->length = 0; |
c->length = 0; |
c->head = NULL; |
c->head->next = NULL; |
return c; |
return c; |
} |
} |
|
|
Line 489 cmo_distributed_polynomial* new_cmo_distributed_polyno |
|
Line 487 cmo_distributed_polynomial* new_cmo_distributed_polyno |
|
cmo_distributed_polynomial* c = malloc(sizeof(cmo_distributed_polynomial)); |
cmo_distributed_polynomial* c = malloc(sizeof(cmo_distributed_polynomial)); |
c->tag = CMO_DISTRIBUTED_POLYNOMIAL; |
c->tag = CMO_DISTRIBUTED_POLYNOMIAL; |
c->length = 0; |
c->length = 0; |
c->head = NULL; |
c->head->next = NULL; |
c->ringdef = NULL; |
c->ringdef = NULL; |
return c; |
return c; |
} |
} |
Line 565 void ox_close(ox_file_t sv) |
|
Line 563 void ox_close(ox_file_t sv) |
|
send_ox_command(sv->control, SM_control_kill); |
send_ox_command(sv->control, SM_control_kill); |
#if DEBUG |
#if DEBUG |
sleep(2); /* OpenXM server の終了を待つ. あまり意味はない. */ |
sleep(2); /* OpenXM server の終了を待つ. あまり意味はない. */ |
fprintf(stderr, "I have closed an Open XM server.\n"); |
fprintf(stderr, "I have closed the connection to an Open XM server.\n"); |
#endif |
#endif |
} |
} |
|
|
Line 615 static char *create_otp() |
|
Line 613 static char *create_otp() |
|
static int login_with_otp(int fd, char* passwd) |
static int login_with_otp(int fd, char* passwd) |
{ |
{ |
char buff[1024]; |
char buff[1024]; |
int n = read(fd, buff, 1024); |
|
int len = strlen(passwd)+1; |
int len = strlen(passwd)+1; |
if (n != len) { |
int n = read(fd, buff, len); |
|
if (strcmp(passwd, buff) != 0) { |
fprintf(stderr, "Socket#%d: Login incorrect.\n", fd); |
fprintf(stderr, "Socket#%d: Login incorrect.\n", fd); |
fprintf(stderr, "password = (%s), length = (%d).\n", passwd, len); |
fprintf(stderr, "password = (%s), %d bytes.\n", passwd, len); |
fprintf(stderr, "received = (%d), length = (%d).\n", buff, n); |
fprintf(stderr, "received = (%s), %d bytes.\n", buff, n); |
fflush(stderr); |
fflush(stderr); |
|
exit(1); |
} |
} |
|
#ifdef DEBUG |
|
fprintf(stderr, "Socket#%d: login!.\n", fd); |
|
fprintf(stderr, "password = (%s), %d bytes.\n", passwd, len); |
|
fprintf(stderr, "received = (%s), %d bytes.\n", buff, n); |
|
fflush(stderr); |
|
#endif |
} |
} |
|
|
/* |
/* |
(-reverse 版の ox_start) |
(-reverse 版の ox_start) |
ox_start は クライアントが呼び出すための関数である. |
ox_start は クライアントが呼び出すための関数である. |
サーバでは使われない. prog1 は コントロールサーバであり, |
サーバでは使われない. ctl_prog は コントロールサーバであり, |
-ox, -reverse, -data, -control, -pass, -host |
-ox, -reverse, -data, -control, -pass, -host |
というオプションを理解することを仮定する. prog2 は計算サーバである. |
というオプションを理解することを仮定する. dat_prog は計算サーバである. |
接続時には, sv->control を先にオープンする. |
接続時には, sv->control を先にオープンする. |
*/ |
*/ |
|
|
ox_file_t ox_start(char* host, char* prog1, char* prog2) |
ox_file_t ox_start(char* host, char* ctl_prog, char* dat_prog) |
{ |
{ |
char *pass = create_otp(); |
char *pass = create_otp(); |
char ctl[16], dat[16]; |
char ctl[16], dat[16]; |
Line 650 ox_file_t ox_start(char* host, char* prog1, char* prog |
|
Line 655 ox_file_t ox_start(char* host, char* prog1, char* prog |
|
if (fork() == 0) { |
if (fork() == 0) { |
dup2(2, 1); |
dup2(2, 1); |
dup2(open(DEFAULT_LOGFILE, O_RDWR|O_CREAT|O_TRUNC, 0644), 2); |
dup2(open(DEFAULT_LOGFILE, O_RDWR|O_CREAT|O_TRUNC, 0644), 2); |
execl(prog1, prog1, "-reverse", "-ox", prog2, |
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); |
} |
} |
Line 681 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
Line 686 ox_file_t ox_start_insecure_nonreverse(char* host, sho |
|
ox_file_t sv = malloc(sizeof(__ox_file_struct)); |
ox_file_t sv = malloc(sizeof(__ox_file_struct)); |
|
|
sv->control = mysocketOpen(host, portControl); |
sv->control = mysocketOpen(host, portControl); |
|
#if 0 |
|
/* ox は insecure のとき byte order の決定が正しくできないようだ... */ |
|
decideByteOrderClient(sv->control, 0); |
|
#endif |
/* 10マイクロ秒, 時間稼ぎする. */ |
/* 10マイクロ秒, 時間稼ぎする. */ |
usleep(10); |
usleep(10); |
sv->stream = mysocketOpen(host, portStream); |
sv->stream = mysocketOpen(host, portStream); |
|
decideByteOrderClient(sv->stream, 0); |
return sv; |
return sv; |
} |
} |
|
|
Line 731 static int cmolen_cmo_mathcap(cmo_mathcap* c) |
|
Line 741 static int cmolen_cmo_mathcap(cmo_mathcap* c) |
|
|
|
static int cmolen_cmo_list(cmo_list* c) |
static int cmolen_cmo_list(cmo_list* c) |
{ |
{ |
int size = sizeof(c->head); |
int size = sizeof(int); |
cell* cp = c->head; |
cell* cp = c->head; |
|
|
while(cp != NULL) { |
while(cp->next != NULL) { |
size += cmolen_cmo(cp->cmo); |
size += cmolen_cmo(cp->cmo); |
cp = cp->next; |
cp = cp->next; |
} |
} |
Line 777 int cmolen_cmo(cmo* c) |
|
Line 787 int cmolen_cmo(cmo* c) |
|
break; |
break; |
case CMO_MATHCAP: |
case CMO_MATHCAP: |
case CMO_RING_BY_NAME: |
case CMO_RING_BY_NAME: |
|
case CMO_INDETERMINATE: |
case CMO_ERROR2: |
case CMO_ERROR2: |
size += cmolen_cmo_mathcap((cmo_mathcap *)c); |
size += cmolen_cmo_mathcap((cmo_mathcap *)c); |
break; |
break; |
Line 834 static int dump_cmo_list(cmo_list* m) |
|
Line 845 static int dump_cmo_list(cmo_list* m) |
|
int len = length_cmo_list(m); |
int len = length_cmo_list(m); |
dump_integer(len); |
dump_integer(len); |
|
|
while(cp != NULL) { |
while(cp->next != NULL) { |
dump_cmo(cp->cmo); |
dump_cmo(cp->cmo); |
cp = cp->next; |
cp = cp->next; |
} |
} |
Line 886 int dump_cmo(cmo* m) |
|
Line 897 int dump_cmo(cmo* m) |
|
break; |
break; |
case CMO_MATHCAP: |
case CMO_MATHCAP: |
case CMO_RING_BY_NAME: |
case CMO_RING_BY_NAME: |
|
case CMO_INDETERMINATE: |
case CMO_ERROR2: |
case CMO_ERROR2: |
dump_cmo_mathcap((cmo_mathcap *)m); |
dump_cmo_mathcap((cmo_mathcap *)m); |
break; |
break; |
Line 1001 static int send_cmo_list(int fd, cmo_list* c) |
|
Line 1013 static int send_cmo_list(int fd, cmo_list* c) |
|
int len = length_cmo_list(c); |
int len = length_cmo_list(c); |
send_int32(fd, len); |
send_int32(fd, len); |
|
|
while(cp != NULL) { |
while(cp->next != NULL) { |
send_cmo(fd, cp->cmo); |
send_cmo(fd, cp->cmo); |
cp = cp->next; |
cp = cp->next; |
} |
} |
Line 1015 static int send_cmo_distributed_polynomial(int fd, cmo |
|
Line 1027 static int send_cmo_distributed_polynomial(int fd, cmo |
|
send_int32(fd, len); |
send_int32(fd, len); |
send_cmo(fd, c->ringdef); |
send_cmo(fd, c->ringdef); |
|
|
while(cp != NULL) { |
while(cp->next != NULL) { |
send_cmo(fd, cp->cmo); |
send_cmo(fd, cp->cmo); |
cp = cp->next; |
cp = cp->next; |
} |
} |
Line 1180 void setCmotypeDisable(int type) |
|
Line 1192 void setCmotypeDisable(int type) |
|
int i = funcs(type); |
int i = funcs(type); |
known_types[i] = -1; |
known_types[i] = -1; |
} |
} |
|
|
#if 0 |
#if 0 |
cmo* (*received_funcs[])(int fd) = { |
cmo* (*received_funcs[])(int fd) = { |
NULL, /* gate keeper */ |
NULL, /* gate keeper */ |