mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Merge duplicate implementations of the trivial Plug.
In the course of reworking the socket vtable system, I noticed that both sshshare.c and x11fwd.c independently invented the idea of a Plug none of whose methods do anything. We don't need more than one of those, so let's centralise the idea to somewhere it can be easily reused.
This commit is contained in:
parent
f6d04ef1c4
commit
b851d748be
4
Recipe
4
Recipe
@ -253,7 +253,7 @@ NONSSH = telnet raw rlogin ldisc pinger
|
||||
SSH = ssh sshcrc sshdes sshmd5 sshrsa sshrand sshsha sshblowf
|
||||
+ sshdh sshcrcda sshpubk sshzlib sshdss x11fwd portfwd
|
||||
+ sshaes sshccp sshsh256 sshsh512 sshbn wildcard pinger ssharcf
|
||||
+ sshgssc pgssapi sshshare sshecc aqsync marshal
|
||||
+ sshgssc pgssapi sshshare sshecc aqsync marshal nullplug
|
||||
WINSSH = SSH winnoise wincapi winpgntc wingss winshare winnps winnpc
|
||||
+ winhsock errsock
|
||||
UXSSH = SSH uxnoise uxagentc uxgss uxshare
|
||||
@ -344,7 +344,7 @@ psftp : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC uxnogtk
|
||||
pageant : [X] uxpgnt uxagentc aqsync pageant sshrsa sshpubk sshdes sshbn
|
||||
+ sshmd5 version tree234 misc sshaes sshsha sshdss sshsh256 sshsh512
|
||||
+ sshecc CONF uxsignal nocproxy nogss be_none x11fwd ux_x11 uxcons
|
||||
+ gtkask gtkmisc UXMISC
|
||||
+ gtkask gtkmisc nullplug UXMISC
|
||||
|
||||
ptermapp : [XT] GTKTERM uxmisc misc ldisc settings uxpty uxsel BE_NONE uxstore
|
||||
+ uxsignal CHARSET uxpterm version time xpmpterm xpmptcfg
|
||||
|
@ -207,6 +207,11 @@ char *get_hostname(void);
|
||||
*/
|
||||
Socket new_error_socket(const char *errmsg, Plug plug);
|
||||
|
||||
/*
|
||||
* Trivial plug that does absolutely nothing. Found in nullplug.c.
|
||||
*/
|
||||
extern Plug nullplug;
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Functions defined outside the network code, which have to be
|
||||
* declared in this header file rather than the main putty.h because
|
||||
|
42
nullplug.c
Normal file
42
nullplug.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* nullplug.c: provide a null implementation of the Plug vtable which
|
||||
* ignores all calls. Occasionally useful in cases where we want to
|
||||
* make a network connection just to see if it works, but not do
|
||||
* anything with it afterwards except close it again.
|
||||
*/
|
||||
|
||||
#include "putty.h"
|
||||
|
||||
static void nullplug_socket_log(Plug plug, int type, SockAddr addr, int port,
|
||||
const char *error_msg, int error_code)
|
||||
{
|
||||
}
|
||||
|
||||
static void nullplug_closing(Plug plug, const char *error_msg, int error_code,
|
||||
int calling_back)
|
||||
{
|
||||
}
|
||||
|
||||
static void nullplug_receive(Plug plug, int urgent, char *data, int len)
|
||||
{
|
||||
}
|
||||
|
||||
static void nullplug_sent(Plug plug, int bufsize)
|
||||
{
|
||||
}
|
||||
|
||||
static const Plug_vtable nullplug_plugvt = {
|
||||
nullplug_socket_log,
|
||||
nullplug_closing,
|
||||
nullplug_receive,
|
||||
nullplug_sent,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const Plug_vtable *nullplug_plugvt_ptr = &nullplug_plugvt;
|
||||
|
||||
/*
|
||||
* There's a singleton instance of nullplug, because it's not
|
||||
* interesting enough to worry about making more than one of them.
|
||||
*/
|
||||
Plug nullplug = &nullplug_plugvt_ptr;
|
24
sshshare.c
24
sshshare.c
@ -2031,39 +2031,17 @@ char *ssh_share_sockname(const char *host, int port, Conf *conf)
|
||||
return sockname;
|
||||
}
|
||||
|
||||
static void nullplug_socket_log(Plug plug, int type, SockAddr addr, int port,
|
||||
const char *error_msg, int error_code) {}
|
||||
static void nullplug_closing(Plug plug, const char *error_msg, int error_code,
|
||||
int calling_back) {}
|
||||
static void nullplug_receive(Plug plug, int urgent, char *data, int len) {}
|
||||
static void nullplug_sent(Plug plug, int bufsize) {}
|
||||
|
||||
static const Plug_vtable nullplug_plugvt = {
|
||||
nullplug_socket_log,
|
||||
nullplug_closing,
|
||||
nullplug_receive,
|
||||
nullplug_sent,
|
||||
NULL
|
||||
};
|
||||
|
||||
struct nullplug {
|
||||
const Plug_vtable *plugvt;
|
||||
};
|
||||
|
||||
int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
|
||||
{
|
||||
char *sockname, *logtext, *ds_err, *us_err;
|
||||
int result;
|
||||
Socket sock;
|
||||
struct nullplug np;
|
||||
|
||||
np.plugvt = &nullplug_plugvt;
|
||||
|
||||
sockname = ssh_share_sockname(host, port, conf);
|
||||
|
||||
sock = NULL;
|
||||
logtext = ds_err = us_err = NULL;
|
||||
result = platform_ssh_share(sockname, conf, &np.plugvt, (Plug)NULL, &sock,
|
||||
result = platform_ssh_share(sockname, conf, nullplug, (Plug)NULL, &sock,
|
||||
&logtext, &ds_err, &us_err, FALSE, TRUE);
|
||||
|
||||
sfree(logtext);
|
||||
|
19
x11fwd.c
19
x11fwd.c
@ -52,22 +52,6 @@ static int xdmseen_cmp(void *a, void *b)
|
||||
memcmp(sa->clientid, sb->clientid, sizeof(sa->clientid));
|
||||
}
|
||||
|
||||
/* Do-nothing "plug" implementation, used by x11_setup_display() when it
|
||||
* creates a trial connection (and then immediately closes it).
|
||||
* XXX: bit out of place here, could in principle live in a platform-
|
||||
* independent network.c or something */
|
||||
static void dummy_plug_log(Plug p, int type, SockAddr addr, int port,
|
||||
const char *error_msg, int error_code) { }
|
||||
static void dummy_plug_closing
|
||||
(Plug p, const char *error_msg, int error_code, int calling_back) { }
|
||||
static void dummy_plug_receive(Plug p, int urgent, char *data, int len) { }
|
||||
static void dummy_plug_sent(Plug p, int bufsize) { }
|
||||
static int dummy_plug_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx) { return 1; }
|
||||
static const Plug_vtable dummy_plug_vtable = {
|
||||
dummy_plug_log, dummy_plug_closing, dummy_plug_receive,
|
||||
dummy_plug_sent, dummy_plug_accepting
|
||||
};
|
||||
|
||||
struct X11FakeAuth *x11_invent_fake_auth(tree234 *authtree, int authtype)
|
||||
{
|
||||
struct X11FakeAuth *auth = snew(struct X11FakeAuth);
|
||||
@ -306,8 +290,7 @@ struct X11Display *x11_setup_display(const char *display, Conf *conf)
|
||||
if (!err) {
|
||||
/* Create trial connection to see if there is a useful Unix-domain
|
||||
* socket */
|
||||
const Plug_vtable *dummy = &dummy_plug_vtable;
|
||||
Socket s = sk_new(sk_addr_dup(ux), 0, 0, 0, 0, 0, &dummy);
|
||||
Socket s = sk_new(sk_addr_dup(ux), 0, 0, 0, 0, 0, nullplug);
|
||||
err = sk_socket_error(s);
|
||||
sk_close(s);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user