libfreerdp-client: fix parsing of port numbers in .rdp file full address, gatewayhostname options

This commit is contained in:
Marc-André Moreau 2014-06-12 10:49:29 -04:00
parent 9e14f5e164
commit 2da89cd8e5
3 changed files with 61 additions and 3 deletions

View File

@ -814,6 +814,38 @@ int freerdp_parse_username(char* username, char** user, char** domain)
return 0;
}
int freerdp_parse_hostname(char* hostname, char** host, int* port)
{
char* p;
int length;
p = strrchr(hostname, ':');
if (p)
{
length = (p - hostname);
*host = (char*) malloc(length + 1);
if (!(*host))
return -1;
CopyMemory(*host, hostname, length);
(*host)[length] = '\0';
*port = atoi(p + 1);
}
else
{
*host = _strdup(hostname);
if (!(*host))
return -1;
*port = -1;
}
return 0;
}
int freerdp_set_connection_type(rdpSettings* settings, int type)
{
settings->ConnectionType = type;

View File

@ -767,10 +767,23 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
free(domain);
}
if (~((size_t) file->FullAddress))
{
int port = -1;
char* host = NULL;
freerdp_parse_hostname(file->FullAddress, &host, &port);
freerdp_set_param_string(settings, FreeRDP_ServerHostname, host);
if (port > 0)
freerdp_set_param_uint32(settings, FreeRDP_ServerPort, (UINT32) port);
free(host);
}
if (~file->ServerPort)
freerdp_set_param_uint32(settings, FreeRDP_ServerPort, file->ServerPort);
if (~((size_t) file->FullAddress))
freerdp_set_param_string(settings, FreeRDP_ServerHostname, file->FullAddress);
if (~file->DesktopWidth)
freerdp_set_param_uint32(settings, FreeRDP_DesktopWidth, file->DesktopWidth);
@ -867,7 +880,19 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
freerdp_set_param_bool(settings, FreeRDP_CompressionEnabled, file->Compression);
if (~((size_t) file->GatewayHostname))
freerdp_set_param_string(settings, FreeRDP_GatewayHostname, file->GatewayHostname);
{
int port = -1;
char* host = NULL;
freerdp_parse_hostname(file->GatewayHostname, &host, &port);
freerdp_set_param_string(settings, FreeRDP_GatewayHostname, host);
if (port > 0)
freerdp_set_param_uint32(settings, FreeRDP_GatewayPort, (UINT32) port);
free(host);
}
if (~file->GatewayUsageMethod)
freerdp_set_gateway_usage_method(settings, file->GatewayUsageMethod);

View File

@ -35,6 +35,7 @@ FREERDP_API int freerdp_client_print_version(void);
FREERDP_API int freerdp_client_print_command_line_help(int argc, char** argv);
FREERDP_API int freerdp_parse_username(char* username, char** user, char** domain);
FREERDP_API int freerdp_parse_hostname(char* hostname, char** host, int* port);
FREERDP_API int freerdp_set_connection_type(rdpSettings* settings, int type);
FREERDP_API int freerdp_client_add_device_channel(rdpSettings* settings, int count, char** params);