costin      01/11/26 08:53:57

  Modified:    jk/java/org/apache/ajp Ajp13.java
  Removed:     jk/java/org/apache/ajp Ajp14.java
  Log:
  Merge logic from Ajp14 in Ajp13, removing the duplicated code.
  
  The difference is that if Ajp13 is configured with a 'setBackward( false )' it'll
  require an auth phase and support all additional handlers ( negotiation, etc ). 
Otherwise it'll
  behave as it did before, as a 'basic' ajp13 worker ( important for 3.2.x where 14 is 
unlikely
  to get ported, and 4.0 where 14 is not yet completed ).
  
  Revision  Changes    Path
  1.20      +69 -5     jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java
  
  Index: Ajp13.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Ajp13.java        2001/11/21 20:49:54     1.19
  +++ Ajp13.java        2001/11/26 16:53:57     1.20
  @@ -74,6 +74,7 @@
   import org.apache.tomcat.util.buf.ByteChunk;
   import org.apache.tomcat.util.http.MimeHeaders;
   import org.apache.tomcat.util.http.HttpMessages;
  +import org.apache.tomcat.util.http.BaseRequest;
   
   /**
    * Represents a single, persistent connection between the web server and
  @@ -93,6 +94,8 @@
    * @author Dan Milstein [[EMAIL PROTECTED]]
    * @author Keith Wannamaker [[EMAIL PROTECTED]]
    * @author Kevin Seguin [[EMAIL PROTECTED]]
  + * @author Henri Gomez [[EMAIL PROTECTED]]
  + * @author Costin Manolache
    */
   public class Ajp13 {
   
  @@ -134,14 +137,26 @@
       boolean end_of_stream;  // true if we've received an empty packet
       
       // Required handler - essential request processing
  -    public RequestHandler reqHandler=new RequestHandler();
  +    public RequestHandler reqHandler;
  +    // AJP14 - detect protocol,set communication parameters, login
  +    // If no password is set, use only Ajp13 messaging
  +    boolean backwardCompat=true;
  +    boolean logged=false;
       
       public Ajp13() {
        super();
        initBuf();
  +        reqHandler=new RequestHandler();
        reqHandler.init( this );
       }
   
  +    public Ajp13(RequestHandler reqHandler ) {
  +     super();
  +     initBuf();
  +        this.reqHandler=reqHandler;
  +     reqHandler.init( this );
  +    }
  +
       /** Will be overriden
        */
       public void initBuf() {
  @@ -159,6 +174,7 @@
           blen = 0; 
           pos = 0;
           end_of_stream = false;
  +        logged=false;
       }
       
       /**
  @@ -175,6 +191,22 @@
        pos = 0;
       }
   
  +    /**
  +     * Backward compat mode, no login  needed
  +     */
  +    public void setBackward(boolean b) 
  +    {
  +        backwardCompat=b;
  +    }
  +
  +    public boolean isLogged() {
  +     return logged;
  +    }
  +
  +    void setLogged( boolean b ) {
  +        logged=b;
  +    }
  +
       // -------------------- Handlers registry --------------------
   
       static final int MAX_HANDLERS=32;
  @@ -217,7 +249,7 @@
        * if there were errors in the reading of the request, and -2 if the
        * server is asking the container to shut itself down.  
        */
  -    public int receiveNextRequest(AjpRequest req) throws IOException {
  +    public int receiveNextRequest(BaseRequest req) throws IOException {
           if (debug > 0) {
               logger.log("receiveNextRequest()");
           }
  @@ -248,18 +280,49 @@
   
       /** Override for ajp14, temporary
        */
  -    public int handleMessage( int type, Ajp13Packet hBuf, AjpRequest req )
  +    public int handleMessage( int type, Ajp13Packet hBuf, BaseRequest req )
           throws IOException
       {
  +        if( type > handlers.length ) {
  +         logger.log( "Invalid handler " + type );
  +         return 500;
  +     }
  +
  +        if( debug > 0 )
  +            logger.log( "Received " + type + " " + handlerName[type]);
  +        
  +        // Ajp14, unlogged
  +     if( ! backwardCompat && ! isLogged() ) {
  +         if( type != NegociationHandler.JK_AJP14_LOGINIT_CMD &&
  +             type != NegociationHandler.JK_AJP14_LOGCOMP_CMD ) {
  +
  +                logger.log( "Ajp14 error: not logged " +
  +                            type + " " + handlerName[type]);
  +
  +             return 300;
  +         }
  +         // else continue
  +     }
  +
  +        // Ajp13 messages
        switch(type) {
  -         
        case RequestHandler.JK_AJP13_FORWARD_REQUEST:
            return reqHandler.decodeRequest(this, hBuf, req);
            
        case JK_AJP13_SHUTDOWN:
            return -2;
        }
  -     return 200; // XXX This is actually an error condition 
  +
  +     // logged || loging message
  +     AjpHandler handler=handlers[type];
  +     if( handler==null ) {
  +         logger.log( "Unknown message " + type + handlerName[type] );
  +         return 200;
  +     }
  +
  +        if( debug > 0 )
  +            logger.log( "Ajp14 handler " + handler );
  +     return handler.handleAjpMessage( type, this, hBuf, req );
       }
   
       // ==================== Servlet Input Support =================
  @@ -469,6 +532,7 @@
        if(null !=in) {
            in.close();
        }
  +        setLogged( false );  // no more logged now 
       }
   
       // -------------------- Debug --------------------
  
  
  

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

Reply via email to