OSDN Git Service

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