proxy.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. int pending_flush;
  23. bufchain pending_input_data;
  24. int 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. int 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. int closing_calling_back;
  55. /* receive */
  56. int receive_urgent;
  57. char *receive_data;
  58. int receive_len;
  59. /* sent */
  60. int sent_bufsize;
  61. /* accepting */
  62. accept_fn_t accepting_constructor;
  63. accept_ctx_t accepting_ctx;
  64. /* configuration, used to look up proxy settings */
  65. Conf *conf;
  66. /* CHAP transient data */
  67. int chap_num_attributes;
  68. int chap_num_attributes_processed;
  69. int chap_current_attribute;
  70. int chap_current_datalen;
  71. Socket sock;
  72. Plug plugimpl;
  73. };
  74. extern void proxy_activate (ProxySocket *);
  75. extern int proxy_http_negotiate (ProxySocket *, int);
  76. extern int proxy_telnet_negotiate (ProxySocket *, int);
  77. extern int proxy_socks4_negotiate (ProxySocket *, int);
  78. extern int proxy_socks5_negotiate (ProxySocket *, int);
  79. /*
  80. * This may be reused by local-command proxies on individual
  81. * platforms.
  82. */
  83. char *format_telnet_command(SockAddr *addr, int port, Conf *conf);
  84. /*
  85. * These are implemented in cproxy.c or nocproxy.c, depending on
  86. * whether encrypted proxy authentication is available.
  87. */
  88. extern void proxy_socks5_offerencryptedauth(BinarySink *);
  89. extern int proxy_socks5_handlechap (ProxySocket *);
  90. extern int proxy_socks5_selectchap(ProxySocket *);
  91. #endif