OSDN Git Service

8aa9db29e0634af4d9d6bdabda7b17b539d8415f
[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_TRANSFER_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                                         // FTPS\91Î\89\9e\r
1021 //                                      iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1022                                         if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
1023                                         {\r
1024                                                 if(AttachSSL(data_socket))\r
1025                                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1026                                                 else\r
1027                                                         iRetCode = FTP_ERROR;\r
1028                                         }\r
1029                                         else\r
1030                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1031 //                                      data_socket = DoClose(data_socket);\r
1032                                 }\r
1033                         }\r
1034                         else\r
1035                         {\r
1036                                 SetErrorMsg(Reply);\r
1037                                 SetTaskMsg(MSGJPN090);\r
1038                                 listen_socket = DoClose(listen_socket);\r
1039                                 iRetCode = 500;\r
1040                         }\r
1041                 }\r
1042                 else\r
1043                         iRetCode = 500;\r
1044         }\r
1045         else\r
1046         {\r
1047                 iRetCode = 500;\r
1048                 SetErrorMsg(MSGJPN279);\r
1049         }\r
1050         DispDownloadFinishMsg(Pkt, iRetCode);\r
1051 \r
1052         return(iRetCode);\r
1053 }\r
1054 \r
1055 \r
1056 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83_\83E\83\93\83\8d\81[\83h ---------------------------------\r
1057 *\r
1058 *       Parameter\r
1059 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1060 *\r
1061 *       Return Value\r
1062 *               int \89\9e\93\9a\83R\81[\83h\r
1063 *----------------------------------------------------------------------------*/\r
1064 \r
1065 static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork)\r
1066 {\r
1067         int iRetCode;\r
1068         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1069         char Buf[1024];\r
1070         int CreateMode;\r
1071         char Adrs[20];\r
1072         int Port;\r
1073         int Flg;\r
1074         char Reply[ERR_MSG_LEN+7];\r
1075 \r
1076         iRetCode = command(Pkt->ctrl_skt, Buf, CancelCheckWork, "PASV");\r
1077         if(iRetCode/100 == FTP_COMPLETE)\r
1078         {\r
1079                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
1080                 {\r
1081                         if((data_socket = connectsock(Adrs, Port, MSGJPN091, CancelCheckWork)) != INVALID_SOCKET)\r
1082                         {\r
1083                                 // \95Ï\90\94\82ª\96¢\8f\89\8aú\89»\82Ì\83o\83O\8fC\90³\r
1084                                 Flg = 1;\r
1085                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
1086                                         ReportWSError("setsockopt", WSAGetLastError());\r
1087 \r
1088                                 if(SetDownloadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &CreateMode, CancelCheckWork) == YES)\r
1089                                 {\r
1090                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
1091                                         iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "%s", Buf);\r
1092                                         if(iRetCode/100 == FTP_PRELIM)\r
1093                                         {\r
1094                                                 // FTPS\91Î\89\9e\r
1095 //                                              iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1096                                                 if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
1097                                                 {\r
1098                                                         if(AttachSSL(data_socket))\r
1099                                                                 iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1100                                                         else\r
1101                                                                 iRetCode = FTP_ERROR;\r
1102                                                 }\r
1103                                                 else\r
1104                                                         iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork);\r
1105 //                                              data_socket = DoClose(data_socket);\r
1106                                         }\r
1107                                         else\r
1108                                         {\r
1109                                                 SetErrorMsg(Reply);\r
1110                                                 SetTaskMsg(MSGJPN092);\r
1111                                                 data_socket = DoClose(data_socket);\r
1112                                                 iRetCode = 500;\r
1113                                         }\r
1114                                 }\r
1115                                 else\r
1116                                         iRetCode = 500;\r
1117                         }\r
1118                         else\r
1119                                 iRetCode = 500;\r
1120                 }\r
1121                 else\r
1122                 {\r
1123                         SetErrorMsg(MSGJPN093);\r
1124                         SetTaskMsg(MSGJPN093);\r
1125                         iRetCode = 500;\r
1126                 }\r
1127         }\r
1128         else\r
1129                 SetErrorMsg(Buf);\r
1130 \r
1131         DispDownloadFinishMsg(Pkt, iRetCode);\r
1132 \r
1133         return(iRetCode);\r
1134 }\r
1135 \r
1136 \r
1137 /*----- \83_\83E\83\93\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
1138 *\r
1139 *       Parameter\r
1140 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1141 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
1142 *               int CreateMode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_ALWAYS/OPEN_ALWAYS)\r
1143 *\r
1144 *       Return Value\r
1145 *               int \89\9e\93\9a\83R\81[\83h\r
1146 *\r
1147 *       Note\r
1148 *               \93]\91\97\82Ì\8co\89ß\95\\8e¦\82Í\r
1149 *                       \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
1150 *                       \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
1151 *----------------------------------------------------------------------------*/\r
1152 \r
1153 static int DownLoadFile(TRANSPACKET *Pkt, SOCKET dSkt, int CreateMode, int *CancelCheckWork)\r
1154 {\r
1155         int iNumBytes;\r
1156         char Buf[BUFSIZE];\r
1157         char Buf2[BUFSIZE+3];\r
1158         HANDLE iFileHandle;\r
1159         SECURITY_ATTRIBUTES Sec;\r
1160         DWORD Writed;\r
1161         CODECONVINFO cInfo;\r
1162         int Continue;\r
1163 //      fd_set ReadFds;\r
1164 //      struct timeval Tout;\r
1165 //      struct timeval *ToutPtr;\r
1166         int iRetCode;\r
1167         int TimeOutErr;\r
1168         char TmpBuf[ONELINE_BUF_SIZE];\r
1169         DWORD dwFileAttributes;\r
1170 \r
1171 #ifdef SET_BUFFER_SIZE\r
1172 /* Add by H.Shirouzu at 2002/10/02 */\r
1173         int buf_size = SOCKBUF_SIZE;\r
1174         for ( ; buf_size > 0; buf_size /= 2)\r
1175                 if (setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
1176                         break;\r
1177 /* End */\r
1178 #endif\r
1179 \r
1180         // \94O\82Ì\82½\82ß\8eó\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\r
1181 #ifdef DISABLE_TRANSFER_NETWORK_BUFFERS\r
1182         int buf_size = 0;\r
1183         setsockopt(dSkt, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size));\r
1184 #endif\r
1185 \r
1186         Pkt->Abort = ABORT_NONE;\r
1187 \r
1188         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
1189         Sec.lpSecurityDescriptor = NULL;\r
1190         Sec.bInheritHandle = FALSE;\r
1191 \r
1192         dwFileAttributes = GetFileAttributes(Pkt->LocalFile);\r
1193         if (dwFileAttributes != INVALID_FILE_ATTRIBUTES && (dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {\r
1194                 // \93Ç\82Ý\8eæ\82è\90ê\97p\r
1195                 if (MessageBox(GetMainHwnd(), MSGJPN296, MSGJPN086, MB_YESNO) == IDYES) {\r
1196                         // \91®\90«\82ð\89ð\8f\9c\r
1197                         SetFileAttributes(Pkt->LocalFile, dwFileAttributes ^ FILE_ATTRIBUTE_READONLY);\r
1198                 }\r
1199         }\r
1200 \r
1201         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &Sec, CreateMode, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)\r
1202         {\r
1203                 // UTF-8\91Î\89\9e\r
1204                 char Buf3[(BUFSIZE + 3) * 4];\r
1205                 CODECONVINFO cInfo2;\r
1206                 int ProcessedBOM = NO;\r
1207                 if(CreateMode == OPEN_ALWAYS)\r
1208                         SetFilePointer(iFileHandle, 0, 0, FILE_END);\r
1209 \r
1210                 if(Pkt->hWndTrans != NULL)\r
1211                 {\r
1212                         TimeStart = time(NULL);\r
1213                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
1214                 }\r
1215 \r
1216                 InitCodeConvInfo(&cInfo);\r
1217                 cInfo.KanaCnv = Pkt->KanaCnv;\r
1218 \r
1219                 InitCodeConvInfo(&cInfo2);\r
1220                 cInfo2.KanaCnv = Pkt->KanaCnv;\r
1221 \r
1222                 /*===== \83t\83@\83C\83\8b\82ð\8eó\90M\82·\82é\83\8b\81[\83v =====*/\r
1223                 while((Pkt->Abort == ABORT_NONE) && (ForceAbort == NO))\r
1224                 {\r
1225 //                      FD_ZERO(&ReadFds);\r
1226 //                      FD_SET(dSkt, &ReadFds);\r
1227 //                      ToutPtr = NULL;\r
1228 //                      if(TimeOut != 0)\r
1229 //                      {\r
1230 //                              Tout.tv_sec = TimeOut;\r
1231 //                              Tout.tv_usec = 0;\r
1232 //                              ToutPtr = &Tout;\r
1233 //                      }\r
1234 //                      iNumBytes = select(0, &ReadFds, NULL, NULL, ToutPtr);\r
1235 //                      if(iNumBytes == SOCKET_ERROR)\r
1236 //                      {\r
1237 //                              ReportWSError("select", WSAGetLastError());\r
1238 //                              if(Pkt->Abort == ABORT_NONE)\r
1239 //                                      Pkt->Abort = ABORT_ERROR;\r
1240 //                              break;\r
1241 //                      }\r
1242 //                      else if(iNumBytes == 0)\r
1243 //                      {\r
1244 //                              SetErrorMsg(MSGJPN094);\r
1245 //                              SetTaskMsg(MSGJPN094);\r
1246 //                              Pkt->Abort = ABORT_ERROR;\r
1247 //                              break;\r
1248 //                      }\r
1249 \r
1250                         if((iNumBytes = do_recv(dSkt, Buf, BUFSIZE, 0, &TimeOutErr, CancelCheckWork)) <= 0)\r
1251                         {\r
1252                                 if(TimeOutErr == YES)\r
1253                                 {\r
1254                                         SetErrorMsg(MSGJPN094);\r
1255                                         SetTaskMsg(MSGJPN094);\r
1256                                         if(Pkt->hWndTrans != NULL)\r
1257                                                 ClearAll = YES;\r
1258                                         if(Pkt->Abort == ABORT_NONE)\r
1259                                                 Pkt->Abort = ABORT_ERROR;\r
1260                                 }\r
1261                                 else if(iNumBytes == SOCKET_ERROR)\r
1262                                 {\r
1263                                         if(Pkt->Abort == ABORT_NONE)\r
1264                                                 Pkt->Abort = ABORT_ERROR;\r
1265                                 }\r
1266                                 break;\r
1267                         }\r
1268 \r
1269                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
1270                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
1271                         {\r
1272                                 cInfo.Str = Buf;\r
1273                                 cInfo.StrLen = iNumBytes;\r
1274                                 cInfo.Buf = Buf2;\r
1275                                 cInfo.BufSize = BUFSIZE+3;\r
1276                                 do\r
1277                                 {\r
1278                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
1279                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
1280 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
1281 //                                              Continue = ConvJIStoSJIS(&cInfo);\r
1282 //                                      else\r
1283 //                                              Continue = ConvEUCtoSJIS(&cInfo);\r
1284                                         char Buf3[(BUFSIZE + 3) * 4];\r
1285                                         CODECONVINFO cInfo2;\r
1286                                         switch(Pkt->KanjiCode)\r
1287                                         {\r
1288                                         case KANJI_SJIS:\r
1289                                                 switch(Pkt->KanjiCodeDesired)\r
1290                                                 {\r
1291                                                 case KANJI_SJIS:\r
1292 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1293 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1294 //                                                      Continue = NO;\r
1295                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1296                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1297                                                         cInfo2.Str = cInfo.Buf;\r
1298                                                         cInfo2.StrLen = cInfo.OutLen;\r
1299                                                         cInfo2.Buf = Buf3;\r
1300                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1301                                                         ConvJIStoSJIS(&cInfo2);\r
1302                                                         break;\r
1303                                                 case KANJI_JIS:\r
1304                                                         Continue = ConvSJIStoJIS(&cInfo);\r
1305                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1306                                                         cInfo2.OutLen = cInfo.OutLen;\r
1307                                                         break;\r
1308                                                 case KANJI_EUC:\r
1309                                                         Continue = ConvSJIStoEUC(&cInfo);\r
1310                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1311                                                         cInfo2.OutLen = cInfo.OutLen;\r
1312                                                         break;\r
1313                                                 case KANJI_UTF8N:\r
1314                                                         if(ProcessedBOM == NO)\r
1315                                                         {\r
1316                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1317                                                                 cInfo2.OutLen = 3;\r
1318                                                                 Continue = YES;\r
1319                                                                 ProcessedBOM = YES;\r
1320                                                                 break;\r
1321                                                         }\r
1322                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
1323                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1324                                                         cInfo2.OutLen = cInfo.OutLen;\r
1325                                                         break;\r
1326                                                 }\r
1327                                                 break;\r
1328                                         case KANJI_JIS:\r
1329                                                 switch(Pkt->KanjiCodeDesired)\r
1330                                                 {\r
1331                                                 case KANJI_SJIS:\r
1332                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1333                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1334                                                         cInfo2.OutLen = cInfo.OutLen;\r
1335                                                         break;\r
1336                                                 case KANJI_JIS:\r
1337 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1338 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1339 //                                                      Continue = NO;\r
1340                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1341                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1342                                                         cInfo2.Str = cInfo.Buf;\r
1343                                                         cInfo2.StrLen = cInfo.OutLen;\r
1344                                                         cInfo2.Buf = Buf3;\r
1345                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1346                                                         ConvSJIStoJIS(&cInfo2);\r
1347                                                         break;\r
1348                                                 case KANJI_EUC:\r
1349                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1350                                                         cInfo2.Str = cInfo.Buf;\r
1351                                                         cInfo2.StrLen = cInfo.OutLen;\r
1352                                                         cInfo2.Buf = Buf3;\r
1353                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1354                                                         ConvSJIStoEUC(&cInfo2);\r
1355                                                         break;\r
1356                                                 case KANJI_UTF8N:\r
1357                                                         if(ProcessedBOM == NO)\r
1358                                                         {\r
1359                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1360                                                                 cInfo2.OutLen = 3;\r
1361                                                                 Continue = YES;\r
1362                                                                 ProcessedBOM = YES;\r
1363                                                                 break;\r
1364                                                         }\r
1365                                                         Continue = ConvJIStoSJIS(&cInfo);\r
1366                                                         cInfo2.Str = cInfo.Buf;\r
1367                                                         cInfo2.StrLen = cInfo.OutLen;\r
1368                                                         cInfo2.Buf = Buf3;\r
1369                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1370                                                         ConvSJIStoUTF8N(&cInfo2);\r
1371                                                         break;\r
1372                                                 }\r
1373                                                 break;\r
1374                                         case KANJI_EUC:\r
1375                                                 switch(Pkt->KanjiCodeDesired)\r
1376                                                 {\r
1377                                                 case KANJI_SJIS:\r
1378                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1379                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1380                                                         cInfo2.OutLen = cInfo.OutLen;\r
1381                                                         break;\r
1382                                                 case KANJI_JIS:\r
1383                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1384                                                         cInfo2.Str = cInfo.Buf;\r
1385                                                         cInfo2.StrLen = cInfo.OutLen;\r
1386                                                         cInfo2.Buf = Buf3;\r
1387                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1388                                                         ConvSJIStoJIS(&cInfo2);\r
1389                                                         break;\r
1390                                                 case KANJI_EUC:\r
1391 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1392 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
1393 //                                                      Continue = NO;\r
1394                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1395                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1396                                                         cInfo2.Str = cInfo.Buf;\r
1397                                                         cInfo2.StrLen = cInfo.OutLen;\r
1398                                                         cInfo2.Buf = Buf3;\r
1399                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1400                                                         ConvSJIStoEUC(&cInfo2);\r
1401                                                         break;\r
1402                                                 case KANJI_UTF8N:\r
1403                                                         if(ProcessedBOM == NO)\r
1404                                                         {\r
1405                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1406                                                                 cInfo2.OutLen = 3;\r
1407                                                                 Continue = YES;\r
1408                                                                 ProcessedBOM = YES;\r
1409                                                                 break;\r
1410                                                         }\r
1411                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
1412                                                         cInfo2.Str = cInfo.Buf;\r
1413                                                         cInfo2.StrLen = cInfo.OutLen;\r
1414                                                         cInfo2.Buf = Buf3;\r
1415                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1416                                                         ConvSJIStoUTF8N(&cInfo2);\r
1417                                                         break;\r
1418                                                 }\r
1419                                                 break;\r
1420                                         case KANJI_UTF8N:\r
1421                                                 if(ProcessedBOM == NO)\r
1422                                                 {\r
1423                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
1424                                                         {\r
1425                                                                 cInfo.Str += 3;\r
1426                                                                 cInfo.StrLen -= 3;\r
1427                                                         }\r
1428                                                         cInfo2.OutLen = 0;\r
1429                                                         switch(Pkt->KanjiCodeDesired)\r
1430                                                         {\r
1431                                                         case KANJI_UTF8N:\r
1432                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
1433                                                                 cInfo2.OutLen = 3;\r
1434                                                                 break;\r
1435                                                         }\r
1436                                                         Continue = YES;\r
1437                                                         ProcessedBOM = YES;\r
1438                                                         break;\r
1439                                                 }\r
1440                                                 switch(Pkt->KanjiCodeDesired)\r
1441                                                 {\r
1442                                                 case KANJI_SJIS:\r
1443                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1444                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1445                                                         cInfo2.OutLen = cInfo.OutLen;\r
1446                                                         break;\r
1447                                                 case KANJI_JIS:\r
1448                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1449                                                         cInfo2.Str = cInfo.Buf;\r
1450                                                         cInfo2.StrLen = cInfo.OutLen;\r
1451                                                         cInfo2.Buf = Buf3;\r
1452                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1453                                                         ConvSJIStoJIS(&cInfo2);\r
1454                                                         break;\r
1455                                                 case KANJI_EUC:\r
1456                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
1457                                                         cInfo2.Str = cInfo.Buf;\r
1458                                                         cInfo2.StrLen = cInfo.OutLen;\r
1459                                                         cInfo2.Buf = Buf3;\r
1460                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1461                                                         ConvSJIStoEUC(&cInfo2);\r
1462                                                         break;\r
1463                                                 case KANJI_UTF8N:\r
1464                                                         memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
1465                                                         cInfo2.OutLen = cInfo.StrLen;\r
1466                                                         Continue = NO;\r
1467                                                         break;\r
1468                                                 }\r
1469                                                 break;\r
1470                                         }\r
1471 //                                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1472                                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1473                                                 Pkt->Abort = ABORT_DISKFULL;\r
1474                                 }\r
1475                                 while((Continue == YES) && (Pkt->Abort == ABORT_NONE));\r
1476                         }\r
1477                         else\r
1478                         {\r
1479                                 if(WriteFile(iFileHandle, Buf, iNumBytes, &Writed, NULL) == FALSE)\r
1480                                         Pkt->Abort = ABORT_DISKFULL;\r
1481                         }\r
1482 \r
1483                         Pkt->ExistSize += iNumBytes;\r
1484                         if(Pkt->hWndTrans != NULL)\r
1485                                 AllTransSizeNow += iNumBytes;\r
1486                         else\r
1487                         {\r
1488                                 /* \93]\91\97\83_\83C\83A\83\8d\83O\82ð\8fo\82³\82È\82¢\8e\9e\82Ì\8co\89ß\95\\8e¦ */\r
1489                                 DispDownloadSize(Pkt->ExistSize);\r
1490                         }\r
1491 \r
1492                         if(BackgrndMessageProc() == YES)\r
1493                                 ForceAbort = YES;\r
1494                 }\r
1495 \r
1496                 /* \8f\91\82«\8ec\82µ\82½\83f\81[\83^\82ð\8f\91\82«\8d\9e\82Þ */\r
1497                 if(Pkt->KanjiCode != KANJI_NOCNV)\r
1498                 {\r
1499                         cInfo.Buf = Buf2;\r
1500                         cInfo.BufSize = BUFSIZE+3;\r
1501                         FlushRestData(&cInfo);\r
1502                         switch(Pkt->KanjiCode)\r
1503                         {\r
1504                         case KANJI_SJIS:\r
1505                                 switch(Pkt->KanjiCodeDesired)\r
1506                                 {\r
1507                                 case KANJI_SJIS:\r
1508                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1509                                         cInfo2.Str = cInfo.Buf;\r
1510                                         cInfo2.StrLen = cInfo.OutLen;\r
1511                                         cInfo2.Buf = Buf3;\r
1512                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1513                                         ConvJIStoSJIS(&cInfo2);\r
1514                                         break;\r
1515                                 case KANJI_JIS:\r
1516                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1517                                         cInfo2.OutLen = cInfo.OutLen;\r
1518                                         break;\r
1519                                 case KANJI_EUC:\r
1520                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1521                                         cInfo2.OutLen = cInfo.OutLen;\r
1522                                         break;\r
1523                                 case KANJI_UTF8N:\r
1524                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1525                                         cInfo2.OutLen = cInfo.OutLen;\r
1526                                         break;\r
1527                                 }\r
1528                                 break;\r
1529                         case KANJI_JIS:\r
1530                                 switch(Pkt->KanjiCodeDesired)\r
1531                                 {\r
1532                                 case KANJI_SJIS:\r
1533                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1534                                         cInfo2.OutLen = cInfo.OutLen;\r
1535                                         break;\r
1536                                 case KANJI_JIS:\r
1537                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1538                                         cInfo2.Str = cInfo.Buf;\r
1539                                         cInfo2.StrLen = cInfo.OutLen;\r
1540                                         cInfo2.Buf = Buf3;\r
1541                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1542                                         ConvSJIStoJIS(&cInfo2);\r
1543                                         break;\r
1544                                 case KANJI_EUC:\r
1545                                         cInfo2.Str = cInfo.Buf;\r
1546                                         cInfo2.StrLen = cInfo.OutLen;\r
1547                                         cInfo2.Buf = Buf3;\r
1548                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1549                                         ConvSJIStoEUC(&cInfo2);\r
1550                                         break;\r
1551                                 case KANJI_UTF8N:\r
1552                                         cInfo2.Str = cInfo.Buf;\r
1553                                         cInfo2.StrLen = cInfo.OutLen;\r
1554                                         cInfo2.Buf = Buf3;\r
1555                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1556                                         ConvSJIStoUTF8N(&cInfo2);\r
1557                                         break;\r
1558                                 }\r
1559                                 break;\r
1560                         case KANJI_EUC:\r
1561                                 switch(Pkt->KanjiCodeDesired)\r
1562                                 {\r
1563                                 case KANJI_SJIS:\r
1564                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1565                                         cInfo2.OutLen = cInfo.OutLen;\r
1566                                         break;\r
1567                                 case KANJI_JIS:\r
1568                                         cInfo2.Str = cInfo.Buf;\r
1569                                         cInfo2.StrLen = cInfo.OutLen;\r
1570                                         cInfo2.Buf = Buf3;\r
1571                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1572                                         ConvSJIStoJIS(&cInfo2);\r
1573                                         break;\r
1574                                 case KANJI_EUC:\r
1575                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
1576                                         cInfo2.Str = cInfo.Buf;\r
1577                                         cInfo2.StrLen = cInfo.OutLen;\r
1578                                         cInfo2.Buf = Buf3;\r
1579                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1580                                         ConvSJIStoEUC(&cInfo2);\r
1581                                         break;\r
1582                                 case KANJI_UTF8N:\r
1583                                         cInfo2.Str = cInfo.Buf;\r
1584                                         cInfo2.StrLen = cInfo.OutLen;\r
1585                                         cInfo2.Buf = Buf3;\r
1586                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1587                                         ConvSJIStoUTF8N(&cInfo2);\r
1588                                         break;\r
1589                                 }\r
1590                                 break;\r
1591                         case KANJI_UTF8N:\r
1592                                 switch(Pkt->KanjiCodeDesired)\r
1593                                 {\r
1594                                 case KANJI_SJIS:\r
1595                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1596                                         cInfo2.OutLen = cInfo.OutLen;\r
1597                                         break;\r
1598                                 case KANJI_JIS:\r
1599                                         cInfo2.Str = cInfo.Buf;\r
1600                                         cInfo2.StrLen = cInfo.OutLen;\r
1601                                         cInfo2.Buf = Buf3;\r
1602                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1603                                         ConvSJIStoJIS(&cInfo2);\r
1604                                         break;\r
1605                                 case KANJI_EUC:\r
1606                                         cInfo2.Str = cInfo.Buf;\r
1607                                         cInfo2.StrLen = cInfo.OutLen;\r
1608                                         cInfo2.Buf = Buf3;\r
1609                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1610                                         ConvSJIStoEUC(&cInfo2);\r
1611                                         break;\r
1612                                 case KANJI_UTF8N:\r
1613                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
1614                                         cInfo2.OutLen = cInfo.OutLen;\r
1615                                         break;\r
1616                                 }\r
1617                                 break;\r
1618                         }\r
1619 //                      if(WriteFile(iFileHandle, Buf2, cInfo.OutLen, &Writed, NULL) == FALSE)\r
1620                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1621                                 Pkt->Abort = ABORT_DISKFULL;\r
1622                         cInfo2.Buf = Buf3;\r
1623                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
1624                         FlushRestData(&cInfo2);\r
1625                         if(WriteFile(iFileHandle, Buf3, cInfo2.OutLen, &Writed, NULL) == FALSE)\r
1626                                 Pkt->Abort = ABORT_DISKFULL;\r
1627                 }\r
1628 \r
1629                 /* \83O\83\89\83t\95\\8e¦\82ð\8dX\90V */\r
1630                 if(Pkt->hWndTrans != NULL)\r
1631                 {\r
1632                         KillTimer(Pkt->hWndTrans, TIMER_DISPLAY);\r
1633                         DispTransferStatus(Pkt->hWndTrans, YES, Pkt);\r
1634                         TimeStart = time(NULL) - TimeStart + 1;\r
1635                 }\r
1636                 else\r
1637                 {\r
1638                         /* \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
1639                         DispDownloadSize(-1);\r
1640                 }\r
1641 \r
1642                 /* \83t\83@\83C\83\8b\82Ì\83^\83C\83\80\83X\83^\83\93\83v\82ð\8d\87\82í\82¹\82é */\r
1643                 if((SaveTimeStamp == YES) &&\r
1644                    ((Pkt->Time.dwLowDateTime != 0) || (Pkt->Time.dwHighDateTime != 0)))\r
1645                 {\r
1646                         SetFileTime(iFileHandle, &Pkt->Time, &Pkt->Time, &Pkt->Time);\r
1647                 }\r
1648 \r
1649                 CloseHandle(iFileHandle);\r
1650 \r
1651                 if(iNumBytes == SOCKET_ERROR)\r
1652                         ReportWSError("recv",WSAGetLastError());\r
1653         }\r
1654         else\r
1655         {\r
1656                 SetErrorMsg(MSGJPN095, Pkt->LocalFile);\r
1657                 SetTaskMsg(MSGJPN095, Pkt->LocalFile);\r
1658                 Pkt->Abort = ABORT_ERROR;\r
1659         }\r
1660 \r
1661 \r
1662         if(shutdown(dSkt, 1) != 0)\r
1663                 ReportWSError("shutdown", WSAGetLastError());\r
1664 \r
1665         DoClose(dSkt);\r
1666 \r
1667         if(ForceAbort == NO)\r
1668         {\r
1669                 /* Abort\82ð\83z\83X\83g\82É\93`\82¦\82é */\r
1670                 if(Pkt->Abort != ABORT_NONE && iFileHandle != INVALID_HANDLE_VALUE)\r
1671                 {\r
1672                         SendData(Pkt->ctrl_skt, "\xFF\xF4\xFF", 3, MSG_OOB, CancelCheckWork);   /* MSG_OOB\82É\92\8d\88Ó */\r
1673                         SendData(Pkt->ctrl_skt, "\xF2", 1, 0, CancelCheckWork);\r
1674                         command(Pkt->ctrl_skt, NULL, CancelCheckWork, "ABOR");\r
1675                 }\r
1676         }\r
1677 \r
1678         iRetCode = ReadReplyMessage(Pkt->ctrl_skt, Buf, 1024, CancelCheckWork, TmpBuf);\r
1679 \r
1680 //#pragma aaa\r
1681 //DoPrintf("##DOWN REPLY : %s", Buf);\r
1682 \r
1683         if(Pkt->Abort == ABORT_DISKFULL)\r
1684         {\r
1685                 SetErrorMsg(MSGJPN096);\r
1686                 SetTaskMsg(MSGJPN096);\r
1687         }\r
1688         if(iRetCode >= FTP_RETRY)\r
1689                 SetErrorMsg(Buf);\r
1690         if(Pkt->Abort != ABORT_NONE)\r
1691                 iRetCode = 500;\r
1692 \r
1693         return(iRetCode);\r
1694 }\r
1695 \r
1696 \r
1697 /*----- \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
1698 *\r
1699 *       Parameter\r
1700 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1701 *               int iRetCode : \89\9e\93\9a\83R\81[\83h\r
1702 *\r
1703 *       Return Value\r
1704 *               \82È\82µ\r
1705 *----------------------------------------------------------------------------*/\r
1706 \r
1707 static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
1708 {\r
1709         char Fname[FMAX_PATH+1];\r
1710 \r
1711         if(ForceAbort == NO)\r
1712         {\r
1713                 if((iRetCode/100) >= FTP_CONTINUE)\r
1714                 {\r
1715                         strcpy(Fname, Pkt->RemoteFile);\r
1716 \r
1717 #if defined(HAVE_OPENVMS)\r
1718                         /* OpenVMS\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
1719                          * \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
1720                         if (AskHostType() == HTYPE_VMS)\r
1721                                 return;\r
1722 #endif\r
1723 \r
1724                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1725                         {\r
1726                                 SetTaskMsg(MSGJPN097);\r
1727                                 strcpy(Fname, MSGJPN098);\r
1728                         }\r
1729                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1730                                 SetTaskMsg(MSGJPN099, TimeStart, Pkt->ExistSize/TimeStart);\r
1731                         else\r
1732                                 SetTaskMsg(MSGJPN100);\r
1733 \r
1734                         if(Pkt->Abort != ABORT_USER)\r
1735                         {\r
1736                                 if(DispUpDownErrDialog(downerr_dlg, Pkt->hWndTrans, Fname) == NO)\r
1737                                         ClearAll = YES;\r
1738                         }\r
1739                 }\r
1740                 else\r
1741                 {\r
1742                         if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
1743                                 SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
1744                         else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
1745                                 SetTaskMsg(MSGJPN102, TimeStart, Pkt->ExistSize/TimeStart);\r
1746                         else\r
1747                                 SetTaskMsg(MSGJPN103, Pkt->ExistSize);\r
1748                 }\r
1749         }\r
1750         return;\r
1751 }\r
1752 \r
1753 \r
1754 /*----- \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
1755 *\r
1756 *       Parameter\r
1757 *               int RedID : \83_\83C\83A\83\8d\83O\83{\83b\83N\83X\82Ì\83\8a\83\\81[\83XID\r
1758 *               HWND hWnd : \8f\91\82«\8d\9e\82Ý\92\86\83_\83C\83A\83\8d\83O\82Ì\83E\83C\83\93\83h\83E\r
1759 *               char *Fname : \83t\83@\83C\83\8b\96¼\r
1760 *\r
1761 *       Return Value\r
1762 *               int \83X\83e\81[\83^\83X (YES=\92\86\8e~/NO=\91S\82Ä\92\86\8e~)\r
1763 *----------------------------------------------------------------------------*/\r
1764 \r
1765 static int DispUpDownErrDialog(int ResID, HWND hWnd, char *Fname)\r
1766 {\r
1767         if(hWnd == NULL)\r
1768                 hWnd = GetMainHwnd();\r
1769 \r
1770         SoundPlay(SND_ERROR);\r
1771         return(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(ResID), hWnd, UpDownErrorDialogProc, (LPARAM)Fname));\r
1772 }\r
1773 \r
1774 \r
1775 /*----- \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
1776 *\r
1777 *       Parameter\r
1778 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1779 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1780 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1781 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1782 *\r
1783 *       Return Value\r
1784 *               BOOL TRUE/FALSE\r
1785 *----------------------------------------------------------------------------*/\r
1786 \r
1787 static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
1788 {\r
1789         switch (message)\r
1790         {\r
1791                 case WM_INITDIALOG :\r
1792                         SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam);\r
1793                         SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg);\r
1794                         return(TRUE);\r
1795 \r
1796                 case WM_COMMAND :\r
1797                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1798                         {\r
1799                                 case IDOK :\r
1800                                         EndDialog(hDlg, YES);\r
1801                                         break;\r
1802 \r
1803                                 case IDCANCEL :\r
1804                                         EndDialog(hDlg, NO);\r
1805                                         break;\r
1806                         }\r
1807                         return(TRUE);\r
1808         }\r
1809     return(FALSE);\r
1810 }\r
1811 \r
1812 \r
1813 /*----- \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
1814 *\r
1815 *       Parameter\r
1816 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1817 *               iont ProcMode : \8f\88\97\9d\83\82\81[\83h(EXIST_xxx)\r
1818 *               LONGLONG Size : \83\8d\81[\83h\8dÏ\82Ý\82Ì\83t\83@\83C\83\8b\82Ì\83T\83C\83Y\r
1819 *               int *Mode : \83t\83@\83C\83\8b\8dì\90¬\83\82\81[\83h (CREATE_xxxx)\r
1820 *\r
1821 *       Return Value\r
1822 *               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
1823 *\r
1824 *       Note\r
1825 *               Pkt->ExistSize\82Ì\83Z\83b\83g\82ð\8ds\82È\82¤\r
1826 *----------------------------------------------------------------------------*/\r
1827 \r
1828 static int SetDownloadResume(TRANSPACKET *Pkt, int ProcMode, LONGLONG Size, int *Mode, int *CancelCheckWork)\r
1829 {\r
1830         int iRetCode;\r
1831         int Com;\r
1832         char Reply[ERR_MSG_LEN+7];\r
1833         char Tmp[40];\r
1834 \r
1835         Com = YES;\r
1836 \r
1837         Pkt->ExistSize = 0;\r
1838         *Mode = CREATE_ALWAYS;\r
1839 \r
1840         if(ProcMode == EXIST_RESUME)\r
1841         {\r
1842                 iRetCode = command(Pkt->ctrl_skt, Reply, CancelCheckWork, "REST %s", MakeNumString(Size, Tmp, FALSE));\r
1843                 if(iRetCode/100 < FTP_RETRY)\r
1844                 {\r
1845                         /* \83\8a\83W\83\85\81[\83\80 */\r
1846                         if(Pkt->hWndTrans != NULL)\r
1847                                 Pkt->ExistSize = Size;\r
1848                         *Mode = OPEN_ALWAYS;\r
1849                 }\r
1850                 else\r
1851                 {\r
1852                         Com = DialogBox(GetFtpInst(), MAKEINTRESOURCE(noresume_dlg), Pkt->hWndTrans, NoResumeWndProc);\r
1853                         if(Com != YES)\r
1854                         {\r
1855                                 if(Com == NO_ALL)               /* \91S\82Ä\92\86\8e~ */\r
1856                                         ClearAll = YES;\r
1857                                 Pkt->Abort = ABORT_USER;\r
1858                         }\r
1859                 }\r
1860         }\r
1861         return(Com);\r
1862 }\r
1863 \r
1864 \r
1865 /*----- resume\83G\83\89\81[\83_\83C\83A\83\8d\83O\82Ì\83R\81[\83\8b\83o\83b\83N ----------------------------------\r
1866 *\r
1867 *       Parameter\r
1868 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
1869 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
1870 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
1871 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
1872 *\r
1873 *       Return Value\r
1874 *               BOOL TRUE/FALSE\r
1875 *----------------------------------------------------------------------------*/\r
1876 \r
1877 static BOOL CALLBACK NoResumeWndProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)\r
1878 {\r
1879         switch (iMessage)\r
1880         {\r
1881                 case WM_INITDIALOG :\r
1882                         return(TRUE);\r
1883 \r
1884                 case WM_COMMAND :\r
1885                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
1886                         {\r
1887                                 case IDOK :\r
1888                                         EndDialog(hDlg, YES);\r
1889                                         break;\r
1890 \r
1891                                 case IDCANCEL :\r
1892                                         EndDialog(hDlg, NO);\r
1893                                         break;\r
1894 \r
1895                                 case RESUME_CANCEL_ALL :\r
1896                                         EndDialog(hDlg, NO_ALL);\r
1897                                         break;\r
1898                         }\r
1899             return(TRUE);\r
1900         }\r
1901         return(FALSE);\r
1902 }\r
1903 \r
1904 \r
1905 \r
1906 /*----- \83A\83b\83v\83\8d\81[\83h\82ð\8ds\82È\82¤ --------------------------------------------------\r
1907 *\r
1908 *       Parameter\r
1909 *               SOCKET cSkt : \83R\83\93\83g\83\8d\81[\83\8b\83\\83P\83b\83g\r
1910 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1911 *\r
1912 *       Return Value\r
1913 *               int \89\9e\93\9a\83R\81[\83h\r
1914 *----------------------------------------------------------------------------*/\r
1915 \r
1916 static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)\r
1917 {\r
1918         int iRetCode;\r
1919         char Reply[ERR_MSG_LEN+7];\r
1920 \r
1921         Pkt->ctrl_skt = cSkt;\r
1922 \r
1923         if(Pkt->Mode != EXIST_IGNORE)\r
1924         {\r
1925                 if(CheckFileReadable(Pkt->LocalFile) == SUCCESS)\r
1926                 {\r
1927                         if(Pkt->Type == TYPE_I)\r
1928                                 Pkt->KanjiCode = KANJI_NOCNV;\r
1929 \r
1930                         iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "TYPE %c", Pkt->Type);\r
1931                         if(iRetCode/100 < FTP_RETRY)\r
1932                         {\r
1933                                 if(Pkt->Mode == EXIST_UNIQUE)\r
1934                                         strcpy(Pkt->Cmd, "STOU ");\r
1935 \r
1936                                 if(Pkt->hWndTrans != NULL)\r
1937                                         DispTransFileInfo(Pkt, MSGJPN104, TRUE, YES);\r
1938 \r
1939                                 if(BackgrndMessageProc() == NO)\r
1940                                 {\r
1941                                         if(AskPasvMode() != YES)\r
1942                                                 iRetCode = UpLoadNonPassive(Pkt);\r
1943                                         else\r
1944                                                 iRetCode = UpLoadPassive(Pkt);\r
1945                                 }\r
1946                                 else\r
1947                                         iRetCode = 500;\r
1948                         }\r
1949                         else\r
1950                                 SetErrorMsg(Reply);\r
1951 \r
1952                         /* \91®\90«\95Ï\8dX */\r
1953                         if((Pkt->Attr != -1) && ((iRetCode/100) == FTP_COMPLETE))\r
1954                                 command(Pkt->ctrl_skt, Reply, &Canceled, "%s %03X %s", AskHostChmodCmd(), Pkt->Attr, Pkt->RemoteFile);\r
1955                 }\r
1956                 else\r
1957                 {\r
1958                         SetErrorMsg(MSGJPN105, Pkt->LocalFile);\r
1959                         SetTaskMsg(MSGJPN105, Pkt->LocalFile);\r
1960                         iRetCode = 500;\r
1961                         Pkt->Abort = ABORT_ERROR;\r
1962                         DispUploadFinishMsg(Pkt, iRetCode);\r
1963                 }\r
1964         }\r
1965         else\r
1966         {\r
1967                 DispTransFileInfo(Pkt, MSGJPN106, TRUE, YES);\r
1968                 SetTaskMsg(MSGJPN107, Pkt->LocalFile);\r
1969                 iRetCode = 200;\r
1970         }\r
1971         return(iRetCode);\r
1972 }\r
1973 \r
1974 \r
1975 /*----- \92Ê\8fí\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ------------------------------------\r
1976 *\r
1977 *       Parameter\r
1978 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
1979 *\r
1980 *       Return Value\r
1981 *               int \89\9e\93\9a\83R\81[\83h\r
1982 *----------------------------------------------------------------------------*/\r
1983 \r
1984 static int UpLoadNonPassive(TRANSPACKET *Pkt)\r
1985 {\r
1986         int iRetCode;\r
1987         int iLength;\r
1988         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
1989         SOCKET listen_socket = INVALID_SOCKET; // data listen socket\r
1990         char Buf[1024];\r
1991         struct sockaddr_in saSockAddr1;\r
1992         int Resume;\r
1993         char Reply[ERR_MSG_LEN+7];\r
1994 \r
1995         if((listen_socket = GetFTPListenSocket(Pkt->ctrl_skt, &Canceled)) != INVALID_SOCKET)\r
1996         {\r
1997                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
1998                 if(Resume == NO)\r
1999                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
2000                 else\r
2001                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
2002 \r
2003                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
2004                 if((iRetCode/100) == FTP_PRELIM)\r
2005                 {\r
2006                         if(SocksGet2ndBindReply(listen_socket, &data_socket) == FAIL)\r
2007                         {\r
2008                                 iLength=sizeof(saSockAddr1);\r
2009                                 data_socket = do_accept(listen_socket,(struct sockaddr *)&saSockAddr1, (int *)&iLength);\r
2010 \r
2011                                 if(shutdown(listen_socket, 1) != 0)\r
2012                                         ReportWSError("shutdown listen", WSAGetLastError());\r
2013                                 listen_socket = DoClose(listen_socket);\r
2014 \r
2015                                 if(data_socket == INVALID_SOCKET)\r
2016                                 {\r
2017                                         SetErrorMsg(MSGJPN280);\r
2018                                         ReportWSError("accept", WSAGetLastError());\r
2019                                         iRetCode = 500;\r
2020                                 }\r
2021                                 else\r
2022                                         DoPrintf("Skt=%u : accept from %s port %u", data_socket, inet_ntoa(saSockAddr1.sin_addr), ntohs(saSockAddr1.sin_port));\r
2023                         }\r
2024 \r
2025                         if(data_socket != INVALID_SOCKET)\r
2026                         {\r
2027                                 // FTPS\91Î\89\9e\r
2028 //                              iRetCode = UpLoadFile(Pkt, data_socket);\r
2029                                 if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
2030                                 {\r
2031                                         if(AttachSSL(data_socket))\r
2032                                                 iRetCode = UpLoadFile(Pkt, data_socket);\r
2033                                         else\r
2034                                                 iRetCode = FTP_ERROR;\r
2035                                 }\r
2036                                 else\r
2037                                         iRetCode = UpLoadFile(Pkt, data_socket);\r
2038                                 data_socket = DoClose(data_socket);\r
2039                         }\r
2040                 }\r
2041                 else\r
2042                 {\r
2043                         SetErrorMsg(Reply);\r
2044                         SetTaskMsg(MSGJPN108);\r
2045                         listen_socket = DoClose(listen_socket);\r
2046                         iRetCode = 500;\r
2047                 }\r
2048         }\r
2049         else\r
2050         {\r
2051                 SetErrorMsg(MSGJPN279);\r
2052                 iRetCode = 500;\r
2053         }\r
2054         DispUploadFinishMsg(Pkt, iRetCode);\r
2055 \r
2056         return(iRetCode);\r
2057 }\r
2058 \r
2059 \r
2060 /*----- Passive\83\82\81[\83h\82Å\83t\83@\83C\83\8b\82ð\83A\83b\83v\83\8d\81[\83h ---------------------------------\r
2061 *\r
2062 *       Parameter\r
2063 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2064 *\r
2065 *       Return Value\r
2066 *               int \89\9e\93\9a\83R\81[\83h\r
2067 *----------------------------------------------------------------------------*/\r
2068 \r
2069 static int UpLoadPassive(TRANSPACKET *Pkt)\r
2070 {\r
2071         int iRetCode;\r
2072         SOCKET data_socket = INVALID_SOCKET;   // data channel socket\r
2073         char Buf[1024];\r
2074         char Adrs[20];\r
2075         int Port;\r
2076         int Flg;\r
2077         int Resume;\r
2078         char Reply[ERR_MSG_LEN+7];\r
2079 \r
2080         iRetCode = command(Pkt->ctrl_skt, Buf, &Canceled, "PASV");\r
2081         if(iRetCode/100 == FTP_COMPLETE)\r
2082         {\r
2083                 if(GetAdrsAndPort(Buf, Adrs, &Port, 19) == SUCCESS)\r
2084                 {\r
2085                         if((data_socket = connectsock(Adrs, Port, MSGJPN109, &Canceled)) != INVALID_SOCKET)\r
2086                         {\r
2087                                 // \95Ï\90\94\82ª\96¢\8f\89\8aú\89»\82Ì\83o\83O\8fC\90³\r
2088                                 Flg = 1;\r
2089                                 if(setsockopt(data_socket, IPPROTO_TCP, TCP_NODELAY, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
2090                                         ReportWSError("setsockopt", WSAGetLastError());\r
2091 \r
2092                                 SetUploadResume(Pkt, Pkt->Mode, Pkt->ExistSize, &Resume);\r
2093                                 if(Resume == NO)\r
2094                                         sprintf(Buf, "%s%s", Pkt->Cmd, Pkt->RemoteFile);\r
2095                                 else\r
2096                                         sprintf(Buf, "%s%s", "APPE ", Pkt->RemoteFile);\r
2097 \r
2098                                 iRetCode = command(Pkt->ctrl_skt, Reply, &Canceled, "%s", Buf);\r
2099                                 if(iRetCode/100 == FTP_PRELIM)\r
2100                                 {\r
2101                                         // FTPS\91Î\89\9e\r
2102 //                                      iRetCode = UpLoadFile(Pkt, data_socket);\r
2103                                         if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
2104                                         {\r
2105                                                 if(AttachSSL(data_socket))\r
2106                                                         iRetCode = UpLoadFile(Pkt, data_socket);\r
2107                                                 else\r
2108                                                         iRetCode = FTP_ERROR;\r
2109                                         }\r
2110                                         else\r
2111                                                 iRetCode = UpLoadFile(Pkt, data_socket);\r
2112 \r
2113                                         data_socket = DoClose(data_socket);\r
2114                                 }\r
2115                                 else\r
2116                                 {\r
2117                                         SetErrorMsg(Reply);\r
2118                                         SetTaskMsg(MSGJPN110);\r
2119                                         data_socket = DoClose(data_socket);\r
2120                                         iRetCode = 500;\r
2121                                 }\r
2122                         }\r
2123                         else\r
2124                         {\r
2125                                 SetErrorMsg(MSGJPN281);\r
2126                                 iRetCode = 500;\r
2127                         }\r
2128                 }\r
2129                 else\r
2130                 {\r
2131                         SetErrorMsg(Buf);\r
2132                         SetTaskMsg(MSGJPN111);\r
2133                         iRetCode = 500;\r
2134                 }\r
2135         }\r
2136         else\r
2137                 SetErrorMsg(Buf);\r
2138 \r
2139         DispUploadFinishMsg(Pkt, iRetCode);\r
2140 \r
2141         return(iRetCode);\r
2142 }\r
2143 \r
2144 \r
2145 /*----- \83A\83b\83v\83\8d\81[\83h\82Ì\8eÀ\8ds ----------------------------------------------------\r
2146 *\r
2147 *       Parameter\r
2148 *               TRANSPACKET *Pkt : \93]\91\97\83t\83@\83C\83\8b\8fî\95ñ\r
2149 *               SOCKET dSkt : \83f\81[\83^\83\\83P\83b\83g\r
2150 *\r
2151 *       Return Value\r
2152 *               int \89\9e\93\9a\83R\81[\83h\r
2153 *\r
2154 *       Note\r
2155 *               \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
2156 *               \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
2157 *----------------------------------------------------------------------------*/\r
2158 \r
2159 static int UpLoadFile(TRANSPACKET *Pkt, SOCKET dSkt)\r
2160 {\r
2161         DWORD iNumBytes;\r
2162         HANDLE iFileHandle;\r
2163         SECURITY_ATTRIBUTES Sec;\r
2164         char Buf[BUFSIZE];\r
2165         char Buf2[BUFSIZE+3];\r
2166         CODECONVINFO cInfo;\r
2167         TERMCODECONVINFO tInfo;\r
2168         int Continue;\r
2169         char *EofPos;\r
2170         int iRetCode;\r
2171 #if 0\r
2172         int TimeOutErr;\r
2173 #endif\r
2174         char TmpBuf[ONELINE_BUF_SIZE];\r
2175         DWORD Low;\r
2176         DWORD High;\r
2177 \r
2178 #ifdef SET_BUFFER_SIZE\r
2179 /* Add by H.Shirouzu at 2002/10/02 */\r
2180         int buf_size = SOCKBUF_SIZE;\r
2181         for ( ; buf_size > 0; buf_size /= 2)\r
2182                 if (setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size)) == 0)\r
2183                         break;\r
2184 /* End */\r
2185 #endif\r
2186 \r
2187         // \94O\82Ì\82½\82ß\91\97\90M\83o\83b\83t\83@\82ð\96³\8cø\82É\82·\82é\r
2188 #ifdef DISABLE_TRANSFER_NETWORK_BUFFERS\r
2189         int buf_size = 0;\r
2190         setsockopt(dSkt, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size));\r
2191 #endif\r
2192 \r
2193         Pkt->Abort = ABORT_NONE;\r
2194 \r
2195         Sec.nLength = sizeof(SECURITY_ATTRIBUTES);\r
2196         Sec.lpSecurityDescriptor = NULL;\r
2197         Sec.bInheritHandle = FALSE;\r
2198 \r
2199         if((iFileHandle = CreateFile(Pkt->LocalFile, GENERIC_READ,\r
2200                 FILE_SHARE_READ|FILE_SHARE_WRITE, &Sec, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)\r
2201         {\r
2202                 // UTF-8\91Î\89\9e\r
2203                 char Buf3[(BUFSIZE + 3) * 4];\r
2204                 CODECONVINFO cInfo2;\r
2205                 int ProcessedBOM = NO;\r
2206                 if(Pkt->hWndTrans != NULL)\r
2207                 {\r
2208                         Low = GetFileSize(iFileHandle, &High);\r
2209                         Pkt->Size = MakeLongLong(High, Low);\r
2210 \r
2211                         High = (DWORD)HIGH32(Pkt->ExistSize);\r
2212                         Low = (DWORD)LOW32(Pkt->ExistSize);\r
2213                         SetFilePointer(iFileHandle, Low, &High, FILE_BEGIN);\r
2214 \r
2215                         AllTransSizeNow = 0;\r
2216                         TimeStart = time(NULL);\r
2217                         SetTimer(Pkt->hWndTrans, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
2218                 }\r
2219 \r
2220                 InitCodeConvInfo(&cInfo);\r
2221                 cInfo.KanaCnv = Pkt->KanaCnv;\r
2222                 InitTermCodeConvInfo(&tInfo);\r
2223 \r
2224                 InitCodeConvInfo(&cInfo2);\r
2225                 cInfo2.KanaCnv = Pkt->KanaCnv;\r
2226 \r
2227                 /*===== \83t\83@\83C\83\8b\82ð\91\97\90M\82·\82é\83\8b\81[\83v =====*/\r
2228                 while((Pkt->Abort == ABORT_NONE) &&\r
2229                           (ForceAbort == NO) &&\r
2230                           (ReadFile(iFileHandle, Buf, BUFSIZE, &iNumBytes, NULL) == TRUE))\r
2231                 {\r
2232                         if(iNumBytes == 0)\r
2233                                 break;\r
2234 \r
2235                         /* EOF\8f\9c\8b\8e */\r
2236                         EofPos = NULL;\r
2237                         if((RmEOF == YES) && (Pkt->Type == TYPE_A))\r
2238                         {\r
2239                                 if((EofPos = memchr(Buf, 0x1A, iNumBytes)) != NULL)\r
2240                                         iNumBytes = EofPos - Buf;\r
2241                         }\r
2242 \r
2243                         /* \8a¿\8e\9a\83R\81[\83h\95Ï\8a· */\r
2244                         if(Pkt->KanjiCode != KANJI_NOCNV)\r
2245                         {\r
2246                                 cInfo.Str = Buf;\r
2247                                 cInfo.StrLen = iNumBytes;\r
2248                                 cInfo.Buf = Buf2;\r
2249                                 cInfo.BufSize = BUFSIZE+3;\r
2250                                 do\r
2251                                 {\r
2252                                         // \82±\82±\82Å\91S\82ÄUTF-8\82Ö\95Ï\8a·\82·\82é\r
2253                                         // TODO: SJIS\88È\8aO\82à\92¼\90ÚUTF-8\82Ö\95Ï\8a·\r
2254 //                                      if(Pkt->KanjiCode == KANJI_JIS)\r
2255 //                                              Continue = ConvSJIStoJIS(&cInfo);\r
2256 //                                      else\r
2257 //                                              Continue = ConvSJIStoEUC(&cInfo);\r
2258                                         switch(Pkt->KanjiCodeDesired)\r
2259                                         {\r
2260                                         case KANJI_SJIS:\r
2261                                                 switch(Pkt->KanjiCode)\r
2262                                                 {\r
2263                                                 case KANJI_SJIS:\r
2264 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2265 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2266 //                                                      Continue = NO;\r
2267                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2268                                                         Continue = ConvSJIStoJIS(&cInfo);\r
2269                                                         cInfo2.Str = cInfo.Buf;\r
2270                                                         cInfo2.StrLen = cInfo.OutLen;\r
2271                                                         cInfo2.Buf = Buf3;\r
2272                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2273                                                         ConvJIStoSJIS(&cInfo2);\r
2274                                                         break;\r
2275                                                 case KANJI_JIS:\r
2276                                                         Continue = ConvSJIStoJIS(&cInfo);\r
2277                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2278                                                         cInfo2.OutLen = cInfo.OutLen;\r
2279                                                         break;\r
2280                                                 case KANJI_EUC:\r
2281                                                         Continue = ConvSJIStoEUC(&cInfo);\r
2282                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2283                                                         cInfo2.OutLen = cInfo.OutLen;\r
2284                                                         break;\r
2285                                                 case KANJI_UTF8N:\r
2286                                                         if(ProcessedBOM == NO)\r
2287                                                         {\r
2288                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2289                                                                 cInfo2.OutLen = 3;\r
2290                                                                 Continue = YES;\r
2291                                                                 ProcessedBOM = YES;\r
2292                                                                 break;\r
2293                                                         }\r
2294                                                         Continue = ConvSJIStoUTF8N(&cInfo);\r
2295                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2296                                                         cInfo2.OutLen = cInfo.OutLen;\r
2297                                                         break;\r
2298                                                 }\r
2299                                                 break;\r
2300                                         case KANJI_JIS:\r
2301                                                 switch(Pkt->KanjiCode)\r
2302                                                 {\r
2303                                                 case KANJI_SJIS:\r
2304                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2305                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2306                                                         cInfo2.OutLen = cInfo.OutLen;\r
2307                                                         break;\r
2308                                                 case KANJI_JIS:\r
2309 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2310 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2311 //                                                      Continue = NO;\r
2312                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2313                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2314                                                         cInfo2.Str = cInfo.Buf;\r
2315                                                         cInfo2.StrLen = cInfo.OutLen;\r
2316                                                         cInfo2.Buf = Buf3;\r
2317                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2318                                                         ConvSJIStoJIS(&cInfo2);\r
2319                                                         break;\r
2320                                                 case KANJI_EUC:\r
2321                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2322                                                         cInfo2.Str = cInfo.Buf;\r
2323                                                         cInfo2.StrLen = cInfo.OutLen;\r
2324                                                         cInfo2.Buf = Buf3;\r
2325                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2326                                                         ConvSJIStoEUC(&cInfo2);\r
2327                                                         break;\r
2328                                                 case KANJI_UTF8N:\r
2329                                                         if(ProcessedBOM == NO)\r
2330                                                         {\r
2331                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2332                                                                 cInfo2.OutLen = 3;\r
2333                                                                 Continue = YES;\r
2334                                                                 ProcessedBOM = YES;\r
2335                                                                 break;\r
2336                                                         }\r
2337                                                         Continue = ConvJIStoSJIS(&cInfo);\r
2338                                                         cInfo2.Str = cInfo.Buf;\r
2339                                                         cInfo2.StrLen = cInfo.OutLen;\r
2340                                                         cInfo2.Buf = Buf3;\r
2341                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2342                                                         ConvSJIStoUTF8N(&cInfo2);\r
2343                                                         break;\r
2344                                                 }\r
2345                                                 break;\r
2346                                         case KANJI_EUC:\r
2347                                                 switch(Pkt->KanjiCode)\r
2348                                                 {\r
2349                                                 case KANJI_SJIS:\r
2350                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2351                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2352                                                         cInfo2.OutLen = cInfo.OutLen;\r
2353                                                         break;\r
2354                                                 case KANJI_JIS:\r
2355                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2356                                                         cInfo2.Str = cInfo.Buf;\r
2357                                                         cInfo2.StrLen = cInfo.OutLen;\r
2358                                                         cInfo2.Buf = Buf3;\r
2359                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2360                                                         ConvSJIStoJIS(&cInfo2);\r
2361                                                         break;\r
2362                                                 case KANJI_EUC:\r
2363 //                                                      memcpy(Buf3, cInfo.Str, cInfo.StrLen);\r
2364 //                                                      cInfo2.OutLen = cInfo.StrLen;\r
2365 //                                                      Continue = NO;\r
2366                                                         // \83J\83i\95Ï\8a·\82Ì\82½\82ß\r
2367                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2368                                                         cInfo2.Str = cInfo.Buf;\r
2369                                                         cInfo2.StrLen = cInfo.OutLen;\r
2370                                                         cInfo2.Buf = Buf3;\r
2371                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2372                                                         ConvSJIStoEUC(&cInfo2);\r
2373                                                         break;\r
2374                                                 case KANJI_UTF8N:\r
2375                                                         if(ProcessedBOM == NO)\r
2376                                                         {\r
2377                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2378                                                                 cInfo2.OutLen = 3;\r
2379                                                                 Continue = YES;\r
2380                                                                 ProcessedBOM = YES;\r
2381                                                                 break;\r
2382                                                         }\r
2383                                                         Continue = ConvEUCtoSJIS(&cInfo);\r
2384                                                         cInfo2.Str = cInfo.Buf;\r
2385                                                         cInfo2.StrLen = cInfo.OutLen;\r
2386                                                         cInfo2.Buf = Buf3;\r
2387                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2388                                                         ConvSJIStoUTF8N(&cInfo2);\r
2389                                                         break;\r
2390                                                 }\r
2391                                                 break;\r
2392                                         case KANJI_UTF8N:\r
2393                                                 if(ProcessedBOM == NO)\r
2394                                                 {\r
2395                                                         if(memcmp(Buf, "\xEF\xBB\xBF", 3) == 0)\r
2396                                                         {\r
2397                                                                 cInfo.Str += 3;\r
2398                                                                 cInfo.StrLen -= 3;\r
2399                                                         }\r
2400                                                         cInfo2.OutLen = 0;\r
2401                                                         switch(Pkt->KanjiCode)\r
2402                                                         {\r
2403                                                         case KANJI_UTF8N:\r
2404                                                                 memcpy(Buf3, "\xEF\xBB\xBF", 3);\r
2405                                                                 cInfo2.OutLen = 3;\r
2406                                                                 break;\r
2407                                                         }\r
2408                                                         Continue = YES;\r
2409                                                         ProcessedBOM = YES;\r
2410                                                         break;\r
2411                                                 }\r
2412                                                 switch(Pkt->KanjiCode)\r
2413                                                 {\r
2414                                                 case KANJI_SJIS:\r
2415                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2416                                                         memcpy(Buf3, cInfo.Buf, cInfo.OutLen);\r
2417                                                         cInfo2.OutLen = cInfo.OutLen;\r
2418                                                         break;\r
2419                                                 case KANJI_JIS:\r
2420                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2421                                                         cInfo2.Str = cInfo.Buf;\r
2422                                                         cInfo2.StrLen = cInfo.OutLen;\r
2423                                                         cInfo2.Buf = Buf3;\r
2424                                                         cInfo2.BufSize = (BUFSIZE + 3) * 4;\r
2425                                                         ConvSJIStoJIS(&cInfo2);\r
2426                                                         break;\r
2427                                                 case KANJI_EUC:\r
2428                                                         Continue = ConvUTF8NtoSJIS(&cInfo);\r
2429                                                         cInfo2.Str = cInfo.Buf;\r
2430                                                         cInfo2.StrLen = cInfo.OutLen;\r
2431                                                         cInfo2.Buf = Buf3;\r
2432                                      &