1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/utils/default_description.c

23 lines
794 B
C
Raw Permalink Normal View History

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.
2021-10-24 08:18:12 +00:00
/*
* Construct a description string for a backend to use as
* backend_description(), or a plug as plug_description().
*
* For some backends this will be overridden: e.g. SSH prefers to
* think in terms of _logical_ host names (i.e. the one associated
* with the host key) rather than the physical details of where you're
* connecting to. But this default is good for simpler backends.
*/
#include "putty.h"
char *default_description(const BackendVtable *backvt,
const char *host, int port)
{
const char *be_name = backvt->displayname_lc;
if (backvt->default_port && port == backvt->default_port)
return dupprintf("%s connection to %s", be_name, host);
else
return dupprintf("%s connection to %s port %d", be_name, host, port);
}