Enable better build-time flexibility over which WinSock to include
[u/mdw/putty] / windlg.c
index 23bf2cb..77db051 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -1,7 +1,13 @@
 #include <windows.h>
 #include <commctrl.h>
 #include <commdlg.h>
+#ifndef AUTO_WINSOCK
+#ifdef WINSOCK_TWO
+#include <winsock2.h>
+#else
 #include <winsock.h>
+#endif
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -149,9 +155,13 @@ static void save_settings (char *section, int do_host) {
     }
     wpps (sesskey, "UserName", cfg.username);
     wppi (sesskey, "NoPTY", cfg.nopty);
+    wppi (sesskey, "AgentFwd", cfg.agentfwd);
+    wpps (sesskey, "RemoteCmd", cfg.remote_cmd);
     wpps (sesskey, "Cipher", cfg.cipher == CIPHER_BLOWFISH ? "blowfish" :
                              cfg.cipher == CIPHER_DES ? "des" : "3des");
     wppi (sesskey, "AuthTIS", cfg.try_tis_auth);
+    wppi (sesskey, "SshProt", cfg.sshprot);
+    wpps (sesskey, "PublicKeyFile", cfg.keyfile);
     wppi (sesskey, "RFCEnviron", cfg.rfc_environ);
     wppi (sesskey, "BackspaceIsDelete", cfg.bksp_is_delete);
     wppi (sesskey, "RXVTHomeEnd", cfg.rxvt_homeend);
@@ -282,6 +292,8 @@ static void load_settings (char *section, int do_host) {
     }
     gpps (sesskey, "UserName", "", cfg.username, sizeof(cfg.username));
     gppi (sesskey, "NoPTY", 0, &cfg.nopty);
+    gppi (sesskey, "AgentFwd", 0, &cfg.agentfwd);
+    gpps (sesskey, "RemoteCmd", "", cfg.remote_cmd, sizeof(cfg.remote_cmd));
     {
        char cipher[10];
        gpps (sesskey, "Cipher", "3des", cipher, 10);
@@ -292,7 +304,9 @@ static void load_settings (char *section, int do_host) {
        else
            cfg.cipher = CIPHER_3DES;
     }
+    gppi (sesskey, "SshProt", 1, &cfg.sshprot);
     gppi (sesskey, "AuthTIS", 0, &cfg.try_tis_auth);
+    gpps (sesskey, "PublicKeyFile", "", cfg.keyfile, sizeof(cfg.keyfile));
     gppi (sesskey, "RFCEnviron", 0, &cfg.rfc_environ);
     gppi (sesskey, "BackspaceIsDelete", 1, &cfg.bksp_is_delete);
     gppi (sesskey, "RXVTHomeEnd", 0, &cfg.rxvt_homeend);
@@ -470,6 +484,7 @@ static int CALLBACK AboutProc (HWND hwnd, UINT msg,
            DialogBox (hinst, MAKEINTRESOURCE(IDD_LICENCEBOX),
                       NULL, LicenceProc);
            EnableWindow(hwnd, 1);
+            SetActiveWindow(hwnd);
            return 0;
        }
        return 0;
@@ -500,6 +515,8 @@ static int GeneralPanelProc (HWND hwnd, UINT msg,
     return 0;
 }
 
+static char savedsession[2048];
+
 static int CALLBACK ConnectionProc (HWND hwnd, UINT msg,
                                    WPARAM wParam, LPARAM lParam) {
     int i;
@@ -507,6 +524,7 @@ static int CALLBACK ConnectionProc (HWND hwnd, UINT msg,
     switch (msg) {
       case WM_INITDIALOG:
        SetDlgItemText (hwnd, IDC0_HOST, cfg.host);
+       SetDlgItemText (hwnd, IDC0_SESSEDIT, savedsession);
        SetDlgItemInt (hwnd, IDC0_PORT, cfg.port, FALSE);
        for (i = 0; i < nsessions; i++)
            SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_ADDSTRING,
@@ -563,9 +581,13 @@ static int CALLBACK ConnectionProc (HWND hwnd, UINT msg,
                cfg.warn_on_close = IsDlgButtonChecked (hwnd, IDC0_CLOSEWARN);
            break;
          case IDC0_SESSEDIT:
-           if (HIWORD(wParam) == EN_CHANGE)
+           if (HIWORD(wParam) == EN_CHANGE) {
                SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,
                                    (WPARAM) -1, 0);
+                GetDlgItemText (hwnd, IDC0_SESSEDIT,
+                                savedsession, sizeof(savedsession)-1);
+                savedsession[sizeof(savedsession)-1] = '\0';
+            }
            break;
          case IDC0_SESSSAVE:
            if (HIWORD(wParam) == BN_CLICKED ||
@@ -995,17 +1017,23 @@ static int CALLBACK TelnetProc (HWND hwnd, UINT msg,
 
 static int CALLBACK SshProc (HWND hwnd, UINT msg,
                             WPARAM wParam, LPARAM lParam) {
+    OPENFILENAME of;
+    char filename[sizeof(cfg.keyfile)];
+
     switch (msg) {
       case WM_INITDIALOG:
        SetDlgItemText (hwnd, IDC3_TTEDIT, cfg.termtype);
        SetDlgItemText (hwnd, IDC3_LOGEDIT, cfg.username);
        CheckDlgButton (hwnd, IDC3_NOPTY, cfg.nopty);
+       CheckDlgButton (hwnd, IDC3_AGENTFWD, cfg.agentfwd);
        CheckRadioButton (hwnd, IDC3_CIPHER3DES, IDC3_CIPHERDES,
                          cfg.cipher == CIPHER_BLOWFISH ? IDC3_CIPHERBLOWF :
                          cfg.cipher == CIPHER_DES ? IDC3_CIPHERDES :
-
                          IDC3_CIPHER3DES);
+       CheckRadioButton (hwnd, IDC3_SSHPROT1, IDC3_SSHPROT2,
+                         cfg.sshprot == 1 ? IDC3_SSHPROT1 : IDC3_SSHPROT2);
        CheckDlgButton (hwnd, IDC3_AUTHTIS, cfg.try_tis_auth);
+       SetDlgItemText (hwnd, IDC3_PKEDIT, cfg.keyfile);
        break;
       case WM_COMMAND:
        switch (LOWORD(wParam)) {
@@ -1024,6 +1052,11 @@ static int CALLBACK SshProc (HWND hwnd, UINT msg,
                HIWORD(wParam) == BN_DOUBLECLICKED)
                cfg.nopty = IsDlgButtonChecked (hwnd, IDC3_NOPTY);
            break;
+         case IDC3_AGENTFWD:
+           if (HIWORD(wParam) == BN_CLICKED ||
+               HIWORD(wParam) == BN_DOUBLECLICKED)
+               cfg.agentfwd = IsDlgButtonChecked (hwnd, IDC3_AGENTFWD);
+           break;
          case IDC3_CIPHER3DES:
          case IDC3_CIPHERBLOWF:
          case IDC3_CIPHERDES:
@@ -1037,11 +1070,51 @@ static int CALLBACK SshProc (HWND hwnd, UINT msg,
                    cfg.cipher = CIPHER_DES;
            }
            break;
+         case IDC3_SSHPROT1:
+         case IDC3_SSHPROT2:
+           if (HIWORD(wParam) == BN_CLICKED ||
+               HIWORD(wParam) == BN_DOUBLECLICKED) {
+               if (IsDlgButtonChecked (hwnd, IDC3_SSHPROT1))
+                   cfg.sshprot = 1;
+               else if (IsDlgButtonChecked (hwnd, IDC3_SSHPROT2))
+                   cfg.sshprot = 2;
+           }
+           break;
          case IDC3_AUTHTIS:
            if (HIWORD(wParam) == BN_CLICKED ||
                HIWORD(wParam) == BN_DOUBLECLICKED)
                cfg.try_tis_auth = IsDlgButtonChecked (hwnd, IDC3_AUTHTIS);
            break;
+         case IDC3_PKEDIT:
+           if (HIWORD(wParam) == EN_CHANGE)
+               GetDlgItemText (hwnd, IDC3_PKEDIT, cfg.keyfile,
+                               sizeof(cfg.keyfile)-1);
+           break;
+         case IDC3_PKBUTTON:
+            /*
+             * FIXME: this crashes. Find out why.
+             */
+            memset(&of, 0, sizeof(of));
+#ifdef OPENFILENAME_SIZE_VERSION_400
+            of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+#else
+            of.lStructSize = sizeof(of);
+#endif
+            of.hwndOwner = hwnd;
+            of.lpstrFilter = "All Files\0*\0\0\0";
+            of.lpstrCustomFilter = NULL;
+            of.nFilterIndex = 1;
+            of.lpstrFile = filename; strcpy(filename, cfg.keyfile);
+            of.nMaxFile = sizeof(filename);
+            of.lpstrFileTitle = NULL;
+            of.lpstrInitialDir = NULL;
+            of.lpstrTitle = "Select Public Key File";
+            of.Flags = 0;
+            if (GetOpenFileName(&of)) {
+                strcpy(cfg.keyfile, filename);
+                SetDlgItemText (hwnd, IDC3_PKEDIT, cfg.keyfile);
+            }
+           break;
        }
        break;
     }
@@ -1401,6 +1474,7 @@ static int CALLBACK MainDlgProc (HWND hwnd, UINT msg,
        DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),
                  GetParent(hwnd), AboutProc);
        EnableWindow(hwnd, 1);
+        SetActiveWindow(hwnd);
     }
     return GenericMainDlgProc (hwnd, msg, wParam, lParam,
                               MAIN_NPANELS, mainp, &page);
@@ -1469,6 +1543,7 @@ int do_config (void) {
     int ret;
 
     get_sesslist(TRUE);
+    savedsession[0] = '\0';
     ret = DialogBox (hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, MainDlgProc);
     get_sesslist(FALSE);