8eebd221 |
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 | * |
2d129d8e |
7 | * Supported proxies: HTTP CONNECT, generic telnet, SOCKS 4 & 5 |
8eebd221 |
8 | */ |
9 | |
10 | #ifndef PUTTY_PROXY_H |
11 | #define PUTTY_PROXY_H |
12 | |
13 | #define PROXY_ERROR_GENERAL 8000 |
14 | #define PROXY_ERROR_UNEXPECTED 8001 |
15 | |
16 | typedef struct Socket_proxy_tag * Proxy_Socket; |
17 | |
18 | struct Socket_proxy_tag { |
7b6c9b99 |
19 | const struct socket_function_table *fn; |
8eebd221 |
20 | /* the above variable absolutely *must* be the first in this structure */ |
21 | |
22 | char * error; |
23 | |
24 | Socket sub_socket; |
25 | Plug plug; |
26 | SockAddr remote_addr; |
27 | int remote_port; |
28 | |
29 | bufchain pending_output_data; |
30 | bufchain pending_oob_output_data; |
31 | int pending_flush; |
32 | bufchain pending_input_data; |
33 | |
34 | #define PROXY_STATE_NEW -1 |
35 | #define PROXY_STATE_ACTIVE 0 |
36 | |
37 | int state; /* proxy states greater than 0 are implementation |
38 | * dependent, but represent various stages/states |
39 | * of the initialization/setup/negotiation with the |
40 | * proxy server. |
41 | */ |
42 | int freeze; /* should we freeze the underlying socket when |
43 | * we are done with the proxy negotiation? this |
44 | * simply caches the value of sk_set_frozen calls. |
45 | */ |
46 | |
47 | #define PROXY_CHANGE_NEW -1 |
48 | #define PROXY_CHANGE_CLOSING 0 |
49 | #define PROXY_CHANGE_SENT 1 |
50 | #define PROXY_CHANGE_RECEIVE 2 |
51 | #define PROXY_CHANGE_ACCEPTING 3 |
52 | |
53 | /* something has changed (a call from the sub socket |
54 | * layer into our Proxy Plug layer, or we were just |
55 | * created, etc), so the proxy layer needs to handle |
56 | * this change (the type of which is the second argument) |
57 | * and further the proxy negotiation process. |
58 | */ |
59 | |
60 | int (*negotiate) (Proxy_Socket /* this */, int /* change type */); |
61 | |
62 | /* current arguments of plug handlers |
63 | * (for use by proxy's negotiate function) |
64 | */ |
65 | |
66 | /* closing */ |
cbe2d68f |
67 | const char *closing_error_msg; |
8eebd221 |
68 | int closing_error_code; |
69 | int closing_calling_back; |
70 | |
71 | /* receive */ |
72 | int receive_urgent; |
73 | char *receive_data; |
74 | int receive_len; |
75 | |
76 | /* sent */ |
77 | int sent_bufsize; |
78 | |
79 | /* accepting */ |
f7f9fb5c |
80 | OSSocket accepting_sock; |
8eebd221 |
81 | |
e8fa8f62 |
82 | /* configuration, used to look up proxy settings */ |
83 | Config cfg; |
8eebd221 |
84 | }; |
85 | |
86 | typedef struct Plug_proxy_tag * Proxy_Plug; |
87 | |
88 | struct Plug_proxy_tag { |
7b6c9b99 |
89 | const struct plug_function_table *fn; |
8eebd221 |
90 | /* the above variable absolutely *must* be the first in this structure */ |
91 | |
92 | Proxy_Socket proxy_socket; |
93 | |
94 | }; |
95 | |
96 | extern void proxy_activate (Proxy_Socket); |
97 | |
98 | extern int proxy_http_negotiate (Proxy_Socket, int); |
99 | extern int proxy_telnet_negotiate (Proxy_Socket, int); |
6971bbe7 |
100 | extern int proxy_socks4_negotiate (Proxy_Socket, int); |
101 | extern int proxy_socks5_negotiate (Proxy_Socket, int); |
8eebd221 |
102 | |
0f0a2507 |
103 | /* |
104 | * This may be reused by local-command proxies on individual |
105 | * platforms. |
106 | */ |
107 | char *format_telnet_command(SockAddr addr, int port, const Config *cfg); |
108 | |
8eebd221 |
109 | #endif |