mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-22 17:39:53 +03:00
Wpc.c: adapt WpcSockConnectEx() for new proxy functions
This commit is contained in:
parent
59dc26aa21
commit
3c21d982fc
@ -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)
|
||||
{
|
||||
CONNECTION c;
|
||||
SOCK *sock;
|
||||
UINT err = ERR_NO_ERROR;
|
||||
UINT ret;
|
||||
// Validate arguments
|
||||
if (param == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Zero(&c, sizeof(c));
|
||||
if (error_code == NULL)
|
||||
{
|
||||
error_code = &ret;
|
||||
}
|
||||
|
||||
sock = NULL;
|
||||
err = ERR_INTERNAL_ERROR;
|
||||
if (param->ProxyType == PROXY_DIRECT)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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:
|
||||
sock = ProxyConnectEx3(&c, param, false, cancel, NULL, timeout);
|
||||
if (sock == NULL)
|
||||
{
|
||||
err = c.Err;
|
||||
}
|
||||
ret = ProxyHttpConnect(&out, &in, cancel);
|
||||
break;
|
||||
|
||||
case PROXY_SOCKS:
|
||||
// SOCKS4 connection
|
||||
sock = SocksConnectEx2(&c, param->ProxyHostName, param->ProxyPort,
|
||||
param->HostName, param->Port,
|
||||
param->ProxyUsername, false, cancel, NULL, timeout, NULL);
|
||||
if (sock == NULL)
|
||||
{
|
||||
err = c.Err;
|
||||
}
|
||||
ret = ProxySocks4Connect(&out, &in, cancel);
|
||||
break;
|
||||
|
||||
case PROXY_SOCKS5:
|
||||
// SOCKS5 connection
|
||||
sock = Socks5Connect(&c, param, false, cancel, NULL, timeout, NULL);
|
||||
if (sock == NULL)
|
||||
{
|
||||
err = c.Err;
|
||||
}
|
||||
ret = ProxySocks5Connect(&out, &in, cancel);
|
||||
break;
|
||||
default:
|
||||
*error_code = ERR_INTERNAL_ERROR;
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user