2018-05-27 14:41:12 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2024-06-26 07:29:39 +00:00
|
|
|
void nullplug_log(Plug *plug, Socket *s, PlugLogType type, SockAddr *addr,
|
2021-09-15 12:48:30 +00:00
|
|
|
int port, const char *err_msg, int err_code)
|
2018-05-27 14:41:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
New API for plug_closing() with a custom type enum.
Passing an operating-system-specific error code to plug_closing(),
such as errno or GetLastError(), was always a bit weird, given that it
generally had to be handled by cross-platform receiving code in
backends. I had the platform.h implementations #define any error
values that the cross-platform code would have to handle specially,
but that's still not a great system, because it also doesn't leave
freedom to invent error representations of my own that don't
correspond to any OS code. (For example, the ones I just removed from
proxy.h.)
So now, the OS error code is gone from the plug_closing API, and in
its place is a custom enumeration of closure types: normal, error, and
the special case BROKEN_PIPE which is the only OS error code we have
so far needed to handle specially. (All others just mean 'abandon the
connection and print the textual message'.)
Having already centralised the handling of OS error codes in the
previous commit, we've now got a convenient place to add any further
type codes for errors needing special handling: each of Unix
plug_closing_errno(), Windows plug_closing_system_error(), and Windows
plug_closing_winsock_error() can easily grow extra special cases if
need be, and each one will only have to live in one place.
2021-11-06 13:28:32 +00:00
|
|
|
void nullplug_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
2018-05-27 14:41:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 12:48:30 +00:00
|
|
|
void nullplug_receive(Plug *plug, int urgent, const char *data, size_t len)
|
2018-05-27 14:41:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-15 12:48:30 +00:00
|
|
|
void nullplug_sent(Plug *plug, size_t bufsize)
|
2018-05-27 14:41:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-05 06:03:46 +00:00
|
|
|
static const PlugVtable nullplug_plugvt = {
|
2021-09-15 12:48:30 +00:00
|
|
|
.log = nullplug_log,
|
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.
We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.
The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.
While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
2020-03-10 21:06:29 +00:00
|
|
|
.closing = nullplug_closing,
|
|
|
|
.receive = nullplug_receive,
|
|
|
|
.sent = nullplug_sent,
|
2018-05-27 14:41:12 +00:00
|
|
|
};
|
|
|
|
|
2018-10-05 06:24:16 +00:00
|
|
|
static Plug nullplug_plug = { &nullplug_plugvt };
|
2018-05-27 14:41:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There's a singleton instance of nullplug, because it's not
|
|
|
|
* interesting enough to worry about making more than one of them.
|
|
|
|
*/
|
2018-10-05 06:24:16 +00:00
|
|
|
Plug *const nullplug = &nullplug_plug;
|