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

Introduce a new 'Interactor' trait.

This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.

To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.

I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.

The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
This commit is contained in:
Simon Tatham
2021-10-30 17:16:08 +01:00
parent 74a0be9c56
commit 44db74ec51
8 changed files with 110 additions and 115 deletions

View File

@ -25,6 +25,7 @@ struct Raw {
Plug plug;
Backend backend;
Interactor interactor;
};
static void raw_size(Backend *be, int width, int height);
@ -116,24 +117,21 @@ static void raw_sent(Plug *plug, size_t bufsize)
seat_sent(raw->seat, raw->bufsize);
}
static char *raw_plug_description(Plug *plug)
{
Raw *raw = container_of(plug, Raw, plug);
return dupstr(raw->description);
}
static char *raw_backend_description(Backend *backend)
{
Raw *raw = container_of(backend, Raw, backend);
return dupstr(raw->description);
}
static const PlugVtable Raw_plugvt = {
.log = raw_log,
.closing = raw_closing,
.receive = raw_receive,
.sent = raw_sent,
.description = raw_plug_description,
};
static char *raw_description(Interactor *itr)
{
Raw *raw = container_of(itr, Raw, interactor);
return dupstr(raw->description);
}
static const InteractorVtable Raw_interactorvt = {
.description = raw_description,
};
/*
@ -159,6 +157,8 @@ static char *raw_init(const BackendVtable *vt, Seat *seat,
memset(raw, 0, sizeof(Raw));
raw->plug.vt = &Raw_plugvt;
raw->backend.vt = vt;
raw->interactor.vt = &Raw_interactorvt;
raw->backend.interactor = &raw->interactor;
raw->s = NULL;
raw->closed_on_socket_error = false;
*backend_handle = &raw->backend;
@ -354,7 +354,6 @@ const BackendVtable raw_backend = {
.provide_ldisc = raw_provide_ldisc,
.unthrottle = raw_unthrottle,
.cfg_info = raw_cfg_info,
.description = raw_backend_description,
.id = "raw",
.displayname_tc = "Raw",
.displayname_lc = "raw",

View File

@ -32,6 +32,7 @@ struct Rlogin {
Plug plug;
Backend backend;
Interactor interactor;
};
static void rlogin_startup(Rlogin *rlogin, int prompt_result,
@ -193,24 +194,21 @@ static void rlogin_startup(Rlogin *rlogin, int prompt_result,
ldisc_check_sendok(rlogin->ldisc);
}
static char *rlogin_plug_description(Plug *plug)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
return dupstr(rlogin->description);
}
static char *rlogin_backend_description(Backend *backend)
{
Rlogin *rlogin = container_of(backend, Rlogin, backend);
return dupstr(rlogin->description);
}
static const PlugVtable Rlogin_plugvt = {
.log = rlogin_log,
.closing = rlogin_closing,
.receive = rlogin_receive,
.sent = rlogin_sent,
.description = rlogin_plug_description,
};
static char *rlogin_description(Interactor *itr)
{
Rlogin *rlogin = container_of(itr, Rlogin, interactor);
return dupstr(rlogin->description);
}
static const InteractorVtable Rlogin_interactorvt = {
.description = rlogin_description,
};
/*
@ -236,6 +234,8 @@ static char *rlogin_init(const BackendVtable *vt, Seat *seat,
memset(rlogin, 0, sizeof(Rlogin));
rlogin->plug.vt = &Rlogin_plugvt;
rlogin->backend.vt = vt;
rlogin->interactor.vt = &Rlogin_interactorvt;
rlogin->backend.interactor = &rlogin->interactor;
rlogin->s = NULL;
rlogin->closed_on_socket_error = false;
rlogin->seat = seat;
@ -461,7 +461,6 @@ const BackendVtable rlogin_backend = {
.provide_ldisc = rlogin_provide_ldisc,
.unthrottle = rlogin_unthrottle,
.cfg_info = rlogin_cfg_info,
.description = rlogin_backend_description,
.id = "rlogin",
.displayname_tc = "Rlogin",
.displayname_lc = "Rlogin", /* proper name, so capitalise it anyway */

View File

@ -107,6 +107,7 @@ struct supdup_tag
Plug plug;
Backend backend;
Interactor interactor;
};
#define SUPDUP_MAX_BACKLOG 4096
@ -642,17 +643,15 @@ static void supdup_send_config(Supdup *supdup)
supdup_send_36bits(supdup, TTYROL); // scroll amount
}
static char *supdup_plug_description(Plug *plug)
static char *supdup_description(Interactor *itr)
{
Supdup *supdup = container_of(plug, Supdup, plug);
Supdup *supdup = container_of(itr, Supdup, interactor);
return dupstr(supdup->description);
}
static char *supdup_backend_description(Backend *backend)
{
Supdup *supdup = container_of(backend, Supdup, backend);
return dupstr(supdup->description);
}
static const InteractorVtable Supdup_interactorvt = {
.description = supdup_description,
};
/*
* Called to set up the Supdup connection.
@ -673,7 +672,6 @@ static char *supdup_init(const BackendVtable *x, Seat *seat,
.closing = supdup_closing,
.receive = supdup_receive,
.sent = supdup_sent,
.description = supdup_plug_description,
};
SockAddr *addr;
const char *err;
@ -686,6 +684,8 @@ static char *supdup_init(const BackendVtable *x, Seat *seat,
memset(supdup, 0, sizeof(Supdup));
supdup->plug.vt = &fn_table;
supdup->backend.vt = &supdup_backend;
supdup->interactor.vt = &Supdup_interactorvt;
supdup->backend.interactor = &supdup->interactor;
supdup->logctx = logctx;
supdup->conf = conf_copy(conf);
supdup->s = NULL;
@ -952,7 +952,6 @@ const BackendVtable supdup_backend = {
.provide_ldisc = supdup_provide_ldisc,
.unthrottle = supdup_unthrottle,
.cfg_info = supdup_cfg_info,
.description = supdup_backend_description,
.id = "supdup",
.displayname_tc = "SUPDUP",
.displayname_lc = "SUPDUP", /* proper name, so capitalise it anyway */

View File

@ -200,6 +200,7 @@ struct Telnet {
Plug plug;
Backend backend;
Interactor interactor;
};
#define TELNET_MAX_BACKLOG 4096
@ -681,24 +682,21 @@ static void telnet_sent(Plug *plug, size_t bufsize)
seat_sent(telnet->seat, telnet->bufsize);
}
static char *telnet_plug_description(Plug *plug)
{
Telnet *telnet = container_of(plug, Telnet, plug);
return dupstr(telnet->description);
}
static char *telnet_backend_description(Backend *backend)
{
Telnet *telnet = container_of(backend, Telnet, backend);
return dupstr(telnet->description);
}
static const PlugVtable Telnet_plugvt = {
.log = telnet_log,
.closing = telnet_closing,
.receive = telnet_receive,
.sent = telnet_sent,
.description = telnet_plug_description,
};
static char *telnet_description(Interactor *itr)
{
Telnet *telnet = container_of(itr, Telnet, interactor);
return dupstr(telnet->description);
}
static const InteractorVtable Telnet_interactorvt = {
.description = telnet_description,
};
/*
@ -724,6 +722,8 @@ static char *telnet_init(const BackendVtable *vt, Seat *seat,
memset(telnet, 0, sizeof(Telnet));
telnet->plug.vt = &Telnet_plugvt;
telnet->backend.vt = vt;
telnet->interactor.vt = &Telnet_interactorvt;
telnet->backend.interactor = &telnet->interactor;
telnet->conf = conf_copy(conf);
telnet->s = NULL;
telnet->socket_connected = false;
@ -1098,7 +1098,6 @@ const BackendVtable telnet_backend = {
.provide_ldisc = telnet_provide_ldisc,
.unthrottle = telnet_unthrottle,
.cfg_info = telnet_cfg_info,
.description = telnet_backend_description,
.id = "telnet",
.displayname_tc = "Telnet",
.displayname_lc = "Telnet", /* proper name, so capitalise it anyway */