mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-31 02:32:49 -05:00
Centralise stub plug/socket functions.
In the previous few commits I noticed some repeated work in the form of pointless empty implementations of Plug's log method, plus some existing (and some new) empty cases of Socket's endpoint_info. As a cleanup, I'm replacing as many as I can find with uses of a central null implementation in the stubs directory.
This commit is contained in:
parent
7618e079f5
commit
807ed08da0
@ -39,16 +39,11 @@ static const char *sk_error_socket_error(Socket *s)
|
|||||||
return es->error;
|
return es->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SocketEndpointInfo *sk_error_endpoint_info(Socket *s, bool peer)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const SocketVtable ErrorSocket_sockvt = {
|
static const SocketVtable ErrorSocket_sockvt = {
|
||||||
.plug = sk_error_plug,
|
.plug = sk_error_plug,
|
||||||
.close = sk_error_close,
|
.close = sk_error_close,
|
||||||
.socket_error = sk_error_socket_error,
|
.socket_error = sk_error_socket_error,
|
||||||
.endpoint_info = sk_error_endpoint_info,
|
.endpoint_info = nullsock_endpoint_info,
|
||||||
/* other methods are NULL */
|
/* other methods are NULL */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -386,6 +386,11 @@ void nullplug_closing(Plug *plug, PlugCloseType type, const char *error_msg);
|
|||||||
void nullplug_receive(Plug *plug, int urgent, const char *data, size_t len);
|
void nullplug_receive(Plug *plug, int urgent, const char *data, size_t len);
|
||||||
void nullplug_sent(Plug *plug, size_t bufsize);
|
void nullplug_sent(Plug *plug, size_t bufsize);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Similar no-op socket function.
|
||||||
|
*/
|
||||||
|
SocketEndpointInfo *nullsock_endpoint_info(Socket *s, bool peer);
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Functions defined outside the network code, which have to be
|
* Functions defined outside the network code, which have to be
|
||||||
* declared in this header file rather than the main putty.h because
|
* declared in this header file rather than the main putty.h because
|
||||||
|
@ -123,11 +123,6 @@ static const char *sshproxy_socket_error(Socket *s)
|
|||||||
return sp->errmsg;
|
return sp->errmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SocketEndpointInfo *sshproxy_endpoint_info(Socket *s, bool peer)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const SocketVtable SshProxy_sock_vt = {
|
static const SocketVtable SshProxy_sock_vt = {
|
||||||
.plug = sshproxy_plug,
|
.plug = sshproxy_plug,
|
||||||
.close = sshproxy_close,
|
.close = sshproxy_close,
|
||||||
@ -136,7 +131,7 @@ static const SocketVtable SshProxy_sock_vt = {
|
|||||||
.write_eof = sshproxy_write_eof,
|
.write_eof = sshproxy_write_eof,
|
||||||
.set_frozen = sshproxy_set_frozen,
|
.set_frozen = sshproxy_set_frozen,
|
||||||
.socket_error = sshproxy_socket_error,
|
.socket_error = sshproxy_socket_error,
|
||||||
.endpoint_info = sshproxy_endpoint_info,
|
.endpoint_info = nullsock_endpoint_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sshproxy_eventlog(LogPolicy *lp, const char *event)
|
static void sshproxy_eventlog(LogPolicy *lp, const char *event)
|
||||||
|
@ -96,20 +96,6 @@ static void free_portlistener_state(struct PortListener *pl)
|
|||||||
sfree(pl);
|
sfree(pl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pfd_log(Plug *plug, Socket *s, PlugLogType type,
|
|
||||||
SockAddr *addr, int port,
|
|
||||||
const char *error_msg, int error_code)
|
|
||||||
{
|
|
||||||
/* we have to dump these since we have no interface to logging.c */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pfl_log(Plug *plug, Socket *s, PlugLogType type,
|
|
||||||
SockAddr *addr, int port,
|
|
||||||
const char *error_msg, int error_code)
|
|
||||||
{
|
|
||||||
/* we have to dump these since we have no interface to logging.c */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pfd_close(struct PortForwarding *pf);
|
static void pfd_close(struct PortForwarding *pf);
|
||||||
|
|
||||||
static void pfd_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
static void pfd_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
||||||
@ -433,7 +419,7 @@ static void pfd_sent(Plug *plug, size_t bufsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable PortForwarding_plugvt = {
|
static const PlugVtable PortForwarding_plugvt = {
|
||||||
.log = pfd_log,
|
.log = nullplug_log,
|
||||||
.closing = pfd_closing,
|
.closing = pfd_closing,
|
||||||
.receive = pfd_receive,
|
.receive = pfd_receive,
|
||||||
.sent = pfd_sent,
|
.sent = pfd_sent,
|
||||||
@ -556,7 +542,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable PortListener_plugvt = {
|
static const PlugVtable PortListener_plugvt = {
|
||||||
.log = pfl_log,
|
.log = nullplug_log,
|
||||||
.closing = pfl_closing,
|
.closing = pfl_closing,
|
||||||
.accepting = pfl_accepting,
|
.accepting = pfl_accepting,
|
||||||
};
|
};
|
||||||
|
10
ssh/server.c
10
ssh/server.c
@ -138,14 +138,6 @@ static const SeatVtable server_seat_vt = {
|
|||||||
.get_cursor_position = nullseat_get_cursor_position,
|
.get_cursor_position = nullseat_get_cursor_position,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void server_socket_log(Plug *plug, Socket *s, PlugLogType type,
|
|
||||||
SockAddr *addr, int port,
|
|
||||||
const char *error_msg, int error_code)
|
|
||||||
{
|
|
||||||
/* server *srv = container_of(plug, server, plug); */
|
|
||||||
/* FIXME */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void server_closing(Plug *plug, PlugCloseType type,
|
static void server_closing(Plug *plug, PlugCloseType type,
|
||||||
const char *error_msg)
|
const char *error_msg)
|
||||||
{
|
{
|
||||||
@ -254,7 +246,7 @@ Conf *make_ssh_server_conf(void)
|
|||||||
void ssh_check_sendok(Ssh *ssh) {}
|
void ssh_check_sendok(Ssh *ssh) {}
|
||||||
|
|
||||||
static const PlugVtable ssh_server_plugvt = {
|
static const PlugVtable ssh_server_plugvt = {
|
||||||
.log = server_socket_log,
|
.log = nullplug_log,
|
||||||
.closing = server_closing,
|
.closing = server_closing,
|
||||||
.receive = server_receive,
|
.receive = server_receive,
|
||||||
.sent = server_sent,
|
.sent = server_sent,
|
||||||
|
@ -371,12 +371,6 @@ bool sesschan_run_subsystem(Channel *chan, ptrlen subsys)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fwd_log(Plug *plug, Socket *s, PlugLogType type, SockAddr *addr,
|
|
||||||
int port, const char *error_msg, int error_code)
|
|
||||||
{ /* don't expect any weirdnesses from a listening socket */ }
|
|
||||||
static void fwd_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
|
||||||
{ /* not here, either */ }
|
|
||||||
|
|
||||||
static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
||||||
{
|
{
|
||||||
sesschan *sess = container_of(p, sesschan, xfwd_plug);
|
sesschan *sess = container_of(p, sesschan, xfwd_plug);
|
||||||
@ -400,8 +394,8 @@ static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable xfwd_plugvt = {
|
static const PlugVtable xfwd_plugvt = {
|
||||||
.log = fwd_log,
|
.log = nullplug_log,
|
||||||
.closing = fwd_closing,
|
.closing = nullplug_closing,
|
||||||
.accepting = xfwd_accepting,
|
.accepting = xfwd_accepting,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -473,8 +467,8 @@ static int agentfwd_accepting(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable agentfwd_plugvt = {
|
static const PlugVtable agentfwd_plugvt = {
|
||||||
.log = fwd_log,
|
.log = nullplug_log,
|
||||||
.closing = fwd_closing,
|
.closing = nullplug_closing,
|
||||||
.accepting = agentfwd_accepting,
|
.accepting = agentfwd_accepting,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -277,12 +277,6 @@ static char *x11_verify(unsigned long peer_ip, int peer_port,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void x11_log(Plug *p, Socket *s, PlugLogType type, SockAddr *addr,
|
|
||||||
int port, const char *error_msg, int error_code)
|
|
||||||
{
|
|
||||||
/* We have no interface to the logging module here, so we drop these. */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void x11_send_init_error(struct X11Connection *conn,
|
static void x11_send_init_error(struct X11Connection *conn,
|
||||||
const char *err_message);
|
const char *err_message);
|
||||||
|
|
||||||
@ -336,7 +330,7 @@ static void x11_sent(Plug *plug, size_t bufsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable X11Connection_plugvt = {
|
static const PlugVtable X11Connection_plugvt = {
|
||||||
.log = x11_log,
|
.log = nullplug_log,
|
||||||
.closing = x11_closing,
|
.closing = x11_closing,
|
||||||
.receive = x11_receive,
|
.receive = x11_receive,
|
||||||
.sent = x11_sent,
|
.sent = x11_sent,
|
||||||
|
@ -28,4 +28,5 @@ add_sources_from_current_dir(utils
|
|||||||
null-mac.c
|
null-mac.c
|
||||||
null-opener.c
|
null-opener.c
|
||||||
null-plug.c
|
null-plug.c
|
||||||
null-seat.c)
|
null-seat.c
|
||||||
|
null-socket.c)
|
||||||
|
12
stubs/null-socket.c
Normal file
12
stubs/null-socket.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* null-socket.c: provide a null implementation of any Socket vtable
|
||||||
|
* method that might otherwise need to be reimplemented in multiple
|
||||||
|
* places as a no-op.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "putty.h"
|
||||||
|
|
||||||
|
SocketEndpointInfo *nullsock_endpoint_info(Socket *s, bool peer)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
@ -315,11 +315,6 @@ static void fdsocket_select_result_input_error(int fd, int event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SocketEndpointInfo *fdsocket_endpoint_info(Socket *s, bool peer)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const SocketVtable FdSocket_sockvt = {
|
static const SocketVtable FdSocket_sockvt = {
|
||||||
.plug = fdsocket_plug,
|
.plug = fdsocket_plug,
|
||||||
.close = fdsocket_close,
|
.close = fdsocket_close,
|
||||||
@ -328,7 +323,7 @@ static const SocketVtable FdSocket_sockvt = {
|
|||||||
.write_eof = fdsocket_write_eof,
|
.write_eof = fdsocket_write_eof,
|
||||||
.set_frozen = fdsocket_set_frozen,
|
.set_frozen = fdsocket_set_frozen,
|
||||||
.socket_error = fdsocket_socket_error,
|
.socket_error = fdsocket_socket_error,
|
||||||
.endpoint_info = fdsocket_endpoint_info,
|
.endpoint_info = nullsock_endpoint_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void fdsocket_connect_success_callback(void *ctx)
|
static void fdsocket_connect_success_callback(void *ctx)
|
||||||
|
@ -237,18 +237,12 @@ void keylist_update(void)
|
|||||||
|
|
||||||
static bool time_to_die = false;
|
static bool time_to_die = false;
|
||||||
|
|
||||||
/*
|
|
||||||
* These functions are part of the plug for our connection to the X
|
|
||||||
* display, so they do get called. They needn't actually do anything,
|
|
||||||
* except that x11_closing has to signal back to the main loop that
|
|
||||||
* it's time to terminate.
|
|
||||||
*/
|
|
||||||
static void x11_log(Plug *p, Socket *s, PlugLogType type, SockAddr *addr,
|
|
||||||
int port, const char *error_msg, int error_code) {}
|
|
||||||
static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {}
|
|
||||||
static void x11_sent(Plug *plug, size_t bufsize) {}
|
|
||||||
static void x11_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
static void x11_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* When the X connection closes, signal back to the main loop that
|
||||||
|
* it's time to terminate.
|
||||||
|
*/
|
||||||
time_to_die = true;
|
time_to_die = true;
|
||||||
}
|
}
|
||||||
struct X11Connection {
|
struct X11Connection {
|
||||||
@ -994,10 +988,10 @@ void run_client(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const PlugVtable X11Connection_plugvt = {
|
static const PlugVtable X11Connection_plugvt = {
|
||||||
.log = x11_log,
|
.log = nullplug_log,
|
||||||
.closing = x11_closing,
|
.closing = x11_closing,
|
||||||
.receive = x11_receive,
|
.receive = nullplug_receive,
|
||||||
.sent = x11_sent,
|
.sent = nullplug_sent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,12 +63,6 @@ static const char *sk_namedpipeserver_socket_error(Socket *s)
|
|||||||
return ps->error;
|
return ps->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SocketEndpointInfo *sk_namedpipeserver_endpoint_info(
|
|
||||||
Socket *s, bool peer)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool create_named_pipe(NamedPipeServerSocket *ps, bool first_instance)
|
static bool create_named_pipe(NamedPipeServerSocket *ps, bool first_instance)
|
||||||
{
|
{
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
@ -197,7 +191,7 @@ static const SocketVtable NamedPipeServerSocket_sockvt = {
|
|||||||
.plug = sk_namedpipeserver_plug,
|
.plug = sk_namedpipeserver_plug,
|
||||||
.close = sk_namedpipeserver_close,
|
.close = sk_namedpipeserver_close,
|
||||||
.socket_error = sk_namedpipeserver_socket_error,
|
.socket_error = sk_namedpipeserver_socket_error,
|
||||||
.endpoint_info = sk_namedpipeserver_endpoint_info,
|
.endpoint_info = nullsock_endpoint_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
Socket *new_named_pipe_listener(const char *pipename, Plug *plug)
|
Socket *new_named_pipe_listener(const char *pipename, Plug *plug)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user