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