tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/common jk_handler_response.c jk_handler_logon.c jk_handler_discovery.c
Date Wed, 12 Dec 2001 21:34:47 GMT
costin      01/12/12 13:34:47

  Modified:    jk/native2/common jk_handler_response.c jk_handler_logon.c
                        jk_handler_discovery.c
  Log:
  Rewrote the existing handlers to use the new interface.
  
  Note that each file will have a factory method that will create a map containing
  all the handlers it supports ( not perfect, it can be done clener, but this is the
  first round )
  
  As before, the handler will process the message and optionally generate a reply
  ( like the original JK_GET_CHUNK message )
  
  Using messages have the benefit that we don't need round-trips.
  The disadvantage is that RPC is more familiar to people, but if we can do soap we
  can probably handle this as well. It is possible to emulate one over the other.
  
  Revision  Changes    Path
  1.5       +192 -149  jakarta-tomcat-connectors/jk/native2/common/jk_handler_response.c
  
  Index: jk_handler_response.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_handler_response.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jk_handler_response.c	2001/12/06 22:54:44	1.4
  +++ jk_handler_response.c	2001/12/12 21:34:47	1.5
  @@ -57,112 +57,36 @@
   
   #include "jk_global.h"
   #include "jk_service.h"
  -#include "jk_msg_buff.h"
  +#include "jk_msg.h"
   #include "jk_env.h"
   #include "jk_requtil.h"
   #include "jk_env.h"
   #include "jk_handler.h"
   #include "jk_endpoint.h"
   
  -static int ajp_unmarshal_response(jk_msg_buf_t   *msg,
  -                                  jk_ws_service_t  *s,
  -                                  jk_endpoint_t *ae,
  -                                  jk_logger_t    *l);
  -
  -int ajp_handle_sendChunk(jk_msg_buf_t   *msg,
  -                         jk_ws_service_t  *r,
  -                         jk_endpoint_t *ae,
  -                         jk_logger_t    *l);
  -
  -
  -int ajp_handle_startResponse(jk_msg_buf_t   *msg,
  -                             jk_ws_service_t  *r,
  -                             jk_endpoint_t *ae,
  -                             jk_logger_t    *l);
  -
  -int ajp_handle_getChunk(jk_msg_buf_t   *msg,
  -                         jk_ws_service_t  *r,
  -                         jk_endpoint_t *ae,
  -                         jk_logger_t    *l);
  -
  -/** SEND_HEADERS handler
  +/*
  + * Write a body chunk from the servlet container to the web server
    */
  -int ajp_handle_startResponse(jk_msg_buf_t   *msg,
  -                             jk_ws_service_t  *r,
  -                             jk_endpoint_t *ae,
  -                             jk_logger_t    *l)
  -{
  -    int err;
  -    
  -    err=ajp_unmarshal_response(msg, r, ae, l);
  -    if( err!=JK_TRUE ) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp_process_callback - ajp_unmarshal_response
failed\n");
  -        return JK_AJP13_ERROR;
  -    }
  -    err=r->start_response(r, r->status, r->msg, 
  -                          (const char * const *)r->out_header_names,
  -                          (const char * const *)r->out_header_values,
  -                          r->out_headers);
  -    if( err!=JK_TRUE ) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp_process_callback - start_response failed\n");
  -        return JK_CLIENT_ERROR;
  -    }
  -    return JK_TRUE;
  -}
  +#define JK_AJP13_SEND_BODY_CHUNK    (unsigned char)3
   
  -/** SEND_BODY_CHUNK handler
  +/*
  + * Send response headers from the servlet container to the web server.
    */
  -int ajp_handle_sendChunk(jk_msg_buf_t   *msg,
  -                         jk_ws_service_t  *r,
  -                         jk_endpoint_t *ae,
  -                         jk_logger_t    *l)
  -{
  -    int err;
  -    unsigned len = (unsigned)jk_b_get_int(msg);
  +#define JK_AJP13_SEND_HEADERS       (unsigned char)4
   
  -    err=r->write(r, jk_b_get_buff(msg) + jk_b_get_pos(msg), len);
  -    if( err!= JK_TRUE ) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp_process_callback - write failed\n");
  -        return JK_CLIENT_ERROR;
  -    }
  -
  -    return JK_TRUE;
  -}
  -
  -/** SEND_BODY_CHUNK handler
  +/*
  + * Marks the end of response.
    */
  -int ajp_handle_getChunk(jk_msg_buf_t   *msg,
  -                        jk_ws_service_t  *r,
  -                        jk_endpoint_t *ae,
  -                        jk_logger_t    *l)
  -{
  -    int len = jk_b_get_int(msg);
  -    
  -    if(len > AJP13_MAX_SEND_BODY_SZ) {
  -        len = AJP13_MAX_SEND_BODY_SZ;
  -    }
  -    if(len > ae->left_bytes_to_send) {
  -        len = ae->left_bytes_to_send;
  -    }
  -    if(len < 0) {
  -        len = 0;
  -    }
  -            
  -    /* the right place to add file storage for upload */
  -    if ((len = ajp_read_into_msg_buff(ae, r, msg, len, l)) >= 0) {
  -        r->content_read += len;
  -        return JK_AJP13_HAS_RESPONSE;
  -    }                  
  -            
  -    l->jkLog(l, JK_LOG_ERROR, "Error ajp_process_callback - ajp_read_into_msg_buff failed\n");
  -    return JK_INTERNAL_ERROR;	    
  -}
  +#define JK_AJP13_GET_BODY_CHUNK     (unsigned char)6
   
  -
  +/*
  + * Marks the end of response.
  + */
  +#define JK_AJP13_END_RESPONSE       (unsigned char)5
   
   
  -/*
  -AJPV13_RESPONSE/AJPV14_RESPONSE:=
  +/** SEND_HEADERS handler
  +   AJPV13_RESPONSE/AJPV14_RESPONSE:=
       response_prefix (2)
       status          (short)
       status_msg      (short)
  @@ -185,78 +109,197 @@
       body    length*(var binary)
   
    */
  -static int ajp_unmarshal_response(jk_msg_buf_t   *msg,
  -                                  jk_ws_service_t  *s,
  -                                  jk_endpoint_t *ae,
  -                                  jk_logger_t    *l)
  +static int jk_handler_startResponse(jk_msg_t   *msg,
  +                                   jk_ws_service_t  *s,
  +                                   jk_endpoint_t *ae,
  +                                   jk_logger_t    *l)
   {
  -    jk_pool_t * p = ae->pool;
  -
  -    s->status = jk_b_get_int(msg);
  -
  -    if (!s->status) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp_unmarshal_response - Null status\n");
  -        return JK_FALSE;
  -    }
  +    int err;
  +    unsigned i;
  +    jk_pool_t * p = s->pool;
   
  -    s->msg = (char *)jk_b_get_string(msg);
  +    s->status = msg->getInt(msg);
  +    s->msg = (char *)msg->getString(msg);
       if (s->msg) {
           jk_xlate_from_ascii(s->msg, strlen(s->msg));
       }
  -
  -    l->jkLog(l, JK_LOG_DEBUG, "ajp_unmarshal_response: status = %d\n", s->status);
  +    s->out_headers = msg->getInt(msg);
  +    s->out_header_names = NULL;
  +    s->out_header_values = NULL;
   
  -    s->out_headers = jk_b_get_int(msg);
  -    s->out_header_names = s->out_header_values = NULL;
  -
  -    l->jkLog(l, JK_LOG_DEBUG, "ajp_unmarshal_response: Number of headers is = %d\n",
s->out_headers);
  -
  -    if (s->out_headers) {
  +    if (s->out_headers > 0 ) {
           s->out_header_names = p->alloc(p, sizeof(char *) * s->out_headers);
           s->out_header_values = p->alloc(p, sizeof(char *) * s->out_headers);
  +        
  +        if (s->out_header_names==NULL ||
  +            s->out_header_values==NULL) {
  +            l->jkLog(l, JK_LOG_ERROR,
  +                     "handler.startResponse() OutOfMemoryError %d headers\n",
  +                     s->out_headers);
  +            return JK_HANDLER_FATAL;
  +        }
  +        for(i = 0 ; i < s->out_headers ; i++) {
  +            unsigned short name = msg->peekInt(msg) ;
   
  -        if (s->out_header_names && s->out_header_values) {
  -            unsigned i;
  -            for(i = 0 ; i < s->out_headers ; i++) {
  -                unsigned short name = jk_b_pget_int(msg, jk_b_get_pos(msg)) ;
  -                
  -                if ((name & 0XFF00) == 0XA000) {
  -                    jk_b_get_int(msg);
  -                    name = name & 0X00FF;
  -                    if (name <= SC_RES_HEADERS_NUM) {
  -                        s->out_header_names[i] = (char *)jk_requtil_getHeaderById(name);
  -                    } else {
  -                        l->jkLog(l, JK_LOG_ERROR, "Error ajp_unmarshal_response - No
such sc (%d)\n", name);
  -                        return JK_FALSE;
  -                    }
  +            if ((name & 0XFF00) == 0XA000) {
  +                msg->getInt(msg);
  +                name = name & 0X00FF;
  +                if (name <= SC_RES_HEADERS_NUM) {
  +                    s->out_header_names[i] =
  +                        (char *)jk_requtil_getHeaderById(name);
                   } else {
  -                    s->out_header_names[i] = (char *)jk_b_get_string(msg);
  -                    if (!s->out_header_names[i]) {
  -                        l->jkLog(l, JK_LOG_ERROR, "Error ajp_unmarshal_response - Null
header name\n");
  -                        return JK_FALSE;
  -                    }
  -                    jk_xlate_from_ascii(s->out_header_names[i],
  -                                 strlen(s->out_header_names[i]));
  -
  +                    l->jkLog(l, JK_LOG_ERROR,
  +                             "handler.response() Invalid header id (%d)\n",
  +                             name);
  +                    return JK_HANDLER_FATAL;
                   }
  -
  -                s->out_header_values[i] = (char *)jk_b_get_string(msg);
  -                if (!s->out_header_values[i]) {
  -                    l->jkLog(l, JK_LOG_ERROR, "Error ajp_unmarshal_response - Null header
value\n");
  -                    return JK_FALSE;
  +            } else {
  +                s->out_header_names[i] = (char *)msg->getString(msg);
  +                if (!s->out_header_names[i]) {
  +                    l->jkLog(l, JK_LOG_ERROR,
  +                             "handler.response() Null header name \n");
  +                    return JK_HANDLER_FATAL;
                   }
  -
  -                jk_xlate_from_ascii(s->out_header_values[i],
  -                             strlen(s->out_header_values[i]));
  -
  -                l->jkLog(l, JK_LOG_DEBUG, "ajp_unmarshal_response: Header[%d] [%s] =
[%s]\n", 
  -                       i,
  -                       s->out_header_names[i],
  -                       s->out_header_values[i]);
  +                jk_xlate_from_ascii(s->out_header_names[i],
  +                                    strlen(s->out_header_names[i]));
               }
  +            s->out_header_values[i] = (char *)msg->getString(msg);
  +            if (!s->out_header_values[i]) {
  +                l->jkLog(l, JK_LOG_ERROR,
  +                         "Error ajp_unmarshal_response - Null header value\n");
  +                return JK_HANDLER_FATAL;
  +            }
  +
  +            jk_xlate_from_ascii(s->out_header_values[i],
  +                                strlen(s->out_header_values[i]));
  +            
  +            l->jkLog(l, JK_LOG_DEBUG,
  +                     "ajp_unmarshal_response: Header[%d] [%s] = [%s]\n", 
  +                     i,
  +                     s->out_header_names[i],
  +                     s->out_header_values[i]);
           }
       }
  +    
  +    l->jkLog(l, JK_LOG_INFO,
  +             "handler.response(): status=%d headers=%d\n",
  +             s->status, s->out_headers);
  +
  +    err=s->start_response(s, s->status, s->msg, 
  +                          (const char * const *)s->out_header_names,
  +                          (const char * const *)s->out_header_values,
  +                          s->out_headers);
  +    if( err!=JK_TRUE ) {
  +        l->jkLog(l, JK_LOG_ERROR,
  +                 "handler.response() Error sending response");
  +        return JK_HANDLER_ERROR;
  +    }
  +    
  +    return JK_HANDLER_OK;
  +}
   
  -    return JK_TRUE;
  +/** SEND_BODY_CHUNK handler
  + */
  +static int jk_handler_sendChunk(jk_msg_t   *msg,
  +                               jk_ws_service_t  *r,
  +                               jk_endpoint_t *ae,
  +                               jk_logger_t    *l)
  +{
  +    int err;
  +    int len;
  +    char *buf;
  +
  +    buf=msg->getBytes( msg, &len );
  +
  +    err=r->write(r, buf, len);
  +    if( err!= JK_TRUE ) {
  +        l->jkLog(l, JK_LOG_ERROR, "Error ajp_process_callback - write failed\n");
  +        return JK_HANDLER_ERROR;
  +    }
  +
  +    return JK_HANDLER_OK;
   }
   
  +static int jk_handler_endResponse(jk_msg_t   *msg,
  +                                 jk_ws_service_t  *r,
  +                                 jk_endpoint_t *ae,
  +                                 jk_logger_t    *l)
  +{
  +    ae->reuse = (int)msg->getByte(msg);
  +            
  +    if((ae->reuse & 0X01) != ae->reuse) {
  +        /*
  +         * Strange protocol error.
  +         */
  +        ae->reuse = JK_FALSE;
  +    }
  +    return JK_HANDLER_LAST;
  +}
  +
  +/** SEND_BODY_CHUNK handler
  + */
  +static int jk_handler_getChunk(jk_msg_t   *msg,
  +                              jk_ws_service_t  *r,
  +                              jk_endpoint_t *ae,
  +                              jk_logger_t    *l)
  +{
  +    int len = msg->getInt(msg);
  +    
  +    if(len > AJP13_MAX_SEND_BODY_SZ) {
  +        len = AJP13_MAX_SEND_BODY_SZ;
  +    }
  +    if(len > r->left_bytes_to_send) {
  +        len = r->left_bytes_to_send;
  +    }
  +    if(len < 0) {
  +        len = 0;
  +    }
  +
  +    len=msg->appendFromServer( msg, r, ae, len );
  +    /* the right place to add file storage for upload */
  +    if (len >= 0) {
  +        r->content_read += len;
  +        return JK_HANDLER_RESPONSE;
  +    }                  
  +            
  +    l->jkLog(l, JK_LOG_ERROR,
  +             "handler_request.getChunk() - ajp_read_into_msg_buff failed\n");
  +    return JK_HANDLER_FATAL;	    
  +}
  +
  +int JK_METHOD jk_handler_response_factory( jk_env_t *env, jk_pool_t *pool,
  +                                           void **result,
  +                                           const char *type, const char *name)
  +{
  +    jk_map_t *map;
  +    jk_handler_t *h;
  +    
  +    map_alloc( &map, pool );
  +    *result=map;
  +    
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="sendHeaders";
  +    h->messageId=JK_AJP13_SEND_HEADERS;
  +    h->callback=jk_handler_startResponse;
  +    map_put( map, h->name, h, NULL );
  +
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="sendChunk";
  +    h->messageId=JK_AJP13_SEND_BODY_CHUNK;
  +    h->callback=jk_handler_sendChunk;
  +    map_put( map, h->name, h, NULL );
  +    
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="endResponse";
  +    h->messageId=JK_AJP13_END_RESPONSE;
  +    h->callback=jk_handler_endResponse;
  +    map_put( map, h->name, h, NULL );
  +
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="getChunk";
  +    h->messageId=JK_AJP13_GET_BODY_CHUNK;
  +    h->callback=jk_handler_getChunk;
  +    map_put( map, h->name, h, NULL );
  +
  +    return JK_TRUE;
  +}
  
  
  
  1.6       +135 -288  jakarta-tomcat-connectors/jk/native2/common/jk_handler_logon.c
  
  Index: jk_handler_logon.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_handler_logon.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- jk_handler_logon.c	2001/12/06 22:54:44	1.5
  +++ jk_handler_logon.c	2001/12/12 21:34:47	1.6
  @@ -58,12 +58,12 @@
   /**
    * Description: AJP14 Login handler
    * Author:      Henri Gomez <hgomez@slib.fr>
  - * Version:     $Revision: 1.5 $                                          
  + * Version:     $Revision: 1.6 $                                          
    */
   
   #include "jk_global.h"
   #include "jk_pool.h"
  -#include "jk_msg_buff.h"
  +#include "jk_msg.h"
   #include "jk_md5.h"
   #include "jk_logger.h"
   #include "jk_service.h"
  @@ -73,11 +73,6 @@
   /* Private definitions */
   
   /*
  - * Initial Login Phase (web server -> servlet engine)
  - */
  -#define AJP14_LOGINIT_CMD	(unsigned char)0x10
  -
  -/*
    * Second Login Phase (servlet engine -> web server), md5 seed is received
    */
   #define AJP14_LOGSEED_CMD	(unsigned char)0x11
  @@ -96,317 +91,141 @@
    * Login Rejected (servlet engine -> web server), will be logged
    */
   #define AJP14_LOGNOK_CMD	(unsigned char)0x14
  -
  -int JK_METHOD jk_handler_logon_factory( jk_env_t *env, void **result,
  -                                        char *type, char *name);
  -
  -
  -/* Private functions */
  -
  -static void ajp14_compute_md5(jk_login_service_t *s, 
  -                              jk_logger_t *l);
   
  -static int ajp14_marshal_login_init_into_msgb(jk_msg_buf_t *msg, 
  -                                              jk_login_service_t *s, 
  -                                              jk_logger_t *l);
  +/* web-server want context info after login */
  +#define AJP14_CONTEXT_INFO_NEG      0x80000000 
   
  -static int ajp14_unmarshal_login_seed(jk_msg_buf_t *msg, 
  -                                      jk_login_service_t *s, 
  -                                      jk_logger_t *l);
  +/* web-server want context updates */
  +#define AJP14_CONTEXT_UPDATE_NEG    0x40000000 
   
  -static  int ajp14_marshal_login_comp_into_msgb(jk_msg_buf_t *msg, 
  -                                               jk_login_service_t *s, 
  -                                               jk_logger_t *l);
  +/* communication could use AJP14 */
  +#define AJP14_PROTO_SUPPORT_AJP14_NEG   0x00010000 
   
  -static int ajp14_unmarshal_log_ok(jk_msg_buf_t *msg, 
  -                                  jk_login_service_t *s, 
  -                                  jk_logger_t *l);
  -
  -static int ajp14_unmarshal_log_nok(jk_msg_buf_t *msg, 
  -                                   jk_logger_t *l);
  -
  -
  -static int jk_handler_logon_logon(jk_endpoint_t *ae, jk_logger_t    *l);
  -static int jk_handler_logon_init( jk_worker_t *w );
  -
  -/* ==================== Impl =================== */
  -
  -int JK_METHOD jk_handler_logon_factory( jk_env_t *env, void **result,
  -                                       char *type, char *name)
  -{
  -    jk_handler_t *h=(jk_handler_t *)malloc( sizeof( jk_handler_t));
  -
  -    h->init=jk_handler_logon_init;
  -    *result=h;
  -    return JK_TRUE;
  -}
  -
  -
  -static int jk_handler_logon_init( jk_worker_t *w ) {
  -    w->logon= jk_handler_logon_logon; 
  -    return JK_TRUE;
  -}
  +int JK_METHOD jk_handler_logon_factory( jk_env_t *env,
  +                                        jk_pool_t *pool,
  +                                        void **result,
  +                                        char *type, char *name);
   
  +#define AJP14_ENTROPY_SEED_LEN		32  /* we're using MD5 => 32 chars */
  +#define AJP14_COMPUTED_KEY_LEN		32  /* we're using MD5 also */
   
  -/* 
  - * AJP14 Logon Phase 
  +/*
  + * Decode the Login Command
    *
  - * INIT + REPLY / NEGO + REPLY 
  - */
  -static int handle_logon(jk_endpoint_t *ae,
  -                        jk_msg_buf_t	   *msg,
  -                        jk_logger_t     *l)
  -{
  -    int	cmd;
  -    
  -    jk_login_service_t *jl = ae->worker->login;
  -    
  -    ajp14_marshal_login_init_into_msgb(msg, jl, l);
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:logon - send init\n");
  -    
  -    if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE)	
  -        return JK_FALSE;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:logon - wait init reply\n");
  -    
  -    jk_b_reset(msg);
  -    
  -    if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE)
  -        return JK_FALSE;
  -    
  -    if ((cmd = jk_b_get_byte(msg)) != AJP14_LOGSEED_CMD) {
  + * +-------------------------+---------------------------+
  + * | LOGIN SEED CMD (1 byte) | MD5 of entropy (String) |
  + * +-------------------------+---------------------------+
  + *
  + * Build the reply: 
  + *   byte    LOGCOMP
  + *   String  MD5 of random + Secret key
  + *   long    negotiation
  + *   String  serverName
  + *
  + */
  +static int jk_handler_login(jk_msg_t       *msg,
  +                            jk_ws_service_t *s,
  +                            jk_endpoint_t *ae,
  +                            jk_logger_t *l)
  +{
  +    int rc;
  +    char *entropy;
  +    char computedKey[AJP14_COMPUTED_KEY_LEN];
  +    char *secret=ae->worker->secret;
  +
  +    entropy= msg->getString( msg );
  +    if( entropy==NULL ) {
           l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14:logon: awaited command %d, received %d\n",
  -               AJP14_LOGSEED_CMD, cmd);
  -        return JK_FALSE;
  +                 "Error ajp14_unmarshal_login_seed - can't get seed\n");
  +        return JK_HANDLER_FATAL;
       }
  -    
  -    if (ajp14_unmarshal_login_seed(msg, jl, l) != JK_TRUE)
  -        return JK_FALSE;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG,
  -           "Into ajp14:logon - received entropy %s\n", jl->entropy);
  -    
  -    ajp14_compute_md5(jl, l);
  -    
  -    if (ajp14_marshal_login_comp_into_msgb(msg, jl, l) != JK_TRUE)
  -        return JK_FALSE;
  -    
  -    if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE) 
  -        return JK_FALSE;
  -    
  -    jk_b_reset(msg);
  -    
  -    if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE)
  -        return JK_FALSE;
  -    
  -    switch (jk_b_get_byte(msg)) {
  -        
  -    case AJP14_LOGOK_CMD  :	
  -        if (ajp14_unmarshal_log_ok(msg, jl, l) == JK_TRUE) {
  -            l->jkLog(l, JK_LOG_DEBUG,
  -                   "Successfully connected to servlet-engine %s\n",
  -                   jl->servlet_engine_name);
  -            return JK_TRUE;
  -        }
  -        break;
  -        
  -    case AJP14_LOGNOK_CMD :
  -        ajp14_unmarshal_log_nok(msg, l);
  -        break;
  -    }
  -    
  -    return JK_FALSE;
  -}
  -
  -
  -static int jk_handler_logon_logon(jk_endpoint_t *ae,
  -                           jk_logger_t    *l)
  -{
  -    jk_pool_t     *p = ae->pool;
  -    jk_msg_buf_t  *msg;
  -    int 	  rc;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:logon\n");
   
  -    msg = jk_b_new(p);
  -    jk_b_set_buffer_size(msg, DEF_BUFFER_SZ);
  -    
  -    if ((rc = handle_logon(ae, msg, l)) == JK_FALSE) 
  -        ajp_close_endpoint(ae, l);
  +    l->jkLog(l, JK_LOG_INFO,
  +           "handle.logseed() received entropy %s\n", entropy);
       
  -    return rc;
  -}
  +    jk_md5((const unsigned char *)entropy,
  +           (const unsigned char *)secret, computedKey);
   
  +    l->jkLog(l, JK_LOG_DEBUG,
  +             "Into ajp14_compute_md5 (%s/%s) -> (%s)\n",
  +             entropy, secret, computedKey);
   
  -/* -------------------- private utils/marshaling -------------------- */
  +    msg->reset( msg );
   
  -/*
  - * Compute the MD5 with ENTROPY / SECRET KEY
  - */
  -static void ajp14_compute_md5(jk_login_service_t *s, 
  -                              jk_logger_t        *l)
  -{
  -    jk_md5((const unsigned char *)s->entropy,
  -           (const unsigned char *)s->secret_key, s->computed_key);
  +    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_login_comp_into_msgb\n");
   
  -    l->jkLog(l, JK_LOG_DEBUG,
  -           "Into ajp14_compute_md5 (%s/%s) -> (%s)\n",
  -           s->entropy, s->secret_key, s->computed_key);
  -}
  +    rc=msg->appendByte( msg, AJP14_LOGCOMP_CMD);
  +    if (rc!=JK_TRUE )
  +        return JK_HANDLER_FATAL;
   
  -/*
  - * Build the Login Init Command
  - *
  - * +-------------------------+---------------------------+-------------------
  - * | LOGIN INIT CMD (1 byte) | NEGOCIATION DATA (32bits) | WEB SERVER INFO
  - * |                         |                           |    (CString) 
  - * +-------------------------+---------------------------+-------------------
  - *
  - */
  -static int ajp14_marshal_login_init_into_msgb(jk_msg_buf_t       *msg,
  -                                              jk_login_service_t *s,
  -                                              jk_logger_t        *l)
  -{
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_login_init_into_msgb\n");
  -    
  -    /* To be on the safe side */
  -    jk_b_reset(msg);
  -    
  -    /*
  -     * LOGIN
  -     */
  -    if (jk_b_append_byte(msg, AJP14_LOGINIT_CMD)) 
  -        return JK_FALSE;
  -    
  -    /*
  -     * NEGOCIATION FLAGS
  -     */
  -    if (jk_b_append_long(msg, s->negociation))
  -        return JK_FALSE;
  -    
  -    /*
  -     * WEB-SERVER NAME
  -     */
  -    if (jk_b_append_string(msg, s->web_server_name)) {
  +    /* COMPUTED-SEED */
  +    rc= msg->appendString( msg, (const unsigned char *)computedKey);
  +    if( rc!=JK_TRUE ) {
           l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_marshal_login_init_into_msgb "
  -               "- Error appending the web_server_name string\n");
  -        return JK_FALSE;
  +                 "handler.loginSecret() error serializing computed secret\n");
  +        return JK_HANDLER_FATAL;
       }
  +    ae->negociation=
  +        (AJP14_CONTEXT_INFO_NEG | AJP14_PROTO_SUPPORT_AJP14_NEG);
  +    msg->appendLong(msg, ae->negociation);
       
  -    return JK_TRUE;
  -}
  +    rc=msg->appendString(msg, ae->worker->workerEnv->server_name);
   
  -
  -/*
  - * Decode the Login Seed Command
  - *
  - * +-------------------------+---------------------------+
  - * | LOGIN SEED CMD (1 byte) | MD5 of entropy (32 chars) |
  - * +-------------------------+---------------------------+
  - *
  - */
  -static int ajp14_unmarshal_login_seed(jk_msg_buf_t       *msg,
  -                                      jk_login_service_t *s,
  -                                      jk_logger_t        *l)
  -{
  -    if (jk_b_get_bytes(msg, (unsigned char *)s->entropy,
  -                       AJP14_ENTROPY_SEED_LEN) < 0) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_login_seed - can't get seed\n");
  -        return JK_FALSE;
  -    }
  -
  -    s->entropy[AJP14_ENTROPY_SEED_LEN] = 0;	/* Just to have a CString */
  -    return JK_TRUE;
  -}
  -
  -/*
  - * Build the Login Computed Command
  - *
  - * +-------------------------+---------------------------------------+
  - * | LOGIN COMP CMD (1 byte) | MD5 of RANDOM + SECRET KEY (32 chars) |
  - * +-------------------------+---------------------------------------+
  - *
  - */
  -static int ajp14_marshal_login_comp_into_msgb(jk_msg_buf_t       *msg,
  -                                              jk_login_service_t *s,
  -                                              jk_logger_t        *l)
  -{
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_login_comp_into_msgb\n");
  +    if ( rc != JK_TRUE)
  +        return JK_HANDLER_FATAL;
       
  -    /* To be on the safe side */
  -    jk_b_reset(msg);
  -
  -    /*
  -     * LOGIN
  -     */
  -    if (jk_b_append_byte(msg, AJP14_LOGCOMP_CMD)) 
  -        return JK_FALSE;
  -
  -    /*
  -     * COMPUTED-SEED
  -     */
  -     if (jk_b_append_bytes(msg, (const unsigned char *)s->computed_key,
  -                           AJP14_COMPUTED_KEY_LEN)) {
  -         l->jkLog(l, JK_LOG_ERROR,
  -                "Error ajp14_marshal_login_comp_into_msgb "
  -                " - Error appending the COMPUTED MD5 bytes\n");
  -        return JK_FALSE;
  -    }
  -
  -    return JK_TRUE;
  +    return JK_HANDLER_RESPONSE;
   }
   
   
   /*
  - * Decode the LogOk Command
  + * Decode the LogOk Command. After that we're done, the connection is
  + * perfect and ready.
    *
    * +--------------------+------------------------+---------------------------
    * | LOGOK CMD (1 byte) | NEGOCIED DATA (32bits) | SERVLET ENGINE INFO(CString)
    * +--------------------+------------------------+---------------------------
    *
    */
  -static int ajp14_unmarshal_log_ok(jk_msg_buf_t       *msg,
  -                                  jk_login_service_t *s,
  -                                  jk_logger_t        *l)
  -{
  -    unsigned long 	nego;
  -    char *			sname;
  -    
  -    nego = jk_b_get_long(msg);
  +static int jk_handler_logok(jk_msg_t       *msg,
  +                            jk_ws_service_t *s,
  +                            jk_endpoint_t *ae,
  +                            jk_logger_t *l)
  +{
  +    unsigned long nego;
  +    char *sname;
  +    int rc;
  +
  +    nego = msg->getLong(msg);
       
       if (nego == 0xFFFFFFFF) {
           l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_log_ok - can't get negociated data\n");
  -        return JK_FALSE;
  +                 "Error ajp14_unmarshal_log_ok - can't get negociated data\n");
  +        return JK_HANDLER_FATAL;
       }
       
  -    sname = (char *)jk_b_get_string(msg);
  +    sname = (char *)msg->getString(msg);
       
       if (! sname) {
           l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_log_ok - "
  -               "can't get servlet engine name\n");
  -        return JK_FALSE;
  +                 "Error ajp14_unmarshal_log_ok - "
  +                 "can't get servlet engine name\n");
  +        return JK_HANDLER_FATAL;
       }
  -
  -    /* take care of removing previously allocated data */
  -    if (s->servlet_engine_name)			
  -        free(s->servlet_engine_name);
       
  -    s->servlet_engine_name = strdup(sname);
  -    
  -    if (! s->servlet_engine_name) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_log_ok - "
  -               " can't malloc servlet engine name\n");
  -        return JK_FALSE;
  +    /* take care of removing previously allocated data */
  +    /* XXXXXXXXX NEED A SUB POOL !!!! */
  +    if (ae->servletContainerName == NULL || 
  +        strcmp( sname, ae->servletContainerName) != 0 )  {
  +        ae->servletContainerName=(char *)ae->pool->pstrdup( ae->pool,
  +                                                            sname );
       }
       
  -    return JK_TRUE;
  +    l->jkLog(l, JK_LOG_DEBUG,
  +             "Successfully connected to servlet-engine %s\n",
  +             ae->servletContainerName);
  +
  +    return JK_HANDLER_LAST;
   }
   
   
  @@ -418,24 +237,52 @@
    * +---------------------+-----------------------+
    *
    */
  -
  -static int ajp14_unmarshal_log_nok(jk_msg_buf_t *msg,
  -                                   jk_logger_t  *l)
  +static int jk_handler_lognok(jk_msg_t       *msg,
  +                             jk_ws_service_t *s,
  +                             jk_endpoint_t *ae,
  +                             jk_logger_t *l)
   {
       unsigned long   status;
       
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_unmarshal_log_nok\n");
  +    status = msg->getLong(msg);
       
  -    status = jk_b_get_long(msg);
  +    l->jkLog(l, JK_LOG_INFO,
  +             "handler.logonFailure() code %08lx", status);
       
  -    if (status == 0xFFFFFFFF) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_log_nok - can't get failure code\n");
  -        return JK_FALSE;
  -    }
  +    return JK_HANDLER_FATAL;
  +}
  +
  +
  +
  +/** Register handlers
  + */
  +int JK_METHOD jk_handler_logon_factory( jk_env_t *env, jk_pool_t *pool,
  +                                        void **result,
  +                                        char *type, char *name)
  +{
  +    jk_map_t *map;
  +    jk_handler_t *h;
  +        
  +    map_alloc( &map, pool );
  +    *result=map;
       
  -    l->jkLog(l, JK_LOG_INFO,
  -           "Can't Log with servlet engine - code %08lx", status);
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="login";
  +    h->messageId=AJP14_LOGSEED_CMD;
  +    h->callback=jk_handler_login;
  +    map_put( map, h->name, h, NULL );
  +
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="logOk";
  +    h->messageId=AJP14_LOGOK_CMD;
  +    h->callback=jk_handler_logok;
  +    map_put( map, h->name, h, NULL );
  +
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="logNok";
  +    h->messageId=AJP14_LOGNOK_CMD;
  +    h->callback=jk_handler_lognok;
  +    map_put( map, h->name, h, NULL );
  +
       return JK_TRUE;
   }
  -
  
  
  
  1.7       +49 -168   jakarta-tomcat-connectors/jk/native2/common/jk_handler_discovery.c
  
  Index: jk_handler_discovery.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_handler_discovery.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- jk_handler_discovery.c	2001/12/06 22:57:13	1.6
  +++ jk_handler_discovery.c	2001/12/12 21:34:47	1.7
  @@ -58,41 +58,23 @@
   /**
    * Description: AJP14 Discovery handler
    * Author:      Henri Gomez <hgomez@slib.fr>
  - * Version:     $Revision: 1.6 $                                          
  + * Version:     $Revision: 1.7 $                                          
    */
   
   #include "jk_global.h"
   #include "jk_pool.h"
   #include "jk_env.h"
  -#include "jk_msg_buff.h"
  +#include "jk_msg.h"
   #include "jk_logger.h"
   #include "jk_service.h"
   #include "jk_handler.h"
   #include "jk_webapp.h"
   #include "jk_workerEnv.h"
   
  -int JK_METHOD jk_handler_discovery_factory( jk_env_t *env, jk_pool_t *pool, void **result,
  +int JK_METHOD jk_handler_discovery_factory( jk_env_t *env, jk_pool_t *pool,
  +                                            void **result,
                                               const char *type, const char *name);
   
  -int jk_handler_discovery_sendDiscovery(jk_endpoint_t *ae,
  -                                       jk_workerEnv_t *we,
  -                                       jk_logger_t    *l);
  -
  -int jk_handler_discovery_handleContextList(jk_endpoint_t  *ae,
  -                                           jk_workerEnv_t *we,
  -                                           jk_msg_buf_t    *msg,
  -                                           jk_logger_t     *l);
  -
  -int jk_handler_discovery_sendGetContextaState(jk_msg_buf_t *msg,
  -                                              jk_workerEnv_t *c,
  -                                              char *vhost,
  -                                              char *cname,
  -                                              jk_logger_t  *l);
  -
  -int jk_handler_discovery_handleContextState(jk_msg_buf_t *msg,
  -                                            jk_workerEnv_t *c,
  -                                            jk_logger_t  *l);
  -
   /*
    * Context Query (web server -> servlet engine), which URI are handled by servlet engine
?
    */
  @@ -121,76 +103,7 @@
   
   #define MAX_URI_SIZE    512
   
  -static int jk_handler_discovery_init( jk_worker_t *w );
  -
  -/* ==================== Constructor and impl. ==================== */
  -
  -int JK_METHOD jk_handler_discovery_factory( jk_env_t *env, jk_pool_t *pool,
  -                                            void **result,
  -                                            const char *type, const char *name)
  -{
  -    jk_handler_t *h=(jk_handler_t *)pool->alloc( pool, sizeof( jk_handler_t));
  -
  -    h->init=jk_handler_discovery_init;
  -    *result=h;
  -    return JK_TRUE;
  -}
  -
  -
  -static int jk_handler_discovery_init( jk_worker_t *w ) {
  -    return JK_TRUE;
  -}
  -
  -
  -/** Send a 'discovery' message. This is a request for tomcat to
  - *  report all configured webapps and mappings.
  - *
  - * Build the Context Query Cmd (autoconf)
  - *
  - * +--------------------------+-
  - * | CONTEXT QRY CMD (1 byte) | 
  - * +--------------------------+-
  - *
  - */
  -int jk_handler_discovery_sendDiscovery(jk_endpoint_t *ae,
  -                                       jk_workerEnv_t *we,
  -                                       jk_logger_t    *l)
  -{
  -    jk_pool_t     *p = ae->pool;
  -    jk_msg_buf_t  *msg;
  -    int           rc=JK_FALSE;
  -    int                 cmd;
  -    int                 i,j;
  -    jk_login_service_t  *jl = ae->worker->login;
  -    jk_webapp_t   *ci;
  -    jk_webapp_t         *webapp;  
  -    char                *buf;
  -
  -
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:discovery\n");
  -    
  -    msg = jk_b_new(p);
  -    jk_b_set_buffer_size(msg, DEF_BUFFER_SZ);
  -    jk_b_reset(msg);
  -    
  -    /*
  -     * CONTEXT QUERY CMD
  -     */
  -    if (jk_b_append_byte(msg, AJP14_CONTEXT_QRY_CMD))
  -        return JK_FALSE;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:discovery - send query\n");
  -
  -    if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE)
  -        return JK_FALSE;
  -    
  -    jk_b_reset(msg);
  -    
  -    return rc;
  -}
  -
   /* -------------------- private utils/marshaling -------------------- */
  -
   /*
    * Decode the ContextList Cmd (Autoconf)
    *
  @@ -205,33 +118,35 @@
    *CONTEXT NAME (CString (*)) | URL1 [\n] URL2 [\n] URL3 [\n] | NEXT CTX. |
    *-------------------+-------------------------------+-----------+
    */
  -int jk_handler_discovery_handleContextList(jk_endpoint_t  *ae,
  -                                           jk_workerEnv_t *we,
  -                                           jk_msg_buf_t    *msg,
  -                                           jk_logger_t     *l)
  +static int jk_handler_contextList(jk_msg_t       *msg,
  +                                  jk_ws_service_t *s,
  +                                  jk_endpoint_t *ae,
  +                                  jk_logger_t *l)
   {
       char *vname;
       char *cname;
       char *uri;
       int                 cmd;
       int                 i,j;
  -    jk_login_service_t  *jl = ae->worker->login;
  -    jk_webapp_t   *ci;
  +    jk_webapp_t         *ci;
       jk_webapp_t         *webapp;  
       char                *buf;
  -
  +    jk_workerEnv_t *we=ae->worker->workerEnv;
  +    
       /*     if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE) */
       /*         return JK_FALSE; */
  -    
  -    if ((cmd = jk_b_get_byte(msg)) != AJP14_CONTEXT_INFO_CMD) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp14:discovery - wrong cmd %d:%d\n",
  +
  +    cmd=msg->getByte( msg );
  +    if (cmd != AJP14_CONTEXT_INFO_CMD) {
  +        l->jkLog(l, JK_LOG_ERROR,
  +                 "handler.discovery() - wrong cmd %d:%d\n",
                    AJP14_CONTEXT_INFO_CMD, cmd);
           return JK_FALSE;
       }
   
       for (;;) {
  -        vname  = (char *)jk_b_get_string(msg);
  -        cname  = (char *)jk_b_get_string(msg); 
  +        vname  = (char *)msg->getString(msg);
  +        cname  = (char *)msg->getString(msg); 
   
           if (cname==NULL || strlen( cname ) == 0 ) {
               l->jkLog(l, JK_LOG_DEBUG, "End of contest list\n");
  @@ -249,7 +164,7 @@
           }
            
           for (;;) {
  -            uri  = (char *)jk_b_get_string(msg);
  +            uri  = (char *)msg->getString(msg);
               
               if (uri==NULL || strlen( uri ) == 0 ) {
                   l->jkLog(l, JK_LOG_DEBUG, "No more URI for context %s", cname);
  @@ -272,62 +187,6 @@
   
   
   /*
  - * Build the Context State Query Cmd
  - *
  - * We send the list of contexts where we want to know state,
  - * empty string end context list*
  - * If cname is set, only ask about THIS context
  - *
  - * +----------------------------+----------------------------------+----------
  - * | CONTEXT STATE CMD (1 byte) |  VIRTUAL HOST NAME  | CONTEXT NAME
  - *                              |   (CString (*))     |  (CString (*)) 
  - * +----------------------------+----------------------------------+----------
  - *
  - */
  -int jk_handler_discovery_sendGetContextaState(jk_msg_buf_t *msg,
  -                                              jk_workerEnv_t *we,
  -                                              char *vhost, 
  -                                              char  *cname,
  -                                              jk_logger_t  *l)
  -{
  -    jk_webapp_t *ci;
  -    int                i;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_state_into_msgb\n");
  -    
  -    /* To be on the safe side */
  -    jk_b_reset(msg);
  -    
  -    /*
  -     * CONTEXT STATE CMD
  -     */
  -    if (jk_b_append_byte(msg, AJP14_CONTEXT_STATE_CMD))
  -        return JK_FALSE;
  -    
  -    /*
  -     * VIRTUAL HOST CSTRING
  -     */
  -     if (jk_b_append_string(msg, vhost)) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb"
  -               "- Error appending the virtual host string\n");
  -        return JK_FALSE;
  -     }
  -     
  -     /*
  -      * CONTEXT CSTRING
  -      */
  -     if (jk_b_append_string(msg, cname )) {
  -         l->jkLog(l, JK_LOG_ERROR,
  -                  "Error ajp14_marshal_context_state_into_msgb"
  -                  "- Error appending the context string %s\n", cname);
  -         return JK_FALSE;
  -     }
  -     
  -     return JK_TRUE;
  -}
  -
  -
  -/*
    * Decode the Context State Reply Cmd
    *
    * We get update of contexts list, empty string end context list*
  @@ -340,19 +199,20 @@
    *CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) | .. |
    * ------------------------+------------------+----+
    */
  -int jk_handler_discovery_handleContextState(jk_msg_buf_t *msg,
  -                                            jk_workerEnv_t *c,
  -                                            jk_logger_t  *l)
  +static int jk_handler_contextState(jk_msg_t       *msg,
  +                                  jk_ws_service_t *s,
  +                                  jk_endpoint_t *ae,
  +                                  jk_logger_t *l)
   {
       char                *vname;
       char                *cname;
       jk_webapp_t   *ci = NULL;
   
       /* get virtual name */
  -    vname  = (char *)jk_b_get_string(msg);
  +    vname  = (char *)msg->getString(msg);
       
       /* get context name */
  -    cname  = (char *)jk_b_get_string(msg);
  +    cname  = (char *)msg->getString(msg);
           
       if (! cname || ! strlen(cname)) {
           return JK_TRUE;
  @@ -368,16 +228,37 @@
           return JK_FALSE;
       }
           
  -    ci->status = jk_b_get_int(msg);
  +    ci->status = msg->getInt(msg);
           
       l->jkLog(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_state_reply "
                "- updated context %s to state %d\n", cname, ci->status);
       return JK_TRUE;
   }
   
  -
  -
   
  +int JK_METHOD jk_handler_discovery_factory( jk_env_t *env, jk_pool_t *pool,
  +                                            void **result,
  +                                            const char *type, const char *name)
  +{
  +    jk_map_t *map;
  +    jk_handler_t *h;
  +    
  +    map_alloc( &map, pool );
  +    *result=map;
  +    
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="contextInfo";
  +    h->messageId=AJP14_CONTEXT_INFO_CMD;
  +    h->callback=jk_handler_contextList;
  +    map_put( map, h->name, h, NULL );
  +
  +    h=(jk_handler_t *)pool->calloc( pool, sizeof( jk_handler_t));
  +    h->name="contextState";
  +    h->messageId=AJP14_CONTEXT_STATE_REP_CMD;
  +    h->callback=jk_handler_contextState;
  +    map_put( map, h->name, h, NULL );
   
  +    return JK_TRUE;
  +}
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message