libfreerdp-client: add support for parsing command-line options from .rdp file
This commit is contained in:
parent
10f1a898ef
commit
4910a33f3c
@ -269,6 +269,18 @@ BOOL freerdp_client_rdp_file_set_string(rdpFile* file, char* name, char* value)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freerdp_client_add_option(rdpFile* file, char* option)
|
||||||
|
{
|
||||||
|
while ((file->argc + 1) > file->argSize)
|
||||||
|
{
|
||||||
|
file->argSize *= 2;
|
||||||
|
file->argv = (char**) realloc(file->argv, file->argSize * sizeof(char*));
|
||||||
|
}
|
||||||
|
|
||||||
|
file->argv[file->argc] = _strdup(option);
|
||||||
|
(file->argc)++;
|
||||||
|
}
|
||||||
|
|
||||||
void freerdp_client_parse_rdp_file_string_unicode(rdpFile* file, WCHAR* name, WCHAR* value)
|
void freerdp_client_parse_rdp_file_string_unicode(rdpFile* file, WCHAR* name, WCHAR* value)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
@ -296,6 +308,21 @@ void freerdp_client_parse_rdp_file_string_ascii(rdpFile* file, char* name, char*
|
|||||||
freerdp_client_rdp_file_set_string(file, name, value);
|
freerdp_client_rdp_file_set_string(file, name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freerdp_client_parse_rdp_file_option_unicode(rdpFile* file, WCHAR* option)
|
||||||
|
{
|
||||||
|
char* optionA = NULL;
|
||||||
|
|
||||||
|
ConvertFromUnicode(CP_UTF8, 0, option, -1, &optionA, 0, NULL, NULL);
|
||||||
|
freerdp_client_add_option(file, optionA);
|
||||||
|
|
||||||
|
free(optionA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void freerdp_client_parse_rdp_file_option_ascii(rdpFile* file, char* option)
|
||||||
|
{
|
||||||
|
freerdp_client_add_option(file, option);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, BYTE* buffer, size_t size)
|
BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, BYTE* buffer, size_t size)
|
||||||
{
|
{
|
||||||
int length;
|
int length;
|
||||||
@ -317,6 +344,12 @@ BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, BYTE* buffer, siz
|
|||||||
beg = line;
|
beg = line;
|
||||||
end = &line[length - 1];
|
end = &line[length - 1];
|
||||||
|
|
||||||
|
if (beg[0] == '/')
|
||||||
|
{
|
||||||
|
freerdp_client_parse_rdp_file_option_ascii(file, line);
|
||||||
|
goto next_line; /* FreeRDP option */
|
||||||
|
}
|
||||||
|
|
||||||
d1 = strchr(line, ':');
|
d1 = strchr(line, ':');
|
||||||
|
|
||||||
if (!d1)
|
if (!d1)
|
||||||
@ -383,6 +416,13 @@ BOOL freerdp_client_parse_rdp_file_buffer_unicode(rdpFile* file, BYTE* buffer, s
|
|||||||
beg = line;
|
beg = line;
|
||||||
end = &line[length - 1];
|
end = &line[length - 1];
|
||||||
|
|
||||||
|
if (beg[0] == '/')
|
||||||
|
{
|
||||||
|
/* FreeRDP option */
|
||||||
|
freerdp_client_parse_rdp_file_option_unicode(file, line);
|
||||||
|
goto next_line;
|
||||||
|
}
|
||||||
|
|
||||||
d1 = _wcschr(line, ':');
|
d1 = _wcschr(line, ':');
|
||||||
|
|
||||||
if (!d1)
|
if (!d1)
|
||||||
@ -533,7 +573,6 @@ BOOL freerdp_client_populate_rdp_file_from_settings(rdpFile* file, rdpSettings*
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL freerdp_client_write_rdp_file(rdpFile* file, const char* name, BOOL unicode)
|
BOOL freerdp_client_write_rdp_file(rdpFile* file, const char* name, BOOL unicode)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -543,6 +582,7 @@ BOOL freerdp_client_write_rdp_file(rdpFile* file, const char* name, BOOL unicode
|
|||||||
WCHAR* unicodestr = NULL;
|
WCHAR* unicodestr = NULL;
|
||||||
|
|
||||||
len = freerdp_client_write_rdp_file_buffer(file, NULL, 0);
|
len = freerdp_client_write_rdp_file_buffer(file, NULL, 0);
|
||||||
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "freerdp_client_write_rdp_file: Error determining buffer size.\n");
|
fprintf(stderr, "freerdp_client_write_rdp_file: Error determining buffer size.\n");
|
||||||
@ -551,9 +591,11 @@ BOOL freerdp_client_write_rdp_file(rdpFile* file, const char* name, BOOL unicode
|
|||||||
|
|
||||||
buffer = (char*) malloc((len + 1) * sizeof(char));
|
buffer = (char*) malloc((len + 1) * sizeof(char));
|
||||||
len2 = freerdp_client_write_rdp_file_buffer(file, buffer, len + 1);
|
len2 = freerdp_client_write_rdp_file_buffer(file, buffer, len + 1);
|
||||||
|
|
||||||
if (len2 == len)
|
if (len2 == len)
|
||||||
{
|
{
|
||||||
fp = fopen(name, "w+b");
|
fp = fopen(name, "w+b");
|
||||||
|
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
{
|
{
|
||||||
if (unicode)
|
if (unicode)
|
||||||
@ -665,7 +707,6 @@ size_t freerdp_client_write_rdp_file_buffer(rdpFile* file, char* buffer, size_t
|
|||||||
WRITE_RDP_FILE_VALUE_RETURN
|
WRITE_RDP_FILE_VALUE_RETURN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings)
|
BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings)
|
||||||
{
|
{
|
||||||
if (~((size_t) file->Domain))
|
if (~((size_t) file->Domain))
|
||||||
@ -913,6 +954,11 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
|
|||||||
freerdp_set_param_bool(settings, FreeRDP_RedirectDrives, TRUE);
|
freerdp_set_param_bool(settings, FreeRDP_RedirectDrives, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file->argc > 1)
|
||||||
|
{
|
||||||
|
freerdp_client_parse_command_line_arguments(file->argc, file->argv, settings);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,12 +967,35 @@ rdpFile* freerdp_client_rdp_file_new()
|
|||||||
rdpFile* file;
|
rdpFile* file;
|
||||||
|
|
||||||
file = (rdpFile*) malloc(sizeof(rdpFile));
|
file = (rdpFile*) malloc(sizeof(rdpFile));
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
FillMemory(file, sizeof(rdpFile), 0xFF);
|
FillMemory(file, sizeof(rdpFile), 0xFF);
|
||||||
|
|
||||||
|
file->argc = 0;
|
||||||
|
file->argSize = 32;
|
||||||
|
file->argv = (char**) malloc(file->argSize * sizeof(char*));
|
||||||
|
|
||||||
|
freerdp_client_add_option(file, "freerdp");
|
||||||
|
}
|
||||||
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freerdp_client_rdp_file_free(rdpFile* file)
|
void freerdp_client_rdp_file_free(rdpFile* file)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
if (file->argv)
|
||||||
|
{
|
||||||
|
for (i = 0; i < file->argc; i++)
|
||||||
|
free(file->argv[i]);
|
||||||
|
|
||||||
|
free(file->argv);
|
||||||
|
}
|
||||||
|
|
||||||
free(file);
|
free(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +129,10 @@ struct rdp_file
|
|||||||
LPSTR DrivesToRedirect; /* drivestoredirect */
|
LPSTR DrivesToRedirect; /* drivestoredirect */
|
||||||
LPSTR DevicesToRedirect; /* devicestoredirect */
|
LPSTR DevicesToRedirect; /* devicestoredirect */
|
||||||
LPSTR WinPosStr; /* winposstr */
|
LPSTR WinPosStr; /* winposstr */
|
||||||
|
|
||||||
|
int argc;
|
||||||
|
char** argv;
|
||||||
|
int argSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct rdp_file rdpFile;
|
typedef struct rdp_file rdpFile;
|
||||||
|
Loading…
Reference in New Issue
Block a user