mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-17 02:57:33 -05:00
Replace method-dispatch #defines with inline functions.
This replaces all the macros like ssh_key_sign() and win_draw_text() which take an object containing a vtable pointer and do the dereferencing to find the actual concrete method to call. Now they're all inline functions, which means more sensible type-checking and more comprehensible error reports when the types go wrong, and also means that there's no risk of double-evaluating the object argument.
This commit is contained in:
188
sshchan.h
188
sshchan.h
@ -62,43 +62,57 @@ struct Channel {
|
||||
unsigned initial_fixed_window_size;
|
||||
};
|
||||
|
||||
#define chan_free(ch) ((ch)->vt->free(ch))
|
||||
#define chan_open_confirmation(ch) ((ch)->vt->open_confirmation(ch))
|
||||
#define chan_open_failed(ch, err) ((ch)->vt->open_failed(ch, err))
|
||||
#define chan_send(ch, err, buf, len) ((ch)->vt->send(ch, err, buf, len))
|
||||
#define chan_send_eof(ch) ((ch)->vt->send_eof(ch))
|
||||
#define chan_set_input_wanted(ch, wanted) \
|
||||
((ch)->vt->set_input_wanted(ch, wanted))
|
||||
#define chan_log_close_msg(ch) ((ch)->vt->log_close_msg(ch))
|
||||
#define chan_want_close(ch, leof, reof) ((ch)->vt->want_close(ch, leof, reof))
|
||||
#define chan_rcvd_exit_status(ch, status) \
|
||||
((ch)->vt->rcvd_exit_status(ch, status))
|
||||
#define chan_rcvd_exit_signal(ch, sig, core, msg) \
|
||||
((ch)->vt->rcvd_exit_signal(ch, sig, core, msg))
|
||||
#define chan_rcvd_exit_signal_numeric(ch, sig, core, msg) \
|
||||
((ch)->vt->rcvd_exit_signal_numeric(ch, sig, core, msg))
|
||||
#define chan_run_shell(ch) \
|
||||
((ch)->vt->run_shell(ch))
|
||||
#define chan_run_command(ch, cmd) \
|
||||
((ch)->vt->run_command(ch, cmd))
|
||||
#define chan_run_subsystem(ch, subsys) \
|
||||
((ch)->vt->run_subsystem(ch, subsys))
|
||||
#define chan_enable_x11_forwarding(ch, oneshot, ap, ad, scr) \
|
||||
((ch)->vt->enable_x11_forwarding(ch, oneshot, ap, ad, scr))
|
||||
#define chan_enable_agent_forwarding(ch) \
|
||||
((ch)->vt->enable_agent_forwarding(ch))
|
||||
#define chan_allocate_pty(ch, termtype, w, h, pw, ph, modes) \
|
||||
((ch)->vt->allocate_pty(ch, termtype, w, h, pw, ph, modes))
|
||||
#define chan_set_env(ch, var, value) \
|
||||
((ch)->vt->set_env(ch, var, value))
|
||||
#define chan_send_break(ch, length) \
|
||||
((ch)->vt->send_break(ch, length))
|
||||
#define chan_send_signal(ch, signame) \
|
||||
((ch)->vt->send_signal(ch, signame))
|
||||
#define chan_change_window_size(ch, w, h, pw, ph) \
|
||||
((ch)->vt->change_window_size(ch, w, h, pw, ph))
|
||||
#define chan_request_response(ch, success) \
|
||||
((ch)->vt->request_response(ch, success))
|
||||
static inline void chan_free(Channel *ch)
|
||||
{ ch->vt->free(ch); }
|
||||
static inline void chan_open_confirmation(Channel *ch)
|
||||
{ ch->vt->open_confirmation(ch); }
|
||||
static inline void chan_open_failed(Channel *ch, const char *err)
|
||||
{ ch->vt->open_failed(ch, err); }
|
||||
static inline size_t chan_send(
|
||||
Channel *ch, bool err, const void *buf, size_t len)
|
||||
{ return ch->vt->send(ch, err, buf, len); }
|
||||
static inline void chan_send_eof(Channel *ch)
|
||||
{ ch->vt->send_eof(ch); }
|
||||
static inline void chan_set_input_wanted(Channel *ch, bool wanted)
|
||||
{ ch->vt->set_input_wanted(ch, wanted); }
|
||||
static inline char *chan_log_close_msg(Channel *ch)
|
||||
{ return ch->vt->log_close_msg(ch); }
|
||||
static inline bool chan_want_close(Channel *ch, bool leof, bool reof)
|
||||
{ return ch->vt->want_close(ch, leof, reof); }
|
||||
static inline bool chan_rcvd_exit_status(Channel *ch, int status)
|
||||
{ return ch->vt->rcvd_exit_status(ch, status); }
|
||||
static inline bool chan_rcvd_exit_signal(
|
||||
Channel *ch, ptrlen sig, bool core, ptrlen msg)
|
||||
{ return ch->vt->rcvd_exit_signal(ch, sig, core, msg); }
|
||||
static inline bool chan_rcvd_exit_signal_numeric(
|
||||
Channel *ch, int sig, bool core, ptrlen msg)
|
||||
{ return ch->vt->rcvd_exit_signal_numeric(ch, sig, core, msg); }
|
||||
static inline bool chan_run_shell(Channel *ch)
|
||||
{ return ch->vt->run_shell(ch); }
|
||||
static inline bool chan_run_command(Channel *ch, ptrlen cmd)
|
||||
{ return ch->vt->run_command(ch, cmd); }
|
||||
static inline bool chan_run_subsystem(Channel *ch, ptrlen subsys)
|
||||
{ return ch->vt->run_subsystem(ch, subsys); }
|
||||
static inline bool chan_enable_x11_forwarding(
|
||||
Channel *ch, bool oneshot, ptrlen ap, ptrlen ad, unsigned scr)
|
||||
{ return ch->vt->enable_x11_forwarding(ch, oneshot, ap, ad, scr); }
|
||||
static inline bool chan_enable_agent_forwarding(Channel *ch)
|
||||
{ return ch->vt->enable_agent_forwarding(ch); }
|
||||
static inline bool chan_allocate_pty(
|
||||
Channel *ch, ptrlen termtype, unsigned w, unsigned h,
|
||||
unsigned pw, unsigned ph, struct ssh_ttymodes modes)
|
||||
{ return ch->vt->allocate_pty(ch, termtype, w, h, pw, ph, modes); }
|
||||
static inline bool chan_set_env(Channel *ch, ptrlen var, ptrlen value)
|
||||
{ return ch->vt->set_env(ch, var, value); }
|
||||
static inline bool chan_send_break(Channel *ch, unsigned length)
|
||||
{ return ch->vt->send_break(ch, length); }
|
||||
static inline bool chan_send_signal(Channel *ch, ptrlen signame)
|
||||
{ return ch->vt->send_signal(ch, signame); }
|
||||
static inline bool chan_change_window_size(
|
||||
Channel *ch, unsigned w, unsigned h, unsigned pw, unsigned ph)
|
||||
{ return ch->vt->change_window_size(ch, w, h, pw, ph); }
|
||||
static inline void chan_request_response(Channel *ch, bool success)
|
||||
{ ch->vt->request_response(ch, success); }
|
||||
|
||||
/*
|
||||
* Reusable methods you can put in vtables to give default handling of
|
||||
@ -217,44 +231,68 @@ struct SshChannel {
|
||||
ConnectionLayer *cl;
|
||||
};
|
||||
|
||||
#define sshfwd_write(c, buf, len) ((c)->vt->write(c, false, buf, len))
|
||||
#define sshfwd_write_ext(c, stderr, buf, len) \
|
||||
((c)->vt->write(c, stderr, buf, len))
|
||||
#define sshfwd_write_eof(c) ((c)->vt->write_eof(c))
|
||||
#define sshfwd_initiate_close(c, err) ((c)->vt->initiate_close(c, err))
|
||||
#define sshfwd_unthrottle(c, bufsize) ((c)->vt->unthrottle(c, bufsize))
|
||||
#define sshfwd_get_conf(c) ((c)->vt->get_conf(c))
|
||||
#define sshfwd_window_override_removed(c) ((c)->vt->window_override_removed(c))
|
||||
#define sshfwd_x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l) \
|
||||
((c)->vt->x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l))
|
||||
#define sshfwd_send_exit_status(c, status) \
|
||||
((c)->vt->send_exit_status(c, status))
|
||||
#define sshfwd_send_exit_signal(c, sig, core, msg) \
|
||||
((c)->vt->send_exit_signal(c, sig, core, msg))
|
||||
#define sshfwd_send_exit_signal_numeric(c, sig, core, msg) \
|
||||
((c)->vt->send_exit_signal_numeric(c, sig, core, msg))
|
||||
#define sshfwd_request_x11_forwarding(c, wr, ap, ad, scr, oneshot) \
|
||||
((c)->vt->request_x11_forwarding(c, wr, ap, ad, scr, oneshot))
|
||||
#define sshfwd_request_agent_forwarding(c, wr) \
|
||||
((c)->vt->request_agent_forwarding(c, wr))
|
||||
#define sshfwd_request_pty(c, wr, conf, w, h) \
|
||||
((c)->vt->request_pty(c, wr, conf, w, h))
|
||||
#define sshfwd_send_env_var(c, wr, var, value) \
|
||||
((c)->vt->send_env_var(c, wr, var, value))
|
||||
#define sshfwd_start_shell(c, wr) \
|
||||
((c)->vt->start_shell(c, wr))
|
||||
#define sshfwd_start_command(c, wr, cmd) \
|
||||
((c)->vt->start_command(c, wr, cmd))
|
||||
#define sshfwd_start_subsystem(c, wr, subsys) \
|
||||
((c)->vt->start_subsystem(c, wr, subsys))
|
||||
#define sshfwd_send_serial_break(c, wr, length) \
|
||||
((c)->vt->send_serial_break(c, wr, length))
|
||||
#define sshfwd_send_signal(c, wr, sig) \
|
||||
((c)->vt->send_signal(c, wr, sig))
|
||||
#define sshfwd_send_terminal_size_change(c, w, h) \
|
||||
((c)->vt->send_terminal_size_change(c, w, h))
|
||||
#define sshfwd_hint_channel_is_simple(c) \
|
||||
((c)->vt->hint_channel_is_simple(c))
|
||||
static inline size_t sshfwd_write_ext(
|
||||
SshChannel *c, bool is_stderr, const void *data, size_t len)
|
||||
{ return c->vt->write(c, is_stderr, data, len); }
|
||||
static inline size_t sshfwd_write(SshChannel *c, const void *data, size_t len)
|
||||
{ return sshfwd_write_ext(c, false, data, len); }
|
||||
static inline void sshfwd_write_eof(SshChannel *c)
|
||||
{ c->vt->write_eof(c); }
|
||||
static inline void sshfwd_initiate_close(SshChannel *c, const char *err)
|
||||
{ c->vt->initiate_close(c, err); }
|
||||
static inline void sshfwd_unthrottle(SshChannel *c, size_t bufsize)
|
||||
{ c->vt->unthrottle(c, bufsize); }
|
||||
static inline Conf *sshfwd_get_conf(SshChannel *c)
|
||||
{ return c->vt->get_conf(c); }
|
||||
static inline void sshfwd_window_override_removed(SshChannel *c)
|
||||
{ c->vt->window_override_removed(c); }
|
||||
static inline void sshfwd_x11_sharing_handover(
|
||||
SshChannel *c, ssh_sharing_connstate *cs, share_channel *sch,
|
||||
const char *addr, int port, int endian, int maj, int min,
|
||||
const void *idata, int ilen)
|
||||
{ return c->vt->x11_sharing_handover(c, cs, sch, addr, port, endian,
|
||||
maj, min, idata, ilen); }
|
||||
static inline void sshfwd_send_exit_status(SshChannel *c, int status)
|
||||
{ c->vt->send_exit_status(c, status); }
|
||||
static inline void sshfwd_send_exit_signal(
|
||||
SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg)
|
||||
{ c->vt->send_exit_signal(c, signame, core_dumped, msg); }
|
||||
static inline void sshfwd_send_exit_signal_numeric(
|
||||
SshChannel *c, int signum, bool core_dumped, ptrlen msg)
|
||||
{ c->vt->send_exit_signal_numeric(c, signum, core_dumped, msg); }
|
||||
static inline void sshfwd_request_x11_forwarding(
|
||||
SshChannel *c, bool want_reply, const char *proto,
|
||||
const char *data, int scr, bool once)
|
||||
{ c->vt->request_x11_forwarding(c, want_reply, proto, data, scr, once); }
|
||||
static inline void sshfwd_request_agent_forwarding(
|
||||
SshChannel *c, bool want_reply)
|
||||
{ c->vt->request_agent_forwarding(c, want_reply); }
|
||||
static inline void sshfwd_request_pty(
|
||||
SshChannel *c, bool want_reply, Conf *conf, int w, int h)
|
||||
{ c->vt->request_pty(c, want_reply, conf, w, h); }
|
||||
static inline bool sshfwd_send_env_var(
|
||||
SshChannel *c, bool want_reply, const char *var, const char *value)
|
||||
{ return c->vt->send_env_var(c, want_reply, var, value); }
|
||||
static inline void sshfwd_start_shell(
|
||||
SshChannel *c, bool want_reply)
|
||||
{ c->vt->start_shell(c, want_reply); }
|
||||
static inline void sshfwd_start_command(
|
||||
SshChannel *c, bool want_reply, const char *command)
|
||||
{ c->vt->start_command(c, want_reply, command); }
|
||||
static inline bool sshfwd_start_subsystem(
|
||||
SshChannel *c, bool want_reply, const char *subsystem)
|
||||
{ return c->vt->start_subsystem(c, want_reply, subsystem); }
|
||||
static inline bool sshfwd_send_serial_break(
|
||||
SshChannel *c, bool want_reply, int length)
|
||||
{ return c->vt->send_serial_break(c, want_reply, length); }
|
||||
static inline bool sshfwd_send_signal(
|
||||
SshChannel *c, bool want_reply, const char *signame)
|
||||
{ return c->vt->send_signal(c, want_reply, signame); }
|
||||
static inline void sshfwd_send_terminal_size_change(
|
||||
SshChannel *c, int w, int h)
|
||||
{ c->vt->send_terminal_size_change(c, w, h); }
|
||||
static inline void sshfwd_hint_channel_is_simple(SshChannel *c)
|
||||
{ c->vt->hint_channel_is_simple(c); }
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* The 'main' or primary channel of the SSH connection is special,
|
||||
|
Reference in New Issue
Block a user