tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util BuffTool.java CookieTools.java RequestUtil.java SecurityTools.java SessionUtil.java
Date Tue, 22 Aug 2000 06:56:59 GMT
costin      00/08/21 23:56:58

  Modified:    .        build.xml
               src/share/org/apache/tomcat/core Request.java Response.java
               src/share/org/apache/tomcat/facade
                        HttpServletRequestFacade.java
               src/share/org/apache/tomcat/request JDBCRealm.java
                        SessionInterceptor.java SimpleRealm.java
                        StaticInterceptor.java
               src/share/org/apache/tomcat/service/http
                        HttpRequestAdapter.java
               src/share/org/apache/tomcat/session StandardManager.java
               src/share/org/apache/tomcat/util BuffTool.java
  Added:       src/share/org/apache/tomcat/helper CookieTools.java
                        RequestUtil.java SecurityTools.java
                        SessionUtil.java
  Removed:     src/share/org/apache/tomcat/util CookieTools.java
                        RequestUtil.java SecurityTools.java
                        SessionUtil.java
  Log:
  More work on separation of modules.
  
  Now "ant tomcat-jars" will build the individual modules as separate jar
  files ( even if compile still has extra dependencies )
  
  Revision  Changes    Path
  1.66      +41 -20    jakarta-tomcat/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/build.xml,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- build.xml	2000/08/22 06:10:37	1.65
  +++ build.xml	2000/08/22 06:56:38	1.66
  @@ -98,10 +98,6 @@
         optimize="${optimize}"
         deprecation="off"
         srcdir="src/share" >
  -      <classpath>
  -	<!-- XXX move serlvet-specific code to helper -->
  -	<pathelement location="${servlet22.jar}" />
  -      </classpath>
         <include name="org/apache/tomcat/util/**" />    
         <include name="org/apache/tomcat/logging/**" />    
         <exclude name="**/util/net/SSLSocketFactory.java"
  @@ -114,6 +110,26 @@
       </jar>
     </target>
   
  +  <!-- ==================== Tomcat.jar ( starter )  ==================== -->
  +
  +  <target name="tomcat.jar" depends="init" >
  +    <javac destdir="${tomcat.build}/classes"
  +      debug="${debug}" 
  +      optimize="${optimize}"
  +      deprecation="off"
  +      srcdir="src/share" >
  +      <!-- no dependencies -->
  +      <include name="org/apache/tomcat/startup/Main.java" />    
  +      <include name="org/apache/tomcat/util/SimpleClassLoader.java" />    
  +    </javac>
  +    <jar jarfile="${tomcat.build}/lib/tomcat.jar"
  +      basedir="${tomcat.build}/classes" 
  +      manifest="src/build/manifest" > 
  +      <include name="org/apache/tomcat/startup/Main.class" /> 
  +      <include name="org/apache/tomcat/util/SimpleClassLoader**" /> 
  +    </jar>
  +  </target>
  +
     <!-- ==================== Tomcat core ==================== -->
   
     <target name="tomcat_core" depends="init" >
  @@ -127,6 +143,7 @@
   	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
         </classpath>
         <include name="org/apache/tomcat/core/**" />    
  +      <include name="org/apache/tomcat/helper/**" />    
         <include name="org/apache/tomcat/loader/**" />    
         <exclude name="org/apache/tomcat/loader/AdaptiveClassLoader12.java" 
                  unless="jdk12.present"/>
  @@ -139,9 +156,9 @@
       <jar jarfile="${tomcat.build}/lib/tomcat_core.jar"
         basedir="${tomcat.build}/classes" > 
         <include name="org/apache/tomcat/core/**" />    
  -      <include name="org/apache/tomcat/util/**" />    
  -      <include name="org/apache/tomcat/startup/**" />    
  +      <include name="org/apache/tomcat/helper/**" />    
         <include name="org/apache/tomcat/loader/**" />    
  +      <include name="org/apache/tomcat/resources/**" />    
       </jar>
     </target>
   
  @@ -155,12 +172,11 @@
         srcdir="src/share" >
         <classpath>
   	<pathelement location="${servlet22.jar}" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_core.jar" />
         </classpath>
         <include name="org/apache/tomcat/startup/**" />    
  -      <include name="org/apache/tomcat/helper/**" />    
  -      <!-- servlet-version specific code 
  -      <exclude name="**/EmbededTomcat.java" />
  -       -->
  +      <exclude name="**/EmbededTomcat.java" unless="jdk12.present" />
       </javac>
       <copydir src="src/share/org/apache/tomcat" 
                dest="${tomcat.build}/classes/org/apache/tomcat">
  @@ -182,11 +198,13 @@
         debug="${debug}" 
         optimize="${optimize}"
         deprecation="off"
  -      srcdir="src/facade22" >
  +      srcdir="src/share" >
         <classpath>
   	<pathelement location="${servlet22.jar}" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_core.jar" />
         </classpath>
  -      <include name="org/apache/tomcat/facade22/**" />    
  +      <include name="org/apache/tomcat/facade/**" />    
       </javac>
       <jar jarfile="${tomcat.build}/lib/facade22.jar"
         basedir="${tomcat.build}/classes" > 
  @@ -203,6 +221,8 @@
         srcdir="src/facade23" >
         <classpath>
   	<pathelement location="${servlet23.jar}" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_core.jar" />
         </classpath>
         <include name="org/apache/tomcat/facade23/**" />    
       </javac>
  @@ -222,9 +242,13 @@
         deprecation="off" >
         <classpath>
   	<pathelement location="${servlet22.jar}" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_util.jar" />
  +	<pathelement location="${tomcat.build}/lib/tomcat_core.jar" />
         </classpath>
         <include name="org/apache/tomcat/context/**" />    
         <include name="org/apache/tomcat/request/**" />    
  +      <include name="org/apache/tomcat/service/**" />    
  +      <include name="org/apache/tomcat/session/**" />    
         <exclude name="org/apache/tomcat/request/Jdk12Interceptor.java" 
   	unless="jdk12.present"/>
         <exclude name="org/apache/tomcat/context/LoaderInterceptor1.java" 
  @@ -236,6 +260,8 @@
         basedir="${tomcat.build}/classes" > 
         <include name="org/apache/tomcat/context/**" /> 
         <include name="org/apache/tomcat/request/**" /> 
  +      <include name="org/apache/tomcat/service/**" /> 
  +      <include name="org/apache/tomcat/session/**" /> 
       </jar>
     </target>
   
  @@ -289,8 +315,9 @@
     </target>
   
     <!-- ==================== Old "jar all" ========== -->
  -  <target name="tomcat-jars" depends="jasper">
  +  <target name="tomcat-jars" depends="tomcat_util,tomcat.jar,tomcat_core,jasper,facade22,tomcat_modules,tomcat_config">
       <!-- create tomcat jar files -->
  +    <!-- 
       <jar jarfile="${tomcat.build}/lib/webserver.jar"
         basedir="${tomcat.build}/classes" > 
         <include name="org/apache/tomcat/**" /> 
  @@ -298,14 +325,8 @@
         <exclude name="org/apache/tomcat/j2ee/**" />
         <exclude name="org/apache/tomcat/util/XMLParser.class" /> 
         <exclude name="org/apache/tomcat/util/XMLTree.class" />
  -    </jar>
  -    <!-- minimal set of classes needed to start up tomcat -->
  -    <jar jarfile="${tomcat.build}/lib/tomcat.jar"
  -      basedir="${tomcat.build}/classes" 
  -      manifest="src/build/manifest" > 
  -      <include name="org/apache/tomcat/startup/Main.class" /> 
  -      <include name="org/apache/tomcat/util/SimpleClassLoader**" /> 
       </jar>
  +    -->
     </target>
   
     <!-- ==================== J2EE integration ========== -->
  
  
  
  1.55      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Request.java	2000/08/18 03:42:14	1.54
  +++ Request.java	2000/08/22 06:56:40	1.55
  @@ -63,6 +63,7 @@
   import org.apache.tomcat.facade.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
  +import org.apache.tomcat.helper.*;
   import java.io.IOException;
   import java.io.*;
   import java.net.*;
  
  
  
  1.29      +4 -3      jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- Response.java	2000/08/14 17:49:13	1.28
  +++ Response.java	2000/08/22 06:56:40	1.29
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.28 2000/08/14 17:49:13 costin Exp $
  - * $Revision: 1.28 $
  - * $Date: 2000/08/14 17:49:13 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.29 2000/08/22 06:56:40 costin Exp $
  + * $Revision: 1.29 $
  + * $Date: 2000/08/22 06:56:40 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,7 @@
   import javax.servlet.*;
   import javax.servlet.http.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.facade.*;
   import org.apache.tomcat.logging.*;
   
  
  
  
  1.11      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HttpServletRequestFacade.java	2000/08/14 17:49:17	1.10
  +++ HttpServletRequestFacade.java	2000/08/22 06:56:43	1.11
  @@ -61,7 +61,7 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.util.*;
  -import org.apache.tomcat.util.RequestUtil;
  +import org.apache.tomcat.helper.RequestUtil;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.facade.*;
   import java.io.*;
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/helper/CookieTools.java
  
  Index: CookieTools.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/helper/CookieTools.java,v 1.1 2000/08/22 06:56:43 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/22 06:56:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.tomcat.helper;
  import  org.apache.tomcat.util.*;
  import java.text.*;
  import java.util.*;
  
  import javax.servlet.http.Cookie;
  
  // XXX use only one Date instance/request, reuse it.
  
  /**
   * Cookie utils - generate cookie header, etc
   *
   * @author Original Author Unknown
   * @author duncan@eng.sun.com
   */
  public class CookieTools {
  
      /** Return the header name to set the cookie, based on cookie
       *  version
       */
      public static String getCookieHeaderName(Cookie cookie) {
          int version = cookie.getVersion();
  
          if (version == 1) {
  	    return "Set-Cookie2";
          } else {
              return "Set-Cookie";
          }
      }
  
      /** Return the header value used to set this cookie
       *  @deprecated Use StringBuffer version
       */
      public static String getCookieHeaderValue(Cookie cookie) {
          StringBuffer buf = new StringBuffer();
  	getCookieHeaderValue( cookie, buf );
  	return buf.toString();
      }
  
      /** Return the header value used to set this cookie
       */
      public static void getCookieHeaderValue(Cookie cookie, StringBuffer buf) {
          int version = cookie.getVersion();
  
          // this part is the same for all cookies
  
          buf.append(cookie.getName());
          buf.append("=");
          maybeQuote(version, buf, cookie.getValue());
  
   	// add version 1 specific information
  	if (version == 1) {
  	    // Version=1 ... required
  	    buf.append (";Version=1");
  
  	    // Comment=comment
  	    if (cookie.getComment() != null) {
  		buf.append (";Comment=");
  		maybeQuote (version, buf, cookie.getComment());
  	    }
  	}
  
  	// add domain information, if present
  
  	if (cookie.getDomain() != null) {
  	    buf.append(";Domain=");
  	    maybeQuote (version, buf, cookie.getDomain());
  	}
  
  	// Max-Age=secs/Discard ... or use old "Expires" format
  	if (cookie.getMaxAge() >= 0) {
  	    if (version == 0) {
  		buf.append (";Expires=");
  		DateTool.oldCookieFormat.format(new Date( System.currentTimeMillis() + cookie.getMaxAge() *1000L) ,buf,
  						new FieldPosition(0));
  
  	    } else {
  		buf.append (";Max-Age=");
  		buf.append (cookie.getMaxAge());
  	    }
  	} else if (version == 1)
  	  buf.append (";Discard");
  
  	// Path=path
  	if (cookie.getPath() != null) {
  	    buf.append (";Path=");
  	    maybeQuote (version, buf, cookie.getPath());
  	}
  
  	// Secure
  	if (cookie.getSecure()) {
  	  buf.append (";Secure");
  	}
      }
  
      static void maybeQuote (int version, StringBuffer buf,
                                      String value)
      {
  	if (version == 0 || isToken (value))
  	  buf.append (value);
  	else {
  	    buf.append ('"');
  	    buf.append (value);
  	    buf.append ('"');
  	}
      }
  
          //
      // from RFC 2068, token special case characters
      //
      private static final String tspecials = "()<>@,;:\\\"/[]?={} \t";
  
      /*
       * Return true iff the string counts as an HTTP/1.1 "token".
       */
      private static boolean isToken (String value) {
  	int len = value.length ();
  
  	for (int i = 0; i < len; i++) {
  	    char c = value.charAt (i);
  
  	    if (c < 0x20 || c >= 0x7f || tspecials.indexOf (c) != -1)
  	      return false;
  	}
  	return true;
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/helper/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.helper;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.core.Constants;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpUtils;
  import javax.servlet.http.Cookie;
  import java.text.*;
  
  /**
   * Usefull methods for request processing. Used to be in ServerRequest or Request,
   * but most are usefull in other adapters. 
   * 
   * @author James Duncan Davidson [duncan@eng.sun.com]
   * @author James Todd [gonzo@eng.sun.com]
   * @author Jason Hunter [jch@eng.sun.com]
   * @author Harish Prabandham
   * @author costin@eng.sun.com
   */
  public class RequestUtil {
  
      public static Hashtable readFormData( Request request ) {
  
          String contentType=request.getContentType();
  	if (contentType != null) {
              if (contentType.indexOf(";")>0)
                  contentType=contentType.substring(0,contentType.indexOf(";"));
              contentType = contentType.toLowerCase().trim();
          }
  
  	int contentLength=request.getContentLength();
  
  	if (contentType != null &&
              contentType.startsWith("application/x-www-form-urlencoded")) {
  	    try {
  		ServletInputStream is=request.getFacade().getInputStream();
                  Hashtable postParameters =  HttpUtils.parsePostData(contentLength, is);
  		return postParameters;
  	    }
  	    catch (IOException e) {
  		// nothing
  		// XXX at least warn ?
  	    }
          }
  	return null;
      }
  
      public static Hashtable mergeParameters(Hashtable one, Hashtable two) {
  	// Try some shortcuts
  	if (one.size() == 0) {
  	    return two;
  	}
  
  	if (two.size() == 0) {
  	    return one;
  	}
  
  	Hashtable combined = (Hashtable) one.clone();
  
          Enumeration e = two.keys();
  
  	while (e.hasMoreElements()) {
  	    String name = (String) e.nextElement();
  	    String[] oneValue = (String[]) one.get(name);
  	    String[] twoValue = (String[]) two.get(name);
  	    String[] combinedValue;
  
  	    if (oneValue == null) {
  		combinedValue = twoValue;
  	    }
  
  	    else {
  		combinedValue = new String[oneValue.length + twoValue.length];
  
  	        System.arraycopy(oneValue, 0, combinedValue, 0,
                      oneValue.length);
  	        System.arraycopy(twoValue, 0, combinedValue,
                      oneValue.length, twoValue.length);
  	    }
  
  	    combined.put(name, combinedValue);
  	}
  
  	return combined;
      }
  
      public static void processCookies( Request request, Vector cookies ) {
  	// XXX bug in original RequestImpl - might not work if multiple
  	// cookie headers.
  	//
  	// XXX need to use the cookies hint in RequestAdapter
      	String cookieString = request.getHeader("cookie");
  	
  	if (cookieString != null) {
              StringTokenizer tok = new StringTokenizer(cookieString,
                                                        ";", false);
              while (tok.hasMoreTokens()) {
                  String token = tok.nextToken();
                  int i = token.indexOf("=");
                  if (i > -1) {
  
                      // XXX
                      // the trims here are a *hack* -- this should
                      // be more properly fixed to be spec compliant
                      
                      String name = token.substring(0, i).trim();
                      String value = token.substring(i+1, token.length()).trim();
  		    // RFC 2109 and bug 
  		    value=stripQuote( value );
                      Cookie cookie = new Cookie(name, value);
                      cookies.addElement(cookie);
                  } else {
                      // we have a bad cookie.... just let it go
                  }
              }
          }
      }
  
      
      /**
       *
       * Strips quotes from the start and end of the cookie string
       * This conforms to RFC 2109
       * 
       * @param value            a <code>String</code> specifying the cookie 
       *                         value (possibly quoted).
       *
       * @see #setValue
       *
       */
      private static String stripQuote( String value )
      {
  	//	log("Strip quote from " + value );
  	if (((value.startsWith("\"")) && (value.endsWith("\""))) ||
  	    ((value.startsWith("'") && (value.endsWith("'"))))) {
  	    try {
  		return value.substring(1,value.length()-1);
  	    } catch (Exception ex) { 
  	    }
  	}
  	return value;
      }  
      
      public static void processFormData(String data, Hashtable parameters) {
          // XXX
          // there's got to be a faster way of doing this.
  	if( data==null ) return; // no parameters
          StringTokenizer tok = new StringTokenizer(data, "&", false);
          while (tok.hasMoreTokens()) {
              String pair = tok.nextToken();
  	    int pos = pair.indexOf('=');
  	    if (pos != -1) {
  		String key = unUrlDecode(pair.substring(0, pos));
  		String value = unUrlDecode(pair.substring(pos+1,
  							  pair.length()));
  		String values[];
  		if (parameters.containsKey(key)) {
  		    String oldValues[] = (String[])parameters.get(key);
  		    values = new String[oldValues.length + 1];
  		    for (int i = 0; i < oldValues.length; i++) {
  			values[i] = oldValues[i];
  		    }
  		    values[oldValues.length] = value;
  		} else {
  		    values = new String[1];
  		    values[0] = value;
  		}
  		parameters.put(key, values);
  	    } else {
  		// we don't have a valid chunk of form data, ignore
  	    }
          }
      }
  
      public static int readData(InputStream in, byte buf[], int length) {
          int read = 0;
          try {
              do {
                  read += in.read(buf, read, length - read);
              } while (read < length && read != -1);
          } catch (IOException e) {
              
          }
  	return read;
      }
  
      /**
       * This method decodes the given urlencoded string.
       *
       * @param  str the url-encoded string
       * @return the decoded string
       * @exception IllegalArgumentException If a '%' is not
       * followed by a valid 2-digit hex number.
       *
       * @author: cut & paste from JServ, much faster that previous tomcat impl 
       */
      public final static String URLDecode(String str)
  	throws NumberFormatException, StringIndexOutOfBoundsException
      {
          if (str == null)  return  null;
  
          StringBuffer dec = new StringBuffer();    // decoded string output
          int strPos = 0;
          int strLen = str.length();
  
          dec.ensureCapacity(str.length());
          while (strPos < strLen) {
              int laPos;        // lookahead position
  
              // look ahead to next URLencoded metacharacter, if any
              for (laPos = strPos; laPos < strLen; laPos++) {
                  char laChar = str.charAt(laPos);
                  if ((laChar == '+') || (laChar == '%')) {
                      break;
                  }
              }
  
              // if there were non-metacharacters, copy them all as a block
              if (laPos > strPos) {
                  dec.append(str.substring(strPos,laPos));
                  strPos = laPos;
              }
  
              // shortcut out of here if we're at the end of the string
              if (strPos >= strLen) {
                  break;
              }
  
              // process next metacharacter
              char metaChar = str.charAt(strPos);
              if (metaChar == '+') {
                  dec.append(' ');
                  strPos++;
                  continue;
              } else if (metaChar == '%') {
  		// We throw the original exception - the super will deal with it
  		//                try {
  		dec.append((char) Integer.parseInt(
  						   str.substring(strPos + 1, strPos + 3), 16));
  		//                } catch (NumberFormatException e) {
  		//                    throw new IllegalArgumentException("invalid hexadecimal "
  		//                    + str.substring(strPos + 1, strPos + 3)
  		//                    + " in URLencoded string (illegal unescaped '%'?)" );
  		//                } catch (StringIndexOutOfBoundsException e) {
  		//                    throw new IllegalArgumentException("illegal unescaped '%' "
  		//                    + " in URLencoded string" );
  		//                }
                  strPos += 3;
              }
          }
  
          return dec.toString();
      }
  
      public static String unUrlDecode(String data) {
  	StringBuffer buf = new StringBuffer();
  	for (int i = 0; i < data.length(); i++) {
  	    char c = data.charAt(i);
  	    switch (c) {
  	    case '+':
  		buf.append(' ');
  		break;
  	    case '%':
  		// XXX XXX 
  		try {
  		    buf.append((char) Integer.parseInt(data.substring(i+1,
                          i+3), 16));
  		    i += 2;
  		} catch (NumberFormatException e) {
                      String msg = "Decode error ";
  		    // XXX no need to add sm just for that
  		    // sm.getString("serverRequest.urlDecode.nfe", data);
  
  		    throw new IllegalArgumentException(msg);
  		} catch (StringIndexOutOfBoundsException e) {
  		    String rest  = data.substring(i);
  		    buf.append(rest);
  		    if (rest.length()==2)
  			i++;
  		}
  		
  		break;
  	    default:
  		buf.append(c);
  		break;
  	    }
  	}
  	return buf.toString();
      }           
  	
  
      // Basically return everything after ";charset="
      // If no charset specified, use the HTTP default (ASCII) character set.
      public static String getCharsetFromContentType(String type) {
          if (type == null) {
              return null;
          }
          int semi = type.indexOf(";");
          if (semi == -1) {
              return null;
          }
          String afterSemi = type.substring(semi + 1);
          int charsetLocation = afterSemi.indexOf("charset=");
          if (charsetLocation == -1) {
              return null;
          }
          String afterCharset = afterSemi.substring(charsetLocation + 8);
          String encoding = afterCharset.trim();
          return encoding;
      }
  
      public static Locale getLocale(Request req) {
      	String acceptLanguage = req.getHeader("Accept-Language");
  	    if( acceptLanguage == null ) return Locale.getDefault();
  
          Hashtable languages = new Hashtable();
          Vector quality=new Vector();
          processAcceptLanguage(acceptLanguage, languages,quality);
  
          if (languages.size() == 0) return Locale.getDefault();
  
          Vector l = new Vector();
          extractLocales( languages,quality, l);
  
          return (Locale)l.elementAt(0);
      }
  
      public static Enumeration getLocales(HttpServletRequest req) {
  	    String acceptLanguage = req.getHeader("Accept-Language");
      	// Short circuit with an empty enumeration if null header
          if (acceptLanguage == null) {
              Vector v = new Vector();
              v.addElement(Locale.getDefault());
              return v.elements();
          }
  
          Hashtable languages = new Hashtable();
          Vector quality=new Vector();
      	processAcceptLanguage(acceptLanguage, languages , quality);
  
          if (languages.size() == 0) {
              Vector v = new Vector();
              v.addElement(Locale.getDefault());
              return v.elements();
          }
      	Vector l = new Vector();
      	extractLocales( languages, quality , l);
      	return l.elements();
      }
  
      public static void processAcceptLanguage( String acceptLanguage,
  					      Hashtable languages, Vector q)
      {
          StringTokenizer languageTokenizer =
              new StringTokenizer(acceptLanguage, ",");
  
          while (languageTokenizer.hasMoreTokens()) {
              String language = languageTokenizer.nextToken().trim();
              int qValueIndex = language.indexOf(';');
              int qIndex = language.indexOf('q');
              int equalIndex = language.indexOf('=');
              Double qValue = new Double(1);
  
              if (qValueIndex > -1 &&
                      qValueIndex < qIndex &&
                      qIndex < equalIndex) {
      	        String qValueStr = language.substring(qValueIndex + 1);
                  language = language.substring(0, qValueIndex);
                  qValueStr = qValueStr.trim().toLowerCase();
                  qValueIndex = qValueStr.indexOf('=');
                  qValue = new Double(0);
                  if (qValueStr.startsWith("q") &&
                      qValueIndex > -1) {
                      qValueStr = qValueStr.substring(qValueIndex + 1);
                      try {
                          qValue = new Double(qValueStr.trim());
                      } catch (NumberFormatException nfe) {
                      }
                  }
              }
  
              // XXX
              // may need to handle "*" at some point in time
  
              if (! language.equals("*")) {
                  String key = qValue.toString();
                  Vector v;
                  if (languages.containsKey(key)) {
                      v = (Vector)languages.get(key) ;
                  } else {
                      v= new Vector();
                      q.addElement(qValue);
                  }
                  v.addElement(language);
                  languages.put(key, v);
              }
          }
      }
  
      public static void extractLocales(Hashtable languages, Vector q,Vector l)
      {
          // XXX We will need to order by q value Vector in the Future ?
          Enumeration e = q.elements();
          while (e.hasMoreElements()) {
              Vector v =
                  (Vector)languages.get(((Double)e.nextElement()).toString());
              Enumeration le = v.elements();
              while (le.hasMoreElements()) {
      	        String language = (String)le.nextElement();
  	        	String country = "";
          		int countryIndex = language.indexOf("-");
                  if (countryIndex > -1) {
                      country = language.substring(countryIndex + 1).trim();
                      language = language.substring(0, countryIndex).trim();
                  }
                  l.addElement(new Locale(language, country));
              }
          }
      }
  
  
  
      /* -------------------- From HttpDate -------------------- */
      // Parse date - XXX This code is _very_ slow ( 3 parsers, GregorianCalendar,
      // etc ). It was moved out to avoid creating 1 Calendar instance ( and
      // a associated parsing ) per header ( the Calendar was created in HttpDate
      // which was created for each HeaderField ).
      // This also avoid passing HttpHeaders - which was required to access
      // HttpHeaderFiled to access HttpDate to access the parsing code.
  
      // we force our locale here as all http dates are in english
      private final static Locale loc = Locale.US;
  
      // all http dates are expressed as time at GMT
      private final static TimeZone zone = TimeZone.getTimeZone("GMT");
  
      // format for RFC 1123 date string -- "Sun, 06 Nov 1994 08:49:37 GMT"
      private final static String rfc1123Pattern ="EEE, dd MMM yyyyy HH:mm:ss z";
  
      // format for RFC 1036 date string -- "Sunday, 06-Nov-94 08:49:37 GMT"
      private final static String rfc1036Pattern ="EEEEEEEEE, dd-MMM-yy HH:mm:ss z";
  
      // format for C asctime() date string -- "Sun Nov  6 08:49:37 1994"
      private final static String asctimePattern ="EEE MMM d HH:mm:ss yyyyy";
  
      private final static SimpleDateFormat rfc1123Format =
  	new SimpleDateFormat(rfc1123Pattern, loc);
  
      private final static SimpleDateFormat rfc1036Format =
  	new SimpleDateFormat(rfc1036Pattern, loc);
  
      private final static SimpleDateFormat asctimeFormat =
  	new SimpleDateFormat(asctimePattern, loc);
  
      public static long toDate( String dateString ) {
  	// XXX
  	Date date=null;
  	try {
              date = rfc1123Format.parse(dateString);
  	} catch (ParseException e) { }
  	
          if( date==null)
  	    try {
  		date = rfc1036Format.parse(dateString);
  	    } catch (ParseException e) { }
  	
          if( date==null)
  	    try {
  		date = asctimeFormat.parse(dateString);
  	    } catch (ParseException pe) {
  	    }
  
  	if(date==null) {
  	    return -1;
  	}
  
  	// Original code was: 
  	//	Calendar calendar = new GregorianCalendar(zone, loc);
  	//calendar.setTime(date);
  	// calendar.getTime().getTime();
  	return date.getTime();
      }
      
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/helper/SecurityTools.java
  
  Index: SecurityTools.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  package org.apache.tomcat.helper;
  
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.util.xml.*;
  import javax.servlet.http.HttpSession;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import org.xml.sax.*;
  
  /**
   *  Various tools used to implement security.
   * 
   */
  public class SecurityTools {
      
      static int base64[]= {
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
  	    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
  	    64,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
  	    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
  	    64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  	    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  	    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
      };
  
      public static String base64Decode( String orig ) {
  	char chars[]=orig.toCharArray();
  	StringBuffer sb=new StringBuffer();
  	int i=0;
  
  	int shift = 0;   // # of excess bits stored in accum
  	int acc = 0;
  	
  	for (i=0; i<chars.length; i++) {
  	    int v = base64[ chars[i] & 0xFF ];
  	    
  	    if ( v >= 64 ) {
  		if( chars[i] != '=' )
  		    System.out.println("Wrong char in base64: " + chars[i]);
  	    } else {
  		acc= ( acc << 6 ) | v;
  		shift += 6;
  		if ( shift >= 8 ) {
  		    shift -= 8;
  		    sb.append( (char) ((acc >> shift) & 0xff));
  		}
  	    }
  	}
  	return sb.toString();
      }
  
      /** Extract the credentails from req
       */
      public static void credentials( Request req , Hashtable credentials ) {
  	Context ctx=req.getContext();
  	String login_type=ctx.getAuthMethod();
  	if( "BASIC".equals( login_type )) {
  	    basicCredentials( req, credentials );
  	}
  	if( "FORM".equals( login_type )) {
  	    formCredentials( req, credentials );
  	}
      }
  	
      
      // XXX use more efficient structures instead of StringBuffer ?
      // ( after everything is stable - not very important if web server is used)
  
      /** Extract userName and password from a request using basic authentication.
       *  Can be used in a JAAS callback or as it is. 
       */
      public static void basicCredentials( Request req, Hashtable credentials )
      {
  	Context ctx=req.getContext();
  
  	String authMethod=ctx.getAuthMethod();
  	if( authMethod==null || "BASIC".equals(authMethod) ) {
  
  	    String authorization = req.getHeader("Authorization");
  
  	    if (authorization == null )
  		return; // no credentials
  	    if( ! authorization.startsWith("Basic "))
  		return; // wrong syntax
  
  	    authorization = authorization.substring(6).trim();
  	    String unencoded=SecurityTools.base64Decode( authorization );
  
  	    int colon = unencoded.indexOf(':');
  	    if (colon < 0)
  		return;
  
  	    credentials.put( "username" , unencoded.substring(0, colon));
  	    credentials.put( "password" , unencoded.substring(colon + 1));
  
  	}
  	return;
      }
  
  
      public static void formCredentials( Request req, Hashtable credentials ) {
  	Context ctx=req.getContext();
  	String authMethod=ctx.getAuthMethod();
  
  	if( "FORM".equals( authMethod ) ) {
  	    HttpSession session=req.getSession( false );
  
  	    if( session == null )
  		return; // not authenticated
  
  	    // XXX The attributes are set on the first access.
  	    // It is possible for a servlet to set the attributes and
  	    // bypass the security checking - but that's ok, since
  	    // everything happens inside a web application and all servlets
  	    // are in the same domain.
  	    String username=(String)session.getAttribute("j_username");
  	    String password=(String)session.getAttribute("j_password");
  	    if( username!=null && password!=null) {
  		credentials.put( "username" , username );
  		credentials.put( "password", password);
  	    }
  	}
      }
  
      public static boolean haveRole( String userRoles[], String requiredRoles[] ) {
  	for( int i=0; i< userRoles.length; i ++ ) {
  	    if( haveRole( userRoles[i], requiredRoles )) return true;
  	}
  	return false;
      }
  
      public static boolean haveRole( String element, String set[] ) {
  	for( int i=0; i< set.length; i ++ ) {
  	    if( element!=null && element.equals( set[i] ))
  		return true;
  	}
  	return false;
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/helper/SessionUtil.java
  
  Index: SessionUtil.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/helper/SessionUtil.java,v 1.1 2000/08/22 06:56:43 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/22 06:56:43 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.helper;
  
  
  import javax.servlet.http.Cookie;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.*;
  
  
  /**
   * General purpose utilities useful to <code>Manager</code> and
   * <code>Session</code> implementations.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/08/22 06:56:43 $
   */
  
  public final class SessionUtil {
      public static final String SESSION_COOKIE_NAME = "JSESSIONID";
      public static final String SESSION_PARAMETER_NAME = "jsessionid";
  
  
      // ------------------------------------------------------- Static Variables
  
  
      /**
       * Private counter used in generating session identifiers.
       */
      private static int counter = 1010;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Construct and return an HTTP Cookie object that contains the specified
       * session id.  If a cookie cannot be created for any reason, return
       * <code>null</code>.
       *
       * @param req The request asking for this cookie to be created
       * @param id The session id for which a cookie should be constructed
       */
      public static Cookie createCookie(Request req, String id) {
  
  	Cookie cookie = new Cookie(SESSION_COOKIE_NAME, id);
  	String serverName = req.getServerName();
  	if (serverName != null)
  	    cookie.setDomain(serverName);
  	String contextPath = req.getContext().getPath();
  	if ((contextPath != null) && (contextPath.length() > 0))
  	    cookie.setPath(contextPath);
  	else
  	    cookie.setPath("/");
  	cookie.setMaxAge(-1);
  	cookie.setVersion(1);
  	return (cookie);
  
      }
  
  
      /**
       * Encode the specified session id into the specified redirect URL,
       * if it is an absolute URL that returns to the specified host name
       * (presumably the host name on which this request was received).
       * If URL rewriting is disabled or unnecessary, the specified URL
       * will be returned unchanged.
       *
       * @param req The request for which we are encoding the session id
       * @param id The session id to be encoded
       * @param url The URL to be encoded with the session id
       *
       * @exception IllegalArgumentException if the specified URL is
       *	not absolute
       */
      public static String encodeRedirectURL(Request req, String id,
  					   String url) {
  
  	// FIXME: Are the rules really the same?
  	return (encodeURL(req, id, url));
  
      }
  
  
      /**
       * Encode the specified session id into the specified URL,
       * if it is a relative URL or an absolute URL that returns to the
       * specified host name (presumably the host name on which this request
       * was received).  If URL rewriting is disabled or unnecessary,
       * the specified URL will be returned unchanged.
       *
       * @param req The request for which we are encoding the session id
       * @param id The session id to be encoded
       * @param url The URL to be encoded with the session id
       */
      public static String encodeURL(Request req, String id, String url) {
  
  	// Encode all relative URLs unless they start with a hash
  	if (!url.startsWith("http:")) {
  	    if (!url.startsWith("#"))
  		return (encode(id, url));
  	    else
  		return (url);
  	}
  
  	// Encode all absolute URLs that return to this hostname
  	String serverName = req.getServerName();
  	String match = "http://" + serverName;
  	if (url.startsWith("http://" + serverName))
  	    return (encode(id, url));
  	else
  	    return (url);
  
      }
  
      /**
       * Generate and return a new session identifier.
       */
      public static String generateSessionId() {
          return SessionIdGenerator.generateId();
      }
  
      /**
       * Return the session id from the specified array of cookies,
       * where the session id cookie was presumably created by the
       * <code>createCookie()</code> method of this Manager.
       * If there is no session id cookie included, return <code>null</code>.
       *
       * @param cookies Array of cookies from which to extract the session id
       */
      public static String parseSessionId(Cookie cookies[]) {
  
  	if (cookies == null)
  	    return (null);
  	for (int i = 0; i < cookies.length; i++) {
  	    if (SESSION_COOKIE_NAME.equals(cookies[i].getName()))
  		return (cookies[i].getValue());
  	}
  	return (null);
  
      }
  
  
      /**
       * Return the session id from the specified request URI, where
       * it was presumably encoded via the <code>encodeRedirectURL()</code> or
       * <code>encodeURL()</code> method of this Manager.
       * If there is no session id included, return <code>null</code>.
       *
       * @param uri The request URI from which to extract the session id
       */
      public static String parseSessionId(String uri) {
  
  	// Search for the required match string in the URI
  	String match = ";" + SESSION_PARAMETER_NAME + "=";
  	int m = uri.indexOf(match);
  	if (m < 0)
  	    return (null);
  
  	// Parse the session identifier
  	String temp = uri.substring(m + match.length());
  	int s = temp.indexOf(';');
  	int q = temp.indexOf('?');
  	if (s < 0) {
  	    if (q < 0)
  		return (temp);
  	    else
  		return (temp.substring(0, q));
  	} else {
  	    if (q < 0)
  		return (temp.substring(0, s));
  	    else if (q < s)
  		return (temp.substring(0, q));
  	    else
  		return (temp.substring(0, s));
  	}
  
      }
  
  
      // -------------------------------------------------------- Private Methods
  
  
      /**
       * Encode the specified session identifier into the specified URL,
       * and return the resulting string.
       *
       * @param id The session id to be encoded
       * @param url The URL to be encoded with the session id
       */
      private static String encode(String id, String url) {
  
  	if ((id == null) || (url == null))
  	    return (url);
  
  	// Locate the beginning of the query string (if any)
  	int question = url.indexOf('?');
  
  	// Encode the session identifier appropriately (before any query)
  	StringBuffer buf = new StringBuffer();
  	if (question < 0)
  	    buf.append(url);
  	else
  	    buf.append(url.substring(0, question));
  	buf.append(';');
  	buf.append(SESSION_PARAMETER_NAME);
  	buf.append('=');
  	buf.append(id);
  	if (question >= 0)
  	    buf.append(url.substring(question));
  	return (buf.toString());
  
      }
  
  
  }
  
  
  
  
  
  
  1.17      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java
  
  Index: JDBCRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/JDBCRealm.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JDBCRealm.java	2000/08/17 22:22:24	1.16
  +++ JDBCRealm.java	2000/08/22 06:56:51	1.17
  @@ -59,6 +59,7 @@
   package org.apache.tomcat.request;
   
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.util.xml.*;
   import org.apache.tomcat.logging.*;
  
  
  
  1.25      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java
  
  Index: SessionInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SessionInterceptor.java	2000/06/30 20:21:41	1.24
  +++ SessionInterceptor.java	2000/08/22 06:56:51	1.25
  @@ -62,6 +62,7 @@
   
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import java.io.*;
   import java.net.*;
   import java.util.*;
  
  
  
  1.8       +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java
  
  Index: SimpleRealm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleRealm.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SimpleRealm.java	2000/08/17 22:22:25	1.7
  +++ SimpleRealm.java	2000/08/22 06:56:52	1.8
  @@ -62,6 +62,7 @@
   
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.util.xml.*;
   import java.io.*;
   import java.net.*;
  
  
  
  1.13      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StaticInterceptor.java	2000/08/11 06:14:11	1.12
  +++ StaticInterceptor.java	2000/08/22 06:56:52	1.13
  @@ -61,6 +61,7 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.core.Constants;
   import org.apache.tomcat.request.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.util.*;
   import java.io.*;
   import java.net.*;
  
  
  
  1.26      +4 -3      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java
  
  Index: HttpRequestAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- HttpRequestAdapter.java	2000/08/12 04:55:48	1.25
  +++ HttpRequestAdapter.java	2000/08/22 06:56:55	1.26
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v 1.25 2000/08/12 04:55:48 costin Exp $
  - * $Revision: 1.25 $
  - * $Date: 2000/08/12 04:55:48 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v 1.26 2000/08/22 06:56:55 costin Exp $
  + * $Revision: 1.26 $
  + * $Date: 2000/08/22 06:56:55 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   package org.apache.tomcat.service.http;
   
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import java.io.*;
  
  
  
  1.13      +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java
  
  Index: StandardManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- StandardManager.java	2000/08/11 21:20:41	1.12
  +++ StandardManager.java	2000/08/22 06:56:55	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.12 2000/08/11 21:20:41 costin Exp $
  - * $Revision: 1.12 $
  - * $Date: 2000/08/11 21:20:41 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/StandardManager.java,v 1.13 2000/08/22 06:56:55 costin Exp $
  + * $Revision: 1.13 $
  + * $Date: 2000/08/22 06:56:55 $
    *
    * ====================================================================
    *
  @@ -71,6 +71,7 @@
   import javax.servlet.http.Cookie;
   import javax.servlet.http.HttpSession;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.helper.*;
   import org.apache.tomcat.core.Request;
   
   /**
  @@ -102,7 +103,7 @@
    * @author Craig R. McClanahan
    * @author costin@eng.sun.com
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Revision: 1.12 $ $Date: 2000/08/11 21:20:41 $
  + * @version $Revision: 1.13 $ $Date: 2000/08/22 06:56:55 $
    */
   public final class StandardManager implements Runnable  {
       // ----------------------------------------------------- Instance Variables
  
  
  
  1.8       +5 -4      jakarta-tomcat/src/share/org/apache/tomcat/util/BuffTool.java
  
  Index: BuffTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/BuffTool.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BuffTool.java	2000/06/23 02:16:29	1.7
  +++ BuffTool.java	2000/08/22 06:56:56	1.8
  @@ -61,7 +61,6 @@
   package org.apache.tomcat.util;
   
   import org.apache.tomcat.util.StringManager;
  -import org.apache.tomcat.core.Constants;
   import java.io.*;
   
   /**
  @@ -69,6 +68,8 @@
    *
    */
   public class BuffTool {
  +    public static final String DEFAULT_CHAR_ENCODING = "8859_1";
  +
       
       public static  void addInt( byte buff[], int pos, int v ) {
   	buff[pos]=(byte) ((v >>>  8) & 0xFF);
  @@ -100,7 +101,7 @@
       public static String getString( byte b[] , int pos, int len ) 
           throws UnsupportedEncodingException
       {
  -	return new String( b, pos, len, Constants.DEFAULT_CHAR_ENCODING );
  +	return new String( b, pos, len, DEFAULT_CHAR_ENCODING );
       }
   
   
  @@ -115,9 +116,9 @@
   		}
   	    }
   	    if( i+8 <len )
  -		System.out.print( new String( buff, i, 8, Constants.DEFAULT_CHAR_ENCODING ));
  +		System.out.print( new String( buff, i, 8, DEFAULT_CHAR_ENCODING ));
   	    else
  -		System.out.print( new String( buff, i, len-i, Constants.DEFAULT_CHAR_ENCODING ));
  +		System.out.print( new String( buff, i, len-i, DEFAULT_CHAR_ENCODING ));
   	    System.out.println();
   	}
   	System.out.println();
  
  
  

Mime
View raw message