[BACK]Return to oxf_old.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/oxf_old.c, Revision 1.3

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/oxf_old.c,v 1.2 2000/10/12 15:53:25 ohara Exp $ */
1.1       ohara       3:
                      4: /* このモジュールは互換性のためのものです。*/
                      5:
                      6: #include <stdio.h>
                      7: #include <stdlib.h>
                      8: #include <string.h>
                      9: #include <unistd.h>
                     10: #include <fcntl.h>
                     11: #include <sys/file.h>
                     12: #include <sys/param.h>
                     13: #include <time.h>
                     14:
                     15: #include "mysocket.h"
                     16: #include "ox_toolkit.h"
                     17:
                     18: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *ctl)
                     19: {
                     20:        oxfp->control = ctl;
                     21:        return oxfp;
                     22: }
                     23:
                     24: static char *concat_openxm_home_bin(char *s);
                     25:
                     26: OXFILE *         ox_start(char* host, char* prog1, char* prog2);
                     27: OXFILE *         ox_start_insecure_nonreverse(char* host, short portControl, short portStream);
                     28: OXFILE *         ox_start_remote_with_ssh(char *dat_prog, char* host);
                     29:
                     30: #if 0
                     31: /* 将来計画: start 関数は次のような設計であるべきだろう */
                     32:
                     33: OXFILE *oxf_connect_client()
                     34: {
                     35:     short port   = 0; /* Listen() に決めさせる. */
                     36:     int listened = Listen(&port);
                     37:
                     38:     execute_server(port);
                     39:     return oxf_connect_passive(listened); /* ここで、認証, バイトオーダの決定 */
                     40: }
                     41:
                     42: OXFILE *ox_start_calc(char *cserver)
                     43: {
                     44:     short port   = 0; /* Listen() に決めさせる. */
                     45:     int listened;
                     46:
                     47:     listened = Listen(&port);
                     48:     oxc_open(oxfp_ctl, port, cserver); /* ここでpasswordを送る手もあるが... */
                     49:     return oxf_connect_passive(listened); /* 認証しない. バイトオーダは決定する. */
                     50:
                     51: }
                     52:
                     53: int ox_start()
                     54: {
                     55:     OXFILE *oxfp_ctl, *oxfp_calc;
                     56:
                     57:     oxfp_ctl = oxf_connect_client();
                     58:     /* mathcap の交換 */
                     59:     oxfp_calc = ox_start_calc("ox_sm1");
                     60:     return oxf_control_set(oxfp_calc, oxfp_ctl);
                     61: }
                     62: #endif
                     63:
                     64: static OXFILE *mysocketAccept2(int listened, char *passwd)
                     65: {
                     66:     OXFILE *oxfp = oxf_connect_passive(listened);
                     67:     if(oxf_confirm_client(oxfp, passwd)) {
                     68:         oxf_determine_byteorder_client(oxfp);
                     69:         return oxfp;
                     70:     }
                     71:     oxf_close(oxfp);
                     72:     return NULL;
                     73: }
                     74:
                     75: /* The environment variable OpenXM_HOME must be defined. */
                     76: static char *concat_openxm_home_bin(char *s)
                     77: {
                     78:     char *path;
                     79:     char *base;
                     80:
                     81:     /* if s includes '/' then it is not concaticated. */
                     82:     if (strchr(s, '/') != NULL) {
                     83:         return s;
                     84:     }
                     85:
                     86:     base = getenv("OpenXM_HOME");
                     87:     path = malloc(strlen(base)+6+strlen(s));
                     88:     sprintf(path, "%s/bin/%s", base, s);
                     89:     return path;
                     90: }
                     91:
                     92: void set_OpenXM_HOME()
                     93: {
                     94:     /* Solaris does not have the setenv(). */
                     95:     if (getenv("OpenXM_HOME") == NULL) {
                     96:         putenv("OpenXM_HOME=/usr/local/OpenXM");
                     97:     }
                     98: }
                     99:
1.2       ohara     100: void ox_exec_local(char* ctl_prog, char* dat_prog, int portControl, int portStream, char *passwd)
1.1       ohara     101: {
                    102:     char  ctl[128], dat[128];
1.2       ohara     103:     char localhost[MAXHOSTNAMELEN];
                    104:
1.1       ohara     105:
                    106:     sprintf(ctl, "%d", portControl);
                    107:     sprintf(dat, "%d", portStream);
                    108:
                    109:     set_OpenXM_HOME();
                    110:     ctl_prog = concat_openxm_home_bin(ctl_prog);
                    111:     dat_prog = concat_openxm_home_bin(dat_prog);
                    112:
1.2       ohara     113:     if (gethostname(localhost, MAXHOSTNAMELEN)==0) {
                    114:                if (fork() == 0) {
                    115:                        execlp("oxlog", "oxlog", "xterm", "-icon", "-e", ctl_prog,
                    116:                                   "-reverse", "-ox", dat_prog,
                    117:                                   "-data", dat, "-control", ctl, "-pass", passwd,
                    118:                                   "-host", localhost, NULL);
                    119:                        exit(1);
                    120:                }
                    121:        }
1.1       ohara     122: }
                    123:
                    124: /*
                    125:    (-reverse 版の ox_start)
                    126:    ox_start は クライアントが呼び出すための関数である.
                    127:    サーバでは使われない.  ctl_prog はコントロールサーバであり,
                    128:    -ox, -reverse, -data, -control, -pass, -host
                    129:    というオプションを理解することを仮定する. dat_prog は計算サーバである.
                    130:    接続時には, ct を先にオープンする.
                    131: */
                    132:
                    133: OXFILE *ox_start(char* host, char* ctl_prog, char* dat_prog)
                    134: {
                    135:     OXFILE *st, *ct;
                    136:     char *passwd = generate_otp();
                    137:     int   listen[2];
1.3     ! ohara     138:     int   ports[2] = {0};  /* short! */
1.1       ohara     139:
1.2       ohara     140:        /* host を無視 */
                    141:     listen[0] = oxf_listen(&ports[0]);
                    142:     listen[1] = oxf_listen(&ports[1]);
1.1       ohara     143:
1.2       ohara     144:     ox_exec_local(ctl_prog, dat_prog, ports[0], ports[1], passwd);
1.1       ohara     145:     ct = mysocketAccept2(listen[0], passwd);
                    146:     if (ct != NULL) {
                    147:         usleep(10);   /* zzz... */
                    148:         st = mysocketAccept2(listen[1], passwd);
                    149:         if (st != NULL) {
                    150:             return oxf_control_set(st, ct);
                    151:         }
                    152:     }
                    153:     return NULL;
                    154: }
                    155:
                    156: /*
                    157:    (-insecure 版の ox_start)  まだ、中身はありません。
                    158:    ox_start_insecure は クライアントが呼び出すための関数である.
                    159:    接続時には, ct を先にオープンする.
                    160:    既定値:
                    161:    portControl = 1200
                    162:    portStream  = 1300
                    163: */
                    164:
                    165: OXFILE *ox_start_insecure(char* host, short portControl, short portStream)
                    166: {
                    167:     OXFILE *ct, *st;
                    168:     ct = oxf_connect_active(host, portControl);
                    169:     /* ox は insecure のとき byte order の決定が正しくできないようだ... */
                    170:     /* oxf_determine_byteorder_client(ct); */
                    171:     /* wainting 10 micro second. */
                    172:     usleep(10);
                    173:     st = oxf_connect_active(host, portStream);
                    174:     oxf_determine_byteorder_client(st);
                    175:     return oxf_control_set(st, ct);
                    176: }
                    177:
                    178: /* ssh -f host oxlog xterm -e ox -ox ox_asir ... */
                    179: void ssh_ox_server(char *remote_host, char *ctl_prog, char *dat_prog, short portControl, short portStream)
                    180: {
                    181:     ctl_prog = concat_openxm_home_bin(ctl_prog);
                    182:     dat_prog = concat_openxm_home_bin(dat_prog);
                    183:
                    184:     if (fork() == 0) {
                    185:         execlp("ssh", "ssh", "-f", remote_host, "oxlog", "xterm", "-icon",
                    186:               "-e", ctl_prog, "-insecure", "-ox", dat_prog,
                    187:               "-data", portStream, "-control", portControl,
                    188:               "-host", remote_host, NULL);
                    189:         exit(1);
                    190:     }
                    191: }
                    192:
                    193: OXFILE *ox_start_remote_with_ssh(char *dat_prog, char* remote_host)
                    194: {
                    195:     ssh_ox_server(remote_host, "ox", dat_prog, 1200, 1300);
                    196:     return ox_start_insecure(remote_host, 1200, 1300);
                    197: }
                    198:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>