2013-11-17 18:03:36 +04: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 11:29:33 +03:00
|
|
|
typedef struct {
|
2013-11-17 18:03:36 +04: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 21:10:23 +03:00
|
|
|
Plug *plug;
|
2018-05-27 11:29:33 +03:00
|
|
|
|
2018-10-05 09:24:16 +03:00
|
|
|
Socket sock;
|
2018-05-27 11:29:33 +03:00
|
|
|
} ErrorSocket;
|
2013-11-17 18:03:36 +04: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 21:10:23 +03:00
|
|
|
static Plug *sk_error_plug(Socket *s, Plug *p)
|
2013-11-17 18:03:36 +04:00
|
|
|
{
|
2018-10-06 01:49:08 +03: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 21:10:23 +03:00
|
|
|
Plug *ret = es->plug;
|
2013-11-17 18:03:36 +04:00
|
|
|
if (p)
|
2019-09-08 22:29:00 +03:00
|
|
|
es->plug = p;
|
2013-11-17 18:03:36 +04: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 21:10:23 +03:00
|
|
|
static void sk_error_close(Socket *s)
|
2013-11-17 18:03:36 +04:00
|
|
|
{
|
2018-10-06 01:49:08 +03:00
|
|
|
ErrorSocket *es = container_of(s, ErrorSocket, sock);
|
2013-11-17 18:03:36 +04:00
|
|
|
|
2018-05-27 11:29:33 +03:00
|
|
|
sfree(es->error);
|
|
|
|
sfree(es);
|
2013-11-17 18:03:36 +04: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 21:10:23 +03:00
|
|
|
static const char *sk_error_socket_error(Socket *s)
|
2013-11-17 18:03:36 +04:00
|
|
|
{
|
2018-10-06 01:49:08 +03:00
|
|
|
ErrorSocket *es = container_of(s, ErrorSocket, sock);
|
2018-05-27 11:29:33 +03:00
|
|
|
return es->error;
|
2013-11-17 18:03:36 +04:00
|
|
|
}
|
|
|
|
|
2018-10-18 22:06:42 +03:00
|
|
|
static SocketPeerInfo *sk_error_peer_info(Socket *s)
|
2015-05-18 15:57:45 +03:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-05 09:03:46 +03:00
|
|
|
static const SocketVtable ErrorSocket_sockvt = {
|
2018-05-27 11:29:33 +03:00
|
|
|
sk_error_plug,
|
|
|
|
sk_error_close,
|
|
|
|
NULL /* write */,
|
|
|
|
NULL /* write_oob */,
|
|
|
|
NULL /* write_eof */,
|
|
|
|
NULL /* set_frozen */,
|
|
|
|
sk_error_socket_error,
|
|
|
|
sk_error_peer_info,
|
|
|
|
};
|
|
|
|
|
2020-01-01 21:58:11 +03:00
|
|
|
Socket *new_error_socket_consume_string(Plug *plug, char *errmsg)
|
2013-11-17 18:03:36 +04:00
|
|
|
{
|
2018-05-27 11:29:33 +03:00
|
|
|
ErrorSocket *es = snew(ErrorSocket);
|
2018-10-05 09:24:16 +03:00
|
|
|
es->sock.vt = &ErrorSocket_sockvt;
|
2018-05-27 11:29:33 +03:00
|
|
|
es->plug = plug;
|
2018-10-07 16:47:16 +03:00
|
|
|
es->error = errmsg;
|
2018-10-05 09:24:16 +03:00
|
|
|
return &es->sock;
|
2013-11-17 18:03:36 +04:00
|
|
|
}
|
2018-10-07 16:47:16 +03: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 21:58:11 +03:00
|
|
|
return new_error_socket_consume_string(plug, msg);
|
2018-10-07 16:47:16 +03:00
|
|
|
}
|