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

Diff for /OpenXM/src/ox_toolkit/ox.c between version 1.4 and 1.5

version 1.4, 1999/12/15 05:57:35 version 1.5, 1999/12/16 06:58:01
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.3 1999/12/14 09:29:13 ohara Exp $ */  /* $OpenXM: OpenXM/src/ox_toolkit/ox.c,v 1.4 1999/12/15 05:57:35 ohara Exp $ */
   
 /*  /*
 関数の名前付け規約(その2):  関数の名前付け規約(その2):
Line 30  YYY_cmo_XXX 関数が処理する.  cmo の内部に cmo_ZZZ への
Line 30  YYY_cmo_XXX 関数が処理する.  cmo の内部に cmo_ZZZ への
 #include <unistd.h>  #include <unistd.h>
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <gmp.h>  
 #include <unistd.h>  
 #include <sys/file.h>  #include <sys/file.h>
   #include <gmp.h>
   
 #include "mysocket.h"  #include "mysocket.h"
 #include "ox.h"  #include "ox.h"
Line 741  static int login_with_otp(int fd, char* passwd)
Line 740  static int login_with_otp(int fd, char* passwd)
     return ret;      return ret;
 }  }
   
 static int exists_ox(char *dir, char *prog)  static int chdir_openxm_home_bin()
 {  {
     char *path = alloca(strlen(dir)+strlen(prog)+6);      char *dir;
     sprintf(path, "%s/%s", dir, prog);      char *base = getenv("OpenXM_HOME");
     return access(path, X_OK|R_OK);  
           if (base != NULL) {
                   dir = alloca(strlen(base)+5);
                   sprintf(dir, "%s/bin", base);
           }else {
                   dir = "/usr/local/OpenXM/bin";
           }
           return chdir(dir);
 }  }
   
 static char *search_ox(char *prog)  /* example: which("xterm", getenv("PATH")); */
   static char *which(char *prog, char *path_env)
 {  {
     char *env = getenv("OpenXM_HOME");          char *tok;
     char *dir;          char *path;
     if (env != NULL) {          char delim[] = ":";
         dir = malloc(strlen(env)+5);          char *e = alloca(strlen(path_env)+1);
         sprintf(dir, "%s/bin", env);          strcpy(e, path_env);
         if (exists_ox(dir, prog) == 0) {          tok = strtok(e, delim);
             return dir;          while (tok != NULL) {
         }                  char *path = malloc(strlen(tok)+strlen(prog)+2);
         free(dir);                  sprintf(path, "%s/%s", tok, prog);
     }                  if (access(path, X_OK&R_OK) == 0) {
     dir = "/usr/local/OpenXM/bin";                          return path;
     if (exists_ox(dir, prog) == 0) {                  }
         return dir;                  free(path);
     }                  tok = strtok(NULL, delim);
     dir = ".";          }
     if (exists_ox(dir, prog) == 0) {          return NULL;
         return dir;  
     }  
     return NULL;  
 }  }
   
 static int mysocketAccept2(int fd, char *pass)  static int mysocketAccept2(int fd, char *pass)
Line 782  static int mysocketAccept2(int fd, char *pass)
Line 786  static int mysocketAccept2(int fd, char *pass)
     return -1;      return -1;
 }  }
   
   /* 0 でなければ、oxlog を介して ox を起動する。*/
   static int flag_ox_start_with_oxlog = 1;
   
 /*  /*
    (-reverse 版の ox_start)     (-reverse 版の ox_start)
    ox_start は クライアントが呼び出すための関数である.     ox_start は クライアントが呼び出すための関数である.
Line 793  static int mysocketAccept2(int fd, char *pass)
Line 800  static int mysocketAccept2(int fd, char *pass)
   
 ox_file_t ox_start(char* host, char* ctl_prog, char* dat_prog)  ox_file_t ox_start(char* host, char* ctl_prog, char* dat_prog)
 {  {
       ox_file_t sv = NULL;
     char *pass;      char *pass;
     char ctl[16], dat[16];      char ctl[128], dat[128];
     short portControl = 0; /* short であることに注意 */      short portControl = 0; /* short であることに注意 */
     short portStream  = 0;      short portStream  = 0;
     ox_file_t sv = NULL;  
     char *dir;      char *dir;
         char *oxlog = "oxlog";          char *oxlog = "oxlog";
   
     if ((dir = search_ox(ctl_prog)) == NULL) {  
         fprintf(stderr, "client:: %s not found.\n", ctl_prog);  
         return NULL;  
     }  
   
     sv = malloc(sizeof(__ox_file_struct));      sv = malloc(sizeof(__ox_file_struct));
     sv->control = mysocketListen(host, &portControl);      sv->control = mysocketListen(host, &portControl);
     sv->stream  = mysocketListen(host, &portStream);      sv->stream  = mysocketListen(host, &portStream);
Line 815  ox_file_t ox_start(char* host, char* ctl_prog, char* d
Line 817  ox_file_t ox_start(char* host, char* ctl_prog, char* d
     pass = create_otp();      pass = create_otp();
   
     if (fork() == 0) {      if (fork() == 0) {
         dup2(2, 1);                  chdir_openxm_home_bin();
         dup2(open(DEFAULT_LOGFILE, O_RDWR|O_CREAT|O_TRUNC, 0644), 2);                  if (flag_ox_start_with_oxlog) {
         chdir(dir);                          execl(oxlog, oxlog, "xterm", "-icon", "-e", ctl_prog,
         execl(oxlog, oxlog, "/usr/X11R6/bin/xterm", "-icon", "-e",                                    "-reverse", "-ox", dat_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);                  }else {
                           dup2(2, 1);
                           dup2(open(mkstemp(LOGFILE), O_RDWR|O_CREAT|O_TRUNC, 0644),  2);
                           execl(ctl_prog, ctl_prog, "-reverse", "-ox", dat_prog,
                                     "-data", dat, "-control", ctl, "-pass", pass,
                                     "-host", host, NULL);
                   }
                   exit(1);
     }      }
   
     if ((sv->control = mysocketAccept2(sv->control, pass)) == -1) {      if ((sv->control = mysocketAccept2(sv->control, pass)) == -1) {
Line 836  ox_file_t ox_start(char* host, char* ctl_prog, char* d
Line 845  ox_file_t ox_start(char* host, char* ctl_prog, char* d
     return sv;      return sv;
 }  }
   
   /* ssh -f host oxlog xterm -e ox -ox ox_asir ... */
   int ssh_ox_server(char *host, char *ctl_prog, char *dat_prog, short portControl, short portStream)
   {
           if (fork() == 0) {
                   execl("ssh", "ssh", "-f", host, "oxlog", "xterm", "-icon",
                             "-e", ctl_prog, "-insecure", "-ox", dat_prog,
                             "-data", portStream, "-control", portControl, "-host", host, NULL);
                   exit(1);
           }
   }
   
 /*  /*
    (-insecure 版の ox_start)  まだ、中身はありません。     (-insecure 版の ox_start)  まだ、中身はありません。
    ox_start_insecure_nonreverse は クライアントが呼び出すための関数である.     ox_start_insecure_nonreverse は クライアントが呼び出すための関数である.
Line 859  ox_file_t ox_start_insecure_nonreverse(char* host, sho
Line 879  ox_file_t ox_start_insecure_nonreverse(char* host, sho
     sv->stream  = mysocketOpen(host, portStream);      sv->stream  = mysocketOpen(host, portStream);
     decideByteOrderClient(sv->stream, 0);      decideByteOrderClient(sv->stream, 0);
     return sv;      return sv;
   }
   
   ox_file_t ox_start_insecure_nonreverse2(char* host, char *ctl_prog, char *dat_prog)
   {
           short portControl= 1200; /* 自動生成させよう... */
           short portStream = 1300;
   
           ssh_ox_server(host, ctl_prog, dat_prog, portControl, portStream);
           return ox_start_insecure_nonreverse(host, portControl, portStream);
 }  }
   
 void ox_reset(ox_file_t sv)  void ox_reset(ox_file_t sv)

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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