OSDN Git Service

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