2013-11-17 14:03:36 +00:00
|
|
|
/*
|
|
|
|
* A dummy Socket implementation which just holds an error message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "tree234.h"
|
|
|
|
#include "putty.h"
|
|
|
|
#include "network.h"
|
|
|
|
|
2018-05-27 08:29:33 +00:00
|
|
|
typedef struct {
|
2013-11-17 14:03:36 +00:00
|
|
|
char *error;
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Plug *plug;
|
2018-05-27 08:29:33 +00:00
|
|
|
|
2018-10-05 06:24:16 +00:00
|
|
|
Socket sock;
|
2018-05-27 08:29:33 +00:00
|
|
|
} ErrorSocket;
|
2013-11-17 14:03:36 +00:00
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
static Plug *sk_error_plug(Socket *s, Plug *p)
|
2013-11-17 14:03:36 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
ErrorSocket *es = container_of(s, ErrorSocket, sock);
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Plug *ret = es->plug;
|
2013-11-17 14:03:36 +00:00
|
|
|
if (p)
|
2019-09-08 19:29:00 +00:00
|
|
|
es->plug = p;
|
2013-11-17 14:03:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
static void sk_error_close(Socket *s)
|
2013-11-17 14:03:36 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
ErrorSocket *es = container_of(s, ErrorSocket, sock);
|
2013-11-17 14:03:36 +00:00
|
|
|
|
2018-05-27 08:29:33 +00:00
|
|
|
sfree(es->error);
|
|
|
|
sfree(es);
|
2013-11-17 14:03:36 +00:00
|
|
|
}
|
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
static const char *sk_error_socket_error(Socket *s)
|
2013-11-17 14:03:36 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
ErrorSocket *es = container_of(s, ErrorSocket, sock);
|
2018-05-27 08:29:33 +00:00
|
|
|
return es->error;
|
2013-11-17 14:03:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 06:03:46 +00:00
|
|
|
static const SocketVtable ErrorSocket_sockvt = {
|
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
|
|
|
.plug = sk_error_plug,
|
|
|
|
.close = sk_error_close,
|
|
|
|
.socket_error = sk_error_socket_error,
|
2024-06-29 11:07:59 +00:00
|
|
|
.endpoint_info = nullsock_endpoint_info,
|
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
|
|
|
/* other methods are NULL */
|
2018-05-27 08:29:33 +00:00
|
|
|
};
|
|
|
|
|
2020-01-01 18:58:11 +00:00
|
|
|
Socket *new_error_socket_consume_string(Plug *plug, char *errmsg)
|
2013-11-17 14:03:36 +00:00
|
|
|
{
|
2018-05-27 08:29:33 +00:00
|
|
|
ErrorSocket *es = snew(ErrorSocket);
|
2018-10-05 06:24:16 +00:00
|
|
|
es->sock.vt = &ErrorSocket_sockvt;
|
2018-05-27 08:29:33 +00:00
|
|
|
es->plug = plug;
|
2018-10-07 13:47:16 +00:00
|
|
|
es->error = errmsg;
|
2018-10-05 06:24:16 +00:00
|
|
|
return &es->sock;
|
2013-11-17 14:03:36 +00:00
|
|
|
}
|
2018-10-07 13:47:16 +00:00
|
|
|
|
|
|
|
Socket *new_error_socket_fmt(Plug *plug, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
msg = dupvprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2020-01-01 18:58:11 +00:00
|
|
|
return new_error_socket_consume_string(plug, msg);
|
2018-10-07 13:47:16 +00:00
|
|
|
}
|