Stray // comments.
[u/mdw/putty] / config.c
index 59140db..1dbdfac 100644 (file)
--- a/config.c
+++ b/config.c
@@ -252,6 +252,7 @@ struct sessionsaver_data {
     union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton;
     union control *okbutton, *cancelbutton;
     struct sesslist *sesslist;
+    int midsession;
 };
 
 /* 
@@ -298,8 +299,6 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
      * allocate space to store the current contents of the saved
      * session edit box (since it must persist even when we switch
      * panels, but is not part of the Config).
-     * 
-     * Of course, this doesn't need to be done mid-session.
      */
     if (!ssd->editbox) {
         savedsession = NULL;
@@ -328,7 +327,9 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
                            SAVEDSESSION_LEN);
        }
     } else if (event == EVENT_ACTION) {
-       if (ctrl == ssd->listbox || ctrl == ssd->loadbutton) {
+       if (!ssd->midsession &&
+           (ctrl == ssd->listbox ||
+            (ssd->loadbutton && ctrl == ssd->loadbutton))) {
            /*
             * The user has double-clicked a session, or hit Load.
             * We must load the selected session, and then
@@ -368,7 +369,8 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
            get_sesslist(ssd->sesslist, TRUE);
            dlg_refresh(ssd->editbox, dlg);
            dlg_refresh(ssd->listbox, dlg);
-       } else if (ctrl == ssd->delbutton) {
+       } else if (!ssd->midsession &&
+                  ssd->delbutton && ctrl == ssd->delbutton) {
            int i = dlg_listbox_index(ssd->listbox, dlg);
            if (i <= 0) {
                dlg_beep(dlg);
@@ -379,7 +381,7 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
                dlg_refresh(ssd->listbox, dlg);
            }
        } else if (ctrl == ssd->okbutton) {
-            if (!savedsession) {
+            if (ssd->midsession) {
                 /* In a mid-session Change Settings, Apply is always OK. */
                dlg_end(dlg, 1);
                 return;
@@ -770,7 +772,7 @@ static void portfwd_handler(union control *ctrl, void *dlg,
 }
 
 void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
-                     int midsession, int protocol)
+                     int midsession, int protocol, int protcfginfo)
 {
     struct controlset *s;
     struct sessionsaver_data *ssd;
@@ -784,7 +786,7 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
     ssd = (struct sessionsaver_data *)
        ctrl_alloc(b, sizeof(struct sessionsaver_data));
     memset(ssd, 0, sizeof(*ssd));
-    ssd->sesslist = (midsession ? NULL : sesslist);
+    ssd->midsession = midsession;
 
     /*
      * The standard panel that appears at the bottom of all panels:
@@ -845,38 +847,55 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
                              "SSH", 's', I(PROT_SSH),
                              NULL);
        }
+    }
 
-       s = ctrl_getset(b, "Session", "savedsessions",
-                       "Load, save or delete a stored session");
-       ctrl_columns(s, 2, 75, 25);
-       ssd->sesslist = sesslist;
-       ssd->editbox = ctrl_editbox(s, "Saved Sessions", 'e', 100,
-                                   HELPCTX(session_saved),
-                                   sessionsaver_handler, P(ssd), P(NULL));
-       ssd->editbox->generic.column = 0;
-       /* Reset columns so that the buttons are alongside the list, rather
-        * than alongside that edit box. */
-       ctrl_columns(s, 1, 100);
-       ctrl_columns(s, 2, 75, 25);
-       ssd->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT,
-                                   HELPCTX(session_saved),
-                                   sessionsaver_handler, P(ssd));
-       ssd->listbox->generic.column = 0;
-       ssd->listbox->listbox.height = 7;
+    /*
+     * The Load/Save panel is available even in mid-session.
+     */
+    s = ctrl_getset(b, "Session", "savedsessions",
+                   "Load, save or delete a stored session");
+    ctrl_columns(s, 2, 75, 25);
+    ssd->sesslist = sesslist;
+    ssd->editbox = ctrl_editbox(s, "Saved Sessions", 'e', 100,
+                               HELPCTX(session_saved),
+                               sessionsaver_handler, P(ssd), P(NULL));
+    ssd->editbox->generic.column = 0;
+    /* Reset columns so that the buttons are alongside the list, rather
+     * than alongside that edit box. */
+    ctrl_columns(s, 1, 100);
+    ctrl_columns(s, 2, 75, 25);
+    ssd->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT,
+                               HELPCTX(session_saved),
+                               sessionsaver_handler, P(ssd));
+    ssd->listbox->generic.column = 0;
+    ssd->listbox->listbox.height = 7;
+    if (!midsession) {
        ssd->loadbutton = ctrl_pushbutton(s, "Load", 'l',
                                          HELPCTX(session_saved),
                                          sessionsaver_handler, P(ssd));
        ssd->loadbutton->generic.column = 1;
-       ssd->savebutton = ctrl_pushbutton(s, "Save", 'v',
-                                         HELPCTX(session_saved),
-                                         sessionsaver_handler, P(ssd));
-       ssd->savebutton->generic.column = 1;
+    } else {
+       /* We can't offer the Load button mid-session, as it would allow the
+        * user to load and subsequently save settings they can't see. (And
+        * also change otherwise immutable settings underfoot; that probably
+        * shouldn't be a problem, but.) */
+       ssd->loadbutton = NULL;
+    }
+    /* "Save" button is permitted mid-session. */
+    ssd->savebutton = ctrl_pushbutton(s, "Save", 'v',
+                                     HELPCTX(session_saved),
+                                     sessionsaver_handler, P(ssd));
+    ssd->savebutton->generic.column = 1;
+    if (!midsession) {
        ssd->delbutton = ctrl_pushbutton(s, "Delete", 'd',
                                         HELPCTX(session_saved),
                                         sessionsaver_handler, P(ssd));
        ssd->delbutton->generic.column = 1;
-       ctrl_columns(s, 1, 100);
+    } else {
+       /* Disable the Delete button mid-session too, for UI consistency. */
+       ssd->delbutton = NULL;
     }
+    ctrl_columns(s, 1, 100);
 
     s = ctrl_getset(b, "Session", "otheropts", NULL);
     c = ctrl_radiobuttons(s, "Close window on exit:", 'w', 4,
@@ -1580,33 +1599,36 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
 
        /*
         * The Connection/SSH/Kex panel. (Owing to repeat key
-        * exchange, this is all meaningful in mid-session.)
+        * exchange, this is all meaningful in mid-session _if_
+        * we're using SSH2 or haven't decided yet.)
         */
-       ctrl_settitle(b, "Connection/SSH/Kex",
-                     "Options controlling SSH key exchange");
-
-       s = ctrl_getset(b, "Connection/SSH/Kex", "main",
-                       "Key exchange algorithm options");
-       c = ctrl_draglist(s, "Algorithm selection policy", 's',
-                         HELPCTX(ssh_kexlist),
-                         kexlist_handler, P(NULL));
-       c->listbox.height = 5;
-
-       s = ctrl_getset(b, "Connection/SSH/Kex", "repeat",
-                       "Options controlling key re-exchange");
-
-       ctrl_editbox(s, "Max minutes before rekey (0 for no limit)", 't', 20,
-                    HELPCTX(ssh_kex_repeat),
-                    dlg_stdeditbox_handler,
-                    I(offsetof(Config,ssh_rekey_time)),
-                    I(-1));
-       ctrl_editbox(s, "Max data before rekey (0 for no limit)", 'd', 20,
-                    HELPCTX(ssh_kex_repeat),
-                    dlg_stdeditbox_handler,
-                    I(offsetof(Config,ssh_rekey_data)),
-                    I(16));
-       ctrl_text(s, "(Use 1M for 1 megabyte, 1G for 1 gigabyte etc)",
-                 HELPCTX(ssh_kex_repeat));
+       if (protcfginfo != 1) {
+           ctrl_settitle(b, "Connection/SSH/Kex",
+                         "Options controlling SSH key exchange");
+
+           s = ctrl_getset(b, "Connection/SSH/Kex", "main",
+                           "Key exchange algorithm options");
+           c = ctrl_draglist(s, "Algorithm selection policy", 's',
+                             HELPCTX(ssh_kexlist),
+                             kexlist_handler, P(NULL));
+           c->listbox.height = 5;
+
+           s = ctrl_getset(b, "Connection/SSH/Kex", "repeat",
+                           "Options controlling key re-exchange");
+
+           ctrl_editbox(s, "Max minutes before rekey (0 for no limit)", 't', 20,
+                        HELPCTX(ssh_kex_repeat),
+                        dlg_stdeditbox_handler,
+                        I(offsetof(Config,ssh_rekey_time)),
+                        I(-1));
+           ctrl_editbox(s, "Max data before rekey (0 for no limit)", 'x', 20,
+                        HELPCTX(ssh_kex_repeat),
+                        dlg_stdeditbox_handler,
+                        I(offsetof(Config,ssh_rekey_data)),
+                        I(16));
+           ctrl_text(s, "(Use 1M for 1 megabyte, 1G for 1 gigabyte etc)",
+                     HELPCTX(ssh_kex_repeat));
+       }
 
        if (!midsession) {