mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-21 22:28:37 -05:00

Previously, SshProxy dealt with creating a TempSeat to wrap the one it was borrowing from its client, and then each client in turn dealt with detecting when it had had its seat borrowed and finishing up with the TempSeat. The latter involved a lot of code duplication; the former didn't involve code duplication _yet_ (since SshProxy was the only thing doing this job), but would have once we started wanting to do interactive password prompting for other types of network proxy. Now all of that functionality is centralised into two new Interactor helper functions: interactor_borrow_seat and interactor_return_seat.
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
/*
|
|
* Centralised functions for the Interactor trait.
|
|
*/
|
|
|
|
#include "putty.h"
|
|
|
|
Seat *interactor_borrow_seat(Interactor *itr)
|
|
{
|
|
Seat *clientseat = interactor_get_seat(itr);
|
|
if (!clientseat)
|
|
return NULL;
|
|
|
|
/* If the client has already had its Seat borrowed, then look
|
|
* through the existing TempSeat to find the underlying one. */
|
|
if (is_tempseat(clientseat))
|
|
return tempseat_get_real(clientseat);
|
|
|
|
/* Otherwise, make a new TempSeat and give that to the client. */
|
|
Seat *tempseat = tempseat_new(clientseat);
|
|
interactor_set_seat(itr, tempseat);
|
|
return clientseat;
|
|
}
|
|
|
|
void interactor_return_seat(Interactor *itr)
|
|
{
|
|
Seat *tempseat = interactor_get_seat(itr);
|
|
if (!is_tempseat(tempseat))
|
|
return; /* no-op */
|
|
|
|
tempseat_flush(tempseat);
|
|
Seat *realseat = tempseat_get_real(tempseat);
|
|
interactor_set_seat(itr, realseat);
|
|
tempseat_free(tempseat);
|
|
|
|
/*
|
|
* We're about to hand this seat back to the parent Interactor to
|
|
* do its own thing with. It will typically expect to start in the
|
|
* same state as if the seat had never been borrowed, i.e. in the
|
|
* starting trust state.
|
|
*/
|
|
seat_set_trust_status(realseat, true);
|
|
}
|
|
|
|
InteractionReadySeat interactor_announce(Interactor *itr)
|
|
{
|
|
Seat *seat = interactor_get_seat(itr);
|
|
|
|
/* TODO: print an announcement of this Interactor's identity, when
|
|
* appropriate */
|
|
|
|
InteractionReadySeat iseat;
|
|
iseat.seat = seat;
|
|
|
|
return iseat;
|
|
}
|