proxy.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Network proxy abstraction in PuTTY
  3. *
  4. * A proxy layer, if necessary, wedges itself between the
  5. * network code and the higher level backend.
  6. *
  7. * Supported proxies: HTTP CONNECT, generic telnet, SOCKS 4 & 5
  8. */
  9. #ifndef PUTTY_PROXY_H
  10. #define PUTTY_PROXY_H
  11. typedef struct ProxySocket ProxySocket;
  12. typedef struct ProxyNegotiator ProxyNegotiator;
  13. typedef struct ProxyNegotiatorVT ProxyNegotiatorVT;
  14. struct ProxySocket {
  15. const char *error;
  16. Socket *sub_socket;
  17. Plug *plug;
  18. SockAddr *remote_addr;
  19. int remote_port;
  20. /* Parameters needed to make further connections to the proxy */
  21. SockAddr *proxy_addr;
  22. int proxy_port;
  23. bool proxy_privport, proxy_oobinline, proxy_nodelay, proxy_keepalive;
  24. bufchain pending_output_data;
  25. bufchain pending_oob_output_data;
  26. bufchain pending_input_data;
  27. bool pending_eof;
  28. bool freeze; /* should we freeze the underlying socket when
  29. * we are done with the proxy negotiation? this
  30. * simply caches the value of sk_set_frozen calls.
  31. */
  32. ProxyNegotiator *pn; /* non-NULL if still negotiating */
  33. bufchain output_from_negotiator;
  34. /* configuration, used to look up proxy settings */
  35. Conf *conf;
  36. /* for interaction with the Seat */
  37. Interactor *clientitr;
  38. LogPolicy *clientlp;
  39. Seat *clientseat;
  40. Socket sock;
  41. Plug plugimpl;
  42. Interactor interactor;
  43. };
  44. struct ProxyNegotiator {
  45. const ProxyNegotiatorVT *vt;
  46. /* Standard fields for any ProxyNegotiator. new() and free() don't
  47. * have to set these up; that's done centrally, to save duplication. */
  48. ProxySocket *ps;
  49. bufchain *input;
  50. bufchain_sink output[1];
  51. Interactor *itr; /* NULL if we are not able to interact with the user */
  52. /* Set to report success during proxy negotiation. */
  53. bool done;
  54. /* Set to report an error during proxy negotiation. The main
  55. * ProxySocket will free it, and will then guarantee never to call
  56. * process_queue again. */
  57. char *error;
  58. /* Set to report user abort during proxy negotiation. */
  59. bool aborted;
  60. /* Set to request the centralised code to make a fresh connection
  61. * to the proxy server, e.g. because an HTTP proxy slammed the
  62. * connection shut after sending 407 Proxy Auth Required. */
  63. bool reconnect;
  64. };
  65. struct ProxyNegotiatorVT {
  66. ProxyNegotiator *(*new)(const ProxyNegotiatorVT *);
  67. void (*process_queue)(ProxyNegotiator *);
  68. void (*free)(ProxyNegotiator *);
  69. const char *type;
  70. };
  71. static inline ProxyNegotiator *proxy_negotiator_new(
  72. const ProxyNegotiatorVT *vt)
  73. { return vt->new(vt); }
  74. static inline void proxy_negotiator_process_queue(ProxyNegotiator *pn)
  75. { pn->vt->process_queue(pn); }
  76. static inline void proxy_negotiator_free(ProxyNegotiator *pn)
  77. { pn->vt->free(pn); }
  78. extern const ProxyNegotiatorVT http_proxy_negotiator_vt;
  79. extern const ProxyNegotiatorVT socks4_proxy_negotiator_vt;
  80. extern const ProxyNegotiatorVT socks5_proxy_negotiator_vt;
  81. extern const ProxyNegotiatorVT telnet_proxy_negotiator_vt;
  82. /*
  83. * Centralised functions to allow ProxyNegotiators to get hold of a
  84. * prompts_t, and to deal with SeatPromptResults coming back.
  85. */
  86. prompts_t *proxy_new_prompts(ProxySocket *ps);
  87. void proxy_spr_abort(ProxyNegotiator *pn, SeatPromptResult spr);
  88. /*
  89. * This may be reused by local-command proxies on individual
  90. * platforms.
  91. */
  92. #define TELNET_CMD_MISSING_USERNAME 0x0001
  93. #define TELNET_CMD_MISSING_PASSWORD 0x0002
  94. char *format_telnet_command(SockAddr *addr, int port, Conf *conf,
  95. unsigned *flags_out);
  96. DeferredSocketOpener *local_proxy_opener(
  97. SockAddr *addr, int port, Plug *plug, Conf *conf, Interactor *itr);
  98. void local_proxy_opener_set_socket(DeferredSocketOpener *opener,
  99. Socket *socket);
  100. char *platform_setup_local_proxy(Socket *socket, const char *cmd);
  101. #include "cproxy.h"
  102. #endif