OSDN Git Service

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