From aac5e096fa0579c754776167c1486bdb693c065d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 30 Oct 2021 17:34:53 +0100 Subject: [PATCH] Add Interactor methods to get/set LogPolicy and Seat. Nothing uses this yet, but the next commit will. --- otherbackends/raw.c | 21 +++++++++++++++++++++ otherbackends/rlogin.c | 21 +++++++++++++++++++++ otherbackends/supdup.c | 21 +++++++++++++++++++++ otherbackends/telnet.c | 21 +++++++++++++++++++++ putty.h | 22 ++++++++++++++++++++++ ssh/ssh.c | 21 +++++++++++++++++++++ 6 files changed, 127 insertions(+) diff --git a/otherbackends/raw.c b/otherbackends/raw.c index 9a391d94..7e80e42b 100644 --- a/otherbackends/raw.c +++ b/otherbackends/raw.c @@ -130,8 +130,29 @@ static char *raw_description(Interactor *itr) return dupstr(raw->description); } +static LogPolicy *raw_logpolicy(Interactor *itr) +{ + Raw *raw = container_of(itr, Raw, interactor); + return log_get_policy(raw->logctx); +} + +static Seat *raw_get_seat(Interactor *itr) +{ + Raw *raw = container_of(itr, Raw, interactor); + return raw->seat; +} + +static void raw_set_seat(Interactor *itr, Seat *seat) +{ + Raw *raw = container_of(itr, Raw, interactor); + raw->seat = seat; +} + static const InteractorVtable Raw_interactorvt = { .description = raw_description, + .logpolicy = raw_logpolicy, + .get_seat = raw_get_seat, + .set_seat = raw_set_seat, }; /* diff --git a/otherbackends/rlogin.c b/otherbackends/rlogin.c index 3ab3c070..6da67070 100644 --- a/otherbackends/rlogin.c +++ b/otherbackends/rlogin.c @@ -207,8 +207,29 @@ static char *rlogin_description(Interactor *itr) return dupstr(rlogin->description); } +static LogPolicy *rlogin_logpolicy(Interactor *itr) +{ + Rlogin *rlogin = container_of(itr, Rlogin, interactor); + return log_get_policy(rlogin->logctx); +} + +static Seat *rlogin_get_seat(Interactor *itr) +{ + Rlogin *rlogin = container_of(itr, Rlogin, interactor); + return rlogin->seat; +} + +static void rlogin_set_seat(Interactor *itr, Seat *seat) +{ + Rlogin *rlogin = container_of(itr, Rlogin, interactor); + rlogin->seat = seat; +} + static const InteractorVtable Rlogin_interactorvt = { .description = rlogin_description, + .logpolicy = rlogin_logpolicy, + .get_seat = rlogin_get_seat, + .set_seat = rlogin_set_seat, }; /* diff --git a/otherbackends/supdup.c b/otherbackends/supdup.c index 3588e9f3..f680c521 100644 --- a/otherbackends/supdup.c +++ b/otherbackends/supdup.c @@ -649,8 +649,29 @@ static char *supdup_description(Interactor *itr) return dupstr(supdup->description); } +static LogPolicy *supdup_logpolicy(Interactor *itr) +{ + Supdup *supdup = container_of(itr, Supdup, interactor); + return log_get_policy(supdup->logctx); +} + +static Seat *supdup_get_seat(Interactor *itr) +{ + Supdup *supdup = container_of(itr, Supdup, interactor); + return supdup->seat; +} + +static void supdup_set_seat(Interactor *itr, Seat *seat) +{ + Supdup *supdup = container_of(itr, Supdup, interactor); + supdup->seat = seat; +} + static const InteractorVtable Supdup_interactorvt = { .description = supdup_description, + .logpolicy = supdup_logpolicy, + .get_seat = supdup_get_seat, + .set_seat = supdup_set_seat, }; /* diff --git a/otherbackends/telnet.c b/otherbackends/telnet.c index bbf539c9..fecee06c 100644 --- a/otherbackends/telnet.c +++ b/otherbackends/telnet.c @@ -695,8 +695,29 @@ static char *telnet_description(Interactor *itr) return dupstr(telnet->description); } +static LogPolicy *telnet_logpolicy(Interactor *itr) +{ + Telnet *telnet = container_of(itr, Telnet, interactor); + return log_get_policy(telnet->logctx); +} + +static Seat *telnet_get_seat(Interactor *itr) +{ + Telnet *telnet = container_of(itr, Telnet, interactor); + return telnet->seat; +} + +static void telnet_set_seat(Interactor *itr, Seat *seat) +{ + Telnet *telnet = container_of(itr, Telnet, interactor); + telnet->seat = seat; +} + static const InteractorVtable Telnet_interactorvt = { .description = telnet_description, + .logpolicy = telnet_logpolicy, + .get_seat = telnet_get_seat, + .set_seat = telnet_set_seat, }; /* diff --git a/putty.h b/putty.h index ffbfa000..7887535f 100644 --- a/putty.h +++ b/putty.h @@ -661,10 +661,32 @@ struct InteractorVtable { * The returned string must be freed by the caller. */ char *(*description)(Interactor *itr); + + /* + * Returns the LogPolicy associated with this Interactor. (A + * Backend can derive this from its logging context; a proxy + * Interactor inherits it from the Interactor for the parent + * network connection.) + */ + LogPolicy *(*logpolicy)(Interactor *itr); + + /* + * Gets and sets the Seat that this Interactor talks to. When a + * Seat is borrowed and replaced with a TempSeat, this will be the + * mechanism by which that replacement happens. + */ + Seat *(*get_seat)(Interactor *itr); + void (*set_seat)(Interactor *itr, Seat *seat); }; static inline char *interactor_description(Interactor *itr) { return itr->vt->description(itr); } +static inline LogPolicy *interactor_logpolicy(Interactor *itr) +{ return itr->vt->logpolicy(itr); } +static inline Seat *interactor_get_seat(Interactor *itr) +{ return itr->vt->get_seat(itr); } +static inline void interactor_set_seat(Interactor *itr, Seat *seat) +{ itr->vt->set_seat(itr, seat); } /* Interactors that are Backends will find this helper function useful * in constructing their description strings */ diff --git a/ssh/ssh.c b/ssh/ssh.c index e240c0c7..adc55391 100644 --- a/ssh/ssh.c +++ b/ssh/ssh.c @@ -732,8 +732,29 @@ static char *ssh_description(Interactor *itr) return dupstr(ssh->description); } +static LogPolicy *ssh_logpolicy(Interactor *itr) +{ + Ssh *ssh = container_of(itr, Ssh, interactor); + return log_get_policy(ssh->logctx); +} + +static Seat *ssh_get_seat(Interactor *itr) +{ + Ssh *ssh = container_of(itr, Ssh, interactor); + return ssh->seat; +} + +static void ssh_set_seat(Interactor *itr, Seat *seat) +{ + Ssh *ssh = container_of(itr, Ssh, interactor); + ssh->seat = seat; +} + static const InteractorVtable Ssh_interactorvt = { .description = ssh_description, + .logpolicy = ssh_logpolicy, + .get_seat = ssh_get_seat, + .set_seat = ssh_set_seat, }; /*