2006-08-28 14:29:02 +00:00
|
|
|
/*
|
|
|
|
* Serial back end (Unix-specific).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <termios.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
#include "tree234.h"
|
|
|
|
|
|
|
|
#define SERIAL_MAX_BACKLOG 4096
|
|
|
|
|
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
|
|
|
typedef struct Serial Serial;
|
|
|
|
struct Serial {
|
2018-09-12 08:10:51 +00:00
|
|
|
Frontend *frontend;
|
2006-08-28 14:29:02 +00:00
|
|
|
int fd;
|
|
|
|
int finished;
|
|
|
|
int inbufsize;
|
|
|
|
bufchain output_data;
|
2018-09-11 15:23:38 +00:00
|
|
|
Backend backend;
|
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
|
|
|
};
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We store our serial backends in a tree sorted by fd, so that
|
|
|
|
* when we get an uxsel notification we know which backend instance
|
|
|
|
* is the owner of the serial port that caused it.
|
|
|
|
*/
|
|
|
|
static int serial_compare_by_fd(void *av, void *bv)
|
|
|
|
{
|
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
|
|
|
Serial *a = (Serial *)av;
|
|
|
|
Serial *b = (Serial *)bv;
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
if (a->fd < b->fd)
|
|
|
|
return -1;
|
|
|
|
else if (a->fd > b->fd)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serial_find_by_fd(void *av, void *bv)
|
|
|
|
{
|
|
|
|
int a = *(int *)av;
|
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
|
|
|
Serial *b = (Serial *)bv;
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
if (a < b->fd)
|
|
|
|
return -1;
|
|
|
|
else if (a > b->fd)
|
|
|
|
return +1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static tree234 *serial_by_fd = NULL;
|
|
|
|
|
2016-05-30 21:52:30 +00:00
|
|
|
static void serial_select_result(int fd, int event);
|
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 serial_uxsel_setup(Serial *serial);
|
|
|
|
static void serial_try_write(Serial *serial);
|
2006-08-28 14:29:02 +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 *serial_configure(Serial *serial, Conf *conf)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
struct termios options;
|
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 18:52:21 +00:00
|
|
|
int bflag, bval, speed, flow, parity;
|
2006-08-28 14:29:02 +00:00
|
|
|
const char *str;
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
if (serial->fd < 0)
|
|
|
|
return "Unable to reconfigure already-closed serial connection";
|
|
|
|
|
|
|
|
tcgetattr(serial->fd, &options);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the appropriate baud rate flag.
|
|
|
|
*/
|
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 18:52:21 +00:00
|
|
|
speed = conf_get_int(conf, CONF_serspeed);
|
2006-08-28 14:29:02 +00:00
|
|
|
#define SETBAUD(x) (bflag = B ## x, bval = x)
|
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 18:52:21 +00:00
|
|
|
#define CHECKBAUD(x) do { if (speed >= x) SETBAUD(x); } while (0)
|
2006-08-28 14:29:02 +00:00
|
|
|
SETBAUD(50);
|
|
|
|
#ifdef B75
|
|
|
|
CHECKBAUD(75);
|
|
|
|
#endif
|
|
|
|
#ifdef B110
|
|
|
|
CHECKBAUD(110);
|
|
|
|
#endif
|
|
|
|
#ifdef B134
|
|
|
|
CHECKBAUD(134);
|
|
|
|
#endif
|
|
|
|
#ifdef B150
|
|
|
|
CHECKBAUD(150);
|
|
|
|
#endif
|
|
|
|
#ifdef B200
|
|
|
|
CHECKBAUD(200);
|
|
|
|
#endif
|
|
|
|
#ifdef B300
|
|
|
|
CHECKBAUD(300);
|
|
|
|
#endif
|
|
|
|
#ifdef B600
|
|
|
|
CHECKBAUD(600);
|
|
|
|
#endif
|
|
|
|
#ifdef B1200
|
|
|
|
CHECKBAUD(1200);
|
|
|
|
#endif
|
|
|
|
#ifdef B1800
|
|
|
|
CHECKBAUD(1800);
|
|
|
|
#endif
|
|
|
|
#ifdef B2400
|
|
|
|
CHECKBAUD(2400);
|
|
|
|
#endif
|
|
|
|
#ifdef B4800
|
|
|
|
CHECKBAUD(4800);
|
|
|
|
#endif
|
|
|
|
#ifdef B9600
|
|
|
|
CHECKBAUD(9600);
|
|
|
|
#endif
|
|
|
|
#ifdef B19200
|
|
|
|
CHECKBAUD(19200);
|
|
|
|
#endif
|
|
|
|
#ifdef B38400
|
|
|
|
CHECKBAUD(38400);
|
|
|
|
#endif
|
|
|
|
#ifdef B57600
|
|
|
|
CHECKBAUD(57600);
|
|
|
|
#endif
|
|
|
|
#ifdef B76800
|
|
|
|
CHECKBAUD(76800);
|
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
|
|
|
CHECKBAUD(115200);
|
|
|
|
#endif
|
2010-12-08 14:21:35 +00:00
|
|
|
#ifdef B153600
|
|
|
|
CHECKBAUD(153600);
|
|
|
|
#endif
|
2006-08-28 14:29:02 +00:00
|
|
|
#ifdef B230400
|
|
|
|
CHECKBAUD(230400);
|
|
|
|
#endif
|
2010-12-08 14:21:35 +00:00
|
|
|
#ifdef B307200
|
|
|
|
CHECKBAUD(307200);
|
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
|
|
|
CHECKBAUD(460800);
|
|
|
|
#endif
|
|
|
|
#ifdef B500000
|
|
|
|
CHECKBAUD(500000);
|
|
|
|
#endif
|
|
|
|
#ifdef B576000
|
|
|
|
CHECKBAUD(576000);
|
|
|
|
#endif
|
|
|
|
#ifdef B921600
|
|
|
|
CHECKBAUD(921600);
|
|
|
|
#endif
|
|
|
|
#ifdef B1000000
|
|
|
|
CHECKBAUD(1000000);
|
|
|
|
#endif
|
|
|
|
#ifdef B1152000
|
|
|
|
CHECKBAUD(1152000);
|
|
|
|
#endif
|
|
|
|
#ifdef B1500000
|
|
|
|
CHECKBAUD(1500000);
|
|
|
|
#endif
|
|
|
|
#ifdef B2000000
|
|
|
|
CHECKBAUD(2000000);
|
|
|
|
#endif
|
|
|
|
#ifdef B2500000
|
|
|
|
CHECKBAUD(2500000);
|
|
|
|
#endif
|
|
|
|
#ifdef B3000000
|
|
|
|
CHECKBAUD(3000000);
|
|
|
|
#endif
|
|
|
|
#ifdef B3500000
|
|
|
|
CHECKBAUD(3500000);
|
|
|
|
#endif
|
|
|
|
#ifdef B4000000
|
|
|
|
CHECKBAUD(4000000);
|
|
|
|
#endif
|
2006-08-28 14:29:02 +00:00
|
|
|
#undef CHECKBAUD
|
|
|
|
#undef SETBAUD
|
|
|
|
cfsetispeed(&options, bflag);
|
|
|
|
cfsetospeed(&options, bflag);
|
|
|
|
msg = dupprintf("Configuring baud rate %d", bval);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
|
|
|
options.c_cflag &= ~CSIZE;
|
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 18:52:21 +00:00
|
|
|
switch (conf_get_int(conf, CONF_serdatabits)) {
|
2006-08-28 14:29:02 +00:00
|
|
|
case 5: options.c_cflag |= CS5; break;
|
|
|
|
case 6: options.c_cflag |= CS6; break;
|
|
|
|
case 7: options.c_cflag |= CS7; break;
|
|
|
|
case 8: options.c_cflag |= CS8; break;
|
|
|
|
default: return "Invalid number of data bits (need 5, 6, 7 or 8)";
|
|
|
|
}
|
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 18:52:21 +00:00
|
|
|
msg = dupprintf("Configuring %d data bits",
|
|
|
|
conf_get_int(conf, CONF_serdatabits));
|
2006-08-28 14:29:02 +00:00
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
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 18:52:21 +00:00
|
|
|
if (conf_get_int(conf, CONF_serstopbits) >= 4) {
|
2006-08-28 14:29:02 +00:00
|
|
|
options.c_cflag |= CSTOPB;
|
|
|
|
} else {
|
|
|
|
options.c_cflag &= ~CSTOPB;
|
|
|
|
}
|
|
|
|
msg = dupprintf("Configuring %d stop bits",
|
|
|
|
(options.c_cflag & CSTOPB ? 2 : 1));
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
2006-10-02 20:52:57 +00:00
|
|
|
options.c_iflag &= ~(IXON|IXOFF);
|
|
|
|
#ifdef CRTSCTS
|
|
|
|
options.c_cflag &= ~CRTSCTS;
|
|
|
|
#endif
|
|
|
|
#ifdef CNEW_RTSCTS
|
|
|
|
options.c_cflag &= ~CNEW_RTSCTS;
|
|
|
|
#endif
|
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 18:52:21 +00:00
|
|
|
flow = conf_get_int(conf, CONF_serflow);
|
|
|
|
if (flow == SER_FLOW_XONXOFF) {
|
2006-10-02 20:52:57 +00:00
|
|
|
options.c_iflag |= IXON | IXOFF;
|
2006-08-28 14:29:02 +00:00
|
|
|
str = "XON/XOFF";
|
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 18:52:21 +00:00
|
|
|
} else if (flow == SER_FLOW_RTSCTS) {
|
2006-08-28 14:29:02 +00:00
|
|
|
#ifdef CRTSCTS
|
|
|
|
options.c_cflag |= CRTSCTS;
|
|
|
|
#endif
|
|
|
|
#ifdef CNEW_RTSCTS
|
|
|
|
options.c_cflag |= CNEW_RTSCTS;
|
|
|
|
#endif
|
|
|
|
str = "RTS/CTS";
|
|
|
|
} else
|
|
|
|
str = "no";
|
|
|
|
msg = dupprintf("Configuring %s flow control", str);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
|
|
|
/* Parity */
|
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 18:52:21 +00:00
|
|
|
parity = conf_get_int(conf, CONF_serparity);
|
|
|
|
if (parity == SER_PAR_ODD) {
|
2006-08-28 14:29:02 +00:00
|
|
|
options.c_cflag |= PARENB;
|
|
|
|
options.c_cflag |= PARODD;
|
|
|
|
str = "odd";
|
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 18:52:21 +00:00
|
|
|
} else if (parity == SER_PAR_EVEN) {
|
2006-08-28 14:29:02 +00:00
|
|
|
options.c_cflag |= PARENB;
|
|
|
|
options.c_cflag &= ~PARODD;
|
|
|
|
str = "even";
|
|
|
|
} else {
|
|
|
|
options.c_cflag &= ~PARENB;
|
|
|
|
str = "no";
|
|
|
|
}
|
|
|
|
msg = dupprintf("Configuring %s parity", str);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
|
|
|
options.c_cflag |= CLOCAL | CREAD;
|
|
|
|
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
2006-10-03 17:16:26 +00:00
|
|
|
options.c_iflag &= ~(ISTRIP | IGNCR | INLCR | ICRNL
|
|
|
|
#ifdef IUCLC
|
|
|
|
| IUCLC
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
options.c_oflag &= ~(OPOST
|
|
|
|
#ifdef ONLCR
|
|
|
|
| ONLCR
|
|
|
|
#endif
|
2007-01-16 19:26:24 +00:00
|
|
|
#ifdef OCRNL
|
|
|
|
| OCRNL
|
|
|
|
#endif
|
|
|
|
#ifdef ONOCR
|
|
|
|
| ONOCR
|
|
|
|
#endif
|
|
|
|
#ifdef ONLRET
|
|
|
|
| ONLRET
|
|
|
|
#endif
|
|
|
|
);
|
2006-08-28 14:29:02 +00:00
|
|
|
options.c_cc[VMIN] = 1;
|
|
|
|
options.c_cc[VTIME] = 0;
|
|
|
|
|
|
|
|
if (tcsetattr(serial->fd, TCSANOW, &options) < 0)
|
|
|
|
return "Unable to configure serial port";
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set up the serial connection.
|
|
|
|
*
|
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
2018-09-12 08:10:51 +00:00
|
|
|
static const char *serial_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 18:52:21 +00:00
|
|
|
Conf *conf,
|
2015-05-15 10:15:42 +00:00
|
|
|
const char *host, int port, char **realhost,
|
|
|
|
int nodelay, int keepalive)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial;
|
2006-08-28 14:29:02 +00:00
|
|
|
const char *err;
|
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 18:52:21 +00:00
|
|
|
char *line;
|
2006-08-28 14:29:02 +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
|
|
|
serial = snew(Serial);
|
2018-09-11 15:23:38 +00:00
|
|
|
serial->backend.vt = &serial_backend;
|
|
|
|
*backend_handle = &serial->backend;
|
2006-08-28 14:29:02 +00:00
|
|
|
|
2018-09-12 08:10:51 +00:00
|
|
|
serial->frontend = frontend;
|
2006-08-28 14:29:02 +00:00
|
|
|
serial->finished = FALSE;
|
|
|
|
serial->inbufsize = 0;
|
|
|
|
bufchain_init(&serial->output_data);
|
|
|
|
|
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 18:52:21 +00:00
|
|
|
line = conf_get_str(conf, CONF_serline);
|
2006-08-28 14:29:02 +00: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 18:52:21 +00:00
|
|
|
char *msg = dupprintf("Opening serial device %s", line);
|
2006-08-28 14:29:02 +00:00
|
|
|
logevent(serial->frontend, msg);
|
2013-07-14 10:46:07 +00:00
|
|
|
sfree(msg);
|
2006-08-28 14:29:02 +00: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 18:52:21 +00:00
|
|
|
serial->fd = open(line, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
2006-08-28 14:29:02 +00:00
|
|
|
if (serial->fd < 0)
|
|
|
|
return "Unable to open serial port";
|
|
|
|
|
2006-12-09 15:44:31 +00:00
|
|
|
cloexec(serial->fd);
|
2006-11-23 14:32:11 +00: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 18:52:21 +00:00
|
|
|
err = serial_configure(serial, conf);
|
2006-08-28 14:29:02 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
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 18:52:21 +00:00
|
|
|
*realhost = dupstr(line);
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
if (!serial_by_fd)
|
|
|
|
serial_by_fd = newtree234(serial_compare_by_fd);
|
|
|
|
add234(serial_by_fd, serial);
|
|
|
|
|
|
|
|
serial_uxsel_setup(serial);
|
|
|
|
|
2006-08-29 18:20:57 +00:00
|
|
|
/*
|
|
|
|
* Specials are always available.
|
|
|
|
*/
|
|
|
|
update_specials_menu(serial->frontend);
|
|
|
|
|
2006-08-28 14:29:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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 serial_close(Serial *serial)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
if (serial->fd >= 0) {
|
|
|
|
close(serial->fd);
|
|
|
|
serial->fd = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_free(Backend *be)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
serial_close(serial);
|
|
|
|
|
|
|
|
bufchain_clear(&serial->output_data);
|
|
|
|
|
|
|
|
sfree(serial);
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_reconfig(Backend *be, Conf *conf)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
/*
|
2011-05-07 10:57:19 +00:00
|
|
|
* FIXME: what should we do if this returns an error?
|
2006-08-28 14:29:02 +00: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 18:52:21 +00:00
|
|
|
serial_configure(serial, conf);
|
2006-08-28 14:29:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 21:52:30 +00:00
|
|
|
static void serial_select_result(int fd, int event)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial;
|
2006-08-28 14:29:02 +00:00
|
|
|
char buf[4096];
|
|
|
|
int ret;
|
|
|
|
int finished = FALSE;
|
|
|
|
|
|
|
|
serial = find234(serial_by_fd, &fd, serial_find_by_fd);
|
|
|
|
|
|
|
|
if (!serial)
|
2016-05-30 21:52:30 +00:00
|
|
|
return; /* spurious event; keep going */
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
if (event == 1) {
|
|
|
|
ret = read(serial->fd, buf, sizeof(buf));
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
/*
|
|
|
|
* Shouldn't happen on a real serial port, but I'm open
|
|
|
|
* to the idea that there might be two-way devices we
|
|
|
|
* can treat _like_ serial ports which can return EOF.
|
|
|
|
*/
|
|
|
|
finished = TRUE;
|
|
|
|
} else if (ret < 0) {
|
2010-11-06 17:22:38 +00:00
|
|
|
#ifdef EAGAIN
|
|
|
|
if (errno == EAGAIN)
|
2016-05-30 21:52:30 +00:00
|
|
|
return; /* spurious */
|
2010-11-06 17:22:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef EWOULDBLOCK
|
|
|
|
if (errno == EWOULDBLOCK)
|
2016-05-30 21:52:30 +00:00
|
|
|
return; /* spurious */
|
2010-11-06 17:22:38 +00:00
|
|
|
#endif
|
2006-08-28 14:29:02 +00:00
|
|
|
perror("read serial port");
|
|
|
|
exit(1);
|
|
|
|
} else if (ret > 0) {
|
|
|
|
serial->inbufsize = from_backend(serial->frontend, 0, buf, ret);
|
|
|
|
serial_uxsel_setup(serial); /* might acquire backlog and freeze */
|
|
|
|
}
|
|
|
|
} else if (event == 2) {
|
|
|
|
/*
|
|
|
|
* Attempt to send data down the pty.
|
|
|
|
*/
|
|
|
|
serial_try_write(serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (finished) {
|
|
|
|
serial_close(serial);
|
|
|
|
|
|
|
|
serial->finished = TRUE;
|
|
|
|
|
|
|
|
notify_remote_exit(serial->frontend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 serial_uxsel_setup(Serial *serial)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
int rwx = 0;
|
|
|
|
|
|
|
|
if (serial->inbufsize <= SERIAL_MAX_BACKLOG)
|
|
|
|
rwx |= 1;
|
|
|
|
if (bufchain_size(&serial->output_data))
|
|
|
|
rwx |= 2; /* might also want to write to it */
|
|
|
|
uxsel_set(serial->fd, rwx, serial_select_result);
|
|
|
|
}
|
|
|
|
|
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 serial_try_write(Serial *serial)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
int len, ret;
|
|
|
|
|
|
|
|
assert(serial->fd >= 0);
|
|
|
|
|
|
|
|
while (bufchain_size(&serial->output_data) > 0) {
|
|
|
|
bufchain_prefix(&serial->output_data, &data, &len);
|
|
|
|
ret = write(serial->fd, data, len);
|
|
|
|
|
|
|
|
if (ret < 0 && (errno == EWOULDBLOCK)) {
|
|
|
|
/*
|
|
|
|
* We've sent all we can for the moment.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret < 0) {
|
|
|
|
perror("write serial port");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
bufchain_consume(&serial->output_data, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
serial_uxsel_setup(serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to send data down the serial connection.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_send(Backend *be, const char *buf, int len)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
|
|
|
|
if (serial->fd < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bufchain_add(&serial->output_data, buf, len);
|
|
|
|
serial_try_write(serial);
|
|
|
|
|
|
|
|
return bufchain_size(&serial->output_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current sendability status.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_sendbuffer(Backend *be)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
return bufchain_size(&serial->output_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_size(Backend *be, int width, int height)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send serial special codes.
|
|
|
|
*/
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static void serial_special(Backend *be, SessionSpecialCode code, int arg)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-29 18:20:57 +00:00
|
|
|
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
if (serial->fd >= 0 && code == SS_BRK) {
|
2006-08-29 18:20:57 +00:00
|
|
|
tcsendbreak(serial->fd, 0);
|
|
|
|
logevent(serial->frontend, "Sending serial break at user request");
|
|
|
|
}
|
|
|
|
|
2006-08-28 14:29:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a list of the special codes that make sense in this
|
|
|
|
* protocol.
|
|
|
|
*/
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static const SessionSpecial *serial_get_specials(Backend *be)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static const struct SessionSpecial specials[] = {
|
|
|
|
{"Break", SS_BRK},
|
|
|
|
{NULL, SS_EXITMENU}
|
2006-08-29 18:20:57 +00:00
|
|
|
};
|
|
|
|
return specials;
|
2006-08-28 14:29:02 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_connected(Backend *be)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
return 1; /* always connected */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_sendok(Backend *be)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_unthrottle(Backend *be, int backlog)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
serial->inbufsize = backlog;
|
|
|
|
serial_uxsel_setup(serial);
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_ldisc(Backend *be, int option)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Local editing and local echo are off by default.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_provide_ldisc(Backend *be, Ldisc *ldisc)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_provide_logctx(Backend *be, LogContext *logctx)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_exitcode(Backend *be)
|
2006-08-28 14:29:02 +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
|
|
|
Serial *serial = FROMFIELD(be, Serial, backend);
|
2006-08-28 14:29:02 +00:00
|
|
|
if (serial->fd >= 0)
|
|
|
|
return -1; /* still connected */
|
|
|
|
else
|
|
|
|
/* Exit codes are a meaningless concept with serial ports */
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cfg_info for Serial does nothing at all.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_cfg_info(Backend *be)
|
2006-08-28 14:29:02 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-05 06:03:46 +00:00
|
|
|
const struct BackendVtable serial_backend = {
|
2006-08-28 14:29:02 +00:00
|
|
|
serial_init,
|
|
|
|
serial_free,
|
|
|
|
serial_reconfig,
|
|
|
|
serial_send,
|
|
|
|
serial_sendbuffer,
|
|
|
|
serial_size,
|
|
|
|
serial_special,
|
|
|
|
serial_get_specials,
|
|
|
|
serial_connected,
|
|
|
|
serial_exitcode,
|
|
|
|
serial_sendok,
|
|
|
|
serial_ldisc,
|
|
|
|
serial_provide_ldisc,
|
|
|
|
serial_provide_logctx,
|
|
|
|
serial_unthrottle,
|
|
|
|
serial_cfg_info,
|
2015-09-25 10:46:28 +00:00
|
|
|
NULL /* test_for_upstream */,
|
2007-06-30 21:56:44 +00:00
|
|
|
"serial",
|
|
|
|
PROT_SERIAL,
|
2007-07-01 15:47:31 +00:00
|
|
|
0
|
2006-08-28 14:29:02 +00:00
|
|
|
};
|