OSDN Git Service

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