diff options
author | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-10-29 20:30:44 +0000 |
---|---|---|
committer | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-10-29 20:30:44 +0000 |
commit | 74f0bbfc53cb5fa519e4e27ece53735ab51b397c (patch) | |
tree | 0dbab9c835be15577ff05b474b6361bb326d66ce /src/libstrongswan/settings.c | |
parent | 5c1fa2516bda1ccf8eb00178c0beb196c2020a94 (diff) | |
download | vyos-strongswan-74f0bbfc53cb5fa519e4e27ece53735ab51b397c.tar.gz vyos-strongswan-74f0bbfc53cb5fa519e4e27ece53735ab51b397c.zip |
- New upstream release.
Diffstat (limited to 'src/libstrongswan/settings.c')
-rw-r--r-- | src/libstrongswan/settings.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/libstrongswan/settings.c b/src/libstrongswan/settings.c index 7c87dccd8..6f9e40395 100644 --- a/src/libstrongswan/settings.c +++ b/src/libstrongswan/settings.c @@ -203,8 +203,44 @@ static int get_int(private_settings_t *this, char *key, int def) } /** - * destry a section -*/ + * Implementation of settings_t.get_time. + */ +static u_int32_t get_time(private_settings_t *this, char *key, u_int32_t def) +{ + char *value, *endptr; + u_int32_t timeval; + + value = find(this->top, key); + if (value) + { + errno = 0; + timeval = strtol(value, &endptr, 10); + if (errno == 0 && timeval >= 0) + { + switch (*endptr) + { + case 'd': /* time in days */ + timeval *= 24 * 3600; + break; + case 'h': /* time in hours */ + timeval *= 3600; + break; + case 'm': /* time in minutes */ + timeval *= 60; + break; + case 's': /* time in seconds */ + default: + break; + } + return timeval; + } + } + return def; +} + +/** + * destroy a section + */ static void section_destroy(section_t *this) { this->kv->destroy_function(this->kv, free); @@ -365,7 +401,8 @@ settings_t *settings_create(char *file) private_settings_t *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, bool def))get_int; + 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; this->public.get_bool = (bool(*)(settings_t*, char *key, bool def))get_bool; this->public.destroy = (void(*)(settings_t*))destroy; |