sshchan.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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->send_eof(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. #endif /* PUTTY_SSHCHAN_H */