diff options
author | Michael Adam <obnox@samba.org> | 2007-08-16 15:27:06 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:29:52 -0500 |
commit | bf374d3d3d12ed352ba8add9b5633855f2851c01 (patch) | |
tree | efe2fdf6d0144a1acd6b724e22443987d03d4477 /source3/param | |
parent | 93fc3a024820bd4a01565b301d37b0e4106500ac (diff) | |
download | samba-bf374d3d3d12ed352ba8add9b5633855f2851c01.tar.gz samba-bf374d3d3d12ed352ba8add9b5633855f2851c01.tar.bz2 samba-bf374d3d3d12ed352ba8add9b5633855f2851c01.zip |
r24495: Add a function lp_canonicalize_parameter: It takes a name of a parameter
and produces the "canonical" (or main) name of the parameter (the one
synonym that does not have the flag FLAG_HIDE). The function also sets
a flag as to whether the synonym is a reverse boolean synonym.
Add some functions for the handling of string representations of boolean
values: return the canonical string representation of a bool, invert
a bool given as a string, canonicalize a bool given as a string.
Michael
(This used to be commit 113ac07199aaf2271af6eba2611dad429ee4c416)
Diffstat (limited to 'source3/param')
-rw-r--r-- | source3/param/loadparm.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 2d64d541a0..0fd251c6f9 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -2191,6 +2191,7 @@ FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, &Globals.client_ldap_sasl_wrappi static int map_parameter(const char *pszParmName); static BOOL set_boolean(BOOL *pb, const char *pszParmValue); +static const char *get_boolean(BOOL bool_value); static int getservicebyname(const char *pszServiceName, service * pserviceDest); static void copy_service(service * pserviceDest, @@ -2813,6 +2814,49 @@ BOOL lp_parameter_is_global(const char *pszParmName) return False; } +/************************************************************************** + Determine the canonical name for a parameter. + Indicate when it is an inverse (boolean) synonym instead of a + "usual" synonym. +**************************************************************************/ + +BOOL lp_canonicalize_parameter(const char *parm_name, const char **canon_parm, + BOOL *inverse) +{ + int num, canon_num; + + if (!lp_parameter_is_valid(parm_name)) { + *canon_parm = NULL; + return False; + } + + *inverse = False; + num = map_parameter(parm_name); + if (num < 0 && !(parm_table[num].flags & FLAG_HIDE)) { + /* it is already canonical (parametric are canonical anyways) */ + *canon_parm = parm_name; + return True; + } + + for (canon_num = 0; parm_table[canon_num].label; canon_num++) { + if (!(parm_table[canon_num].flags & FLAG_HIDE) && + (parm_table[num].ptr == parm_table[canon_num].ptr)) + { + *canon_parm = parm_table[canon_num].label; + if ((parm_table[canon_num].type == P_BOOL) && + (parm_table[num].type == P_BOOLREV)) + { + *inverse = True; + } + return True; + } + } + + /* 'include', 'copy', 'config file' and friends left */ + *canon_parm = parm_name; + return True; +} + /*************************************************************************** Map a parameter's string representation to something we can use. Returns False if the parameter string is not recognised, else TRUE. @@ -2920,6 +2964,54 @@ static BOOL set_boolean(BOOL *pb, const char *pszParmValue) } /*************************************************************************** + Get the standard string representation of a boolean value ("yes" or "no") +***************************************************************************/ + +static const char *get_boolean(BOOL bool_value) +{ + static const char *yes_str = "yes"; + static const char *no_str = "no"; + + return (bool_value ? yes_str : no_str); +} + +/*************************************************************************** + Provide the string of the negated boolean value associated to the boolean + given as a string. Returns False if the passed string does not correctly + represent a boolean. +***************************************************************************/ + +BOOL lp_invert_boolean(const char *str, const char **inverse_str) +{ + BOOL val; + + if (!set_boolean(&val, str)) { + return False; + } + + *inverse_str = get_boolean(!val); + return True; +} + +/*************************************************************************** + Provide the canonical string representation of a boolean value given + as a string. Return True on success, False if the string given does + not correctly represent a boolean. +***************************************************************************/ + +BOOL lp_canonicalize_boolean(const char *str, const char**canon_str) +{ + BOOL val; + + if (!set_boolean(&val, str)) { + return False; + } + + *canon_str = get_boolean(val); + return True; +} + +/*************************************************************************** Find a service by name. Otherwise works like get_service. ***************************************************************************/ @@ -4321,6 +4413,22 @@ BOOL dump_a_parameter(int snum, char *parm_name, FILE * f, BOOL isGlobal) } /*************************************************************************** + Return info about the requested parameter (given as a string). + Return NULL when the string is not a valid parameter name. +***************************************************************************/ + +struct parm_struct *lp_get_parameter(const char *param_name) +{ + int num = map_parameter(param_name); + + if (num < 0) { + return NULL; + } + + return &parm_table[num]; +} + +/*************************************************************************** Return info about the next parameter in a service. snum==GLOBAL_SECTION_SNUM gives the globals. Return NULL when out of parameters. |