From bb76f3f98ed2e49ad4114a34a2a7fa0e6655f33d Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 17 Aug 2007 15:38:19 +0000 Subject: [PATCH] r24526: Refactor determiniation of the index of the canonical form of a parameter given in string representation into a function of its own (map_parameter_canonical). Michael (This used to be commit 0dfb5eee25e287c129f7d34e4d079c60d56dce59) --- source3/param/loadparm.c | 50 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index c867c5f5082..ea1bb0a23f4 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -2190,6 +2190,7 @@ FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, &Globals.client_ldap_sasl_wrappi /* local prototypes */ static int map_parameter(const char *pszParmName); +static int map_parameter_canonical(const char *pszParmName, BOOL *inverse); static BOOL set_boolean(BOOL *pb, const char *pszParmValue); static const char *get_boolean(BOOL bool_value); static int getservicebyname(const char *pszServiceName, @@ -2825,31 +2826,23 @@ BOOL lp_parameter_is_global(const char *pszParmName) BOOL lp_canonicalize_parameter(const char *parm_name, const char **canon_parm, BOOL *inverse) { - int num, canon_num; + int 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) */ + num = map_parameter_canonical(parm_name, inverse); + if (num < 0) { + /* parametric option */ *canon_parm = parm_name; - return True; + } else { + *canon_parm = parm_table[num].label; } - for (canon_num = 0; parm_table[canon_num].label; canon_num++) { - if (is_synonym_of(num, canon_num, inverse)) { - *canon_parm = parm_table[canon_num].label; - return True; - } - } - - /* 'include', 'copy', 'config file' and friends left */ - *canon_parm = parm_name; return True; + } /*************************************************************************** @@ -2877,6 +2870,33 @@ static int map_parameter(const char *pszParmName) return (-1); } +/*************************************************************************** + Map a parameter's string representation to the index of the canonical + form of the parameter (it might be a synonym). + Returns -1 if the parameter string is not recognised. +***************************************************************************/ + +static int map_parameter_canonical(const char *pszParmName, BOOL *inverse) +{ + int parm_num, canon_num; + + *inverse = False; + + parm_num = map_parameter(pszParmName); + if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_HIDE)) { + /* invalid, parametric or no canidate for synonyms ... */ + return parm_num; + } + + for (canon_num = 0; parm_table[canon_num].label; canon_num++) { + if (is_synonym_of(parm_num, canon_num, inverse)) { + return canon_num; + } + } + + return parm_num; +} + /*************************************************************************** return true if parameter number parm1 is a synonym of parameter number parm2 (parm2 being the principal name).