Merge pull request #6415 from akallabeth/proxy_settings_api
Use freerdp_settings_[s|g]et* api to access proxy vaiables.
This commit is contained in:
commit
0f70aa2f43
@ -1567,9 +1567,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
else
|
||||
compatibility = freerdp_client_detect_command_line(argc - 1, &argv[1], &flags);
|
||||
|
||||
settings->ProxyHostname = NULL;
|
||||
settings->ProxyUsername = NULL;
|
||||
settings->ProxyPassword = NULL;
|
||||
freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, NULL);
|
||||
freerdp_settings_set_string(settings, FreeRDP_ProxyUsername, NULL);
|
||||
freerdp_settings_set_string(settings, FreeRDP_ProxyPassword, NULL);
|
||||
|
||||
if (compatibility)
|
||||
{
|
||||
@ -2089,7 +2089,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
CommandLineSwitchCase(arg, "proxy")
|
||||
{
|
||||
/* initial value */
|
||||
settings->ProxyType = PROXY_TYPE_HTTP;
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_HTTP))
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
|
||||
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
|
||||
{
|
||||
@ -2104,12 +2105,23 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
*p = '\0';
|
||||
|
||||
if (_stricmp("no_proxy", arg->Value) == 0)
|
||||
settings->ProxyType = PROXY_TYPE_IGNORE;
|
||||
|
||||
{
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
|
||||
PROXY_TYPE_IGNORE))
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
}
|
||||
if (_stricmp("http", arg->Value) == 0)
|
||||
settings->ProxyType = PROXY_TYPE_HTTP;
|
||||
{
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
|
||||
PROXY_TYPE_HTTP))
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
}
|
||||
else if (_stricmp("socks5", arg->Value) == 0)
|
||||
settings->ProxyType = PROXY_TYPE_SOCKS;
|
||||
{
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
|
||||
PROXY_TYPE_SOCKS))
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now");
|
||||
@ -2142,18 +2154,15 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
}
|
||||
|
||||
*colonPtr = '\0';
|
||||
settings->ProxyUsername = _strdup(arg->Value);
|
||||
|
||||
if (!settings->ProxyUsername)
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_ProxyUsername, arg->Value))
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate proxy username");
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
}
|
||||
|
||||
*atPtr = '\0';
|
||||
settings->ProxyPassword = _strdup(colonPtr + 1);
|
||||
|
||||
if (!settings->ProxyPassword)
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_ProxyPassword, colonPtr + 1))
|
||||
{
|
||||
WLog_ERR(TAG, "unable to allocate proxy password");
|
||||
return COMMAND_LINE_ERROR_MEMORY;
|
||||
@ -2172,11 +2181,16 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
|
||||
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
|
||||
|
||||
length = (size_t)(p - arg->Value);
|
||||
settings->ProxyPort = (UINT16)val;
|
||||
settings->ProxyHostname = (char*)malloc(length + 1);
|
||||
strncpy(settings->ProxyHostname, arg->Value, length);
|
||||
settings->ProxyHostname[length] = '\0';
|
||||
if (!freerdp_settings_set_uint16(settings, FreeRDP_ProxyPort, val))
|
||||
return FALSE;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
p = strchr(arg->Value, '/');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, arg->Value))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -647,8 +647,8 @@ static BOOL rpc_channel_tls_connect(RpcChannel* channel, int timeout)
|
||||
|
||||
context = channel->client->context;
|
||||
settings = context->settings;
|
||||
proxyUsername = settings->ProxyUsername;
|
||||
proxyPassword = settings->ProxyPassword;
|
||||
proxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername);
|
||||
proxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword);
|
||||
{
|
||||
sockfd = freerdp_tcp_connect(context, settings, channel->client->host,
|
||||
channel->client->port, timeout);
|
||||
|
@ -1022,10 +1022,10 @@ static BOOL rpc_client_resolve_gateway(rdpSettings* settings, char** host, UINT1
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
const char* peerHostname = settings->GatewayHostname;
|
||||
const char* proxyUsername = settings->ProxyUsername;
|
||||
const char* proxyPassword = settings->ProxyPassword;
|
||||
*port = settings->GatewayPort;
|
||||
const char* peerHostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname);
|
||||
const char* proxyUsername = freerdp_settings_get_string(settings, FreeRDP_GatewayUsername);
|
||||
const char* proxyPassword = freerdp_settings_get_string(settings, FreeRDP_GatewayPassword);
|
||||
*port = freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort);
|
||||
*isProxy = proxy_prepare(settings, &peerHostname, port, &proxyUsername, &proxyPassword);
|
||||
result = freerdp_tcp_resolve_host(peerHostname, *port, 0);
|
||||
|
||||
|
@ -71,28 +71,28 @@ static BOOL proxy_parse_uri(rdpSettings* settings, const char* uri);
|
||||
BOOL proxy_prepare(rdpSettings* settings, const char** lpPeerHostname, UINT16* lpPeerPort,
|
||||
const char** lpProxyUsername, const char** lpProxyPassword)
|
||||
{
|
||||
if (settings->ProxyType == PROXY_TYPE_IGNORE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_IGNORE)
|
||||
return FALSE;
|
||||
|
||||
/* For TSGateway, find the system HTTPS proxy automatically */
|
||||
if (settings->ProxyType == PROXY_TYPE_NONE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_NONE)
|
||||
proxy_read_environment(settings, "https_proxy");
|
||||
|
||||
if (settings->ProxyType == PROXY_TYPE_NONE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_NONE)
|
||||
proxy_read_environment(settings, "HTTPS_PROXY");
|
||||
|
||||
if (settings->ProxyType != PROXY_TYPE_NONE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
|
||||
proxy_read_environment(settings, "no_proxy");
|
||||
|
||||
if (settings->ProxyType != PROXY_TYPE_NONE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
|
||||
proxy_read_environment(settings, "NO_PROXY");
|
||||
|
||||
if (settings->ProxyType != PROXY_TYPE_NONE)
|
||||
if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
|
||||
{
|
||||
*lpPeerHostname = settings->ProxyHostname;
|
||||
*lpPeerPort = settings->ProxyPort;
|
||||
*lpProxyUsername = settings->ProxyUsername;
|
||||
*lpProxyPassword = settings->ProxyPassword;
|
||||
*lpPeerHostname = freerdp_settings_get_string(settings, FreeRDP_ProxyHostname);
|
||||
*lpPeerPort = freerdp_settings_get_uint32(settings, FreeRDP_ProxyPort);
|
||||
*lpProxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername);
|
||||
*lpProxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -274,9 +274,10 @@ void proxy_read_environment(rdpSettings* settings, char* envname)
|
||||
{
|
||||
if (check_no_proxy(settings, env))
|
||||
{
|
||||
WLog_INFO(TAG, "deactivating proxy: %s [%s=%s]", settings->ServerHostname, envname,
|
||||
WLog_INFO(TAG, "deactivating proxy: %s [%s=%s]",
|
||||
freerdp_settings_get_string(settings, FreeRDP_ServerHostname), envname,
|
||||
env);
|
||||
settings->ProxyType = PROXY_TYPE_NONE;
|
||||
freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_NONE);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -288,31 +289,38 @@ void proxy_read_environment(rdpSettings* settings, char* envname)
|
||||
free(env);
|
||||
}
|
||||
|
||||
BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
|
||||
BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in)
|
||||
{
|
||||
const char *hostname, *pport;
|
||||
BOOL rc = FALSE;
|
||||
char *hostname, *pport;
|
||||
const char* protocol;
|
||||
const char* p;
|
||||
char* p;
|
||||
UINT16 port;
|
||||
int hostnamelen;
|
||||
char* uri_copy = _strdup(uri_in);
|
||||
char* uri = uri_copy;
|
||||
if (!uri)
|
||||
return FALSE;
|
||||
p = strstr(uri, "://");
|
||||
|
||||
if (p)
|
||||
{
|
||||
if (p == uri + 4 && !strncmp("http", uri, 4))
|
||||
{
|
||||
settings->ProxyType = PROXY_TYPE_HTTP;
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_HTTP))
|
||||
goto fail;
|
||||
|
||||
protocol = "http";
|
||||
}
|
||||
else if (p == uri + 6 && !strncmp("socks5", uri, 6))
|
||||
{
|
||||
settings->ProxyType = PROXY_TYPE_SOCKS;
|
||||
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_SOCKS))
|
||||
goto fail;
|
||||
protocol = "socks5";
|
||||
}
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now");
|
||||
return FALSE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
uri = p + 3;
|
||||
@ -320,7 +328,7 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
|
||||
else
|
||||
{
|
||||
WLog_ERR(TAG, "No scheme in proxy URI");
|
||||
return FALSE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
hostname = uri;
|
||||
@ -345,33 +353,28 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
|
||||
}
|
||||
|
||||
if (pport)
|
||||
{
|
||||
hostnamelen = pport - hostname;
|
||||
}
|
||||
else
|
||||
{
|
||||
hostnamelen = strlen(hostname);
|
||||
}
|
||||
*pport = '\0';
|
||||
|
||||
settings->ProxyHostname = calloc(hostnamelen + 1, 1);
|
||||
if (!freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, hostname))
|
||||
goto fail;
|
||||
|
||||
if (!settings->ProxyHostname)
|
||||
{
|
||||
WLog_ERR(TAG, "Not enough memory");
|
||||
return FALSE;
|
||||
}
|
||||
if (!freerdp_settings_set_uint16(settings, FreeRDP_ProxyPort, port))
|
||||
goto fail;
|
||||
|
||||
memcpy(settings->ProxyHostname, hostname, hostnamelen);
|
||||
settings->ProxyPort = port;
|
||||
WLog_INFO(TAG, "Parsed proxy configuration: %s://%s:%d", protocol, settings->ProxyHostname,
|
||||
settings->ProxyPort);
|
||||
return TRUE;
|
||||
WLog_INFO(TAG, "Parsed proxy configuration: %s://%s:%d", protocol,
|
||||
freerdp_settings_get_string(settings, FreeRDP_ProxyHostname),
|
||||
freerdp_settings_get_uint16(settings, FreeRDP_ProxyPort));
|
||||
rc = TRUE;
|
||||
|
||||
fail:
|
||||
free(uri_copy);
|
||||
return rc;
|
||||
}
|
||||
|
||||
BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername,
|
||||
const char* proxyPassword, const char* hostname, UINT16 port)
|
||||
{
|
||||
switch (settings->ProxyType)
|
||||
switch (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType))
|
||||
{
|
||||
case PROXY_TYPE_NONE:
|
||||
case PROXY_TYPE_IGNORE:
|
||||
|
Loading…
Reference in New Issue
Block a user