Skip to content

Commit 807ed08

Browse files
committed
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.
1 parent 7618e07 commit 807ed08

File tree

12 files changed

+38
-81
lines changed

12 files changed

+38
-81
lines changed

errsock.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,11 @@ static const char *sk_error_socket_error(Socket *s)
3939
return es->error;
4040
}
4141

42-
static SocketEndpointInfo *sk_error_endpoint_info(Socket *s, bool peer)
43-
{
44-
return NULL;
45-
}
46-
4742
static const SocketVtable ErrorSocket_sockvt = {
4843
.plug = sk_error_plug,
4944
.close = sk_error_close,
5045
.socket_error = sk_error_socket_error,
51-
.endpoint_info = sk_error_endpoint_info,
46+
.endpoint_info = nullsock_endpoint_info,
5247
/* other methods are NULL */
5348
};
5449

network.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ void nullplug_closing(Plug *plug, PlugCloseType type, const char *error_msg);
386386
void nullplug_receive(Plug *plug, int urgent, const char *data, size_t len);
387387
void nullplug_sent(Plug *plug, size_t bufsize);
388388

389+
/*
390+
* Similar no-op socket function.
391+
*/
392+
SocketEndpointInfo *nullsock_endpoint_info(Socket *s, bool peer);
393+
389394
/* ----------------------------------------------------------------------
390395
* Functions defined outside the network code, which have to be
391396
* declared in this header file rather than the main putty.h because

proxy/sshproxy.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ static const char *sshproxy_socket_error(Socket *s)
123123
return sp->errmsg;
124124
}
125125

126-
static SocketEndpointInfo *sshproxy_endpoint_info(Socket *s, bool peer)
127-
{
128-
return NULL;
129-
}
130-
131126
static const SocketVtable SshProxy_sock_vt = {
132127
.plug = sshproxy_plug,
133128
.close = sshproxy_close,
@@ -136,7 +131,7 @@ static const SocketVtable SshProxy_sock_vt = {
136131
.write_eof = sshproxy_write_eof,
137132
.set_frozen = sshproxy_set_frozen,
138133
.socket_error = sshproxy_socket_error,
139-
.endpoint_info = sshproxy_endpoint_info,
134+
.endpoint_info = nullsock_endpoint_info,
140135
};
141136

142137
static void sshproxy_eventlog(LogPolicy *lp, const char *event)

ssh/portfwd.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,6 @@ static void free_portlistener_state(struct PortListener *pl)
9696
sfree(pl);
9797
}
9898

99-
static void pfd_log(Plug *plug, Socket *s, PlugLogType type,
100-
SockAddr *addr, int port,
101-
const char *error_msg, int error_code)
102-
{
103-
/* we have to dump these since we have no interface to logging.c */
104-
}
105-
106-
static void pfl_log(Plug *plug, Socket *s, PlugLogType type,
107-
SockAddr *addr, int port,
108-
const char *error_msg, int error_code)
109-
{
110-
/* we have to dump these since we have no interface to logging.c */
111-
}
112-
11399
static void pfd_close(struct PortForwarding *pf);
114100

115101
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)
433419
}
434420

435421
static const PlugVtable PortForwarding_plugvt = {
436-
.log = pfd_log,
422+
.log = nullplug_log,
437423
.closing = pfd_closing,
438424
.receive = pfd_receive,
439425
.sent = pfd_sent,
@@ -556,7 +542,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
556542
}
557543

558544
static const PlugVtable PortListener_plugvt = {
559-
.log = pfl_log,
545+
.log = nullplug_log,
560546
.closing = pfl_closing,
561547
.accepting = pfl_accepting,
562548
};

ssh/server.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ static const SeatVtable server_seat_vt = {
138138
.get_cursor_position = nullseat_get_cursor_position,
139139
};
140140

141-
static void server_socket_log(Plug *plug, Socket *s, PlugLogType type,
142-
SockAddr *addr, int port,
143-
const char *error_msg, int error_code)
144-
{
145-
/* server *srv = container_of(plug, server, plug); */
146-
/* FIXME */
147-
}
148-
149141
static void server_closing(Plug *plug, PlugCloseType type,
150142
const char *error_msg)
151143
{
@@ -254,7 +246,7 @@ Conf *make_ssh_server_conf(void)
254246
void ssh_check_sendok(Ssh *ssh) {}
255247

256248
static const PlugVtable ssh_server_plugvt = {
257-
.log = server_socket_log,
249+
.log = nullplug_log,
258250
.closing = server_closing,
259251
.receive = server_receive,
260252
.sent = server_sent,

ssh/sesschan.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,6 @@ bool sesschan_run_subsystem(Channel *chan, ptrlen subsys)
371371
return false;
372372
}
373373

374-
static void fwd_log(Plug *plug, Socket *s, PlugLogType type, SockAddr *addr,
375-
int port, const char *error_msg, int error_code)
376-
{ /* don't expect any weirdnesses from a listening socket */ }
377-
static void fwd_closing(Plug *plug, PlugCloseType type, const char *error_msg)
378-
{ /* not here, either */ }
379-
380374
static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
381375
{
382376
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)
400394
}
401395

402396
static const PlugVtable xfwd_plugvt = {
403-
.log = fwd_log,
404-
.closing = fwd_closing,
397+
.log = nullplug_log,
398+
.closing = nullplug_closing,
405399
.accepting = xfwd_accepting,
406400
};
407401

@@ -473,8 +467,8 @@ static int agentfwd_accepting(
473467
}
474468

475469
static const PlugVtable agentfwd_plugvt = {
476-
.log = fwd_log,
477-
.closing = fwd_closing,
470+
.log = nullplug_log,
471+
.closing = nullplug_closing,
478472
.accepting = agentfwd_accepting,
479473
};
480474

ssh/x11fwd.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,6 @@ static char *x11_verify(unsigned long peer_ip, int peer_port,
277277
return NULL;
278278
}
279279

280-
static void x11_log(Plug *p, Socket *s, PlugLogType type, SockAddr *addr,
281-
int port, const char *error_msg, int error_code)
282-
{
283-
/* We have no interface to the logging module here, so we drop these. */
284-
}
285-
286280
static void x11_send_init_error(struct X11Connection *conn,
287281
const char *err_message);
288282

@@ -336,7 +330,7 @@ static void x11_sent(Plug *plug, size_t bufsize)
336330
}
337331

338332
static const PlugVtable X11Connection_plugvt = {
339-
.log = x11_log,
333+
.log = nullplug_log,
340334
.closing = x11_closing,
341335
.receive = x11_receive,
342336
.sent = x11_sent,

stubs/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ add_sources_from_current_dir(utils
2828
null-mac.c
2929
null-opener.c
3030
null-plug.c
31-
null-seat.c)
31+
null-seat.c
32+
null-socket.c)

stubs/null-socket.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* null-socket.c: provide a null implementation of any Socket vtable
3+
* method that might otherwise need to be reimplemented in multiple
4+
* places as a no-op.
5+
*/
6+
7+
#include "putty.h"
8+
9+
SocketEndpointInfo *nullsock_endpoint_info(Socket *s, bool peer)
10+
{
11+
return NULL;
12+
}

unix/fd-socket.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,6 @@ static void fdsocket_select_result_input_error(int fd, int event)
315315
}
316316
}
317317

318-
static SocketEndpointInfo *fdsocket_endpoint_info(Socket *s, bool peer)
319-
{
320-
return NULL;
321-
}
322-
323318
static const SocketVtable FdSocket_sockvt = {
324319
.plug = fdsocket_plug,
325320
.close = fdsocket_close,
@@ -328,7 +323,7 @@ static const SocketVtable FdSocket_sockvt = {
328323
.write_eof = fdsocket_write_eof,
329324
.set_frozen = fdsocket_set_frozen,
330325
.socket_error = fdsocket_socket_error,
331-
.endpoint_info = fdsocket_endpoint_info,
326+
.endpoint_info = nullsock_endpoint_info,
332327
};
333328

334329
static void fdsocket_connect_success_callback(void *ctx)

0 commit comments

Comments
 (0)