OSDN Git Service

Fix bugs of text encoding routines.
[ffftp/ffftp.git] / getput.c
1 /*=============================================================================\r
2 *\r
3 *                                                       \83_\83E\83\93\83\8d\81[\83h\81^\83A\83b\83v\83\8d\81[\83h\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 /* \82±\82Ì\83\\81[\83X\82Í\88ê\95\94\81AWS_FTP Version 93.12.05 \82Ì\83\\81[\83X\82ð\8eQ\8dl\82É\82µ\82Ü\82µ\82½\81B */\r
31 /* \83X\83\8c\83b\83h\82Ì\8dì\90¬\81^\8fI\97¹\82É\8aÖ\82µ\82Ä\81A\94ó\8cû\93a\8dì\90¬\82Ì\83p\83b\83`\82ð\91g\82Ý\8d\9e\82Ý\82Ü\82µ\82½\81B */\r
32 \r
33 /*\r
34         \88ê\95\94\81A\8d\82\91¬\89»\82Ì\82½\82ß\82Ì\83R\81[\83h\92Ç\89Á 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_NETWORK_BUFFERS\r
61 #undef BUFSIZE\r
62 #define BUFSIZE                 (64 * 1024)     // RWIN\92l\88È\89º\82Å\8f[\95ª\82È\91å\82«\82³\82ª\96]\82Ü\82µ\82¢\82Æ\8ev\82í\82ê\82é\81B\r
63 #undef SET_BUFFER_SIZE\r
64 #endif\r
65 \r
66 #define TIMER_DISPLAY           1               /* \95\\8e¦\8dX\90V\97p\83^\83C\83}\82ÌID */\r
67 #define DISPLAY_TIMING          500             /* \95\\8e¦\8dX\90V\8e\9e\8aÔ 0.5\95b */\r
68 \r
69 #define ERR_MSG_LEN                     1024\r
70 \r
71 \r
72 /* \8dí\8f\9c\8am\94F\83_\83C\83A\83\8d\83O\82Ì\8fî\95ñ */\r
73 typedef struct {\r
74         int Cur;\r
75         TRANSPACKET *Pkt;\r
76 } MIRRORDELETEINFO;\r
77 \r
78 \r
79 /*===== \83v\83\8d\83g\83^\83C\83v =====*/\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 /*===== \83\8d\81[\83J\83\8b\82È\83\8f\81[\83N =====*/\r
110 \r
111 static HANDLE hTransferThread;\r
112 static int fTransferThreadExit = FALSE;\r
113 \r
114 static HANDLE hRunMutex;                                /* \93]\91\97\83X\83\8c\83b\83h\8eÀ\8ds\83~\83\85\81[\83e\83b\83N\83X */\r
115 static HANDLE hListAccMutex;                    /* \93]\91\97\83t\83@\83C\83\8b\83A\83N\83Z\83X\97p\83~\83\85\81[\83e\83b\83N\83X */\r
116 \r
117 static int TransFiles = 0;                              /* \93]\91\97\91Ò\82¿\83t\83@\83C\83\8b\90\94 */\r
118 static TRANSPACKET *TransPacketBase = NULL;     /* \93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g */\r
119 \r
120 static int Canceled;            /* \92\86\8e~\83t\83\89\83O YES/NO */\r
121 static int ClearAll;            /* \91S\82Ä\92\86\8e~\83t\83\89\83O YES/NO */\r
122 \r
123 static int ForceAbort;          /* \93]\91\97\92\86\8e~\83t\83\89\83O */\r
124                                                         /* \82±\82Ì\83t\83\89\83O\82Í\83X\83\8c\83b\83h\82ð\8fI\97¹\82³\82¹\82é\82Æ\82«\82É\8eg\82¤ */\r
125 \r
126 static LONGLONG AllTransSizeNow;        /* \8d¡\89ñ\82Ì\93]\91\97\82Å\93]\91\97\82µ\82½\83T\83C\83Y */\r
127 static time_t TimeStart;        /* \93]\91\97\8aJ\8en\8e\9e\8aÔ */\r
128 \r
129 static int KeepDlg = NO;        /* \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82©\82Ç\82¤\82© (YES/NO) */\r
130 static int MoveToForeground = NO;               /* \83E\83C\83\93\83h\83E\82ð\91O\96Ê\82É\88Ú\93®\82·\82é\82©\82Ç\82¤\82© (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 /*===== \8aO\95\94\8eQ\8fÆ =====*/\r
136 \r
137 /* \90Ý\92è\92l */\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 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82ð\8bN\93®\82·\82é ----------------------------------------\r
149 *\r
150 *       Parameter\r
151 *               \82È\82µ\r
152 *\r
153 *       Return Value\r
154 *               \82È\82µ\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(FAIL); /* XXX */\r
171 \r
172         return(SUCCESS);\r
173 }\r
174 \r
175 \r
176 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82ð\8fI\97¹\82·\82é ----------------------------------------\r
177 *\r
178 *       Parameter\r
179 *               \82È\82µ\r
180 *\r
181 *       Return Value\r
182 *               \82È\82µ\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 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\82ð\83\8a\83X\83g\82É\92Ç\89Á\82·\82é --------------------------------\r
208 *\r
209 *       Parameter\r
210 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
211 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
212 *\r
213 *       Return Value\r
214 *               int \83X\83e\81[\83^\83X\r
215 *                       SUCCESS/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 = 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 = SUCCESS;\r
240         }\r
241         return(Sts);\r
242 }\r
243 \r
244 \r
245 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\83\8a\83X\83g\82ð\83N\83\8a\83A\82·\82é --------------------------------\r
246 *\r
247 *       Parameter\r
248 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
249 *\r
250 *       Return Value\r
251 *               \82È\82µ\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 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\83\8a\83X\83g\82©\82ç\82P\82Â\82Ì\8fî\95ñ\82ð\8eæ\82è\8f\9c\82­ --------------------\r
272 *\r
273 *       Parameter\r
274 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
275 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
276 *\r
277 *       Return Value\r
278 *               int \83X\83e\81[\83^\83X\r
279 *                       SUCCESS/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 = FAIL;\r
289         Pos = *Base;\r
290         if(Num == 0)\r
291         {\r
292                 *Base = Pos->Next;\r
293                 free(Pos);\r
294                 Sts = 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 = SUCCESS;\r
307                                 break;\r
308                         }\r
309                 }\r
310         }\r
311         return(Sts);\r
312 }\r
313 \r
314 \r
315 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\8fî\95ñ\82ð\93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82É\93o\98^\82·\82é --------------------\r
316 *\r
317 *       Parameter\r
318 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
319 *\r
320 *       Return Value\r
321 *               \82È\82µ\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) == 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 /*----- \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\82ð\93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82É\92Ç\89Á\82·\82é ------------------------\r
346 *\r
347 *       Parameter\r
348 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
349 *               TRANSPACKET **Base : \83\8a\83X\83g\82Ì\90æ\93ª\r
350 *\r
351 *       Return Value\r
352 *               \82È\82µ\r
353 *\r
354 *       Note\r
355 *               Pkt\8e©\91Ì\82ð\83\8a\83X\83g\82É\98A\8c\8b\82·\82é\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 /*----- \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\82ð\95\\8e¦\82·\82é --------------------------------------------\r
393 *\r
394 *       Parameter\r
395 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
396 *\r
397 *       Return Value\r
398 *               \82È\82µ\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 /*----- \93]\91\97\83t\83@\83C\83\8b\83\8a\83X\83g\82ð\83N\83\8a\83A\82·\82é ----------------------------------------\r
423 *\r
424 *       Parameter\r
425 *               \82È\82µ\r
426 *\r
427 *       Return Value\r
428 *               \82È\82µ\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                 /* \8dÅ\8cã\82Ì"BACKCUR"\82Í\95K\97v\82È\82Ì\82Å\8fÁ\82³\82È\82¢ */\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 /*----- \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82æ\82¤\82É\82·\82é\82©\82Ç\82¤\82©\82ð\90Ý\92è --------------------\r
472 *\r
473 *       Parameter\r
474 *               int Sw : \93]\91\97\92\86\83_\83C\83A\83\8d\83O\82ð\8fÁ\82³\82È\82¢\82©\82Ç\82¤\82© (YES/NO)\r
475 *\r
476 *       Return Value\r
477 *               \82È\82µ\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 /*----- \8c»\8dÝ\93]\91\97\92\86\82©\82Ç\82¤\82©\82ð\95Ô\82· ----------------------------------------------\r
488 *\r
489 *       Parameter\r
490 *               \82È\82µ\r
491 *\r
492 *       Return Value\r
493 *               int \83X\83e\81[\83^\83X (YES/NO=\93]\91\97\92\86\82Å\82Í\82È\82¢)\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 /*----- \93]\91\97\82·\82é\83t\83@\83C\83\8b\82Ì\90\94\82ð\95Ô\82· --------------------------------------------\r
503 *\r
504 *       Parameter\r
505 *               \82È\82µ\r
506 *\r
507 *       Return Value\r
508 *               int \93]\91\97\82·\82é\83t\83@\83C\83\8b\82Ì\90\94\r
509 *----------------------------------------------------------------------------*/\r
510 \r
511 int AskTransferFileNum(void)\r
512 {\r
513         return(TransFiles);\r
514 }\r
515 \r
516 \r
517 /*----- \93]\91\97\92\86\83E\83C\83\93\83h\83E\82ð\91O\96Ê\82É\8fo\82· ------------------------------------------\r
518 *\r
519 *       Parameter\r
520 *               \82È\82µ\r
521 *\r
522 *       Return Value\r
523 *               \82È\82µ\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 /*----- \93]\91\97\83\\83P\83b\83g\82Ì\83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\8fî\95ñ\82ð\8f\89\8aú\89» ------------------------\r
534 *\r
535 *       Parameter\r
536 *               \82È\82µ\r
537 *\r
538 *       Return Value\r
539 *               \82È\82µ\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 /*----- \83t\83@\83C\83\8b\93]\91\97\83X\83\8c\83b\83h\82Ì\83\81\83C\83\93\83\8b\81[\83v ------------------------------------\r
550 *\r
551 *       Parameter\r
552 *               void *Dummy : \8eg\82í\82È\82¢\r
553 *\r
554 *       Return Value\r
555 *               \82È\82µ\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                         /* \83_\83E\83\93\83\8d\81[\83h */\r
618                         if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
619                         {\r
620                                 /* \95s\90³\82È\83p\83X\82ð\8c\9f\8fo */\r
621                                 if(CheckPathViolation(TransPacketBase) == NO)\r
622                                 {\r
623                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
624                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
625                                         {\r
626                                                 if(strncmp(TransPacketBase->Cmd, "RETR-S", 6) == 0)\r
627                                                 {\r
628                                                         /* \83T\83C\83Y\82Æ\93ú\95t\82ð\8eæ\93¾ */\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() == SUCCESS)\r
638                                                                 DoDownLoad(AskTrnCtrlSkt(), TransPacketBase, NO, &Canceled);\r
639 //                                              }\r
640                                         }\r
641                                 }\r
642                         }\r
643                         /* \83A\83b\83v\83\8d\81[\83h */\r
644                         else if(strncmp(TransPacketBase->Cmd, "STOR", 4) == 0)\r
645                         {\r
646                                 /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
647                                 if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == SUCCESS)\r
648                                 {\r
649                                         Up = YES;\r
650 //                                      if(DoUpLoad(AskTrnCtrlSkt(), TransPacketBase) == 429)\r
651 //                                      {\r
652 //                                              if(ReConnectTrnSkt() == SUCCESS)\r
653                                                         DoUpLoad(AskTrnCtrlSkt(), TransPacketBase);\r
654 //                                      }\r
655                                 }\r
656                         }\r
657                         /* \83t\83H\83\8b\83_\8dì\90¬\81i\83\8d\81[\83J\83\8b\82Ü\82½\82Í\83z\83X\83g\81j */\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                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
665                                         CwdSts = FTP_COMPLETE;\r
666 \r
667                                         strcpy(Tmp, TransPacketBase->RemoteFile);\r
668                                         if(ProcForNonFullpath(Tmp, CurDir, hWndTrans, 1) == 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                                                 /* \82·\82Å\82É\83t\83H\83\8b\83_\82ª\82 \82é\8fê\8d\87\82à\82 \82é\82Ì\82Å\81A */\r
679                                                 /* \82±\82±\82Å\82Í\83G\83\89\81[\83`\83F\83b\83N\82Í\82µ\82È\82¢ */\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                         /* \83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\8fí\82É\83z\83X\83g\91¤\81j */\r
692                         else if(strncmp(TransPacketBase->Cmd, "R-MKD", 5) == 0)\r
693                         {\r
694                                 DispTransFileInfo(TransPacketBase, MSGJPN079, FALSE, YES);\r
695 \r
696                                 /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
697                                 if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == 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                         /* \83f\83B\83\8c\83N\83g\83\8a\8dí\8f\9c\81i\8fí\82É\83z\83X\83g\91¤\81j */\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                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
715                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == 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                         /* \83t\83@\83C\83\8b\8dí\8f\9c\81i\8fí\82É\83z\83X\83g\91¤\81j */\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                                         /* \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\82½\82ß\82Ì\8f\88\97\9d */\r
731                                         if(MakeNonFullPath(TransPacketBase, CurDir, Tmp) == 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                         /* \83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\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                         /* \83f\83B\83\8c\83N\83g\83\8a\8dí\8f\9c\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\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                         /* \83t\83@\83C\83\8b\8dí\8f\9c\81i\8fí\82É\83\8d\81[\83J\83\8b\91¤\81j */\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                         /* \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82ð\90Ý\92è */\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                         /* \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\82ð\96ß\82· */\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                         /* \8e©\93®\8fI\97¹\82Ì\82½\82ß\82Ì\92Ê\92m */\r
797                         else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
798                         {\r
799                                 GoExit = YES;\r
800                         }\r
801 \r
802                         /*===== \82P\82Â\82Ì\8f\88\97\9d\8fI\82í\82è =====*/\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 /*----- \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\83t\83@\83C\83\8b\83A\83N\83Z\83X\82Ì\8f\80\94õ ------------------------------\r
874 *\r
875 *       Parameter\r
876 *               TRANSPACKET *Pkt : \93]\91\97\83p\83P\83b\83g\r
877 *               char *Cur : \83J\83\8c\83\93\83g\83f\83B\83\8c\83N\83g\83\8a\r
878 *               char *Tmp : \8dì\8bÆ\97p\83G\83\8a\83A\r
879 *\r
880 *       Return Value\r
881 *               int \83X\83e\81[\83^\83X(SUCCESS/FAIL)\r
882 *\r
883 *       Note\r
884 *               \83t\83\8b\83p\83X\82ð\8eg\82í\82È\82¢\8e\9e\82Í\81A\r
885 *                       \82±\82Ì\83\82\83W\83\85\81[\83\8b\93à\82Å CWD \82ð\8ds\82È\82¢\81A\r
886 *                       Pkt->RemoteFile \82É\83t\83@\83C\83\8b\96¼\82Ì\82Ý\8ec\82·\81B\81i\83p\83X\96¼\82Í\8fÁ\82·\81j\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 == FAIL)\r
895                 ClearAll = YES;\r
896 \r
897         return(Sts);\r
898 }\r
899 \r
900 \r
901 \r
902 \r
903 /*----- \83_\83E\83\93\83\8d\81[\83h\82ð\8ds\82È\82¤ --------------------------------------------------\r
904 *\r
905 *       Parameter\r
906 *               SOCKET cSkt : \83R\83\93\83g\83\8d\81[\83\8b\83\\83P\83b\83g\r
907 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
908 *               int DirList : \83f\83B\83\8c\83N\83g\83\8a\83\8a\83X\83g\82Ì\83_\83E\83\93\83\8d\81[\83h(YES/NO)\r
909 *\r
910 *       Return Value\r
911 *               int \89\9e\93\9a\83R\81[\83h\r
912 *\r
913 *       Note\r
914 *               \82±\82Ì\83\82\83W\83\85\81[\83\8b\82Í\81A\83t\83@\83C\83\8b\88ê\97\97\82Ì\8eæ\93¾\82È\82Ç\82ð\8ds\82È\82¤\8dÛ\82É\83\81\83C\83\93\82Ì\83X\83\8c\83b\83h\r
915 *               \82©\82ç\82à\8cÄ\82Î\82ê\82é\81B\83\81\83C\83\93\82Ì\83X\83\8c\83b\83h\82©\82ç\8cÄ\82Î\82ê\82é\8e\9e\82Í Pkt->hWndTrans == NULL\81B\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 /*----- \92Ê\8fí\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83_\83E\83\93\83\8d\81[\83h ------------------------------------\r
972 *\r
973 *       Parameter\r
974 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
975 *\r
976 *       Return Value\r
977 *               int \89\9e\93\9a\83R\81[\83h\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) == 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                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1021 //                                      data_socket = DoClose(data_socket);\r
1022                                 }\r
1023                         }\r
1024                         else\r
1025                         {\r
1026                                 SetErrorMsg(Reply);\r
1027                                 SetTaskMsg(MSGJPN090);\r
1028                                 listen_socket = DoClose(listen_socket);\r
1029                                 iRetCode = 500;\r
1030                         }\r
1031                 }\r
1032                 else\r
1033                         iRetCode = 500;\r
1034         }\r
1035         else\r
1036         {\r
1037                 iRetCode = 500;\r
1038                 SetErrorMsg(MSGJPN279);\r
1039         }\r
1040         DispDownloadFinishMsg(Pkt, iRetCode);\r
1041 \r
1042         return(iRetCode);\r
1043 }\r
1044 \r
1045 \r
1046 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83_\83E\83\93\83\8d\81[\83h ---------------------------------\r
1047 *\r
1048 *       Parameter\r
1049 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1050 *\r
1051 *       Return Value\r
1052 *               int \89\9e\93\9a\83R\81[\83h\r
1053 *----------------------------------------------------------------------------*/\r
1054 \r
1055 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
1056 {\r
1057         int iRetCode;\r
1058         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1059         char Buf[1024];\r
1060         int CreateMode;\r
1061         char Adrs[20];\r
1062         int Port;\r
1063         int Flg;\r
1064         char Reply[ERR_MSG_LEN+7];\r
1065 \r
1066         iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
1067         if(iRetCode/100 == FTP_COMPLETE)\r
1068         {\r
1069                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
1070                 {\r
1071                         if((data_socket = connectsock(Adrs, Port, MSGJPN091, CancelCheckWork)) != INVALID_SOCKET)\r
1072                         {\r
1073                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1074                                         ReportWSError("setsockopt", WSAGetLastError());\r
1075 \r
1076                                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
1077                                 {\r
1078                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1079                                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
1080                                         if(iRetCode/100 == FTP_PRELIM)\r
1081                                         {\r
1082                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1083 //                                              data_socket = DoClose(data_socket);\r
1084                                         }\r
1085                                         else\r
1086                                         {\r
1087                                                 SetErrorMsg(Reply);\r
1088                                                 SetTaskMsg(MSGJPN092);\r
1089                                                 data_socket = DoClose(data_socket);\r
1090                                                 iRetCode = 500;\r
1091                                         }\r
1092                                 }\r
1093                                 else\r
1094                                         iRetCode = 500;\r
1095                         }\r
1096                         else\r
1097                                 iRetCode = 500;\r
1098                 }\r
1099                 else\r
1100                 {\r
1101                         SetErrorMsg(MSGJPN093);\r
1102                         SetTaskMsg(MSGJPN093);\r
1103                         iRetCode = 500;\r
1104                 }\r
1105         }\r
1106         else\r
1107                 SetErrorMsg(Buf);\r
1108 \r
1109         DispDownloadFinishMsg(Pkt, iRetCode);\r
1110 \r
1111         return(iRetCode);\r
1112 }\r
1113 \r
1114 \r
1115 /*----- \83_\83E\83\93\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
1116 *\r
1117 *       Parameter\r
1118 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1119 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
1120 *               int CreateMode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_ALWAYS/OPEN_ALWAYS)\r
1121 *\r
1122 *       Return Value\r
1123 *               int \89\9e\93\9a\83R\81[\83h\r
1124 *\r
1125 *       Note\r
1126 *               \93]\91\97\82Ì\8co\89ß\95\\8e¦\82Í\r
1127 *                       \83_\83C\83A\83\8d\83O\82ð\8fo\82·(Pkt->hWndTrans!=NULL)\8fê\8d\87\81A\83C\83\93\83^\81[\83o\83\8b\83^\83C\83}\82Å\8co\89ß\82ð\95\\8e¦\82·\82é\r
1128 *                       \83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8fê\8d\87\81A\82±\82Ì\83\8b\81[\83`\83\93\82©\82çDispDownloadSize()\82ð\8cÄ\82Ô\r
1129 *----------------------------------------------------------------------------*/\r
1130 \r
1131 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork)\r
1132 {\r
1133         int iNumBytes;\r
1134         char Buf[BUFSIZE];\r
1135         char Buf2[BUFSIZE+3];\r
1136         HANDLE iFileHandle;\r
1137         SECURITY_ATTRIBUTES Sec;\r
1138         DWORD Writed;\r
1139         CODECONVINFO cInfo;\r
1140         int Continue;\r
1141 //      fd_set ReadFds;\r
1142 //      struct timeval Tout;\r
1143 //      struct timeval *ToutPtr;\r
1144         int iRetCode;\r
1145         int TimeOutErr;\r
1146         char TmpBuf[ONELINE_BUF_SIZE];\r
1147         DWORD dwFileAttributes;\r
1148 \r
1149 #ifdef SET_BUFFER_SIZE\r
1150 /* Add by H.Shirouzu at 2002/10/02 */\r
1151         int buf_size = SOCKBUF_SIZE;\r
1152         for ( ; buf_size > 0; buf_size /= 2)\r
1153                 if (setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
1154                         break;\r
1155 /* End */\r
1156 #endif\r
1157 \r
1158 #ifdef DISABLE_NETWORK_BUFFERS\r
1159         // \94O\82Ì\82½\82ß\8eó\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\81B\r
1160         int buf_size = 0;\r
1161         setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size));\r
1162 #endif\r
1163 \r
1164         Pkt->Abort = ABORT_NONE;\r
1165 \r
1166         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
1167         Sec.lpSecurityDescriptor = NULL;\r
1168         Sec.bInheritHandle = FALSE;\r
1169 \r
1170         dwFileAttributes = GetFileAttributes(Pkt->LocalFile);\r
1171         if (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {\r
1172                 // \93Ç\82Ý\8eæ\82è\90ê\97p\r
1173                 if (MessageBox(GetMainHwnd(), MSGJPN296, MSGJPN086, MB_YESNO) == IDYES) {\r
1174                         // \91®\90«\82ð\89ð\8f\9c\r
1175                         SetFileAttributes(Pkt->LocalFile, dwFileAttributes ^ FILE_ATTRIBUTE_READONLY);\r
1176                 }\r
1177         }\r
1178 \r
1179         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
1180         {\r
1181                 // UTF-8\91Î\89\9e\r
1182                 char Buf3[(BUFSIZE + 3) * 4];\r
1183                 CODECONVINFO cInfo2;\r
1184                 int ProcessedBOM = NO;\r
1185                 if(CreateMode == OPEN_ALWAYS)\r
1186                         SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
1187 \r
1188                 if(Pkt->hWndTrans != NULL)\r
1189                 {\r
1190                         TimeStart = time(NULL);\r
1191                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
1192                 }\r
1193 \r
1194                 InitCodeConvInfo(&cInfo);\r
1195                 cInfo.KanaCnv = Pkt->KanaCnv;\r
1196 \r
1197                 InitCodeConvInfo(&cInfo2);\r
1198                 cInfo2.KanaCnv = Pkt->KanaCnv;\r
1199 \r
1200                 /*===== \83t\83@\83C\83\8b\82ð\8eó\90M\82·\82é\83\8b\81[\83v =====*/\r
1201                 while((Pkt->Abort == ABORT_NONE) && (ForceAbort == NO))\r
1202                 {\r
1203 //                      FD_ZERO(&ReadFds);\r
1204 //                      FD_SET(dSkt, &ReadFds);\r
1205 //                      ToutPtr = NULL;\r
1206 //                      if(TimeOut != 0)\r
1207 //                      {\r
1208 //                              Tout.tv_sec = TimeOut;\r
1209 //                              Tout.tv_usec = 0;\r
1210 //                              ToutPtr = &Tout;\r
1211 //                      }\r
1212 //                      iNumBytes = select(0, &ReadFds, NULL, NULL, ToutPtr);\r
1213 //                      if(iNumBytes == SOCKET_ERROR)\r
1214 //                      {\r
1215 //                              ReportWSError("select", WSAGetLastError());\r
1216 //                              if(Pkt->Abort == ABORT_NONE)\r
1217 //                                      Pkt->Abort = ABORT_ERROR;\r
1218 //                              break;\r
1219 //                      }\r
1220 //                      else if(iNumBytes == 0)\r
1221 //                      {\r
1222 //                              SetErrorMsg(MSGJPN094);\r
1223 //                              SetTaskMsg(MSGJPN094);\r
1224 //                              Pkt->Abort = ABORT_ERROR;\r
1225 //                              break;\r
1226 //                      }\r
1227 \r
1228                         if((iNumBytes = do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, CancelCheckWork)) <= 0)\r
1229                         {\r
1230                                 if(TimeOutErr == YES)\r
1231                                 {\r
1232                                         SetErrorMsg(MSGJPN094);\r
1233                                         SetTaskMsg(MSGJPN094);\r
1234                                         if(Pkt->hWndTrans != NULL)\r
1235                                                 ClearAll = YES;\r
1236                                         if(Pkt->Abort == ABORT_NONE)\r
1237                                                 Pkt->Abort = ABORT_ERROR;\r
1238                                 }\r
1239                                 else if(iNumBytes == SOCKET_ERROR)\r
1240                                 {\r
1241                                         if(Pkt->Abort == ABORT_NONE)\r
1242                                                 Pkt->Abort = ABORT_ERROR;\r
1243                                 }\r
1244                                 break;\r
1245                         }\r
1246 \r
1247                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
1248                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
1249                         {\r
1250                                 cInfo.Str = Buf;\r
1251                                 cInfo.StrLen = iNumBytes;\r
1252                                 cInfo.Buf = Buf2;\r
1253                                 cInfo.BufSize = BUFSIZE+3;\r
1254                                 do\r
1255                                 {\r
1256                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
1257                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
1258 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
1259 //                                              Continue = ConvJIStoSJIS(&cInfo);\r
1260 //                                      else\r
1261 //                                              Continue = ConvEUCtoSJIS(&cInfo);\r
1262                                         char Buf3[(BUFSIZE + 3) * 4];\r
1263                                         CODECONVINFO cInfo2;\r
1264                                         switch(Pkt->KanjiCode)\r
1265                                         {\r
1266                                         case KANJI_SJIS:\r
1267                                                 switch(Pkt->KanjiCodeDesired)\r
1268                                                 {\r
1269                                                 case KANJI_SJIS:\r
1270 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1271 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1272 //                                                      Continue = NO;\r
1273                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1274                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1275                                                         cInfo2.Str = cInfo.Buf;\r
1276                                                         cInfo2.StrLen = cInfo.OutLen;\r
1277                                                         cInfo2.Buf = Buf3;\r
1278                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1279                                                         ConvJIStoSJIS(&cInfo2);\r
1280                                                         break;\r
1281                                                 case KANJI_JIS:\r
1282                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1283                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1284                                                         cInfo2.OutLen = cInfo.OutLen;\r
1285                                                         break;\r
1286                                                 case KANJI_EUC:\r
1287                                                         Continue = ConvSJIStoEUC(&cInfo);\r
1288                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1289                                                         cInfo2.OutLen = cInfo.OutLen;\r
1290                                                         break;\r
1291                                                 case KANJI_UTF8N:\r
1292                                                         if(ProcessedBOM == NO)\r
1293                                                         {\r
1294                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1295                                                                 cInfo2.OutLen = 3;\r
1296                                                                 Continue = YES;\r
1297                                                                 ProcessedBOM = YES;\r
1298                                                                 break;\r
1299                                                         }\r
1300                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
1301                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1302                                                         cInfo2.OutLen = cInfo.OutLen;\r
1303                                                         break;\r
1304                                                 }\r
1305                                                 break;\r
1306                                         case KANJI_JIS:\r
1307                                                 switch(Pkt->KanjiCodeDesired)\r
1308                                                 {\r
1309                                                 case KANJI_SJIS:\r
1310                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1311                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1312                                                         cInfo2.OutLen = cInfo.OutLen;\r
1313                                                         break;\r
1314                                                 case KANJI_JIS:\r
1315 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1316 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1317 //                                                      Continue = NO;\r
1318                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1319                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1320                                                         cInfo2.Str = cInfo.Buf;\r
1321                                                         cInfo2.StrLen = cInfo.OutLen;\r
1322                                                         cInfo2.Buf = Buf3;\r
1323                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1324                                                         ConvSJIStoJIS(&cInfo2);\r
1325                                                         break;\r
1326                                                 case KANJI_EUC:\r
1327                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1328                                                         cInfo2.Str = cInfo.Buf;\r
1329                                                         cInfo2.StrLen = cInfo.OutLen;\r
1330                                                         cInfo2.Buf = Buf3;\r
1331                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1332                                                         ConvSJIStoEUC(&cInfo2);\r
1333                                                         break;\r
1334                                                 case KANJI_UTF8N:\r
1335                                                         if(ProcessedBOM == NO)\r
1336                                                         {\r
1337                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1338                                                                 cInfo2.OutLen = 3;\r
1339                                                                 Continue = YES;\r
1340                                                                 ProcessedBOM = YES;\r
1341                                                                 break;\r
1342                                                         }\r
1343                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1344                                                         cInfo2.Str = cInfo.Buf;\r
1345                                                         cInfo2.StrLen = cInfo.OutLen;\r
1346                                                         cInfo2.Buf = Buf3;\r
1347                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1348                                                         ConvSJIStoUTF8N(&cInfo2);\r
1349                                                         break;\r
1350                                                 }\r
1351                                                 break;\r
1352                                         case KANJI_EUC:\r
1353                                                 switch(Pkt->KanjiCodeDesired)\r
1354                                                 {\r
1355                                                 case KANJI_SJIS:\r
1356                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1357                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1358                                                         cInfo2.OutLen = cInfo.OutLen;\r
1359                                                         break;\r
1360                                                 case KANJI_JIS:\r
1361                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1362                                                         cInfo2.Str = cInfo.Buf;\r
1363                                                         cInfo2.StrLen = cInfo.OutLen;\r
1364                                                         cInfo2.Buf = Buf3;\r
1365                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1366                                                         ConvSJIStoJIS(&cInfo2);\r
1367                                                         break;\r
1368                                                 case KANJI_EUC:\r
1369 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1370 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1371 //                                                      Continue = NO;\r
1372                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1373                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1374                                                         cInfo2.Str = cInfo.Buf;\r
1375                                                         cInfo2.StrLen = cInfo.OutLen;\r
1376                                                         cInfo2.Buf = Buf3;\r
1377                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1378                                                         ConvSJIStoEUC(&cInfo2);\r
1379                                                         break;\r
1380                                                 case KANJI_UTF8N:\r
1381                                                         if(ProcessedBOM == NO)\r
1382                                                         {\r
1383                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1384                                                                 cInfo2.OutLen = 3;\r
1385                                                                 Continue = YES;\r
1386                                                                 ProcessedBOM = YES;\r
1387                                                                 break;\r
1388                                                         }\r
1389                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1390                                                         cInfo2.Str = cInfo.Buf;\r
1391                                                         cInfo2.StrLen = cInfo.OutLen;\r
1392                                                         cInfo2.Buf = Buf3;\r
1393                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1394                                                         ConvSJIStoUTF8N(&cInfo2);\r
1395                                                         break;\r
1396                                                 }\r
1397                                                 break;\r
1398                                         case KANJI_UTF8N:\r
1399                                                 if(ProcessedBOM == NO)\r
1400                                                 {\r
1401                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
1402                                                         {\r
1403                                                                 cInfo.Str += 3;\r
1404                                                                 cInfo.StrLen -= 3;\r
1405                                                         }\r
1406                                                         cInfo2.OutLen = 0;\r
1407                                                         switch(Pkt->KanjiCodeDesired)\r
1408                                                         {\r
1409                                                         case KANJI_UTF8N:\r
1410                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1411                                                                 cInfo2.OutLen = 3;\r
1412                                                                 break;\r
1413                                                         }\r
1414                                                         Continue = YES;\r
1415                                                         ProcessedBOM = YES;\r
1416                                                         break;\r
1417                                                 }\r
1418                                                 switch(Pkt->KanjiCodeDesired)\r
1419                                                 {\r
1420                                                 case KANJI_SJIS:\r
1421                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1422                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1423                                                         cInfo2.OutLen = cInfo.OutLen;\r
1424                                                         break;\r
1425                                                 case KANJI_JIS:\r
1426                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1427                                                         cInfo2.Str = cInfo.Buf;\r
1428                                                         cInfo2.StrLen = cInfo.OutLen;\r
1429                                                         cInfo2.Buf = Buf3;\r
1430                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1431                                                         ConvSJIStoJIS(&cInfo2);\r
1432                                                         break;\r
1433                                                 case KANJI_EUC:\r
1434                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1435                                                         cInfo2.Str = cInfo.Buf;\r
1436                                                         cInfo2.StrLen = cInfo.OutLen;\r
1437                                                         cInfo2.Buf = Buf3;\r
1438                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1439                                                         ConvSJIStoEUC(&cInfo2);\r
1440                                                         break;\r
1441                                                 case KANJI_UTF8N:\r
1442                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1443                                                         cInfo2.OutLen = cInfo.StrLen;\r
1444                                                         Continue = NO;\r
1445                                                         break;\r
1446                                                 }\r
1447                                                 break;\r
1448                                         }\r
1449 //                                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1450                                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1451                                                 Pkt->Abort = ABORT_DISKFULL;\r
1452                                 }\r
1453                                 while((Continue == YES) && (Pkt->Abort == ABORT_NONE));\r
1454                         }\r
1455                         else\r
1456                         {\r
1457                                 if(WriteFile(iFileHandle, Buf, iNumBytes, &Writed, NULL) == FALSE)\r
1458                                         Pkt->Abort = ABORT_DISKFULL;\r
1459                         }\r
1460 \r
1461                         Pkt->ExistSize += iNumBytes;\r
1462                         if(Pkt->hWndTrans != NULL)\r
1463                                 AllTransSizeNow += iNumBytes;\r
1464                         else\r
1465                         {\r
1466                                 /* \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8e\9e\82Ì\8co\89ß\95\\8e¦ */\r
1467                                 DispDownloadSize(Pkt->ExistSize);\r
1468                         }\r
1469 \r
1470                         if(BackgrndMessageProc() == YES)\r
1471                                 ForceAbort = YES;\r
1472                 }\r
1473 \r
1474                 /* \8f\91\82«\8ec\82µ\82½\83f\81[\83^\82ð\8f\91\82«\8d\9e\82Þ */\r
1475                 if(Pkt->KanjiCode != KANJI_NOCNV)\r
1476                 {\r
1477                         cInfo.Buf = Buf2;\r
1478                         cInfo.BufSize = BUFSIZE+3;\r
1479                         FlushRestData(&cInfo);\r
1480                         switch(Pkt->KanjiCode)\r
1481                         {\r
1482                         case KANJI_SJIS:\r
1483                                 switch(Pkt->KanjiCodeDesired)\r
1484                                 {\r
1485                                 case KANJI_SJIS:\r
1486                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1487                                         cInfo2.Str = cInfo.Buf;\r
1488                                         cInfo2.StrLen = cInfo.OutLen;\r
1489                                         cInfo2.Buf = Buf3;\r
1490                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1491                                         ConvJIStoSJIS(&cInfo2);\r
1492                                         break;\r
1493                                 case KANJI_JIS:\r
1494                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1495                                         cInfo2.OutLen = cInfo.OutLen;\r
1496                                         break;\r
1497                                 case KANJI_EUC:\r
1498                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1499                                         cInfo2.OutLen = cInfo.OutLen;\r
1500                                         break;\r
1501                                 case KANJI_UTF8N:\r
1502                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1503                                         cInfo2.OutLen = cInfo.OutLen;\r
1504                                         break;\r
1505                                 }\r
1506                                 break;\r
1507                         case KANJI_JIS:\r
1508                                 switch(Pkt->KanjiCodeDesired)\r
1509                                 {\r
1510                                 case KANJI_SJIS:\r
1511                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1512                                         cInfo2.OutLen = cInfo.OutLen;\r
1513                                         break;\r
1514                                 case KANJI_JIS:\r
1515                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1516                                         cInfo2.Str = cInfo.Buf;\r
1517                                         cInfo2.StrLen = cInfo.OutLen;\r
1518                                         cInfo2.Buf = Buf3;\r
1519                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1520                                         ConvSJIStoJIS(&cInfo2);\r
1521                                         break;\r
1522                                 case KANJI_EUC:\r
1523                                         cInfo2.Str = cInfo.Buf;\r
1524                                         cInfo2.StrLen = cInfo.OutLen;\r
1525                                         cInfo2.Buf = Buf3;\r
1526                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1527                                         ConvSJIStoEUC(&cInfo2);\r
1528                                         break;\r
1529                                 case KANJI_UTF8N:\r
1530                                         cInfo2.Str = cInfo.Buf;\r
1531                                         cInfo2.StrLen = cInfo.OutLen;\r
1532                                         cInfo2.Buf = Buf3;\r
1533                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1534                                         ConvSJIStoUTF8N(&cInfo2);\r
1535                                         break;\r
1536                                 }\r
1537                                 break;\r
1538                         case KANJI_EUC:\r
1539                                 switch(Pkt->KanjiCodeDesired)\r
1540                                 {\r
1541                                 case KANJI_SJIS:\r
1542                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1543                                         cInfo2.OutLen = cInfo.OutLen;\r
1544                                         break;\r
1545                                 case KANJI_JIS:\r
1546                                         cInfo2.Str = cInfo.Buf;\r
1547                                         cInfo2.StrLen = cInfo.OutLen;\r
1548                                         cInfo2.Buf = Buf3;\r
1549                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1550                                         ConvSJIStoJIS(&cInfo2);\r
1551                                         break;\r
1552                                 case KANJI_EUC:\r
1553                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1554                                         cInfo2.Str = cInfo.Buf;\r
1555                                         cInfo2.StrLen = cInfo.OutLen;\r
1556                                         cInfo2.Buf = Buf3;\r
1557                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1558                                         ConvSJIStoEUC(&cInfo2);\r
1559                                         break;\r
1560                                 case KANJI_UTF8N:\r
1561                                         cInfo2.Str = cInfo.Buf;\r
1562                                         cInfo2.StrLen = cInfo.OutLen;\r
1563                                         cInfo2.Buf = Buf3;\r
1564                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1565                                         ConvSJIStoUTF8N(&cInfo2);\r
1566                                         break;\r
1567                                 }\r
1568                                 break;\r
1569                         case KANJI_UTF8N:\r
1570                                 switch(Pkt->KanjiCodeDesired)\r
1571                                 {\r
1572                                 case KANJI_SJIS:\r
1573                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1574                                         cInfo2.OutLen = cInfo.OutLen;\r
1575                                         break;\r
1576                                 case KANJI_JIS:\r
1577                                         cInfo2.Str = cInfo.Buf;\r
1578                                         cInfo2.StrLen = cInfo.OutLen;\r
1579                                         cInfo2.Buf = Buf3;\r
1580                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1581                                         ConvSJIStoJIS(&cInfo2);\r
1582                                         break;\r
1583                                 case KANJI_EUC:\r
1584                                         cInfo2.Str = cInfo.Buf;\r
1585                                         cInfo2.StrLen = cInfo.OutLen;\r
1586                                         cInfo2.Buf = Buf3;\r
1587                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1588                                         ConvSJIStoEUC(&cInfo2);\r
1589                                         break;\r
1590                                 case KANJI_UTF8N:\r
1591                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1592                                         cInfo2.OutLen = cInfo.OutLen;\r
1593                                         break;\r
1594                                 }\r
1595                                 break;\r
1596                         }\r
1597 //                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1598                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1599                                 Pkt->Abort = ABORT_DISKFULL;\r
1600                         cInfo2.Buf = Buf3;\r
1601                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1602                         FlushRestData(&cInfo2);\r
1603                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1604                                 Pkt->Abort = ABORT_DISKFULL;\r
1605                 }\r
1606 \r
1607                 /* \83O\83\89\83t\95\\8e¦\82ð\8dX\90V */\r
1608                 if(Pkt->hWndTrans != NULL)\r
1609                 {\r
1610                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
1611                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
1612                         TimeStart = time(NULL) - TimeStart + 1;\r
1613                 }\r
1614                 else\r
1615                 {\r
1616                         /* \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8e\9e\82Ì\8co\89ß\95\\8e¦\82ð\8fÁ\82· */\r
1617                         DispDownloadSize(-1);\r
1618                 }\r
1619 \r
1620                 /* \83t\83@\83C\83\8b\82Ì\83^\83C\83\80\83X\83^\83\93\83v\82ð\8d\87\82í\82¹\82é */\r
1621                 if((SaveTimeStamp == YES) &&\r
1622                    ((Pkt->Time.dwLowDateTime != 0) || (Pkt->Time.dwHighDateTime != 0)))\r
1623                 {\r
1624                         SetFileTime(iFileHandle, &Pkt->Time, &Pkt->Time, &Pkt->Time);\r
1625                 }\r
1626 \r
1627                 CloseHandle(iFileHandle);\r
1628 \r
1629                 if(iNumBytes == SOCKET_ERROR)\r
1630                         ReportWSError("recv",WSAGetLastError());\r
1631         }\r
1632         else\r
1633         {\r
1634                 SetErrorMsg(MSGJPN095, Pkt->LocalFile);\r
1635                 SetTaskMsg(MSGJPN095, Pkt->LocalFile);\r
1636                 Pkt->Abort = ABORT_ERROR;\r
1637         }\r
1638 \r
1639 \r
1640         if(shutdown(dSkt, 1) != 0)\r
1641                 ReportWSError("shutdown", WSAGetLastError());\r
1642 \r
1643         DoClose(dSkt);\r
1644 \r
1645         if(ForceAbort == NO)\r
1646         {\r
1647                 /* Abort\82ð\83z\83X\83g\82É\93`\82¦\82é */\r
1648                 if(Pkt->Abort != ABORT_NONE && iFileHandle != INVALID_HANDLE_VALUE)\r
1649                 {\r
1650                         SendData(Pkt->ctrl_skt, "\xFF\xF4\xFF", 3, MSG_OOB, CancelCheckWork);   /* MSG_OOB\82É\92\8d\88Ó */\r
1651                         SendData(Pkt->ctrl_skt, "\xF2", 1, 0, CancelCheckWork);\r
1652                         command(Pkt->ctrl_skt, NULL, CancelCheckWork, "ABOR");\r
1653                 }\r
1654         }\r
1655 \r
1656         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, CancelCheckWork, TmpBuf);\r
1657 \r
1658 //#pragma aaa\r
1659 //DoPrintf("##DOWN REPLY : %s", Buf);\r
1660 \r
1661         if(Pkt->Abort == ABORT_DISKFULL)\r
1662         {\r
1663                 SetErrorMsg(MSGJPN096);\r
1664                 SetTaskMsg(MSGJPN096);\r
1665         }\r
1666         if(iRetCode >= FTP_RETRY)\r
1667                 SetErrorMsg(Buf);\r
1668         if(Pkt->Abort != ABORT_NONE)\r
1669                 iRetCode = 500;\r
1670 \r
1671         return(iRetCode);\r
1672 }\r
1673 \r
1674 \r
1675 /*----- \83_\83E\83\93\83\8d\81[\83h\8fI\97¹\81^\92\86\8e~\8e\9e\82Ì\83\81\83b\83Z\81[\83W\82ð\95\\8e¦ ----------------------------\r
1676 *\r
1677 *       Parameter\r
1678 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1679 *               int iRetCode : \89\9e\93\9a\83R\81[\83h\r
1680 *\r
1681 *       Return Value\r
1682 *               \82È\82µ\r
1683 *----------------------------------------------------------------------------*/\r
1684 \r
1685 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
1686 {\r
1687         char Fname[FMAX_PATH+1];\r
1688 \r
1689         if(ForceAbort == NO)\r
1690         {\r
1691                 if((iRetCode/100) >= FTP_CONTINUE)\r
1692                 {\r
1693                         strcpy(Fname, Pkt->RemoteFile);\r
1694 \r
1695 #if defined(HAVE_OPENVMS)\r
1696                         /* OpenVMS\82Ì\8fê\8d\87\81A\8bó\83f\83B\83\8c\83N\83g\83\8a\82Ö\88Ú\93®\82·\82é\82Æ550 File not found\82É\82È\82Á\82Ä\r
1697                          * \83G\83\89\81[\83_\83C\83A\83\8d\83O\82â\83G\83\89\81[\83\81\83b\83Z\81[\83W\82ª\8fo\82é\82Ì\82Å\89½\82à\82µ\82È\82¢ */\r
1698                         if (AskHostType() == HTYPE_VMS)\r
1699                                 return;\r
1700 #endif\r
1701 \r
1702                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1703                         {\r
1704                                 SetTaskMsg(MSGJPN097);\r
1705                                 strcpy(Fname, MSGJPN098);\r
1706                         }\r
1707                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1708                                 SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
1709                         else\r
1710                                 SetTaskMsg(MSGJPN100);\r
1711 \r
1712                         if(Pkt->Abort != ABORT_USER)\r
1713                         {\r
1714                                 if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
1715                                         ClearAll = YES;\r
1716                         }\r
1717                 }\r
1718                 else\r
1719                 {\r
1720                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1721                                 SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
1722                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1723                                 SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
1724                         else\r
1725                                 SetTaskMsg(MSGJPN103, Pkt->ExistSize);\r
1726                 }\r
1727         }\r
1728         return;\r
1729 }\r
1730 \r
1731 \r
1732 /*----- \83_\83E\83\93\83\8d\81[\83h\81^\83A\83b\83v\83\8d\81[\83h\83G\83\89\81[\82Ì\83_\83C\83A\83\8d\83O\82ð\95\\8e¦ --------------------\r
1733 *\r
1734 *       Parameter\r
1735 *               int RedID : \83_\83C\83A\83\8d\83O\83{\83b\83N\83X\82Ì\83\8a\83\\81[\83XID\r
1736 *               HWND hWnd : \8f\91\82«\8d\9e\82Ý\92\86\83_\83C\83A\83\8d\83O\82Ì\83E\83C\83\93\83h\83E\r
1737 *               char *Fname : \83t\83@\83C\83\8b\96¼\r
1738 *\r
1739 *       Return Value\r
1740 *               int \83X\83e\81[\83^\83X (YES=\92\86\8e~/NO=\91S\82Ä\92\86\8e~)\r
1741 *----------------------------------------------------------------------------*/\r
1742 \r
1743 static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
1744 {\r
1745         if(hWnd == NULL)\r
1746                 hWnd = GetMainHwnd();\r
1747 \r
1748         SoundPlay(SND_ERROR);\r
1749         return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
1750 }\r
1751 \r
1752 \r
1753 /*----- \83_\83E\83\93\83\8d\81[\83h\83G\83\89\81[\81^\83A\83b\83v\83\8d\81[\83h\83G\83\89\81[\83_\83C\83A\83\8d\83O\82Ì\83R\81[\83\8b\83o\83b\83N --------\r
1754 *\r
1755 *       Parameter\r
1756 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1757 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1758 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1759 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1760 *\r
1761 *       Return Value\r
1762 *               BOOL TRUE/FALSE\r
1763 *----------------------------------------------------------------------------*/\r
1764 \r
1765 static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1766 {\r
1767         switch (message)\r
1768         {\r
1769                 case WM_INITDIALOG :\r
1770                         SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
1771                         SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
1772                         return(TRUE);\r
1773 \r
1774                 case WM_COMMAND :\r
1775                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1776                         {\r
1777                                 case IDOK :\r
1778                                         EndDialog(hDlg, YES);\r
1779                                         break;\r
1780 \r
1781                                 case IDCANCEL :\r
1782                                         EndDialog(hDlg, NO);\r
1783                                         break;\r
1784                         }\r
1785                         return(TRUE);\r
1786         }\r
1787     return(FALSE);\r
1788 }\r
1789 \r
1790 \r
1791 /*----- \83_\83E\83\93\83\8d\81[\83h\82Ì\83\8a\83W\83\85\81[\83\80\82Ì\8f\80\94õ\82ð\8ds\82¤ ----------------------------------\r
1792 *\r
1793 *       Parameter\r
1794 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1795 *               iont ProcMode : \8f\88\97\9d\83\82\81[\83h(EXIST_xxx)\r
1796 *               LONGLONG Size : \83\8d\81[\83h\8dÏ\82Ý\82Ì\83t\83@\83C\83\8b\82Ì\83T\83C\83Y\r
1797 *               int *Mode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_xxxx)\r
1798 *\r
1799 *       Return Value\r
1800 *               int \93]\91\97\82ð\8ds\82¤\82©\82Ç\82¤\82©(YES/NO=\82±\82Ì\83t\83@\83C\83\8b\82ð\92\86\8e~/NO_ALL=\91S\82Ä\92\86\8e~)\r
1801 *\r
1802 *       Note\r
1803 *               Pkt->ExistSize\82Ì\83Z\83b\83g\82ð\8ds\82È\82¤\r
1804 *----------------------------------------------------------------------------*/\r
1805 \r
1806 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork)\r
1807 {\r
1808         int iRetCode;\r
1809         int Com;\r
1810         char Reply[ERR_MSG_LEN+7];\r
1811         char Tmp[40];\r
1812 \r
1813         Com = YES;\r
1814 \r
1815         Pkt->ExistSize = 0;\r
1816         *Mode = CREATE_ALWAYS;\r
1817 \r
1818         if(ProcMode == EXIST_RESUME)\r
1819         {\r
1820                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "REST %s", MakeNumString(Size, Tmp, FALSE));\r
1821                 if(iRetCode/100 < FTP_RETRY)\r
1822                 {\r
1823                         /* \83\8a\83W\83\85\81[\83\80 */\r
1824                         if(Pkt->hWndTrans != NULL)\r
1825                                 Pkt->ExistSize = Size;\r
1826                         *Mode = OPEN_ALWAYS;\r
1827                 }\r
1828                 else\r
1829                 {\r
1830                         Com = DialogBox(GetFtpInst(), MAKEINTRESOURCE(noresume_dlg), Pkt->hWndTrans, NoResumeWndProc);\r
1831                         if(Com != YES)\r
1832                         {\r
1833                                 if(Com == NO_ALL)               /* \91S\82Ä\92\86\8e~ */\r
1834                                         ClearAll = YES;\r
1835                                 Pkt->Abort = ABORT_USER;\r
1836                         }\r
1837                 }\r
1838         }\r
1839         return(Com);\r
1840 }\r
1841 \r
1842 \r
1843 /*----- resume\83G\83\89\81[\83_\83C\83A\83\8d\83O\82Ì\83R\81[\83\8b\83o\83b\83N ----------------------------------\r
1844 *\r
1845 *       Parameter\r
1846 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1847 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1848 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1849 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1850 *\r
1851 *       Return Value\r
1852 *               BOOL TRUE/FALSE\r
1853 *----------------------------------------------------------------------------*/\r
1854 \r
1855 static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
1856 {\r
1857         switch (iMessage)\r
1858         {\r
1859                 case WM_INITDIALOG :\r
1860                         return(TRUE);\r
1861 \r
1862                 case WM_COMMAND :\r
1863                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1864                         {\r
1865                                 case IDOK :\r
1866                                         EndDialog(hDlg, YES);\r
1867                                         break;\r
1868 \r
1869                                 case IDCANCEL :\r
1870                                         EndDialog(hDlg, NO);\r
1871                                         break;\r
1872 \r
1873                                 case RESUME_CANCEL_ALL :\r
1874                                         EndDialog(hDlg, NO_ALL);\r
1875                                         break;\r
1876                         }\r
1877             return(TRUE);\r
1878         }\r
1879         return(FALSE);\r
1880 }\r
1881 \r
1882 \r
1883 \r
1884 /*----- \83A\83b\83v\83\8d\81[\83h\82ð\8ds\82È\82¤ --------------------------------------------------\r
1885 *\r
1886 *       Parameter\r
1887 *               SOCKET cSkt : \83R\83\93\83g\83\8d\81[\83\8b\83\\83P\83b\83g\r
1888 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1889 *\r
1890 *       Return Value\r
1891 *               int \89\9e\93\9a\83R\81[\83h\r
1892 *----------------------------------------------------------------------------*/\r
1893 \r
1894 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)\r
1895 {\r
1896         int iRetCode;\r
1897         char Reply[ERR_MSG_LEN+7];\r
1898 \r
1899         Pkt->ctrl_skt = cSkt;\r
1900 \r
1901         if(Pkt->Mode != EXIST_IGNORE)\r
1902         {\r
1903                 if(CheckFileReadable(Pkt->LocalFile) == SUCCESS)\r
1904                 {\r
1905                         if(Pkt->Type == TYPE_I)\r
1906                                 Pkt->KanjiCode = KANJI_NOCNV;\r
1907 \r
1908                         iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
1909                         if(iRetCode/100 < FTP_RETRY)\r
1910                         {\r
1911                                 if(Pkt->Mode == EXIST_UNIQUE)\r
1912                                         strcpy(Pkt->Cmd, "STOU ");\r
1913 \r
1914                                 if(Pkt->hWndTrans != NULL)\r
1915                                         DispTransFileInfo(Pkt, MSGJPN104, TRUE, YES);\r
1916 \r
1917                                 if(BackgrndMessageProc() == NO)\r
1918                                 {\r
1919                                         if(AskPasvMode() != YES)\r
1920                                                 iRetCode = UpLoadNonPassive(Pkt);\r
1921                                         else\r
1922                                                 iRetCode = UpLoadPassive(Pkt);\r
1923                                 }\r
1924                                 else\r
1925                                         iRetCode = 500;\r
1926                         }\r
1927                         else\r
1928                                 SetErrorMsg(Reply);\r
1929 \r
1930                         /* \91®\90«\95Ï\8dX */\r
1931                         if((Pkt->Attr != -1) && ((iRetCode/100) == FTP_COMPLETE))\r
1932                                 command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
1933                 }\r
1934                 else\r
1935                 {\r
1936                         SetErrorMsg(MSGJPN105, Pkt->LocalFile);\r
1937                         SetTaskMsg(MSGJPN105, Pkt->LocalFile);\r
1938                         iRetCode = 500;\r
1939                         Pkt->Abort = ABORT_ERROR;\r
1940                         DispUploadFinishMsg(Pkt, iRetCode);\r
1941                 }\r
1942         }\r
1943         else\r
1944         {\r
1945                 DispTransFileInfo(Pkt, MSGJPN106, TRUE, YES);\r
1946                 SetTaskMsg(MSGJPN107, Pkt->LocalFile);\r
1947                 iRetCode = 200;\r
1948         }\r
1949         return(iRetCode);\r
1950 }\r
1951 \r
1952 \r
1953 /*----- \92Ê\8fí\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ------------------------------------\r
1954 *\r
1955 *       Parameter\r
1956 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1957 *\r
1958 *       Return Value\r
1959 *               int \89\9e\93\9a\83R\81[\83h\r
1960 *----------------------------------------------------------------------------*/\r
1961 \r
1962 static int UpLoadNonPassive(TRANSPACKET *Pkt)\r
1963 {\r
1964         int iRetCode;\r
1965         int iLength;\r
1966         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1967         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
1968         char Buf[1024];\r
1969         struct sockaddr_in saSockAddr1;\r
1970         int Resume;\r
1971         char Reply[ERR_MSG_LEN+7];\r
1972 \r
1973         if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled)) != INVALID_SOCKET)\r
1974         {\r
1975                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
1976                 if(Resume == NO)\r
1977                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1978                 else\r
1979                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
1980 \r
1981                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
1982                 if((iRetCode/100) == FTP_PRELIM)\r
1983                 {\r
1984                         if(SocksGet2ndBindReply(listen_socket, &data_socket) == FAIL)\r
1985                         {\r
1986                                 iLength=sizeof(saSockAddr1);\r
1987                                 data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
1988 \r
1989                                 if(shutdown(listen_socket, 1) != 0)\r
1990                                         ReportWSError("shutdown listen", WSAGetLastError());\r
1991                                 listen_socket = DoClose(listen_socket);\r
1992 \r
1993                                 if(data_socket == INVALID_SOCKET)\r
1994                                 {\r
1995                                         SetErrorMsg(MSGJPN280);\r
1996                                         ReportWSError("accept", WSAGetLastError());\r
1997                                         iRetCode = 500;\r
1998                                 }\r
1999                                 else\r
2000                                         DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
2001                         }\r
2002 \r
2003                         if(data_socket != INVALID_SOCKET)\r
2004                         {\r
2005                                 iRetCode = UpLoadFile(Pkt, data_socket);\r
2006                                 data_socket = DoClose(data_socket);\r
2007                         }\r
2008                 }\r
2009                 else\r
2010                 {\r
2011                         SetErrorMsg(Reply);\r
2012                         SetTaskMsg(MSGJPN108);\r
2013                         listen_socket = DoClose(listen_socket);\r
2014                         iRetCode = 500;\r
2015                 }\r
2016         }\r
2017         else\r
2018         {\r
2019                 SetErrorMsg(MSGJPN279);\r
2020                 iRetCode = 500;\r
2021         }\r
2022         DispUploadFinishMsg(Pkt, iRetCode);\r
2023 \r
2024         return(iRetCode);\r
2025 }\r
2026 \r
2027 \r
2028 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ---------------------------------\r
2029 *\r
2030 *       Parameter\r
2031 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2032 *\r
2033 *       Return Value\r
2034 *               int \89\9e\93\9a\83R\81[\83h\r
2035 *----------------------------------------------------------------------------*/\r
2036 \r
2037 static int UpLoadPassive(TRANSPACKET *Pkt)\r
2038 {\r
2039         int iRetCode;\r
2040         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
2041         char Buf[1024];\r
2042         char Adrs[20];\r
2043         int Port;\r
2044         int Flg;\r
2045         int Resume;\r
2046         char Reply[ERR_MSG_LEN+7];\r
2047 \r
2048         iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled, "PASV");\r
2049         if(iRetCode/100 == FTP_COMPLETE)\r
2050         {\r
2051                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
2052                 {\r
2053                         if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled)) != INVALID_SOCKET)\r
2054                         {\r
2055                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
2056                                         ReportWSError("setsockopt", WSAGetLastError());\r
2057 \r
2058                                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
2059                                 if(Resume == NO)\r
2060                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
2061                                 else\r
2062                                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
2063 \r
2064                                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
2065                                 if(iRetCode/100 == FTP_PRELIM)\r
2066                                 {\r
2067                                         iRetCode = UpLoadFile(Pkt, data_socket);\r
2068 \r
2069                                         data_socket = DoClose(data_socket);\r
2070                                 }\r
2071                                 else\r
2072                                 {\r
2073                                         SetErrorMsg(Reply);\r
2074                                         SetTaskMsg(MSGJPN110);\r
2075                                         data_socket = DoClose(data_socket);\r
2076                                         iRetCode = 500;\r
2077                                 }\r
2078                         }\r
2079                         else\r
2080                         {\r
2081                                 SetErrorMsg(MSGJPN281);\r
2082                                 iRetCode = 500;\r
2083                         }\r
2084                 }\r
2085                 else\r
2086                 {\r
2087                         SetErrorMsg(Buf);\r
2088                         SetTaskMsg(MSGJPN111);\r
2089                         iRetCode = 500;\r
2090                 }\r
2091         }\r
2092         else\r
2093                 SetErrorMsg(Buf);\r
2094 \r
2095         DispUploadFinishMsg(Pkt, iRetCode);\r
2096 \r
2097         return(iRetCode);\r
2098 }\r
2099 \r
2100 \r
2101 /*----- \83A\83b\83v\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
2102 *\r
2103 *       Parameter\r
2104 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2105 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
2106 *\r
2107 *       Return Value\r
2108 *               int \89\9e\93\9a\83R\81[\83h\r
2109 *\r
2110 *       Note\r
2111 *               \93]\91\97\82Ì\8co\89ß\95\\8e¦\82Í\81A\83C\83\93\83^\81[\83o\83\8b\83^\83C\83}\82Å\8co\89ß\82ð\95\\8e¦\82·\82é\r
2112 *               \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\82Å\83A\83b\83v\83\8d\81[\83h\82·\82é\82±\82Æ\82Í\82È\82¢\r
2113 *----------------------------------------------------------------------------*/\r
2114 \r
2115 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)\r
2116 {\r
2117         DWORD iNumBytes;\r
2118         HANDLE iFileHandle;\r
2119         SECURITY_ATTRIBUTES Sec;\r
2120         char Buf[BUFSIZE];\r
2121         char Buf2[BUFSIZE+3];\r
2122         CODECONVINFO cInfo;\r
2123         TERMCODECONVINFO tInfo;\r
2124         int Continue;\r
2125         char *EofPos;\r
2126         int iRetCode;\r
2127 #if 0\r
2128         int TimeOutErr;\r
2129 #endif\r
2130         char TmpBuf[ONELINE_BUF_SIZE];\r
2131         DWORD Low;\r
2132         DWORD High;\r
2133 \r
2134 #ifdef SET_BUFFER_SIZE\r
2135 /* Add by H.Shirouzu at 2002/10/02 */\r
2136         int buf_size = SOCKBUF_SIZE;\r
2137         for ( ; buf_size > 0; buf_size /= 2)\r
2138                 if (setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
2139                         break;\r
2140 /* End */\r
2141 #endif\r
2142 \r
2143 #ifdef DISABLE_NETWORK_BUFFERS\r
2144         // \94O\82Ì\82½\82ß\91\97\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\81B\r
2145         int buf_size = 0;\r
2146         setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size));\r
2147 #endif\r
2148 \r
2149         Pkt->Abort = ABORT_NONE;\r
2150 \r
2151         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
2152         Sec.lpSecurityDescriptor = NULL;\r
2153         Sec.bInheritHandle = FALSE;\r
2154 \r
2155         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ,\r
2156                 FILE_SHARE_READ|FILE_SHARE_WRITE, &Sec, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)\r
2157         {\r
2158                 // UTF-8\91Î\89\9e\r
2159                 char Buf3[(BUFSIZE + 3) * 4];\r
2160                 CODECONVINFO cInfo2;\r
2161                 int ProcessedBOM = NO;\r
2162                 if(Pkt->hWndTrans != NULL)\r
2163                 {\r
2164                         Low = GetFileSize(iFileHandle, &High);\r
2165                         Pkt->Size = MakeLongLong(High, Low);\r
2166 \r
2167                         High = (DWORD)HIGH32(Pkt->ExistSize);\r
2168                         Low = (DWORD)LOW32(Pkt->ExistSize);\r
2169                         SetFilePointer(iFileHandle, Low, &High, FILE_BEGIN);\r
2170 \r
2171                         AllTransSizeNow = 0;\r
2172                         TimeStart = time(NULL);\r
2173                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
2174                 }\r
2175 \r
2176                 InitCodeConvInfo(&cInfo);\r
2177                 cInfo.KanaCnv = Pkt->KanaCnv;\r
2178                 InitTermCodeConvInfo(&tInfo);\r
2179 \r
2180                 InitCodeConvInfo(&cInfo2);\r
2181                 cInfo2.KanaCnv = Pkt->KanaCnv;\r
2182 \r
2183                 /*===== \83t\83@\83C\83\8b\82ð\91\97\90M\82·\82é\83\8b\81[\83v =====*/\r
2184                 while((Pkt->Abort == ABORT_NONE) &&\r
2185                           (ForceAbort == NO) &&\r
2186                           (ReadFile(iFileHandle, Buf, BUFSIZE, &iNumBytes, NULL) == TRUE))\r
2187                 {\r
2188                         if(iNumBytes == 0)\r
2189                                 break;\r
2190 \r
2191                         /* EOF\8f\9c\8b\8e */\r
2192                         EofPos = NULL;\r
2193                         if((RmEOF == YES) && (Pkt->Type == TYPE_A))\r
2194                         {\r
2195                                 if((EofPos = memchr(Buf, 0x1A, iNumBytes)) != NULL)\r
2196                                         iNumBytes = EofPos - Buf;\r
2197                         }\r
2198 \r
2199                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
2200                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
2201                         {\r
2202                                 cInfo.Str = Buf;\r
2203                                 cInfo.StrLen = iNumBytes;\r
2204                                 cInfo.Buf = Buf2;\r
2205                                 cInfo.BufSize = BUFSIZE+3;\r
2206                                 do\r
2207                                 {\r
2208                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
2209                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
2210 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
2211 //                                              Continue = ConvSJIStoJIS(&cInfo);\r
2212 //                                      else\r
2213 //                                              Continue = ConvSJIStoEUC(&cInfo);\r
2214                                         switch(Pkt->KanjiCodeDesired)\r
2215                                         {\r
2216                                         case KANJI_SJIS:\r
2217                                                 switch(Pkt->KanjiCode)\r
2218                                                 {\r
2219                                                 case KANJI_SJIS:\r
2220 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2221 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2222 //                                                      Continue = NO;\r
2223                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2224                                                         Continue = ConvSJIStoJIS(&cInfo);\r
2225                                                         cInfo2.Str = cInfo.Buf;\r
2226                                                         cInfo2.StrLen = cInfo.OutLen;\r
2227                                                         cInfo2.Buf = Buf3;\r
2228                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2229                                                         ConvJIStoSJIS(&cInfo2);\r
2230                                                         break;\r
2231                                                 case KANJI_JIS:\r
2232                                                         Continue = ConvSJIStoJIS(&cInfo);\r
2233                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2234                                                         cInfo2.OutLen = cInfo.OutLen;\r
2235                                                         break;\r
2236                                                 case KANJI_EUC:\r
2237                                                         Continue = ConvSJIStoEUC(&cInfo);\r
2238                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2239                                                         cInfo2.OutLen = cInfo.OutLen;\r
2240                                                         break;\r
2241                                                 case KANJI_UTF8N:\r
2242                                                         if(ProcessedBOM == NO)\r
2243                                                         {\r
2244                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2245                                                                 cInfo2.OutLen = 3;\r
2246                                                                 Continue = YES;\r
2247                                                                 ProcessedBOM = YES;\r
2248                                                                 break;\r
2249                                                         }\r
2250                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
2251                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2252                                                         cInfo2.OutLen = cInfo.OutLen;\r
2253                                                         break;\r
2254                                                 }\r
2255                                                 break;\r
2256                                         case KANJI_JIS:\r
2257                                                 switch(Pkt->KanjiCode)\r
2258                                                 {\r
2259                                                 case KANJI_SJIS:\r
2260                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2261                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2262                                                         cInfo2.OutLen = cInfo.OutLen;\r
2263                                                         break;\r
2264                                                 case KANJI_JIS:\r
2265 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2266 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2267 //                                                      Continue = NO;\r
2268                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2269                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2270                                                         cInfo2.Str = cInfo.Buf;\r
2271                                                         cInfo2.StrLen = cInfo.OutLen;\r
2272                                                         cInfo2.Buf = Buf3;\r
2273                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2274                                                         ConvSJIStoJIS(&cInfo2);\r
2275                                                         break;\r
2276                                                 case KANJI_EUC:\r
2277                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2278                                                         cInfo2.Str = cInfo.Buf;\r
2279                                                         cInfo2.StrLen = cInfo.OutLen;\r
2280                                                         cInfo2.Buf = Buf3;\r
2281                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2282                                                         ConvSJIStoEUC(&cInfo2);\r
2283                                                         break;\r
2284                                                 case KANJI_UTF8N:\r
2285                                                         if(ProcessedBOM == NO)\r
2286                                                         {\r
2287                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2288                                                                 cInfo2.OutLen = 3;\r
2289                                                                 Continue = YES;\r
2290                                                                 ProcessedBOM = YES;\r
2291                                                                 break;\r
2292                                                         }\r
2293                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2294                                                         cInfo2.Str = cInfo.Buf;\r
2295                                                         cInfo2.StrLen = cInfo.OutLen;\r
2296                                                         cInfo2.Buf = Buf3;\r
2297                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2298                                                         ConvSJIStoUTF8N(&cInfo2);\r
2299                                                         break;\r
2300                                                 }\r
2301                                                 break;\r
2302                                         case KANJI_EUC:\r
2303                                                 switch(Pkt->KanjiCode)\r
2304                                                 {\r
2305                                                 case KANJI_SJIS:\r
2306                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2307                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2308                                                         cInfo2.OutLen = cInfo.OutLen;\r
2309                                                         break;\r
2310                                                 case KANJI_JIS:\r
2311                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2312                                                         cInfo2.Str = cInfo.Buf;\r
2313                                                         cInfo2.StrLen = cInfo.OutLen;\r
2314                                                         cInfo2.Buf = Buf3;\r
2315                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2316                                                         ConvSJIStoJIS(&cInfo2);\r
2317                                                         break;\r
2318                                                 case KANJI_EUC:\r
2319 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2320 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2321 //                                                      Continue = NO;\r
2322                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2323                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2324                                                         cInfo2.Str = cInfo.Buf;\r
2325                                                         cInfo2.StrLen = cInfo.OutLen;\r
2326                                                         cInfo2.Buf = Buf3;\r
2327                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2328                                                         ConvSJIStoEUC(&cInfo2);\r
2329                                                         break;\r
2330                                                 case KANJI_UTF8N:\r
2331                                                         if(ProcessedBOM == NO)\r
2332                                                         {\r
2333                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2334                                                                 cInfo2.OutLen = 3;\r
2335                                                                 Continue = YES;\r
2336                                                                 ProcessedBOM = YES;\r
2337                                                                 break;\r
2338                                                         }\r
2339                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2340                                                         cInfo2.Str = cInfo.Buf;\r
2341                                                         cInfo2.StrLen = cInfo.OutLen;\r
2342                                                         cInfo2.Buf = Buf3;\r
2343                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2344                                                         ConvSJIStoUTF8N(&cInfo2);\r
2345                                                         break;\r
2346                                                 }\r
2347                                                 break;\r
2348                                         case KANJI_UTF8N:\r
2349                                                 if(ProcessedBOM == NO)\r
2350                                                 {\r
2351                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
2352                                                         {\r
2353                                                                 cInfo.Str += 3;\r
2354                                                                 cInfo.StrLen -= 3;\r
2355                                                         }\r
2356                                                         cInfo2.OutLen = 0;\r
2357                                                         switch(Pkt->KanjiCode)\r
2358                                                         {\r
2359                                                         case KANJI_UTF8N:\r
2360                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2361                                                                 cInfo2.OutLen = 3;\r
2362                                                                 break;\r
2363                                                         }\r
2364                                                         Continue = YES;\r
2365                                                         ProcessedBOM = YES;\r
2366                                                         break;\r
2367                                                 }\r
2368                                                 switch(Pkt->KanjiCode)\r
2369                                                 {\r
2370                                                 case KANJI_SJIS:\r
2371                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2372                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2373                                                         cInfo2.OutLen = cInfo.OutLen;\r
2374                                                         break;\r
2375                                                 case KANJI_JIS:\r
2376                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2377                                                         cInfo2.Str = cInfo.Buf;\r
2378                                                         cInfo2.StrLen = cInfo.OutLen;\r
2379                                                         cInfo2.Buf = Buf3;\r
2380                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2381                                                         ConvSJIStoJIS(&cInfo2);\r
2382                                                         break;\r
2383                                                 case KANJI_EUC:\r
2384                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2385                                                         cInfo2.Str = cInfo.Buf;\r
2386                                                         cInfo2.StrLen = cInfo.OutLen;\r
2387                                                         cInfo2.Buf = Buf3;\r
2388                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2389                                                         ConvSJIStoEUC(&cInfo2);\r
2390                                                         break;\r
2391                                                 case KANJI_UTF8N:\r
2392                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2393                                                         cInfo2.OutLen = cInfo.StrLen;\r
2394                                                         Continue = NO;\r
2395                                                         break;\r
2396                                                 }\r
2397                                                 break;\r
2398                                         }\r
2399 \r
2400 //                                      if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FAIL)\r
2401                                         if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FAIL)\r
2402                                         {\r
2403                                                 Pkt->Abort = ABORT_ERROR;\r
2404                                                         break;\r
2405                                         }\r
2406                                 }\r
2407                                 while(Continue == YES);\r
2408                         }\r
2409                         else\r
2410                         {\r
2411                                 if(TermCodeConvAndSend(&tInfo, dSkt, Buf, iNumBytes, Pkt->Type) == FAIL)\r
2412                                         Pkt->Abort = ABORT_ERROR;\r
2413                         }\r
2414 \r
2415                         Pkt->ExistSize += iNumBytes;\r
2416                         if(Pkt->hWndTrans != NULL)\r
2417                                 AllTransSizeNow += iNumBytes;\r
2418 \r
2419                         if(BackgrndMessageProc() == YES)\r
2420                                 ForceAbort = YES;\r
2421 \r
2422                         if(EofPos != NULL)\r
2423                                 break;\r
2424                 }\r
2425 \r
2426                 if((ForceAbort == NO) && (Pkt->Abort == ABORT_NONE))\r
2427                 {\r
2428                         /* \91\97\82è\8ec\82µ\82½\83f\81[\83^\82ð\91\97\90M */\r
2429                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
2430                         {\r
2431                                 cInfo.Buf = Buf2;\r
2432                                 cInfo.BufSize = BUFSIZE+3;\r
2433                                 FlushRestData(&cInfo);\r
2434                                 switch(Pkt->KanjiCodeDesired)\r
2435                                 {\r
2436                                 case KANJI_SJIS:\r
2437                                         switch(Pkt->KanjiCode)\r
2438                                         {\r
2439                                         case KANJI_SJIS:\r
2440                                                 // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2441                                                 cInfo2.Str = cInfo.Buf;\r
2442                                                 cInfo2.StrLen = cInfo.OutLen;\r
2443                                                 cInfo2.Buf = Buf3;\r
2444                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2445                                                 ConvJIStoSJIS(&cInfo2);\r
2446                                                 break;\r
2447                                         case KANJI_JIS:\r
2448                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2449                                                 cInfo2.OutLen = cInfo.OutLen;\r
2450                                                 break;\r
2451                                         case KANJI_EUC:\r
2452                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2453                                                 cInfo2.OutLen = cInfo.OutLen;\r
2454                                                 break;\r
2455                                         case KANJI_UTF8N:\r
2456                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2457                                                 cInfo2.OutLen = cInfo.OutLen;\r
2458                                                 break;\r
2459                                         }\r
2460                                         break;\r
2461                                 case KANJI_JIS:\r
2462                                         switch(Pkt->KanjiCode)\r
2463                                         {\r
2464                                         case KANJI_SJIS:\r
2465                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2466                                                 cInfo2.OutLen = cInfo.OutLen;\r
2467                                                 break;\r
2468                                         case KANJI_JIS:\r
2469                                                 // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2470                                                 cInfo2.Str = cInfo.Buf;\r
2471                                                 cInfo2.StrLen = cInfo.OutLen;\r
2472                                                 cInfo2.Buf = Buf3;\r
2473                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2474                                                 ConvSJIStoJIS(&cInfo2);\r
2475                                                 break;\r
2476                                         case KANJI_EUC:\r
2477                                                 cInfo2.Str = cInfo.Buf;\r
2478                                                 cInfo2.StrLen = cInfo.OutLen;\r
2479                                                 cInfo2.Buf = Buf3;\r
2480                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2481                                                 ConvSJIStoEUC(&cInfo2);\r
2482                                                 break;\r
2483                                         case KANJI_UTF8N:\r
2484                                                 cInfo2.Str = cInfo.Buf;\r
2485                                                 cInfo2.StrLen = cInfo.OutLen;\r
2486                                                 cInfo2.Buf = Buf3;\r
2487                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2488                                                 ConvSJIStoUTF8N(&cInfo2);\r
2489                                                 break;\r
2490                                         }\r
2491                                         break;\r
2492                                 case KANJI_EUC:\r
2493                                         switch(Pkt->KanjiCode)\r
2494                                         {\r
2495                                         case KANJI_SJIS:\r
2496                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2497                                                 cInfo2.OutLen = cInfo.OutLen;\r
2498                                                 break;\r
2499                                         case KANJI_JIS:\r
2500                                                 cInfo2.Str = cInfo.Buf;\r
2501                                                 cInfo2.StrLen = cInfo.OutLen;\r
2502                                                 cInfo2.Buf = Buf3;\r
2503                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2504                                                 ConvSJIStoJIS(&cInfo2);\r
2505                                                 break;\r
2506                                         case KANJI_EUC:\r
2507                                                 // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2508                                                 cInfo2.Str = cInfo.Buf;\r
2509                                                 cInfo2.StrLen = cInfo.OutLen;\r
2510                                                 cInfo2.Buf = Buf3;\r
2511                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2512                                                 ConvSJIStoEUC(&cInfo2);\r
2513                                                 break;\r
2514                                         case KANJI_UTF8N:\r
2515                                                 cInfo2.Str = cInfo.Buf;\r
2516                                                 cInfo2.StrLen = cInfo.OutLen;\r
2517                                                 cInfo2.Buf = Buf3;\r
2518                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2519                                                 ConvSJIStoUTF8N(&cInfo2);\r
2520                                                 break;\r
2521                                         }\r
2522                                         break;\r
2523                                 case KANJI_UTF8N:\r
2524                                         switch(Pkt->KanjiCode)\r
2525                                         {\r
2526                                         case KANJI_SJIS:\r
2527                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2528                                                 cInfo2.OutLen = cInfo.OutLen;\r
2529                                                 break;\r
2530                                         case KANJI_JIS:\r
2531                                                 cInfo2.Str = cInfo.Buf;\r
2532                                                 cInfo2.StrLen = cInfo.OutLen;\r
2533                                                 cInfo2.Buf = Buf3;\r
2534                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2535                                                 ConvSJIStoJIS(&cInfo2);\r
2536                                                 break;\r
2537                                         case KANJI_EUC:\r
2538                                                 cInfo2.Str = cInfo.Buf;\r
2539                                                 cInfo2.StrLen = cInfo.OutLen;\r
2540                                                 cInfo2.Buf = Buf3;\r
2541                                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2542                                                 ConvSJIStoEUC(&cInfo2);\r
2543                                                 break;\r
2544                                         case KANJI_UTF8N:\r
2545                                                 memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2546                                                 cInfo2.OutLen = cInfo.OutLen;\r
2547                                                 break;\r
2548                                         }\r
2549                                         break;\r
2550                                 }\r
2551 \r
2552 //                              if(TermCodeConvAndSend(&tInfo, dSkt, Buf2, cInfo.OutLen, Pkt->Type) == FAIL)\r
2553                                 if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FAIL)\r
2554                                         Pkt->Abort = ABORT_ERROR;\r
2555                                 cInfo2.Buf = Buf3;\r
2556                                 cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2557                                 FlushRestData(&cInfo2);\r
2558                                 if(TermCodeConvAndSend(&tInfo, dSkt, Buf3, cInfo2.OutLen, Pkt->Type) == FAIL)\r
2559                                         Pkt->Abort = ABORT_ERROR;\r
2560                         }\r
2561 \r
2562                         tInfo.Buf = Buf2;\r
2563                         tInfo.BufSize = BUFSIZE+3;\r
2564                         FlushRestTermCodeConvData(&tInfo);\r
2565                         if(SendData(dSkt, Buf2, tInfo.OutLen, 0, &Canceled) == FAIL)\r
2566                                 Pkt->Abort = ABORT_ERROR;\r
2567                 }\r
2568 \r
2569                 /* \83O\83\89\83t\95\\8e¦\82ð\8dX\90V */\r
2570                 if(Pkt->hWndTrans != NULL)\r
2571                 {\r
2572                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
2573                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
2574                         TimeStart = time(NULL) - TimeStart + 1;\r
2575                 }\r
2576                 CloseHandle(iFileHandle);\r
2577         }\r
2578         else\r
2579         {\r
2580                 SetErrorMsg(MSGJPN112, Pkt->LocalFile);\r
2581                 SetTaskMsg(MSGJPN112, Pkt->LocalFile);\r
2582                 Pkt->Abort = ABORT_ERROR;\r
2583         }\r
2584 \r
2585         if(shutdown(dSkt, 1) != 0)\r
2586                 ReportWSError("shutdown", WSAGetLastError());\r
2587 \r
2588 #if 0\r
2589         /* clean up */\r
2590         while(do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, &Canceled) > 0)\r
2591                 ;\r
2592 #endif\r
2593 \r
2594         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, &Canceled, TmpBuf);\r
2595 \r
2596 //#pragma aaa\r
2597 //DoPrintf("##UP REPLY : %s", Buf);\r
2598 \r
2599         if(iRetCode >= FTP_RETRY)\r
2600                 SetErrorMsg(Buf);\r
2601 \r
2602         if(Pkt->Abort != ABORT_NONE)\r
2603                 iRetCode = 500;\r
2604 \r
2605         return(iRetCode);\r
2606 }\r
2607 \r
2608 \r
2609 /*----- \83o\83b\83t\83@\82Ì\93à\97e\82ð\89ü\8ds\83R\81[\83h\95Ï\8a·\82µ\82Ä\91\97\90M --------------------------------\r
2610 *\r
2611 *       Parameter\r
2612 *               TERMCODECONVINFO *tInfo : \89ü\8ds\83R\81[\83h\95Ï\8a·\83p\83P\83b\83g\r
2613 *               SOCKET Skt : \83\\83P\83b\83g\r
2614 *               char *Data : \83f\81[\83^\r
2615 *               int Size : \83f\81[\83^\82Ì\83T\83C\83Y\r
2616 *               int Ascii : \83\82\81[\83h\81@\81@(TYPE_xx)\r
2617 *\r
2618 *       Return Value\r
2619 *               int \89\9e\93\9a\83R\81[\83h\r
2620 *----------------------------------------------------------------------------*/\r
2621 \r
2622 static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data, int Size, int Ascii)\r
2623 {\r
2624         char Buf3[BUFSIZE*2];\r
2625         int Continue;\r
2626         int Ret;\r
2627 \r
2628         Ret = SUCCESS;\r
2629 \r
2630 // CR-LF\88È\8aO\82Ì\89ü\8ds\83R\81[\83h\82ð\95Ï\8a·\82µ\82È\82¢\83\82\81[\83h\82Í\82±\82±\82Ö\92Ç\89Á\r
2631         if(Ascii == TYPE_A)\r
2632         {\r
2633                 tInfo->Str = Data;\r
2634                 tInfo->StrLen = Size;\r
2635                 tInfo->Buf = Buf3;\r
2636                 tInfo->BufSize = BUFSIZE*2;\r
2637                 do\r
2638                 {\r
2639                         Continue = ConvTermCodeToCRLF(tInfo);\r
2640                         if((Ret = SendData(Skt, Buf3, tInfo->OutLen, 0, &Canceled)) == FAIL)\r
2641                                 break;\r
2642                 }\r
2643                 while(Continue == YES);\r
2644         }\r
2645         else\r
2646                 Ret = SendData(Skt, Data, Size, 0, &Canceled);\r
2647 \r
2648         return(Ret);\r
2649 }\r
2650 \r
2651 \r
2652 /*----- \83A\83b\83v\83\8d\81[\83h\8fI\97¹\81^\92\86\8e~\8e\9e\82Ì\83\81\83b\83Z\81[\83W\82ð\95\\8e¦ ----------------------------\r
2653 *\r
2654 *       Parameter\r
2655 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2656 *               int iRetCode : \89\9e\93\9a\83R\81[\83h\r
2657 *\r
2658 *       Return Value\r
2659 *               \82È\82µ\r
2660 *----------------------------------------------------------------------------*/\r
2661 \r
2662 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
2663 {\r
2664         if(ForceAbort == NO)\r
2665         {\r
2666                 if((iRetCode/100) >= FTP_CONTINUE)\r
2667                 {\r
2668                         if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2669                                 SetTaskMsg(MSGJPN113, TimeStart, Pkt->ExistSize/TimeStart);\r
2670                         else\r
2671                                 SetTaskMsg(MSGJPN114);\r
2672 \r
2673                         if(Pkt->Abort != ABORT_USER)\r
2674                         {\r
2675                                 if(DispUpDownErrDialog(uperr_dlg, Pkt->hWndTrans, Pkt->LocalFile) == NO)\r
2676                                         ClearAll = YES;\r
2677                         }\r
2678                 }\r
2679                 else\r
2680                 {\r
2681                         if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
2682                                 SetTaskMsg(MSGJPN115, TimeStart, Pkt->ExistSize/TimeStart);\r
2683                         else\r
2684                                 SetTaskMsg(MSGJPN116);\r
2685                 }\r
2686         }\r
2687         return;\r
2688 }\r
2689 \r
2690 \r
2691 /*----- \83A\83b\83v\83\8d\81[\83h\82Ì\83\8a\83W\83\85\81[\83\80\82Ì\8f\80\94õ\82ð\8ds\82¤ ----------------------------------\r
2692 *\r
2693 *       Parameter\r
2694 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2695 *               iont ProcMode : \8f\88\97\9d\83\82\81[\83h(EXIST_xxx)\r
2696 *               LONGLONG Size : \83z\83X\83g\82É\82 \82é\83t\83@\83C\83\8b\82Ì\83T\83C\83Y\r
2697 *               int *Mode : \83\8a\83W\83\85\81[\83\80\82ð\8ds\82¤\82©\82Ç\82¤\82© (YES/NO)\r
2698 *\r
2699 *       Return Value\r
2700 *               int \83X\83e\81[\83^\83X = YE