Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3089 by yutakapon, Thu Jan 3 16:15:40 2008 UTC revision 3090 by yutakapon, Fri Jan 4 06:27:51 2008 UTC
# Line 89  typedef struct bufchain { Line 89  typedef struct bufchain {
89  typedef struct scp {  typedef struct scp {
90          enum scp_dir dir;              // transfer direction          enum scp_dir dir;              // transfer direction
91          enum scp_state state;          // SCP state          enum scp_state state;          // SCP state
92          char sendfile[MAX_PATH];       // sending filename          char localfile[MAX_PATH];      // local filename
93          char sendfilefull[MAX_PATH];   // sending filename fullpath          char localfilefull[MAX_PATH];  // local filename fullpath
94          char dstfile[MAX_PATH];       // sending filename          char remotefile[MAX_PATH];     // remote filename
95          FILE *sendfp;                  // file pointer          FILE *localfp;                 // file pointer for local file
96          struct _stat filestat;         // file status information          struct _stat filestat;         // file status information
97          HWND progress;          HWND progress_window;
98          HANDLE thread;          HANDLE thread;
99          unsigned int tid;          unsigned int thread_id;
100          PTInstVar pvar;          PTInstVar pvar;
101            // for receiving file
         // receiving file  
102          long long filetotalsize;          long long filetotalsize;
103          long long filercvsize;          long long filercvsize;
104  } scp_t;  } scp_t;
# Line 196  static Channel_t *ssh2_channel_new(unsig Line 195  static Channel_t *ssh2_channel_new(unsig
195          c->bufchain = NULL;          c->bufchain = NULL;
196          if (type == TYPE_SCP) {          if (type == TYPE_SCP) {
197                  c->scp.state = SCP_INIT;                  c->scp.state = SCP_INIT;
198                  c->scp.progress = NULL;                  c->scp.progress_window = NULL;
199                  c->scp.thread = (HANDLE)-1;                  c->scp.thread = (HANDLE)-1;
200                  c->scp.sendfp = NULL;                  c->scp.localfp = NULL;
201          }          }
202    
203          return (c);          return (c);
# Line 276  static void ssh2_channel_delete(Channel_ Line 275  static void ssh2_channel_delete(Channel_
275    
276          if (c->type == TYPE_SCP) {          if (c->type == TYPE_SCP) {
277                  c->scp.state = SCP_CLOSING;                  c->scp.state = SCP_CLOSING;
278                  if (c->scp.sendfp != NULL)                  if (c->scp.localfp != NULL)
279                          fclose(c->scp.sendfp);                          fclose(c->scp.localfp);
280                  if (c->scp.progress != NULL) {                  if (c->scp.progress_window != NULL) {
281                          DestroyWindow(c->scp.progress);                          DestroyWindow(c->scp.progress_window);
282                          c->scp.progress = NULL;                          c->scp.progress_window = NULL;
283                  }                  }
284                  if (c->scp.thread != (HANDLE)-1L) {                  if (c->scp.thread != (HANDLE)-1L) {
285                          WaitForSingleObject(c->scp.thread, INFINITE);                          WaitForSingleObject(c->scp.thread, INFINITE);
# Line 3404  static int SSH_scp_transaction(PTInstVar Line 3403  static int SSH_scp_transaction(PTInstVar
3403    
3404          if (direction == TOLOCAL) {  // copy local to remote          if (direction == TOLOCAL) {  // copy local to remote
3405                  fp = fopen(sendfile, "rb");                  fp = fopen(sendfile, "rb");
3406                  if (fp == NULL)                  if (fp == NULL) {
3407                            char buf[80];
3408                            _snprintf_s(buf, sizeof(buf), _TRUNCATE, "fopen: %d", GetLastError());
3409                            MessageBox(NULL, buf, "TTSSH: file open error", MB_OK | MB_ICONERROR);
3410                          goto error;                          goto error;
3411                    }
3412    
3413                  strncpy_s(c->scp.sendfilefull, sizeof(c->scp.sendfilefull), sendfile, _TRUNCATE);  // full path                  strncpy_s(c->scp.localfilefull, sizeof(c->scp.localfilefull), sendfile, _TRUNCATE);  // full path
3414                  ExtractFileName(sendfile, c->scp.sendfile, sizeof(c->scp.sendfile));   // file name only                  ExtractFileName(sendfile, c->scp.localfile, sizeof(c->scp.localfile));   // file name only
3415                  if (dstfile == NULL || dstfile[0] == '\0') { // remote file path                  if (dstfile == NULL || dstfile[0] == '\0') { // remote file path
3416                          strncpy_s(c->scp.dstfile, sizeof(c->scp.dstfile), c->scp.sendfile, _TRUNCATE);  // full path                          strncpy_s(c->scp.remotefile, sizeof(c->scp.remotefile), c->scp.localfile, _TRUNCATE);  // full path
3417                  } else {                  } else {
3418                          strncpy_s(c->scp.dstfile, sizeof(c->scp.dstfile), dstfile, _TRUNCATE);  // full path                          strncpy_s(c->scp.remotefile, sizeof(c->scp.remotefile), dstfile, _TRUNCATE);  // full path
3419                  }                  }
3420                  c->scp.sendfp = fp;     // file pointer                  c->scp.localfp = fp;     // file pointer
3421    
3422                  if (_stat(c->scp.sendfilefull, &st) == 0) {                  if (_stat(c->scp.localfilefull, &st) == 0) {
3423                          c->scp.filestat = st;                          c->scp.filestat = st;
3424                  } else {                  } else {
3425                          goto error;                          goto error;
3426                  }                  }
3427          } else { // copy remote to local          } else { // copy remote to local
3428                  // ローカルファイルの保存先はまだ決め打ち (yutaka)                  // ローカルファイルの保存先はまだ決め打ち (yutaka)
3429                  _snprintf_s(c->scp.sendfilefull, sizeof(c->scp.sendfilefull), _TRUNCATE, "d:\\%s", sendfile);                  _snprintf_s(c->scp.localfilefull, sizeof(c->scp.localfilefull), _TRUNCATE, "d:\\%s", sendfile);
3430                  strncpy_s(c->scp.sendfile, sizeof(c->scp.sendfile), sendfile, _TRUNCATE);  // full path                  strncpy_s(c->scp.localfile, sizeof(c->scp.localfile), sendfile, _TRUNCATE);  // full path
3431    
3432                  fp = fopen(c->scp.sendfilefull, "wb");                  fp = fopen(c->scp.localfilefull, "wb");
3433                  if (fp == NULL)                  if (fp == NULL)
3434                          goto error;                          goto error;
3435    
3436                  c->scp.sendfp = fp;     // file pointer                  c->scp.localfp = fp;     // file pointer
3437          }          }
3438    
3439          // setup SCP data          // setup SCP data
# Line 6882  static BOOL handle_SSH2_open_confirm(PTI Line 6885  static BOOL handle_SSH2_open_confirm(PTI
6885          if (c->type == TYPE_SCP) {          if (c->type == TYPE_SCP) {
6886                  char sbuf[MAX_PATH + 30];                  char sbuf[MAX_PATH + 30];
6887                  if (c->scp.dir == TOLOCAL) {                  if (c->scp.dir == TOLOCAL) {
6888                          _snprintf_s(sbuf, sizeof(sbuf), _TRUNCATE, "scp -t %s", c->scp.dstfile);                          _snprintf_s(sbuf, sizeof(sbuf), _TRUNCATE, "scp -t %s", c->scp.remotefile);
6889    
6890                  } else {                                  } else {                
6891                          _snprintf_s(sbuf, sizeof(sbuf), _TRUNCATE, "scp -f %s", c->scp.dstfile);                          _snprintf_s(sbuf, sizeof(sbuf), _TRUNCATE, "scp -f %s", c->scp.remotefile);
6892    
6893                  }                  }
6894                  buffer_put_string(msg, sbuf, strlen(sbuf));                  buffer_put_string(msg, sbuf, strlen(sbuf));
# Line 7219  static unsigned __stdcall ssh_scp_thread Line 7222  static unsigned __stdcall ssh_scp_thread
7222          char buf[8192];          char buf[8192];
7223          char s[80];          char s[80];
7224          size_t ret;          size_t ret;
7225          HWND hWnd = c->scp.progress;          HWND hWnd = c->scp.progress_window;
7226          scp_dlg_parm_t parm;          scp_dlg_parm_t parm;
7227    
7228          //SendMessage(GetDlgItem(hWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.sendfile);          //SendMessage(GetDlgItem(hWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.localfile);
7229          SendMessage(GetDlgItem(hWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.sendfilefull);          SendMessage(GetDlgItem(hWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.localfilefull);
7230    
7231          do {          do {
7232                  // Cancelボタンが押下されたらウィンドウが消える。                  // Cancelボタンが押下されたらウィンドウが消える。
# Line 7231  static unsigned __stdcall ssh_scp_thread Line 7234  static unsigned __stdcall ssh_scp_thread
7234                          goto cancel_abort;                          goto cancel_abort;
7235    
7236                  // ファイルから読み込んだデータはかならずサーバへ送信する。                  // ファイルから読み込んだデータはかならずサーバへ送信する。
7237                  ret = fread(buf, 1, sizeof(buf), c->scp.sendfp);                  ret = fread(buf, 1, sizeof(buf), c->scp.localfp);
7238                  if (ret == 0)                  if (ret == 0)
7239                          break;                          break;
7240    
# Line 7298  static void SSH2_scp_tolocal(PTInstVar p Line 7301  static void SSH2_scp_tolocal(PTInstVar p
7301                  char buf[128];                  char buf[128];
7302    
7303                  _snprintf_s(buf, sizeof(buf), _TRUNCATE, "C0644 %lld %s\n",                  _snprintf_s(buf, sizeof(buf), _TRUNCATE, "C0644 %lld %s\n",
7304                          (long long)c->scp.filestat.st_size, c->scp.sendfile);                          (long long)c->scp.filestat.st_size, c->scp.localfile);
7305    
7306                  c->scp.state = SCP_FILEINFO;                  c->scp.state = SCP_FILEINFO;
7307                  SSH2_send_channel_data(pvar, c, buf, strlen(buf));                  SSH2_send_channel_data(pvar, c, buf, strlen(buf));
# Line 7313  static void SSH2_scp_tolocal(PTInstVar p Line 7316  static void SSH2_scp_tolocal(PTInstVar p
7316                  hDlgWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SSHSCP_PROGRESS),                  hDlgWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SSHSCP_PROGRESS),
7317                                     pvar->cv->HWin, (DLGPROC)ssh_scp_dlg_proc);                                     pvar->cv->HWin, (DLGPROC)ssh_scp_dlg_proc);
7318                  if (hDlgWnd != NULL) {                  if (hDlgWnd != NULL) {
7319                          c->scp.progress = hDlgWnd;                          c->scp.progress_window = hDlgWnd;
7320                          ShowWindow(hDlgWnd, SW_SHOW);                          ShowWindow(hDlgWnd, SW_SHOW);
7321                  }                  }
7322    
# Line 7342  static unsigned __stdcall ssh_scp_receiv Line 7345  static unsigned __stdcall ssh_scp_receiv
7345          PTInstVar pvar = c->scp.pvar;          PTInstVar pvar = c->scp.pvar;
7346          long long total_size = 0;          long long total_size = 0;
7347          char s[80];          char s[80];
7348          HWND hWnd = c->scp.progress;          HWND hWnd = c->scp.progress_window;
7349          MSG msg;          MSG msg;
7350          unsigned char *data;          unsigned char *data;
7351          unsigned int buflen;          unsigned int buflen;
# Line 7360  static unsigned __stdcall ssh_scp_receiv Line 7363  static unsigned __stdcall ssh_scp_receiv
7363    
7364                                  c->scp.filercvsize += buflen;                                  c->scp.filercvsize += buflen;
7365    
7366                                  if (fwrite(data, 1, buflen, c->scp.sendfp) < buflen) { // error                                  if (fwrite(data, 1, buflen, c->scp.localfp) < buflen) { // error
7367                                          // TODO:                                          // TODO:
7368                                  }                                  }
7369    
# Line 7368  static unsigned __stdcall ssh_scp_receiv Line 7371  static unsigned __stdcall ssh_scp_receiv
7371    
7372                                  _snprintf_s(s, sizeof(s), _TRUNCATE, "%lld / %lld (%d%%)", c->scp.filercvsize, c->scp.filetotalsize,                                  _snprintf_s(s, sizeof(s), _TRUNCATE, "%lld / %lld (%d%%)", c->scp.filercvsize, c->scp.filetotalsize,
7373                                          (100 * c->scp.filercvsize / c->scp.filetotalsize)%100 );                                          (100 * c->scp.filercvsize / c->scp.filetotalsize)%100 );
7374                                  SendMessage(GetDlgItem(c->scp.progress, IDC_PROGRESS), WM_SETTEXT, 0, (LPARAM)s);                                  SendMessage(GetDlgItem(c->scp.progress_window, IDC_PROGRESS), WM_SETTEXT, 0, (LPARAM)s);
7375    
7376                                  if (c->scp.filercvsize >= c->scp.filetotalsize) { // EOF                                  if (c->scp.filercvsize >= c->scp.filetotalsize) { // EOF
7377                                          c->scp.state = SCP_CLOSING;                                          c->scp.state = SCP_CLOSING;
7378                                          ShowWindow(c->scp.progress, SW_HIDE);                                          ShowWindow(c->scp.progress_window, SW_HIDE);
7379                                          goto done;                                          goto done;
7380                                  }                                  }
7381    
# Line 7429  static BOOL SSH2_scp_fromremote(PTInstVa Line 7432  static BOOL SSH2_scp_fromremote(PTInstVa
7432                          hDlgWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SSHSCP_PROGRESS),                          hDlgWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SSHSCP_PROGRESS),
7433                                             pvar->cv->HWin, (DLGPROC)ssh_scp_dlg_proc);                                             pvar->cv->HWin, (DLGPROC)ssh_scp_dlg_proc);
7434                          if (hDlgWnd != NULL) {                          if (hDlgWnd != NULL) {
7435                                  c->scp.progress = hDlgWnd;                                  c->scp.progress_window = hDlgWnd;
7436                                  SetWindowText(hDlgWnd, "TTSSH: SCP receiving file");                                  SetWindowText(hDlgWnd, "TTSSH: SCP receiving file");
7437                                  SendMessage(GetDlgItem(hDlgWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.sendfilefull);                                  SendMessage(GetDlgItem(hDlgWnd, IDC_FILENAME), WM_SETTEXT, 0, (LPARAM)c->scp.localfilefull);
7438                                  ShowWindow(hDlgWnd, SW_SHOW);                                  ShowWindow(hDlgWnd, SW_SHOW);
7439                          }                          }
7440    
# Line 7440  static BOOL SSH2_scp_fromremote(PTInstVa Line 7443  static BOOL SSH2_scp_fromremote(PTInstVa
7443                                  // TODO:                                  // TODO:
7444                          }                          }
7445                          c->scp.thread = thread;                          c->scp.thread = thread;
7446                          c->scp.tid = tid;                          c->scp.thread_id = tid;
7447    
7448                          goto reply;                          goto reply;
7449    
# Line 7453  static BOOL SSH2_scp_fromremote(PTInstVa Line 7456  static BOOL SSH2_scp_fromremote(PTInstVa
7456                  unsigned char *newdata = malloc(buflen);                  unsigned char *newdata = malloc(buflen);
7457                  if (newdata != NULL) {                  if (newdata != NULL) {
7458                          memcpy(newdata, data, buflen);                          memcpy(newdata, data, buflen);
7459                          PostThreadMessage(c->scp.tid, WM_RECEIVING_FILE, (WPARAM)newdata, (LPARAM)buflen);                          PostThreadMessage(c->scp.thread_id, WM_RECEIVING_FILE, (WPARAM)newdata, (LPARAM)buflen);
7460                  }                  }
7461    
7462          } else if (c->scp.state == SCP_CLOSING) {  // EOFの受信          } else if (c->scp.state == SCP_CLOSING) {  // EOFの受信

Legend:
Removed from v.3089  
changed lines
  Added in v.3090

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26