From: Stephen D. <sd...@us...> - 2005-08-04 04:52:21
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24682/nsd Modified Files: config.c nsd.h Log Message: * include/ns.h: * nsd/nsd.h: * nsd/config.c: Add config value wrappers which handle defaults and in the case of integer values, range checking. Index: config.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/config.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** config.c 22 Jul 2005 06:41:24 -0000 1.3 --- config.c 4 Aug 2005 04:52:12 -0000 1.4 *************** *** 40,43 **** --- 40,45 ---- #define ISSLASH(c) ((c) == '/' || (c) == '\\') + #define _MAX(x,y) ((x) > (y) ? (x) : (y)) + #define _MIN(x,y) ((x) > (y) ? (y) : (x)) /* *************** *** 50,53 **** --- 52,174 ---- static char *ConfigGet(CONST char *section, CONST char *key, int exact); + + + /* + *---------------------------------------------------------------------- + * + * Ns_ConfigString -- + * + * Return a config file value, or the default if not found. + * + * Results: + * Pointer to value string. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + CONST char * + Ns_ConfigString(CONST char *section, CONST char *key, CONST char *def) + { + CONST char *value; + + value = Ns_ConfigGetValue(section, key); + if (value == NULL) { + value = def; + } + return value; + } + + + /* + *---------------------------------------------------------------------- + * + * Ns_ConfigBool -- + * + * Return a boolean config file value, or the default if not + * found. + * + * Results: + * NS_TRUE or NS_FALSE. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + int + Ns_ConfigBool(CONST char *section, CONST char *key, int def) + { + int value; + + if (!Ns_ConfigGetBool(section, key, &value)) { + value = def ? NS_TRUE : NS_FALSE; + } + return value; + } + + + /* + *---------------------------------------------------------------------- + * + * Ns_ConfigInt -- + * + * Return an integer config file value, or the default if not + * found. + * + * Results: + * An integer. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + int + Ns_ConfigInt(CONST char *section, CONST char *key, int def) + { + int value; + + if (!Ns_ConfigGetInt(section, key, &value)) { + value = def; + } + return value; + } + + + /* + *---------------------------------------------------------------------- + * + * Ns_ConfigIntRange -- + * + * Return an integer config file value, or the default if not + * found. The returned value will be between the given min and max. + * + * Results: + * An integer. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + int + Ns_ConfigIntRange(CONST char *section, CONST char *key, int def, + int min, int max) + { + int value; + + value = Ns_ConfigInt(section, key, def); + value = _MAX(value, min); + value = _MIN(value, max); + + return value; + } + /* Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** nsd.h 1 Aug 2005 16:22:25 -0000 1.29 --- nsd.h 4 Aug 2005 04:52:12 -0000 1.30 *************** *** 837,840 **** --- 837,848 ---- /* + * Global parameters. + */ + + #define NsParamString(key, def) Ns_ConfigString(NS_CONFIG_PARAMETERS, (key), (def)) + #define NsParamBool(key, def) Ns_ConfigBool(NS_CONFIG_PARAMETERS, (key), (def)) + #define NsParamInt(key, def) Ns_ConfigInt(NS_CONFIG_PARAMETERS, (key), (def)) + + /* * Libnsd initialization routines. */ |