OSDN Git Service

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