OSDN Git Service

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