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

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

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