From: Stephen D. <sd...@us...> - 2005-07-30 03:17:59
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29888/nsd Modified Files: nsd.h server.c tclinit.c tclmisc.c Log Message: * include/ns.h: * nsd/nsd.h: * nsd/server.c: * nsd/tclinit.c: * nsd/tclmisc.c: Add Ns_TclLogErrorInfo and allow admin to configure which conenction headers to log for Tcl errors. (RFE #1241432) Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** nsd.h 30 Jul 2005 03:11:06 -0000 1.27 --- nsd.h 30 Jul 2005 03:17:50 -0000 1.28 *************** *** 653,656 **** --- 653,657 ---- int epoch; Tcl_Obj *modules; + CONST char **errorLogHeaders; } tcl; Index: tclmisc.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclmisc.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tclmisc.c 12 Jul 2005 08:26:04 -0000 1.11 --- tclmisc.c 30 Jul 2005 03:17:50 -0000 1.12 *************** *** 79,82 **** --- 79,185 ---- *---------------------------------------------------------------------- * + * Ns_TclLogErrorInfo -- + * + * Log the global errorInfo variable to the server log along with + * some connection info, if available. + * + * Results: + * Returns a read-only pointer to the complete errorInfo. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + CONST char * + Ns_TclLogErrorInfo(Tcl_Interp *interp, CONST char *extraInfo) + { + NsInterp *itPtr = NsGetInterpData(interp); + Ns_Conn *conn; + CONST char *errorInfo, **logHeaders, **hdr; + char *value; + Ns_DString ds; + + if (extraInfo != NULL) { + Tcl_AddObjErrorInfo(interp, extraInfo, -1); + } + errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY); + if (errorInfo == NULL) { + errorInfo = ""; + } + if (itPtr != NULL && itPtr->conn != NULL) { + conn = itPtr->conn; + Ns_DStringInit(&ds); + Ns_DStringVarAppend(&ds, conn->request->method, " ", conn->request->url, + ", PeerAddress: ", Ns_ConnPeer(conn), NULL); + + logHeaders = itPtr->servPtr->tcl.errorLogHeaders; + if (logHeaders != NULL) { + for (hdr = logHeaders; *hdr != NULL; hdr++) { + if ((value = Ns_SetIGet(conn->headers, *hdr)) != NULL) { + Ns_DStringVarAppend(&ds, ", ", *hdr, ": ", value, NULL); + } + } + } + Ns_Log(Error, "%s\n%s", Ns_DStringValue(&ds), errorInfo); + Ns_DStringFree(&ds); + } else { + Ns_Log(Error, "%s\n%s", Tcl_GetStringResult(interp), errorInfo); + } + + return errorInfo; + } + + + /* + *---------------------------------------------------------------------- + * + * Ns_TclLogError -- + * + * Log the global errorInfo variable to the server log. + * + * Results: + * Returns a read-only pointer to the errorInfo. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + CONST char * + Ns_TclLogError(Tcl_Interp *interp) + { + return Ns_TclLogErrorInfo(interp, NULL); + } + + + /* + *---------------------------------------------------------------------- + * + * Ns_TclLogErrorRequest -- + * + * Deprecated. See: Ns_TclLoggErrorInfo. + * + * Results: + * Returns a pointer to the read-only errorInfo. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + CONST char * + Ns_TclLogErrorRequest(Tcl_Interp *interp, Ns_Conn *conn) + { + return Ns_TclLogErrorInfo(interp, NULL); + } + + + /* + *---------------------------------------------------------------------- + * * NsTclStripHtmlCmd -- * Index: tclinit.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclinit.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tclinit.c 30 Jul 2005 03:11:07 -0000 1.10 --- tclinit.c 30 Jul 2005 03:17:50 -0000 1.11 *************** *** 690,764 **** *---------------------------------------------------------------------- * - * Ns_TclLogError -- - * - * Log the global errorInfo variable to the server log. - * - * Results: - * Returns a pointer to the errorInfo. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - - char * - Ns_TclLogError(Tcl_Interp *interp) - { - CONST char *errorInfo; - - errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY); - if (errorInfo == NULL) { - errorInfo = ""; - } - Ns_Log(Error, "%s\n%s", Tcl_GetStringResult(interp), errorInfo); - - return (char *) errorInfo; - } - - - /* - *---------------------------------------------------------------------- - * - * Ns_TclLogErrorRequest -- - * - * Log both errorInfo and info about the HTTP request that led - * to it. - * - * Results: - * Returns a pointer to the errorInfo. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - - char * - Ns_TclLogErrorRequest(Tcl_Interp *interp, Ns_Conn *conn) - { - char *agent; - CONST char *errorInfo; - - errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY); - if (errorInfo == NULL) { - errorInfo = Tcl_GetStringResult(interp); - } - agent = Ns_SetIGet(conn->headers, "user-agent"); - if (agent == NULL) { - agent = "?"; - } - Ns_Log(Error, "error for %s %s, " - "User-Agent: %s, PeerAddress: %s\n%s", - conn->request->method, conn->request->url, - agent, Ns_ConnPeer(conn), errorInfo); - - return (char*) errorInfo; - } - - - /* - *---------------------------------------------------------------------- - * * Ns_TclInitModule -- * --- 690,693 ---- Index: server.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/server.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** server.c 12 Jul 2005 11:19:22 -0000 1.10 --- server.c 30 Jul 2005 03:17:50 -0000 1.11 *************** *** 320,323 **** --- 320,333 ---- /* + * Initialize the list of connection headers to log for Tcl errors. + */ + + p = Ns_ConfigGetValue(path, "errorlogheaders"); + if (p != NULL && Tcl_SplitList(NULL, p, &n, &servPtr->tcl.errorLogHeaders) + != TCL_OK) { + Ns_Log(Error, "invalid error log headers: %s", p); + } + + /* * Initialize the Tcl detached channel support. */ |