• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision8533 (tree)
Time2020-02-09 14:55:20
Authorzmatsuo

Log Message

TTSSH 設定ダイアログを多言語化

- Debugビルド時、終了時のメモリリークチェックを常に行うようにした

Change Summary

Incremental Difference

--- trunk/ttssh2/ttxssh/ttxssh.c (revision 8532)
+++ trunk/ttssh2/ttxssh/ttxssh.c (revision 8533)
@@ -84,6 +84,8 @@
8484
8585 #include "compat_w95.h"
8686 #include "compat_win.h"
87+#include "layer_for_unicode.h"
88+#include "codeconv.h"
8789
8890 #include "libputty.h"
8991
@@ -2532,71 +2534,61 @@
25322534 return FALSE;
25332535 }
25342536
2535-static char *get_cipher_name(int cipher)
2537+void UTIL_get_lang_msgW(const char *key, wchar_t *UIMsg, const wchar_t *def)
25362538 {
2537- switch (cipher) {
2538- case SSH_CIPHER_NONE:
2539- UTIL_get_lang_msg("DLG_SSHSETUP_CIPHER_BORDER", pvar,
2540- "<ciphers below this line are disabled>");
2541- return pvar->ts->UIMsg;
2542- case SSH_CIPHER_3DES:
2543- return "3DES(SSH1)";
2544- case SSH_CIPHER_DES:
2545- return "DES(SSH1)";
2546- case SSH_CIPHER_BLOWFISH:
2547- return "Blowfish(SSH1)";
2539+ const char *UILanguageFile = pvar->ts->UILanguageFile;
2540+ GetI18nStrW("TTSSH", key, UIMsg, MAX_UIMSG, def, UILanguageFile);
2541+}
25482542
2549- // for SSH2(yutaka)
2550- case SSH2_CIPHER_AES128_CBC:
2551- return "aes128-cbc(SSH2)";
2552- case SSH2_CIPHER_AES192_CBC:
2553- return "aes192-cbc(SSH2)";
2554- case SSH2_CIPHER_AES256_CBC:
2555- return "aes256-cbc(SSH2)";
2556- case SSH2_CIPHER_3DES_CBC:
2557- return "3des-cbc(SSH2)";
2558- case SSH2_CIPHER_BLOWFISH_CBC:
2559- return "blowfish-cbc(SSH2)";
2560- case SSH2_CIPHER_AES128_CTR:
2561- return "aes128-ctr(SSH2)";
2562- case SSH2_CIPHER_AES192_CTR:
2563- return "aes192-ctr(SSH2)";
2564- case SSH2_CIPHER_AES256_CTR:
2565- return "aes256-ctr(SSH2)";
2566- case SSH2_CIPHER_ARCFOUR:
2567- return "arcfour(SSH2)";
2568- case SSH2_CIPHER_ARCFOUR128:
2569- return "arcfour128(SSH2)";
2570- case SSH2_CIPHER_ARCFOUR256:
2571- return "arcfour256(SSH2)";
2572- case SSH2_CIPHER_CAST128_CBC:
2573- return "cast128-cbc(SSH2)";
2574- case SSH2_CIPHER_3DES_CTR:
2575- return "3des-ctr(SSH2)";
2576- case SSH2_CIPHER_BLOWFISH_CTR:
2577- return "blowfish-ctr(SSH2)";
2578- case SSH2_CIPHER_CAST128_CTR:
2579- return "cast128-ctr(SSH2)";
2580- case SSH2_CIPHER_CAMELLIA128_CBC:
2581- return "camellia128-cbc(SSH2)";
2582- case SSH2_CIPHER_CAMELLIA192_CBC:
2583- return "camellia192-cbc(SSH2)";
2584- case SSH2_CIPHER_CAMELLIA256_CBC:
2585- return "camellia256-cbc(SSH2)";
2586- case SSH2_CIPHER_CAMELLIA128_CTR:
2587- return "camellia128-ctr(SSH2)";
2588- case SSH2_CIPHER_CAMELLIA192_CTR:
2589- return "camellia192-ctr(SSH2)";
2590- case SSH2_CIPHER_CAMELLIA256_CTR:
2591- return "camellia256-ctr(SSH2)";
2592- case SSH2_CIPHER_AES128_GCM:
2593- return "aes128-gcm@openssh.com(SSH2)";
2594- case SSH2_CIPHER_AES256_GCM:
2595- return "aes256-gcm@openssh.com(SSH2)";
2543+static wchar_t *get_cipher_nameW(int cipher)
2544+{
2545+ typedef struct {
2546+ int no;
2547+ const char *nameA;
2548+ } list_t;
2549+ static const list_t list[] = {
2550+ { SSH_CIPHER_3DES, "3DES(SSH1)" },
2551+ { SSH_CIPHER_DES, "DES(SSH1)" },
2552+ { SSH_CIPHER_BLOWFISH, "Blowfish(SSH1)" },
2553+ { SSH2_CIPHER_AES128_CBC, "aes128-cbc(SSH2)" },
2554+ { SSH2_CIPHER_AES192_CBC, "aes192-cbc(SSH2)" },
2555+ { SSH2_CIPHER_AES256_CBC, "aes256-cbc(SSH2)" },
2556+ { SSH2_CIPHER_3DES_CBC, "3des-cbc(SSH2)" },
2557+ { SSH2_CIPHER_BLOWFISH_CBC, "blowfish-cbc(SSH2)" },
2558+ { SSH2_CIPHER_AES128_CTR, "aes128-ctr(SSH2)" },
2559+ { SSH2_CIPHER_AES192_CTR, "aes192-ctr(SSH2)" },
2560+ { SSH2_CIPHER_AES256_CTR, "aes256-ctr(SSH2)" },
2561+ { SSH2_CIPHER_ARCFOUR, "arcfour(SSH2)" },
2562+ { SSH2_CIPHER_ARCFOUR128, "arcfour128(SSH2)" },
2563+ { SSH2_CIPHER_ARCFOUR256, "arcfour256(SSH2)" },
2564+ { SSH2_CIPHER_CAST128_CBC, "cast128-cbc(SSH2)" },
2565+ { SSH2_CIPHER_3DES_CTR, "3des-ctr(SSH2)" },
2566+ { SSH2_CIPHER_BLOWFISH_CTR, "blowfish-ctr(SSH2)" },
2567+ { SSH2_CIPHER_CAST128_CTR, "cast128-ctr(SSH2)" },
2568+ { SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc(SSH2)" },
2569+ { SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc(SSH2)" },
2570+ { SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc(SSH2)" },
2571+ { SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr(SSH2)" },
2572+ { SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr(SSH2)" },
2573+ { SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr(SSH2)" },
2574+ { SSH2_CIPHER_AES128_GCM, "aes128-gcm@openssh.com(SSH2)" },
2575+ { SSH2_CIPHER_AES256_GCM, "aes256-gcm@openssh.com(SSH2)" },
2576+ };
2577+ int i;
2578+ const list_t *p = list;
25962579
2597- default:
2598- return NULL;
2580+ if (cipher == SSH_CIPHER_NONE) {
2581+ wchar_t uimsg[MAX_UIMSG];
2582+ UTIL_get_lang_msgW("DLG_SSHSETUP_CIPHER_BORDER", uimsg,
2583+ L"<ciphers below this line are disabled>");
2584+ return _wcsdup(uimsg);
25992585 }
2586+ for (i = 0; i < _countof(list); p++,i++) {
2587+ if (p->no == cipher) {
2588+ return ToWcharA(p->nameA);
2589+ }
2590+ }
2591+ return NULL;
26002592 }
26012593
26022594 static void set_move_button_status(HWND dlg, int type, int up, int down)
@@ -2623,10 +2615,10 @@
26232615 HWND hostkeyRotationControlList = GetDlgItem(dlg, IDC_HOSTKEY_ROTATION_COMBO);
26242616 int i;
26252617 int ch;
2626- static const char *rotationItem[SSH_UPDATE_HOSTKEYS_MAX] = {
2627- "No",
2628- "Yes",
2629- "Ask",
2618+ static const wchar_t *rotationItem[SSH_UPDATE_HOSTKEYS_MAX] = {
2619+ L"No",
2620+ L"Yes",
2621+ L"Ask",
26302622 };
26312623 static const char *rotationItemKey[SSH_UPDATE_HOSTKEYS_MAX] = {
26322624 "DLG_SSHSETUP_HOSTKEY_ROTATION_NO",
@@ -2633,6 +2625,7 @@
26332625 "DLG_SSHSETUP_HOSTKEY_ROTATION_YES",
26342626 "DLG_SSHSETUP_HOSTKEY_ROTATION_ASK",
26352627 };
2628+ wchar_t uimsg[MAX_UIMSG];
26362629
26372630 const static DlgTextInfo text_info[] = {
26382631 { 0, "DLG_SSHSETUP_TITLE" },
@@ -2691,10 +2684,11 @@
26912684
26922685 for (i = 0; pvar->settings.CipherOrder[i] != 0; i++) {
26932686 int cipher = pvar->settings.CipherOrder[i] - '0';
2694- char *name = get_cipher_name(cipher);
2695-
2687+ wchar_t *name = get_cipher_nameW(cipher);
26962688 if (name != NULL) {
2697- SendMessage(cipherControl, LB_ADDSTRING, 0, (LPARAM) name);
2689+ int index = _SendMessageW(cipherControl, LB_ADDSTRING, 0, (LPARAM) name);
2690+ _SendMessageW(cipherControl, LB_SETITEMDATA, index, cipher);
2691+ free(name);
26982692 }
26992693 }
27002694
@@ -2705,19 +2699,17 @@
27052699 normalize_kex_order(pvar->settings.KexOrder);
27062700 for (i = 0; pvar->settings.KexOrder[i] != 0; i++) {
27072701 int index = pvar->settings.KexOrder[i] - '0';
2708- char *name = NULL;
27092702
27102703 if (index == 0) {
2711- UTIL_get_lang_msg("DLG_SSHSETUP_KEX_BORDER", pvar,
2712- "<KEXs below this line are disabled>");
2713- name = pvar->ts->UIMsg;
2704+ UTIL_get_lang_msgW("DLG_SSHSETUP_KEX_BORDER", uimsg,
2705+ L"<KEXs below this line are disabled>");
2706+ _SendMessageW(kexControl, LB_ADDSTRING, 0, (LPARAM)uimsg);
27142707 } else {
2715- name = get_kex_algorithm_name(index);
2708+ const char *name = get_kex_algorithm_name(index);
2709+ if (name != NULL) {
2710+ SendMessageA(kexControl, LB_ADDSTRING, 0, (LPARAM) name);
2711+ }
27162712 }
2717-
2718- if (name != NULL) {
2719- SendMessage(kexControl, LB_ADDSTRING, 0, (LPARAM) name);
2720- }
27212713 }
27222714 SendMessage(kexControl, LB_SETCURSEL, 0, 0);
27232715 set_move_button_status(dlg, IDC_SSHKEX_LIST, IDC_SSHKEX_MOVEUP, IDC_SSHKEX_MOVEDOWN);
@@ -2726,19 +2718,17 @@
27262718 normalize_host_key_order(pvar->settings.HostKeyOrder);
27272719 for (i = 0; pvar->settings.HostKeyOrder[i] != 0; i++) {
27282720 int index = pvar->settings.HostKeyOrder[i] - '0';
2729- char *name = NULL;
27302721
27312722 if (index == 0) {
2732- UTIL_get_lang_msg("DLG_SSHSETUP_HOST_KEY_BORDER", pvar,
2733- "<Host Keys below this line are disabled>");
2734- name = pvar->ts->UIMsg;
2723+ UTIL_get_lang_msgW("DLG_SSHSETUP_HOST_KEY_BORDER", uimsg,
2724+ L"<Host Keys below this line are disabled>");
2725+ _SendMessageW(hostkeyControl, LB_ADDSTRING, 0, (LPARAM)uimsg);
27352726 } else {
2736- name = get_ssh_keytype_name(index);
2727+ const char *name = get_ssh_keytype_name(index);
2728+ if (name != NULL) {
2729+ SendMessageA(hostkeyControl, LB_ADDSTRING, 0, (LPARAM) name);
2730+ }
27372731 }
2738-
2739- if (name != NULL) {
2740- SendMessage(hostkeyControl, LB_ADDSTRING, 0, (LPARAM) name);
2741- }
27422732 }
27432733 SendMessage(hostkeyControl, LB_SETCURSEL, 0, 0);
27442734 set_move_button_status(dlg, IDC_SSHHOST_KEY_LIST, IDC_SSHHOST_KEY_MOVEUP, IDC_SSHHOST_KEY_MOVEDOWN);
@@ -2747,19 +2737,17 @@
27472737 normalize_mac_order(pvar->settings.MacOrder);
27482738 for (i = 0; pvar->settings.MacOrder[i] != 0; i++) {
27492739 int index = pvar->settings.MacOrder[i] - '0';
2750- const char *name = NULL;
27512740
27522741 if (index == 0) {
2753- UTIL_get_lang_msg("DLG_SSHSETUP_MAC_BORDER", pvar,
2754- "<MACs below this line are disabled>");
2755- name = pvar->ts->UIMsg;
2742+ UTIL_get_lang_msgW("DLG_SSHSETUP_MAC_BORDER", uimsg,
2743+ L"<MACs below this line are disabled>");
2744+ _SendMessageW(macControl, LB_ADDSTRING, 0, (LPARAM)uimsg);
27562745 } else {
2757- name = get_ssh2_mac_name_by_id(index);
2746+ const char *name = get_ssh2_mac_name_by_id(index);
2747+ if (name != NULL) {
2748+ SendMessageA(macControl, LB_ADDSTRING, 0, (LPARAM) name);
2749+ }
27582750 }
2759-
2760- if (name != NULL) {
2761- SendMessage(macControl, LB_ADDSTRING, 0, (LPARAM) name);
2762- }
27632751 }
27642752 SendMessage(macControl, LB_SETCURSEL, 0, 0);
27652753 set_move_button_status(dlg, IDC_SSHMAC_LIST, IDC_SSHMAC_MOVEUP, IDC_SSHMAC_MOVEDOWN);
@@ -2768,19 +2756,17 @@
27682756 normalize_comp_order(pvar->settings.CompOrder);
27692757 for (i = 0; pvar->settings.CompOrder[i] != 0; i++) {
27702758 int index = pvar->settings.CompOrder[i] - '0';
2771- char *name = NULL;
27722759
27732760 if (index == 0) {
2774- UTIL_get_lang_msg("DLG_SSHSETUP_COMP_BORDER", pvar,
2775- "<Compression methods below this line are disabled>");
2776- name = pvar->ts->UIMsg;
2761+ UTIL_get_lang_msgW("DLG_SSHSETUP_COMP_BORDER", uimsg,
2762+ L"<Compression methods below this line are disabled>");
2763+ _SendMessageW(compControl, LB_ADDSTRING, 0, (LPARAM)uimsg);
27772764 } else {
2778- name = get_ssh2_comp_name(index);
2765+ const char *name = get_ssh2_comp_name(index);
2766+ if (name != NULL) {
2767+ SendMessageA(compControl, LB_ADDSTRING, 0, (LPARAM) name);
2768+ }
27792769 }
2780-
2781- if (name != NULL) {
2782- SendMessage(compControl, LB_ADDSTRING, 0, (LPARAM) name);
2783- }
27842770 }
27852771 SendMessage(compControl, LB_SETCURSEL, 0, 0);
27862772 set_move_button_status(dlg, IDC_SSHCOMP_LIST, IDC_SSHCOMP_MOVEUP, IDC_SSHCOMP_MOVEDOWN);
@@ -2835,8 +2821,8 @@
28352821
28362822 // hostkey rotation(OpenSSH 6.8)
28372823 for (i = 0; i < SSH_UPDATE_HOSTKEYS_MAX; i++) {
2838- UTIL_get_lang_msg(rotationItemKey[i], pvar, rotationItem[i]);
2839- SendMessage(hostkeyRotationControlList, CB_INSERTSTRING, i, (LPARAM)pvar->ts->UIMsg);
2824+ UTIL_get_lang_msgW(rotationItemKey[i], uimsg, rotationItem[i]);
2825+ _SendMessageW(hostkeyRotationControlList, CB_INSERTSTRING, i, (LPARAM)uimsg);
28402826 }
28412827 ch = pvar->settings.UpdateHostkeys;
28422828 if (!(ch >= 0 && ch < SSH_UPDATE_HOSTKEYS_MAX))
@@ -2848,7 +2834,7 @@
28482834 char buf[10];
28492835 _snprintf_s(buf, sizeof(buf), _TRUNCATE,
28502836 "%d", pvar->settings.LogLevel);
2851- SetDlgItemText(dlg, IDC_LOGLEVEL_VALUE, buf);
2837+ SetDlgItemTextA(dlg, IDC_LOGLEVEL_VALUE, buf);
28522838 }
28532839
28542840
@@ -2936,22 +2922,9 @@
29362922 count = (int) SendMessage(cipherControl, LB_GETCOUNT, 0, 0);
29372923 buf2index = 0;
29382924 for (i = 0; i < count; i++) {
2939- int len = SendMessage(cipherControl, LB_GETTEXTLEN, i, 0);
2940-
2941- if (len > 0 && len < sizeof(buf)) { /* should always be true */
2942- buf[0] = 0;
2943- SendMessage(cipherControl, LB_GETTEXT, i, (LPARAM) buf);
2944- for (j = 0; j <= SSH_CIPHER_MAX; j++) {
2945- char *cipher_name = get_cipher_name(j);
2946- if (cipher_name != NULL && strcmp(buf, cipher_name) == 0) {
2947- break;
2948- }
2949- }
2950- if (j <= SSH_CIPHER_MAX) {
2951- buf2[buf2index] = '0' + j;
2952- buf2index++;
2953- }
2954- }
2925+ int chipher = _SendMessageW(cipherControl, LB_GETITEMDATA, i, 0);
2926+ buf2[buf2index] = '0' + chipher;
2927+ buf2index++;
29552928 }
29562929 buf2[buf2index] = 0;
29572930 normalize_cipher_order(buf2);
@@ -3125,22 +3098,23 @@
31253098
31263099 static void move_cur_sel_delta(HWND listbox, int delta)
31273100 {
3128- int curPos = (int) SendMessage(listbox, LB_GETCURSEL, 0, 0);
3129- int maxPos = (int) SendMessage(listbox, LB_GETCOUNT, 0, 0) - 1;
3101+ int curPos = (int) _SendMessageW(listbox, LB_GETCURSEL, 0, 0);
3102+ int maxPos = (int) _SendMessageW(listbox, LB_GETCOUNT, 0, 0) - 1;
31303103 int newPos = curPos + delta;
3131- char buf[1024];
31323104
31333105 if (curPos >= 0 && newPos >= 0 && newPos <= maxPos) {
3134- int len = SendMessage(listbox, LB_GETTEXTLEN, curPos, 0);
3135-
3136- if (len > 0 && len < sizeof(buf)) { /* should always be true */
3137- buf[0] = 0;
3138- SendMessage(listbox, LB_GETTEXT, curPos, (LPARAM) buf);
3139- SendMessage(listbox, LB_DELETESTRING, curPos, 0);
3140- SendMessage(listbox, LB_INSERTSTRING, newPos,
3141- (LPARAM) (char *) buf);
3142- SendMessage(listbox, LB_SETCURSEL, newPos, 0);
3143- }
3106+ int item_data;
3107+ int index;
3108+ size_t len = _SendMessageW(listbox, LB_GETTEXTLEN, curPos, 0);
3109+ wchar_t *buf = malloc(sizeof(wchar_t) * (len+1));
3110+ buf[0] = 0;
3111+ _SendMessageW(listbox, LB_GETTEXT, curPos, (LPARAM) buf);
3112+ item_data = (int)_SendMessageW(listbox, LB_GETITEMDATA, curPos, 0);
3113+ _SendMessageW(listbox, LB_DELETESTRING, curPos, 0);
3114+ index = (int)_SendMessageW(listbox, LB_INSERTSTRING, newPos, (LPARAM)buf);
3115+ _SendMessageW(listbox, LB_SETITEMDATA, index, item_data);
3116+ _SendMessageW(listbox, LB_SETCURSEL, newPos, 0);
3117+ free(buf);
31443118 }
31453119 }
31463120
@@ -5360,10 +5334,9 @@
53605334 case DLL_PROCESS_ATTACH:
53615335 /* do process initialization */
53625336 #ifdef _DEBUG
5363- //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
5364- // リーク時のブロック番号を元にブレークを仕掛けるには、以下のようにする。
5365- // cf. http://www.microsoft.com/japan/msdn/vs_previous/visualc/techmat/feature/MemLeaks/
5366- //_CrtSetBreakAlloc(3228);
5337+ _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
5338+ // リーク時のブロック番号を元にブレークを仕掛けるには、以下のようにする。
5339+ //_CrtSetBreakAlloc(3228);
53675340 #endif
53685341 DoCover_IsDebuggerPresent();
53695342 DisableThreadLibraryCalls(hInstance);
Show on old repository browser