libwinpr-utils: fix .ini parser whitespace trimming

This commit is contained in:
Marc-André Moreau 2014-03-25 00:32:05 -04:00
parent 43031d6b66
commit 64b550e18f
3 changed files with 113 additions and 10 deletions

View File

@ -241,9 +241,9 @@ int IniFile_Load(wIniFile* ini)
{ {
separator = strchr(line, '='); separator = strchr(line, '=');
end = separator - 1; end = separator;
while ((end > line) && ((end[-1] == ' ') || (end[-1] == '\t'))) while ((&end[-1] > line) && ((end[-1] == ' ') || (end[-1] == '\t')))
end--; end--;
*end = '\0'; *end = '\0';

View File

@ -3,7 +3,7 @@
#include <winpr/ini.h> #include <winpr/ini.h>
const char TEST_INI_FILE[] = const char TEST_INI_01[] =
"; This is a sample .ini config file\n" "; This is a sample .ini config file\n"
"\n" "\n"
"[first_section]\n" "[first_section]\n"
@ -16,6 +16,17 @@ const char TEST_INI_FILE[] =
"URL = \"http://www.example.com/~username\"\n" "URL = \"http://www.example.com/~username\"\n"
"\n"; "\n";
const char TEST_INI_02[] =
"[FreeRDS]\n"
"prefix=\"/usr/local\"\n"
"bindir=\"bin\"\n"
"sbindir=\"sbin\"\n"
"libdir=\"lib\"\n"
"datarootdir=\"share\"\n"
"localstatedir=\"var\"\n"
"sysconfdir=\"etc\"\n"
"\n";
int TestIni(int argc, char* argv[]) int TestIni(int argc, char* argv[])
{ {
int i, j; int i, j;
@ -27,9 +38,11 @@ int TestIni(int argc, char* argv[])
char** keyNames; char** keyNames;
char** sectionNames; char** sectionNames;
/* First Sample */
ini = IniFile_New(); ini = IniFile_New();
IniFile_ParseString(ini, TEST_INI_FILE); IniFile_ParseString(ini, TEST_INI_01);
sectionNames = IniFile_GetSectionNames(ini, &nSections); sectionNames = IniFile_GetSectionNames(ini, &nSections);
@ -92,6 +105,33 @@ int TestIni(int argc, char* argv[])
IniFile_Free(ini); IniFile_Free(ini);
/* Second Sample */
ini = IniFile_New();
IniFile_ParseString(ini, TEST_INI_02);
sectionNames = IniFile_GetSectionNames(ini, &nSections);
for (i = 0; i < nSections; i++)
{
keyNames = IniFile_GetSectionKeyNames(ini, sectionNames[i], &nKeys);
printf("[%s]\n", sectionNames[i]);
for (j = 0; j < nKeys; j++)
{
sValue = IniFile_GetKeyValueString(ini, sectionNames[i], keyNames[j]);
printf("%s = %s\n", keyNames[j], sValue);
}
free(keyNames);
}
free(sectionNames);
IniFile_Free(ini);
return 0; return 0;
} }

View File

@ -22,6 +22,8 @@
#endif #endif
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/ini.h>
#include <winpr/path.h>
#include <winpr/synch.h> #include <winpr/synch.h>
#include <winpr/library.h> #include <winpr/library.h>
#include <winpr/environment.h> #include <winpr/environment.h>
@ -395,17 +397,12 @@ BOOL WTSRegisterWtsApiFunctionTable(PWtsApiFunctionTable table)
return TRUE; return TRUE;
} }
void InitializeWtsApiStubs(void) void InitializeWtsApiStubs_Env()
{ {
DWORD nSize; DWORD nSize;
char* env = NULL; char* env = NULL;
INIT_WTSAPI_FN pInitWtsApi; INIT_WTSAPI_FN pInitWtsApi;
if (g_Initialized)
return;
g_Initialized = TRUE;
if (g_WtsApi) if (g_WtsApi)
return; return;
@ -430,3 +427,69 @@ void InitializeWtsApiStubs(void)
g_WtsApi = pInitWtsApi(); g_WtsApi = pInitWtsApi();
} }
} }
void InitializeWtsApiStubs_FreeRDS()
{
char* prefix;
char* libdir;
wIniFile* ini;
if (g_WtsApi)
return;
ini = IniFile_New();
if (IniFile_Parse(ini, "/var/run/freerds.instance") < 0)
{
printf("failed to parse freerds.instance\n");
}
prefix = IniFile_GetKeyValueString(ini, "FreeRDS", "prefix");
libdir = IniFile_GetKeyValueString(ini, "FreeRDS", "libdir");
printf("FreeRDS: %s / %s\n", prefix, libdir);
if (prefix && libdir)
{
char* prefix_libdir;
char* wtsapi_library;
prefix_libdir = GetCombinedPath(prefix, libdir);
wtsapi_library = GetCombinedPath(prefix_libdir, "libfreerds-fdsapi.so");
if (wtsapi_library)
{
INIT_WTSAPI_FN pInitWtsApi;
g_WtsApiModule = LoadLibraryA(wtsapi_library);
if (g_WtsApiModule)
{
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
if (pInitWtsApi)
{
g_WtsApi = pInitWtsApi();
}
}
}
free(prefix_libdir);
free(wtsapi_library);
}
IniFile_Free(ini);
}
void InitializeWtsApiStubs(void)
{
if (g_Initialized)
return;
g_Initialized = TRUE;
InitializeWtsApiStubs_Env();
if (!g_WtsApi)
InitializeWtsApiStubs_FreeRDS();
}