1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Rework special-commands system to add an integer argument.

In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.

So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.

While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
This commit is contained in:
Simon Tatham
2018-09-24 09:35:52 +01:00
parent 26f7a2ac72
commit f4fbaa1bd9
19 changed files with 224 additions and 194 deletions

View File

@ -132,7 +132,7 @@ static struct unicode_data ucsdata;
static int session_closed;
static int reconfiguring = FALSE;
static const struct telnet_special *specials = NULL;
static const SessionSpecial *specials = NULL;
static HMENU specials_menu = NULL;
static int n_specials = 0;
@ -965,10 +965,10 @@ void update_specials_menu(Frontend *frontend)
for (i = 0; nesting > 0; i++) {
assert(IDM_SPECIAL_MIN + 0x10 * i < IDM_SPECIAL_MAX);
switch (specials[i].code) {
case TS_SEP:
case SS_SEP:
AppendMenu(new_menu, MF_SEPARATOR, 0, 0);
break;
case TS_SUBMENU:
case SS_SUBMENU:
assert(nesting < 2);
nesting++;
saved_menu = new_menu; /* XXX lame stacking */
@ -976,7 +976,7 @@ void update_specials_menu(Frontend *frontend)
AppendMenu(saved_menu, MF_POPUP | MF_ENABLED,
(UINT_PTR) new_menu, specials[i].name);
break;
case TS_EXITMENU:
case SS_EXITMENU:
nesting--;
if (nesting) {
new_menu = saved_menu; /* XXX lame stacking */
@ -2415,7 +2415,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
if (i >= n_specials)
break;
if (backend)
backend_special(backend, specials[i].code);
backend_special(
backend, specials[i].code, specials[i].arg);
}
}
break;
@ -4406,7 +4407,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
}
if (wParam == VK_CANCEL && shift_state == 2) { /* Ctrl-Break */
if (backend)
backend_special(backend, TS_BRK);
backend_special(backend, SS_BRK, 0);
return 0;
}
if (wParam == VK_PAUSE) { /* Break/Pause */

View File

@ -247,7 +247,7 @@ int stdin_gotdata(struct handle *h, void *data, int len)
if (len > 0) {
return backend_send(backend, data, len);
} else {
backend_special(backend, TS_EOF);
backend_special(backend, SS_EOF, 0);
return 0;
}
} else

View File

@ -348,11 +348,11 @@ static void serbreak_timer(void *ctx, unsigned long now)
/*
* Send serial special codes.
*/
static void serial_special(Backend *be, Telnet_Special code)
static void serial_special(Backend *be, SessionSpecialCode code, int arg)
{
Serial serial = FROMFIELD(be, struct serial_backend_data, backend);
if (serial->port && code == TS_BRK) {
if (serial->port && code == SS_BRK) {
logevent(serial->frontend, "Starting serial break at user request");
SetCommBreak(serial->port);
/*
@ -377,11 +377,11 @@ static void serial_special(Backend *be, Telnet_Special code)
* Return a list of the special codes that make sense in this
* protocol.
*/
static const struct telnet_special *serial_get_specials(Backend *be)
static const SessionSpecial *serial_get_specials(Backend *be)
{
static const struct telnet_special specials[] = {
{"Break", TS_BRK},
{NULL, TS_EXITMENU}
static const SessionSpecial specials[] = {
{"Break", SS_BRK},
{NULL, SS_EXITMENU}
};
return specials;
}