/* * jsperror.c: an Error function that uses a JSP to return an error to the user * * Rob Crittenden * 08/17/2001 Initial Revision * * How to install this program: * * Add the following lines to your obj.conf: * * Init fn="load-modules" shlib="" funcs="jsp-error" * ... * Error fn="jsp-error" reason="Not Found" \ * path="/usr/netscape/ent41sp2/docs/HelloWorld.jsp" uri="/HelloWorld.jsp" * * Function Parameters: * fn - always jsp-error * path - The complete path to the JSP you want to serve. * uri - The URI of the JSP you want to serve. * reason/code - This is a regular Error function so you can specify * reason or code or both if you want (as long as the code * & error match). * * NSServletService() is picky about the path not matching the URI so you have * to specify both. * * NOTE: You don't need to have JSP's enabled in the server for this to work * since we call NSServletService() directly, but you do need to have * servlets enabled. */ #include NSAPI_PUBLIC int jsp_error(pblock *pb, Session *sn, Request *rq) { pb_param *realpath = pblock_find("path", rq->vars); char *path = pblock_findval("path", pb); char *uri = pblock_findval("uri", pb); FuncPtr jsp_function; if (!path) { log_error(LOG_FAILURE, "jsp-error", sn, rq, "jsp-error: path not set."); return REQ_ABORTED; } if (!uri) { log_error(LOG_FAILURE, "jsp-error", sn, rq, "jsp-error: uri not set."); return REQ_ABORTED; } /* Set the new path */ if (realpath) { FREE(realpath->value); realpath->value = STRDUP(path); } else { pblock_nvinsert("path", path, rq->vars); } /* The URI needs to match, set that too */ pblock_nvreplace("uri", uri, rq->reqpb); /* Set the MIME type for JSP's */ pblock_nvreplace("content-type", "magnus-internal/jsp", rq->srvhdrs); /* call the JSP */ if ((jsp_function = func_find("NSServletService")) == NULL) log_error(LOG_FAILURE, "jsp-error", sn, rq, "NSServletService() not found in server function table"); else return(*jsp_function)(NULL, sn, rq); }