OSDN Git Service

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