Author: costin
Date: Tue May 23 19:54:17 2006
New Revision: 409044

URL: http://svn.apache.org/viewvc?rev=409044&view=rev
Log:
Updates to match the cleaned-up stuff

Added:
    tomcat/sandbox/java/org/apache/coyote/servlet/Main.java
    tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java
    tomcat/sandbox/java/org/apache/coyote/servlet/util/ClientAbortException.java
      - copied, changed from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/ClientAbortException.java
    tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageReader.java
      - copied, changed from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/MessageReader.java
    tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java
      - copied, changed from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/MessageWriter.java
Modified:
    tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletInputStreamImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletOutputStreamImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletReaderImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java
    tomcat/sandbox/java/org/apache/coyote/servlet/ServletWriterImpl.java

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/CoyoteServletFacade.java Tue 
May 23 19:54:17 2006
@@ -2,7 +2,7 @@
  */
 package org.apache.coyote.servlet;
 
-import java.io.IOException;
+import java.io.File;
 import java.util.HashMap;
 
 import javax.servlet.Servlet;
@@ -10,18 +10,11 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
-import org.apache.coyote.ActionCode;
-import org.apache.coyote.Adapter;
-import org.apache.coyote.Request;
-import org.apache.coyote.Response;
-import org.apache.coyote.adapters.FileAdapter;
-import org.apache.coyote.http11.Http11Protocol;
-import org.apache.coyote.standalone.MessageWriter;
-import org.apache.tomcat.util.buf.ByteChunk;
-import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.servlets.file.FileServlet;
 import org.apache.tomcat.util.http.mapper.Mapper;
-import org.apache.tomcat.util.http.mapper.MappingData;
-import org.apache.tomcat.util.res.StringManager;
+import org.apache.tomcat.util.loader.Module;
+import org.apache.tomcat.util.loader.Repository;
+import org.apache.tomcat.util.net.http11.Http11Protocol;
 
 /**
  * Frontend for a minimal servlet impl for coyote.
@@ -35,6 +28,14 @@
  */
 public class CoyoteServletFacade {
     static CoyoteServletFacade facade = new CoyoteServletFacade();
+    
+    /** Simple interface to be used by manually or generated web.xml
+     *  readers.
+     */ 
+    public static interface WebappInitializer {
+        public void initWebapp(CoyoteServletFacade facade, ServletContext ctx) 
+          throws ServletException;
+    }
 
     protected HashMap hosts = new HashMap(); 
     protected Http11Protocol proto;
@@ -43,14 +44,14 @@
     
     String hostname = ""; // current hostname, used for settings
     
-    protected CoyoteServletProcessor mainAdapter;
-    FileAdapter fa = new FileAdapter();
+    protected MapperAdapter mainAdapter;
+    //FileAdapter fa = new FileAdapter();
     
     
     private CoyoteServletFacade() {
         proto = new Http11Protocol();
 
-        mainAdapter = new CoyoteServletProcessor(mapper);        
+        mainAdapter = new MapperAdapter(mapper);        
 
         //Counters cnt=new Counters();
         //cnt.setNext( mainAdapter );
@@ -67,14 +68,18 @@
         return facade;
     }
     
+    public Http11Protocol getProtocol() {
+        return proto;
+    }
+    
     public void initHttp(int port) {
-        proto.setPort(port);
+        proto.getEndpoint().setPort(port);
     }
 
     public void start() {
-        if( proto.getPort() == 0 ) { //&& 
+        if( proto.getEndpoint().getPort() == 0 ) { //&& 
                 //proto.getEndpoint().getServerSocket() == null) {
-            proto.setPort(8800);
+            proto.getEndpoint().setPort(8800);
         }
         
         try {
@@ -97,8 +102,11 @@
      * @param hostname - "" if default host, or string to be matched with Host 
header
      * @param path - context path, "/" for root, "/examples", etc
      * @return a servlet context
+     * @throws ServletException 
      */
-    public ServletContext createServletContext(String hostname, String path) {
+    public ServletContext createServletContext(String hostname, String path) 
+            throws ServletException {
+        
         Host host = (Host)hosts.get(hostname);
         if( host == null ) {
             host = new Host();
@@ -106,7 +114,7 @@
             hosts.put(hostname, host);
             mapper.addHost(hostname, new String[] {}, host);
         }
-        ServletContextImpl ctx = new ServletContextImpl(path);
+        ServletContextImpl ctx = new ServletContextImpl();
         ctx.setParent(host);
         ctx.setPath(path);
         
@@ -116,10 +124,19 @@
         // 
         mapper.addContext(hostname, path, ctx, new String[] {"index.html"}, 
                 null);
-        mapper.addWrapper(hostname, path, "/", fa);
+        
         host.addChild(ctx);
+        
+        // Add default mappings. 
+        ServletConfig fileS = createServletWrapper(ctx, "file", 
+                new FileServlet());
+        addMapping("/", fileS);
         return ctx;
     }
+    
+    public void setBasePath(ServletContext ctx, String dir) {
+        ((ServletContextImpl)ctx).setBasePath(dir);
+    }
 
     // -------------- Web.xml reader will call this ---------
     // For specialized cases - you can call this directly
@@ -144,286 +161,34 @@
     public void addMapping(String path, ServletConfig wrapper) {
         ServletContextImpl ctx = 
(ServletContextImpl)wrapper.getServletContext();
         Host host = (ctx).getParent();
-        mapper.addWrapper(host.getName(), ctx.getPath(), path, 
-                new CoyoteServletAdapter(wrapper));
+        mapper.addWrapper(host.getName(), ctx.getPath(), path, wrapper);
+        //new CoyoteServletAdapter(wrapper));
     }
     
-    // TODO: auth
-    
-    public static class CoyoteServletProcessor implements Adapter {
-        private Mapper mapper=new Mapper();
-      
-        public CoyoteServletProcessor(Mapper mapper2) {
-            mapper = mapper2;
-        }
-
-        public void service(Request req, final Response res)
-                throws Exception {
-            try {
-                
-                MessageBytes decodedURI = req.decodedURI();
-                decodedURI.duplicate(req.requestURI());
-
-                if (decodedURI.getType() == MessageBytes.T_BYTES) {
-                    // %xx decoding of the URL
-                    try {
-                        req.getURLDecoder().convert(decodedURI, false);
-                    } catch (IOException ioe) {
-                        res.setStatus(400);
-                        res.setMessage("Invalid URI");
-                        throw ioe;
-                    }
-                    // Normalization
-                    if (!normalize(req.decodedURI())) {
-                        res.setStatus(400);
-                        res.setMessage("Invalid URI");
-                        return;
-                    }
-                    // Character decoding
-                    //convertURI(decodedURI, request);
-                } else {
-                    // The URL is chars or String, and has been sent using an 
in-memory
-                    // protocol handler, we have to assume the URL has been 
properly
-                    // decoded already
-                    decodedURI.toChars();
-                }
-
-
-                
-                // TODO: per thread data - does it help ? 
-                
-                MappingData mapRes = new MappingData();
-                mapper.map(req.remoteHost(), req.decodedURI(), 
-                        mapRes);
-                
-                Adapter h=(Adapter)mapRes.wrapper;
-                if (h != null) {
-                    h.service( req, res );
-                }
-                
-            } catch( Throwable t ) {
-                t.printStackTrace(System.out);
-            } 
-
-            // Final processing
-            MessageWriter.getWriter(req, res, 0).flush();
-            res.finish();
-
-            req.recycle();
-            res.recycle();
 
-        }
+    public void initContext(ServletContext ctx) {
+        // Set up class loader.
+        String base = ((ServletContextImpl)ctx).getBasePath();
+        Repository ctxRepo = new Repository();
+        ctxRepo.setParentClassLoader(this.getClass().getClassLoader());
+        ctxRepo.addDir(new File(base + "/WEB-INF/classes"));
+        ctxRepo.addLibs(new File(base + "/WEB-INF/lib"));
         
-        /**
-         * Normalize URI.
-         * <p>
-         * This method normalizes "\", "//", "/./" and "/../". This method will
-         * return false when trying to go above the root, or if the URI 
contains
-         * a null byte.
-         * 
-         * @param uriMB URI to be normalized
-         */
-        public static boolean normalize(MessageBytes uriMB) {
-
-            ByteChunk uriBC = uriMB.getByteChunk();
-            byte[] b = uriBC.getBytes();
-            int start = uriBC.getStart();
-            int end = uriBC.getEnd();
-
-            // URL * is acceptable
-            if ((end - start == 1) && b[start] == (byte) '*')
-              return true;
-
-            int pos = 0;
-            int index = 0;
-
-            // Replace '\' with '/'
-            // Check for null byte
-            for (pos = start; pos < end; pos++) {
-                if (b[pos] == (byte) '\\')
-                    b[pos] = (byte) '/';
-                if (b[pos] == (byte) 0)
-                    return false;
-            }
-
-            // The URL must start with '/'
-            if (b[start] != (byte) '/') {
-                return false;
-            }
-
-            // Replace "//" with "/"
-            for (pos = start; pos < (end - 1); pos++) {
-                if (b[pos] == (byte) '/') {
-                    while ((pos + 1 < end) && (b[pos + 1] == (byte) '/')) {
-                        copyBytes(b, pos, pos + 1, end - pos - 1);
-                        end--;
-                    }
-                }
-            }
-
-            // If the URI ends with "/." or "/..", then we append an extra "/"
-            // Note: It is possible to extend the URI by 1 without any side 
effect
-            // as the next character is a non-significant WS.
-            if (((end - start) >= 2) && (b[end - 1] == (byte) '.')) {
-                if ((b[end - 2] == (byte) '/') 
-                    || ((b[end - 2] == (byte) '.') 
-                        && (b[end - 3] == (byte) '/'))) {
-                    b[end] = (byte) '/';
-                    end++;
-                }
-            }
-
-            uriBC.setEnd(end);
-
-            index = 0;
-
-            // Resolve occurrences of "/./" in the normalized path
-            while (true) {
-                index = uriBC.indexOf("/./", 0, 3, index);
-                if (index < 0)
-                    break;
-                copyBytes(b, start + index, start + index + 2, 
-                          end - start - index - 2);
-                end = end - 2;
-                uriBC.setEnd(end);
-            }
-
-            index = 0;
-
-            // Resolve occurrences of "/../" in the normalized path
-            while (true) {
-                index = uriBC.indexOf("/../", 0, 4, index);
-                if (index < 0)
-                    break;
-                // Prevent from going outside our context
-                if (index == 0)
-                    return false;
-                int index2 = -1;
-                for (pos = start + index - 1; (pos >= 0) && (index2 < 0); pos 
--) {
-                    if (b[pos] == (byte) '/') {
-                        index2 = pos;
-                    }
-                }
-                copyBytes(b, start + index2, start + index + 3,
-                          end - start - index - 3);
-                end = end + index2 - index - 3;
-                uriBC.setEnd(end);
-                index = index2;
-            }
-
-            //uriBC.setBytes(b, start, end);
-            uriBC.setEnd(end);
-            return true;
-
-        }
-
+        ClassLoader cl = ctxRepo.getClassLoader();
         
-        /**
-         * Copy an array of bytes to a different position. Used during 
-         * normalization.
-         */
-        protected static void copyBytes(byte[] b, int dest, int src, int len) {
-            for (int pos = 0; pos < len; pos++) {
-                b[pos + dest] = b[pos + src];
-            }
-        }
-
-        public boolean event(Request req, Response res, boolean error) throws 
Exception {
-            // TODO Auto-generated method stub
-            return false;
+        // Code-based configuration - experiment with generated web.xml->class
+        try {
+            Class c = cl.loadClass("WebappInit");
+            WebappInitializer webInit = (WebappInitializer)c.newInstance();
+            webInit.initWebapp(this, ctx);
+        } catch(Throwable t) {
+            t.printStackTrace();
         }
-
-    }
-    
-    public static class CoyoteServletAdapter implements Adapter {
-        static StringManager sm = 
StringManager.getManager("org.apache.coyote.servlet");
-
-        private static org.apache.commons.logging.Log log=
-            org.apache.commons.logging.LogFactory.getLog( 
CoyoteServletAdapter.class );
-
-        
-        public static final int ADAPTER_NOTES = 1;
-
-        ServletConfigImpl servletConfig;
         
-        public CoyoteServletAdapter( ServletConfig cfg ) {
-            this.servletConfig = (ServletConfigImpl)cfg;
-        }
+        // TODO: read a simpler version of web.xml
         
+        // TODO: read the real web.xml
         
-        /** Coyote / mapper adapter. Result of the mapper.
-         *  
-         *  This replaces the valve chain, the path is: 
-         *    1. coyote calls mapper -> result Adapter 
-         *    2. service is called. Additional filters are set on the wrapper. 
-         */
-        public void service(org.apache.coyote.Request req, 
org.apache.coyote.Response res) 
-            throws IOException {
-            
-            ServletRequestImpl request = (ServletRequestImpl) 
req.getNote(ADAPTER_NOTES);
-            ServletResponseImpl response = (ServletResponseImpl) 
res.getNote(ADAPTER_NOTES);
-
-            if (request == null) {
-
-                // Create objects
-                request = new ServletRequestImpl();
-                request.setCoyoteRequest(req);
-                response = new ServletResponseImpl();
-                response.setRequest(request);
-                response.setCoyoteResponse(res);
-
-                // Link objects
-                request.setResponse(response);
-
-                // Set as notes
-                req.setNote(ADAPTER_NOTES, request);
-                res.setNote(ADAPTER_NOTES, response);
-
-                // Set query string encoding
-//                req.getParameters().setQueryStringEncoding
-//                    (connector.getURIEncoding());
-
-            }
-
-            try {
-
-                // Parse and set Catalina and configuration specific 
-                // request parameters
-//                if ( postParseRequest(req, request, res, response) ) {
-//                    // Calling the container
-//                    
connector.getContainer().getPipeline().getFirst().invoke(request, response);
-//                }
-                // Catalina default valves :
-                // Find host/context
-                // apply auth filters
-                // 
-                
-
-                Servlet servlet = servletConfig.allocate();
-                
-                servlet.service(request, response);
-                
-                response.finishResponse();
-                req.action( ActionCode.ACTION_POST_REQUEST , null);
-
-            } catch (IOException e) {
-                ;
-            } catch (Throwable t) {
-                log.error(sm.getString("coyoteAdapter.service"), t);
-            } finally {
-                // Recycle the wrapper request and response
-                request.recycle();
-                response.recycle();
-            }
-
-        }
-
-
-        public boolean event(Request req, Response res, boolean error) throws 
Exception {
-            // TODO Auto-generated method stub
-            return false;
-        }
-
     }
 
 }

Added: tomcat/sandbox/java/org/apache/coyote/servlet/Main.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/Main.java?rev=409044&view=auto
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/Main.java (added)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/Main.java Tue May 23 19:54:17 
2006
@@ -0,0 +1,48 @@
+package org.apache.coyote.servlet;
+
+import javax.servlet.ServletContext;
+
+
+/** 
+ * Simple example of embeding coyote servlet.
+ * 
+ */
+public class Main  {
+    CoyoteServletFacade facade;
+    
+    public Main() {        
+    }
+
+    /**
+     */
+    public void run() {
+        init();
+        start();
+    }
+    
+    public void init() {
+        facade = CoyoteServletFacade.getServletImpl();
+        facade.initHttp(8800);
+        facade.getProtocol().getEndpoint().setDaemon(false);        
+    }
+    
+    
+    public void start() {
+        try {
+            ServletContext ctx = facade.createServletContext("localhost", "");
+            facade.setBasePath(ctx, "webapps/ROOT");
+            facade.initContext(ctx);
+            facade.start();
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+    }
+    
+    // ------------------- Main ---------------------
+    public static void main( String args[]) {
+        Main sa=new Main();
+        sa.run();
+    }
+
+    
+}
\ No newline at end of file

Added: tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java?rev=409044&view=auto
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java (added)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/MapperAdapter.java Tue May 23 
19:54:17 2006
@@ -0,0 +1,279 @@
+package org.apache.coyote.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+
+import org.apache.coyote.ActionCode;
+import org.apache.coyote.Adapter;
+import org.apache.coyote.Request;
+import org.apache.coyote.Response;
+import org.apache.coyote.servlet.util.MessageWriter;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.http.mapper.Mapper;
+import org.apache.tomcat.util.http.mapper.MappingData;
+
+/** Main adapter - mapping.
+ * TODO: filters
+ * TODO: auth
+ */
+public class MapperAdapter implements Adapter {
+    private Mapper mapper=new Mapper();
+    private static org.apache.commons.logging.Log log=
+        org.apache.commons.logging.LogFactory.getLog( MapperAdapter.class );
+
+
+    public MapperAdapter(Mapper mapper2) {
+        mapper = mapper2;
+    }
+
+    public void service(Request req, final Response res)
+            throws Exception {
+        try {
+            
+            MessageBytes decodedURI = req.decodedURI();
+            decodedURI.duplicate(req.requestURI());
+
+            if (decodedURI.getType() == MessageBytes.T_BYTES) {
+                // %xx decoding of the URL
+                try {
+                    req.getURLDecoder().convert(decodedURI, false);
+                } catch (IOException ioe) {
+                    res.setStatus(400);
+                    res.setMessage("Invalid URI");
+                    throw ioe;
+                }
+                // Normalization
+                if (!normalize(req.decodedURI())) {
+                    res.setStatus(400);
+                    res.setMessage("Invalid URI");
+                    return;
+                }
+                // Character decoding
+                //convertURI(decodedURI, request);
+            } else {
+                // The URL is chars or String, and has been sent using an 
in-memory
+                // protocol handler, we have to assume the URL has been 
properly
+                // decoded already
+                decodedURI.toChars();
+            }
+
+
+            
+            // TODO: per thread data - does it help ? 
+            
+            MappingData mapRes = new MappingData();
+            mapper.map(req.remoteHost(), req.decodedURI(), 
+                       mapRes);
+            
+            ServletConfigImpl h=(ServletConfigImpl)mapRes.wrapper;
+            if (h != null) {
+                serviceServlet( req, res, h );
+            }
+            
+        } catch( Throwable t ) {
+            t.printStackTrace(System.out);
+        } 
+
+        // Final processing
+        MessageWriter.getWriter(req, res, 0).flush();
+        res.finish();
+
+        req.recycle();
+        res.recycle();
+
+    }
+    
+    public static final int ADAPTER_NOTES = 1;
+
+    
+    /** Coyote / mapper adapter. Result of the mapper.
+     *  
+     *  This replaces the valve chain, the path is: 
+     *    1. coyote calls mapper -> result Adapter 
+     *    2. service is called. Additional filters are set on the wrapper. 
+     */
+    public void serviceServlet(org.apache.coyote.Request req, 
+                               org.apache.coyote.Response res,
+                               ServletConfigImpl servletConfig) 
+        throws IOException {
+        
+        ServletRequestImpl request = (ServletRequestImpl) 
req.getNote(ADAPTER_NOTES);
+        ServletResponseImpl response = (ServletResponseImpl) 
res.getNote(ADAPTER_NOTES);
+
+        if (request == null) {
+
+            // Create objects
+            request = new ServletRequestImpl();
+            request.setCoyoteRequest(req);
+            response = new ServletResponseImpl();
+            response.setRequest(request);
+            response.setCoyoteResponse(res);
+
+            // Link objects
+            request.setResponse(response);
+
+            // Set as notes
+            req.setNote(ADAPTER_NOTES, request);
+            res.setNote(ADAPTER_NOTES, response);
+
+            // Set query string encoding
+//            req.getParameters().setQueryStringEncoding
+//                (connector.getURIEncoding());
+
+        }
+
+        try {
+
+            // Parse and set Catalina and configuration specific 
+            // request parameters
+//            if ( postParseRequest(req, request, res, response) ) {
+//                // Calling the container
+//                
connector.getContainer().getPipeline().getFirst().invoke(request, response);
+//            }
+            // Catalina default valves :
+            // Find host/context
+            // apply auth filters
+            // 
+            
+
+            Servlet servlet = servletConfig.allocate();
+            
+            servlet.service(request, response);
+            
+            response.finishResponse();
+            req.action( ActionCode.ACTION_POST_REQUEST , null);
+
+        } catch (IOException e) {
+            ;
+        } catch (Throwable t) {
+            t.printStackTrace();
+        } finally {
+            // Recycle the wrapper request and response
+            request.recycle();
+            response.recycle();
+        }
+    }
+
+    
+    /**
+     * Normalize URI.
+     * <p>
+     * This method normalizes "\", "//", "/./" and "/../". This method will
+     * return false when trying to go above the root, or if the URI contains
+     * a null byte.
+     * 
+     * @param uriMB URI to be normalized
+     */
+    public static boolean normalize(MessageBytes uriMB) {
+
+        ByteChunk uriBC = uriMB.getByteChunk();
+        byte[] b = uriBC.getBytes();
+        int start = uriBC.getStart();
+        int end = uriBC.getEnd();
+
+        // URL * is acceptable
+        if ((end - start == 1) && b[start] == (byte) '*')
+          return true;
+
+        int pos = 0;
+        int index = 0;
+
+        // Replace '\' with '/'
+        // Check for null byte
+        for (pos = start; pos < end; pos++) {
+            if (b[pos] == (byte) '\\')
+                b[pos] = (byte) '/';
+            if (b[pos] == (byte) 0)
+                return false;
+        }
+
+        // The URL must start with '/'
+        if (b[start] != (byte) '/') {
+            return false;
+        }
+
+        // Replace "//" with "/"
+        for (pos = start; pos < (end - 1); pos++) {
+            if (b[pos] == (byte) '/') {
+                while ((pos + 1 < end) && (b[pos + 1] == (byte) '/')) {
+                    copyBytes(b, pos, pos + 1, end - pos - 1);
+                    end--;
+                }
+            }
+        }
+
+        // If the URI ends with "/." or "/..", then we append an extra "/"
+        // Note: It is possible to extend the URI by 1 without any side effect
+        // as the next character is a non-significant WS.
+        if (((end - start) >= 2) && (b[end - 1] == (byte) '.')) {
+            if ((b[end - 2] == (byte) '/') 
+                || ((b[end - 2] == (byte) '.') 
+                    && (b[end - 3] == (byte) '/'))) {
+                b[end] = (byte) '/';
+                end++;
+            }
+        }
+
+        uriBC.setEnd(end);
+
+        index = 0;
+
+        // Resolve occurrences of "/./" in the normalized path
+        while (true) {
+            index = uriBC.indexOf("/./", 0, 3, index);
+            if (index < 0)
+                break;
+            copyBytes(b, start + index, start + index + 2, 
+                      end - start - index - 2);
+            end = end - 2;
+            uriBC.setEnd(end);
+        }
+
+        index = 0;
+
+        // Resolve occurrences of "/../" in the normalized path
+        while (true) {
+            index = uriBC.indexOf("/../", 0, 4, index);
+            if (index < 0)
+                break;
+            // Prevent from going outside our context
+            if (index == 0)
+                return false;
+            int index2 = -1;
+            for (pos = start + index - 1; (pos >= 0) && (index2 < 0); pos --) {
+                if (b[pos] == (byte) '/') {
+                    index2 = pos;
+                }
+            }
+            copyBytes(b, start + index2, start + index + 3,
+                      end - start - index - 3);
+            end = end + index2 - index - 3;
+            uriBC.setEnd(end);
+            index = index2;
+        }
+
+        //uriBC.setBytes(b, start, end);
+        uriBC.setEnd(end);
+        return true;
+
+    }
+
+    
+    /**
+     * Copy an array of bytes to a different position. Used during 
+     * normalization.
+     */
+    protected static void copyBytes(byte[] b, int dest, int src, int len) {
+        for (int pos = 0; pos < len; pos++) {
+            b[pos + dest] = b[pos + src];
+        }
+    }
+
+    public boolean event(Request req, Response res, boolean error) throws 
Exception {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+}
\ No newline at end of file

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletContextImpl.java Tue 
May 23 19:54:17 2006
@@ -66,11 +66,9 @@
 
     // ----------------------------------------------------------- Constructors
 
-    public ServletContextImpl(String basePath) {
-        this.basePath = basePath;
+    public ServletContextImpl() {
     }
 
-
     // ----------------------------------------------------- Instance Variables
 
 
@@ -1008,6 +1006,14 @@
 
     void setPath(String path) {
         this.path = path;
+    }
+    
+    public void setBasePath(String basePath) {
+        this.basePath = basePath;        
+    }
+
+    public String getBasePath() {
+        return basePath;
     }
 
     public SessionManager getManager() {

Modified: 
tomcat/sandbox/java/org/apache/coyote/servlet/ServletInputStreamImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletInputStreamImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletInputStreamImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletInputStreamImpl.java 
Tue May 23 19:54:17 2006
@@ -21,7 +21,7 @@
 
 import javax.servlet.ServletInputStream;
 
-import org.apache.coyote.standalone.MessageReader;
+import org.apache.coyote.servlet.util.MessageReader;
 
 /**
  * This class handles reading bytes.

Modified: 
tomcat/sandbox/java/org/apache/coyote/servlet/ServletOutputStreamImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletOutputStreamImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletOutputStreamImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletOutputStreamImpl.java 
Tue May 23 19:54:17 2006
@@ -21,7 +21,7 @@
 
 import javax.servlet.ServletOutputStream;
 
-import org.apache.coyote.standalone.MessageWriter;
+import org.apache.coyote.servlet.util.MessageWriter;
 
 /**
  * Coyote implementation of the servlet output stream.

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletReaderImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletReaderImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletReaderImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletReaderImpl.java Tue 
May 23 19:54:17 2006
@@ -20,7 +20,7 @@
 import java.io.BufferedReader;
 import java.io.IOException;
 
-import org.apache.coyote.standalone.MessageReader;
+import org.apache.coyote.servlet.util.MessageReader;
 
 
 /**

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletRequestImpl.java Tue 
May 23 19:54:17 2006
@@ -53,10 +53,10 @@
 
 import org.apache.coyote.ActionCode;
 import org.apache.coyote.servlet.util.Enumerator;
+import org.apache.coyote.servlet.util.MessageReader;
 import org.apache.coyote.servlet.util.ParameterMap;
 import org.apache.coyote.servlet.util.RequestUtil;
 import org.apache.coyote.servlet.util.StringParser;
-import org.apache.coyote.standalone.MessageReader;
 
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.buf.MessageBytes;

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletResponseImpl.java Tue 
May 23 19:54:17 2006
@@ -34,7 +34,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.coyote.servlet.util.CharsetMapper;
-import org.apache.coyote.standalone.MessageWriter;
+import org.apache.coyote.servlet.util.MessageWriter;
 
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.UEncoder;

Modified: tomcat/sandbox/java/org/apache/coyote/servlet/ServletWriterImpl.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/ServletWriterImpl.java?rev=409044&r1=409043&r2=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/servlet/ServletWriterImpl.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/ServletWriterImpl.java Tue 
May 23 19:54:17 2006
@@ -20,7 +20,7 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 
-import org.apache.coyote.standalone.MessageWriter;
+import org.apache.coyote.servlet.util.MessageWriter;
 
 /**
  * Coyote implementation of the servlet writer.

Copied: 
tomcat/sandbox/java/org/apache/coyote/servlet/util/ClientAbortException.java 
(from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/ClientAbortException.java)
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/util/ClientAbortException.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/util/ClientAbortException.java&p1=tomcat/sandbox/java/org/apache/coyote/standalone/ClientAbortException.java&r1=408800&r2=409044&rev=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/standalone/ClientAbortException.java 
(original)
+++ 
tomcat/sandbox/java/org/apache/coyote/servlet/util/ClientAbortException.java 
Tue May 23 19:54:17 2006
@@ -15,7 +15,7 @@
  */
 
 
-package org.apache.coyote.standalone;
+package org.apache.coyote.servlet.util;
 
 import java.io.IOException;
 

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageReader.java 
(from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/MessageReader.java)
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageReader.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageReader.java&p1=tomcat/sandbox/java/org/apache/coyote/standalone/MessageReader.java&r1=408800&r2=409044&rev=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/standalone/MessageReader.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageReader.java Tue 
May 23 19:54:17 2006
@@ -14,7 +14,7 @@
  * limitations under the License.
  */ 
 
-package org.apache.coyote.standalone;
+package org.apache.coyote.servlet.util;
 
 import java.io.IOException;
 import java.io.Reader;

Copied: tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java 
(from r408800, 
tomcat/sandbox/java/org/apache/coyote/standalone/MessageWriter.java)
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java?p2=tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java&p1=tomcat/sandbox/java/org/apache/coyote/standalone/MessageWriter.java&r1=408800&r2=409044&rev=409044&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/standalone/MessageWriter.java 
(original)
+++ tomcat/sandbox/java/org/apache/coyote/servlet/util/MessageWriter.java Tue 
May 23 19:54:17 2006
@@ -14,7 +14,7 @@
  * limitations under the License.
  */ 
 
-package org.apache.coyote.standalone;
+package org.apache.coyote.servlet.util;
 
 
 import java.io.IOException;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to