OSDN Git Service

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