OSDN Git Service

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