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

Add 'description' methods for Backend and Plug.

These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.

Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.

The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.

Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"

In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
This commit is contained in:
Simon Tatham
2021-10-24 09:18:12 +01:00
parent 5374444879
commit f1746d69b1
9 changed files with 165 additions and 6 deletions

View File

@ -19,6 +19,7 @@ struct Raw {
LogContext *logctx;
Ldisc *ldisc;
bool sent_console_eof, sent_socket_eof, socket_connected;
char *description;
Conf *conf;
@ -115,11 +116,24 @@ 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,
};
/*
@ -151,6 +165,7 @@ static char *raw_init(const BackendVtable *vt, Seat *seat,
raw->bufsize = 0;
raw->socket_connected = false;
raw->conf = conf_copy(conf);
raw->description = default_description(vt, host, port);
raw->seat = seat;
raw->logctx = logctx;
@ -205,6 +220,7 @@ static void raw_free(Backend *be)
if (raw->s)
sk_close(raw->s);
conf_free(raw->conf);
sfree(raw->description);
sfree(raw);
}
@ -337,6 +353,7 @@ 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",