OSDN Git Service

Change the character code of windows into UTF-16 completely.
[ffftp/ffftp.git] / main.c
diff --git a/main.c b/main.c
index 25b623a..3b7df5b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -28,6 +28,8 @@
 /============================================================================*/\r
 \r
 #define  STRICT\r
+// IPv6対応\r
+#include <winsock2.h>\r
 #include <windows.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -37,7 +39,8 @@
 #include <windowsx.h>\r
 #include <commctrl.h>\r
 #include <stdarg.h>\r
-#include <winsock.h>\r
+// IPv6対応\r
+//#include <winsock.h>\r
 \r
 #include "common.h"\r
 #include "resource.h"\r
@@ -127,6 +130,11 @@ static int SuppressRefresh = 0;
 \r
 static DWORD dwCookie;\r
 \r
+// 暗号化通信対応\r
+static char SSLRootCAFilePath[FMAX_PATH+1];\r
+// マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策\r
+static DWORD MainThreadId;\r
+\r
 \r
 /*===== グローバルなワーク =====*/\r
 \r
@@ -218,10 +226,9 @@ int MirUpDelNotify = YES;
 int MirDownDelNotify = YES; \r
 int FolderAttr = NO;\r
 int FolderAttrNum = 777;\r
-// 同時接続対応\r
-int MaxThreadCount = 1;\r
 // 暗号化通信対応\r
 BYTE CertificateCacheHash[MAX_CERT_CACHE_HASH][20];\r
+BYTE SSLRootCAFileHash[20];\r
 \r
 \r
 \r
@@ -308,9 +315,11 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi
                InitializeLoadLibraryHook();\r
 #endif\r
 \r
+       // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策\r
 #ifdef DISABLE_MULTI_CPUS\r
        SetProcessAffinityMask(GetCurrentProcess(), 1);\r
 #endif\r
+       MainThreadId = GetCurrentThreadId();\r
 \r
        // yutaka\r
        if(OleInitialize(NULL) != S_OK){\r
@@ -471,6 +480,9 @@ static int InitApp(LPSTR lpszCmdLine, int cmdShow)
                        // 暗号化通信対応\r
                        SetSSLTimeoutCallback(TimeOut * 1000, SSLTimeoutCallback);\r
                        SetSSLConfirmCallback(SSLConfirmCallback);\r
+                       GetModuleFileName(NULL, SSLRootCAFilePath, FMAX_PATH);\r
+                       strcpy(GetFileName(SSLRootCAFilePath), "ssl.pem");\r
+                       LoadSSLRootCAFile();\r
 \r
                        LoadJre();\r
                        if(NoRasControl == NO)\r
@@ -620,13 +632,7 @@ static int MakeAllWindows(int cmdShow)
                WinPosX = CW_USEDEFAULT;\r
                WinPosY = 0;\r
        }\r
-       // UTF-8対応\r
-       // ユーザー定義のクラスはデフォルトのWNDPROCがShift_JIS専用のため\r
-//     hWndFtp = CreateWindow(FtpClassStr, "FFFTP",\r
-//                             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,\r
-//                             WinPosX, WinPosY, WinWidth, WinHeight,\r
-//                             HWND_DESKTOP, 0, hInstFtp, NULL);\r
-       hWndFtp = CreateWindowA(FtpClassStr, "FFFTP",\r
+       hWndFtp = CreateWindow(FtpClassStr, "FFFTP",\r
                                WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,\r
                                WinPosX, WinPosY, WinWidth, WinHeight,\r
                                HWND_DESKTOP, 0, hInstFtp, NULL);\r
@@ -833,12 +839,20 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
 {\r
        PAINTSTRUCT ps;\r
        LPTOOLTIPTEXT lpttt;\r
+       // UTF-8対応\r
+       LPTOOLTIPTEXTW wlpttt;\r
        RECT Rect;\r
 \r
        int TmpTransType;\r
 \r
        switch (message)\r
        {\r
+               // 自動切断対策\r
+               case WM_TIMER :\r
+                       if(wParam == 1)\r
+                               NoopProc();\r
+                       break;\r
+\r
                case WM_COMMAND :\r
                        // 同時接続対応\r
                        // 中断後に受信バッファに応答が残っていると次のコマンドの応答が正しく処理できない\r
@@ -847,11 +861,21 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
                        switch(LOWORD(wParam))\r
                        {\r
                                case MENU_CONNECT :\r
+                                       // 自動切断対策\r
+                                       KillTimer(hWnd, 1);\r
                                        ConnectProc(DLG_TYPE_CON, -1);\r
+                                       // 自動切断対策\r
+                                       if(AskNoopInterval() > 0)\r
+                                               SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL);\r
                                        break;\r
 \r
                                case MENU_CONNECT_NUM :\r
+                                       // 自動切断対策\r
+                                       KillTimer(hWnd, 1);\r
                                        ConnectProc(DLG_TYPE_CON, (int)lParam);\r
+                                       // 自動切断対策\r
+                                       if(AskNoopInterval() > 0)\r
+                                               SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL);\r
                                        if(AskConnecting() == YES)\r
                                        {\r
                                                if(HIWORD(wParam) & OPT_MIRROR)\r
@@ -872,11 +896,21 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
                                        break;\r
 \r
                                case MENU_SET_CONNECT :\r
+                                       // 自動切断対策\r
+                                       KillTimer(hWnd, 1);\r
                                        ConnectProc(DLG_TYPE_SET, -1);\r
+                                       // 自動切断対策\r
+                                       if(AskNoopInterval() > 0)\r
+                                               SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL);\r
                                        break;\r
 \r
                                case MENU_QUICK :\r
+                                       // 自動切断対策\r
+                                       KillTimer(hWnd, 1);\r
                                        QuickConnectProc();\r
+                                       // 自動切断対策\r
+                                       if(AskNoopInterval() > 0)\r
+                                               SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL);\r
                                        break;\r
 \r
                                case MENU_DISCONNECT :\r
@@ -910,7 +944,12 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
                                case MENU_HIST_18 :\r
                                case MENU_HIST_19 :\r
                                case MENU_HIST_20 :\r
+                                       // 自動切断対策\r
+                                       KillTimer(hWnd, 1);\r
                                        HistoryConnectProc(LOWORD(wParam));\r
+                                       // 自動切断対策\r
+                                       if(AskNoopInterval() > 0)\r
+                                               SetTimer(hWnd, 1, AskNoopInterval() * 1000, NULL);\r
                                        break;\r
 \r
                                case MENU_UPDIR :\r
@@ -1367,8 +1406,13 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
                        switch(((LPNMHDR)lParam)->code)\r
                        {\r
                                /* ツールチップコントロールメッセージの処理 */\r
-                               case TTN_NEEDTEXT:\r
+                               // UTF-8対応\r
+//                             case TTN_NEEDTEXT:\r
+                               case TTN_NEEDTEXTW:\r
                                        lpttt = (LPTOOLTIPTEXT)lParam;\r
+                                       // UTF-8対応\r
+                                       // lptttは単なる警告回避用\r
+                                       wlpttt = (LPTOOLTIPTEXTW)lParam;\r
                                        lpttt->hinst = hInstFtp;\r
                                        switch(lpttt->hdr.idFrom)\r
                                        {\r
@@ -1498,15 +1542,14 @@ static LRESULT CALLBACK FtpWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA
                                                        lpttt->lpszText = MSGJPN176;\r
                                                        break;\r
                                        }\r
-                                       // UTF-8からShift_JISへ変換\r
+                                       // UTF-8対応\r
+                                       // UTF-8からUTF-16 LEへ変換\r
                                        {\r
                                                static wchar_t StringBufferUTF16[1024];\r
-                                               static char StringBufferSJIS[1024];\r
                                                if(lpttt->lpszText)\r
                                                {\r
                                                        MtoW(StringBufferUTF16, sizeof(StringBufferUTF16)/ sizeof(wchar_t), lpttt->lpszText, -1);\r
-                                                       WtoA(StringBufferSJIS, sizeof(StringBufferSJIS)/ sizeof(char), StringBufferUTF16, -1);\r
-                                                       lpttt->lpszText = StringBufferSJIS;\r
+                                                       wlpttt->lpszText = StringBufferUTF16;\r
                                                }\r
                                        }\r
                                        break;\r
@@ -2478,7 +2521,7 @@ void ExecViewer(char *Fname, int App)
        // 任意のコードが実行されるバグ修正\r
        // 拡張子が無いと補完されるため\r
 //     if((App == -1) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32))\r
-       if((App == -1) && strrchr(Fname, '.') > strrchr(Fname, '\\') && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32))\r
+       if((App == -1) && (strlen(GetFileExt(GetFileName(Fname))) > 0) && (FindExecutable(Fname, NULL, AssocProg) > (HINSTANCE)32))\r
        {\r
                DoPrintf("ShellExecute - %s", Fname);\r
                ShellExecute(NULL, "open", Fname, NULL, CurDir, SW_SHOW);\r
@@ -2792,7 +2835,9 @@ int BackgrndMessageProc(void)
        Ret = NO;\r
        while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))\r
        {\r
-               if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg))\r
+               // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策\r
+//             if(!HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg))\r
+               if(!IsMainThread() || !HtmlHelp(NULL, NULL, HH_PRETRANSLATEMESSAGE, (DWORD)&Msg))\r
                {\r
                        /* ディレクトリ名の表示コンボボックスでBSやRETが効くように */\r
                        /* コンボボックス内ではアクセラレータを無効にする */\r
@@ -2914,11 +2959,14 @@ BOOL __stdcall SSLTimeoutCallback(BOOL* pbAborted)
 BOOL __stdcall SSLConfirmCallback(BOOL* pbAborted, BOOL bVerified, LPCSTR Certificate, LPCSTR CommonName)\r
 {\r
        BOOL bResult;\r
-       int i;\r
        uint32 Hash[5];\r
+       int i;\r
        char* pm0;\r
        bResult = FALSE;\r
        sha_memory((char*)Certificate, (uint32)(strlen(Certificate) * sizeof(char)), (uint32*)&Hash);\r
+       // sha.cはビッグエンディアンのため\r
+       for(i = 0; i < 5; i++)\r
+               Hash[i] = _byteswap_ulong(Hash[i]);\r
        i = 0;\r
        while(i < MAX_CERT_CACHE_HASH)\r
        {\r
@@ -2949,3 +2997,46 @@ BOOL __stdcall SSLConfirmCallback(BOOL* pbAborted, BOOL bVerified, LPCSTR Certif
        return bResult;\r
 }\r
 \r
+BOOL LoadSSLRootCAFile()\r
+{\r
+       BOOL bResult;\r
+       HANDLE hFile;\r
+       DWORD Size;\r
+       BYTE* pBuffer;\r
+       uint32 Hash[5];\r
+       int i;\r
+       bResult = FALSE;\r
+       if((hFile = CreateFile(SSLRootCAFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)\r
+       {\r
+               Size = GetFileSize(hFile, NULL);\r
+               if(pBuffer = (BYTE*)malloc(Size))\r
+               {\r
+                       if(ReadFile(hFile, pBuffer, Size, &Size, NULL))\r
+                       {\r
+                               sha_memory((char*)pBuffer, (uint32)Size, (uint32*)&Hash);\r
+                               // sha.cはビッグエンディアンのため\r
+                               for(i = 0; i < 5; i++)\r
+                                       Hash[i] = _byteswap_ulong(Hash[i]);\r
+                               // 同梱する"ssl.pem"に合わせてSHA1ハッシュ値を変更すること\r
+                               if(memcmp(&Hash, &SSLRootCAFileHash, 20) == 0 || memcmp(&Hash, "\xF0\x1B\x48\x26\x67\x44\x3A\xFF\x0A\x16\xD3\xBB\x8A\x33\xEB\x70\x6D\x75\xA6\x0D", 20) == 0\r
+                                       || DialogBox(GetFtpInst(), MAKEINTRESOURCE(updatesslroot_dlg), GetMainHwnd(), ExeEscDialogProc) == YES)\r
+                               {\r
+                                       memcpy(&SSLRootCAFileHash, &Hash, 20);\r
+                                       if(SetSSLRootCertificate(pBuffer, Size))\r
+                                               bResult = TRUE;\r
+                               }\r
+                       }\r
+                       free(pBuffer);\r
+               }\r
+               CloseHandle(hFile);\r
+       }\r
+       return bResult;\r
+}\r
+\r
+// マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策\r
+BOOL IsMainThread()\r
+{\r
+       if(GetCurrentThreadId() != MainThreadId)\r
+               return FALSE;\r
+       return TRUE;\r
+}
\ No newline at end of file