1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12: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

75
putty.h
View File

@ -633,8 +633,56 @@ enum {
/* In (no)sshproxy.c */
extern const bool ssh_proxy_supported;
/*
* The Interactor trait is implemented by anything that is capable of
* presenting interactive prompts or questions to the user during
* network connection setup. Every Backend that ever needs to do this
* is an Interactor, but also, while a Backend is making its initial
* network connection, it may go via network proxy code which is also
* an Interactor and can ask questions of its own.
*/
struct Interactor {
const InteractorVtable *vt;
};
struct InteractorVtable {
/*
* Returns a user-facing description of the nature of the network
* connection being made. Used in interactive proxy authentication
* to announce which connection attempt is now in control of the
* Seat.
*
* The idea is not just to be written in natural language, but to
* connect with the user's idea of _why_ they think some
* connection is being made. For example, instead of saying 'TCP
* connection to 123.45.67.89 port 22', you might say 'SSH
* connection to [logical host name for SSH host key purposes]'.
*
* The returned string must be freed by the caller.
*/
char *(*description)(Interactor *itr);
};
static inline char *interactor_description(Interactor *itr)
{ return itr->vt->description(itr); }
/* Interactors that are Backends will find this helper function useful
* in constructing their description strings */
char *default_description(const BackendVtable *backvt,
const char *host, int port);
/*
* The Backend trait is the top-level one that governs each of the
* user-facing main modes that PuTTY can use to talk to some
* destination: SSH, Telnet, serial port, pty, etc.
*/
struct Backend {
const BackendVtable *vt;
/* Many Backends are also Interactors. If this one is, a pointer
* to its Interactor trait lives here. */
Interactor *interactor;
};
struct BackendVtable {
char *(*init) (const BackendVtable *vt, Seat *seat,
@ -680,28 +728,6 @@ struct BackendVtable {
* connections that would be lost if this one were terminated. */
char *(*close_warn_text)(Backend *be);
/*
* Returns a user-facing description of the nature of the network
* connection being made. Used in interactive proxy authentication
* to announce which connection attempt is now in control of the
* Seat.
*
* The idea is not just to be written in natural language, but to
* connect with the user's idea of _why_ they think some
* connection is being made. For example, instead of saying 'TCP
* connection to 123.45.67.89 port 22', you might say 'SSH
* connection to [logical host name for SSH host key purposes]'.
*
* This function pointer may be NULL, or may exist but return
* NULL, in which case no user-facing description is available.
* (Backends which are never proxied, such as pty and ConPTY, need
* not bother to fill this in.)
*
* If a non-NULL string is returned, it must be freed by the
* caller.
*/
char *(*description)(Backend *be);
/* 'id' is a machine-readable name for the backend, used in
* saved-session storage. 'displayname_tc' and 'displayname_lc'
* are human-readable names, one in title-case for config boxes,
@ -750,11 +776,6 @@ static inline void backend_unthrottle(Backend *be, size_t bufsize)
{ be->vt->unthrottle(be, bufsize); }
static inline int backend_cfg_info(Backend *be)
{ return be->vt->cfg_info(be); }
static inline char *backend_description(Backend *be)
{ return be->vt->description ? be->vt->description(be) : NULL; }
char *default_description(const BackendVtable *backvt,
const char *host, int port);
extern const struct BackendVtable *const backends[];
/*