Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 17361 invoked by uid 500); 3 Apr 2001 22:45:34 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: tomcat-dev@jakarta.apache.org Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 17344 invoked by uid 500); 3 Apr 2001 22:45:34 -0000 Delivered-To: apmail-jakarta-tomcat-4.0-cvs@apache.org Date: 3 Apr 2001 22:45:33 -0000 Message-ID: <20010403224533.17339.qmail@apache.org> From: amyroh@apache.org To: jakarta-tomcat-4.0-cvs@apache.org Subject: cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi SsiMediator.java amyroh 01/04/03 15:45:33 Modified: catalina/src/share/org/apache/catalina/util/ssi SsiMediator.java Log: Fixed virtual behavior to follow NCSA rules with a webapp-relative option. Revision Changes Path 1.3 +48 -9 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java Index: SsiMediator.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SsiMediator.java 2001/04/02 21:14:29 1.2 +++ SsiMediator.java 2001/04/03 22:45:33 1.3 @@ -1,8 +1,8 @@ /* * SsiMediator.java - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v 1.2 2001/04/02 21:14:29 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2001/04/02 21:14:29 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/ssi/SsiMediator.java,v 1.3 2001/04/03 22:45:33 amyroh Exp $ + * $Revision: 1.3 $ + * $Date: 2001/04/03 22:45:33 $ * * ==================================================================== * @@ -85,7 +85,8 @@ /** * @author Bip Thelin - * @version $Revision: 1.2 $, $Date: 2001/04/02 21:14:29 $ + * @author Amy Roh + * @version $Revision: 1.3 $, $Date: 2001/04/03 22:45:33 $ * */ public class SsiMediator { @@ -106,12 +107,18 @@ protected static ServletContext servletContext = null; + protected static ServletContext origServletContext = null; + + protected static String contextPath = null; + protected static String relpath = "/"; protected static String path = new String(); protected static int debug = 0; + protected static boolean isVirtualWebappRelative = false; + public SsiMediator() {} static { @@ -129,9 +136,10 @@ OutputStream out, ServletContext servletContext, int debug, - String path) { + String path, + boolean isVirtualWebappRelative) { this.debug = debug; - flush(req, res, out, servletContext, path); + flush(req, res, out, servletContext, path, isVirtualWebappRelative); } public final SsiCommand getCommand(String cmd) { @@ -142,13 +150,17 @@ HttpServletResponse res, OutputStream out, ServletContext servletContext, - String path) { + String path, + boolean isVirtualWebappRelative) { this.req = req; this.res = res; this.out = out; this.servletContext = servletContext; + this.origServletContext = servletContext; + this.contextPath = req.getContextPath(); this.path = path; this.relpath = path.substring(0, path.lastIndexOf("/")+1); + this.isVirtualWebappRelative = isVirtualWebappRelative; int c=0; serverVariables.put("AUTH_TYPE", @@ -295,6 +307,32 @@ normalized.substring(index + 3); } + if (!isVirtualWebappRelative) { + // case of virtual="file.txt", "./file.txt", or dir/file.txt + if ((!path.startsWith("/")) || (path.startsWith("./"))) { + // handle as file in the current directory with original servletContext + servletContext = origServletContext; + }else if (path.indexOf("/", 1)==-1) { + //root context + servletContext = servletContext.getContext("/"); + } else if (!contextPath.equals("")) { + //starts with the context path of this webapp + if ((normalized !=null) && (normalized.startsWith(contextPath))) { + // strip off the context path + servletContext = servletContext.getContext(contextPath); + normalized = normalized.substring(contextPath.length()); + } + } else if (normalized != null){ + // find which context is the right one to handle + String context = normalized.substring(0, path.indexOf("/", 1)); + ServletContext sc = servletContext.getContext(context); + if (sc!=null) { + servletContext = sc; + normalized = normalized.substring(context.length()); + } + } + } + return (normalized); } @@ -325,6 +363,8 @@ * normalized = RequestUtil.URLDecode(normalized, "UTF8"); */ + servletContext = origServletContext; + if (normalized == null) return (null); @@ -341,8 +381,7 @@ normalized.substring(index + 1); } - // If it starts with a "/" or contains "../" we - // return null. + // If it starts with a "/" or contains "../" we return null. if (normalized.startsWith("/") || normalized.indexOf("../") >= 0) return (null);