proxy.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #define PROXY_ERROR_GENERAL 8000
  12. #define PROXY_ERROR_UNEXPECTED 8001
  13. typedef struct ProxySocket ProxySocket;
  14. struct ProxySocket {
  15. const char *error;
  16. Socket *sub_socket;
  17. Plug *plug;
  18. SockAddr *remote_addr;
  19. int remote_port;
  20. bufchain pending_output_data;
  21. bufchain pending_oob_output_data;
  22. bufchain pending_input_data;
  23. bool pending_eof;
  24. #define PROXY_STATE_NEW -1
  25. #define PROXY_STATE_ACTIVE 0
  26. int state; /* proxy states greater than 0 are implementation
  27. * dependent, but represent various stages/states
  28. * of the initialization/setup/negotiation with the
  29. * proxy server.
  30. */
  31. bool freeze; /* should we freeze the underlying socket when
  32. * we are done with the proxy negotiation? this
  33. * simply caches the value of sk_set_frozen calls.
  34. */
  35. #define PROXY_CHANGE_NEW -1
  36. #define PROXY_CHANGE_CLOSING 0
  37. #define PROXY_CHANGE_SENT 1
  38. #define PROXY_CHANGE_RECEIVE 2
  39. #define PROXY_CHANGE_ACCEPTING 3
  40. /* something has changed (a call from the sub socket
  41. * layer into our Proxy Plug layer, or we were just
  42. * created, etc), so the proxy layer needs to handle
  43. * this change (the type of which is the second argument)
  44. * and further the proxy negotiation process.
  45. */
  46. int (*negotiate) (ProxySocket * /* this */, int /* change type */);
  47. /* current arguments of plug handlers
  48. * (for use by proxy's negotiate function)
  49. */
  50. /* closing */
  51. const char *closing_error_msg;
  52. int closing_error_code;
  53. bool closing_calling_back;
  54. /* receive */
  55. bool receive_urgent;
  56. const char *receive_data;
  57. int receive_len;
  58. /* accepting */
  59. accept_fn_t accepting_constructor;
  60. accept_ctx_t accepting_ctx;
  61. /* configuration, used to look up proxy settings */
  62. Conf *conf;
  63. /* CHAP transient data */
  64. int chap_num_attributes;
  65. int chap_num_attributes_processed;
  66. int chap_current_attribute;
  67. int chap_current_datalen;
  68. Socket sock;
  69. Plug plugimpl;
  70. };
  71. extern void proxy_activate (ProxySocket *);
  72. extern int proxy_http_negotiate (ProxySocket *, int);
  73. extern int proxy_telnet_negotiate (ProxySocket *, int);
  74. extern int proxy_socks4_negotiate (ProxySocket *, int);
  75. extern int proxy_socks5_negotiate (ProxySocket *, int);
  76. /*
  77. * This may be reused by local-command proxies on individual
  78. * platforms.
  79. */
  80. char *format_telnet_command(SockAddr *addr, int port, Conf *conf);
  81. /*
  82. * These are implemented in cproxy.c or nocproxy.c, depending on
  83. * whether encrypted proxy authentication is available.
  84. */
  85. extern void proxy_socks5_offerencryptedauth(BinarySink *);
  86. extern int proxy_socks5_handlechap (ProxySocket *);
  87. extern int proxy_socks5_selectchap(ProxySocket *);
  88. #endif