From 0a09c12edc8efc8cf88338fc40e89f0ac1f616b8 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 16 Feb 2020 11:43:20 +0000 Subject: [PATCH] Pass the BackendVtable pointer to backend_init. Now I can have multiple BackendVtable structures sharing all their function pointers, and still tell which is which when init is setting things up. --- putty.h | 6 +++--- raw.c | 10 +++++----- rlogin.c | 10 +++++----- ssh.c | 10 +++++----- telnet.c | 8 ++++---- testback.c | 26 ++++++++++++++------------ unix/uxpty.c | 9 +++++---- unix/uxser.c | 10 +++++----- windows/winser.c | 8 ++++---- 9 files changed, 50 insertions(+), 47 deletions(-) diff --git a/putty.h b/putty.h index d35c3b22..9e509ace 100644 --- a/putty.h +++ b/putty.h @@ -482,8 +482,8 @@ struct Backend { const BackendVtable *vt; }; struct BackendVtable { - const char *(*init) (Seat *seat, Backend **backend_out, - LogContext *logctx, Conf *conf, + const char *(*init) (const BackendVtable *vt, Seat *seat, + Backend **backend_out, LogContext *logctx, Conf *conf, const char *host, int port, char **realhost, bool nodelay, bool keepalive); @@ -525,7 +525,7 @@ struct BackendVtable { static inline const char *backend_init( const BackendVtable *vt, Seat *seat, Backend **out, LogContext *logctx, Conf *conf, const char *host, int port, char **rhost, bool nd, bool ka) -{ return vt->init(seat, out, logctx, conf, host, port, rhost, nd, ka); } +{ return vt->init(vt, seat, out, logctx, conf, host, port, rhost, nd, ka); } static inline void backend_free(Backend *be) { be->vt->free(be); } static inline void backend_reconfig(Backend *be, Conf *conf) diff --git a/raw.c b/raw.c index 142eed89..faf37794 100644 --- a/raw.c +++ b/raw.c @@ -119,10 +119,10 @@ static const PlugVtable Raw_plugvt = { * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *raw_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - bool nodelay, bool keepalive) +static const char *raw_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -135,7 +135,7 @@ static const char *raw_init(Seat *seat, Backend **backend_handle, raw = snew(Raw); raw->plug.vt = &Raw_plugvt; - raw->backend.vt = &raw_backend; + raw->backend.vt = vt; raw->s = NULL; raw->closed_on_socket_error = false; *backend_handle = &raw->backend; diff --git a/rlogin.c b/rlogin.c index 50bae179..dcd6c599 100644 --- a/rlogin.c +++ b/rlogin.c @@ -153,10 +153,10 @@ static const PlugVtable Rlogin_plugvt = { * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *rlogin_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - bool nodelay, bool keepalive) +static const char *rlogin_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { SockAddr *addr; const char *err; @@ -167,7 +167,7 @@ static const char *rlogin_init(Seat *seat, Backend **backend_handle, rlogin = snew(Rlogin); rlogin->plug.vt = &Rlogin_plugvt; - rlogin->backend.vt = &rlogin_backend; + rlogin->backend.vt = vt; rlogin->s = NULL; rlogin->closed_on_socket_error = false; rlogin->seat = seat; diff --git a/ssh.c b/ssh.c index 8ee3284f..8c7319bf 100644 --- a/ssh.c +++ b/ssh.c @@ -866,10 +866,10 @@ static void ssh_cache_conf_values(Ssh *ssh) * * Returns an error message, or NULL on success. */ -static const char *ssh_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - bool nodelay, bool keepalive) +static const char *ssh_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { const char *p; Ssh *ssh; @@ -891,7 +891,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, ssh->term_width = conf_get_int(ssh->conf, CONF_width); ssh->term_height = conf_get_int(ssh->conf, CONF_height); - ssh->backend.vt = &ssh_backend; + ssh->backend.vt = vt; *backend_handle = &ssh->backend; ssh->seat = seat; diff --git a/telnet.c b/telnet.c index 2496d4ee..a69fe569 100644 --- a/telnet.c +++ b/telnet.c @@ -678,9 +678,9 @@ static const PlugVtable Telnet_plugvt = { * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *telnet_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, +static const char *telnet_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, char **realhost, bool nodelay, bool keepalive) { SockAddr *addr; @@ -694,7 +694,7 @@ static const char *telnet_init(Seat *seat, Backend **backend_handle, telnet = snew(Telnet); telnet->plug.vt = &Telnet_plugvt; - telnet->backend.vt = &telnet_backend; + telnet->backend.vt = vt; telnet->conf = conf_copy(conf); telnet->s = NULL; telnet->closed_on_socket_error = false; diff --git a/testback.c b/testback.c index 0916c8ec..276f5464 100644 --- a/testback.c +++ b/testback.c @@ -32,10 +32,12 @@ #include "putty.h" -static const char *null_init(Seat *, Backend **, LogContext *, Conf *, - const char *, int, char **, int, int); -static const char *loop_init(Seat *, Backend **, LogContext *, Conf *, - const char *, int, char **, int, int); +static const char *null_init(const BackendVtable *, Seat *, Backend **, + LogContext *, Conf *, const char *, int, char **, + bool, bool); +static const char *loop_init(const BackendVtable *, Seat *, Backend **, + LogContext *, Conf *, const char *, int, char **, + bool, bool); static void null_free(Backend *); static void loop_free(Backend *); static void null_reconfig(Backend *, Conf *); @@ -72,10 +74,10 @@ struct loop_state { Backend backend; }; -static const char *null_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - int nodelay, int keepalive) { +static const char *null_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { /* No local authentication phase in this protocol */ seat_set_trust_status(seat, false); @@ -83,10 +85,10 @@ static const char *null_init(Seat *seat, Backend **backend_handle, return NULL; } -static const char *loop_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - int nodelay, int keepalive) { +static const char *loop_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { struct loop_state *st = snew(struct loop_state); /* No local authentication phase in this protocol */ diff --git a/unix/uxpty.c b/unix/uxpty.c index 38a6f6a1..d20f8fbb 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1268,9 +1268,9 @@ Backend *pty_backend_create( * it gets the argv array from the global variable pty_argv, expecting * that it will have been invoked by pterm. */ -static const char *pty_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, +static const char *pty_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, char **realhost, bool nodelay, bool keepalive) { const char *cmd = NULL; @@ -1281,7 +1281,8 @@ static const char *pty_init(Seat *seat, Backend **backend_handle, if (pty_argv && pty_argv[0] && !pty_argv[1]) cmd = pty_argv[0]; - *backend_handle= pty_backend_create( + assert(vt == &pty_backend); + *backend_handle = pty_backend_create( seat, logctx, conf, pty_argv, cmd, modes, false, NULL, NULL); *realhost = dupstr(""); return NULL; diff --git a/unix/uxser.c b/unix/uxser.c index 4d5e4d3e..da44188e 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -279,10 +279,10 @@ static const char *serial_configure(Serial *serial, Conf *conf) * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *serial_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, char **realhost, - bool nodelay, bool keepalive) +static const char *serial_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, + char **realhost, bool nodelay, bool keepalive) { Serial *serial; const char *err; @@ -292,7 +292,7 @@ static const char *serial_init(Seat *seat, Backend **backend_handle, seat_set_trust_status(seat, false); serial = snew(Serial); - serial->backend.vt = &serial_backend; + serial->backend.vt = vt; *backend_handle = &serial->backend; serial->seat = seat; diff --git a/windows/winser.c b/windows/winser.c index 947456ac..5b589c2b 100644 --- a/windows/winser.c +++ b/windows/winser.c @@ -191,9 +191,9 @@ static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf) * Also places the canonical host name into `realhost'. It must be * freed by the caller. */ -static const char *serial_init(Seat *seat, Backend **backend_handle, - LogContext *logctx, Conf *conf, - const char *host, int port, +static const char *serial_init(const BackendVtable *vt, Seat *seat, + Backend **backend_handle, LogContext *logctx, + Conf *conf, const char *host, int port, char **realhost, bool nodelay, bool keepalive) { Serial *serial; @@ -209,7 +209,7 @@ static const char *serial_init(Seat *seat, Backend **backend_handle, serial->out = serial->in = NULL; serial->bufsize = 0; serial->break_in_progress = false; - serial->backend.vt = &serial_backend; + serial->backend.vt = vt; *backend_handle = &serial->backend; serial->seat = seat;