mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-04 13:02:47 -05:00
Convenience wrappers on plug_closing().
Having a single plug_closing() function covering various kinds of closure is reasonably convenient from the point of view of Plug implementations, but it's annoying for callers, who all have to fill in pointless NULL and 0 parameters in the cases where they're not used. Added some inline helper functions in network.h alongside the main plug_closing() dispatch wrappers, so that each kind of connection closure can present a separate API for the Socket side of the interface, without complicating the vtable for the Plug side. Also, added OS-specific extra helpers in the Unix and Windows directories, which centralise the job of taking an OS error code (of whatever kind) and translating it into its error message. In passing, this removes the horrible ad-hoc made-up error codes in proxy.h, which is OK, because nothing checked for them anyway, and also I'm about to do an API change to plug_closing proper that removes the need for them.
This commit is contained in:
@ -671,8 +671,8 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
||||
/* We can't rely on whether the %n incremented the sscanf return */
|
||||
if (sscanf((char *)data, "HTTP/%i.%i %n",
|
||||
&maj_ver, &min_ver, &status) < 2 || status == -1) {
|
||||
plug_closing(p->plug, "Proxy error: HTTP response was absent",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: "
|
||||
"HTTP response was absent");
|
||||
sfree(data);
|
||||
return 1;
|
||||
}
|
||||
@ -687,7 +687,7 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
||||
(data[eol-1] == '\r' || data[eol-1] == '\n'))
|
||||
data[--eol] = '\0';
|
||||
buf = dupprintf("Proxy error: %s", data+status);
|
||||
plug_closing(p->plug, buf, PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, buf);
|
||||
sfree(buf);
|
||||
sfree(data);
|
||||
return 1;
|
||||
@ -737,8 +737,7 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
||||
}
|
||||
}
|
||||
|
||||
plug_closing(p->plug, "Proxy error: unexpected proxy error",
|
||||
PROXY_ERROR_UNEXPECTED);
|
||||
plug_closing_error(p->plug, "Proxy error: unexpected proxy error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -854,9 +853,9 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
||||
bufchain_fetch(&p->pending_input_data, data, 8);
|
||||
|
||||
if (data[0] != 0) {
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy responded with "
|
||||
"unexpected reply code version",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||
"responded with unexpected "
|
||||
"reply code version");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -864,17 +863,17 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
||||
|
||||
switch (data[1]) {
|
||||
case 92:
|
||||
plug_closing(p->plug, "Proxy error: SOCKS server wanted IDENTD on client",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS server "
|
||||
"wanted IDENTD on client");
|
||||
break;
|
||||
case 93:
|
||||
plug_closing(p->plug, "Proxy error: Username and IDENTD on client don't agree",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: Username and "
|
||||
"IDENTD on client don't agree");
|
||||
break;
|
||||
case 91:
|
||||
default:
|
||||
plug_closing(p->plug, "Proxy error: Error while communicating with proxy",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: Error while "
|
||||
"communicating with proxy");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -890,8 +889,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
||||
}
|
||||
}
|
||||
|
||||
plug_closing(p->plug, "Proxy error: unexpected proxy error",
|
||||
PROXY_ERROR_UNEXPECTED);
|
||||
plug_closing_error(p->plug, "Proxy error: unexpected proxy error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -996,8 +994,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
bufchain_fetch(&p->pending_input_data, data, 2);
|
||||
|
||||
if (data[0] != 5) {
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned unexpected version",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||
"returned unexpected version");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1006,8 +1004,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
else if (data[1] == 0x02) p->state = 5; /* username/password authentication */
|
||||
else if (data[1] == 0x03) p->state = 6; /* CHAP authentication */
|
||||
else {
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy did not accept our authentication",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy did not "
|
||||
"accept our authentication");
|
||||
return 1;
|
||||
}
|
||||
bufchain_consume(&p->pending_input_data, 2);
|
||||
@ -1030,17 +1028,15 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
bufchain_fetch(&p->pending_input_data, data, 2);
|
||||
|
||||
if (data[0] != 1) {
|
||||
plug_closing(p->plug, "Proxy error: SOCKS password "
|
||||
"subnegotiation contained wrong version number",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS password "
|
||||
"subnegotiation contained wrong version "
|
||||
"number");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (data[1] != 0) {
|
||||
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy refused"
|
||||
" password authentication",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy refused "
|
||||
"password authentication");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1142,8 +1138,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
bufchain_fetch(&p->pending_input_data, data, 5);
|
||||
|
||||
if (data[0] != 5) {
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned wrong version number",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||
"returned wrong version number");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1166,7 +1162,7 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
data[1]);
|
||||
break;
|
||||
}
|
||||
plug_closing(p->plug, buf, PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1180,9 +1176,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
case 4: len += 16; break;/* IPv6 address */
|
||||
case 3: len += 1+(unsigned char)data[4]; break; /* domain name */
|
||||
default:
|
||||
plug_closing(p->plug, "Proxy error: SOCKS proxy returned "
|
||||
"unrecognised address format",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
|
||||
"returned unrecognised address format");
|
||||
return 1;
|
||||
}
|
||||
if (bufchain_size(&p->pending_input_data) < len)
|
||||
@ -1196,8 +1191,8 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
|
||||
if (p->state == 4) {
|
||||
/* TODO: Handle GSSAPI authentication */
|
||||
plug_closing(p->plug, "Proxy error: We don't support GSSAPI authentication",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: We don't support "
|
||||
"GSSAPI authentication");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1223,10 +1218,9 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
strbuf_free(auth);
|
||||
p->state = 7;
|
||||
} else
|
||||
plug_closing(p->plug, "Proxy error: Server chose "
|
||||
"username/password authentication but we "
|
||||
"didn't offer it!",
|
||||
PROXY_ERROR_GENERAL);
|
||||
plug_closing_error(p->plug, "Proxy error: Server chose "
|
||||
"username/password authentication "
|
||||
"but we didn't offer it!");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1238,8 +1232,7 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
|
||||
}
|
||||
|
||||
plug_closing(p->plug, "Proxy error: Unexpected proxy error",
|
||||
PROXY_ERROR_UNEXPECTED);
|
||||
plug_closing_error(p->plug, "Proxy error: Unexpected proxy error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1509,7 +1502,6 @@ int proxy_telnet_negotiate (ProxySocket *p, int change)
|
||||
return 1;
|
||||
}
|
||||
|
||||
plug_closing(p->plug, "Proxy error: Unexpected proxy error",
|
||||
PROXY_ERROR_UNEXPECTED);
|
||||
plug_closing_error(p->plug, "Proxy error: Unexpected proxy error");
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user