sshchan.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Abstraction of the various ways to handle the local end of an SSH
  3. * connection-layer channel.
  4. */
  5. #ifndef PUTTY_SSHCHAN_H
  6. #define PUTTY_SSHCHAN_H
  7. struct ChannelVtable {
  8. void (*free)(Channel *);
  9. /* Called for channel types that were created at the same time as
  10. * we sent an outgoing CHANNEL_OPEN, when the confirmation comes
  11. * back from the server indicating that the channel has been
  12. * opened, or the failure message indicating that it hasn't,
  13. * respectively. In the latter case, this must _not_ free the
  14. * Channel structure - the client will call the free method
  15. * separately. But it might do logging or other local cleanup. */
  16. void (*open_confirmation)(Channel *);
  17. void (*open_failed)(Channel *, const char *error_text);
  18. int (*send)(Channel *, int is_stderr, const void *buf, int len);
  19. void (*send_eof)(Channel *);
  20. void (*set_input_wanted)(Channel *, int wanted);
  21. char *(*log_close_msg)(Channel *);
  22. int (*want_close)(Channel *, int sent_local_eof, int rcvd_remote_eof);
  23. };
  24. struct Channel {
  25. const struct ChannelVtable *vt;
  26. unsigned initial_fixed_window_size;
  27. };
  28. #define chan_free(ch) ((ch)->vt->free(ch))
  29. #define chan_open_confirmation(ch) ((ch)->vt->open_confirmation(ch))
  30. #define chan_open_failed(ch, err) ((ch)->vt->open_failed(ch, err))
  31. #define chan_send(ch, err, buf, len) ((ch)->vt->send(ch, err, buf, len))
  32. #define chan_send_eof(ch) ((ch)->vt->send_eof(ch))
  33. #define chan_set_input_wanted(ch, wanted) \
  34. ((ch)->vt->set_input_wanted(ch, wanted))
  35. #define chan_log_close_msg(ch) ((ch)->vt->log_close_msg(ch))
  36. #define chan_want_close(ch, leof, reof) ((ch)->vt->want_close(ch, leof, reof))
  37. /*
  38. * Reusable methods you can put in vtables to give default handling of
  39. * some of those functions.
  40. */
  41. /* open_confirmation / open_failed for any channel it doesn't apply to */
  42. void chan_remotely_opened_confirmation(Channel *chan);
  43. void chan_remotely_opened_failure(Channel *chan, const char *errtext);
  44. /* want_close for any channel that wants the default behaviour of not
  45. * closing until both directions have had an EOF */
  46. int chan_no_eager_close(Channel *, int, int);
  47. /*
  48. * Constructor for a trivial do-nothing implementation of
  49. * ChannelVtable. Used for 'zombie' channels, i.e. channels whose
  50. * proper local source of data has been shut down or otherwise stopped
  51. * existing, but the SSH side is still there and needs some kind of a
  52. * Channel implementation to talk to. In particular, the want_close
  53. * method for this channel always returns 'yes, please close this
  54. * channel asap', regardless of whether local and/or remote EOF have
  55. * been sent - indeed, even if _neither_ has.
  56. */
  57. Channel *zombiechan_new(void);
  58. /* ----------------------------------------------------------------------
  59. * This structure is owned by an SSH connection layer, and identifies
  60. * the connection layer's end of the channel, for the Channel
  61. * implementation to talk back to.
  62. */
  63. struct SshChannelVtable {
  64. int (*write)(SshChannel *c, const void *, int);
  65. void (*write_eof)(SshChannel *c);
  66. void (*unclean_close)(SshChannel *c, const char *err);
  67. void (*unthrottle)(SshChannel *c, int bufsize);
  68. Conf *(*get_conf)(SshChannel *c);
  69. void (*window_override_removed)(SshChannel *c);
  70. void (*x11_sharing_handover)(SshChannel *c,
  71. ssh_sharing_connstate *share_cs,
  72. share_channel *share_chan,
  73. const char *peer_addr, int peer_port,
  74. int endian, int protomajor, int protominor,
  75. const void *initial_data, int initial_len);
  76. };
  77. struct SshChannel {
  78. const struct SshChannelVtable *vt;
  79. };
  80. #define sshfwd_write(c, buf, len) ((c)->vt->write(c, buf, len))
  81. #define sshfwd_write_eof(c) ((c)->vt->write_eof(c))
  82. #define sshfwd_unclean_close(c, err) ((c)->vt->unclean_close(c, err))
  83. #define sshfwd_unthrottle(c, bufsize) ((c)->vt->unthrottle(c, bufsize))
  84. #define sshfwd_get_conf(c) ((c)->vt->get_conf(c))
  85. #define sshfwd_window_override_removed(c) ((c)->vt->window_override_removed(c))
  86. #define sshfwd_x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l) \
  87. ((c)->vt->x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l))
  88. #endif /* PUTTY_SSHCHAN_H */