1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Remove PROXY_CHANGE_{SENT,CLOSING,ACCEPTING}.

These were just boilerplate in all the proxy negotiation functions:
every negotiator had to contain a handler for each of these events,
and they all handled them in exactly the same way. Remove them and
centralise the handling in the shared code.

A long time ago, some of these event codes were added with purpose in
mind. PROXY_CHANGE_CLOSING was there to anticipate the possibility
that you might need to make multiple TCP connections to the proxy
server (e.g. retrying with different authentication) before
successfully getting a connection you could use to talk to the
ultimate destination. And PROXY_CHANGE_ACCEPTING was there so that we
could use the listening side of SOCKS (where you ask the proxy to open
a listening socket on your behalf). But neither of them has ever been
used, and now that the code has evolved, I think probably if we do
ever need to do either of those things then they'll want to be done
differently.
This commit is contained in:
Simon Tatham 2021-11-19 10:42:20 +00:00
parent 1bf93289c9
commit 23c64fa00e
2 changed files with 4 additions and 149 deletions

View File

@ -187,13 +187,7 @@ static void plug_proxy_closing(Plug *p, PlugCloseType type,
{
ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
if (ps->state != PROXY_STATE_ACTIVE) {
ps->closing_type = type;
ps->closing_error_msg = error_msg;
ps->negotiate(ps, PROXY_CHANGE_CLOSING);
} else {
plug_closing(ps->plug, type, error_msg);
}
plug_closing(ps->plug, type, error_msg);
}
static void plug_proxy_receive(
@ -220,24 +214,16 @@ static void plug_proxy_sent (Plug *p, size_t bufsize)
{
ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
if (ps->state != PROXY_STATE_ACTIVE) {
ps->negotiate(ps, PROXY_CHANGE_SENT);
if (ps->state != PROXY_STATE_ACTIVE)
return;
}
plug_sent(ps->plug, bufsize);
}
static int plug_proxy_accepting(Plug *p,
accept_fn_t constructor, accept_ctx_t ctx)
{
ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
if (ps->state != PROXY_STATE_ACTIVE) {
ps->accepting_constructor = constructor;
ps->accepting_ctx = ctx;
return ps->negotiate(ps, PROXY_CHANGE_ACCEPTING);
}
return plug_accepting(ps->plug, constructor, ctx);
unreachable("ProxySockets never create listening Sockets");
}
/*
@ -610,36 +596,6 @@ int proxy_http_negotiate (ProxySocket *ps, int change)
return 0;
}
if (change == PROXY_CHANGE_CLOSING) {
/* if our proxy negotiation process involves closing and opening
* new sockets, then we would want to intercept this closing
* callback when we were expecting it. if we aren't anticipating
* a socket close, then some error must have occurred. we'll
* just pass those errors up to the backend.
*/
plug_closing(ps->plug, ps->closing_type, ps->closing_error_msg);
return 0; /* ignored */
}
if (change == PROXY_CHANGE_SENT) {
/* some (or all) of what we wrote to the proxy was sent.
* we don't do anything new, however, until we receive the
* proxy's response. we might want to set a timer so we can
* timeout the proxy negotiation after a while...
*/
return 0;
}
if (change == PROXY_CHANGE_ACCEPTING) {
/* we should _never_ see this, as we are using our socket to
* connect to a proxy, not accepting inbound connections.
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(ps->plug,
ps->accepting_constructor, ps->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
/* we have received data from the underlying socket, which
* we'll need to parse, process, and respond to appropriately.
@ -798,36 +754,6 @@ int proxy_socks4_negotiate (ProxySocket *ps, int change)
return 0;
}
if (change == PROXY_CHANGE_CLOSING) {
/* if our proxy negotiation process involves closing and opening
* new sockets, then we would want to intercept this closing
* callback when we were expecting it. if we aren't anticipating
* a socket close, then some error must have occurred. we'll
* just pass those errors up to the backend.
*/
plug_closing(ps->plug, ps->closing_type, ps->closing_error_msg);
return 0; /* ignored */
}
if (change == PROXY_CHANGE_SENT) {
/* some (or all) of what we wrote to the proxy was sent.
* we don't do anything new, however, until we receive the
* proxy's response. we might want to set a timer so we can
* timeout the proxy negotiation after a while...
*/
return 0;
}
if (change == PROXY_CHANGE_ACCEPTING) {
/* we should _never_ see this, as we are using our socket to
* connect to a proxy, not accepting inbound connections.
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(ps->plug,
ps->accepting_constructor, ps->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
/* we have received data from the underlying socket, which
* we'll need to parse, process, and respond to appropriately.
@ -940,36 +866,6 @@ int proxy_socks5_negotiate (ProxySocket *ps, int change)
return 0;
}
if (change == PROXY_CHANGE_CLOSING) {
/* if our proxy negotiation process involves closing and opening
* new sockets, then we would want to intercept this closing
* callback when we were expecting it. if we aren't anticipating
* a socket close, then some error must have occurred. we'll
* just pass those errors up to the backend.
*/
plug_closing(ps->plug, ps->closing_type, ps->closing_error_msg);
return 0; /* ignored */
}
if (change == PROXY_CHANGE_SENT) {
/* some (or all) of what we wrote to the proxy was sent.
* we don't do anything new, however, until we receive the
* proxy's response. we might want to set a timer so we can
* timeout the proxy negotiation after a while...
*/
return 0;
}
if (change == PROXY_CHANGE_ACCEPTING) {
/* we should _never_ see this, as we are using our socket to
* connect to a proxy, not accepting inbound connections.
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(ps->plug,
ps->accepting_constructor, ps->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
/* we have received data from the underlying socket, which
* we'll need to parse, process, and respond to appropriately.
@ -1462,36 +1358,6 @@ int proxy_telnet_negotiate (ProxySocket *ps, int change)
return 0;
}
if (change == PROXY_CHANGE_CLOSING) {
/* if our proxy negotiation process involves closing and opening
* new sockets, then we would want to intercept this closing
* callback when we were expecting it. if we aren't anticipating
* a socket close, then some error must have occurred. we'll
* just pass those errors up to the backend.
*/
plug_closing(ps->plug, ps->closing_type, ps->closing_error_msg);
return 0; /* ignored */
}
if (change == PROXY_CHANGE_SENT) {
/* some (or all) of what we wrote to the proxy was sent.
* we don't do anything new, however, until we receive the
* proxy's response. we might want to set a timer so we can
* timeout the proxy negotiation after a while...
*/
return 0;
}
if (change == PROXY_CHANGE_ACCEPTING) {
/* we should _never_ see this, as we are using our socket to
* connect to a proxy, not accepting inbound connections.
* what should we do? close the socket with an appropriate
* error message?
*/
return plug_accepting(ps->plug,
ps->accepting_constructor, ps->accepting_ctx);
}
if (change == PROXY_CHANGE_RECEIVE) {
/* we have received data from the underlying socket, which
* we'll need to parse, process, and respond to appropriately.

View File

@ -39,10 +39,7 @@ struct ProxySocket {
*/
#define PROXY_CHANGE_NEW -1
#define PROXY_CHANGE_CLOSING 0
#define PROXY_CHANGE_SENT 1
#define PROXY_CHANGE_RECEIVE 2
#define PROXY_CHANGE_ACCEPTING 3
/* something has changed (a call from the sub socket
* layer into our Proxy Plug layer, or we were just
@ -57,19 +54,11 @@ struct ProxySocket {
* (for use by proxy's negotiate function)
*/
/* closing */
PlugCloseType closing_type;
const char *closing_error_msg;
/* receive */
bool receive_urgent;
const char *receive_data;
int receive_len;
/* accepting */
accept_fn_t accepting_constructor;
accept_ctx_t accepting_ctx;
/* configuration, used to look up proxy settings */
Conf *conf;