1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-23 01:49:53 +03:00

Wpc.c: adapt WpcSockConnectEx() for new proxy functions

This commit is contained in:
Davide Beatrici 2019-10-29 04:47:43 +01:00
parent 59dc26aa21
commit 3c21d982fc

View File

@ -500,64 +500,73 @@ SOCK *WpcSockConnect(WPC_CONNECT *param, UINT *error_code, UINT timeout)
} }
SOCK *WpcSockConnectEx(WPC_CONNECT *param, UINT *error_code, UINT timeout, bool *cancel) SOCK *WpcSockConnectEx(WPC_CONNECT *param, UINT *error_code, UINT timeout, bool *cancel)
{ {
CONNECTION c;
SOCK *sock; SOCK *sock;
UINT err = ERR_NO_ERROR; UINT ret;
// Validate arguments // Validate arguments
if (param == NULL) if (param == NULL)
{ {
return NULL; return NULL;
} }
Zero(&c, sizeof(c)); if (error_code == NULL)
{
error_code = &ret;
}
sock = NULL; if (param->ProxyType == PROXY_DIRECT)
err = ERR_INTERNAL_ERROR; {
sock = TcpConnectEx3(param->HostName, param->Port, timeout, cancel, NULL, true, NULL, false, NULL);
*error_code = (sock != NULL ? ERR_NO_ERROR : ERR_CONNECT_FAILED);
return sock;
}
else
{
PROXY_PARAM_OUT out;
PROXY_PARAM_IN in;
UINT ret;
Zero(&in, sizeof(in));
in.Timeout = timeout;
StrCpy(in.TargetHostname, sizeof(in.TargetHostname), param->HostName);
in.TargetPort = param->Port;
StrCpy(in.Hostname, sizeof(in.Hostname), param->ProxyHostName);
in.Port = param->ProxyPort;
StrCpy(in.Username, sizeof(in.Username), param->ProxyUsername);
StrCpy(in.Password, sizeof(in.Password), param->ProxyPassword);
StrCpy(in.HttpCustomHeader, sizeof(in.HttpCustomHeader), param->CustomHttpHeader);
switch (param->ProxyType) switch (param->ProxyType)
{ {
case PROXY_DIRECT:
sock = TcpConnectEx3(param->HostName, param->Port, timeout, cancel, NULL, true, NULL, false, NULL);
if (sock == NULL)
{
err = ERR_CONNECT_FAILED;
}
break;
case PROXY_HTTP: case PROXY_HTTP:
sock = ProxyConnectEx3(&c, param, false, cancel, NULL, timeout); ret = ProxyHttpConnect(&out, &in, cancel);
if (sock == NULL)
{
err = c.Err;
}
break; break;
case PROXY_SOCKS: case PROXY_SOCKS:
// SOCKS4 connection ret = ProxySocks4Connect(&out, &in, cancel);
sock = SocksConnectEx2(&c, param->ProxyHostName, param->ProxyPort,
param->HostName, param->Port,
param->ProxyUsername, false, cancel, NULL, timeout, NULL);
if (sock == NULL)
{
err = c.Err;
}
break; break;
case PROXY_SOCKS5: case PROXY_SOCKS5:
// SOCKS5 connection ret = ProxySocks5Connect(&out, &in, cancel);
sock = Socks5Connect(&c, param, false, cancel, NULL, timeout, NULL); break;
if (sock == NULL) default:
{ *error_code = ERR_INTERNAL_ERROR;
err = c.Err; Debug("WpcSockConnect(): Unknown proxy type: %u!\n", param->ProxyType);
} return NULL;
} }
if (error_code != NULL) *error_code = ProxyCodeToCedar(ret);
if (*error_code != ERR_NO_ERROR)
{ {
*error_code = err; Debug("ClientConnectGetSocket(): Connection via proxy server failed with error %u\n", ret);
return NULL;
} }
return sock; return out.Sock;
}
} }
SOCK *WpcSockConnect2(char *hostname, UINT port, INTERNET_SETTING *t, UINT *error_code, UINT timeout) SOCK *WpcSockConnect2(char *hostname, UINT port, INTERNET_SETTING *t, UINT *error_code, UINT timeout)
{ {