From: Stephen D. <sd...@us...> - 2005-12-11 04:44:14
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4761/nsd Modified Files: fastpath.c nsd.h proc.c server.c tclcmds.c tclrequest.c Log Message: * include/ns.h: * nsd/nsd.h: * nsd/fastpath.c: * nsd/tclrequest.c: * nsd/tclcmds.c: * nsd/server.c: * nsd/proc.c: * tests/ns_register_proc.test: Add new Tcl command ns_register_fastpath which re-register the original fastpath proc for static file serving, for the specified method and URL. This allows e.g. a Tcl proc to be registered as the default handler for the URL / and then override this with the fastpath proc for /images. The fastpath proc invokes no Tcl and therefore does not allocate an interp. Non-Tcl using threads can be segregated using the conn pool mechanism. (RFE: http://sf.net/tracker/index.php?func=detail&aid=1012770&group_id=3152&atid=353152) Index: fastpath.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/fastpath.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** fastpath.c 7 Nov 2005 03:17:55 -0000 1.25 --- fastpath.c 11 Dec 2005 04:44:05 -0000 1.26 *************** *** 245,293 **** /* *---------------------------------------------------------------------- ! * FastGetRestart -- * ! * Construct the full URL and redirect internally. * * Results: ! * See Ns_ConnRedirect(). * * Side effects: ! * See Ns_ConnRedirect(). * *---------------------------------------------------------------------- */ ! static int ! FastGetRestart(Ns_Conn *conn, CONST char *page) { ! int status; ! Ns_DString ds; ! ! Ns_DStringInit(&ds); ! Ns_MakePath(&ds, conn->request->url, page, NULL); ! status = Ns_ConnRedirect(conn, ds.string); ! Ns_DStringFree(&ds); ! return status; } - - /* - *---------------------------------------------------------------------- - * NsFastGet -- - * - * Return the contents of a URL. - * - * Results: - * Return NS_OK for success or NS_ERROR for failure. - * - * Side effects: - * Contents of file may be cached in file cache. - * - *---------------------------------------------------------------------- - */ - int ! NsFastGet(void *arg, Ns_Conn *conn) { Ns_DString ds; --- 245,275 ---- /* *---------------------------------------------------------------------- ! * Ns_FastPathProc, NsFastPathProc -- * ! * Return the contents of a URL. * * Results: ! * Return NS_OK for success or NS_ERROR for failure. * * Side effects: ! * Contents of file may be cached in file cache. * *---------------------------------------------------------------------- */ ! int ! Ns_FastPathProc(void *arg, Ns_Conn *conn) { ! char *server = arg; ! NsServer *servPtr; ! if ((servPtr = NsGetServer(server)) == NULL) { ! return NS_ERROR; ! } ! return NsFastPathProc(servPtr, conn); } int ! NsFastPathProc(void *arg, Ns_Conn *conn) { Ns_DString ds; *************** *** 365,368 **** --- 347,380 ---- /* *---------------------------------------------------------------------- + * FastGetRestart -- + * + * Construct the full URL and redirect internally. + * + * Results: + * See Ns_ConnRedirect(). + * + * Side effects: + * See Ns_ConnRedirect(). + * + *---------------------------------------------------------------------- + */ + + static int + FastGetRestart(Ns_Conn *conn, CONST char *page) + { + int status; + Ns_DString ds; + + Ns_DStringInit(&ds); + Ns_MakePath(&ds, conn->request->url, page, NULL); + status = Ns_ConnRedirect(conn, ds.string); + Ns_DStringFree(&ds); + + return status; + } + + + /* + *---------------------------------------------------------------------- * FreeEntry -- * Index: tclcmds.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclcmds.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** tclcmds.c 7 Nov 2005 03:17:55 -0000 1.25 --- tclcmds.c 11 Dec 2005 04:44:05 -0000 1.26 *************** *** 126,129 **** --- 126,130 ---- NsTclRandObjCmd, NsTclRegisterAdpObjCmd, + NsTclRegisterFastPathObjCmd, NsTclRegisterFastUrl2FileObjCmd, NsTclRegisterFilterObjCmd, *************** *** 388,391 **** --- 389,393 ---- {"ns_register_adp", NULL, NsTclRegisterAdpObjCmd}, {"ns_register_adptag", NsTclRegisterTagCmd, NULL}, + {"ns_register_fastpath", NULL, NsTclRegisterFastPathObjCmd}, {"ns_register_fasturl2file", NULL, NsTclRegisterFastUrl2FileObjCmd}, {"ns_register_filter", NULL, NsTclRegisterFilterObjCmd}, Index: server.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/server.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** server.c 7 Nov 2005 03:17:55 -0000 1.14 --- server.c 11 Dec 2005 04:44:05 -0000 1.15 *************** *** 415,421 **** */ ! Ns_RegisterRequest(server, "GET", "/", NsFastGet, NULL, servPtr, 0); ! Ns_RegisterRequest(server, "HEAD", "/", NsFastGet, NULL, servPtr, 0); ! Ns_RegisterRequest(server, "POST", "/", NsFastGet, NULL, servPtr, 0); /* --- 415,421 ---- */ ! Ns_RegisterRequest(server, "GET", "/", NsFastPathProc, NULL, servPtr, 0); ! Ns_RegisterRequest(server, "HEAD", "/", NsFastPathProc, NULL, servPtr, 0); ! Ns_RegisterRequest(server, "POST", "/", NsFastPathProc, NULL, servPtr, 0); /* Index: nsd.h =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsd.h,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** nsd.h 24 Nov 2005 19:01:20 -0000 1.39 --- nsd.h 11 Dec 2005 04:44:05 -0000 1.40 *************** *** 880,884 **** extern Ns_ArgProc NsConnArgProc; extern Ns_FilterProc NsTclFilterProc; ! extern Ns_OpProc NsFastGet; extern Ns_OpProc NsTclRequestProc; extern Ns_OpProc NsAdpRequestProc; --- 880,884 ---- extern Ns_ArgProc NsConnArgProc; extern Ns_FilterProc NsTclFilterProc; ! extern Ns_OpProc NsFastPathProc; extern Ns_OpProc NsTclRequestProc; extern Ns_OpProc NsAdpRequestProc; Index: proc.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/proc.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** proc.c 7 Nov 2005 03:17:55 -0000 1.9 --- proc.c 11 Dec 2005 04:44:05 -0000 1.10 *************** *** 80,84 **** {(void *) NsAdpRequestProc, "ns:adprequest", ServerArgProc}, {(void *) NsAdpMapProc, "ns:adpmap", Ns_StringArgProc}, ! {(void *) NsFastGet, "ns:fastget", ServerArgProc}, {(void *) NsTclTraceProc, "ns:tcltrace", Ns_TclCallbackArgProc}, {(void *) NsTclUrl2FileProc, "ns:tclurl2file", Ns_TclCallbackArgProc}, --- 80,84 ---- {(void *) NsAdpRequestProc, "ns:adprequest", ServerArgProc}, {(void *) NsAdpMapProc, "ns:adpmap", Ns_StringArgProc}, ! {(void *) NsFastPathProc, "ns:fastget", ServerArgProc}, {(void *) NsTclTraceProc, "ns:tcltrace", Ns_TclCallbackArgProc}, {(void *) NsTclUrl2FileProc, "ns:tclurl2file", Ns_TclCallbackArgProc}, Index: tclrequest.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclrequest.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tclrequest.c 5 Dec 2005 08:40:23 -0000 1.7 --- tclrequest.c 11 Dec 2005 04:44:05 -0000 1.8 *************** *** 134,137 **** --- 134,182 ---- *---------------------------------------------------------------------- * + * NsTclRegisterFastPathObjCmd -- + * + * Implements ns_register_fastpath as obj command. + * + * Results: + * Tcl result. + * + * Side effects: + * See docs. + * + *---------------------------------------------------------------------- + */ + + int + NsTclRegisterFastPathObjCmd(ClientData arg, Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[], int adp) + { + NsInterp *itPtr = arg; + char *method, *url; + int flags = 0; + + Ns_ObjvSpec opts[] = { + {"-noinherit", Ns_ObjvBool, &flags, (void *) NS_OP_NOINHERIT}, + {"--", Ns_ObjvBreak, NULL, NULL}, + {NULL, NULL, NULL, NULL} + }; + Ns_ObjvSpec args[] = { + {"method", Ns_ObjvString, &method, NULL}, + {"url", Ns_ObjvString, &url, NULL}, + {NULL, NULL, NULL, NULL} + }; + if (Ns_ParseObjv(opts, args, interp, 1, objc, objv) != NS_OK) { + return TCL_ERROR; + } + + Ns_RegisterRequest(itPtr->servPtr->server, method, url, + NsFastPathProc, NULL, itPtr->servPtr, flags); + + return TCL_OK; + } + + + /* + *---------------------------------------------------------------------- + * * NsTclRegisterAdpObjCmd -- * |