libfreerdp-client: add functions for getting/setting rdp file options

This commit is contained in:
Marc-André Moreau 2013-12-04 16:29:45 -05:00
parent 0ffc6a93ae
commit 4b341daa3d
3 changed files with 157 additions and 2 deletions

View File

@ -295,7 +295,7 @@ BOOL freerdp_client_rdp_file_set_string(rdpFile* file, char* name, char* value,
if (bStandard)
file->lines[index].flags |= RDP_FILE_LINE_FLAG_STANDARD;
file->lines[index].valueLength = strlen(file->lines[index].sValue);
file->lines[index].valueLength = 0;
}
return bStandard;
@ -313,8 +313,11 @@ void freerdp_client_add_option(rdpFile* file, char* option)
(file->argc)++;
}
void freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index)
int freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index)
{
if (index < 0)
index = file->lineCount;
while ((file->lineCount + 1) > file->lineSize)
{
file->lineSize *= 2;
@ -325,6 +328,8 @@ void freerdp_client_parse_rdp_file_add_line(rdpFile* file, char* line, int index
file->lines[file->lineCount].text = _strdup(line);
file->lines[file->lineCount].index = index;
(file->lineCount)++;
return index;
}
void freerdp_client_parse_rdp_file_add_line_unicode(rdpFile* file, WCHAR* line, int index)
@ -1057,6 +1062,137 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings*
return TRUE;
}
rdpFileLine* freerdp_client_rdp_file_find_line_index(rdpFile* file, int index)
{
rdpFileLine* line;
line = &(file->lines[index]);
return line;
}
rdpFileLine* freerdp_client_rdp_file_find_line_by_name(rdpFile* file, const char* name)
{
int index;
BOOL bFound = FALSE;
rdpFileLine* line = NULL;
for (index = 0; index < file->lineCount; index++)
{
line = &(file->lines[index]);
if (line->flags & RDP_FILE_LINE_FLAG_FORMATTED)
{
if (strcmp(name, line->name) == 0)
{
bFound = TRUE;
break;
}
}
}
return (bFound) ? line : NULL;
}
int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, const char* value)
{
int index;
int length;
char* text;
rdpFileLine* line;
line = freerdp_client_rdp_file_find_line_by_name(file, name);
length = _scprintf("%s:s:%s", name, value);
text = (char*) malloc(length + 1);
sprintf_s(text, length, "%s:s:%s", name, value);
text[length] = '\0';
if (line)
{
free(line->sValue);
line->sValue = _strdup(value);
free(line->text);
line->text = text;
}
else
{
index = freerdp_client_parse_rdp_file_add_line(file, text, -1);
line = freerdp_client_rdp_file_find_line_index(file, index);
freerdp_client_rdp_file_set_string(file, (char*) name, (char*) value, index);
free(text);
}
return 0;
}
char* freerdp_client_rdp_file_get_string_option(rdpFile* file, const char* name)
{
rdpFileLine* line;
line = freerdp_client_rdp_file_find_line_by_name(file, name);
if (!line)
return NULL;
if (!(line->flags & RDP_FILE_LINE_FLAG_TYPE_STRING))
return NULL;
return line->sValue;
}
int freerdp_client_rdp_file_set_integer_option(rdpFile* file, const char* name, int value)
{
int index;
int length;
char* text;
rdpFileLine* line;
line = freerdp_client_rdp_file_find_line_by_name(file, name);
length = _scprintf("%s:i:%d", name, value);
text = (char*) malloc(length + 1);
sprintf_s(text, length, "%s:i:%d", name, value);
text[length] = '\0';
if (line)
{
line->iValue = value;
free(line->text);
line->text = text;
}
else
{
index = freerdp_client_parse_rdp_file_add_line(file, text, -1);
line = freerdp_client_rdp_file_find_line_index(file, index);
freerdp_client_rdp_file_set_integer(file, (char*) name, value, index);
free(text);
}
return 0;
}
int freerdp_client_rdp_file_get_integer_option(rdpFile* file, const char* name)
{
rdpFileLine* line;
line = freerdp_client_rdp_file_find_line_by_name(file, name);
if (!line)
return -1;
if (!(line->flags & RDP_FILE_LINE_FLAG_TYPE_INTEGER))
return -1;
return line->iValue;
}
void freerdp_client_file_string_check_free(LPSTR str)
{
if (~((size_t) str))

View File

@ -263,6 +263,8 @@ static char testRdpFileUTF8[] =
int TestClientRdpFile(int argc, char* argv[])
{
int index;
int iValue;
char* sValue;
rdpFile* file;
rdpFileLine* line;
@ -328,6 +330,17 @@ int TestClientRdpFile(int argc, char* argv[])
return -1;
}
iValue = freerdp_client_rdp_file_get_integer_option(file, "vendor integer");
freerdp_client_rdp_file_set_integer_option(file, "vendor integer", 456);
iValue = freerdp_client_rdp_file_get_integer_option(file, "vendor integer");
sValue = freerdp_client_rdp_file_get_string_option(file, "vendor string");
freerdp_client_rdp_file_set_string_option(file, "vendor string", "apple");
sValue = freerdp_client_rdp_file_get_string_option(file, "vendor string");
freerdp_client_rdp_file_set_string_option(file, "fruits", "banana,oranges");
freerdp_client_rdp_file_set_integer_option(file, "numbers", 123456789);
for (index = 0; index < file->lineCount; index++)
{
line = &(file->lines[index]);

View File

@ -172,6 +172,12 @@ FREERDP_API BOOL freerdp_client_populate_rdp_file_from_settings(rdpFile* file, c
FREERDP_API BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, BOOL unicode);
FREERDP_API size_t freerdp_client_write_rdp_file_buffer(const rdpFile* file, char* buffer, size_t size);
FREERDP_API int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, const char* value);
FREERDP_API char* freerdp_client_rdp_file_get_string_option(rdpFile* file, const char* name);
FREERDP_API int freerdp_client_rdp_file_set_integer_option(rdpFile* file, const char* name, int value);
FREERDP_API int freerdp_client_rdp_file_get_integer_option(rdpFile* file, const char* name);
FREERDP_API rdpFile* freerdp_client_rdp_file_new(void);
FREERDP_API void freerdp_client_rdp_file_free(rdpFile* file);