2006-04-23 22:26:03 +04:00
|
|
|
/*
|
|
|
|
* "Raw" backend.
|
|
|
|
*/
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-12-22 13:40:47 +04:00
|
|
|
#include <limits.h>
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
#define RAW_MAX_BACKLOG 4096
|
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
typedef struct raw_backend_data {
|
|
|
|
Socket s;
|
2012-12-22 13:40:47 +04:00
|
|
|
int closed_on_socket_error;
|
2002-10-25 15:30:33 +04:00
|
|
|
int bufsize;
|
2018-09-12 11:10:51 +03:00
|
|
|
Frontend *frontend;
|
2015-11-22 17:33:28 +03:00
|
|
|
int sent_console_eof, sent_socket_eof, session_started;
|
|
|
|
|
|
|
|
Conf *conf;
|
2018-05-27 11:29:33 +03:00
|
|
|
|
|
|
|
const Plug_vtable *plugvt;
|
2018-09-11 18:23:38 +03:00
|
|
|
Backend backend;
|
2002-10-25 15:30:33 +04:00
|
|
|
} *Raw;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_size(Backend *be, int width, int height);
|
2002-10-25 15:30:33 +04:00
|
|
|
|
2018-05-26 10:31:34 +03:00
|
|
|
static void c_write(Raw raw, const void *buf, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
int backlog = from_backend(raw->frontend, 0, buf, len);
|
|
|
|
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2005-01-16 17:29:34 +03:00
|
|
|
static void raw_log(Plug plug, int type, SockAddr addr, int port,
|
|
|
|
const char *error_msg, int error_code)
|
|
|
|
{
|
2018-05-27 11:29:33 +03:00
|
|
|
Raw raw = FROMFIELD(plug, struct raw_backend_data, plugvt);
|
2015-11-22 14:49:14 +03:00
|
|
|
backend_socket_log(raw->frontend, type, addr, port,
|
2015-11-22 17:33:28 +03:00
|
|
|
error_msg, error_code, raw->conf, raw->session_started);
|
2005-01-16 17:29:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-13 15:44:03 +04:00
|
|
|
static void raw_check_close(Raw raw)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Called after we send EOF on either the socket or the console.
|
|
|
|
* Its job is to wind up the session once we have sent EOF on both.
|
|
|
|
*/
|
|
|
|
if (raw->sent_console_eof && raw->sent_socket_eof) {
|
|
|
|
if (raw->s) {
|
|
|
|
sk_close(raw->s);
|
|
|
|
raw->s = NULL;
|
|
|
|
notify_remote_exit(raw->frontend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-03 01:03:24 +03:00
|
|
|
static void raw_closing(Plug plug, const char *error_msg, int error_code,
|
|
|
|
int calling_back)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2018-05-27 11:29:33 +03:00
|
|
|
Raw raw = FROMFIELD(plug, struct raw_backend_data, plugvt);
|
2002-10-25 15:30:33 +04:00
|
|
|
|
2001-03-13 13:22:45 +03:00
|
|
|
if (error_msg) {
|
2011-09-13 15:44:03 +04:00
|
|
|
/* A socket error has occurred. */
|
|
|
|
if (raw->s) {
|
|
|
|
sk_close(raw->s);
|
|
|
|
raw->s = NULL;
|
2012-12-22 13:40:47 +04:00
|
|
|
raw->closed_on_socket_error = TRUE;
|
2011-09-13 15:44:03 +04:00
|
|
|
notify_remote_exit(raw->frontend);
|
|
|
|
}
|
|
|
|
logevent(raw->frontend, error_msg);
|
|
|
|
connection_fatal(raw->frontend, "%s", error_msg);
|
|
|
|
} else {
|
|
|
|
/* Otherwise, the remote side closed the connection normally. */
|
|
|
|
if (!raw->sent_console_eof && from_backend_eof(raw->frontend)) {
|
|
|
|
/*
|
|
|
|
* The front end wants us to close the outgoing side of the
|
|
|
|
* connection as soon as we see EOF from the far end.
|
|
|
|
*/
|
|
|
|
if (!raw->sent_socket_eof) {
|
|
|
|
if (raw->s)
|
|
|
|
sk_write_eof(raw->s);
|
|
|
|
raw->sent_socket_eof= TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
raw->sent_console_eof = TRUE;
|
|
|
|
raw_check_close(raw);
|
|
|
|
}
|
2001-03-13 13:22:45 +03:00
|
|
|
}
|
|
|
|
|
2016-06-03 01:03:24 +03:00
|
|
|
static void raw_receive(Plug plug, int urgent, char *data, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2018-05-27 11:29:33 +03:00
|
|
|
Raw raw = FROMFIELD(plug, struct raw_backend_data, plugvt);
|
2002-10-25 15:30:33 +04:00
|
|
|
c_write(raw, data, len);
|
2015-11-22 17:33:28 +03:00
|
|
|
/* We count 'session start', for proxy logging purposes, as being
|
|
|
|
* when data is received from the network and printed. */
|
|
|
|
raw->session_started = TRUE;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2001-09-08 02:39:01 +04:00
|
|
|
static void raw_sent(Plug plug, int bufsize)
|
|
|
|
{
|
2018-05-27 11:29:33 +03:00
|
|
|
Raw raw = FROMFIELD(plug, struct raw_backend_data, plugvt);
|
2002-10-25 15:30:33 +04:00
|
|
|
raw->bufsize = bufsize;
|
2001-09-08 02:39:01 +04:00
|
|
|
}
|
|
|
|
|
2018-05-27 11:29:33 +03:00
|
|
|
static const Plug_vtable Raw_plugvt = {
|
|
|
|
raw_log,
|
|
|
|
raw_closing,
|
|
|
|
raw_receive,
|
|
|
|
raw_sent
|
|
|
|
};
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
2000-10-23 14:32:37 +04:00
|
|
|
* Called to set up the raw connection.
|
|
|
|
*
|
1999-11-01 19:40:40 +03:00
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
2001-05-09 18:01:15 +04:00
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
1999-11-01 19:40:40 +03:00
|
|
|
*/
|
2018-09-12 11:10:51 +03:00
|
|
|
static const char *raw_init(Frontend *frontend, Backend **backend_handle,
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 22:52:21 +04:00
|
|
|
Conf *conf,
|
2015-05-15 13:15:42 +03:00
|
|
|
const char *host, int port, char **realhost,
|
|
|
|
int nodelay, int keepalive)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2000-10-23 14:32:37 +04:00
|
|
|
SockAddr addr;
|
2003-05-04 18:18:18 +04:00
|
|
|
const char *err;
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 22:52:21 +04:00
|
|
|
int addressfamily;
|
|
|
|
char *loghost;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2003-03-29 19:14:26 +03:00
|
|
|
raw = snew(struct raw_backend_data);
|
2018-05-27 11:29:33 +03:00
|
|
|
raw->plugvt = &Raw_plugvt;
|
2018-09-11 18:23:38 +03:00
|
|
|
raw->backend.vt = &raw_backend;
|
2002-10-25 15:30:33 +04:00
|
|
|
raw->s = NULL;
|
2012-12-22 13:40:47 +04:00
|
|
|
raw->closed_on_socket_error = FALSE;
|
2018-09-11 18:23:38 +03:00
|
|
|
*backend_handle = &raw->backend;
|
2011-09-13 15:44:03 +04:00
|
|
|
raw->sent_console_eof = raw->sent_socket_eof = FALSE;
|
2014-11-22 19:35:54 +03:00
|
|
|
raw->bufsize = 0;
|
2015-11-22 17:33:28 +03:00
|
|
|
raw->session_started = FALSE;
|
|
|
|
raw->conf = conf_copy(conf);
|
2002-10-25 15:30:33 +04:00
|
|
|
|
2018-09-12 11:10:51 +03:00
|
|
|
raw->frontend = frontend;
|
2002-10-22 20:11:33 +04:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 22:52:21 +04:00
|
|
|
addressfamily = conf_get_int(conf, CONF_addressfamily);
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
2015-11-22 12:58:14 +03:00
|
|
|
addr = name_lookup(host, port, realhost, conf, addressfamily,
|
|
|
|
raw->frontend, "main connection");
|
2003-08-07 20:04:33 +04:00
|
|
|
if ((err = sk_addr_error(addr)) != NULL) {
|
|
|
|
sk_addr_free(addr);
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
2003-08-07 20:04:33 +04:00
|
|
|
}
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 23; /* default telnet port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
2004-06-20 21:07:38 +04:00
|
|
|
raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
|
2018-05-27 11:29:33 +03:00
|
|
|
&raw->plugvt, conf);
|
2003-01-04 19:21:17 +03:00
|
|
|
if ((err = sk_socket_error(raw->s)) != NULL)
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 22:52:21 +04:00
|
|
|
loghost = conf_get_str(conf, CONF_loghost);
|
|
|
|
if (*loghost) {
|
2008-06-01 15:16:32 +04:00
|
|
|
char *colon;
|
|
|
|
|
|
|
|
sfree(*realhost);
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 22:52:21 +04:00
|
|
|
*realhost = dupstr(loghost);
|
2014-01-25 19:58:54 +04:00
|
|
|
|
|
|
|
colon = host_strrchr(*realhost, ':');
|
|
|
|
if (colon)
|
2008-06-01 15:16:32 +04:00
|
|
|
*colon++ = '\0';
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_free(Backend *be)
|
2003-01-16 02:30:21 +03:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2003-01-16 02:30:21 +03:00
|
|
|
|
|
|
|
if (raw->s)
|
|
|
|
sk_close(raw->s);
|
2015-11-22 17:33:28 +03:00
|
|
|
conf_free(raw->conf);
|
2003-01-16 02:30:21 +03:00
|
|
|
sfree(raw);
|
|
|
|
}
|
|
|
|
|
2003-01-12 17:48:29 +03:00
|
|
|
/*
|
|
|
|
* Stub routine (we don't have any need to reconfigure this backend).
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_reconfig(Backend *be, Conf *conf)
|
2003-01-12 17:48:29 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
|
|
|
* Called to send data down the raw connection.
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_send(Backend *be, const char *buf, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2002-10-25 15:30:33 +04:00
|
|
|
|
|
|
|
if (raw->s == NULL)
|
2001-08-27 19:55:44 +04:00
|
|
|
return 0;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
raw->bufsize = sk_write(raw->s, buf, len);
|
2001-08-25 21:09:23 +04:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
return raw->bufsize;
|
2001-08-25 21:09:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current socket sendability status.
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_sendbuffer(Backend *be)
|
2001-08-25 21:09:23 +04:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2002-10-25 15:30:33 +04:00
|
|
|
return raw->bufsize;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_size(Backend *be, int width, int height)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
1999-11-01 19:40:40 +03:00
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-09-13 15:44:03 +04:00
|
|
|
* Send raw special codes. We only handle outgoing EOF here.
|
1999-11-01 19:40:40 +03:00
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_special(Backend *be, Telnet_Special code)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2011-09-13 15:44:03 +04:00
|
|
|
if (code == TS_EOF && raw->s) {
|
|
|
|
sk_write_eof(raw->s);
|
|
|
|
raw->sent_socket_eof= TRUE;
|
|
|
|
raw_check_close(raw);
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-05 00:21:05 +04:00
|
|
|
/*
|
|
|
|
* Return a list of the special codes that make sense in this
|
|
|
|
* protocol.
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static const struct telnet_special *raw_get_specials(Backend *be)
|
2003-04-05 00:21:05 +04:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_connected(Backend *be)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2006-08-27 12:03:19 +04:00
|
|
|
return raw->s != NULL;
|
2001-05-06 18:35:20 +04:00
|
|
|
}
|
2000-09-08 20:42:11 +04:00
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_sendok(Backend *be)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2000-09-08 18:45:20 +04:00
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_unthrottle(Backend *be, int backlog)
|
2001-08-25 21:09:23 +04:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2002-10-25 15:30:33 +04:00
|
|
|
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
|
2001-08-25 21:09:23 +04:00
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_ldisc(Backend *be, int option)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2001-01-24 17:08:20 +03:00
|
|
|
if (option == LD_EDIT || option == LD_ECHO)
|
2001-05-06 18:35:20 +04:00
|
|
|
return 1;
|
2001-01-24 17:08:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_provide_ldisc(Backend *be, Ldisc *ldisc)
|
2002-10-26 14:16:19 +04:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static void raw_provide_logctx(Backend *be, LogContext *logctx)
|
2002-10-26 16:58:13 +04:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_exitcode(Backend *be)
|
2001-12-29 18:31:42 +03:00
|
|
|
{
|
2018-09-11 18:23:38 +03:00
|
|
|
Raw raw = FROMFIELD(be, struct raw_backend_data, backend);
|
2003-03-31 16:10:08 +04:00
|
|
|
if (raw->s != NULL)
|
|
|
|
return -1; /* still connected */
|
2012-12-22 13:40:47 +04:00
|
|
|
else if (raw->closed_on_socket_error)
|
|
|
|
return INT_MAX; /* a socket error counts as an unclean exit */
|
2003-03-31 16:10:08 +04:00
|
|
|
else
|
|
|
|
/* Exit codes are a meaningless concept in the Raw protocol */
|
|
|
|
return 0;
|
2001-12-29 18:31:42 +03:00
|
|
|
}
|
|
|
|
|
2004-12-29 15:32:25 +03:00
|
|
|
/*
|
|
|
|
* cfg_info for Raw does nothing at all.
|
|
|
|
*/
|
2018-09-11 18:23:38 +03:00
|
|
|
static int raw_cfg_info(Backend *be)
|
2004-12-29 15:32:25 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
const struct Backend_vtable raw_backend = {
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_init,
|
2003-01-16 02:30:21 +03:00
|
|
|
raw_free,
|
2003-01-12 17:48:29 +03:00
|
|
|
raw_reconfig,
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_send,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_sendbuffer,
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_size,
|
2000-09-08 18:45:20 +04:00
|
|
|
raw_special,
|
2003-04-05 00:21:05 +04:00
|
|
|
raw_get_specials,
|
2006-08-27 12:03:19 +04:00
|
|
|
raw_connected,
|
2001-12-29 18:31:42 +03:00
|
|
|
raw_exitcode,
|
2000-10-04 18:35:15 +04:00
|
|
|
raw_sendok,
|
2001-01-24 17:08:20 +03:00
|
|
|
raw_ldisc,
|
2002-10-26 14:16:19 +04:00
|
|
|
raw_provide_ldisc,
|
2002-10-26 16:58:13 +04:00
|
|
|
raw_provide_logctx,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_unthrottle,
|
2004-12-29 15:32:25 +03:00
|
|
|
raw_cfg_info,
|
2015-09-25 13:46:28 +03:00
|
|
|
NULL /* test_for_upstream */,
|
2007-07-01 01:56:44 +04:00
|
|
|
"raw",
|
|
|
|
PROT_RAW,
|
2007-07-01 19:47:31 +04:00
|
|
|
0
|
1999-11-01 19:40:40 +03:00
|
|
|
};
|