OSDN Git Service

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