proxy.h 3.2 KB

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