From: Stephen D. <sd...@us...> - 2005-10-16 08:52:56
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23373/nsd Modified Files: config.c driver.c log.c nsconf.c nsd.h nsmain.c Log Message: * nsd/config.c: Log the section, key, value and any default, min or max whenever a configuration value is looked up. Log at level Debug which by default is off. Can now quickly determine which config keys are valid/used. * nsd/nsmain.c: * nsd/nsconf.c: * nsd/log.c: Initialise log system earlier -- dissable Dev and Debug log levels during early boot up. * nsd/driver.c: * nsd/nsd.h: Some logging cleanup. Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** nsd.h 9 Oct 2005 22:27:24 -0000 1.35 --- nsd.h 16 Oct 2005 08:52:48 -0000 1.36 *************** *** 594,598 **** bool enabled; int opts; /* NSD_STRIP_WWW | NSD_STRIP_PORT */ ! char *hostprefix; int hosthashlevel; Ns_ServerRootProc *serverRootProc; --- 594,598 ---- bool enabled; int opts; /* NSD_STRIP_WWW | NSD_STRIP_PORT */ ! CONST char *hostprefix; int hosthashlevel; Ns_ServerRootProc *serverRootProc; Index: config.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/config.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** config.c 9 Oct 2005 04:42:30 -0000 1.6 --- config.c 16 Oct 2005 08:52:48 -0000 1.7 *************** *** 49,52 **** --- 49,53 ---- static Ns_Set *GetSection(CONST char *section, int create); static char *ConfigGet(CONST char *section, CONST char *key, int exact); + static int ToBool(CONST char *value, int *valuePtr); *************** *** 73,81 **** CONST char *value; ! value = Ns_ConfigGetValue(section, key); ! if (value == NULL) { ! value = def; ! } ! return value; } --- 74,82 ---- CONST char *value; ! value = ConfigGet(section, key, 0); ! Ns_Log(Debug, "config: %s:%s value=\"%s\" default=\"%s\" (string)", ! section, key, value, def); ! ! return value ? value : def; } *************** *** 101,110 **** 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; } --- 102,118 ---- Ns_ConfigBool(CONST char *section, CONST char *key, int def) { ! CONST char *s; ! int value, found = NS_FALSE; ! s = ConfigGet(section, key, 0); ! if (s != NULL && ToBool(s, &value)) { ! found = NS_TRUE; } ! Ns_Log(Debug, "config: %s:%s value=%s default=%s (bool)", ! section, key, ! found ? (value ? "true" : "false") : "(null)", ! def ? "true" : "false"); ! ! return found ? value : def; } *************** *** 113,120 **** *---------------------------------------------------------------------- * ! * Ns_ConfigInt -- * * Return an integer config file value, or the default if not ! * found. * * Results: --- 121,128 ---- *---------------------------------------------------------------------- * ! * Ns_ConfigInt, 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: *************** *** 122,126 **** * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 130,134 ---- * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 130,169 **** 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; } --- 138,170 ---- Ns_ConfigInt(CONST char *section, CONST char *key, int def) { ! return Ns_ConfigIntRange(section, key, def, INT_MIN, INT_MAX); } int Ns_ConfigIntRange(CONST char *section, CONST char *key, int def, int min, int max) { + CONST char *s; int value; ! s = ConfigGet(section, key, 0); ! if (s != NULL && Ns_StrToInt(s, &value) == NS_OK) { ! Ns_Log(Debug, "config: %s:%s value=%d min=%d max=%d default=%d (int)", ! section, key, value, min, max, def); ! } else { ! Ns_Log(Debug, "config: %s:%s value=(null) min=%d max=%d default=%d (int)", ! section, key, min, max, def); ! value = def; ! } ! if (value < min) { ! Ns_Log(Warning, "config: %s:%s value=%d, rounded up to %d", ! section, key, value, min); ! value = min; ! } ! if (value > max) { ! Ns_Log(Warning, "config: %s:%s value=%d, rounded down to %d", ! section, key, value, max); ! value = max; ! } return value; } *************** *** 189,193 **** Ns_ConfigGetValue(CONST char *section, CONST char *key) { ! return ConfigGet(section, key, 0); } --- 190,200 ---- Ns_ConfigGetValue(CONST char *section, CONST char *key) { ! char *value; ! ! value = ConfigGet(section, key, 0); ! Ns_Log(Debug, "config: %s:%s value=%s (string)", ! section, key, value); ! ! return value; } *************** *** 212,216 **** Ns_ConfigGetValueExact(CONST char *section, CONST char *key) { ! return ConfigGet(section, key, 1); } --- 219,229 ---- Ns_ConfigGetValueExact(CONST char *section, CONST char *key) { ! char *value; ! ! value = ConfigGet(section, key, 1); ! Ns_Log(Debug, "config: %s:%s value=%s (string, exact match)", ! section, key, value); ! ! return value; } *************** *** 236,246 **** Ns_ConfigGetInt(CONST char *section, CONST char *key, int *valuePtr) { ! char *s; ! s = Ns_ConfigGetValue(section, key); ! if (s == NULL || sscanf(s, "%d", valuePtr) != 1) { ! return NS_FALSE; } ! return NS_TRUE; } --- 249,267 ---- Ns_ConfigGetInt(CONST char *section, CONST char *key, int *valuePtr) { ! CONST char *s; ! int found; ! s = ConfigGet(section, key, 0); ! if (s != NULL && Ns_StrToInt(s, valuePtr) == NS_OK) { ! Ns_Log(Debug, "config: %s:%s value=%d min=%d max=%d (int)", ! section, key, *valuePtr, INT_MIN, INT_MAX); ! found = NS_TRUE; ! } else { ! Ns_Log(Debug, "config: %s:%s value=(null) min=%d max=%d (int)", ! section, key, INT_MIN, INT_MAX); ! *valuePtr = 0; ! found = NS_FALSE; } ! return found; } *************** *** 296,325 **** Ns_ConfigGetBool(CONST char *section, CONST char *key, int *valuePtr) { ! char *s; ! s = Ns_ConfigGetValue(section, key); ! if (s == NULL) { ! return NS_FALSE; } ! if (STREQ(s, "1") ! || STRIEQ(s, "y") ! || STRIEQ(s, "yes") ! || STRIEQ(s, "on") ! || STRIEQ(s, "t") ! || STRIEQ(s, "true")) { ! ! *valuePtr = 1; ! } else if (STREQ(s, "0") ! || STRIEQ(s, "n") ! || STRIEQ(s, "no") ! || STRIEQ(s, "off") ! || STRIEQ(s, "f") ! || STRIEQ(s, "false")) { ! *valuePtr = 0; ! } else if (sscanf(s, "%d", valuePtr) != 1) { ! return NS_FALSE; ! } ! return NS_TRUE; } --- 317,332 ---- Ns_ConfigGetBool(CONST char *section, CONST char *key, int *valuePtr) { ! CONST char *s; ! int found = NS_FALSE; ! s = ConfigGet(section, key, 0); ! if (s != NULL && ToBool(s, valuePtr)) { ! found = NS_TRUE; } ! Ns_Log(Debug, "config: %s:%s value=%s (bool)", ! section, key, ! found ? (*valuePtr ? "true" : "false") : "(null)"); ! return found; } *************** *** 370,373 **** --- 377,381 ---- } va_end(ap); + Ns_Log(Debug, "config section: %s", Ns_DStringValue(&ds)); set = Ns_ConfigGetSection(ds.string); *************** *** 777,778 **** --- 785,833 ---- return set; } + + + /* + *---------------------------------------------------------------------- + * + * ToBool -- + * + * Interpret value as a boolean. There are many ways to represent + * a boolean value. + * + * Results: + * NS_TRUE if value converted to boolean, NS_FALSE otherwise. + * + * Side effects: + * The boolean value is returned by reference. + * + *---------------------------------------------------------------------- + */ + + int + ToBool(CONST char *value, int *valuePtr) + { + int bool; + + if (STREQ(value, "1") + || STRIEQ(value, "y") + || STRIEQ(value, "yes") + || STRIEQ(value, "on") + || STRIEQ(value, "t") + || STRIEQ(value, "true")) { + + bool = NS_TRUE; + } else if (STREQ(value, "0") + || STRIEQ(value, "n") + || STRIEQ(value, "no") + || STRIEQ(value, "off") + || STRIEQ(value, "f") + || STRIEQ(value, "false")) { + + bool = NS_FALSE; + } else if (Ns_StrToInt(value, &bool) != NS_OK) { + return NS_FALSE; + } + *valuePtr = bool ? NS_TRUE : NS_FALSE; + + return NS_TRUE; + } Index: log.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/log.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** log.c 8 Oct 2005 12:06:07 -0000 1.9 --- log.c 16 Oct 2005 08:52:48 -0000 1.10 *************** *** 104,109 **** {"Fatal", NS_TRUE}, {"Bug", NS_TRUE}, ! {"Debug", NS_TRUE}, ! {"Dev", NS_TRUE} }; --- 104,109 ---- {"Fatal", NS_TRUE}, {"Bug", NS_TRUE}, ! {"Debug", NS_FALSE}, ! {"Dev", NS_FALSE} }; *************** *** 156,162 **** CONST char *path = NS_CONFIG_PARAMETERS; - logConfig[Notice].enabled = Ns_ConfigBool(path, "lognotice", NS_TRUE); logConfig[Debug].enabled = Ns_ConfigBool(path, "logdebug", NS_FALSE); logConfig[Dev].enabled = Ns_ConfigBool(path, "logdev", NS_FALSE); if (Ns_ConfigBool(path, "logroll", NS_TRUE)) { --- 156,162 ---- CONST char *path = NS_CONFIG_PARAMETERS; logConfig[Debug].enabled = Ns_ConfigBool(path, "logdebug", NS_FALSE); logConfig[Dev].enabled = Ns_ConfigBool(path, "logdev", NS_FALSE); + logConfig[Notice].enabled = Ns_ConfigBool(path, "lognotice", NS_TRUE); if (Ns_ConfigBool(path, "logroll", NS_TRUE)) { Index: nsmain.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsmain.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** nsmain.c 11 Oct 2005 21:19:31 -0000 1.23 --- nsmain.c 16 Oct 2005 08:52:48 -0000 1.24 *************** *** 582,585 **** --- 582,591 ---- } nsconf.home = SetCwd(nsconf.home); + + /* + * Update core config values. + */ + + NsConfUpdate(); #ifdef _WIN32 *************** *** 613,622 **** /* - * Update core config values. - */ - - NsConfUpdate(); - - /* * Open the log file now that the home directory and runtime * user id have been set. --- 619,622 ---- Index: nsconf.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsconf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** nsconf.c 8 Oct 2005 12:06:07 -0000 1.7 --- nsconf.c 16 Oct 2005 08:52:48 -0000 1.8 *************** *** 158,167 **** char *path = NS_CONFIG_PARAMETERS; NsUpdateEncodings(); NsUpdateMimeTypes(); NsUpdateUrlEncode(); - Ns_DStringInit(&ds); - /* * libnsthread --- 158,171 ---- char *path = NS_CONFIG_PARAMETERS; + /* + * log.c + */ + + NsConfigLog(); + NsUpdateEncodings(); NsUpdateMimeTypes(); NsUpdateUrlEncode(); /* * libnsthread *************** *** 174,183 **** /* - * log.c - */ - - NsConfigLog(); - - /* * nsmain.c */ --- 178,181 ---- *************** *** 204,209 **** if (Ns_ConfigBool(path, "dnscache", NS_TRUE)) { ! int max = Ns_ConfigInt(path, "dnscachemaxentries", 100); ! i = Ns_ConfigInt(path, "dnscachetimeout", 60); if (max > 0 && i > 0) { i *= 60; /* NB: Config minutes, seconds internally. */ --- 202,207 ---- if (Ns_ConfigBool(path, "dnscache", NS_TRUE)) { ! int max = Ns_ConfigIntRange(path, "dnscachemaxentries", 100, 0, INT_MAX); ! i = Ns_ConfigIntRange(path, "dnscachetimeout", 60, 0, INT_MAX); if (max > 0 && i > 0) { i *= 60; /* NB: Config minutes, seconds internally. */ *************** *** 216,219 **** --- 214,218 ---- */ + Ns_DStringInit(&ds); nsconf.tcl.sharedlibrary = Ns_ConfigGetValue(path, "tcllibrary"); if (nsconf.tcl.sharedlibrary == NULL) { *************** *** 222,226 **** } nsconf.tcl.lockoninit = Ns_ConfigBool(path, "tclinitlock", NS_FALSE); - Ns_DStringFree(&ds); } --- 221,224 ---- Index: driver.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/driver.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** driver.c 9 Oct 2005 04:42:30 -0000 1.23 --- driver.c 16 Oct 2005 08:52:48 -0000 1.24 *************** *** 321,325 **** drvPtr->protocol = ns_strdup(defproto); drvPtr->address = ns_strdup(address); ! drvPtr->port = Ns_ConfigInt(path, "port", defport); drvPtr->location = Ns_ConfigGetValue(path, "location"); if (drvPtr->location != NULL && strstr(drvPtr->location, "://")) { --- 321,325 ---- drvPtr->protocol = ns_strdup(defproto); drvPtr->address = ns_strdup(address); ! drvPtr->port = Ns_ConfigIntRange(path, "port", defport, 0, 65535); drvPtr->location = Ns_ConfigGetValue(path, "location"); if (drvPtr->location != NULL && strstr(drvPtr->location, "://")) { |