cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java

2000-12-01 Thread costin

costin  00/12/01 00:19:18

  Modified:src/share/org/apache/tomcat/modules/session SessionId.java
   src/share/org/apache/tomcat/request AccessInterceptor.java
   src/share/org/apache/tomcat/util/http Cookies.java
ServerCookie.java
  Log:
  - Finish the new parser for Cookies - supports Version=1, faster, better
  ( I hope ). It needs few more tests and cleanup, but it should be ok.
  I'll start removing the old code, and need to make sure all cookies-related
  fixes from 3.2 are merged.
  
  - SessionId - send only one cookie ( that is supported by all browsers ),
  don't send the cookie ( Set-Cookie:) if we are in the same session already
  ( save bandwith, browser warnings if the user have verbose cookies )
  
  - fixed small bug in AccessInterceptor ( the substring mini-optimization)
  
  Revision  ChangesPath
  1.5   +19 -11
jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionId.java
  
  Index: SessionId.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionId.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SessionId.java2000/12/01 06:00:38 1.4
  +++ SessionId.java2000/12/01 08:19:14 1.5
  @@ -223,7 +223,13 @@
return 0;
   if (noCookies)
   return 0;
  -
  + if( reqSessionId.equals( rrequest.getRequestedSessionId() )) {
  + // we are already in a session - no need to
  + // send the Set-Cookie again ( plus it's annoying if
  + // the user doesn't want sessions but rewriting )
  + //  log( "We are in a session already ");
  + return 0;
  + }

   // GS, set the path attribute to the cookie. This way
   // multiple session cookies can be used, one for each
  @@ -242,19 +248,21 @@
   //  // }
   
// we know reqSessionId doesn't need quoting ( we generate it )
  - StringBuffer buf = new StringBuffer();
  - buf.append( "JSESSIONID=" ).append( reqSessionId );
  - buf.append( ";Version=1" );
  - buf.append( ";Path=" );
  - ServerCookie.maybeQuote( 1 , buf, sessionPath ); // XXX ugly 
  - buf.append( ";Discard" );
  - // discard results from:cookie.setMaxAge(-1);
  +//   StringBuffer buf = new StringBuffer();
  +//   buf.append( "JSESSIONID=" ).append( reqSessionId );
  +//   buf.append( ";Version=1" );
  +//   buf.append( ";Path=" );
  +//   ServerCookie.maybeQuote( 1 , buf, sessionPath ); // XXX ugly 
  +//   buf.append( ";Discard" );
  +//   // discard results from:cookie.setMaxAge(-1);


  - response.addHeader( "Set-Cookie2",
  - buf.toString() ); // XXX XXX garbage generator
  +//   response.addHeader( "Set-Cookie2",
  +//   buf.toString() ); // XXX XXX garbage generator
   
  - buf = new StringBuffer();
  + // We'll use a Netscape cookie for sessions - it's
  + // the only one supported by all browsers
  + StringBuffer buf = new StringBuffer();
buf.append( "JSESSIONID=" ).append( reqSessionId );
buf.append( ";Path=" ).append(  sessionPath  );
response.addHeader( "Set-Cookie",
  
  
  
  1.24  +2 -0  
jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java
  
  Index: AccessInterceptor.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/AccessInterceptor.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- AccessInterceptor.java2000/11/30 04:58:48 1.23
  +++ AccessInterceptor.java2000/12/01 08:19:16 1.24
  @@ -304,6 +304,8 @@
// changed to eliminate the allocation ( will be changed again
// when MessageBytes will be used in intercepotrs, now they are
// in core
  + if( path.length()  ctPathL - 2  )
  + return false;
for( int i=0; i ctPathL - 2 ; i++ ) {
if( path.charAt( i ) != ctPath.charAt( i ))
return false;
  
  
  
  1.4   +147 -51   
jakarta-tomcat/src/share/org/apache/tomcat/util/http/Cookies.java
  
  Index: Cookies.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/http/Cookies.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Cookies.java  2000/12/01 06:00:38 1.3
  +++ Cookies.java  2000/12/01 08:19:17 1.4
  @@ -79,7 +79,8 @@
   // expected average number of cookies per request
   public static final int INITIAL_SIZE=4; 
   ServerCookie scookies[]=new ServerCookie[INITIAL_SIZE];
  -int cookieCount=-1; // -1 = cookies not processed yet
  +int 

Re: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java

2000-12-01 Thread Paul Frieden

I was just flipping through this code because I did some changes to
CookieTools.  To force a V0 cookie to be deleted properly, the time
should actually be set way in the past rather than the current time to
make it be deleted properly.  I did it by checking if maxAge was 0 and
setting the expires time way back if it was rather than converting the
current time to the expiration time.

Paul

[EMAIL PROTECTED] wrote:
 
 costin  00/11/30 22:00:39
 
   Modified:src/facade22/org/apache/tomcat/facade
 HttpServletRequestFacade.java
 HttpServletResponseFacade.java
src/share/org/apache/tomcat/core Request.java
src/share/org/apache/tomcat/helper CookieTools.java
src/share/org/apache/tomcat/modules/session SessionId.java
src/share/org/apache/tomcat/util/http Cookies.java
 ServerCookie.java
   Added:   src/examples/WEB-INF/classes CookieExample1.java
   Log:
   - Start using Cookies and the enhanced ServerCookie.
 
   - CookieTools are no longer needed ( it's all commented out, will be
   removed after I test the new code )
 
   - Added a new example, that supports all V1 attributes ( even if no
   browser except lynx can be use V1 ) - it is needed to verify the
   parsing code works for V1.
 
   - The code now uses RFC2109 ( easy to go forward to 2965 ). Discard is removed,
   since it's in the new spec.
 
   Revision  ChangesPath
   1.1  
jakarta-tomcat/src/examples/WEB-INF/classes/CookieExample1.java
 
   Index: CookieExample1.java
   ===
   /* $Id: CookieExample1.java,v 1.1 2000/12/01 06:00:23 costin Exp $
*
*/
 
   import java.io.*;
   import java.text.*;
   import java.util.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
 
   /**
* Example servlet showing request headers
*
* @author James Duncan Davidson [EMAIL PROTECTED]
*/
 
   public class CookieExample1 extends HttpServlet {
 
   ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
 
   public void doGet(HttpServletRequest request,
 HttpServletResponse response)
   throws IOException, ServletException
   {
   response.setContentType("text/html");
 
   PrintWriter out = response.getWriter();
   out.println("html");
   out.println("body bgcolor=\"white\"");
   out.println("head");
 
   String title = rb.getString("cookies.title");
   out.println("title" + title + "/title");
   out.println("/head");
   out.println("body");
 
 // relative links
 
   // XXX
   // making these absolute till we work out the
   // addition of a PathInfo issue
 
   out.println("a href=\"/examples/servlets/cookies.html\"");
   out.println("img src=\"/examples/images/code.gif\" height=24 " +
   "width=24 align=right border=0 alt=\"view code\"/a");
   out.println("a href=\"/examples/servlets/index.html\"");
   out.println("img src=\"/examples/images/return.gif\" height=24 " +
   "width=24 align=right border=0 alt=\"return\"/a");
 
   out.println("h3" + title + "/h3");
 
   Cookie[] cookies = request.getCookies();
   if (cookies.length  0) {
   out.println(rb.getString("cookies.cookies") + "br");
   for (int i = 0; i  cookies.length; i++) {
   Cookie cookie = cookies[i];
   out.print("Cookie Name: " + cookie.getName() + "br");
   out.print("Cookie Value: " + cookie.getValue() + "br");
   out.println("Cookie Version: " + cookie.getVersion() + "br");
 out.println("Cookie Domain: " + cookie.getDomain() + "br");
 out.println("Cookie Path: " + cookie.getPath() + "br");
 out.println("br");
   }
   } else {
   out.println(rb.getString("cookies.no-cookies"));
   }
 
   String cookieName = request.getParameter("cookiename");
   String cookieValue = request.getParameter("cookievalue");
 String path= request.getParameter( "cookiepath" );
 String domain= request.getParameter( "cookiedomain" );
 String secure= request.getParameter( "cookiesecure" );
 String version= request.getParameter( "cookieversion" );
 String comment= request.getParameter( "cookiecomment" );
 String maxage= request.getParameter( "cookiemaxage" );
   if (cookieName != null  !"".equals( cookieName) ) {
 // cookie without value is valid !
 Cookie cookie = new Cookie(cookieName, cookieValue);
 if( ! "".equals( path ))
 cookie.setPath( path );
 if( ! "".equals( domain ))
 cookie.setDomain( domain 

Re: cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java

2000-12-01 Thread cmanolache

Thanks, I'll check it in. I was reviewing the 3.2 fixes in cookies, 
I hope I'll get them all updated.
( including this one )

Costin


 I was just flipping through this code because I did some changes to
 CookieTools.  To force a V0 cookie to be deleted properly, the time
 should actually be set way in the past rather than the current time to
 make it be deleted properly.  I did it by checking if maxAge was 0 and
 setting the expires time way back if it was rather than converting the
 current time to the expiration time.
 
 Paul
 
 [EMAIL PROTECTED] wrote:
  
  costin  00/11/30 22:00:39
  
Modified:src/facade22/org/apache/tomcat/facade
  HttpServletRequestFacade.java
  HttpServletResponseFacade.java
 src/share/org/apache/tomcat/core Request.java
 src/share/org/apache/tomcat/helper CookieTools.java
 src/share/org/apache/tomcat/modules/session SessionId.java
 src/share/org/apache/tomcat/util/http Cookies.java
  ServerCookie.java
Added:   src/examples/WEB-INF/classes CookieExample1.java
Log:
- Start using Cookies and the enhanced ServerCookie.
  
- CookieTools are no longer needed ( it's all commented out, will be
removed after I test the new code )
  
- Added a new example, that supports all V1 attributes ( even if no
browser except lynx can be use V1 ) - it is needed to verify the
parsing code works for V1.
  
- The code now uses RFC2109 ( easy to go forward to 2965 ). Discard is removed,
since it's in the new spec.
  
Revision  ChangesPath
1.1  
jakarta-tomcat/src/examples/WEB-INF/classes/CookieExample1.java
  
Index: CookieExample1.java
===
/* $Id: CookieExample1.java,v 1.1 2000/12/01 06:00:23 costin Exp $
 *
 */
  
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
  
/**
 * Example servlet showing request headers
 *
 * @author James Duncan Davidson [EMAIL PROTECTED]
 */
  
public class CookieExample1 extends HttpServlet {
  
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
  
public void doGet(HttpServletRequest request,
  HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
  
PrintWriter out = response.getWriter();
out.println("html");
out.println("body bgcolor=\"white\"");
out.println("head");
  
String title = rb.getString("cookies.title");
out.println("title" + title + "/title");
out.println("/head");
out.println("body");
  
  // relative links
  
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
  
out.println("a href=\"/examples/servlets/cookies.html\"");
out.println("img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"/a");
out.println("a href=\"/examples/servlets/index.html\"");
out.println("img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"/a");
  
out.println("h3" + title + "/h3");
  
Cookie[] cookies = request.getCookies();
if (cookies.length  0) {
out.println(rb.getString("cookies.cookies") + "br");
for (int i = 0; i  cookies.length; i++) {
Cookie cookie = cookies[i];
out.print("Cookie Name: " + cookie.getName() + "br");
out.print("Cookie Value: " + cookie.getValue() + "br");
out.println("Cookie Version: " + cookie.getVersion() + "br");
  out.println("Cookie Domain: " + cookie.getDomain() + "br");
  out.println("Cookie Path: " + cookie.getPath() + "br");
  out.println("br");
}
} else {
out.println(rb.getString("cookies.no-cookies"));
}
  
String cookieName = request.getParameter("cookiename");
String cookieValue = request.getParameter("cookievalue");
  String path= request.getParameter( "cookiepath" );
  String domain= request.getParameter( "cookiedomain" );
  String secure= request.getParameter( "cookiesecure" );
  String version= request.getParameter( "cookieversion" );
  String comment= request.getParameter( "cookiecomment" );
  String maxage= request.getParameter( "cookiemaxage" );
if (cookieName != null  !"".equals( cookieName) ) {
  // cookie 

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java

2000-11-30 Thread costin

costin  00/11/30 14:43:56

  Modified:.changes3.3
   src/facade22/org/apache/tomcat/facade CookieFacade.java
HttpServletRequestFacade.java
HttpServletResponseFacade.java
   src/share/org/apache/tomcat/core Request.java
   src/share/org/apache/tomcat/helper CookieTools.java
   src/share/org/apache/tomcat/modules/session SessionId.java
   src/share/org/apache/tomcat/util/http Cookies.java
ServerCookie.java
  Removed: src/share/org/apache/tomcat/util ServerCookie.java
  Log:
  Removed the old ServerCookie and 1/2 of CookieTools.
  
  Revision  ChangesPath
  1.2   +22 -3 jakarta-tomcat/changes3.3
  
  Index: changes3.3
  ===
  RCS file: /home/cvs/jakarta-tomcat/changes3.3,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- changes3.32000/11/30 08:19:10 1.1
  +++ changes3.32000/11/30 22:43:43 1.2
  @@ -134,8 +134,6 @@
   
   - better integration for form login with apache
   
  -- This is the living To-Do list for Tomcat 3.3
  -
   - Optimize error handling. For example, we can use int IDs for error 
   messages ( needs enhancements in StringManager ) 
   - Cache the error page handler ( instead of doing a second mapping 
  @@ -153,5 +151,26 @@
   - Merge HTTP1.1 code from catalina
   
   - Merge JMX code from catalina
  +
  +- Merge JNDI code from catalina
  +
  +- Experiment and implement "sendFile" for chunks of static JSP, cache the
  +static region as byte[] on the server ( integrated mode )
  +
  +- Fix mod_jk for Apache2.0 !!!
  +
  +- Add callbacks to mod_jk, integrate authentication ( user Apache's user db)
  +
  +- Experiment with mixed applications, integrate the session and auth 
  +representation of mod_perl and php
  +
  +- Implement the profiling web app ( that allows you to get a profile of a 
  +servlet container, how expensive is each API call )
  +
  +- Expose more internals via /admin ( number of threads, memory, etc)
  +
  +- Experiment with Apache2.0 config ( and IIS ? ), try to integrate
  +
  +- Make sure the  request parsed by Apache is not parsed again.
   
  -- Merge JNDI code from catalina
  \ No newline at end of file
  +- Interceptor == Module == SAF ( will this ever happen ?)
  
  
  
  1.4   +1 -0  
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/CookieFacade.java
  
  Index: CookieFacade.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/CookieFacade.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CookieFacade.java 2000/10/27 20:50:49 1.3
  +++ CookieFacade.java 2000/11/30 22:43:46 1.4
  @@ -61,6 +61,7 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.http.*;
   import org.apache.tomcat.helper.RequestUtil;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.facade.*;
  
  
  
  1.10  +1 -0  
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletRequestFacade.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HttpServletRequestFacade.java 2000/11/30 04:58:36 1.9
  +++ HttpServletRequestFacade.java 2000/11/30 22:43:46 1.10
  @@ -61,6 +61,7 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.http.*;
   import org.apache.tomcat.helper.RequestUtil;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.facade.*;
  
  
  
  1.12  +3 -13 
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java
  
  Index: HttpServletResponseFacade.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- HttpServletResponseFacade.java2000/11/30 07:59:03 1.11
  +++ HttpServletResponseFacade.java2000/11/30 22:43:46 1.12
  @@ -61,6 +61,7 @@
   package org.apache.tomcat.facade;
   
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.http.*;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.helper.*;
   import java.io.*;
  @@ -113,19 +114,8 @@
// frequent operation ( for example sc can be reused )
ServerCookie sc=new ServerCookie();
cookie2serverCookie( cookie, sc);
  - addHeader( 

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java

2000-11-30 Thread costin

costin  00/11/30 22:00:39

  Modified:src/facade22/org/apache/tomcat/facade
HttpServletRequestFacade.java
HttpServletResponseFacade.java
   src/share/org/apache/tomcat/core Request.java
   src/share/org/apache/tomcat/helper CookieTools.java
   src/share/org/apache/tomcat/modules/session SessionId.java
   src/share/org/apache/tomcat/util/http Cookies.java
ServerCookie.java
  Added:   src/examples/WEB-INF/classes CookieExample1.java
  Log:
  - Start using Cookies and the enhanced ServerCookie.
  
  - CookieTools are no longer needed ( it's all commented out, will be
  removed after I test the new code )
  
  - Added a new example, that supports all V1 attributes ( even if no
  browser except lynx can be use V1 ) - it is needed to verify the
  parsing code works for V1.
  
  - The code now uses RFC2109 ( easy to go forward to 2965 ). Discard is removed,
  since it's in the new spec.
  
  Revision  ChangesPath
  1.1  jakarta-tomcat/src/examples/WEB-INF/classes/CookieExample1.java
  
  Index: CookieExample1.java
  ===
  /* $Id: CookieExample1.java,v 1.1 2000/12/01 06:00:23 costin Exp $
   *
   */
  
  import java.io.*;
  import java.text.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  /**
   * Example servlet showing request headers
   *
   * @author James Duncan Davidson [EMAIL PROTECTED]
   */
  
  public class CookieExample1 extends HttpServlet {
  
  ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
  
  public void doGet(HttpServletRequest request,
HttpServletResponse response)
  throws IOException, ServletException
  {
  response.setContentType("text/html");
  
  PrintWriter out = response.getWriter();
  out.println("html");
  out.println("body bgcolor=\"white\"");
  out.println("head");
  
  String title = rb.getString("cookies.title");
  out.println("title" + title + "/title");
  out.println("/head");
  out.println("body");
  
// relative links
  
  // XXX
  // making these absolute till we work out the
  // addition of a PathInfo issue 

  out.println("a href=\"/examples/servlets/cookies.html\"");
  out.println("img src=\"/examples/images/code.gif\" height=24 " +
  "width=24 align=right border=0 alt=\"view code\"/a");
  out.println("a href=\"/examples/servlets/index.html\"");
  out.println("img src=\"/examples/images/return.gif\" height=24 " +
  "width=24 align=right border=0 alt=\"return\"/a");
  
  out.println("h3" + title + "/h3");
  
  Cookie[] cookies = request.getCookies();
  if (cookies.length  0) {
  out.println(rb.getString("cookies.cookies") + "br");
  for (int i = 0; i  cookies.length; i++) {
  Cookie cookie = cookies[i];
  out.print("Cookie Name: " + cookie.getName() + "br");
  out.print("Cookie Value: " + cookie.getValue() + "br");
  out.println("Cookie Version: " + cookie.getVersion() + "br");
out.println("Cookie Domain: " + cookie.getDomain() + "br");
out.println("Cookie Path: " + cookie.getPath() + "br");
out.println("br");
  }
  } else {
  out.println(rb.getString("cookies.no-cookies"));
  }
  
  String cookieName = request.getParameter("cookiename");
  String cookieValue = request.getParameter("cookievalue");
String path= request.getParameter( "cookiepath" );
String domain= request.getParameter( "cookiedomain" );
String secure= request.getParameter( "cookiesecure" );
String version= request.getParameter( "cookieversion" );
String comment= request.getParameter( "cookiecomment" );
String maxage= request.getParameter( "cookiemaxage" );
  if (cookieName != null  !"".equals( cookieName) ) {
// cookie without value is valid !
Cookie cookie = new Cookie(cookieName, cookieValue);
if( ! "".equals( path ))
cookie.setPath( path );
if( ! "".equals( domain ))
cookie.setDomain( domain );
if( ! "".equals( secure ))
cookie.setSecure( true );
if( "1".equals( version )) 
cookie.setVersion(1);
if( ! "".equals( comment ))
cookie.setComment( comment );
if( ! "".equals( maxage )) {
try {
Integer max=new Integer( maxage );
cookie.setMaxAge( max.intValue() );
} catch(Exception ex ) {
}