pass NULL to library_init() to load settings from default file
This commit is contained in:
@@ -54,7 +54,8 @@ libstrongswan_la_LIBADD = -lpthread $(DLLIB) $(BTLIB) $(SOCKLIB) $(RTLIB)
|
||||
INCLUDES = -I$(top_srcdir)/src/libstrongswan
|
||||
AM_CFLAGS = \
|
||||
-DIPSEC_DIR=\"${ipsecdir}\" \
|
||||
-DPLUGINDIR=\"${plugindir}\"
|
||||
-DPLUGINDIR=\"${plugindir}\" \
|
||||
-DSTRONGSWAN_CONF=\"${strongswan_conf}\"
|
||||
|
||||
if USE_LEAK_DETECTIVE
|
||||
AM_CFLAGS += -DLEAK_DETECTIVE
|
||||
|
||||
@@ -484,8 +484,12 @@ static void destroy(private_settings_t *this)
|
||||
*/
|
||||
settings_t *settings_create(char *file)
|
||||
{
|
||||
private_settings_t *this = malloc_thing(private_settings_t);
|
||||
private_settings_t *this;
|
||||
char *pos;
|
||||
FILE *fd;
|
||||
int len;
|
||||
|
||||
this = malloc_thing(private_settings_t);
|
||||
this->public.get_str = (char*(*)(settings_t*, char *key, char* def, ...))get_str;
|
||||
this->public.get_int = (int(*)(settings_t*, char *key, int def, ...))get_int;
|
||||
this->public.get_time = (u_int32_t(*)(settings_t*, char *key, u_int32_t def, ...))get_time;
|
||||
@@ -496,39 +500,35 @@ settings_t *settings_create(char *file)
|
||||
this->top = NULL;
|
||||
this->text = NULL;
|
||||
|
||||
if (file)
|
||||
if (file == NULL)
|
||||
{
|
||||
FILE *fd;
|
||||
int len;
|
||||
char *pos;
|
||||
file = STRONGSWAN_CONF;
|
||||
}
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL)
|
||||
{
|
||||
DBG1("'%s' does not exist or is not readable", file);
|
||||
return &this->public;
|
||||
}
|
||||
fseek(fd, 0, SEEK_END);
|
||||
len = ftell(fd);
|
||||
rewind(fd);
|
||||
this->text = malloc(len + 1);
|
||||
this->text[len] = '\0';
|
||||
if (fread(this->text, 1, len, fd) != len)
|
||||
{
|
||||
free(this->text);
|
||||
this->text = NULL;
|
||||
return &this->public;
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
fd = fopen(file, "r");
|
||||
if (fd == NULL)
|
||||
{
|
||||
DBG1("'%s' does not exist or is not readable", file);
|
||||
return &this->public;
|
||||
}
|
||||
fseek(fd, 0, SEEK_END);
|
||||
len = ftell(fd);
|
||||
rewind(fd);
|
||||
this->text = malloc(len + 1);
|
||||
this->text[len] = '\0';
|
||||
if (fread(this->text, 1, len, fd) != len)
|
||||
{
|
||||
free(this->text);
|
||||
this->text = NULL;
|
||||
return &this->public;
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
pos = this->text;
|
||||
this->top = parse_section(&pos, NULL);
|
||||
if (this->top == NULL)
|
||||
{
|
||||
free(this->text);
|
||||
this->text = NULL;
|
||||
return &this->public;
|
||||
}
|
||||
pos = this->text;
|
||||
this->top = parse_section(&pos, NULL);
|
||||
if (this->top == NULL)
|
||||
{
|
||||
free(this->text);
|
||||
this->text = NULL;
|
||||
}
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,10 @@ struct settings_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* Load setings from a file.
|
||||
* Load settings from a file.
|
||||
*
|
||||
* @param file file to read settings from, NULL for default
|
||||
* @return settings object
|
||||
*/
|
||||
settings_t *settings_create(char *file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user