proxy.h 3.4 KB

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