OSDN Git Service

Fix bugs of UTF-8 to UTF-16 API bridge.
authors_kawamoto <s_kawamoto@users.sourceforge.jp>
Thu, 22 Sep 2011 16:10:11 +0000 (01:10 +0900)
committers_kawamoto <s_kawamoto@users.sourceforge.jp>
Thu, 22 Sep 2011 16:10:11 +0000 (01:10 +0900)
Add support for additional features of hosts.
Add support for MLSD command.

FFFTP_Eng_Release/FFFTP.exe
Release/FFFTP.exe
common.h
connect.c
filelist.c
history.c
hostman.c
mbswrapper.c
mbswrapper.h
registory.c
remote.c

index 0b64ded..f81e343 100644 (file)
Binary files a/FFFTP_Eng_Release/FFFTP.exe and b/FFFTP_Eng_Release/FFFTP.exe differ
index d7e988d..f7a9129 100644 (file)
Binary files a/Release/FFFTP.exe and b/Release/FFFTP.exe differ
index 0061c89..4cfb78e 100644 (file)
--- a/common.h
+++ b/common.h
 #define LIST_UNIX_73   45              /* UNIX 73 */\r
 #define LIST_UNIX_74   46              /* UNIX 74 */\r
 #define LIST_UNIX_75   47              /* UNIX 75 */\r
 #define LIST_UNIX_73   45              /* UNIX 73 */\r
 #define LIST_UNIX_74   46              /* UNIX 74 */\r
 #define LIST_UNIX_75   47              /* UNIX 75 */\r
+// MLSD対応\r
+#define LIST_MLSD              48\r
 \r
 #define LIST_MELCOM            0x100   /* MELCOM80 */\r
 \r
 \r
 #define LIST_MELCOM            0x100   /* MELCOM80 */\r
 \r
@@ -868,6 +870,12 @@ LIST_UNIX_70
 #define CRYPT_FTPIS                    2\r
 #define CRYPT_SFTP                     3\r
 \r
 #define CRYPT_FTPIS                    2\r
 #define CRYPT_SFTP                     3\r
 \r
+// FEAT対応\r
+// UTF-8対応\r
+#define FEATURE_UTF8           0x00000001\r
+// MLSD対応\r
+#define FEATURE_MLSD           0x00000002\r
+\r
 \r
 /*=================================================\r
 *              ストラクチャ\r
 \r
 /*=================================================\r
 *              ストラクチャ\r
@@ -918,6 +926,10 @@ typedef struct {
        int UseSFTP;                                            /* SFTPで接続する (YES/NO) */\r
        // 同時接続対応\r
        int MaxThreadCount;                                     /* 同時接続数 */\r
        int UseSFTP;                                            /* SFTPで接続する (YES/NO) */\r
        // 同時接続対応\r
        int MaxThreadCount;                                     /* 同時接続数 */\r
+       // FEAT対応\r
+       int Feature;                                            /* 利用可能な機能のフラグ (FEATURE_xxx) */\r
+       // MLSD対応\r
+       int UseMLSD;                                            /* "MLSD"コマンドを使用する */\r
 } HOSTDATA;\r
 \r
 \r
 } HOSTDATA;\r
 \r
 \r
@@ -970,6 +982,8 @@ typedef struct historydata {
        int UseSFTP;                                            /* SFTPで接続する (YES/NO) */\r
        // 同時接続対応\r
        int MaxThreadCount;                                     /* 同時接続数 */\r
        int UseSFTP;                                            /* SFTPで接続する (YES/NO) */\r
        // 同時接続対応\r
        int MaxThreadCount;                                     /* 同時接続数 */\r
+       // MLSD対応\r
+       int UseMLSD;                                            /* "MLSD"コマンドを使用する */\r
        struct historydata *Next;\r
 } HISTORYDATA;\r
 \r
        struct historydata *Next;\r
 } HISTORYDATA;\r
 \r
@@ -1383,6 +1397,10 @@ int AskUseFTPIS(void);
 int AskUseSFTP(void);\r
 // 同時接続対応\r
 int AskMaxThreadCount(void);\r
 int AskUseSFTP(void);\r
 // 同時接続対応\r
 int AskMaxThreadCount(void);\r
+// FEAT対応\r
+int AskHostFeature(void);\r
+// MLSD対応\r
+int AskUseMLSD(void);\r
 \r
 /*===== cache.c =====*/\r
 \r
 \r
 /*===== cache.c =====*/\r
 \r
index bb43e11..7259032 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -957,7 +957,7 @@ int ReConnectCmdSkt(void)
 // 同時接続対応\r
 int ReConnectTrnSkt(SOCKET *Skt)\r
 {\r
 // 同時接続対応\r
 int ReConnectTrnSkt(SOCKET *Skt)\r
 {\r
-       char Path[FMAX_PATH+1];\r
+//     char Path[FMAX_PATH+1];\r
        int Sts;\r
 \r
        Sts = FFFTP_FAIL;\r
        int Sts;\r
 \r
        Sts = FFFTP_FAIL;\r
@@ -1476,6 +1476,29 @@ static SOCKET DoConnect(char *Host, char *User, char *Pass, char *Acct, int Port
 #endif\r
        TryConnect = NO;\r
 \r
 #endif\r
        TryConnect = NO;\r
 \r
+       // FEAT対応\r
+       // ホストの機能を確認\r
+       if(ContSock != INVALID_SOCKET)\r
+       {\r
+               if((Sts = command(ContSock, Reply, &CancelFlg, "FEAT")) == 211)\r
+               {\r
+                       // 改行文字はReadReplyMessageで消去されるため区切り文字に空白を使用\r
+                       // UTF-8対応\r
+                       if(strstr(Reply, " UTF8 "))\r
+                               CurHost.Feature |= FEATURE_UTF8;\r
+                       // MLST対応\r
+                       if(strstr(Reply, " MLST ") || strstr(Reply, " MLSD "))\r
+                               CurHost.Feature |= FEATURE_MLSD;\r
+               }\r
+               // UTF-8対応\r
+               if(CurHost.NameKanjiCode == KANJI_AUTO && (CurHost.Feature & FEATURE_UTF8))\r
+               {\r
+                       if((Sts = command(ContSock, Reply, &CancelFlg, "OPTS UTF8 ON")) == 200)\r
+                       {\r
+                       }\r
+               }\r
+       }\r
+\r
        return(ContSock);\r
 }\r
 \r
        return(ContSock);\r
 }\r
 \r
@@ -2238,3 +2261,15 @@ int AskMaxThreadCount(void)
        return(CurHost.MaxThreadCount);\r
 }\r
 \r
        return(CurHost.MaxThreadCount);\r
 }\r
 \r
+// FEAT対応\r
+int AskHostFeature(void)\r
+{\r
+       return(CurHost.Feature);\r
+}\r
+\r
+// MLSD対応\r
+int AskUseMLSD(void)\r
+{\r
+       return(CurHost.UseMLSD);\r
+}\r
+\r
index 9436ac5..33edb2c 100644 (file)
@@ -97,6 +97,8 @@ static int CheckYYMMDDformat(char *Str, char Sym, int Dig3);
 static int CheckYYYYMMDDformat(char *Str, char Sym);\r
 static int ResolvFileInfo(char *Str, int ListType, char *Fname, LONGLONG *Size, FILETIME *Time, int *Attr, char *Owner, int *Link, int *InfoExist);\r
 static int FindField(char *Str, char *Buf, int Num, int ToLast);\r
 static int CheckYYYYMMDDformat(char *Str, char Sym);\r
 static int ResolvFileInfo(char *Str, int ListType, char *Fname, LONGLONG *Size, FILETIME *Time, int *Attr, char *Owner, int *Link, int *InfoExist);\r
 static int FindField(char *Str, char *Buf, int Num, int ToLast);\r
+// MLSD対応\r
+static int FindField2(char *Str, char *Buf, char Separator, int Num, int ToLast);\r
 static void GetMonth(char *Str, WORD *Month, WORD *Day);\r
 static int GetYearMonthDay(char *Str, WORD *Year, WORD *Month, WORD *Day);\r
 static int GetHourAndMinute(char *Str, WORD *Hour, WORD *Minute);\r
 static void GetMonth(char *Str, WORD *Month, WORD *Day);\r
 static int GetYearMonthDay(char *Str, WORD *Year, WORD *Month, WORD *Day);\r
 static int GetHourAndMinute(char *Str, WORD *Hour, WORD *Minute);\r
@@ -3594,6 +3596,14 @@ static int AnalizeFileInfo(char *Str)
                        }\r
                }\r
 \r
                        }\r
                }\r
 \r
+               // MLSD対応\r
+               if(Ret == LIST_UNKNOWN)\r
+               {\r
+                       if(FindField2(Str, Tmp, ';', 1, NO) == FFFTP_SUCCESS && FindField2(Str, Tmp, '=', 1, NO) == FFFTP_SUCCESS)\r
+                       {\r
+                               Ret = LIST_MLSD;\r
+                       }\r
+               }\r
        }\r
 \r
 DoPrintf("ListType=%d", Ret);\r
        }\r
 \r
 DoPrintf("ListType=%d", Ret);\r
@@ -4830,6 +4840,56 @@ static int ResolvFileInfo(char *Str, int ListType, char *Fname, LONGLONG *Size,
                                        Ret = NODE_NONE;\r
                        }\r
                        break;\r
                                        Ret = NODE_NONE;\r
                        }\r
                        break;\r
+\r
+                       // MLSD対応\r
+               case LIST_MLSD:\r
+                       {\r
+                               int i = 0;\r
+                               char Tmp[FMAX_PATH + 1];\r
+                               char Name[FMAX_PATH + 1];\r
+                               char Value[FMAX_PATH + 1];\r
+                               while(FindField2(Str, Tmp, ';', i, NO) == FFFTP_SUCCESS)\r
+                               {\r
+                                       if(strncmp(Tmp, " ", 1) == 0)\r
+                                               strcpy(Fname, Tmp + 1);\r
+                                       else if(FindField2(Tmp, Name, '=', 0, NO) == FFFTP_SUCCESS && FindField2(Tmp, Value, '=', 1, NO) == FFFTP_SUCCESS)\r
+                                       {\r
+                                               if(_stricmp(Name, "type") == 0)\r
+                                               {\r
+                                                       if(_stricmp(Value, "dir") == 0)\r
+                                                               Ret = NODE_DIR;\r
+                                                       else if(_stricmp(Value, "file") == 0)\r
+                                                               Ret = NODE_FILE;\r
+                                               }\r
+                                               else if(_stricmp(Name, "size") == 0)\r
+                                               {\r
+                                                       *Size = _atoi64(Value);\r
+                                                       *InfoExist |= FINFO_SIZE;\r
+                                               }\r
+                                               else if(_stricmp(Name, "modify") == 0)\r
+                                               {\r
+                                                       sTime.wYear = atoi_n(Value, 4);\r
+                                                       sTime.wMonth = atoi_n(Value + 4, 2);\r
+                                                       sTime.wDay = atoi_n(Value + 6, 2);\r
+                                                       sTime.wHour = atoi_n(Value + 8, 2);\r
+                                                       sTime.wMinute = atoi_n(Value + 10, 2);\r
+                                                       sTime.wSecond = atoi_n(Value + 12, 2);\r
+                                                       SystemTimeToFileTime(&sTime, Time);\r
+                                                       SpecificLocalFileTime2FileTime(Time, AskHostTimeZone());\r
+                                                       *InfoExist |= FINFO_DATE | FINFO_TIME;\r
+                                               }\r
+                                               else if(_stricmp(Name, "UNIX.mode") == 0)\r
+                                               {\r
+                                                       *Attr = strtol(Value, NULL, 16);\r
+                                                       *InfoExist |= FINFO_ATTR;\r
+                                               }\r
+                                               else if(_stricmp(Name, "UNIX.owner") == 0)\r
+                                                       strcpy(Owner, Value);\r
+                                       }\r
+                                       i++;\r
+                               }\r
+                       }\r
+                       break;\r
        }\r
 \r
        if((Ret != NODE_NONE) && (strlen(Fname) > 0))\r
        }\r
 \r
        if((Ret != NODE_NONE) && (strlen(Fname) > 0))\r
@@ -4902,6 +4962,53 @@ static int FindField(char *Str, char *Buf, int Num, int ToLast)
 }\r
 \r
 \r
 }\r
 \r
 \r
+// MLSD対応\r
+static int FindField2(char *Str, char *Buf, char Separator, int Num, int ToLast)\r
+{\r
+       char *Pos;\r
+       int Sts;\r
+\r
+       Sts = FFFTP_FAIL;\r
+       *Buf = NUL;\r
+       if(Num >= 0)\r
+       {\r
+               while(*Str == Separator)\r
+                       Str++;\r
+\r
+               for(; Num > 0; Num--)\r
+               {\r
+                       if((Str = strchr(Str, Separator)) != NULL)\r
+                       {\r
+                               while(*Str == Separator)\r
+                               {\r
+                                       if(*Str == NUL)\r
+                                       {\r
+                                               Str = NULL;\r
+                                               break;\r
+                                       }\r
+                                       Str++;\r
+                               }\r
+                       }\r
+                       else\r
+                               break;\r
+               }\r
+       }\r
+\r
+       if(Str != NULL)\r
+       {\r
+               if((ToLast == YES) || ((Pos = strchr(Str, Separator)) == NULL))\r
+                       strcpy(Buf, Str);\r
+               else\r
+               {\r
+                       strncpy(Buf, Str, Pos - Str);\r
+                       *(Buf + (Pos - Str)) = NUL;\r
+               }\r
+               Sts = FFFTP_SUCCESS;\r
+       }\r
+       return(Sts);\r
+}\r
+\r
+\r
 /*----- 文字列から月を求める --------------------------------------------------\r
 *\r
 *      Parameter\r
 /*----- 文字列から月を求める --------------------------------------------------\r
 *\r
 *      Parameter\r
index a2aec84..9e1e464 100644 (file)
--- a/history.c
+++ b/history.c
@@ -229,6 +229,8 @@ static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New)
        New->UseSFTP = Host->UseSFTP;\r
        // 同時接続対応\r
        New->MaxThreadCount = Host->MaxThreadCount;\r
        New->UseSFTP = Host->UseSFTP;\r
        // 同時接続対応\r
        New->MaxThreadCount = Host->MaxThreadCount;\r
+       // MLSD対応\r
+       New->UseMLSD = Host->UseMLSD;\r
        return;\r
 }\r
 \r
        return;\r
 }\r
 \r
@@ -284,6 +286,8 @@ void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)
        Host->UseSFTP = Hist->UseSFTP;\r
        // 同時接続対応\r
        Host->MaxThreadCount = Hist->MaxThreadCount;\r
        Host->UseSFTP = Hist->UseSFTP;\r
        // 同時接続対応\r
        Host->MaxThreadCount = Hist->MaxThreadCount;\r
+       // MLSD対応\r
+       Host->UseMLSD = Hist->UseMLSD;\r
        return;\r
 }\r
 \r
        return;\r
 }\r
 \r
index b1e0343..b79519f 100644 (file)
--- a/hostman.c
+++ b/hostman.c
@@ -1029,6 +1029,8 @@ int CopyHostFromListInConnect(int Num, HOSTDATA *Set)
                Set->UseSFTP = Pos->Set.UseSFTP;\r
                // 同時接続対応\r
                Set->MaxThreadCount = Pos->Set.MaxThreadCount;\r
                Set->UseSFTP = Pos->Set.UseSFTP;\r
                // 同時接続対応\r
                Set->MaxThreadCount = Pos->Set.MaxThreadCount;\r
+               // MLSD対応\r
+               Set->UseMLSD = Pos->Set.UseMLSD;\r
                Sts = FFFTP_SUCCESS;\r
        }\r
        return(Sts);\r
                Sts = FFFTP_SUCCESS;\r
        }\r
        return(Sts);\r
@@ -1309,6 +1311,9 @@ void CopyDefaultHost(HOSTDATA *Set)
        Set->UseSFTP = YES;\r
        // 同時接続対応\r
        Set->MaxThreadCount = 1;\r
        Set->UseSFTP = YES;\r
        // 同時接続対応\r
        Set->MaxThreadCount = 1;\r
+       // MLSD対応\r
+       Set->Feature = 0;\r
+       Set->UseMLSD = YES;\r
        return;\r
 }\r
 \r
        return;\r
 }\r
 \r
index 08a549b..585a26b 100644 (file)
@@ -355,6 +355,18 @@ void FreeDuplicatedString(void* p)
 #define END_ROUTINE                                            }while(0);end_of_routine:
 #define QUIT_ROUTINE                                   goto end_of_routine;
 
 #define END_ROUTINE                                            }while(0);end_of_routine:
 #define QUIT_ROUTINE                                   goto end_of_routine;
 
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
+{
+       int r = 0;
+       char* pm0 = NULL;
+START_ROUTINE
+       pm0 = DuplicateWtoM(lpCmdLine, -1);
+       r = WinMainM(hInstance, hPrevInstance, pm0, nCmdShow);
+END_ROUTINE
+       FreeDuplicatedString(pm0);
+       return r;
+}
+
 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
 {
        HANDLE r = INVALID_HANDLE_VALUE;
 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
 {
        HANDLE r = INVALID_HANDLE_VALUE;
index 50e1ae1..cb4f3ab 100644 (file)
@@ -11,6 +11,9 @@
 
 #ifndef DO_NOT_REPLACE
 
 
 #ifndef DO_NOT_REPLACE
 
+#undef WinMain
+#define WinMain WinMainM
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow);
 #undef CreateFile
 #define CreateFile CreateFileM
 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
 #undef CreateFile
 #define CreateFile CreateFileM
 HANDLE CreateFileM(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
@@ -222,5 +225,7 @@ char* DuplicateWtoM(LPCWSTR lpString, int c);
 char* DuplicateWtoA(LPCWSTR lpString, int c);
 void FreeDuplicatedString(void* p);
 
 char* DuplicateWtoA(LPCWSTR lpString, int c);
 void FreeDuplicatedString(void* p);
 
+int WINAPI WinMainM(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
+
 #endif
 
 #endif
 
index 578d3ac..b6e4648 100644 (file)
@@ -468,6 +468,8 @@ void SaveRegistory(void)
                                                        SaveIntNum(hKey5, "SFTP", Hist.UseSFTP, DefaultHist.UseSFTP);\r
                                                        // 同時接続対応\r
                                                        SaveIntNum(hKey5, "ThreadCount", Hist.MaxThreadCount, DefaultHist.MaxThreadCount);\r
                                                        SaveIntNum(hKey5, "SFTP", Hist.UseSFTP, DefaultHist.UseSFTP);\r
                                                        // 同時接続対応\r
                                                        SaveIntNum(hKey5, "ThreadCount", Hist.MaxThreadCount, DefaultHist.MaxThreadCount);\r
+                                                       // MLSD対応\r
+                                                       SaveIntNum(hKey5, "MLSD", Hist.UseMLSD, DefaultHist.UseMLSD);\r
 \r
                                                        CloseSubKey(hKey5);\r
                                                        n++;\r
 \r
                                                        CloseSubKey(hKey5);\r
                                                        n++;\r
@@ -542,6 +544,8 @@ void SaveRegistory(void)
                                                        SaveIntNum(hKey5, "SFTP", Host.UseSFTP, DefaultHost.UseSFTP);\r
                                                        // 同時接続対応\r
                                                        SaveIntNum(hKey5, "ThreadCount", Host.MaxThreadCount, DefaultHost.MaxThreadCount);\r
                                                        SaveIntNum(hKey5, "SFTP", Host.UseSFTP, DefaultHost.UseSFTP);\r
                                                        // 同時接続対応\r
                                                        SaveIntNum(hKey5, "ThreadCount", Host.MaxThreadCount, DefaultHost.MaxThreadCount);\r
+                                                       // MLSD対応\r
+                                                       SaveIntNum(hKey5, "MLSD", Host.UseMLSD, DefaultHost.UseMLSD);\r
                                                }\r
                                                CloseSubKey(hKey5);\r
                                        }\r
                                                }\r
                                                CloseSubKey(hKey5);\r
                                        }\r
@@ -798,6 +802,8 @@ int LoadRegistory(void)
                                        ReadIntValueFromReg(hKey5, "SFTP", &Hist.UseSFTP);\r
                                        // 同時接続対応\r
                                        ReadIntValueFromReg(hKey5, "ThreadCount", &Hist.MaxThreadCount);\r
                                        ReadIntValueFromReg(hKey5, "SFTP", &Hist.UseSFTP);\r
                                        // 同時接続対応\r
                                        ReadIntValueFromReg(hKey5, "ThreadCount", &Hist.MaxThreadCount);\r
+                                       // MLSD対応\r
+                                       ReadIntValueFromReg(hKey5, "MLSD", &Hist.UseMLSD);\r
 \r
                                        CloseSubKey(hKey5);\r
                                        AddHistoryToHistory(&Hist);\r
 \r
                                        CloseSubKey(hKey5);\r
                                        AddHistoryToHistory(&Hist);\r
@@ -871,6 +877,8 @@ int LoadRegistory(void)
                                        ReadIntValueFromReg(hKey5, "SFTP", &Host.UseSFTP);\r
                                        // 同時接続対応\r
                                        ReadIntValueFromReg(hKey5, "ThreadCount", &Host.MaxThreadCount);\r
                                        ReadIntValueFromReg(hKey5, "SFTP", &Host.UseSFTP);\r
                                        // 同時接続対応\r
                                        ReadIntValueFromReg(hKey5, "ThreadCount", &Host.MaxThreadCount);\r
+                                       // MLSD対応\r
+                                       ReadIntValueFromReg(hKey5, "MLSD", &Host.UseMLSD);\r
 \r
                                        CloseSubKey(hKey5);\r
 \r
 \r
                                        CloseSubKey(hKey5);\r
 \r
index 3b8c736..a61b119 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -593,7 +593,12 @@ static int DoDirList(HWND hWnd, SOCKET cSkt, char *AddOpt, char *Path, int Num,
        }\r
        else\r
        {\r
        }\r
        else\r
        {\r
-               strcpy(MainTransPkt.Cmd, "LIST");\r
+               // MLSD対応\r
+//             strcpy(MainTransPkt.Cmd, "LIST");\r
+               if(AskUseMLSD() && (AskHostFeature() & FEATURE_MLSD))\r
+                       strcpy(MainTransPkt.Cmd, "MLSD");\r
+               else\r
+                       strcpy(MainTransPkt.Cmd, "LIST");\r
                if(strlen(AddOpt) > 0)\r
                {\r
                        strcat(MainTransPkt.Cmd, " -");\r
                if(strlen(AddOpt) > 0)\r
                {\r
                        strcat(MainTransPkt.Cmd, " -");\r