[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.8

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

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