From bf374d3d3d12ed352ba8add9b5633855f2851c01 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 16 Aug 2007 15:27:06 +0000 Subject: 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) --- source3/param/loadparm.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'source3/param') 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. @@ -2919,6 +2963,54 @@ static BOOL set_boolean(BOOL *pb, const char *pszParmValue) return (bRetval); } +/*************************************************************************** + 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. ***************************************************************************/ @@ -4320,6 +4412,22 @@ BOOL dump_a_parameter(int snum, char *parm_name, FILE * f, BOOL isGlobal) return result; } +/*************************************************************************** + 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. -- cgit