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

44
misc.c
View File

@ -216,12 +216,24 @@ char *host_strduptrim(const char *s)
return dupstr(s);
}
prompts_t *new_prompts(Frontend *frontend)
void seat_connection_fatal(Seat *seat, const char *fmt, ...)
{
va_list ap;
char *msg;
va_start(ap, fmt);
msg = dupvprintf(fmt, ap);
va_end(ap);
seat->vt->connection_fatal(seat, msg);
sfree(msg); /* if we return */
}
prompts_t *new_prompts(void)
{
prompts_t *p = snew(prompts_t);
p->prompts = NULL;
p->n_prompts = 0;
p->frontend = frontend;
p->data = NULL;
p->to_server = TRUE; /* to be on the safe side */
p->name = p->instruction = NULL;
@ -1348,3 +1360,31 @@ char *buildinfo(const char *newline)
return strbuf_to_str(buf);
}
int nullseat_output(
Seat *seat, int is_stderr, const void *data, int len) { return 0; }
int nullseat_eof(Seat *seat) { return TRUE; }
int nullseat_get_userpass_input(
Seat *seat, prompts_t *p, bufchain *input) { return 0; }
void nullseat_notify_remote_exit(Seat *seat) {}
void nullseat_connection_fatal(Seat *seat, const char *message) {}
void nullseat_update_specials_menu(Seat *seat) {}
char *nullseat_get_ttymode(Seat *seat, const char *mode) { return NULL; }
void nullseat_set_busy_status(Seat *seat, BusyStatus status) {}
int nullseat_verify_ssh_host_key(
Seat *seat, const char *host, int port,
const char *keytype, char *keystr, char *key_fingerprint,
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
int nullseat_confirm_weak_crypto_primitive(
Seat *seat, const char *algtype, const char *algname,
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
int nullseat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
int nullseat_is_never_utf8(Seat *seat) { return FALSE; }
int nullseat_is_always_utf8(Seat *seat) { return TRUE; }
void nullseat_echoedit_update(Seat *seat, int echoing, int editing) {}
const char *nullseat_get_x_display(Seat *seat) { return NULL; }
int nullseat_get_windowid(Seat *seat, long *id_out) { return FALSE; }
int nullseat_get_char_cell_size(
Seat *seat, int *width, int *height) { return FALSE; }