mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05:00
Turn Backend into a sensible classoid.
Nearly every part of the code that ever handles a full backend structure has historically done it using a pair of pointer variables, one pointing at a constant struct full of function pointers, and the other pointing to a 'void *' state object that's passed to each of those. While I'm modernising the rest of the code, this seems like a good time to turn that into the same more or less type-safe and less cumbersome system as I'm using for other parts of the code, such as Socket, Plug, BinaryPacketProtocol and so forth: the Backend structure contains a vtable pointer, and a system of macro wrappers handles dispatching through that vtable.
This commit is contained in:
21
settings.c
21
settings.c
@ -74,18 +74,18 @@ const char *const ttymodes[] = {
|
||||
* (which is only present in tools that manage settings).
|
||||
*/
|
||||
|
||||
Backend *backend_from_name(const char *name)
|
||||
const struct Backend_vtable *backend_vt_from_name(const char *name)
|
||||
{
|
||||
Backend **p;
|
||||
const struct Backend_vtable *const *p;
|
||||
for (p = backends; *p != NULL; p++)
|
||||
if (!strcmp((*p)->name, name))
|
||||
return *p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Backend *backend_from_proto(int proto)
|
||||
const struct Backend_vtable *backend_vt_from_proto(int proto)
|
||||
{
|
||||
Backend **p;
|
||||
const struct Backend_vtable *const *p;
|
||||
for (p = backends; *p != NULL; p++)
|
||||
if ((*p)->protocol == proto)
|
||||
return *p;
|
||||
@ -528,9 +528,10 @@ void save_open_settings(void *sesskey, Conf *conf)
|
||||
write_setting_i(sesskey, "SSHLogOmitData", conf_get_int(conf, CONF_logomitdata));
|
||||
p = "raw";
|
||||
{
|
||||
const Backend *b = backend_from_proto(conf_get_int(conf, CONF_protocol));
|
||||
if (b)
|
||||
p = b->name;
|
||||
const struct Backend_vtable *vt =
|
||||
backend_vt_from_proto(conf_get_int(conf, CONF_protocol));
|
||||
if (vt)
|
||||
p = vt->name;
|
||||
}
|
||||
write_setting_s(sesskey, "Protocol", p);
|
||||
write_setting_i(sesskey, "PortNumber", conf_get_int(conf, CONF_port));
|
||||
@ -791,9 +792,9 @@ void load_open_settings(void *sesskey, Conf *conf)
|
||||
conf_set_int(conf, CONF_protocol, default_protocol);
|
||||
conf_set_int(conf, CONF_port, default_port);
|
||||
{
|
||||
const Backend *b = backend_from_name(prot);
|
||||
if (b) {
|
||||
conf_set_int(conf, CONF_protocol, b->protocol);
|
||||
const struct Backend_vtable *vt = backend_vt_from_name(prot);
|
||||
if (vt) {
|
||||
conf_set_int(conf, CONF_protocol, vt->protocol);
|
||||
gppi(sesskey, "PortNumber", default_port, conf, CONF_port);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user