2018-05-24 10:59:01 +03:00
|
|
|
/*
|
|
|
|
* defs.h: initial definitions for PuTTY.
|
|
|
|
*
|
|
|
|
* The rule about this header file is that it can't depend on any
|
|
|
|
* other header file in this code base. This is where we define
|
|
|
|
* things, as much as we can, that other headers will want to refer
|
|
|
|
* to, such as opaque structure types and their associated typedefs,
|
|
|
|
* or macros that are used by other headers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PUTTY_DEFS_H
|
|
|
|
#define PUTTY_DEFS_H
|
|
|
|
|
2018-05-27 18:56:51 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-05-26 09:19:18 +03:00
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
2018-05-24 10:59:01 +03:00
|
|
|
typedef struct conf_tag Conf;
|
|
|
|
typedef struct terminal_tag Terminal;
|
|
|
|
|
|
|
|
typedef struct Filename Filename;
|
|
|
|
typedef struct FontSpec FontSpec;
|
|
|
|
|
|
|
|
typedef struct bufchain_tag bufchain;
|
|
|
|
|
|
|
|
typedef struct strbuf strbuf;
|
|
|
|
|
|
|
|
struct RSAKey;
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef uint32_t uint32;
|
|
|
|
|
2018-05-24 11:17:13 +03:00
|
|
|
typedef struct BinarySink BinarySink;
|
Introduce a centralised unmarshaller, 'BinarySource'.
This is the companion to the BinarySink system I introduced a couple
of weeks ago, and provides the same type-genericity which will let me
use the same get_* routines on an SSH packet, an SFTP packet or
anything else that chooses to include an implementing substructure.
However, unlike BinarySink which contained a (one-function) vtable,
BinarySource contains only mutable data fields - so another thing you
might very well want to do is to simply instantiate a bare one without
any containing object at all. I couldn't quite coerce C into letting
me use the same setup macro in both cases, so I've arranged a
BinarySource_INIT you can use on larger implementing objects and a
BinarySource_BARE_INIT you can use on a BinarySource not contained in
anything.
The API follows the general principle that even if decoding fails, the
decode functions will always return _some_ kind of value, with the
same dynamically-allocated-ness they would have used for a completely
successful value. But they also set an error flag in the BinarySource
which can be tested later. So instead of having to decode a 10-field
packet by means of 10 separate 'if (!get_foo(src)) throw error'
clauses, you can just write 10 'variable = get_foo(src)' statements
followed by a single check of get_err(src), and if the error check
fails, you have to do exactly the same set of frees you would have
after a successful decode.
2018-06-02 10:25:19 +03:00
|
|
|
typedef struct BinarySource BinarySource;
|
2018-05-24 11:17:13 +03:00
|
|
|
|
2018-05-27 11:29:33 +03:00
|
|
|
typedef struct SockAddr_tag *SockAddr;
|
|
|
|
|
|
|
|
typedef struct Socket_vtable Socket_vtable;
|
|
|
|
typedef struct Plug_vtable Plug_vtable;
|
|
|
|
|
2018-09-11 18:23:38 +03:00
|
|
|
typedef struct Backend Backend;
|
|
|
|
typedef struct Backend_vtable Backend_vtable;
|
|
|
|
|
2018-09-11 17:02:59 +03:00
|
|
|
typedef struct Ldisc_tag Ldisc;
|
2018-09-11 17:17:16 +03:00
|
|
|
typedef struct LogContext_tag LogContext;
|
2018-09-11 17:02:59 +03:00
|
|
|
|
2018-09-12 11:10:51 +03:00
|
|
|
typedef struct Frontend Frontend;
|
|
|
|
|
2018-09-11 17:33:10 +03:00
|
|
|
typedef struct ssh_tag *Ssh;
|
2018-09-11 18:23:38 +03:00
|
|
|
|
Replace enum+union of local channel types with a vtable.
There's now an interface called 'Channel', which handles the local
side of an SSH connection-layer channel, in terms of knowing where to
send incoming channel data to, whether to close the channel, etc.
Channel and the previous 'struct ssh_channel' mutually refer. The
latter contains all the SSH-specific parts, and as much of the common
logic as possible: in particular, Channel doesn't have to know
anything about SSH packet formats, or which SSH protocol version is in
use, or deal with all the fiddly stuff about window sizes - with the
exception that x11fwd.c's implementation of it does have to be able to
ask for a small fixed initial window size for the bodgy system that
distinguishes upstream from downstream X forwardings.
I've taken the opportunity to move the code implementing the detailed
behaviour of agent forwarding out of ssh.c, now that all of it is on
the far side of a uniform interface. (This also means that if I later
implement agent forwarding directly to a Unix socket as an
alternative, it'll be a matter of changing just the one call to
agentf_new() that makes the Channel to plug into a forwarding.)
2018-09-12 17:03:47 +03:00
|
|
|
typedef struct Channel Channel;
|
2018-09-14 15:47:13 +03:00
|
|
|
typedef struct SshChannel SshChannel;
|
Replace enum+union of local channel types with a vtable.
There's now an interface called 'Channel', which handles the local
side of an SSH connection-layer channel, in terms of knowing where to
send incoming channel data to, whether to close the channel, etc.
Channel and the previous 'struct ssh_channel' mutually refer. The
latter contains all the SSH-specific parts, and as much of the common
logic as possible: in particular, Channel doesn't have to know
anything about SSH packet formats, or which SSH protocol version is in
use, or deal with all the fiddly stuff about window sizes - with the
exception that x11fwd.c's implementation of it does have to be able to
ask for a small fixed initial window size for the bodgy system that
distinguishes upstream from downstream X forwardings.
I've taken the opportunity to move the code implementing the detailed
behaviour of agent forwarding out of ssh.c, now that all of it is on
the far side of a uniform interface. (This also means that if I later
implement agent forwarding directly to a Unix socket as an
alternative, it'll be a matter of changing just the one call to
agentf_new() that makes the Channel to plug into a forwarding.)
2018-09-12 17:03:47 +03:00
|
|
|
|
2018-09-13 11:09:10 +03:00
|
|
|
typedef struct ssh_sharing_state ssh_sharing_state;
|
|
|
|
typedef struct ssh_sharing_connstate ssh_sharing_connstate;
|
|
|
|
typedef struct share_channel share_channel;
|
|
|
|
|
2018-09-14 19:04:39 +03:00
|
|
|
typedef struct PortFwdManager PortFwdManager;
|
|
|
|
typedef struct PortFwdRecord PortFwdRecord;
|
|
|
|
|
2018-09-13 14:58:44 +03:00
|
|
|
typedef struct dlgparam dlgparam;
|
|
|
|
|
2018-09-14 10:45:42 +03:00
|
|
|
typedef struct settings_w settings_w;
|
|
|
|
typedef struct settings_r settings_r;
|
|
|
|
typedef struct settings_e settings_e;
|
|
|
|
|
2018-05-27 11:29:33 +03:00
|
|
|
/* Note indirection: for historical reasons (it used to be closer to
|
|
|
|
* the OS socket type), the type that most code uses for a socket is
|
|
|
|
* 'Socket', not 'Socket *'. So an implementation of Socket or Plug
|
|
|
|
* has a 'const Socket *' field for the vtable pointer, and the
|
|
|
|
* 'Socket' type returned to client code is a pointer to _that_ in
|
|
|
|
* turn. */
|
|
|
|
typedef const Socket_vtable **Socket;
|
|
|
|
typedef const Plug_vtable **Plug;
|
|
|
|
|
2018-05-27 18:56:51 +03:00
|
|
|
/*
|
|
|
|
* A small structure wrapping up a (pointer, length) pair so that it
|
|
|
|
* can be conveniently passed to or from a function.
|
|
|
|
*/
|
|
|
|
typedef struct ptrlen {
|
|
|
|
const void *ptr;
|
|
|
|
size_t len;
|
|
|
|
} ptrlen;
|
|
|
|
|
2018-06-09 11:00:11 +03:00
|
|
|
typedef struct logblank_t logblank_t;
|
|
|
|
|
2018-05-24 10:59:01 +03:00
|
|
|
/* Do a compile-time type-check of 'to_check' (without evaluating it),
|
|
|
|
* as a side effect of returning the value 'to_return'. Note that
|
|
|
|
* although this macro double-*expands* to_return, it always
|
|
|
|
* *evaluates* exactly one copy of it, so it's side-effect safe. */
|
|
|
|
#define TYPECHECK(to_check, to_return) \
|
|
|
|
(sizeof(to_check) ? (to_return) : (to_return))
|
|
|
|
|
2018-05-24 16:55:10 +03:00
|
|
|
/* Return a pointer to the object of structure type 'type' whose field
|
|
|
|
* with name 'field' is pointed at by 'object'. */
|
|
|
|
#define FROMFIELD(object, type, field) \
|
|
|
|
TYPECHECK(object == &((type *)0)->field, \
|
|
|
|
((type *)(((char *)(object)) - offsetof(type, field))))
|
|
|
|
|
2018-05-24 10:59:01 +03:00
|
|
|
#endif /* PUTTY_DEFS_H */
|