summaryrefslogtreecommitdiffstats
path: root/src/util/profile/prof_get.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2009-12-07 22:36:41 +0000
committerTom Yu <tlyu@mit.edu>2009-12-07 22:36:41 +0000
commitac911f663389980be59a0f9ee98f062e6c627658 (patch)
treec423ac7174c1a82a107013894a6944a506e68774 /src/util/profile/prof_get.c
parent741938feb12538b659a36d7e0329efe6a5550669 (diff)
downloadkrb5-ac911f663389980be59a0f9ee98f062e6c627658.tar.gz
krb5-ac911f663389980be59a0f9ee98f062e6c627658.tar.xz
krb5-ac911f663389980be59a0f9ee98f062e6c627658.zip
Mark and reindent util, with some exceptions
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23455 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/prof_get.c')
-rw-r--r--src/util/profile/prof_get.c551
1 files changed, 276 insertions, 275 deletions
diff --git a/src/util/profile/prof_get.c b/src/util/profile/prof_get.c
index 87861fce38..460d2e5f21 100644
--- a/src/util/profile/prof_get.c
+++ b/src/util/profile/prof_get.c
@@ -1,6 +1,7 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* prof_get.c --- routines that expose the public interfaces for
- * querying items from the profile.
+ * querying items from the profile.
*
*/
@@ -27,9 +28,9 @@
*/
struct profile_string_list {
- char **list;
- unsigned int num;
- unsigned int max;
+ char **list;
+ unsigned int num;
+ unsigned int max;
};
/*
@@ -37,13 +38,13 @@ struct profile_string_list {
*/
static errcode_t init_list(struct profile_string_list *list)
{
- list->num = 0;
- list->max = 10;
- list->list = malloc(list->max * sizeof(char *));
- if (list->list == 0)
- return ENOMEM;
- list->list[0] = 0;
- return 0;
+ list->num = 0;
+ list->max = 10;
+ list->list = malloc(list->max * sizeof(char *));
+ if (list->list == 0)
+ return ENOMEM;
+ list->list[0] = 0;
+ return 0;
}
/*
@@ -52,21 +53,21 @@ static errcode_t init_list(struct profile_string_list *list)
*/
static void end_list(struct profile_string_list *list, char ***ret_list)
{
- char **cp;
-
- if (list == 0)
- return;
-
- if (ret_list) {
- *ret_list = list->list;
- return;
- } else {
- for (cp = list->list; *cp; cp++)
- free(*cp);
- free(list->list);
- }
- list->num = list->max = 0;
- list->list = 0;
+ char **cp;
+
+ if (list == 0)
+ return;
+
+ if (ret_list) {
+ *ret_list = list->list;
+ return;
+ } else {
+ for (cp = list->list; *cp; cp++)
+ free(*cp);
+ free(list->list);
+ }
+ list->num = list->max = 0;
+ list->list = 0;
}
/*
@@ -74,24 +75,24 @@ static void end_list(struct profile_string_list *list, char ***ret_list)
*/
static errcode_t add_to_list(struct profile_string_list *list, const char *str)
{
- char *newstr, **newlist;
- unsigned int newmax;
-
- if (list->num+1 >= list->max) {
- newmax = list->max + 10;
- newlist = realloc(list->list, newmax * sizeof(char *));
- if (newlist == 0)
- return ENOMEM;
- list->max = newmax;
- list->list = newlist;
- }
- newstr = strdup(str);
- if (newstr == 0)
- return ENOMEM;
-
- list->list[list->num++] = newstr;
- list->list[list->num] = 0;
- return 0;
+ char *newstr, **newlist;
+ unsigned int newmax;
+
+ if (list->num+1 >= list->max) {
+ newmax = list->max + 10;
+ newlist = realloc(list->list, newmax * sizeof(char *));
+ if (newlist == 0)
+ return ENOMEM;
+ list->max = newmax;
+ list->list = newlist;
+ }
+ newstr = strdup(str);
+ if (newstr == 0)
+ return ENOMEM;
+
+ list->list[list->num++] = newstr;
+ list->list[list->num] = 0;
+ return 0;
}
/*
@@ -99,16 +100,16 @@ static errcode_t add_to_list(struct profile_string_list *list, const char *str)
*/
static int is_list_member(struct profile_string_list *list, const char *str)
{
- char **cpp;
+ char **cpp;
- if (!list->list)
- return 0;
+ if (!list->list)
+ return 0;
- for (cpp = list->list; *cpp; cpp++) {
- if (!strcmp(*cpp, str))
- return 1;
- }
- return 0;
+ for (cpp = list->list; *cpp; cpp++) {
+ if (!strcmp(*cpp, str))
+ return 1;
+ }
+ return 0;
}
/*
@@ -117,51 +118,51 @@ static int is_list_member(struct profile_string_list *list, const char *str)
*/
void KRB5_CALLCONV profile_free_list(char **list)
{
- char **cp;
+ char **cp;
if (list == 0)
- return;
+ return;
for (cp = list; *cp; cp++)
- free(*cp);
+ free(*cp);
free(list);
}
errcode_t KRB5_CALLCONV
profile_get_values(profile_t profile, const char *const *names,
- char ***ret_values)
+ char ***ret_values)
{
- errcode_t retval;
- void *state;
- char *value;
- struct profile_string_list values;
-
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
-
- if ((retval = init_list(&values)))
- return retval;
-
- do {
- if ((retval = profile_node_iterator(&state, 0, 0, &value)))
- goto cleanup;
- if (value)
- add_to_list(&values, value);
- } while (state);
-
- if (values.num == 0) {
- retval = PROF_NO_RELATION;
- goto cleanup;
- }
-
- end_list(&values, ret_values);
- return 0;
+ errcode_t retval;
+ void *state;
+ char *value;
+ struct profile_string_list values;
+
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
+
+ if ((retval = init_list(&values)))
+ return retval;
+
+ do {
+ if ((retval = profile_node_iterator(&state, 0, 0, &value)))
+ goto cleanup;
+ if (value)
+ add_to_list(&values, value);
+ } while (state);
+
+ if (values.num == 0) {
+ retval = PROF_NO_RELATION;
+ goto cleanup;
+ }
+
+ end_list(&values, ret_values);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
/*
@@ -169,105 +170,105 @@ cleanup:
* helper function for profile_get_string, profile_get_integer, etc.
*/
errcode_t profile_get_value(profile_t profile, const char **names,
- const char **ret_value)
+ const char **ret_value)
{
- errcode_t retval;
- void *state;
- char *value;
+ errcode_t retval;
+ void *state;
+ char *value;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = profile_node_iterator(&state, 0, 0, &value)))
- goto cleanup;
+ if ((retval = profile_node_iterator(&state, 0, 0, &value)))
+ goto cleanup;
- if (value)
- *ret_value = value;
- else
- retval = PROF_NO_RELATION;
+ if (value)
+ *ret_value = value;
+ else
+ retval = PROF_NO_RELATION;
cleanup:
- profile_node_iterator_free(&state);
- return retval;
+ profile_node_iterator_free(&state);
+ return retval;
}
errcode_t KRB5_CALLCONV
profile_get_string(profile_t profile, const char *name, const char *subname,
- const char *subsubname, const char *def_val,
- char **ret_string)
+ const char *subsubname, const char *def_val,
+ char **ret_string)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
-
- if (profile) {
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- retval = profile_get_value(profile, names, &value);
- if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION)
- value = def_val;
- else if (retval)
- return retval;
- } else
- value = def_val;
-
- if (value) {
- *ret_string = strdup(value);
- if (*ret_string == 0)
- return ENOMEM;
- } else
- *ret_string = 0;
- return 0;
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+
+ if (profile) {
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION)
+ value = def_val;
+ else if (retval)
+ return retval;
+ } else
+ value = def_val;
+
+ if (value) {
+ *ret_string = strdup(value);
+ if (*ret_string == 0)
+ return ENOMEM;
+ } else
+ *ret_string = 0;
+ return 0;
}
errcode_t KRB5_CALLCONV
profile_get_integer(profile_t profile, const char *name, const char *subname,
- const char *subsubname, int def_val, int *ret_int)
+ const char *subsubname, int def_val, int *ret_int)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
- char *end_value;
- long ret_long;
-
- *ret_int = def_val;
- if (profile == 0)
- return 0;
-
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- 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;
-
- if (value[0] == 0)
- /* Empty string is no good. */
- return PROF_BAD_INTEGER;
- errno = 0;
- ret_long = strtol (value, &end_value, 10);
-
- /* Overflow or underflow. */
- if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0)
- return PROF_BAD_INTEGER;
- /* Value outside "int" range. */
- if ((long) (int) ret_long != ret_long)
- return PROF_BAD_INTEGER;
- /* Garbage in string. */
- if (end_value != value + strlen (value))
- return PROF_BAD_INTEGER;
-
-
- *ret_int = ret_long;
- return 0;
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+ char *end_value;
+ long ret_long;
+
+ *ret_int = def_val;
+ if (profile == 0)
+ return 0;
+
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ 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;
+
+ if (value[0] == 0)
+ /* Empty string is no good. */
+ return PROF_BAD_INTEGER;
+ errno = 0;
+ ret_long = strtol (value, &end_value, 10);
+
+ /* Overflow or underflow. */
+ if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0)
+ return PROF_BAD_INTEGER;
+ /* Value outside "int" range. */
+ if ((long) (int) ret_long != ret_long)
+ return PROF_BAD_INTEGER;
+ /* Garbage in string. */
+ if (end_value != value + strlen (value))
+ return PROF_BAD_INTEGER;
+
+
+ *ret_int = ret_long;
+ return 0;
}
static const char *const conf_yes[] = {
@@ -286,50 +287,50 @@ profile_parse_boolean(const char *s, int *ret_boolean)
const char *const *p;
if (ret_boolean == NULL)
- return PROF_EINVAL;
+ return PROF_EINVAL;
for(p=conf_yes; *p; p++) {
- if (!strcasecmp(*p,s)) {
- *ret_boolean = 1;
- return 0;
- }
+ if (!strcasecmp(*p,s)) {
+ *ret_boolean = 1;
+ return 0;
+ }
}
for(p=conf_no; *p; p++) {
- if (!strcasecmp(*p,s)) {
- *ret_boolean = 0;
- return 0;
- }
+ if (!strcasecmp(*p,s)) {
+ *ret_boolean = 0;
+ return 0;
+ }
}
- return PROF_BAD_BOOLEAN;
+ return PROF_BAD_BOOLEAN;
}
errcode_t KRB5_CALLCONV
profile_get_boolean(profile_t profile, const char *name, const char *subname,
- const char *subsubname, int def_val, int *ret_boolean)
+ const char *subsubname, int def_val, int *ret_boolean)
{
- const char *value;
- errcode_t retval;
- const char *names[4];
-
- if (profile == 0) {
- *ret_boolean = def_val;
- return 0;
- }
-
- names[0] = name;
- names[1] = subname;
- names[2] = subsubname;
- names[3] = 0;
- retval = profile_get_value(profile, names, &value);
- if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
- *ret_boolean = def_val;
- return 0;
- } else if (retval)
- return retval;
-
- return profile_parse_boolean (value, ret_boolean);
+ const char *value;
+ errcode_t retval;
+ const char *names[4];
+
+ if (profile == 0) {
+ *ret_boolean = def_val;
+ return 0;
+ }
+
+ names[0] = name;
+ names[1] = subname;
+ names[2] = subsubname;
+ names[3] = 0;
+ retval = profile_get_value(profile, names, &value);
+ if (retval == PROF_NO_SECTION || retval == PROF_NO_RELATION) {
+ *ret_boolean = def_val;
+ return 0;
+ } else if (retval)
+ return retval;
+
+ return profile_parse_boolean (value, ret_boolean);
}
/*
@@ -338,34 +339,34 @@ profile_get_boolean(profile_t profile, const char *name, const char *subname,
*/
errcode_t KRB5_CALLCONV
profile_get_subsection_names(profile_t profile, const char **names,
- char ***ret_names)
+ char ***ret_names)
{
- errcode_t retval;
- void *state;
- char *name;
- struct profile_string_list values;
+ errcode_t retval;
+ void *state;
+ char *name;
+ struct profile_string_list values;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = init_list(&values)))
- return retval;
+ if ((retval = init_list(&values)))
+ return retval;
- do {
- if ((retval = profile_node_iterator(&state, 0, &name, 0)))
- goto cleanup;
- if (name)
- add_to_list(&values, name);
- } while (state);
+ do {
+ if ((retval = profile_node_iterator(&state, 0, &name, 0)))
+ goto cleanup;
+ if (name)
+ add_to_list(&values, name);
+ } while (state);
- end_list(&values, ret_names);
- return 0;
+ end_list(&values, ret_names);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
/*
@@ -374,85 +375,85 @@ cleanup:
*/
errcode_t KRB5_CALLCONV
profile_get_relation_names(profile_t profile, const char **names,
- char ***ret_names)
+ char ***ret_names)
{
- errcode_t retval;
- void *state;
- char *name;
- struct profile_string_list values;
+ errcode_t retval;
+ void *state;
+ char *name;
+ struct profile_string_list values;
- if ((retval = profile_node_iterator_create(profile, names,
- PROFILE_ITER_LIST_SECTION | PROFILE_ITER_RELATIONS_ONLY,
- &state)))
- return retval;
+ if ((retval = profile_node_iterator_create(profile, names,
+ PROFILE_ITER_LIST_SECTION | PROFILE_ITER_RELATIONS_ONLY,
+ &state)))
+ return retval;
- if ((retval = init_list(&values)))
- return retval;
+ if ((retval = init_list(&values)))
+ return retval;
- do {
- if ((retval = profile_node_iterator(&state, 0, &name, 0)))
- goto cleanup;
- if (name && !is_list_member(&values, name))
- add_to_list(&values, name);
- } while (state);
+ do {
+ if ((retval = profile_node_iterator(&state, 0, &name, 0)))
+ goto cleanup;
+ if (name && !is_list_member(&values, name))
+ add_to_list(&values, name);
+ } while (state);
- end_list(&values, ret_names);
- return 0;
+ end_list(&values, ret_names);
+ return 0;
cleanup:
- end_list(&values, 0);
- return retval;
+ end_list(&values, 0);
+ return retval;
}
errcode_t KRB5_CALLCONV
profile_iterator_create(profile_t profile, const char *const *names, int flags,
- void **ret_iter)
+ void **ret_iter)
{
- return profile_node_iterator_create(profile, names, flags, ret_iter);
+ return profile_node_iterator_create(profile, names, flags, ret_iter);
}
void KRB5_CALLCONV
profile_iterator_free(void **iter_p)
{
- profile_node_iterator_free(iter_p);
+ profile_node_iterator_free(iter_p);
}
errcode_t KRB5_CALLCONV
profile_iterator(void **iter_p, char **ret_name, char **ret_value)
{
- char *name, *value;
- errcode_t retval;
-
- retval = profile_node_iterator(iter_p, 0, &name, &value);
- if (retval)
- return retval;
-
- if (ret_name) {
- if (name) {
- *ret_name = strdup(name);
- if (!*ret_name)
- return ENOMEM;
- } else
- *ret_name = 0;
- }
- if (ret_value) {
- if (value) {
- *ret_value = strdup(value);
- if (!*ret_value) {
- if (ret_name) {
- free(*ret_name);
- *ret_name = 0;
- }
- return ENOMEM;
- }
- } else
- *ret_value = 0;
- }
- return 0;
+ char *name, *value;
+ errcode_t retval;
+
+ retval = profile_node_iterator(iter_p, 0, &name, &value);
+ if (retval)
+ return retval;
+
+ if (ret_name) {
+ if (name) {
+ *ret_name = strdup(name);
+ if (!*ret_name)
+ return ENOMEM;
+ } else
+ *ret_name = 0;
+ }
+ if (ret_value) {
+ if (value) {
+ *ret_value = strdup(value);
+ if (!*ret_value) {
+ if (ret_name) {
+ free(*ret_name);
+ *ret_name = 0;
+ }
+ return ENOMEM;
+ }
+ } else
+ *ret_value = 0;
+ }
+ return 0;
}
void KRB5_CALLCONV
profile_release_string(char *str)
{
- free(str);
+ free(str);
}