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:
@ -33,6 +33,7 @@
|
||||
#define g_signal_handler_disconnect gtk_signal_disconnect
|
||||
#define g_object_get_data gtk_object_get_data
|
||||
#define g_object_set_data gtk_object_set_data
|
||||
#define g_object_set_data_full gtk_object_set_data_full
|
||||
#define g_object_ref_sink gtk_object_sink
|
||||
|
||||
#define GDK_GRAB_SUCCESS GrabSuccess
|
||||
|
@ -1573,10 +1573,10 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
if (event->keyval == GDK_KEY_Break &&
|
||||
(event->state & GDK_CONTROL_MASK)) {
|
||||
#ifdef KEY_EVENT_DIAGNOSTICS
|
||||
debug((" - Ctrl-Break special case, sending TS_BRK\n"));
|
||||
debug((" - Ctrl-Break special case, sending SS_BRK\n"));
|
||||
#endif
|
||||
if (inst->backend)
|
||||
backend_special(inst->backend, TS_BRK);
|
||||
backend_special(inst->backend, SS_BRK, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4414,11 +4414,10 @@ void copy_all_menuitem(GtkMenuItem *item, gpointer data)
|
||||
void special_menuitem(GtkMenuItem *item, gpointer data)
|
||||
{
|
||||
Frontend *inst = (Frontend *)data;
|
||||
int code = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item),
|
||||
"user-data"));
|
||||
SessionSpecial *sc = g_object_get_data(G_OBJECT(item), "user-data");
|
||||
|
||||
if (inst->backend)
|
||||
backend_special(inst->backend, code);
|
||||
backend_special(inst->backend, sc->code, sc->arg);
|
||||
}
|
||||
|
||||
void about_menuitem(GtkMenuItem *item, gpointer data)
|
||||
@ -4915,9 +4914,11 @@ void set_window_icon(GtkWidget *window, const char *const *const *icon,
|
||||
#endif
|
||||
}
|
||||
|
||||
static void free_special_cmd(gpointer data) { sfree(data); }
|
||||
|
||||
void update_specials_menu(Frontend *inst)
|
||||
{
|
||||
const struct telnet_special *specials;
|
||||
const SessionSpecial *specials;
|
||||
|
||||
if (inst->backend)
|
||||
specials = backend_get_specials(inst->backend);
|
||||
@ -4936,7 +4937,7 @@ void update_specials_menu(Frontend *inst)
|
||||
for (i = 0; nesting > 0; i++) {
|
||||
GtkWidget *menuitem = NULL;
|
||||
switch (specials[i].code) {
|
||||
case TS_SUBMENU:
|
||||
case SS_SUBMENU:
|
||||
assert (nesting < 2);
|
||||
saved_menu = menu; /* XXX lame stacking */
|
||||
menu = gtk_menu_new();
|
||||
@ -4947,20 +4948,24 @@ void update_specials_menu(Frontend *inst)
|
||||
menuitem = NULL;
|
||||
nesting++;
|
||||
break;
|
||||
case TS_EXITMENU:
|
||||
case SS_EXITMENU:
|
||||
nesting--;
|
||||
if (nesting) {
|
||||
menu = saved_menu; /* XXX lame stacking */
|
||||
saved_menu = NULL;
|
||||
}
|
||||
break;
|
||||
case TS_SEP:
|
||||
case SS_SEP:
|
||||
menuitem = gtk_menu_item_new();
|
||||
break;
|
||||
default:
|
||||
menuitem = gtk_menu_item_new_with_label(specials[i].name);
|
||||
g_object_set_data(G_OBJECT(menuitem), "user-data",
|
||||
GINT_TO_POINTER(specials[i].code));
|
||||
{
|
||||
SessionSpecial *sc = snew(SessionSpecial);
|
||||
*sc = specials[i]; /* structure copy */
|
||||
g_object_set_data_full(G_OBJECT(menuitem), "user-data",
|
||||
sc, free_special_cmd);
|
||||
}
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(special_menuitem), inst);
|
||||
break;
|
||||
|
@ -464,7 +464,7 @@ static void from_tty(void *vbuf, unsigned len)
|
||||
break;
|
||||
case FF00:
|
||||
if (*p == '\0') {
|
||||
backend_special(backend, TS_BRK);
|
||||
backend_special(backend, SS_BRK, 0);
|
||||
} else {
|
||||
/*
|
||||
* Pretend that PARMRK wasn't set. This involves
|
||||
@ -991,7 +991,7 @@ int main(int argc, char **argv)
|
||||
perror("stdin: read");
|
||||
exit(1);
|
||||
} else if (ret == 0) {
|
||||
backend_special(backend, TS_EOF);
|
||||
backend_special(backend, SS_EOF, 0);
|
||||
sending = FALSE; /* send nothing further after this */
|
||||
} else {
|
||||
if (local_tty)
|
||||
|
@ -1159,7 +1159,7 @@ static void pty_size(Backend *be, int width, int height)
|
||||
/*
|
||||
* Send special codes.
|
||||
*/
|
||||
static void pty_special(Backend *be, Telnet_Special code)
|
||||
static void pty_special(Backend *be, SessionSpecialCode code, int arg)
|
||||
{
|
||||
/* Pty pty = FROMFIELD(be, struct pty_tag, backend); */
|
||||
/* Do nothing! */
|
||||
@ -1170,7 +1170,7 @@ static void pty_special(Backend *be, Telnet_Special code)
|
||||
* Return a list of the special codes that make sense in this
|
||||
* protocol.
|
||||
*/
|
||||
static const struct telnet_special *pty_get_specials(Backend *be)
|
||||
static const SessionSpecial *pty_get_specials(Backend *be)
|
||||
{
|
||||
/* Pty pty = FROMFIELD(be, struct pty_tag, backend); */
|
||||
/*
|
||||
|
12
unix/uxser.c
12
unix/uxser.c
@ -496,11 +496,11 @@ static void serial_size(Backend *be, int width, int height)
|
||||
/*
|
||||
* 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->fd >= 0 && code == TS_BRK) {
|
||||
if (serial->fd >= 0 && code == SS_BRK) {
|
||||
tcsendbreak(serial->fd, 0);
|
||||
logevent(serial->frontend, "Sending serial break at user request");
|
||||
}
|
||||
@ -512,11 +512,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 struct SessionSpecial specials[] = {
|
||||
{"Break", SS_BRK},
|
||||
{NULL, SS_EXITMENU}
|
||||
};
|
||||
return specials;
|
||||
}
|
||||
|
Reference in New Issue
Block a user