Added profile_get_boolean
authorMiro Jurisic <meeroh@mit.edu>
Fri, 24 Mar 2000 21:09:05 +0000 (21:09 +0000)
committerMiro Jurisic <meeroh@mit.edu>
Fri, 24 Mar 2000 21:09:05 +0000 (21:09 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12136 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/prof_err.et
src/util/profile/prof_get.c
src/util/profile/profile.exp
src/util/profile/profile.hin

index aec9f22fa08922a125a091ae2e19433eaba03593..d30a26b319fe3310d02bb3e15ee4d97f912fbc63 100644 (file)
@@ -1,3 +1,11 @@
+2000-03-24  Miro Jurisic  <meeroh@mit.edu>
+
+       * prof_get.c: Added prof_get_boolean and changed prof_get_integer
+       to return errors for malformed input
+       * prof.hin: Added prof_get_boolean
+       * profile.exp: Added prof_get_boolean
+       * prof_err.et: Added PROF_BAD_BOOLEAN, PROF_BAD_INTEGER
+
 Fri Jan 28 16:27:01 2000  Ezra Peisach  <epeisach@mit.edu>
 
        * argv_parse.c: Include string.h (for strlen prototype)
index e6e35db0acc4f37a737c8cc74d13b4da46c5f67f..dc248f417bfba7534f2d46e10b0c34ec2e3baf51 100644 (file)
@@ -54,4 +54,10 @@ error_code   PROF_FAIL_OPEN,         "Couldn't open profile file"
 #
 error_code     PROF_EXISTS,            "Section already exists"
 
+#
+# generated by prof_get.c
+#
+error_code     PROF_BAD_BOOLEAN,               "Invalid boolean value"
+error_code     PROF_BAD_INTEGER,               "Invalid integer value"
+
 end
index 2589b24e4b8efe5e504f32666cd3bca581a246df..cf8cef41fcd3aba01aff800108f7ab386205d0eb 100644 (file)
@@ -252,6 +252,8 @@ profile_get_integer(profile, name, subname, subsubname,
        const char      *value;
        errcode_t       retval;
        const char      *names[4];
+       const char *end_value;
+       long            ret_long;
 
        if (profile == 0) {
                *ret_int = def_val;
@@ -268,11 +270,85 @@ profile_get_integer(profile, name, subname, subsubname,
                return 0;
        } else if (retval)
                return retval;
+               
+       ret_long = strtol (value, &end_value, 10);
+       if ((errno != 0) || (end_value != value + strlen (value)) || 
+           (end_value == value) || (ret_long > INT_MAX) ||
+           (ret_long < INT_MIN)) {
+           return PROF_BAD_INTEGER;
+       }
+       
    
-       *ret_int = atoi(value);
+       *ret_int = ret_long;
        return 0;
 }
 
+static char *conf_yes[] = {
+    "y", "yes", "true", "t", "1", "on",
+    0,
+};
+
+static char *conf_no[] = {
+    "n", "no", "false", "nil", "0", "off",
+    0,
+};
+
+static errcode_t
+profile_parse_boolean(s, ret_boolean)
+     char *s;
+     int* ret_boolean;
+{
+    char **p;
+    
+    if (ret_boolean == NULL)
+       return PROF_EINVAL;
+
+    for(p=conf_yes; *p; p++) {
+       if (!strcasecmp(*p,s))
+               *ret_boolean = 1;
+           return 0;
+    }
+
+    for(p=conf_no; *p; p++) {
+       if (!strcasecmp(*p,s))
+               *ret_boolean = 0;
+           return 0;
+    }
+       
+       return PROF_BAD_BOOLEAN;
+}
+
+KRB5_DLLIMP errcode_t KRB5_CALLCONV
+profile_get_boolean(profile, name, subname, subsubname,
+                             def_val, ret_boolean)
+       profile_t       profile;
+       const char      *name, *subname, *subsubname;
+       int             def_val;
+       int             *ret_int;
+{
+       const char      *value;
+       errcode_t       retval;
+       const char      *names[4];
+
+       if (profile == 0) {
+               *ret_int = 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_int = def_val;
+               return 0;
+       } else if (retval)
+               return retval;
+   
+       return prof_parse_boolean (value, ret_int);
+}
+
 /*
  * This function will return the list of the names of subections in the
  * under the specified section name.
index 3eaeb1dfdf9faa3b390a1eb6c97d77e6191576a2..ade672adc07bf62e53bacc2b0fcc701f2d480afd 100644 (file)
@@ -11,6 +11,7 @@ profile_release
 profile_get_values
 profile_free_list
 profile_get_string
+profile_get_boolean
 profile_get_integer
 profile_get_relation_names
 profile_get_subsection_names
index f681f36f46b6d5a1f8123126525351f7cdd9a469..863f60d55f07d94c4ece637072dd38f92abf815a 100644 (file)
@@ -95,6 +95,11 @@ KRB5_DLLIMP long KRB5_CALLCONV profile_get_integer
                        const char *subsubname, int def_val,
                        int *ret_default));
 
+KRB5_DLLIMP long KRB5_CALLCONV profile_get_boolean
+       PROTOTYPE((profile_t profile, const char *name, const char *subname,
+                       const char *subsubname, int def_val,
+                       int *ret_default));
+
 KRB5_DLLIMP long KRB5_CALLCONV profile_get_relation_names
        PROTOTYPE((profile_t profile, const char **names, char ***ret_names));