FFFTPのソースコードです。
Revisión | d5878fa6cb48dc4d50810d608f13cc8128c1331b (tree) |
---|---|
Tiempo | 2012-09-06 17:50:44 |
Autor | s_kawamoto <s_kawamoto@user...> |
Commiter | s_kawamoto |
Add conditions to send dummy commands for keep alive.
Set the interval of dummy commands to 60 seconds by default.
@@ -1611,7 +1611,7 @@ void ReformToVMSstylePathName(char *Path); | ||
1611 | 1611 | void ReformVMSDirName(char *DirName, int Flg); |
1612 | 1612 | #endif |
1613 | 1613 | // 自動切断対策 |
1614 | -void NoopProc(void); | |
1614 | +void NoopProc(int Force); | |
1615 | 1615 | |
1616 | 1616 | /*===== local.c =====*/ |
1617 | 1617 |
@@ -1654,7 +1654,9 @@ int DoDirListCmdSkt(char *AddOpt, char *Path, int Num, int *CancelCheckWork); | ||
1654 | 1654 | #if defined(HAVE_TANDEM) |
1655 | 1655 | void SwitchOSSProc(void); |
1656 | 1656 | #endif |
1657 | -int CommandProcCmd(char *Reply, char *fmt, ...); | |
1657 | +// 同時接続対応 | |
1658 | +//int CommandProcCmd(char *Reply, char *fmt, ...); | |
1659 | +int CommandProcCmd(char *Reply, int* CancelCheckWork, char *fmt, ...); | |
1658 | 1660 | // 同時接続対応 |
1659 | 1661 | //int CommandProcTrn(char *Reply, char *fmt, ...); |
1660 | 1662 | int CommandProcTrn(SOCKET cSkt, char *Reply, int* CancelCheckWork, char *fmt, ...); |
@@ -3731,11 +3731,11 @@ static int RenameUnuseableName(char *Fname) | ||
3731 | 3731 | |
3732 | 3732 | // 自動切断対策 |
3733 | 3733 | // NOOPコマンドでは効果が無いホストが多いためLISTコマンドを使用 |
3734 | -void NoopProc(void) | |
3734 | +void NoopProc(int Force) | |
3735 | 3735 | { |
3736 | 3736 | int CancelCheckWork; |
3737 | 3737 | CancelCheckWork = NO; |
3738 | - if(AskConnecting() == YES && AskUserOpeDisabled() == NO) | |
3738 | + if(Force == YES || (AskConnecting() == YES && AskUserOpeDisabled() == NO)) | |
3739 | 3739 | { |
3740 | 3740 | if(AskReuseCmdSkt() == NO || AskShareProh() == YES || AskTransferNow() == NO) |
3741 | 3741 | { |
@@ -184,6 +184,8 @@ extern int FolderAttr; | ||
184 | 184 | extern int FolderAttrNum; |
185 | 185 | // 同時接続対応 |
186 | 186 | extern int SendQuit; |
187 | +// 自動切断対策 | |
188 | +extern time_t LastDataConnectionTime; | |
187 | 189 | |
188 | 190 | |
189 | 191 | /*----- ファイル転送スレッドを起動する ---------------------------------------- |
@@ -2260,6 +2262,8 @@ static int DownloadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *Canc | ||
2260 | 2262 | if(shutdown(dSkt, 1) != 0) |
2261 | 2263 | ReportWSError("shutdown", WSAGetLastError()); |
2262 | 2264 | |
2265 | + // 自動切断対策 | |
2266 | + LastDataConnectionTime = time(NULL); | |
2263 | 2267 | DoClose(dSkt); |
2264 | 2268 | |
2265 | 2269 | if(ForceAbort == NO) |
@@ -3535,6 +3539,8 @@ static int UploadFile(TRANSPACKET *Pkt, SOCKET dSkt) | ||
3535 | 3539 | Pkt->Abort = ABORT_ERROR; |
3536 | 3540 | } |
3537 | 3541 | |
3542 | + // 自動切断対策 | |
3543 | + LastDataConnectionTime = time(NULL); | |
3538 | 3544 | if(shutdown(dSkt, 1) != 0) |
3539 | 3545 | ReportWSError("shutdown", WSAGetLastError()); |
3540 | 3546 |
@@ -1356,7 +1356,7 @@ void CopyDefaultHost(HOSTDATA *Set) | ||
1356 | 1356 | Set->NetType = NTYPE_AUTO; |
1357 | 1357 | Set->CurNetType = NTYPE_AUTO; |
1358 | 1358 | // 自動切断対策 |
1359 | - Set->NoopInterval = 0; | |
1359 | + Set->NoopInterval = 60; | |
1360 | 1360 | // 再転送対応 |
1361 | 1361 | Set->TransferErrorMode = EXIST_OVW; |
1362 | 1362 | Set->TransferErrorNotify = YES; |
@@ -35,6 +35,8 @@ | ||
35 | 35 | #include <stdlib.h> |
36 | 36 | #include <string.h> |
37 | 37 | #include <mbstring.h> |
38 | +// 自動切断対策 | |
39 | +#include <time.h> | |
38 | 40 | #include <malloc.h> |
39 | 41 | #include <windowsx.h> |
40 | 42 | #include <commctrl.h> |
@@ -248,6 +250,9 @@ int DispFileIcon = NO; | ||
248 | 250 | int MakeAllDir = YES; |
249 | 251 | // UTF-8対応 |
250 | 252 | int LocalKanjiCode = KANJI_SJIS; |
253 | +// 自動切断対策 | |
254 | +int NoopEnable = NO; | |
255 | +time_t LastDataConnectionTime = 0; | |
251 | 256 | |
252 | 257 | |
253 | 258 |
@@ -939,9 +944,8 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA | ||
939 | 944 | SendMessage(GetLocalHwnd(), LVM_ENSUREVISIBLE, (WPARAM)Pos, (LPARAM)TRUE); |
940 | 945 | } |
941 | 946 | } |
942 | - break; | |
943 | - case 2: | |
944 | - NoopProc(); | |
947 | + if(NoopEnable == YES && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
948 | + NoopProc(NO); | |
945 | 949 | break; |
946 | 950 | } |
947 | 951 | break; |
@@ -955,20 +959,18 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA | ||
955 | 959 | { |
956 | 960 | case MENU_CONNECT : |
957 | 961 | // 自動切断対策 |
958 | - KillTimer(hWnd, 2); | |
962 | + NoopEnable = NO; | |
959 | 963 | ConnectProc(DLG_TYPE_CON, -1); |
960 | 964 | // 自動切断対策 |
961 | - if(AskNoopInterval() > 0) | |
962 | - SetTimer(hWnd, 2, AskNoopInterval() * 1000, NULL); | |
965 | + NoopEnable = YES; | |
963 | 966 | break; |
964 | 967 | |
965 | 968 | case MENU_CONNECT_NUM : |
966 | 969 | // 自動切断対策 |
967 | - KillTimer(hWnd, 2); | |
970 | + NoopEnable = NO; | |
968 | 971 | ConnectProc(DLG_TYPE_CON, (int)lParam); |
969 | 972 | // 自動切断対策 |
970 | - if(AskNoopInterval() > 0) | |
971 | - SetTimer(hWnd, 2, AskNoopInterval() * 1000, NULL); | |
973 | + NoopEnable = YES; | |
972 | 974 | if(AskConnecting() == YES) |
973 | 975 | { |
974 | 976 | if(HIWORD(wParam) & OPT_MIRROR) |
@@ -990,20 +992,18 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA | ||
990 | 992 | |
991 | 993 | case MENU_SET_CONNECT : |
992 | 994 | // 自動切断対策 |
993 | - KillTimer(hWnd, 2); | |
995 | + NoopEnable = NO; | |
994 | 996 | ConnectProc(DLG_TYPE_SET, -1); |
995 | 997 | // 自動切断対策 |
996 | - if(AskNoopInterval() > 0) | |
997 | - SetTimer(hWnd, 2, AskNoopInterval() * 1000, NULL); | |
998 | + NoopEnable = YES; | |
998 | 999 | break; |
999 | 1000 | |
1000 | 1001 | case MENU_QUICK : |
1001 | 1002 | // 自動切断対策 |
1002 | - KillTimer(hWnd, 2); | |
1003 | + NoopEnable = NO; | |
1003 | 1004 | QuickConnectProc(); |
1004 | 1005 | // 自動切断対策 |
1005 | - if(AskNoopInterval() > 0) | |
1006 | - SetTimer(hWnd, 2, AskNoopInterval() * 1000, NULL); | |
1006 | + NoopEnable = YES; | |
1007 | 1007 | break; |
1008 | 1008 | |
1009 | 1009 | case MENU_DISCONNECT : |
@@ -1038,11 +1038,10 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA | ||
1038 | 1038 | case MENU_HIST_19 : |
1039 | 1039 | case MENU_HIST_20 : |
1040 | 1040 | // 自動切断対策 |
1041 | - KillTimer(hWnd, 2); | |
1041 | + NoopEnable = NO; | |
1042 | 1042 | HistoryConnectProc(LOWORD(wParam)); |
1043 | 1043 | // 自動切断対策 |
1044 | - if(AskNoopInterval() > 0) | |
1045 | - SetTimer(hWnd, 2, AskNoopInterval() * 1000, NULL); | |
1044 | + NoopEnable = YES; | |
1046 | 1045 | break; |
1047 | 1046 | |
1048 | 1047 | case MENU_UPDIR : |
@@ -66,6 +66,8 @@ extern int SendQuit; | ||
66 | 66 | |
67 | 67 | // 同時接続対応 |
68 | 68 | extern int CancelFlg; |
69 | +// 自動切断対策 | |
70 | +extern time_t LastDataConnectionTime; | |
69 | 71 | |
70 | 72 | /*===== ローカルなワーク =====*/ |
71 | 73 |
@@ -96,13 +98,19 @@ int DoCWD(char *Path, int Disp, int ForceGet, int ErrorBell) | ||
96 | 98 | Sts = FTP_COMPLETE * 100; |
97 | 99 | |
98 | 100 | if(strcmp(Path, "..") == 0) |
99 | - Sts = CommandProcCmd(NULL, "CDUP"); | |
101 | + // 同時接続対応 | |
102 | +// Sts = CommandProcCmd(NULL, "CDUP"); | |
103 | + Sts = CommandProcCmd(NULL, &CancelFlg, "CDUP"); | |
100 | 104 | else if(strcmp(Path, "") != 0) |
101 | 105 | { |
102 | 106 | if((AskHostType() != HTYPE_VMS) || (strchr(Path, '[') != NULL)) |
103 | - Sts = CommandProcCmd(NULL, "CWD %s", Path); | |
107 | + // 同時接続対応 | |
108 | +// Sts = CommandProcCmd(NULL, "CWD %s", Path); | |
109 | + Sts = CommandProcCmd(NULL, &CancelFlg, "CWD %s", Path); | |
104 | 110 | else |
105 | - Sts = CommandProcCmd(NULL, "CWD [.%s]", Path); /* VMS用 */ | |
111 | + // 同時接続対応 | |
112 | +// Sts = CommandProcCmd(NULL, "CWD [.%s]", Path); /* VMS用 */ | |
113 | + Sts = CommandProcCmd(NULL, &CancelFlg, "CWD [.%s]", Path); /* VMS用 */ | |
106 | 114 | } |
107 | 115 | |
108 | 116 | if((Sts/100 >= FTP_CONTINUE) && (ErrorBell == YES)) |
@@ -220,12 +228,16 @@ static int DoPWD(char *Buf) | ||
220 | 228 | |
221 | 229 | if(PwdCommandType == PWD_XPWD) |
222 | 230 | { |
223 | - Sts = CommandProcCmd(Tmp, "XPWD"); | |
231 | + // 同時接続対応 | |
232 | +// Sts = CommandProcCmd(Tmp, "XPWD"); | |
233 | + Sts = CommandProcCmd(Tmp, &CancelFlg, "XPWD"); | |
224 | 234 | if(Sts/100 != FTP_COMPLETE) |
225 | 235 | PwdCommandType = PWD_PWD; |
226 | 236 | } |
227 | 237 | if(PwdCommandType == PWD_PWD) |
228 | - Sts = CommandProcCmd(Tmp, "PWD"); | |
238 | + // 同時接続対応 | |
239 | +// Sts = CommandProcCmd(Tmp, "PWD"); | |
240 | + Sts = CommandProcCmd(Tmp, &CancelFlg, "PWD"); | |
229 | 241 | |
230 | 242 | if(Sts/100 == FTP_COMPLETE) |
231 | 243 | { |
@@ -279,11 +291,17 @@ int DoMKD(char *Path) | ||
279 | 291 | { |
280 | 292 | int Sts; |
281 | 293 | |
282 | - Sts = CommandProcCmd(NULL, "MKD %s", Path); | |
294 | + // 同時接続対応 | |
295 | +// Sts = CommandProcCmd(NULL, "MKD %s", Path); | |
296 | + Sts = CommandProcCmd(NULL, &CancelFlg, "MKD %s", Path); | |
283 | 297 | |
284 | 298 | if(Sts/100 >= FTP_CONTINUE) |
285 | 299 | SoundPlay(SND_ERROR); |
286 | 300 | |
301 | + // 自動切断対策 | |
302 | + if(CancelFlg == NO && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
303 | + NoopProc(YES); | |
304 | + | |
287 | 305 | return(Sts/100); |
288 | 306 | } |
289 | 307 |
@@ -301,11 +319,17 @@ int DoRMD(char *Path) | ||
301 | 319 | { |
302 | 320 | int Sts; |
303 | 321 | |
304 | - Sts = CommandProcCmd(NULL, "RMD %s", Path); | |
322 | + // 同時接続対応 | |
323 | +// Sts = CommandProcCmd(NULL, "RMD %s", Path); | |
324 | + Sts = CommandProcCmd(NULL, &CancelFlg, "RMD %s", Path); | |
305 | 325 | |
306 | 326 | if(Sts/100 >= FTP_CONTINUE) |
307 | 327 | SoundPlay(SND_ERROR); |
308 | 328 | |
329 | + // 自動切断対策 | |
330 | + if(CancelFlg == NO && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
331 | + NoopProc(YES); | |
332 | + | |
309 | 333 | return(Sts/100); |
310 | 334 | } |
311 | 335 |
@@ -323,11 +347,17 @@ int DoDELE(char *Path) | ||
323 | 347 | { |
324 | 348 | int Sts; |
325 | 349 | |
326 | - Sts = CommandProcCmd(NULL, "DELE %s", Path); | |
350 | + // 同時接続対応 | |
351 | +// Sts = CommandProcCmd(NULL, "DELE %s", Path); | |
352 | + Sts = CommandProcCmd(NULL, &CancelFlg, "DELE %s", Path); | |
327 | 353 | |
328 | 354 | if(Sts/100 >= FTP_CONTINUE) |
329 | 355 | SoundPlay(SND_ERROR); |
330 | 356 | |
357 | + // 自動切断対策 | |
358 | + if(CancelFlg == NO && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
359 | + NoopProc(YES); | |
360 | + | |
331 | 361 | return(Sts/100); |
332 | 362 | } |
333 | 363 |
@@ -346,7 +376,9 @@ int DoRENAME(char *Src, char *Dst) | ||
346 | 376 | { |
347 | 377 | int Sts; |
348 | 378 | |
349 | - Sts = CommandProcCmd(NULL, "RNFR %s", Src); | |
379 | + // 同時接続対応 | |
380 | +// Sts = CommandProcCmd(NULL, "RNFR %s", Src); | |
381 | + Sts = CommandProcCmd(NULL, &CancelFlg, "RNFR %s", Src); | |
350 | 382 | if(Sts == 350) |
351 | 383 | // 同時接続対応 |
352 | 384 | // Sts = command(AskCmdCtrlSkt(), NULL, &CheckCancelFlg, "RNTO %s", Dst); |
@@ -355,6 +387,10 @@ int DoRENAME(char *Src, char *Dst) | ||
355 | 387 | if(Sts/100 >= FTP_CONTINUE) |
356 | 388 | SoundPlay(SND_ERROR); |
357 | 389 | |
390 | + // 自動切断対策 | |
391 | + if(CancelFlg == NO && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
392 | + NoopProc(YES); | |
393 | + | |
358 | 394 | return(Sts/100); |
359 | 395 | } |
360 | 396 |
@@ -373,11 +409,17 @@ int DoCHMOD(char *Path, char *Mode) | ||
373 | 409 | { |
374 | 410 | int Sts; |
375 | 411 | |
376 | - Sts = CommandProcCmd(NULL, "%s %s %s", AskHostChmodCmd(), Mode, Path); | |
412 | + // 同時接続対応 | |
413 | +// Sts = CommandProcCmd(NULL, "%s %s %s", AskHostChmodCmd(), Mode, Path); | |
414 | + Sts = CommandProcCmd(NULL, &CancelFlg, "%s %s %s", AskHostChmodCmd(), Mode, Path); | |
377 | 415 | |
378 | 416 | if(Sts/100 >= FTP_CONTINUE) |
379 | 417 | SoundPlay(SND_ERROR); |
380 | 418 | |
419 | + // 自動切断対策 | |
420 | + if(CancelFlg == NO && AskNoopInterval() > 0 && time(NULL) - LastDataConnectionTime >= AskNoopInterval()) | |
421 | + NoopProc(YES); | |
422 | + | |
381 | 423 | return(Sts/100); |
382 | 424 | } |
383 | 425 |
@@ -681,7 +723,9 @@ static int DoDirList(HWND hWnd, SOCKET cSkt, char *AddOpt, char *Path, int Num, | ||
681 | 723 | * コマンドコントロールソケットを使う |
682 | 724 | *----------------------------------------------------------------------------*/ |
683 | 725 | |
684 | -int CommandProcCmd(char *Reply, char *fmt, ...) | |
726 | +// 同時接続対応 | |
727 | +//int CommandProcCmd(char *Reply, char *fmt, ...) | |
728 | +int CommandProcCmd(char *Reply, int* CancelCheckWork, char *fmt, ...) | |
685 | 729 | { |
686 | 730 | va_list Args; |
687 | 731 | char Cmd[1024]; |
@@ -703,7 +747,7 @@ int CommandProcCmd(char *Reply, char *fmt, ...) | ||
703 | 747 | // { |
704 | 748 | // 同時接続対応 |
705 | 749 | // Sts = command(AskCmdCtrlSkt(), Reply, &CheckCancelFlg, "%s", Cmd); |
706 | - Sts = command(AskCmdCtrlSkt(), Reply, &CancelFlg, "%s", Cmd); | |
750 | + Sts = command(AskCmdCtrlSkt(), Reply, CancelCheckWork, "%s", Cmd); | |
707 | 751 | // } |
708 | 752 | // } |
709 | 753 | return(Sts); |