1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -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:
Simon Tatham
2021-11-06 13:25:42 +00:00
parent 5fdce31eca
commit 364e1aa3f3
12 changed files with 103 additions and 94 deletions

View File

@ -65,15 +65,13 @@ int proxy_socks5_handlechap (ProxySocket *p)
* number of attributes
*/
if (data[0] != 0x01) {
plug_closing(p->plug, "Proxy error: SOCKS proxy wants"
" a different CHAP version",
PROXY_ERROR_GENERAL);
plug_closing_error(p->plug, "Proxy error: SOCKS proxy wants "
"a different CHAP version");
return 1;
}
if (data[1] == 0x00) {
plug_closing(p->plug, "Proxy error: SOCKS proxy won't"
" negotiate CHAP with us",
PROXY_ERROR_GENERAL);
plug_closing_error(p->plug, "Proxy error: SOCKS proxy won't "
"negotiate CHAP with us");
return 1;
}
p->chap_num_attributes = data[1];
@ -103,9 +101,8 @@ int proxy_socks5_handlechap (ProxySocket *p)
if (data[0] == 0x00)
p->state = 2;
else {
plug_closing(p->plug, "Proxy error: SOCKS proxy"
" refused CHAP authentication",
PROXY_ERROR_GENERAL);
plug_closing_error(p->plug, "Proxy error: SOCKS proxy "
"refused CHAP authentication");
return 1;
}
break;
@ -122,10 +119,9 @@ int proxy_socks5_handlechap (ProxySocket *p)
case 0x11:
/* Chose a protocol */
if (data[0] != 0x85) {
plug_closing(p->plug, "Proxy error: Server chose "
"CHAP of other than HMAC-MD5 but we "
"didn't offer it!",
PROXY_ERROR_GENERAL);
plug_closing_error(p->plug, "Proxy error: Server chose "
"CHAP of other than HMAC-MD5 but we "
"didn't offer it!");
return 1;
}
break;
@ -172,8 +168,7 @@ int proxy_socks5_selectchap(ProxySocket *p)
p->state = 8;
} else
plug_closing(p->plug, "Proxy error: Server chose "
"CHAP authentication but we didn't offer it!",
PROXY_ERROR_GENERAL);
plug_closing_error(p->plug, "Proxy error: Server chose "
"CHAP authentication but we didn't offer it!");
return 1;
}