diff options
author | Theodore Tso <tytso@mit.edu> | 1995-04-21 01:18:51 +0000 |
---|---|---|
committer | Theodore Tso <tytso@mit.edu> | 1995-04-21 01:18:51 +0000 |
commit | c8c8392ae815d9226e653304c7c7c99b2a98bf33 (patch) | |
tree | 68040be4589d2e5a203497f1f85b292e467ee9a8 /src/util | |
parent | 409c50ae2b901f93b706b3b7674766457294b711 (diff) | |
download | krb5-c8c8392ae815d9226e653304c7c7c99b2a98bf33.tar.gz krb5-c8c8392ae815d9226e653304c7c7c99b2a98bf33.tar.xz krb5-c8c8392ae815d9226e653304c7c7c99b2a98bf33.zip |
Add new functions profile_get_string() and profile_get_integer(), for
the simple case of pulling a single string or integer from the config file.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5418 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/profile/prof_init.c | 85 | ||||
-rw-r--r-- | src/util/profile/profile.h.in | 8 |
2 files changed, 91 insertions, 2 deletions
diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c index de3c3b71a..f27773706 100644 --- a/src/util/profile/prof_init.c +++ b/src/util/profile/prof_init.c @@ -119,11 +119,11 @@ errcode_t profile_get_values(profile, names, ret_values) { prf_file_t file; errcode_t retval; - struct profile_node *parent, *section; + struct profile_node *section; void *state; char *value; struct string_list values; - char **cpp; + const char **cpp; if (names == 0 || names[0] == 0 || names[1] == 0) return PROF_BAD_NAMESET; @@ -156,3 +156,84 @@ cleanup: return retval; } +/* + * XXX this version only works to get values from the first file. + */ +static errcode_t profile_get_value(profile, names, ret_value) + profile_t profile; + const char **names; + char **ret_value; +{ + prf_file_t file; + errcode_t retval; + struct profile_node *section; + void *state; + char *value; + const char **cpp; + + if (names == 0 || names[0] == 0 || names[1] == 0) + return PROF_BAD_NAMESET; + + file = profile->first_file; + section = file->root; + + for (cpp = names; cpp[1]; cpp++) { + state = 0; + retval = profile_find_node_subsection(section, *cpp, + &state, 0, §ion); + if (retval) + goto cleanup; + } + + state = 0; + retval = profile_find_node_relation(section, *cpp, &state, 0, &value); + if (retval) + goto cleanup; + + *ret_value = value; + return 0; +cleanup: + return retval; +} + +errcode_t profile_get_string(profile, names, def_val, ret_string) + profile_t profile; + const char **names; + const char *def_val; + char **ret_string; +{ + const char *value; + errcode_t retval; + + retval = profile_get_value(profile, names, &value); + if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) + value = def_val; + else if (retval) + return retval; + + *ret_string = malloc(strlen(value)+1); + if (*ret_string == 0) + return ENOMEM; + strcpy(*ret_string, value); + return 0; +} + +errcode_t profile_get_integer(profile, names, def_val, ret_int) + profile_t profile; + const char **names; + int def_val; + int *ret_int; +{ + char *value; + errcode_t retval; + + retval = profile_get_value(profile, names, &value); + if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) { + *ret_int = def_val; + return 0; + } else if (retval) + return retval; + + *ret_int = atoi(value); + return 0; +} diff --git a/src/util/profile/profile.h.in b/src/util/profile/profile.h.in index d157d2262..afa2a3032 100644 --- a/src/util/profile/profile.h.in +++ b/src/util/profile/profile.h.in @@ -18,3 +18,11 @@ extern void profile_release extern long profile_get_values PROTOTYPE ((profile_t profile, const char **names, char ***ret_values)); + +extern long profile_get_string + PROTOTYPE((profile_t profile, const char **names, const char *def_val, + char **ret_string)); +extern long profile_get_integer + PROTOTYPE((profile_t profile, const char **names, int def_val, + int *ret_default)); + |