2013-11-17 14:03:36 +00:00
|
|
|
/*
|
|
|
|
* A dummy Socket implementation which just holds an error message.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define DEFINE_PLUG_METHOD_MACROS
|
|
|
|
#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;
|
|
|
|
Plug plug;
|
2018-05-27 08:29:33 +00:00
|
|
|
|
|
|
|
const Socket_vtable *sockvt;
|
|
|
|
} ErrorSocket;
|
2013-11-17 14:03:36 +00:00
|
|
|
|
|
|
|
static Plug sk_error_plug(Socket s, Plug p)
|
|
|
|
{
|
2018-05-27 08:29:33 +00:00
|
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
|
|
|
Plug ret = es->plug;
|
2013-11-17 14:03:36 +00:00
|
|
|
if (p)
|
2018-05-27 08:29:33 +00:00
|
|
|
es->plug = p;
|
2013-11-17 14:03:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sk_error_close(Socket s)
|
|
|
|
{
|
2018-05-27 08:29:33 +00:00
|
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static const char *sk_error_socket_error(Socket s)
|
|
|
|
{
|
2018-05-27 08:29:33 +00:00
|
|
|
ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt);
|
|
|
|
return es->error;
|
2013-11-17 14:03:36 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 12:57:45 +00:00
|
|
|
static char *sk_error_peer_info(Socket s)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-27 08:29:33 +00:00
|
|
|
static const Socket_vtable ErrorSocket_sockvt = {
|
|
|
|
sk_error_plug,
|
|
|
|
sk_error_close,
|
|
|
|
NULL /* write */,
|
|
|
|
NULL /* write_oob */,
|
|
|
|
NULL /* write_eof */,
|
|
|
|
NULL /* flush */,
|
|
|
|
NULL /* set_frozen */,
|
|
|
|
sk_error_socket_error,
|
|
|
|
sk_error_peer_info,
|
|
|
|
};
|
|
|
|
|
2013-11-17 14:03:36 +00:00
|
|
|
Socket new_error_socket(const char *errmsg, Plug plug)
|
|
|
|
{
|
2018-05-27 08:29:33 +00:00
|
|
|
ErrorSocket *es = snew(ErrorSocket);
|
|
|
|
es->sockvt = &ErrorSocket_sockvt;
|
|
|
|
es->plug = plug;
|
|
|
|
es->error = dupstr(errmsg);
|
|
|
|
return &es->sockvt;
|
2013-11-17 14:03:36 +00:00
|
|
|
}
|