OSDN Git Service

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