1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-14 17:47:33 -05:00

New abstraction 'Seat', to pass to backends.

This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)

The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.

For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)

I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
This commit is contained in:
Simon Tatham
2018-10-11 19:58:42 +01:00
parent 109df9f46b
commit b4c8fd9d86
42 changed files with 1046 additions and 719 deletions

View File

@ -71,7 +71,7 @@ static int pty_signal_pipe[2] = { -1, -1 }; /* obviously bogus initial val */
struct Pty {
Conf *conf;
int master_fd, slave_fd;
Frontend *frontend;
Seat *seat;
char name[FILENAME_MAX];
pid_t child_pid;
int term_width, term_height;
@ -633,7 +633,7 @@ void pty_real_select_result(Pty *pty, int event, int status)
perror("read pty master");
exit(1);
} else if (ret > 0) {
from_backend(pty->frontend, 0, buf, ret);
seat_stdout(pty->seat, buf, ret);
}
} else if (event == 2) {
/*
@ -675,10 +675,10 @@ void pty_real_select_result(Pty *pty, int event, int status)
" %d (%.400s)]\r\n", WTERMSIG(pty->exit_code),
strsignal(WTERMSIG(pty->exit_code)));
#endif
from_backend(pty->frontend, 0, message, strlen(message));
seat_stdout(pty->seat, message, strlen(message));
}
notify_remote_exit(pty->frontend);
seat_notify_remote_exit(pty->seat);
}
}
@ -736,7 +736,7 @@ static void pty_uxsel_setup(Pty *pty)
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static const char *pty_init(Frontend *frontend, Backend **backend_handle,
static const char *pty_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port,
char **realhost, int nodelay, int keepalive)
@ -760,7 +760,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle,
#endif
}
pty->frontend = frontend;
pty->seat = seat;
pty->backend.vt = &pty_backend;
*backend_handle = &pty->backend;
@ -781,7 +781,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle,
close(pty_utmp_helper_pipe); /* just let the child process die */
pty_utmp_helper_pipe = -1;
} else {
const char *location = get_x_display(pty->frontend);
const char *location = seat_get_x_display(pty->seat);
int len = strlen(location)+1, pos = 0; /* +1 to include NUL */
while (pos < len) {
int ret = write(pty_utmp_helper_pipe, location+pos, len - pos);
@ -798,7 +798,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle,
#endif
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
got_windowid = get_windowid(pty->frontend, &windowid);
got_windowid = seat_get_windowid(pty->seat, &windowid);
#endif
/*
@ -888,7 +888,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle,
* Set the IUTF8 bit iff the character set is UTF-8.
*/
#ifdef IUTF8
if (frontend_is_utf8(frontend))
if (seat_is_utf8(seat))
attrs.c_iflag |= IUTF8;
else
attrs.c_iflag &= ~IUTF8;
@ -928,7 +928,7 @@ static const char *pty_init(Frontend *frontend, Backend **backend_handle,
* terminal to match the display the terminal itself is
* on.
*/
const char *x_display = get_x_display(pty->frontend);
const char *x_display = seat_get_x_display(pty->seat);
char *x_display_env_var = dupprintf("DISPLAY=%s", x_display);
putenv(x_display_env_var);
/* As above, we don't free this. */
@ -1150,16 +1150,17 @@ static void pty_size(Backend *be, int width, int height)
{
Pty *pty = container_of(be, Pty, backend);
struct winsize size;
int xpixel = 0, ypixel = 0;
pty->term_width = width;
pty->term_height = height;
seat_get_char_cell_size(pty->seat, &xpixel, &ypixel);
size.ws_row = (unsigned short)pty->term_height;
size.ws_col = (unsigned short)pty->term_width;
size.ws_xpixel = (unsigned short) pty->term_width *
font_dimension(pty->frontend, 0);
size.ws_ypixel = (unsigned short) pty->term_height *
font_dimension(pty->frontend, 1);
size.ws_xpixel = (unsigned short)pty->term_width * xpixel;
size.ws_ypixel = (unsigned short)pty->term_height * ypixel;
ioctl(pty->master_fd, TIOCSWINSZ, (void *)&size);
return;
}