OSDN Git Service

Fix bugs of simultaneous connection.
[ffftp/ffftp.git] / getput.c
1 /*=============================================================================\r
2 *\r
3 *                                                       ダウンロード/アップロード\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 /* このソースは一部、WS_FTP Version 93.12.05 のソースを参考にしました。 */\r
31 /* スレッドの作成/終了に関して、樋口殿作成のパッチを組み込みました。 */\r
32 \r
33 /*\r
34         一部、高速化のためのコード追加 by H.Shirouzu at 2002/10/02\r
35 */\r
36 \r
37 #define STRICT\r
38 #include <stdio.h>\r
39 #include <stdlib.h>\r
40 #include <stdarg.h>\r
41 #include <string.h>\r
42 #include <mbstring.h>\r
43 #include <time.h>\r
44 // IPv6対応\r
45 //#include <winsock.h>\r
46 #include <winsock2.h>\r
47 #include <windowsx.h>\r
48 #include <commctrl.h>\r
49 #include <process.h>\r
50 \r
51 #include "common.h"\r
52 #include "resource.h"\r
53 \r
54 #define SET_BUFFER_SIZE\r
55 \r
56 /* Add by H.Shirouzu at 2002/10/02 */\r
57 #undef BUFSIZE\r
58 #define BUFSIZE                 (32 * 1024)\r
59 #define SOCKBUF_SIZE    (256 * 1024)\r
60 /* End */\r
61 \r
62 #ifdef DISABLE_TRANSFER_NETWORK_BUFFERS\r
63 #undef BUFSIZE\r
64 #define BUFSIZE                 (64 * 1024)     // RWIN値以下で充分な大きさが望ましいと思われる。\r
65 #undef SET_BUFFER_SIZE\r
66 #endif\r
67 \r
68 #define TIMER_DISPLAY           1               /* 表示更新用タイマのID */\r
69 #define DISPLAY_TIMING          500             /* 表示更新時間 0.5秒 */\r
70 \r
71 #define ERR_MSG_LEN                     1024\r
72 \r
73 \r
74 /* 削除確認ダイアログの情報 */\r
75 typedef struct {\r
76         int Cur;\r
77         TRANSPACKET *Pkt;\r
78 } MIRRORDELETEINFO;\r
79 \r
80 \r
81 /*===== プロトタイプ =====*/\r
82 \r
83 static void DispTransPacket(TRANSPACKET *Pkt);\r
84 static void EraseTransFileList(void);\r
85 static ULONG WINAPI TransferThread(void *Dummy);\r
86 static int MakeNonFullPath(TRANSPACKET *Pkt, char *CurDir, char *Tmp);\r
87 static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork);\r
88 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork);\r
89 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork);\r
90 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
91 // 再転送対応\r
92 //static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname);\r
93 static int DispUpDownErrDialog(int ResID, HWND hWnd, TRANSPACKET *Pkt);\r
94 // 64ビット対応\r
95 //static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
96 static INT_PTR CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
97 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork);\r
98 // 64ビット対応\r
99 //static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
100 static INT_PTR CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
101 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt);\r
102 static int UpLoadNonPassive(TRANSPACKET *Pkt);\r
103 static int UpLoadPassive(TRANSPACKET *Pkt);\r
104 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt);\r
105 // 同時接続対応\r
106 //static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii);\r
107 static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii, int *CancelCheckWork);\r
108 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode);\r
109 static int SetUploadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode);\r
110 static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);\r
111 static void DispTransferStatus(HWND hWnd, int End, TRANSPACKET *Pkt);\r
112 static void DispTransFileInfo(TRANSPACKET *Pkt, char *Title, int SkipButton, int Info);\r
113 // IPv6対応\r
114 //static int GetAdrsAndPort(char *Str, char *Adrs, int *Port, int Max);\r
115 static int GetAdrsAndPort(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
116 static int GetAdrsAndPortIPv4(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
117 static int GetAdrsAndPortIPv6(SOCKET Skt, char *Str, char *Adrs, int *Port, int Max);\r
118 static int IsSpecialDevice(char *Fname);\r
119 static int MirrorDelNotify(int Cur, int Notify, TRANSPACKET *Pkt);\r
120 // 64ビット対応\r
121 //static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
122 static INT_PTR CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
123 static void SetErrorMsg(char *fmt, ...);\r
124 // 同時接続対応\r
125 static char* GetErrMsg();\r
126 \r
127 /*===== ローカルなワーク =====*/\r
128 \r
129 // 同時接続対応\r
130 //static HANDLE hTransferThread;\r
131 static HANDLE hTransferThread[MAX_DATA_CONNECTION];\r
132 static int fTransferThreadExit = FALSE;\r
133 \r
134 static HANDLE hRunMutex;                                /* 転送スレッド実行ミューテックス */\r
135 static HANDLE hListAccMutex;                    /* 転送ファイルアクセス用ミューテックス */\r
136 \r
137 static int TransFiles = 0;                              /* 転送待ちファイル数 */\r
138 static TRANSPACKET *TransPacketBase = NULL;     /* 転送ファイルリスト */\r
139 // 同時接続対応\r
140 static TRANSPACKET *NextTransPacketBase = NULL;\r
141 \r
142 // 同時接続対応\r
143 //static int Canceled;          /* 中止フラグ YES/NO */\r
144 static int Canceled[MAX_DATA_CONNECTION];               /* 中止フラグ YES/NO */\r
145 static int ClearAll;            /* 全て中止フラグ YES/NO */\r
146 \r
147 static int ForceAbort;          /* 転送中止フラグ */\r
148                                                         /* このフラグはスレッドを終了させるときに使う */\r
149 \r
150 // 同時接続対応\r
151 //static LONGLONG AllTransSizeNow;      /* 今回の転送で転送したサイズ */\r
152 //static time_t TimeStart;      /* 転送開始時間 */\r
153 static LONGLONG AllTransSizeNow[MAX_DATA_CONNECTION];   /* 今回の転送で転送したサイズ */\r
154 static time_t TimeStart[MAX_DATA_CONNECTION];   /* 転送開始時間 */\r
155 \r
156 static int KeepDlg = NO;        /* 転送中ダイアログを消さないかどうか (YES/NO) */\r
157 static int MoveToForeground = NO;               /* ウインドウを前面に移動するかどうか (YES/NO) */\r
158 \r
159 // 同時接続対応\r
160 //static char CurDir[FMAX_PATH+1] = { "" };\r
161 static char CurDir[MAX_DATA_CONNECTION][FMAX_PATH+1];\r
162 // 同時接続対応\r
163 //static char ErrMsg[ERR_MSG_LEN+7];\r
164 static char ErrMsg[MAX_DATA_CONNECTION+1][ERR_MSG_LEN+7];\r
165 static DWORD ErrMsgThreadId[MAX_DATA_CONNECTION+1];\r
166 static HANDLE hErrMsgMutex;\r
167 \r
168 // 同時接続対応\r
169 static int WaitForMainThread = NO;\r
170 // 再転送対応\r
171 static int TransferErrorMode = EXIST_OVW;\r
172 static int TransferErrorNotify = NO;\r
173 \r
174 /*===== 外部参照 =====*/\r
175 \r
176 /* 設定値 */\r
177 extern int SaveTimeStamp;\r
178 extern int RmEOF;\r
179 // extern int TimeOut;\r
180 extern int FwallType;\r
181 extern int MirUpDelNotify;\r
182 extern int MirDownDelNotify;\r
183 extern int FolderAttr;\r
184 extern int FolderAttrNum;\r
185 \r
186 \r
187 /*----- ファイル転送スレッドを起動する ----------------------------------------\r
188 *\r
189 *       Parameter\r
190 *               なし\r
191 *\r
192 *       Return Value\r
193 *               なし\r
194 *----------------------------------------------------------------------------*/\r
195 \r
196 int MakeTransferThread(void)\r
197 {\r
198         DWORD dwID;\r
199         int i;\r
200 \r
201         hListAccMutex = CreateMutex( NULL, FALSE, NULL );\r
202         hRunMutex = CreateMutex( NULL, TRUE, NULL );\r
203         // 同時接続対応\r
204         hErrMsgMutex = CreateMutex( NULL, FALSE, NULL );\r
205 \r
206         ClearAll = NO;\r
207         ForceAbort = NO;\r
208 \r
209         fTransferThreadExit = FALSE;\r
210         // 同時接続対応\r
211 //      hTransferThread = (HANDLE)_beginthreadex(NULL, 0, TransferThread, 0, 0, &dwID);\r
212 //      if (hTransferThread == NULL)\r
213 //              return(FFFTP_FAIL); /* XXX */\r
214         for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
215         {\r
216                 hTransferThread[i] = (HANDLE)_beginthreadex(NULL, 0, TransferThread, (void*)i, 0, &dwID);\r
217                 if(hTransferThread[i] == NULL)\r
218                         return FFFTP_FAIL;\r
219         }\r
220 \r
221         return(FFFTP_SUCCESS);\r
222 }\r
223 \r
224 \r
225 /*----- ファイル転送スレッドを終了する ----------------------------------------\r
226 *\r
227 *       Parameter\r
228 *               なし\r
229 *\r
230 *       Return Value\r
231 *               なし\r
232 *----------------------------------------------------------------------------*/\r
233 \r
234 void CloseTransferThread(void)\r
235 {\r
236         int i;\r
237         // 同時接続対応\r
238 //      Canceled = YES;\r
239         for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
240                 Canceled[i] = YES;\r
241         ClearAll = YES;\r
242         ForceAbort = YES;\r
243 \r
244         fTransferThreadExit = TRUE;\r
245         // 同時接続対応\r
246 //      while(WaitForSingleObject(hTransferThread, 10) == WAIT_TIMEOUT)\r
247 //      {\r
248 //              BackgrndMessageProc();\r
249 //              Canceled = YES;\r
250 //      }\r
251 //      CloseHandle(hTransferThread);\r
252         for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
253         {\r
254                 while(WaitForSingleObject(hTransferThread[i], 10) == WAIT_TIMEOUT)\r
255                 {\r
256                         BackgrndMessageProc();\r
257                         Canceled[i] = YES;\r
258                 }\r
259                 CloseHandle(hTransferThread[i]);\r
260         }\r
261 \r
262         ReleaseMutex( hRunMutex );\r
263 \r
264         CloseHandle( hListAccMutex );\r
265         CloseHandle( hRunMutex );\r
266         // 同時接続対応\r
267         CloseHandle( hErrMsgMutex );\r
268         return;\r
269 }\r
270 \r
271 \r
272 /*----- 転送するファイル情報をリストに追加する --------------------------------\r
273 *\r
274 *       Parameter\r
275 *               TRANSPACKET *Pkt : 転送ファイル情報\r
276 *               TRANSPACKET **Base : リストの先頭\r
277 *\r
278 *       Return Value\r
279 *               int ステータス\r
280 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
281 *----------------------------------------------------------------------------*/\r
282 \r
283 int AddTmpTransFileList(TRANSPACKET *Pkt, TRANSPACKET **Base)\r
284 {\r
285         TRANSPACKET *Pos;\r
286         TRANSPACKET *Prev;\r
287         int Sts;\r
288 \r
289         Sts = FFFTP_FAIL;\r
290         if((Pos = malloc(sizeof(TRANSPACKET))) != NULL)\r
291         {\r
292                 memcpy(Pos, Pkt, sizeof(TRANSPACKET));\r
293                 Pos->Next = NULL;\r
294 \r
295                 if(*Base == NULL)\r
296                         *Base = Pos;\r
297                 else\r
298                 {\r
299                         Prev = *Base;\r
300                         while(Prev->Next != NULL)\r
301                                 Prev = Prev->Next;\r
302                         Prev->Next = Pos;\r
303                 }\r
304                 Sts = FFFTP_SUCCESS;\r
305         }\r
306         return(Sts);\r
307 }\r
308 \r
309 \r
310 /*----- 転送するファイル情報リストをクリアする --------------------------------\r
311 *\r
312 *       Parameter\r
313 *               TRANSPACKET **Base : リストの先頭\r
314 *\r
315 *       Return Value\r
316 *               なし\r
317 *----------------------------------------------------------------------------*/\r
318 \r
319 void EraseTmpTransFileList(TRANSPACKET **Base)\r
320 {\r
321         TRANSPACKET *Pos;\r
322         TRANSPACKET *Next;\r
323 \r
324         Pos = *Base;\r
325         while(Pos != NULL)\r
326         {\r
327                 Next = Pos->Next;\r
328                 free(Pos);\r
329                 Pos = Next;\r
330         }\r
331         *Base = NULL;\r
332         return;\r
333 }\r
334 \r
335 \r
336 /*----- 転送するファイル情報リストから1つの情報を取り除く --------------------\r
337 *\r
338 *       Parameter\r
339 *               TRANSPACKET *Pkt : 転送ファイル情報\r
340 *               TRANSPACKET **Base : リストの先頭\r
341 *\r
342 *       Return Value\r
343 *               int ステータス\r
344 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
345 *----------------------------------------------------------------------------*/\r
346 \r
347 int RemoveTmpTransFileListItem(TRANSPACKET **Base, int Num)\r
348 {\r
349         TRANSPACKET *Pos;\r
350         TRANSPACKET *Prev;\r
351         int Sts;\r
352 \r
353         Sts = FFFTP_FAIL;\r
354         Pos = *Base;\r
355         if(Num == 0)\r
356         {\r
357                 *Base = Pos->Next;\r
358                 free(Pos);\r
359                 Sts = FFFTP_SUCCESS;\r
360         }\r
361         else\r
362         {\r
363                 while(Pos != NULL)\r
364                 {\r
365                         Prev = Pos;\r
366                         Pos = Pos->Next;\r
367                         if(--Num == 0)\r
368                         {\r
369                                 Prev->Next = Pos->Next;\r
370                                 free(Pos);\r
371                                 Sts = FFFTP_SUCCESS;\r
372                                 break;\r
373                         }\r
374                 }\r
375         }\r
376         return(Sts);\r
377 }\r
378 \r
379 \r
380 /*----- 転送するファイル情報を転送ファイルリストに登録する --------------------\r
381 *\r
382 *       Parameter\r
383 *               TRANSPACKET *Pkt : 転送ファイル情報\r
384 *\r
385 *       Return Value\r
386 *               なし\r
387 *----------------------------------------------------------------------------*/\r
388 \r
389 void AddTransFileList(TRANSPACKET *Pkt)\r
390 {\r
391         // 同時接続対応\r
392         TRANSPACKET *Pos;\r
393 \r
394         DispTransPacket(Pkt);\r
395 \r
396         // 同時接続対応\r
397 //      WaitForSingleObject(hListAccMutex, INFINITE);\r
398         while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
399         {\r
400                 WaitForMainThread = YES;\r
401                 BackgrndMessageProc();\r
402                 Sleep(1);\r
403         }\r
404 \r
405         // 同時接続対応\r
406         Pos = TransPacketBase;\r
407         if(Pos != NULL)\r
408         {\r
409                 while(Pos->Next != NULL)\r
410                         Pos = Pos->Next;\r
411         }\r
412         if(AddTmpTransFileList(Pkt, &TransPacketBase) == FFFTP_SUCCESS)\r
413         {\r
414                 if((strncmp(Pkt->Cmd, "RETR", 4) == 0) ||\r
415                    (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
416                 {\r
417                         TransFiles++;\r
418                         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
419                 }\r
420         }\r
421         // 同時接続対応\r
422         if(NextTransPacketBase == NULL)\r
423         {\r
424                 if(Pos)\r
425                         NextTransPacketBase = Pos->Next;\r
426                 else\r
427                         NextTransPacketBase = TransPacketBase;\r
428         }\r
429         ReleaseMutex(hListAccMutex);\r
430         // 同時接続対応\r
431         WaitForMainThread = NO;\r
432 \r
433         return;\r
434 }\r
435 \r
436 \r
437 /*----- 転送ファイル情報を転送ファイルリストに追加する ------------------------\r
438 *\r
439 *       Parameter\r
440 *               TRANSPACKET *Pkt : 転送ファイル情報\r
441 *               TRANSPACKET **Base : リストの先頭\r
442 *\r
443 *       Return Value\r
444 *               なし\r
445 *\r
446 *       Note\r
447 *               Pkt自体をリストに連結する\r
448 *----------------------------------------------------------------------------*/\r
449 \r
450 void AppendTransFileList(TRANSPACKET *Pkt)\r
451 {\r
452         TRANSPACKET *Pos;\r
453 \r
454         // 同時接続対応\r
455 //      WaitForSingleObject(hListAccMutex, INFINITE);\r
456         while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
457         {\r
458                 WaitForMainThread = YES;\r
459                 BackgrndMessageProc();\r
460                 Sleep(1);\r
461         }\r
462 \r
463         if(TransPacketBase == NULL)\r
464                 TransPacketBase = Pkt;\r
465         else\r
466         {\r
467                 Pos = TransPacketBase;\r
468                 while(Pos->Next != NULL)\r
469                         Pos = Pos->Next;\r
470                 Pos->Next = Pkt;\r
471         }\r
472         // 同時接続対応\r
473         if(NextTransPacketBase == NULL)\r
474                 NextTransPacketBase = Pkt;\r
475 \r
476         while(Pkt != NULL)\r
477         {\r
478                 DispTransPacket(Pkt);\r
479 \r
480                 if((strncmp(Pkt->Cmd, "RETR", 4) == 0) ||\r
481                    (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
482                 {\r
483                         TransFiles++;\r
484                         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
485                 }\r
486                 Pkt = Pkt->Next;\r
487         }\r
488 \r
489         ReleaseMutex(hListAccMutex);\r
490         // 同時接続対応\r
491         WaitForMainThread = NO;\r
492         return;\r
493 }\r
494 \r
495 \r
496 /*----- 転送ファイル情報を表示する --------------------------------------------\r
497 *\r
498 *       Parameter\r
499 *               TRANSPACKET *Pkt : 転送ファイル情報\r
500 *\r
501 *       Return Value\r
502 *               なし\r
503 *----------------------------------------------------------------------------*/\r
504 \r
505 static void DispTransPacket(TRANSPACKET *Pkt)\r
506 {\r
507         if((strncmp(Pkt->Cmd, "RETR", 4) == 0) || (strncmp(Pkt->Cmd, "STOR", 4) == 0))\r
508                 DoPrintf("TransList Cmd=%s : %s : %s", Pkt->Cmd, Pkt->RemoteFile, Pkt->LocalFile);\r
509         else if(strncmp(Pkt->Cmd, "R-", 2) == 0)\r
510                 DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->RemoteFile);\r
511         else if(strncmp(Pkt->Cmd, "L-", 2) == 0)\r
512                 DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->LocalFile);\r
513         else if(strncmp(Pkt->Cmd, "MKD", 3) == 0)\r
514         {\r
515                 if(strlen(Pkt->LocalFile) > 0)\r
516                         DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->LocalFile);\r
517                 else\r
518                         DoPrintf("TransList Cmd=%s : %s", Pkt->Cmd, Pkt->RemoteFile);\r
519         }\r
520         else\r
521                 DoPrintf("TransList Cmd=%s", Pkt->Cmd);\r
522         return;\r
523 }\r
524 \r
525 \r
526 /*----- 転送ファイルリストをクリアする ----------------------------------------\r
527 *\r
528 *       Parameter\r
529 *               なし\r
530 *\r
531 *       Return Value\r
532 *               なし\r
533 *----------------------------------------------------------------------------*/\r
534 \r
535 static void EraseTransFileList(void)\r
536 {\r
537         TRANSPACKET *New;\r
538         TRANSPACKET *Next;\r
539         TRANSPACKET *NotDel;\r
540         TRANSPACKET Pkt;\r
541 \r
542         NotDel = NULL;\r
543 \r
544         // 同時接続対応\r
545 //      WaitForSingleObject(hListAccMutex, INFINITE);\r
546         while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
547         {\r
548                 WaitForMainThread = YES;\r
549                 BackgrndMessageProc();\r
550                 Sleep(1);\r
551         }\r
552         New = TransPacketBase;\r
553         while(New != NULL)\r
554         {\r
555                 /* 最後の"BACKCUR"は必要なので消さない */\r
556                 if(strcmp(New->Cmd, "BACKCUR") == 0)\r
557                 {\r
558                         if(NotDel != NULL)\r
559                                 // 同時接続対応\r
560 //                              free(NotDel);\r
561                                 strcpy(NotDel->Cmd, "");\r
562                         NotDel = New;\r
563                         New = New->Next;\r
564                         // 同時接続対応\r
565 //                      NotDel->Next = NULL;\r
566                 }\r
567                 else\r
568                 {\r
569                         Next = New->Next;\r
570                         // 同時接続対応\r
571 //                      free(New);\r
572                         strcpy(New->Cmd, "");\r
573                         New = Next;\r
574                 }\r
575         }\r
576         TransPacketBase = NotDel;\r
577         // 同時接続対応\r
578         NextTransPacketBase = NotDel;\r
579         TransFiles = 0;\r
580         PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
581         ReleaseMutex(hListAccMutex);\r
582         // 同時接続対応\r
583         WaitForMainThread = NO;\r
584 \r
585         strcpy(Pkt.Cmd, "GOQUIT");\r
586         AddTransFileList(&Pkt);\r
587         return;\r
588 }\r
589 \r
590 \r
591 /*----- 転送中ダイアログを消さないようにするかどうかを設定 --------------------\r
592 *\r
593 *       Parameter\r
594 *               int Sw : 転送中ダイアログを消さないかどうか (YES/NO)\r
595 *\r
596 *       Return Value\r
597 *               なし\r
598 *----------------------------------------------------------------------------*/\r
599 \r
600 void KeepTransferDialog(int Sw)\r
601 {\r
602         KeepDlg = Sw;\r
603         return;\r
604 }\r
605 \r
606 \r
607 /*----- 現在転送中かどうかを返す ----------------------------------------------\r
608 *\r
609 *       Parameter\r
610 *               なし\r
611 *\r
612 *       Return Value\r
613 *               int ステータス (YES/NO=転送中ではない)\r
614 *----------------------------------------------------------------------------*/\r
615 \r
616 int AskTransferNow(void)\r
617 {\r
618         return(TransPacketBase != NULL ? YES : NO);\r
619 }\r
620 \r
621 \r
622 /*----- 転送するファイルの数を返す --------------------------------------------\r
623 *\r
624 *       Parameter\r
625 *               なし\r
626 *\r
627 *       Return Value\r
628 *               int 転送するファイルの数\r
629 *----------------------------------------------------------------------------*/\r
630 \r
631 int AskTransferFileNum(void)\r
632 {\r
633         return(TransFiles);\r
634 }\r
635 \r
636 \r
637 /*----- 転送中ウインドウを前面に出す ------------------------------------------\r
638 *\r
639 *       Parameter\r
640 *               なし\r
641 *\r
642 *       Return Value\r
643 *               なし\r
644 *----------------------------------------------------------------------------*/\r
645 \r
646 void GoForwardTransWindow(void)\r
647 {\r
648         MoveToForeground = YES;\r
649         return;\r
650 }\r
651 \r
652 \r
653 /*----- 転送ソケットのカレントディレクトリ情報を初期化 ------------------------\r
654 *\r
655 *       Parameter\r
656 *               なし\r
657 *\r
658 *       Return Value\r
659 *               なし\r
660 *----------------------------------------------------------------------------*/\r
661 \r
662 void InitTransCurDir(void)\r
663 {\r
664         // 同時接続対応\r
665 //      strcpy(CurDir, "");\r
666         int i;\r
667         for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
668                 strcpy(CurDir[i], "");\r
669         return;\r
670 }\r
671 \r
672 \r
673 /*----- ファイル転送スレッドのメインループ ------------------------------------\r
674 *\r
675 *       Parameter\r
676 *               void *Dummy : 使わない\r
677 *\r
678 *       Return Value\r
679 *               なし\r
680 *----------------------------------------------------------------------------*/\r
681 \r
682 static ULONG WINAPI TransferThread(void *Dummy)\r
683 {\r
684         TRANSPACKET *Pos;\r
685         HWND hWndTrans;\r
686         char Tmp[FMAX_PATH+1];\r
687         int CwdSts;\r
688         int GoExit;\r
689 //      int Down;\r
690 //      int Up;\r
691         static int Down;\r
692         static int Up;\r
693         int DelNotify;\r
694         int ThreadCount;\r
695         SOCKET CmdSkt;\r
696         SOCKET NewCmdSkt;\r
697         SOCKET TrnSkt;\r
698         RECT WndRect;\r
699         int i;\r
700         DWORD LastUsed;\r
701 \r
702         hWndTrans = NULL;\r
703         Down = NO;\r
704         Up = NO;\r
705         GoExit = NO;\r
706         DelNotify = NO;\r
707         // 同時接続対応\r
708         // ソケットは各転送スレッドが管理\r
709         ThreadCount = (int)Dummy;\r
710         CmdSkt = INVALID_SOCKET;\r
711         NewCmdSkt = INVALID_SOCKET;\r
712         TrnSkt = INVALID_SOCKET;\r
713         SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);\r
714 \r
715         while((TransPacketBase != NULL) ||\r
716                   (WaitForSingleObject(hRunMutex, 200) == WAIT_TIMEOUT))\r
717         {\r
718                 if(fTransferThreadExit == TRUE)\r
719                         break;\r
720 \r
721                 if(WaitForMainThread == YES)\r
722                 {\r
723                         BackgrndMessageProc();\r
724                         Sleep(100);\r
725                         continue;\r
726                 }\r
727 \r
728 //              WaitForSingleObject(hListAccMutex, INFINITE);\r
729                 while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
730                 {\r
731                         BackgrndMessageProc();\r
732                         Sleep(1);\r
733                 }\r
734 //              memset(ErrMsg, NUL, ERR_MSG_LEN+7);\r
735                 memset(GetErrMsg(), NUL, ERR_MSG_LEN+7);\r
736 \r
737 //              Canceled = NO;\r
738                 Canceled[ThreadCount] = NO;\r
739 \r
740                 while(TransPacketBase != NULL && strcmp(TransPacketBase->Cmd, "") == 0)\r
741                 {\r
742                         Pos = TransPacketBase;\r
743                         TransPacketBase = TransPacketBase->Next;\r
744                         free(Pos);\r
745                 }\r
746                 NewCmdSkt = AskCmdCtrlSkt();\r
747                 if(AskReuseCmdSkt() == YES && ThreadCount == 0)\r
748                 {\r
749                         if(TransPacketBase && ThreadCount < AskMaxThreadCount())\r
750                                 TrnSkt = AskTrnCtrlSkt();\r
751                 }\r
752                 else\r
753                 {\r
754                         if(TransPacketBase && NewCmdSkt != INVALID_SOCKET && ThreadCount < AskMaxThreadCount())\r
755                         {\r
756                                 if(TrnSkt == INVALID_SOCKET || NewCmdSkt != CmdSkt)\r
757                                 {\r
758                                         ReleaseMutex(hListAccMutex);\r
759                                         ReConnectTrnSkt(&TrnSkt, &Canceled[ThreadCount]);\r
760                                         // 同時ログイン数制限対策\r
761                                         if(TrnSkt != INVALID_SOCKET)\r
762                                                 LastUsed = timeGetTime();\r
763                                         else\r
764                                         {\r
765                                                 // 同時ログイン数制限に引っかかった可能性あり\r
766                                                 // 負荷を下げるために約10秒間待機\r
767                                                 i = 10000;\r
768                                                 while(NewCmdSkt != CmdSkt && i > 0)\r
769                                                 {\r
770                                                         BackgrndMessageProc();\r
771                                                         Sleep(1);\r
772                                                         i--;\r
773                                                 }\r
774                                         }\r
775 //                                      WaitForSingleObject(hListAccMutex, INFINITE);\r
776                                         while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
777                                         {\r
778                                                 BackgrndMessageProc();\r
779                                                 Sleep(1);\r
780                                         }\r
781                                 }\r
782                         }\r
783                         else\r
784                         {\r
785                                 if(TrnSkt != INVALID_SOCKET)\r
786                                 {\r
787                                         // 同時ログイン数制限対策\r
788                                         // 10秒間は再利用を許可\r
789                                         if(timeGetTime() - LastUsed > 10000)\r
790                                         {\r
791                                                 ReleaseMutex(hListAccMutex);\r
792                                                 SendData(TrnSkt, "QUIT\r\n", 6, 0, &Canceled[ThreadCount]);\r
793                                                 DoClose(TrnSkt);\r
794                                                 TrnSkt = INVALID_SOCKET;\r
795 //                                              WaitForSingleObject(hListAccMutex, INFINITE);\r
796                                                 while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
797                                                 {\r
798                                                         BackgrndMessageProc();\r
799                                                         Sleep(1);\r
800                                                 }\r
801                                         }\r
802                                 }\r
803                         }\r
804                 }\r
805                 CmdSkt = NewCmdSkt;\r
806 //              if(TransPacketBase != NULL)\r
807                 if(TrnSkt != INVALID_SOCKET && NextTransPacketBase != NULL)\r
808                 {\r
809                         Pos = NextTransPacketBase;\r
810                         NextTransPacketBase = NextTransPacketBase->Next;\r
811                         // ディレクトリ操作は非同期で行わない\r
812 //                      ReleaseMutex(hListAccMutex);\r
813                         if(hWndTrans == NULL)\r
814                         {\r
815 //                              if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
816 //                                 (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0) ||\r
817 //                                 (strncmp(TransPacketBase->Cmd, "MKD", 3) == 0) ||\r
818 //                                 (strncmp(TransPacketBase->Cmd, "L-", 2) == 0) ||\r
819 //                                 (strncmp(TransPacketBase->Cmd, "R-", 2) == 0))\r
820                                 if((strncmp(Pos->Cmd, "RETR", 4) == 0) ||\r
821                                    (strncmp(Pos->Cmd, "STOR", 4) == 0) ||\r
822                                    (strncmp(Pos->Cmd, "MKD", 3) == 0) ||\r
823                                    (strncmp(Pos->Cmd, "L-", 2) == 0) ||\r
824                                    (strncmp(Pos->Cmd, "R-", 2) == 0))\r
825                                 {\r
826                                         hWndTrans = CreateDialog(GetFtpInst(), MAKEINTRESOURCE(transfer_dlg), HWND_DESKTOP, (DLGPROC)TransDlgProc);\r
827                                         if(MoveToForeground == YES)\r
828                                                 SetForegroundWindow(hWndTrans);\r
829                                         ShowWindow(hWndTrans, SW_SHOWNOACTIVATE);\r
830                                         GetWindowRect(hWndTrans, &WndRect);\r
831                                         SetWindowPos(hWndTrans, NULL, WndRect.left, WndRect.top + (WndRect.bottom - WndRect.top) * ThreadCount - (WndRect.bottom - WndRect.top) * (AskMaxThreadCount() - 1) / 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER);\r
832                                 }\r
833                         }\r
834 //                      TransPacketBase->hWndTrans = hWndTrans;\r
835                         Pos->hWndTrans = hWndTrans;\r
836                         Pos->ctrl_skt = TrnSkt;\r
837                         Pos->ThreadCount = ThreadCount;\r
838 \r
839                         if(hWndTrans != NULL)\r
840                         {\r
841                                 if(MoveToForeground == YES)\r
842                                 {\r
843                                         SetForegroundWindow(hWndTrans);\r
844                                         MoveToForeground = NO;\r
845                                 }\r
846                         }\r
847 \r
848                         if(hWndTrans != NULL)\r
849 //                              SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)TransPacketBase);\r
850                                 SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)Pos);\r
851 \r
852                         /* ダウンロード */\r
853 //                      if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
854                         if(strncmp(Pos->Cmd, "RETR", 4) == 0)\r
855                         {\r
856                                 // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
857 //                              ReleaseMutex(hListAccMutex);\r
858                                 /* 不正なパスを検出 */\r
859 //                              if(CheckPathViolation(TransPacketBase) == NO)\r
860                                 if(CheckPathViolation(Pos) == NO)\r
861                                 {\r
862                                         /* フルパスを使わないための処理 */\r
863 //                                      if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
864                                         if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
865                                         {\r
866 //                                              if(strncmp(TransPacketBase->Cmd, "RETR-S", 6) == 0)\r
867                                                 if(strncmp(Pos->Cmd, "RETR-S", 6) == 0)\r
868                                                 {\r
869                                                         /* サイズと日付を取得 */\r
870 //                                                      DoSIZE(TransPacketBase->RemoteFile, &TransPacketBase->Size);\r
871 //                                                      DoMDTM(TransPacketBase->RemoteFile, &TransPacketBase->Time);\r
872 //                                                      strcpy(TransPacketBase->Cmd, "RETR ");\r
873                                                         DoSIZE(TrnSkt, Pos->RemoteFile, &Pos->Size, &Canceled[Pos->ThreadCount]);\r
874                                                         DoMDTM(TrnSkt, Pos->RemoteFile, &Pos->Time, &Canceled[Pos->ThreadCount]);\r
875                                                         strcpy(Pos->Cmd, "RETR ");\r
876                                                 }\r
877 \r
878                                                 Down = YES;\r
879 //                                              if(DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO) == 429)\r
880 //                                              {\r
881 //                                                      if(ReConnectTrnSkt() == FFFTP_SUCCESS)\r
882 //                                                              DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO, &Canceled);\r
883                                                                 DoDownLoad(TrnSkt, Pos, NO, &Canceled[Pos->ThreadCount]);\r
884 //                                              }\r
885                                         }\r
886                                 }\r
887                                 // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
888                                 ReleaseMutex(hListAccMutex);\r
889                         }\r
890                         /* アップロード */\r
891 //                      else if(strncmp(TransPacketBase->Cmd, "STOR", 4) == 0)\r
892                         else if(strncmp(Pos->Cmd, "STOR", 4) == 0)\r
893                         {\r
894                                 // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
895 //                              ReleaseMutex(hListAccMutex);\r
896                                 /* フルパスを使わないための処理 */\r
897 //                              if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
898                                 if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
899                                 {\r
900                                         Up = YES;\r
901 //                                      if(DoUpLoad(AskTrnCtrlSkt(), TransPacketBase) == 429)\r
902 //                                      {\r
903 //                                              if(ReConnectTrnSkt() == FFFTP_SUCCESS)\r
904 //                                                      DoUpLoad(AskTrnCtrlSkt(), TransPacketBase);\r
905                                                         DoUpLoad(TrnSkt, Pos);\r
906 //                                      }\r
907                                 }\r
908                                 // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
909                                 ReleaseMutex(hListAccMutex);\r
910                         }\r
911                         /* フォルダ作成(ローカルまたはホスト) */\r
912 //                      else if(strncmp(TransPacketBase->Cmd, "MKD", 3) == 0)\r
913                         else if(strncmp(Pos->Cmd, "MKD", 3) == 0)\r
914                         {\r
915 //                              DispTransFileInfo(TransPacketBase, MSGJPN078, FALSE, YES);\r
916                                 DispTransFileInfo(Pos, MSGJPN078, FALSE, YES);\r
917 \r
918 //                              if(strlen(TransPacketBase->RemoteFile) > 0)\r
919                                 if(strlen(Pos->RemoteFile) > 0)\r
920                                 {\r
921                                         /* フルパスを使わないための処理 */\r
922                                         CwdSts = FTP_COMPLETE;\r
923 \r
924 //                                      strcpy(Tmp, TransPacketBase->RemoteFile);\r
925                                         strcpy(Tmp, Pos->RemoteFile);\r
926 //                                      if(ProcForNonFullpath(Tmp, CurDir, hWndTrans, 1) == FFFTP_FAIL)\r
927                                         if(ProcForNonFullpath(TrnSkt, Tmp, CurDir[Pos->ThreadCount], hWndTrans, &Canceled[Pos->ThreadCount]) == FFFTP_FAIL)\r
928                                         {\r
929                                                 ClearAll = YES;\r
930                                                 CwdSts = FTP_ERROR;\r
931                                         }\r
932 \r
933                                         if(CwdSts == FTP_COMPLETE)\r
934                                         {\r
935                                                 Up = YES;\r
936 //                                              CommandProcTrn(NULL, "MKD %s", Tmp);\r
937                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "MKD %s", Tmp);\r
938                                                 /* すでにフォルダがある場合もあるので、 */\r
939                                                 /* ここではエラーチェックはしない */\r
940 \r
941                                         if(FolderAttr)\r
942 //                                              CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
943                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Tmp);\r
944                                         }\r
945                                 }\r
946 //                              else if(strlen(TransPacketBase->LocalFile) > 0)\r
947                                 else if(strlen(Pos->LocalFile) > 0)\r
948                                 {\r
949                                         Down = YES;\r
950 //                                      DoLocalMKD(TransPacketBase->LocalFile);\r
951                                         DoLocalMKD(Pos->LocalFile);\r
952                                 }\r
953                                 ReleaseMutex(hListAccMutex);\r
954                         }\r
955                         /* ディレクトリ作成(常にホスト側) */\r
956 //                      else if(strncmp(TransPacketBase->Cmd, "R-MKD", 5) == 0)\r
957                         else if(strncmp(Pos->Cmd, "R-MKD", 5) == 0)\r
958                         {\r
959 //                              DispTransFileInfo(TransPacketBase, MSGJPN079, FALSE, YES);\r
960                                 DispTransFileInfo(Pos, MSGJPN079, FALSE, YES);\r
961 \r
962                                 /* フルパスを使わないための処理 */\r
963 //                              if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
964                                 if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
965                                 {\r
966                                         Up = YES;\r
967 //                                      CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
968                                         CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
969 \r
970                                         if(FolderAttr)\r
971 //                                              CommandProcTrn(NULL, "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, TransPacketBase->RemoteFile);\r
972                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s %03d %s", AskHostChmodCmd(), FolderAttrNum, Pos->RemoteFile);\r
973                                 }\r
974                                 ReleaseMutex(hListAccMutex);\r
975                         }\r
976                         /* ディレクトリ削除(常にホスト側) */\r
977 //                      else if(strncmp(TransPacketBase->Cmd, "R-RMD", 5) == 0)\r
978                         else if(strncmp(Pos->Cmd, "R-RMD", 5) == 0)\r
979                         {\r
980 //                              DispTransFileInfo(TransPacketBase, MSGJPN080, FALSE, YES);\r
981                                 DispTransFileInfo(Pos, MSGJPN080, FALSE, YES);\r
982 \r
983 //                              DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
984                                 DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, Pos);\r
985                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
986                                 {\r
987                                         /* フルパスを使わないための処理 */\r
988 //                                      if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
989                                         if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
990                                         {\r
991                                                 Up = YES;\r
992 //                                              CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
993                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
994                                         }\r
995                                 }\r
996                                 ReleaseMutex(hListAccMutex);\r
997                         }\r
998                         /* ファイル削除(常にホスト側) */\r
999 //                      else if(strncmp(TransPacketBase->Cmd, "R-DELE", 6) == 0)\r
1000                         else if(strncmp(Pos->Cmd, "R-DELE", 6) == 0)\r
1001                         {\r
1002 //                              DispTransFileInfo(TransPacketBase, MSGJPN081, FALSE, YES);\r
1003                                 DispTransFileInfo(Pos, MSGJPN081, FALSE, YES);\r
1004 \r
1005 //                              DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, TransPacketBase);\r
1006                                 DelNotify = MirrorDelNotify(WIN_REMOTE, DelNotify, Pos);\r
1007                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
1008                                 {\r
1009                                         /* フルパスを使わないための処理 */\r
1010 //                                      if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == FFFTP_SUCCESS)\r
1011                                         if(MakeNonFullPath(Pos, CurDir[Pos->ThreadCount], Tmp) == FFFTP_SUCCESS)\r
1012                                         {\r
1013                                                 Up = YES;\r
1014 //                                              CommandProcTrn(NULL, "%s%s", TransPacketBase->Cmd+2, TransPacketBase->RemoteFile);\r
1015                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "%s%s", Pos->Cmd+2, Pos->RemoteFile);\r
1016                                         }\r
1017                                 }\r
1018                                 ReleaseMutex(hListAccMutex);\r
1019                         }\r
1020                         /* ディレクトリ作成(常にローカル側) */\r
1021 //                      else if(strncmp(TransPacketBase->Cmd, "L-MKD", 5) == 0)\r
1022                         else if(strncmp(Pos->Cmd, "L-MKD", 5) == 0)\r
1023                         {\r
1024 //                              DispTransFileInfo(TransPacketBase, MSGJPN082, FALSE, YES);\r
1025                                 DispTransFileInfo(Pos, MSGJPN082, FALSE, YES);\r
1026 \r
1027                                 Down = YES;\r
1028 //                              DoLocalMKD(TransPacketBase->LocalFile);\r
1029                                 DoLocalMKD(Pos->LocalFile);\r
1030                                 ReleaseMutex(hListAccMutex);\r
1031                         }\r
1032                         /* ディレクトリ削除(常にローカル側) */\r
1033 //                      else if(strncmp(TransPacketBase->Cmd, "L-RMD", 5) == 0)\r
1034                         else if(strncmp(Pos->Cmd, "L-RMD", 5) == 0)\r
1035                         {\r
1036 //                              DispTransFileInfo(TransPacketBase, MSGJPN083, FALSE, YES);\r
1037                                 DispTransFileInfo(Pos, MSGJPN083, FALSE, YES);\r
1038 \r
1039 //                              DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
1040                                 DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, Pos);\r
1041                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
1042                                 {\r
1043                                         Down = YES;\r
1044 //                                      DoLocalRMD(TransPacketBase->LocalFile);\r
1045                                         DoLocalRMD(Pos->LocalFile);\r
1046                                 }\r
1047                                 ReleaseMutex(hListAccMutex);\r
1048                         }\r
1049                         /* ファイル削除(常にローカル側) */\r
1050 //                      else if(strncmp(TransPacketBase->Cmd, "L-DELE", 6) == 0)\r
1051                         else if(strncmp(Pos->Cmd, "L-DELE", 6) == 0)\r
1052                         {\r
1053 //                              DispTransFileInfo(TransPacketBase, MSGJPN084, FALSE, YES);\r
1054                                 DispTransFileInfo(Pos, MSGJPN084, FALSE, YES);\r
1055 \r
1056 //                              DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, TransPacketBase);\r
1057                                 DelNotify = MirrorDelNotify(WIN_LOCAL, DelNotify, Pos);\r
1058                                 if((DelNotify == YES) || (DelNotify == YES_ALL))\r
1059                                 {\r
1060                                         Down = YES;\r
1061 //                                      DoLocalDELE(TransPacketBase->LocalFile);\r
1062                                         DoLocalDELE(Pos->LocalFile);\r
1063                                 }\r
1064                                 ReleaseMutex(hListAccMutex);\r
1065                         }\r
1066                         /* カレントディレクトリを設定 */\r
1067 //                      else if(strcmp(TransPacketBase->Cmd, "SETCUR") == 0)\r
1068                         else if(strcmp(Pos->Cmd, "SETCUR") == 0)\r
1069                         {\r
1070 //                              if(AskShareProh() == YES)\r
1071                                 if(AskReuseCmdSkt() == NO || AskShareProh() == YES)\r
1072                                 {\r
1073 //                                      if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
1074                                         if(strcmp(CurDir[Pos->ThreadCount], Pos->RemoteFile) != 0)\r
1075                                         {\r
1076 //                                              if(CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile)/100 != FTP_COMPLETE)\r
1077                                                 if(CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "CWD %s", Pos->RemoteFile)/100 != FTP_COMPLETE)\r
1078                                                 {\r
1079                                                         DispCWDerror(hWndTrans);\r
1080                                                         ClearAll = YES;\r
1081                                                 }\r
1082                                         }\r
1083                                 }\r
1084 //                              strcpy(CurDir, TransPacketBase->RemoteFile);\r
1085                                 strcpy(CurDir[Pos->ThreadCount], Pos->RemoteFile);\r
1086                                 ReleaseMutex(hListAccMutex);\r
1087                         }\r
1088                         /* カレントディレクトリを戻す */\r
1089 //                      else if(strcmp(TransPacketBase->Cmd, "BACKCUR") == 0)\r
1090                         else if(strcmp(Pos->Cmd, "BACKCUR") == 0)\r
1091                         {\r
1092 //                              if(AskShareProh() == NO)\r
1093                                 if(AskReuseCmdSkt() == YES && AskShareProh() == NO)\r
1094                                 {\r
1095 //                                      if(strcmp(CurDir, TransPacketBase->RemoteFile) != 0)\r
1096 //                                              CommandProcTrn(NULL, "CWD %s", TransPacketBase->RemoteFile);\r
1097 //                                      strcpy(CurDir, TransPacketBase->RemoteFile);\r
1098                                         if(strcmp(CurDir[Pos->ThreadCount], Pos->RemoteFile) != 0)\r
1099                                                 CommandProcTrn(TrnSkt, NULL, &Canceled[Pos->ThreadCount], "CWD %s", Pos->RemoteFile);\r
1100                                         strcpy(CurDir[Pos->ThreadCount], Pos->RemoteFile);\r
1101                                 }\r
1102                                 ReleaseMutex(hListAccMutex);\r
1103                         }\r
1104                         /* 自動終了のための通知 */\r
1105 //                      else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
1106                         else if(strcmp(Pos->Cmd, "GOQUIT") == 0)\r
1107                         {\r
1108                                 ReleaseMutex(hListAccMutex);\r
1109                                 GoExit = YES;\r
1110                         }\r
1111                         else\r
1112                                 ReleaseMutex(hListAccMutex);\r
1113 \r
1114                         /*===== 1つの処理終わり =====*/\r
1115 \r
1116                         if(ForceAbort == NO)\r
1117                         {\r
1118 //                              WaitForSingleObject(hListAccMutex, INFINITE);\r
1119                                 while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
1120                                 {\r
1121                                         BackgrndMessageProc();\r
1122                                         Sleep(1);\r
1123                                 }\r
1124                                 if(ClearAll == YES)\r
1125 //                                      EraseTransFileList();\r
1126                                 {\r
1127                                         for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
1128                                                 Canceled[i] = YES;\r
1129                                         EraseTransFileList();\r
1130                                         Pos = NULL;\r
1131                                 }\r
1132                                 else\r
1133                                 {\r
1134 //                                      if((strncmp(TransPacketBase->Cmd, "RETR", 4) == 0) ||\r
1135 //                                         (strncmp(TransPacketBase->Cmd, "STOR", 4) == 0))\r
1136                                         if((strncmp(Pos->Cmd, "RETR", 4) == 0) ||\r
1137                                            (strncmp(Pos->Cmd, "STOR", 4) == 0))\r
1138                                         {\r
1139 //                                              TransFiles--;\r
1140                                                 if(TransFiles > 0)\r
1141                                                         TransFiles--;\r
1142                                                 PostMessage(GetMainHwnd(), WM_CHANGE_COND, 0, 0);\r
1143                                         }\r
1144 //                                      Pos = TransPacketBase;\r
1145 //                                      TransPacketBase = TransPacketBase->Next;\r
1146 //                                      free(Pos);\r
1147                                 }\r
1148                                 ClearAll = NO;\r
1149                                 ReleaseMutex(hListAccMutex);\r
1150 \r
1151                                 if(BackgrndMessageProc() == YES)\r
1152                                 {\r
1153                                         WaitForSingleObject(hListAccMutex, INFINITE);\r
1154                                         EraseTransFileList();\r
1155                                         ReleaseMutex(hListAccMutex);\r
1156                                 }\r
1157                         }\r
1158                         if(hWndTrans != NULL)\r
1159                                 SendMessage(hWndTrans, WM_SET_PACKET, 0, 0);\r
1160                         if(Pos != NULL)\r
1161                                 strcpy(Pos->Cmd, "");\r
1162                         LastUsed = timeGetTime();\r
1163                 }\r
1164 //              else\r
1165                 else if(TransPacketBase == NULL)\r
1166                 {\r
1167                         DelNotify = NO;\r
1168 \r
1169                         ReleaseMutex(hListAccMutex);\r
1170                         if(KeepDlg == NO)\r
1171                         {\r
1172                                 if(hWndTrans != NULL)\r
1173                                 {\r
1174                                         DestroyWindow(hWndTrans);\r
1175                                         hWndTrans = NULL;\r
1176 \r
1177 //                                      if(GoExit == YES)\r
1178 //                                      {\r
1179 //                                              SoundPlay(SND_TRANS);\r
1180 //\r
1181 //                                              if(AskAutoExit() == NO)\r
1182 //                                              {\r
1183 //                                                      if(Down == YES)\r
1184 //                                                              PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
1185 //                                                      if(Up == YES)\r
1186 //                                                              PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
1187 //                                              }\r
1188 //                                              Down = NO;\r
1189 //                                              Up = NO;\r
1190 //                                      }\r
1191                                 }\r
1192                         }\r
1193                         BackgrndMessageProc();\r
1194 //                      Sleep(1);\r
1195                         Sleep(100);\r
1196 \r
1197                         if(GoExit == YES)\r
1198                         {\r
1199                                 SoundPlay(SND_TRANS);\r
1200                                 if(AskAutoExit() == NO)\r
1201                                 {\r
1202                                         if(Down == YES)\r
1203                                                 PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
1204                                         if(Up == YES)\r
1205                                                 PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
1206                                 }\r
1207                                 Down = NO;\r
1208                                 Up = NO;\r
1209                                 PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_AUTO_EXIT, 0), 0);\r
1210                                 GoExit = NO;\r
1211                         }\r
1212 \r
1213                         // 再転送対応\r
1214                         TransferErrorMode = AskTransferErrorMode();\r
1215                         TransferErrorNotify = AskTransferErrorNotify();\r
1216                 }\r
1217                 else\r
1218                 {\r
1219                         ReleaseMutex(hListAccMutex);\r
1220                         if(hWndTrans != NULL)\r
1221                         {\r
1222                                 DestroyWindow(hWndTrans);\r
1223                                 hWndTrans = NULL;\r
1224                         }\r
1225                         BackgrndMessageProc();\r
1226                         if(ThreadCount < AskMaxThreadCount())\r
1227                                 Sleep(1);\r
1228                         else\r
1229                                 Sleep(100);\r
1230                 }\r
1231         }\r
1232         if(AskReuseCmdSkt() == NO || ThreadCount > 0)\r
1233         {\r
1234                 if(TrnSkt != INVALID_SOCKET)\r
1235                 {\r
1236                         SendData(TrnSkt, "QUIT\r\n", 6, 0, &Canceled[ThreadCount]);\r
1237                         DoClose(TrnSkt);\r
1238                 }\r
1239         }\r
1240         return 0;\r
1241 }\r
1242 \r
1243 \r
1244 /*----- フルパスを使わないファイルアクセスの準備 ------------------------------\r
1245 *\r
1246 *       Parameter\r
1247 *               TRANSPACKET *Pkt : 転送パケット\r
1248 *               char *Cur : カレントディレクトリ\r
1249 *               char *Tmp : 作業用エリア\r
1250 *\r
1251 *       Return Value\r
1252 *               int ステータス(FFFTP_SUCCESS/FFFTP_FAIL)\r
1253 *\r
1254 *       Note\r
1255 *               フルパスを使わない時は、\r
1256 *                       このモジュール内で CWD を行ない、\r
1257 *                       Pkt->RemoteFile にファイル名のみ残す。(パス名は消す)\r
1258 *----------------------------------------------------------------------------*/\r
1259 \r
1260 // 同時接続対応\r
1261 static int MakeNonFullPath(TRANSPACKET *Pkt, char *Cur, char *Tmp)\r
1262 {\r
1263         int Sts;\r
1264 \r
1265 //      Sts = ProcForNonFullpath(Pkt->RemoteFile, Cur, Pkt->hWndTrans, 1);\r
1266         Sts = ProcForNonFullpath(Pkt->ctrl_skt, Pkt->RemoteFile, Cur, Pkt->hWndTrans, &Canceled[Pkt->ThreadCount]);\r
1267         if(Sts == FFFTP_FAIL)\r
1268                 ClearAll = YES;\r
1269 \r
1270         return(Sts);\r
1271 }\r
1272 \r
1273 \r
1274 \r
1275 \r
1276 /*----- ダウンロードを行なう --------------------------------------------------\r
1277 *\r
1278 *       Parameter\r
1279 *               SOCKET cSkt : コントロールソケット\r
1280 *               TRANSPACKET *Pkt : 転送ファイル情報\r
1281 *               int DirList : ディレクトリリストのダウンロード(YES/NO)\r
1282 *\r
1283 *       Return Value\r
1284 *               int 応答コード\r
1285 *\r
1286 *       Note\r
1287 *               このモジュールは、ファイル一覧の取得などを行なう際にメインのスレッド\r
1288 *               からも呼ばれる。メインのスレッドから呼ばれる時は Pkt->hWndTrans == NULL。\r
1289 *----------------------------------------------------------------------------*/\r
1290 \r
1291 int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)\r
1292 {\r
1293         int iRetCode;\r
1294         char Reply[ERR_MSG_LEN+7];\r
1295 \r
1296         Pkt->ctrl_skt = cSkt;\r
1297         if(IsSpecialDevice(GetFileName(Pkt->LocalFile)) == YES)\r
1298         {\r
1299                 iRetCode = 500;\r
1300                 SetTaskMsg(MSGJPN085, GetFileName(Pkt->LocalFile));\r
1301                 DispDownloadFinishMsg(Pkt, iRetCode);\r
1302         }\r
1303         else if(Pkt->Mode != EXIST_IGNORE)\r
1304         {\r
1305                 if(Pkt->Type == TYPE_I)\r
1306                         Pkt->KanjiCode = KANJI_NOCNV;\r
1307 \r
1308                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "TYPE %c", Pkt->Type);\r
1309                 if(iRetCode/100 < FTP_RETRY)\r
1310                 {\r
1311                         if(Pkt->hWndTrans != NULL)\r
1312                         {\r
1313                                 // 同時接続対応\r
1314 //                              AllTransSizeNow = 0;\r
1315                                 AllTransSizeNow[Pkt->ThreadCount] = 0;\r
1316 \r
1317                                 if(DirList == NO)\r
1318                                         DispTransFileInfo(Pkt, MSGJPN086, TRUE, YES);\r
1319                                 else\r
1320                                         DispTransFileInfo(Pkt, MSGJPN087, FALSE, NO);\r
1321                         }\r
1322 \r
1323                         if(BackgrndMessageProc() == NO)\r
1324                         {\r
1325                                 if(AskPasvMode() != YES)\r
1326                                         iRetCode = DownLoadNonPassive(Pkt, CancelCheckWork);\r
1327                                 else\r
1328                                         iRetCode = DownLoadPassive(Pkt, CancelCheckWork);\r
1329                         }\r
1330                         else\r
1331                                 iRetCode = 500;\r
1332                 }\r
1333                 else\r
1334                         SetErrorMsg(Reply);\r
1335         }\r
1336         else\r
1337         {\r
1338                 DispTransFileInfo(Pkt, MSGJPN088, TRUE, YES);\r
1339                 SetTaskMsg(MSGJPN089, Pkt->RemoteFile);\r
1340                 iRetCode = 200;\r
1341         }\r
1342         return(iRetCode);\r
1343 }\r
1344 \r
1345 \r
1346 /*----- 通常モードでファイルをダウンロード ------------------------------------\r
1347 *\r
1348 *       Parameter\r
1349 *               TRANSPACKET *Pkt : 転送ファイル情報\r
1350 *\r
1351 *       Return Value\r
1352 *               int 応答コード\r
1353 *----------------------------------------------------------------------------*/\r
1354 \r
1355 static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
1356 {\r
1357         int iRetCode;\r
1358         int iLength;\r
1359         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1360         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
1361         char Buf[1024];\r
1362         int CreateMode;\r
1363         // IPv6対応\r
1364 //      struct sockaddr_in saSockAddr1;\r
1365         struct sockaddr_in saSockAddrIPv4;\r
1366         struct sockaddr_in6 saSockAddrIPv6;\r
1367         char Reply[ERR_MSG_LEN+7];\r
1368 \r
1369         if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, CancelCheckWork)) != INVALID_SOCKET)\r
1370         {\r
1371                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
1372                 {\r
1373                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1374                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
1375                         if(iRetCode/100 == FTP_PRELIM)\r
1376                         {\r
1377                                 // 同時接続対応\r
1378 //                              if(SocksGet2ndBindReply(listen_socket, &data_socket) == FFFTP_FAIL)\r
1379                                 if(SocksGet2ndBindReply(listen_socket, &data_socket, CancelCheckWork) == FFFTP_FAIL)\r
1380                                 {\r
1381                                         // IPv6対応\r
1382 //                                      iLength = sizeof(saSockAddr1);\r
1383 //                                      data_socket = do_accept(listen_socket, (struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
1384                                         switch(AskCurNetType())\r
1385                                         {\r
1386                                         case NTYPE_IPV4:\r
1387                                                 iLength=sizeof(saSockAddrIPv4);\r
1388                                                 data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv4, (int *)&iLength);\r
1389                                                 break;\r
1390                                         case NTYPE_IPV6:\r
1391                                                 iLength=sizeof(saSockAddrIPv6);\r
1392                                                 data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddrIPv6, (int *)&iLength);\r
1393                                                 break;\r
1394                                         }\r
1395 \r
1396                                         if(shutdown(listen_socket, 1) != 0)\r
1397                                                 ReportWSError("shutdown listen", WSAGetLastError());\r
1398                                         listen_socket = DoClose(listen_socket);\r
1399 \r
1400                                         if(data_socket == INVALID_SOCKET)\r
1401                                         {\r
1402                                                 SetErrorMsg(MSGJPN280);\r
1403                                                 ReportWSError("accept", WSAGetLastError());\r
1404                                                 iRetCode = 500;\r
1405                                         }\r
1406                                         else\r
1407                                                 // IPv6対応\r
1408 //                                              DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
1409                                         {\r
1410                                                 switch(AskCurNetType())\r
1411                                                 {\r
1412                                                 case NTYPE_IPV4:\r
1413                                                         DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddrIPv4.sin_addr), ntohs(saSockAddrIPv4.sin_port));\r
1414                                                         break;\r
1415                                                 case NTYPE_IPV6:\r
1416                                                         DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet6_ntoa(saSockAddrIPv6.sin6_addr), ntohs(saSockAddrIPv6.sin6_port));\r
1417                                                         break;\r
1418                                                 }\r
1419                                         }\r
1420                                 }\r
1421 \r
1422                                 if(data_socket != INVALID_SOCKET)\r
1423                                 {\r
1424                                         // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
1425                                         ReleaseMutex(hListAccMutex);\r
1426                                         // FTPS対応\r
1427 //                                      iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1428                                         if(IsSSLAttached(Pkt->ctrl_skt))\r
1429                                         {\r
1430                                                 if(AttachSSL(data_socket, Pkt->ctrl_skt, CancelCheckWork))\r
1431                                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1432                                                 else\r
1433                                                         iRetCode = 500;\r
1434                                         }\r
1435                                         else\r
1436                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1437 //                                      data_socket = DoClose(data_socket);\r
1438                                 }\r
1439                         }\r
1440                         else\r
1441                         {\r
1442                                 SetErrorMsg(Reply);\r
1443                                 SetTaskMsg(MSGJPN090);\r
1444                                 listen_socket = DoClose(listen_socket);\r
1445                                 iRetCode = 500;\r
1446                         }\r
1447                 }\r
1448                 else\r
1449                         iRetCode = 500;\r
1450         }\r
1451         else\r
1452         {\r
1453                 iRetCode = 500;\r
1454                 SetErrorMsg(MSGJPN279);\r
1455         }\r
1456         DispDownloadFinishMsg(Pkt, iRetCode);\r
1457 \r
1458         return(iRetCode);\r
1459 }\r
1460 \r
1461 \r
1462 /*----- Passiveモードでファイルをダウンロード ---------------------------------\r
1463 *\r
1464 *       Parameter\r
1465 *               TRANSPACKET *Pkt : 転送ファイル情報\r
1466 *\r
1467 *       Return Value\r
1468 *               int 応答コード\r
1469 *----------------------------------------------------------------------------*/\r
1470 \r
1471 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
1472 {\r
1473         int iRetCode;\r
1474         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1475         char Buf[1024];\r
1476         int CreateMode;\r
1477         // IPv6対応\r
1478 //      char Adrs[20];\r
1479         char Adrs[40];\r
1480         int Port;\r
1481         int Flg;\r
1482         char Reply[ERR_MSG_LEN+7];\r
1483 \r
1484         // IPv6対応\r
1485 //      iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
1486         switch(AskCurNetType())\r
1487         {\r
1488         case NTYPE_IPV4:\r
1489                 iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
1490                 break;\r
1491         case NTYPE_IPV6:\r
1492                 iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "EPSV");\r
1493                 break;\r
1494         }\r
1495         if(iRetCode/100 == FTP_COMPLETE)\r
1496         {\r
1497                 // IPv6対応\r
1498 //              if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == FFFTP_SUCCESS)\r
1499                 if(GetAdrsAndPort(Pkt->ctrl_skt, Buf, Adrs, &Port, 39) == FFFTP_SUCCESS)\r
1500                 {\r
1501                         if((data_socket = connectsock(Adrs, Port, MSGJPN091, CancelCheckWork)) != INVALID_SOCKET)\r
1502                         {\r
1503                                 // 変数が未初期化のバグ修正\r
1504                                 Flg = 1;\r
1505                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1506                                         ReportWSError("setsockopt", WSAGetLastError());\r
1507 \r
1508                                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
1509                                 {\r
1510                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1511                                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
1512                                         if(iRetCode/100 == FTP_PRELIM)\r
1513                                         {\r
1514                                                 // 一部TYPE、STOR(RETR)、PORT(PASV)を並列に処理できないホストがあるため\r
1515                                                 ReleaseMutex(hListAccMutex);\r
1516                                                 // FTPS対応\r
1517 //                                              iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1518                                                 if(IsSSLAttached(Pkt->ctrl_skt))\r
1519                                                 {\r
1520                                                         if(AttachSSL(data_socket, Pkt->ctrl_skt, CancelCheckWork))\r
1521                                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1522                                                         else\r
1523                                                                 iRetCode = 500;\r
1524                                                 }\r
1525                                                 else\r
1526                                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1527 //                                              data_socket = DoClose(data_socket);\r
1528                                         }\r
1529                                         else\r
1530                                         {\r
1531                                                 SetErrorMsg(Reply);\r
1532                                                 SetTaskMsg(MSGJPN092);\r
1533                                                 data_socket = DoClose(data_socket);\r
1534                                                 iRetCode = 500;\r
1535                                         }\r
1536                                 }\r
1537                                 else\r
1538                                         iRetCode = 500;\r
1539                         }\r
1540                         else\r
1541                                 iRetCode = 500;\r
1542                 }\r
1543                 else\r
1544                 {\r
1545                         SetErrorMsg(MSGJPN093);\r
1546                         SetTaskMsg(MSGJPN093);\r
1547                         iRetCode = 500;\r
1548                 }\r
1549         }\r
1550         else\r
1551                 SetErrorMsg(Buf);\r
1552 \r
1553         DispDownloadFinishMsg(Pkt, iRetCode);\r
1554 \r
1555         return(iRetCode);\r
1556 }\r
1557 \r
1558 \r
1559 /*----- ダウンロードの実行 ----------------------------------------------------\r
1560 *\r
1561 *       Parameter\r
1562 *               TRANSPACKET *Pkt : 転送ファイル情報\r
1563 *               SOCKET dSkt : データソケット\r
1564 *               int CreateMode : ファイル作成モード (CREATE_ALWAYS/OPEN_ALWAYS)\r
1565 *\r
1566 *       Return Value\r
1567 *               int 応答コード\r
1568 *\r
1569 *       Note\r
1570 *               転送の経過表示は\r
1571 *                       ダイアログを出す(Pkt->hWndTrans!=NULL)場合、インターバルタイマで経過を表示する\r
1572 *                       ダイアログを出さない場合、このルーチンからDispDownloadSize()を呼ぶ\r
1573 *----------------------------------------------------------------------------*/\r
1574 \r
1575 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork)\r
1576 {\r
1577         int iNumBytes;\r
1578         char Buf[BUFSIZE];\r
1579         char Buf2[BUFSIZE+3];\r
1580         HANDLE iFileHandle;\r
1581         SECURITY_ATTRIBUTES Sec;\r
1582         DWORD Writed;\r
1583         CODECONVINFO cInfo;\r
1584         int Continue;\r
1585 //      fd_set ReadFds;\r
1586 //      struct timeval Tout;\r
1587 //      struct timeval *ToutPtr;\r
1588         int iRetCode;\r
1589         int TimeOutErr;\r
1590         char TmpBuf[ONELINE_BUF_SIZE];\r
1591         DWORD dwFileAttributes;\r
1592 \r
1593 #ifdef SET_BUFFER_SIZE\r
1594 /* Add by H.Shirouzu at 2002/10/02 */\r
1595         int buf_size = SOCKBUF_SIZE;\r
1596         for ( ; buf_size > 0; buf_size /= 2)\r
1597                 if (setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
1598                         break;\r
1599 /* End */\r
1600 #endif\r
1601 \r
1602         // 念のため受信バッファを無効にする\r
1603 #ifdef DISABLE_TRANSFER_NETWORK_BUFFERS\r
1604         int buf_size = 0;\r
1605         setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size));\r
1606 #endif\r
1607 \r
1608         Pkt->Abort = ABORT_NONE;\r
1609 \r
1610         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
1611         Sec.lpSecurityDescriptor = NULL;\r
1612         Sec.bInheritHandle = FALSE;\r
1613 \r
1614         dwFileAttributes = GetFileAttributes(Pkt->LocalFile);\r
1615         if (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {\r
1616                 // 読み取り専用\r
1617                 if (MessageBox(GetMainHwnd(), MSGJPN296, MSGJPN086, MB_YESNO) == IDYES) {\r
1618                         // 属性を解除\r
1619                         SetFileAttributes(Pkt->LocalFile, dwFileAttributes ^ FILE_ATTRIBUTE_READONLY);\r
1620                 }\r
1621         }\r
1622 \r
1623         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &Sec, CreateMode, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)\r
1624         {\r
1625                 // UTF-8対応\r
1626                 char Buf3[(BUFSIZE + 3) * 4];\r
1627                 CODECONVINFO cInfo2;\r
1628                 int ProcessedBOM = NO;\r
1629                 // 4GB超対応(kaokunさん提供)\r
1630                 DWORD High = 0;\r
1631                 if(CreateMode == OPEN_ALWAYS)\r
1632                         // 4GB超対応(kaokunさん提供)\r
1633 //                      SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
1634                         SetFilePointer(iFileHandle, 0, &High, FILE_END);\r
1635 \r
1636                 if(Pkt->hWndTrans != NULL)\r
1637                 {\r
1638                         // 同時接続対応\r
1639 //                      TimeStart = time(NULL);\r
1640                         TimeStart[Pkt->ThreadCount] = time(NULL);\r
1641                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
1642                 }\r
1643 \r
1644                 InitCodeConvInfo(&cInfo);\r
1645                 cInfo.KanaCnv = Pkt->KanaCnv;\r
1646 \r
1647                 InitCodeConvInfo(&cInfo2);\r
1648                 cInfo2.KanaCnv = Pkt->KanaCnv;\r
1649 \r
1650                 /*===== ファイルを受信するループ =====*/\r
1651                 while((Pkt->Abort == ABORT_NONE) && (ForceAbort == NO))\r
1652                 {\r
1653 //                      FD_ZERO(&ReadFds);\r
1654 //                      FD_SET(dSkt, &ReadFds);\r
1655 //                      ToutPtr = NULL;\r
1656 //                      if(TimeOut != 0)\r
1657 //                      {\r
1658 //                              Tout.tv_sec = TimeOut;\r
1659 //                              Tout.tv_usec = 0;\r
1660 //                              ToutPtr = &Tout;\r
1661 //                      }\r
1662 //                      iNumBytes = select(0, &ReadFds, NULL, NULL, ToutPtr);\r
1663 //                      if(iNumBytes == SOCKET_ERROR)\r
1664 //                      {\r
1665 //                              ReportWSError("select", WSAGetLastError());\r
1666 //                              if(Pkt->Abort == ABORT_NONE)\r
1667 //                                      Pkt->Abort = ABORT_ERROR;\r
1668 //                              break;\r
1669 //                      }\r
1670 //                      else if(iNumBytes == 0)\r
1671 //                      {\r
1672 //                              SetErrorMsg(MSGJPN094);\r
1673 //                              SetTaskMsg(MSGJPN094);\r
1674 //                              Pkt->Abort = ABORT_ERROR;\r
1675 //                              break;\r
1676 //                      }\r
1677 \r
1678                         if((iNumBytes = do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, CancelCheckWork)) <= 0)\r
1679                         {\r
1680                                 if(TimeOutErr == YES)\r
1681                                 {\r
1682                                         SetErrorMsg(MSGJPN094);\r
1683                                         SetTaskMsg(MSGJPN094);\r
1684                                         if(Pkt->hWndTrans != NULL)\r
1685                                                 ClearAll = YES;\r
1686                                         if(Pkt->Abort == ABORT_NONE)\r
1687                                                 Pkt->Abort = ABORT_ERROR;\r
1688                                 }\r
1689                                 else if(iNumBytes == SOCKET_ERROR)\r
1690                                 {\r
1691                                         if(Pkt->Abort == ABORT_NONE)\r
1692                                                 Pkt->Abort = ABORT_ERROR;\r
1693                                 }\r
1694                                 break;\r
1695                         }\r
1696 \r
1697                         /* 漢字コード変換 */\r
1698                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
1699                         {\r
1700                                 cInfo.Str = Buf;\r
1701                                 cInfo.StrLen = iNumBytes;\r
1702                                 cInfo.Buf = Buf2;\r
1703                                 cInfo.BufSize = BUFSIZE+3;\r
1704                                 do\r
1705                                 {\r
1706                                         // ここで全てUTF-8へ変換する\r
1707                                         // TODO: SJIS以外も直接UTF-8へ変換\r
1708 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
1709 //                                              Continue = ConvJIStoSJIS(&cInfo);\r
1710 //                                      else\r
1711 //                                              Continue = ConvEUCtoSJIS(&cInfo);\r
1712                                         char Buf3[(BUFSIZE + 3) * 4];\r
1713                                         CODECONVINFO cInfo2;\r
1714                                         switch(Pkt->KanjiCode)\r
1715                                         {\r
1716                                         case KANJI_SJIS:\r
1717                                                 switch(Pkt->KanjiCodeDesired)\r
1718                                                 {\r
1719                                                 case KANJI_SJIS:\r
1720 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1721 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1722 //                                                      Continue = NO;\r
1723                                                         // カナ変換のため\r
1724                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1725                                                         cInfo2.Str = cInfo.Buf;\r
1726                                                         cInfo2.StrLen = cInfo.OutLen;\r
1727                                                         cInfo2.Buf = Buf3;\r
1728                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1729                                                         ConvJIStoSJIS(&cInfo2);\r
1730                                                         break;\r
1731                                                 case KANJI_JIS:\r
1732                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1733                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1734                                                         cInfo2.OutLen = cInfo.OutLen;\r
1735                                                         break;\r
1736                                                 case KANJI_EUC:\r
1737                                                         Continue = ConvSJIStoEUC(&cInfo);\r
1738                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1739                                                         cInfo2.OutLen = cInfo.OutLen;\r
1740                                                         break;\r
1741                                                 case KANJI_UTF8N:\r
1742                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
1743                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1744                                                         cInfo2.OutLen = cInfo.OutLen;\r
1745                                                         break;\r
1746                                                 case KANJI_UTF8BOM:\r
1747                                                         if(ProcessedBOM == NO)\r
1748                                                         {\r
1749                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1750                                                                 cInfo2.OutLen = 3;\r
1751                                                                 Continue = YES;\r
1752                                                                 ProcessedBOM = YES;\r
1753                                                                 break;\r
1754                                                         }\r
1755                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
1756                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1757                                                         cInfo2.OutLen = cInfo.OutLen;\r
1758                                                         break;\r
1759                                                 }\r
1760                                                 break;\r
1761                                         case KANJI_JIS:\r
1762                                                 switch(Pkt->KanjiCodeDesired)\r
1763                                                 {\r
1764                                                 case KANJI_SJIS:\r
1765                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1766                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1767                                                         cInfo2.OutLen = cInfo.OutLen;\r
1768                                                         break;\r
1769                                                 case KANJI_JIS:\r
1770 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1771 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1772 //                                                      Continue = NO;\r
1773                                                         // カナ変換のため\r
1774                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1775                                                         cInfo2.Str = cInfo.Buf;\r
1776                                                         cInfo2.StrLen = cInfo.OutLen;\r
1777                                                         cInfo2.Buf = Buf3;\r
1778                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1779                                                         ConvSJIStoJIS(&cInfo2);\r
1780                                                         break;\r
1781                                                 case KANJI_EUC:\r
1782                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1783                                                         cInfo2.Str = cInfo.Buf;\r
1784                                                         cInfo2.StrLen = cInfo.OutLen;\r
1785                                                         cInfo2.Buf = Buf3;\r
1786                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1787                                                         ConvSJIStoEUC(&cInfo2);\r
1788                                                         break;\r
1789                                                 case KANJI_UTF8N:\r
1790                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1791                                                         cInfo2.Str = cInfo.Buf;\r
1792                                                         cInfo2.StrLen = cInfo.OutLen;\r
1793                                                         cInfo2.Buf = Buf3;\r
1794                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1795                                                         ConvSJIStoUTF8N(&cInfo2);\r
1796                                                         break;\r
1797                                                 case KANJI_UTF8BOM:\r
1798                                                         if(ProcessedBOM == NO)\r
1799                                                         {\r
1800                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1801                                                                 cInfo2.OutLen = 3;\r
1802                                                                 Continue = YES;\r
1803                                                                 ProcessedBOM = YES;\r
1804                                                                 break;\r
1805                                                         }\r
1806                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1807                                                         cInfo2.Str = cInfo.Buf;\r
1808                                                         cInfo2.StrLen = cInfo.OutLen;\r
1809                                                         cInfo2.Buf = Buf3;\r
1810                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1811                                                         ConvSJIStoUTF8N(&cInfo2);\r
1812                                                         break;\r
1813                                                 }\r
1814                                                 break;\r
1815                                         case KANJI_EUC:\r
1816                                                 switch(Pkt->KanjiCodeDesired)\r
1817                                                 {\r
1818                                                 case KANJI_SJIS:\r
1819                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1820                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1821                                                         cInfo2.OutLen = cInfo.OutLen;\r
1822                                                         break;\r
1823                                                 case KANJI_JIS:\r
1824                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1825                                                         cInfo2.Str = cInfo.Buf;\r
1826                                                         cInfo2.StrLen = cInfo.OutLen;\r
1827                                                         cInfo2.Buf = Buf3;\r
1828                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1829                                                         ConvSJIStoJIS(&cInfo2);\r
1830                                                         break;\r
1831                                                 case KANJI_EUC:\r
1832 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1833 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1834 //                                                      Continue = NO;\r
1835                                                         // カナ変換のため\r
1836                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1837                                                         cInfo2.Str = cInfo.Buf;\r
1838                                                         cInfo2.StrLen = cInfo.OutLen;\r
1839                                                         cInfo2.Buf = Buf3;\r
1840                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1841                                                         ConvSJIStoEUC(&cInfo2);\r
1842                                                         break;\r
1843                                                 case KANJI_UTF8N:\r
1844                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1845                                                         cInfo2.Str = cInfo.Buf;\r
1846                                                         cInfo2.StrLen = cInfo.OutLen;\r
1847                                                         cInfo2.Buf = Buf3;\r
1848                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1849                                                         ConvSJIStoUTF8N(&cInfo2);\r
1850                                                         break;\r
1851                                                 case KANJI_UTF8BOM:\r
1852                                                         if(ProcessedBOM == NO)\r
1853                                                         {\r
1854                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1855                                                                 cInfo2.OutLen = 3;\r
1856                                                                 Continue = YES;\r
1857                                                                 ProcessedBOM = YES;\r
1858                                                                 break;\r
1859                                                         }\r
1860                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1861                                                         cInfo2.Str = cInfo.Buf;\r
1862                                                         cInfo2.StrLen = cInfo.OutLen;\r
1863                                                         cInfo2.Buf = Buf3;\r
1864                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1865                                                         ConvSJIStoUTF8N(&cInfo2);\r
1866                                                         break;\r
1867                                                 }\r
1868                                                 break;\r
1869                                         case KANJI_UTF8N:\r
1870                                                 switch(Pkt->KanjiCodeDesired)\r
1871                                                 {\r
1872                                                 case KANJI_SJIS:\r
1873                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1874                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1875                                                         cInfo2.OutLen = cInfo.OutLen;\r
1876                                                         break;\r
1877                                                 case KANJI_JIS:\r
1878                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1879                                                         cInfo2.Str = cInfo.Buf;\r
1880                                                         cInfo2.StrLen = cInfo.OutLen;\r
1881                                                         cInfo2.Buf = Buf3;\r
1882                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1883                                                         ConvSJIStoJIS(&cInfo2);\r
1884                                                         break;\r
1885                                                 case KANJI_EUC:\r
1886                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1887                                                         cInfo2.Str = cInfo.Buf;\r
1888                                                         cInfo2.StrLen = cInfo.OutLen;\r
1889                                                         cInfo2.Buf = Buf3;\r
1890                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1891                                                         ConvSJIStoEUC(&cInfo2);\r
1892                                                         break;\r
1893                                                 case KANJI_UTF8N:\r
1894                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1895                                                         cInfo2.OutLen = cInfo.StrLen;\r
1896                                                         Continue = NO;\r
1897                                                         break;\r
1898                                                 case KANJI_UTF8BOM:\r
1899                                                         if(ProcessedBOM == NO)\r
1900                                                         {\r
1901                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1902                                                                 cInfo2.OutLen = 3;\r
1903                                                                 Continue = YES;\r
1904                                                                 ProcessedBOM = YES;\r
1905                                                                 break;\r
1906                                                         }\r
1907                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1908                                                         cInfo2.OutLen = cInfo.StrLen;\r
1909                                                         Continue = NO;\r
1910                                                         break;\r
1911                                                 }\r
1912                                                 break;\r
1913                                         case KANJI_UTF8BOM:\r
1914                                                 if(ProcessedBOM == NO)\r
1915                                                 {\r
1916                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
1917                                                         {\r
1918                                                                 cInfo.Str += 3;\r
1919                                                                 cInfo.StrLen -= 3;\r
1920                                                         }\r
1921                                                         cInfo2.OutLen = 0;\r
1922                                                         switch(Pkt->KanjiCodeDesired)\r
1923                                                         {\r
1924                                                         case KANJI_UTF8BOM:\r
1925                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1926                                                                 cInfo2.OutLen = 3;\r
1927                                                                 break;\r
1928                                                         }\r
1929                                                         Continue = YES;\r
1930                                                         ProcessedBOM = YES;\r
1931                                                         break;\r
1932                                                 }\r
1933                                                 switch(Pkt->KanjiCodeDesired)\r
1934                                                 {\r
1935                                                 case KANJI_SJIS:\r
1936                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1937                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1938                                                         cInfo2.OutLen = cInfo.OutLen;\r
1939                                                         break;\r
1940                                                 case KANJI_JIS:\r
1941                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1942                                                         cInfo2.Str = cInfo.Buf;\r
1943                                                         cInfo2.StrLen = cInfo.OutLen;\r
1944                                                         cInfo2.Buf = Buf3;\r
1945                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1946                                                         ConvSJIStoJIS(&cInfo2);\r
1947                                                         break;\r
1948                                                 case KANJI_EUC:\r
1949                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1950                                                         cInfo2.Str = cInfo.Buf;\r
1951                                                         cInfo2.StrLen = cInfo.OutLen;\r
1952                                                         cInfo2.Buf = Buf3;\r
1953                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1954                                                         ConvSJIStoEUC(&cInfo2);\r
1955                                                         break;\r
1956                                                 case KANJI_UTF8N:\r
1957                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1958                                                         cInfo2.OutLen = cInfo.StrLen;\r
1959                                                         Continue = NO;\r
1960                                                         break;\r
1961                                                 case KANJI_UTF8BOM:\r
1962                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1963                                                         cInfo2.OutLen = cInfo.StrLen;\r
1964                                                         Continue = NO;\r
1965                                                         break;\r
1966                                                 }\r
1967                                                 break;\r
1968                                         }\r
1969 //                                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1970                                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1971                                                 Pkt->Abort = ABORT_DISKFULL;\r
1972                                 }\r
1973                                 while((Continue == YES) && (Pkt->Abort == ABORT_NONE));\r
1974                         }\r
1975                         else\r
1976                         {\r
1977                                 if(WriteFile(iFileHandle, Buf, iNumBytes, &Writed, NULL) == FALSE)\r
1978                                         Pkt->Abort = ABORT_DISKFULL;\r
1979                         }\r
1980 \r
1981                         Pkt->ExistSize += iNumBytes;\r
1982                         if(Pkt->hWndTrans != NULL)\r
1983                                 // 同時接続対応\r
1984 //                              AllTransSizeNow += iNumBytes;\r
1985                                 AllTransSizeNow[Pkt->ThreadCount] += iNumBytes;\r
1986                         else\r
1987                         {\r
1988                                 /* 転送ダイアログを出さない時の経過表示 */\r
1989                                 DispDownloadSize(Pkt->ExistSize);\r
1990                         }\r
1991 \r
1992                         if(BackgrndMessageProc() == YES)\r
1993                                 ForceAbort = YES;\r
1994                 }\r
1995 \r
1996                 /* 書き残したデータを書き込む */\r
1997                 if(Pkt->KanjiCode != KANJI_NOCNV)\r
1998                 {\r
1999                         cInfo.Buf = Buf2;\r
2000                         cInfo.BufSize = BUFSIZE+3;\r
2001                         FlushRestData(&cInfo);\r
2002                         switch(Pkt->KanjiCode)\r
2003                         {\r
2004                         case KANJI_SJIS:\r
2005                                 switch(Pkt->KanjiCodeDesired)\r
2006                                 {\r
2007                                 case KANJI_SJIS:\r
2008                                         // カナ変換のため\r
2009                                         cInfo2.Str = cInfo.Buf;\r
2010                                         cInfo2.StrLen = cInfo.OutLen;\r
2011                                         cInfo2.Buf = Buf3;\r
2012                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2013                                         ConvJIStoSJIS(&cInfo2);\r
2014                                         break;\r
2015                                 case KANJI_JIS:\r
2016                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2017                                         cInfo2.OutLen = cInfo.OutLen;\r
2018                                         break;\r
2019                                 case KANJI_EUC:\r
2020                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2021                                         cInfo2.OutLen = cInfo.OutLen;\r
2022                                         break;\r
2023                                 case KANJI_UTF8N:\r
2024                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2025                                         cInfo2.OutLen = cInfo.OutLen;\r
2026                                         break;\r
2027                                 case KANJI_UTF8BOM:\r
2028                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2029                                         cInfo2.OutLen = cInfo.OutLen;\r
2030                                         break;\r
2031                                 }\r
2032                                 break;\r
2033                         case KANJI_JIS:\r
2034                                 switch(Pkt->KanjiCodeDesired)\r
2035                                 {\r
2036                                 case KANJI_SJIS:\r
2037                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2038                                         cInfo2.OutLen = cInfo.OutLen;\r
2039                                         break;\r
2040                                 case KANJI_JIS:\r
2041                                         // カナ変換のため\r
2042                                         cInfo2.Str = cInfo.Buf;\r
2043                                         cInfo2.StrLen = cInfo.OutLen;\r
2044                                         cInfo2.Buf = Buf3;\r
2045                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2046                                         ConvSJIStoJIS(&cInfo2);\r
2047                                         break;\r
2048                                 case KANJI_EUC:\r
2049                                         cInfo2.Str = cInfo.Buf;\r
2050                                         cInfo2.StrLen = cInfo.OutLen;\r
2051                                         cInfo2.Buf = Buf3;\r
2052                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2053                                         ConvSJIStoEUC(&cInfo2);\r
2054                                         break;\r
2055                                 case KANJI_UTF8N:\r
2056                                         cInfo2.Str = cInfo.Buf;\r
2057                                         cInfo2.StrLen = cInfo.OutLen;\r
2058                                         cInfo2.Buf = Buf3;\r
2059                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2060                                         ConvSJIStoUTF8N(&cInfo2);\r
2061                                         break;\r
2062                                 case KANJI_UTF8BOM:\r
2063                                         cInfo2.Str = cInfo.Buf;\r
2064                                         cInfo2.StrLen = cInfo.OutLen;\r
2065                                         cInfo2.Buf = Buf3;\r
2066                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2067                                         ConvSJIStoUTF8N(&cInfo2);\r
2068                                         break;\r
2069                                 }\r
2070                                 break;\r
2071                         case KANJI_EUC:\r
2072                                 switch(Pkt->KanjiCodeDesired)\r
2073                                 {\r
2074                                 case KANJI_SJIS:\r
2075                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2076                                         cInfo2.OutLen = cInfo.OutLen;\r
2077                                         break;\r
2078                                 case KANJI_JIS:\r
2079                                         cInfo2.Str = cInfo.Buf;\r
2080                                         cInfo2.StrLen = cInfo.OutLen;\r
2081                                         cInfo2.Buf = Buf3;\r
2082                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2083                                         ConvSJIStoJIS(&cInfo2);\r
2084                                         break;\r
2085                                 case KANJI_EUC:\r
2086                                         // カナ変換のため\r
2087                                         cInfo2.Str = cInfo.Buf;\r
2088                                         cInfo2.StrLen = cInfo.OutLen;\r
2089                                         cInfo2.Buf = Buf3;\r
2090                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2091                                         ConvSJIStoEUC(&cInfo2);\r
2092                                         break;\r
2093                                 case KANJI_UTF8N:\r
2094                                         cInfo2.Str = cInfo.Buf;\r
2095                                         cInfo2.StrLen = cInfo.OutLen;\r
2096                                         cInfo2.Buf = Buf3;\r
2097                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2098                                         ConvSJIStoUTF8N(&cInfo2);\r
2099                                         break;\r
2100                                 case KANJI_UTF8BOM:\r
2101                                         cInfo2.Str = cInfo.Buf;\r
2102                                         cInfo2.StrLen = cInfo.OutLen;\r
2103                                         cInfo2.Buf = Buf3;\r
2104                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2105                                         ConvSJIStoUTF8N(&cInfo2);\r
2106                                         break;\r
2107                                 }\r
2108                                 break;\r
2109                         case KANJI_UTF8N:\r
2110                                 switch(Pkt->KanjiCodeDesired)\r
2111                                 {\r
2112                                 case KANJI_SJIS:\r
2113                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2114                                         cInfo2.OutLen = cInfo.OutLen;\r
2115                                         break;\r
2116                                 case KANJI_JIS:\r
2117                                         cInfo2.Str = cInfo.Buf;\r
2118                                         cInfo2.StrLen = cInfo.OutLen;\r
2119                                         cInfo2.Buf = Buf3;\r
2120                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2121                                         ConvSJIStoJIS(&cInfo2);\r
2122                                         break;\r
2123                                 case KANJI_EUC:\r
2124                                         cInfo2.Str = cInfo.Buf;\r
2125                                         cInfo2.StrLen = cInfo.OutLen;\r
2126                                         cInfo2.Buf = Buf3;\r
2127                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2128                                         ConvSJIStoEUC(&cInfo2);\r
2129                                         break;\r
2130                                 case KANJI_UTF8N:\r
2131                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2132                                         cInfo2.OutLen = cInfo.OutLen;\r
2133                                         break;\r
2134                                 case KANJI_UTF8BOM:\r
2135                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2136                                         cInfo2.OutLen = cInfo.OutLen;\r
2137                                         break;\r
2138                                 }\r
2139                                 break;\r
2140                         case KANJI_UTF8BOM:\r
2141                                 switch(Pkt->KanjiCodeDesired)\r
2142                                 {\r
2143                                 case KANJI_SJIS:\r
2144                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2145                                         cInfo2.OutLen = cInfo.OutLen;\r
2146                                         break;\r
2147                                 case KANJI_JIS:\r
2148                                         cInfo2.Str = cInfo.Buf;\r
2149                                         cInfo2.StrLen = cInfo.OutLen;\r
2150                                         cInfo2.Buf = Buf3;\r
2151                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2152                                         ConvSJIStoJIS(&cInfo2);\r
2153                                         break;\r
2154                                 case KANJI_EUC:\r
2155                                         cInfo2.Str = cInfo.Buf;\r
2156                                         cInfo2.StrLen = cInfo.OutLen;\r
2157                                         cInfo2.Buf = Buf3;\r
2158                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2159                                         ConvSJIStoEUC(&cInfo2);\r
2160                                         break;\r
2161                                 case KANJI_UTF8N:\r
2162                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2163                                         cInfo2.OutLen = cInfo.OutLen;\r
2164                                         break;\r
2165                                 case KANJI_UTF8BOM:\r
2166                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2167                                         cInfo2.OutLen = cInfo.OutLen;\r
2168                                         break;\r
2169                                 }\r
2170                                 break;\r
2171                         }\r
2172 //                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
2173                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
2174                                 Pkt->Abort = ABORT_DISKFULL;\r
2175                         cInfo2.Buf = Buf3;\r
2176                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2177                         FlushRestData(&cInfo2);\r
2178                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
2179                                 Pkt->Abort = ABORT_DISKFULL;\r
2180                 }\r
2181 \r
2182                 /* グラフ表示を更新 */\r
2183                 if(Pkt->hWndTrans != NULL)\r
2184                 {\r
2185                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
2186                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
2187                         // 同時接続対応\r
2188 //                      TimeStart = time(NULL) - TimeStart + 1;\r
2189                         TimeStart[Pkt->ThreadCount] = time(NULL) - TimeStart[Pkt->ThreadCount] + 1;\r
2190                 }\r
2191                 else\r
2192                 {\r
2193                         /* 転送ダイアログを出さない時の経過表示を消す */\r
2194                         DispDownloadSize(-1);\r
2195                 }\r
2196 \r
2197                 /* ファイルのタイムスタンプを合わせる */\r
2198                 if((SaveTimeStamp == YES) &&\r
2199                    ((Pkt->Time.dwLowDateTime != 0) || (Pkt->Time.dwHighDateTime != 0)))\r
2200                 {\r
2201                         SetFileTime(iFileHandle, &Pkt->Time, &Pkt->Time, &Pkt->Time);\r
2202                 }\r
2203 \r
2204                 CloseHandle(iFileHandle);\r
2205 \r
2206                 if(iNumBytes == SOCKET_ERROR)\r
2207                         ReportWSError("recv",WSAGetLastError());\r
2208         }\r
2209         else\r
2210         {\r
2211                 SetErrorMsg(MSGJPN095, Pkt->LocalFile);\r
2212                 SetTaskMsg(MSGJPN095, Pkt->LocalFile);\r
2213                 Pkt->Abort = ABORT_ERROR;\r
2214         }\r
2215 \r
2216 \r
2217         if(shutdown(dSkt, 1) != 0)\r
2218                 ReportWSError("shutdown", WSAGetLastError());\r
2219 \r
2220         DoClose(dSkt);\r
2221 \r
2222         if(ForceAbort == NO)\r
2223         {\r
2224                 /* Abortをホストに伝える */\r
2225                 if(Pkt->Abort != ABORT_NONE && iFileHandle != INVALID_HANDLE_VALUE)\r
2226                 {\r
2227                         SendData(Pkt->ctrl_skt, "\xFF\xF4\xFF", 3, MSG_OOB, CancelCheckWork);   /* MSG_OOBに注意 */\r
2228                         SendData(Pkt->ctrl_skt, "\xF2", 1, 0, CancelCheckWork);\r
2229                         command(Pkt->ctrl_skt, NULL, CancelCheckWork, "ABOR");\r
2230                 }\r
2231         }\r
2232 \r
2233         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, CancelCheckWork, TmpBuf);\r
2234 \r
2235 //#pragma aaa\r
2236 //DoPrintf("##DOWN REPLY : %s", Buf);\r
2237 \r
2238         if(Pkt->Abort == ABORT_DISKFULL)\r
2239         {\r
2240                 SetErrorMsg(MSGJPN096);\r
2241                 SetTaskMsg(MSGJPN096);\r
2242         }\r
2243         if(iRetCode >= FTP_RETRY)\r
2244                 SetErrorMsg(Buf);\r
2245         if(Pkt->Abort != ABORT_NONE)\r
2246                 iRetCode = 500;\r
2247 \r
2248         return(iRetCode);\r
2249 }\r
2250 \r
2251 \r
2252 /*----- ダウンロード終了/中止時のメッセージを表示 ----------------------------\r
2253 *\r
2254 *       Parameter\r
2255 *               TRANSPACKET *Pkt : 転送ファイル情報\r
2256 *               int iRetCode : 応答コード\r
2257 *\r
2258 *       Return Value\r
2259 *               なし\r
2260 *----------------------------------------------------------------------------*/\r
2261 \r
2262 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
2263 {\r
2264         char Fname[FMAX_PATH+1];\r
2265 \r
2266         if(ForceAbort == NO)\r
2267         {\r
2268                 if((iRetCode/100) >= FTP_CONTINUE)\r
2269                 {\r
2270                         strcpy(Fname, Pkt->RemoteFile);\r
2271 \r
2272 #if defined(HAVE_OPENVMS)\r
2273                         /* OpenVMSの場合、空ディレクトリへ移動すると550 File not foundになって\r
2274                          * エラーダイアログやエラーメッセージが出るので何もしない */\r
2275                         if (AskHostType() == HTYPE_VMS)\r
2276                                 return;\r
2277 #endif\r
2278 \r
2279                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
2280                         {\r
2281                                 SetTaskMsg(MSGJPN097);\r
2282                                 strcpy(Fname, MSGJPN098);\r
2283                         }\r
2284                         // 同時接続対応\r
2285 //                      else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2286 //                              SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
2287                         else if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
2288                                 SetTaskMsg(MSGJPN099, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
2289                         else\r
2290                                 SetTaskMsg(MSGJPN100);\r
2291 \r
2292                         if(Pkt->Abort != ABORT_USER)\r
2293                         {\r
2294                                 // 全て中止を選択後にダイアログが表示されるバグ対策\r
2295 //                              if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
2296                                 // 再転送対応\r
2297 //                              if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO && DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
2298 //                                      ClearAll = YES;\r
2299                                 if(Canceled[Pkt->ThreadCount] == NO && ClearAll == NO)\r
2300                                 {\r
2301                                         if(strncmp(Pkt->Cmd, "RETR", 4) == 0 || strncmp(Pkt->Cmd, "STOR", 4) == 0)\r
2302                                         {\r
2303                                                 if(TransferErrorNotify == YES && DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Pkt) == NO)\r
2304                                                         ClearAll = YES;\r
2305                                                 else\r
2306                                                 {\r
2307                                                         Pkt->Mode = TransferErrorMode;\r
2308                                                         AddTransFileList(Pkt);\r
2309                                                 }\r
2310                                         }\r
2311                                 }\r
2312                         }\r
2313                 }\r
2314                 else\r
2315                 {\r
2316                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
2317                                 SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
2318                         // 同時接続対応\r
2319 //                      else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2320 //                              SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
2321                         else if((Pkt->hWndTrans != NULL) && (TimeStart[Pkt->ThreadCount] != 0))\r
2322                                 // "0 B/S"と表示されるバグを修正\r
2323                                 // 原因は%dにあたる部分に64ビット値が渡されているため\r
2324 //                              SetTaskMsg(MSGJPN102, TimeStart[Pkt->ThreadCount], Pkt->ExistSize/TimeStart[Pkt->ThreadCount]);\r
2325                                 SetTaskMsg(MSGJPN102, (LONG)TimeStart[Pkt->ThreadCount], (LONG)(Pkt->ExistSize/TimeStart[Pkt->ThreadCount]));\r
2326                         else\r
2327                                 SetTaskMsg(MSGJPN103, Pkt->ExistSize);\r
2328                 }\r
2329         }\r
2330         return;\r
2331 }\r
2332 \r
2333 \r
2334 /*----- ダウンロード/アップロードエラーのダイアログを表示 --------------------\r
2335 *\r
2336 *       Parameter\r
2337 *               int RedID : ダイアログボックスのリソースID\r
2338 *               HWND hWnd : 書き込み中ダイアログのウインドウ\r
2339 *               char *Fname : ファイル名\r
2340 *\r
2341 *       Return Value\r
2342 *               int ステータス (YES=中止/NO=全て中止)\r
2343 *----------------------------------------------------------------------------*/\r
2344 \r
2345 // 再転送対応\r
2346 //static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
2347 static int DispUpDownErrDialog(int ResID, HWND hWnd, TRANSPACKET *Pkt)\r
2348 {\r
2349         if(hWnd == NULL)\r
2350                 hWnd = GetMainHwnd();\r
2351 \r
2352         SoundPlay(SND_ERROR);\r
2353         // 再転送対応\r
2354 //      return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
2355         return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Pkt));\r
2356 }\r
2357 \r
2358 \r
2359 /*----- ダウンロードエラー/アップロードエラーダイアログのコールバック --------\r
2360 *\r
2361 *       Parameter\r
2362 *               HWND hDlg : ウインドウハンドル\r
2363 *               UINT message : メッセージ番号\r
2364 *               WPARAM wParam : メッセージの WPARAM 引数\r
2365 *               LPARAM lParam : メッセージの LPARAM 引数\r
2366 *\r
2367 *       Return Value\r
2368 *               BOOL TRUE/FALSE\r
2369 *----------------------------------------------------------------------------*/\r
2370 \r
2371 // 64ビット対応\r
2372 //static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2373 static INT_PTR CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
2374 {\r
2375         static TRANSPACKET *Pkt;\r
2376         static const RADIOBUTTON DownExistButton[] = {\r
2377                 { DOWN_EXIST_OVW, EXIST_OVW },\r
2378                 { DOWN_EXIST_RESUME, EXIST_RESUME },\r
2379                 { DOWN_EXIST_IGNORE, EXIST_IGNORE }\r
2380         };\r
2381         #define DOWNEXISTBUTTONS        (sizeof(DownExistButton)/sizeof(RADIOBUTTON))\r
2382 \r
2383         switch (message)\r
2384         {\r
2385                 case WM_INITDIALOG :\r
2386                         Pkt = (TRANSPACKET *)lParam;\r
2387 //                      SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
2388                         SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)Pkt->RemoteFile);\r
2389                         // 同時接続対応\r
2390 //                      SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
2391                         SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)GetErrMsg());\r
2392 \r
2393                         if((Pkt->Type == TYPE_A) || (Pkt->ExistSize <= 0))\r
2394                                 EnableWindow(GetDlgItem(hDlg, DOWN_EXIST_RESUME), FALSE);\r
2395 \r
2396                         SetRadioButtonByValue(hDlg, TransferErrorMode, DownExistButton, DOWNEXISTBUTTONS);\r
2397                         return(TRUE);\r
2398 \r
2399                 case WM_COMMAND :\r
2400                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
2401                         {\r
2402                                 case IDOK_ALL :\r
2403                                         TransferErrorNotify = NO;\r
2404                                         /* ここに break はない */\r
2405 \r
2406                                 case IDOK :\r
2407                                         TransferErrorMode = AskRadioButtonValue(hDlg, DownExistButton, DOWNEXISTBUTTONS);\r
2408                                         EndDialog(hDlg, YES);\r
2409                                         break;\r
2410 \r
2411                                 case IDCANCEL :\r
2412                                         EndDialog(hDlg, NO);\r
2413                                         break;\r
2414 \r
2415                                 case IDHELP :\r
2416 //                                      hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000009);\r
2417                                         break;\r
2418                         }\r
2419             return(TRUE);\r
2420         }\r
2421         return(FALSE);\r
2422 }\r
2423 \r
2424 \r
2425 /*----- ダウンロードのリジュームの準備を行う ----------------------------------\r
2426 *\r
2427 *       Parameter\r
2428 *               TRANSPACKET *Pkt : 転送ファイル情報\r
2429 *               iont ProcMode : 処理モード(EXIST_xxx)\r
2430 *               LONGLONG Size : ロード済みのファイルのサイズ\r
2431 *               int *Mode : ファイル作成モード (CREATE_xxxx)\r
2432 *\r
2433 *       Return Value\r
2434 *               int 転送を行うかどうか(YES/NO=このファイルを中止/NO_ALL=全て中止)\r
2435 *\r
2436 *       Note\r
2437 *               Pkt->ExistSizeのセットを行なう\r
2438 *----------------------------------------------------------------------------*/\r
2439 \r
2440 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork)\r
2441 {\r
2442         int iRetCode;\r
2443         int Com;\r
2444         char Reply[ERR_MSG_LEN+7];\r
2445         char Tmp[40];\r
2446 \r
2447         Com = YES;\r
2448 \r
2449         Pkt->ExistSize = 0;\r
2450         *Mode = CREATE_ALWAYS;\r
2451 \r
2452         if(ProcMode == EXIST_RESUME)\r
2453         {\r
2454                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "REST %s", MakeNumString(Size, Tmp, FALSE));\r
2455                 if(iRetCode/100 < FTP_RETRY)\r
2456                 {\r
2457                         /* リジューム */\r
2458                         if(Pkt->hWndTrans != NULL)\r
2459                                 Pkt->ExistSize = Size;\r
2460                         *Mode = OPEN_ALWAYS;\r
2461                 }\r
2462                 else\r
2463                 {\r
2464                         Com = DialogBox(GetFtpInst(), MAKEINTRESOURCE(noresume_dlg), Pkt->hWndTrans, NoResumeWndProc);\r
2465                         if(Com != YES)\r
2466                         {\r
2467                                 if(Com == NO_ALL)               /* 全て中止 */\r
2468                                         ClearAll = YES;\r
2469                                 Pkt->Abort = ABORT_USER;\r
2470                         }\r
2471                 }\r
2472         }\r
2473         return(Com);\r
2474 }\r
2475 \r
2476 \r
2477 /*----- resumeエラーダイアログのコールバック ----------------------------------\r
2478 *\r
2479 *       Parameter\r
2480 *               HWND hDlg : ウインドウハンドル\r
2481 *               UINT message : メッセージ番号\r
2482 *               WPARAM wParam : メッセージの WPARAM 引数\r
2483 *               LPARAM lParam : メッセージの LPARAM 引数\r
2484 *\r
2485 *       Return Value\r
2486 *               BOOL TRUE/FALSE\r
2487 *----------------------------------------------------------------------------*/\r
2488 \r
2489 // 64ビット対応\r
2490 //static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
2491 static INT_PTR CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
2492 {\r
2493         switch (iMessage)\r
2494         {\r
2495                 case WM_INITDIALOG :\r
2496                         return(TRUE);\r
2497 \r
2498                 case WM_COMMAND :\r
2499                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
2500                         {\r
2501                                 case IDOK :\r
2502                                         EndDialog(hDlg, YES);\r
2503                                         break;\r
2504 \r
2505                                 case IDCANCEL :\r
2506                                         EndDialog(hDlg, NO);\r
2507                                         break;\r
2508 \r
2509                                 case RESUME_CANCEL_ALL :\r
2510                                         EndDialog(hDlg, NO_ALL);\r
2511                                         break;\r
2512                         }\r
2513             return(TRUE);\r
2514         }\r
2515         return(FALSE);\r
2516 }\r
2517 \r
2518 \r
2519 \r
2520 /*----- アップロードを行なう --------------------------------------------------\r
2521 *\r
2522 *       Parameter\r
2523 *               SOCKET cSkt : コントロールソケット\r
2524 *               TRANSPACKET *Pkt : 転送ファイル情報\r
2525 *\r
2526 *       Return Value\r
2527 *               int 応答コード\r
2528 *----------------------------------------------------------------------------*/\r
2529 \r
2530 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)\r
2531 {\r
2532         int iRetCode;\r
2533         char Reply[ERR_MSG_LEN+7];\r
2534 \r
2535         Pkt->ctrl_skt = cSkt;\r
2536 \r
2537         if(Pkt->Mode != EXIST_IGNORE)\r
2538         {\r
2539                 if(CheckFileReadable(Pkt->LocalFile) == FFFTP_SUCCESS)\r
2540                 {\r
2541                         if(Pkt->Type == TYPE_I)\r
2542                                 Pkt->KanjiCode = KANJI_NOCNV;\r
2543 \r
2544                         // 同時接続対応\r
2545 //                      iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
2546                         iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "TYPE %c", Pkt->Type);\r
2547                         if(iRetCode/100 < FTP_RETRY)\r
2548                         {\r
2549                                 if(Pkt->Mode == EXIST_UNIQUE)\r
2550                                         strcpy(Pkt->Cmd, "STOU ");\r
2551 \r
2552                                 if(Pkt->hWndTrans != NULL)\r
2553                                         DispTransFileInfo(Pkt, MSGJPN104, TRUE, YES);\r
2554 \r
2555                                 if(BackgrndMessageProc() == NO)\r
2556                                 {\r
2557                                         if(AskPasvMode() != YES)\r
2558                                                 iRetCode = UpLoadNonPassive(Pkt);\r
2559                                         else\r
2560                                                 iRetCode = UpLoadPassive(Pkt);\r
2561                                 }\r
2562                                 else\r
2563                                         iRetCode = 500;\r
2564                         }\r
2565                         else\r
2566                                 SetErrorMsg(Reply);\r
2567 \r
2568                         /* 属性変更 */\r
2569                         if((Pkt->Attr != -1) && ((iRetCode/100) == FTP_COMPLETE))\r
2570                                 // 同時接続対応\r
2571 //                              command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
2572                                 command(Pkt->ctrl_skt, Reply, &Canceled[Pkt->ThreadCount], "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
2573                 }\r
2574                 else\r
2575                 {\r
2576                         SetErrorMsg(MSGJPN105, Pkt->LocalFile);\r
2577                         SetTaskMsg(MSGJPN105, Pkt->LocalFile);\r
2578                         iRetCode = 500;\r
2579                         Pkt->Abort = ABORT_ERROR;\r
2580                         DispUploadFinishMsg(Pkt, iRetCode);\r
2581                 }\r
2582         }\r
2583         else\r
2584         {\r
2585                 DispTransFileInfo(Pkt, MSGJPN106, TRUE, YES);\r
2586                 SetTaskMsg(MSGJPN107, Pkt->LocalFile);\r
2587                 iRetCode = 200;\r
2588         }\r
2589         return(iRetCode);\r
2590 }\r
2591 \r
2592 \r
2593 /*----- 通常モードでファイルをアップロード ------------------------------------\r
2594 *\r
2595 *       Parameter\r
2596 *               TRANSPACKET *Pkt : 転送ファイル情報\r
2597 *\r
2598 *       Return Value\r
2599 *               int 応答コード\r
2600 *----------------------------------------------------------------------------*/\r
2601 \r
2602 static int UpLoadNonPassive(TRANSPACKET *Pkt)\r
2603 {\r
2604         int iRetCode;\r
2605         int iLength;\r
2606         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
2607         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
2608         char Buf[1024];\r
2609         // IPv6対応\r
2610 //      struct sockaddr_in saSockAddr1;\r
2611         struct sockaddr_in saSockAddrIPv4;\r