hgomez      01/06/01 03:02:05

  Modified:    jk/src/native/common jk_ajp14.c jk_ajp14.h
  Log:
  New marshal/unmarshal on ajp14 protocol
  
  Revision  Changes    Path
  1.3       +393 -4    jakarta-tomcat-connectors/jk/src/native/common/jk_ajp14.c
  
  Index: jk_ajp14.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/src/native/common/jk_ajp14.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jk_ajp14.c        2001/05/21 15:23:34     1.2
  +++ jk_ajp14.c        2001/06/01 10:02:02     1.3
  @@ -56,12 +56,14 @@
   /***************************************************************************
    * Description: Next generation bi-directional protocol handler.           *
    * Author:      Henri Gomez <[EMAIL PROTECTED]>                               *
  - * Version:     $Revision: 1.2 $                                           *
  + * Version:     $Revision: 1.3 $                                           *
    ***************************************************************************/
   
   
   #include "jk_global.h"
   #include "jk_util.h"
  +#include "jk_map.h"
  +#include "jk_context.h"
   #include "jk_ajp14.h"
   
   /*
  @@ -75,6 +77,7 @@
        jk_log(l, JK_LOG_DEBUG, "Into ajp14_compute_md5 (%s)\n", s->computed_key);
   }
   
  +
   /*
    * Build the Login Init Command
    *
  @@ -108,14 +111,38 @@
        /*
         * WEB-SERVER NAME
         */
  -     if (jk_b_append_string(msg, s->server_name)) {
  -        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_login_init_into_msgb - Error 
appending the server_name string\n");
  +     if (jk_b_append_string(msg, s->web_server_name)) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_login_init_into_msgb - Error 
appending the web_server_name string\n");
           return JK_FALSE;
       }
   
       return JK_TRUE;
   }
   
  +
  +/*
  + * Decode the Login Seed Command
  + *
  + * +-------------------------+---------------------------+
  + * | LOGIN SEED CMD (1 byte) | MD5 of entropy (32 chars) |
  + * +-------------------------+---------------------------+
  + *
  + */
  +
  +int ajp14_unmarshal_login_seed(jk_msg_buf_t *msg,
  +                               jk_login_service_t *s,
  +                               jk_pool_t *p,
  +                               jk_logger_t *l)
  +{
  +    if (jk_b_get_bytes(msg, s->entropy, AJP14_ENTROPY_SEED_LEN) < 0) {
  +        jk_log(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
    *
  @@ -140,6 +167,8 @@
       if (jk_b_append_byte(msg, AJP14_LOGCOMP_CMD)) 
           return JK_FALSE;
   
  +     ajp14_compute_md5(s, l);
  +
        /*
         * COMPUTED-SEED
         */
  @@ -153,6 +182,139 @@
   
   
   /*
  + * Decode the LogOk Command
  + *
  + * +--------------------+------------------------+-------------------------------+
  + * | LOGOK CMD (1 byte) | NEGOCIED DATA (32bits) | SERVLET ENGINE INFO (CString) |
  + * +--------------------+------------------------+-------------------------------+
  + *
  + */
  +
  +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);
  +
  +     if (nego == 0xFFFFFFFF) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't get 
negociated data\n");
  +        return JK_FALSE;
  +    }
  +
  +     sname = (char *)jk_b_get_string(msg);
  +
  +     if (! sname) {
  +             jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't get 
servlet engine name\n");
  +             return JK_FALSE;
  +     }
  +     
  +     if (s->servlet_engine_name)                     /* take care of removing 
previously allocated data */
  +             free(s->servlet_engine_name);
  +
  +     s->servlet_engine_name = strdup(sname);
  +
  +     if (! s->servlet_engine_name) {
  +             jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't malloc 
servlet engine name\n");
  +             return JK_FALSE;
  +     }
  +
  +     return JK_TRUE;
  +}
  +
  +
  +/*
  + * Decode the Log Nok Command 
  + *
  + * +---------------------+-----------------------+
  + * | LOGNOK CMD (1 byte) | FAILURE CODE (32bits) |
  + * +---------------------+-----------------------+
  + *
  + */
  +
  +int ajp14_unmarshal_log_nok(jk_msg_buf_t *msg,
  +                            jk_logger_t *l)
  +{
  +     unsigned long   status;
  +
  +    jk_log(l, JK_LOG_DEBUG, "Into ajp14_unmarshal_log_nok\n");
  +
  +     status = jk_b_get_long(msg);
  +
  +    if (status == 0xFFFFFFFF) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_nok - can't get failure 
code\n");
  +        return JK_FALSE;
  +    }
  +
  +     jk_log(l, JK_LOG_INFO, "Can't Log with servlet engine - code %08lx", status);
  +     return JK_TRUE;
  +}
  +
  +
  +/* 
  + * Build the Shutdown Cmd
  + *
  + * +-----------------------+---------------------------------------+
  + * | SHUTDOWN CMD (1 byte) | MD5 of RANDOM + SECRET KEY (32 chars) |
  + * +-----------------------+---------------------------------------+
  + *
  + */
  +
  +int ajp14_marshal_shutdown_into_msgb(jk_msg_buf_t       *msg,
  +                                     jk_login_service_t *s,
  +                                     jk_logger_t        *l)
  +{
  +    jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_shutdown_into_msgb\n");
  +
  +    /* To be on the safe side */
  +    jk_b_reset(msg);
  +
  +    /*
  +     * SHUTDOWN CMD
  +     */
  +    if (jk_b_append_byte(msg, AJP14_SHUTDOWN_CMD))
  +        return JK_FALSE;
  +
  +    /*
  +     * COMPUTED-SEED
  +     */
  +     if (jk_b_append_bytes(msg, s->computed_key, AJP14_COMPUTED_KEY_LEN)) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_shutdown_into_msgb - Error 
appending the COMPUTED MD5 bytes\n");
  +        return JK_FALSE;
  +    }
  +
  +     return JK_TRUE;
  +}
  +
  +/*
  + * Decode the Shutdown Nok Command
  + *
  + * +----------------------+-----------------------+
  + * | SHUTNOK CMD (1 byte) | FAILURE CODE (32bits) |
  + * +----------------------+-----------------------+
  + *
  + */
  +int ajp14_unmarshal_shutdown_nok(jk_msg_buf_t *msg,
  +                                 jk_logger_t *l)
  +{
  +    unsigned long   status;
  +
  +    jk_log(l, JK_LOG_DEBUG, "Into ajp14_unmarshal_shutdown_nok\n");
  +
  +    status = jk_b_get_long(msg);
  +
  +    if (status == 0xFFFFFFFF) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_shutdown_nok - can't get 
failure code\n");
  +        return JK_FALSE;
  +    }
  +
  +    jk_log(l, JK_LOG_INFO, "Can't shutdown servlet engine - code %08lx", status);
  +    return JK_TRUE;
  +}
  +
  +/*
    * Build the Unknown Packet
    *
    * 
+-----------------------------+---------------------------------+------------------------------+
  @@ -183,7 +345,8 @@
                return JK_FALSE;
   
        /*
  -      * UNHANDLED MESSAGE
  +      * UNHANDLED MESSAGE (Question : Did we have to send all the message or only 
part of)
  +      *                                       (           ie: only 1k max           
                                                     )
         */
        if (jk_b_append_bytes(msg, jk_b_get_buff(unk), jk_b_get_len(unk))) {
           jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_unknown_packet_into_msgb - 
Error appending the UNHANDLED MESSAGE\n");
  @@ -191,4 +354,230 @@
       }
   
       return JK_TRUE;
  +}
  +
  +/*
  + * Build the Context Query Cmd (autoconf)
  + *
  + * +--------------------------+---------------------------------+
  + * | CONTEXT QRY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) |
  + * +--------------------------+---------------------------------+
  + *
  + */
  +
  +int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t     *msg,
  +                                                                               char 
            *virtual,
  +                                                                               
jk_logger_t      *l)
  +{
  +     jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_query_into_msgb\n");
  +
  +     /* To be on the safe side */
  +     jk_b_reset(msg);
  +
  +    /*
  +     * CONTEXT QUERY CMD
  +     */
  +    if (jk_b_append_byte(msg, AJP14_CONTEXT_QRY_CMD))
  +        return JK_FALSE;
  +
  +    /*
  +     * VIRTUAL HOST CSTRING
  +     */
  +     if (jk_b_append_string(msg, virtual)) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_query_into_msgb - 
Error appending the virtual host string\n");
  +        return JK_FALSE;
  +    }
  +
  +     return JK_TRUE;
  +}
  +
  +
  +/*
  + * Decode the Context Info Cmd (Autoconf)
  + *
  + * The Autoconf feature of AJP14, let us know which URL/URI could
  + * be handled by the servlet-engine
  + *
  + * 
+---------------------------+---------------------------------+----------------------------+-------------------------------+
  + * | CONTEXT INFO CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME 
(CString (*)) | URL1 [\n] URL2 [\n] URL3 [\n] |
  + * 
+---------------------------+---------------------------------+----------------------------+-------------------------------+
  + *
  + */
  +
  +int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
  +                                                              jk_context_t *context,
  +                                 jk_logger_t *l)
  +{
  +    char *sname;
  +     char *old;
  +     int      i;
  +
  +    sname  = (char *)jk_b_get_string(msg);
  +
  +    if (! sname) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get 
virtual hostname\n");
  +        return JK_FALSE;
  +    }
  +
  +    if (context->virtual)         /* take care of removing previously allocated 
data */
  +        free(context->virtual);
  +
  +    context->virtual = strdup(sname);
  +
  +    if (! context->virtual) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't malloc 
virtual hostname\n");
  +        return JK_FALSE;
  +    }
  +
  +    sname  = (char *)jk_b_get_string(msg); 
  +
  +    if (! sname) {
  +        log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get 
context\n");
  +        return JK_FALSE;
  +    }   
  +
  +    if (context->cbase)       /* take care of removing previously allocated data */
  +        free(context->cbase);
  +
  +    context->cbase = strdup(sname);
  + 
  +    if (! context->cbase) {
  +        log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't malloc 
context\n");
  +        return JK_FALSE;
  +    }
  +
  +     for (i = 1;; i++) {
  +
  +             sname  = (char *)jk_b_get_string(msg);
  +
  +             if (!sname) {
  +                     log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - 
can't get URL\n");
  +                     return JK_FALSE;
  +             }
  +
  +             if (! strlen(sname)) {
  +                     log(l, JK_LOG_INFO, "No more URI/URL (%d)", i);
  +                     break;
  +             }
  +
  +             log(l, JK_LOG_INFO, "Got URL (%s) for virtualhost %s and base context 
%s", sname, context->virtual, context->cbase);
  +             context_add_uri(context, sname);
  +     }
  +     
  +    return JK_TRUE;
  +}
  +
  +
  +/*
  + * Build the Context State Query Cmd
  + *
  + * 
+----------------------------+----------------------------------+----------------------------+
  + * | CONTEXT STATE CMD (1 byte) |  VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME 
(CString (*)) |
  + * 
+----------------------------+----------------------------------+----------------------------+
  + *
  + */
  +
  +int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t       *msg,
  +                                          jk_context_t               *context,
  +                                          jk_logger_t        *l)
  +{
  +    jk_log(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, context->virtual)) {
  +        jk_log(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, context->cbase)) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - 
Error appending the context string\n");
  +        return JK_FALSE;
  +    }
  +    
  +    return JK_TRUE;
  +}
  +
  +
  +/*
  + * Decode the Context State Reply Cmd
  + *
  + * 
+----------------------------------+---------------------------------+----------------------------+------------------+
  + * | CONTEXT STATE REPLY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT 
NAME (CString (*)) | UP/DOWN (1 byte) |
  + * 
+----------------------------------+---------------------------------+----------------------------+------------------+
  + *
  + */
  +
  +int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
  +                                                                             
jk_context_t *context,
  +                                                     jk_logger_t *l)
  +{
  +    char *sname;
  +
  +     sname  = (char *)jk_b_get_string(msg);
  +
  +    if (! sname) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't 
get virtual hostname\n");
  +        return JK_FALSE;
  +    }
  +
  +    if (context->virtual)         /* take care of removing previously allocated 
data */
  +        free(context->virtual);
  +
  +    context->virtual = strdup(sname);
  +
  +    if (! context->virtual) {
  +        jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't 
malloc virtual hostname\n");
  +        return JK_FALSE;
  +    }
  +
  +     sname  = (char *)jk_b_get_string(msg);
  +
  +     if (! sname) {
  +             log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - 
can't get context\n");
  +             return JK_FALSE;
  +     }       
  +
  +     if (context->cbase)             /* take care of removing previously allocated 
data */
  +             free(context->cbase);
  +
  +     context->cbase = strdup(sname);
  +
  +     if (! context->cbase) {
  +             log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - 
can't malloc context\n");
  +             return JK_FALSE;
  +     }
  +
  +     context->status = jk_b_get_int(msg);
  +
  +    return JK_TRUE;
  +}
  +
  +/*
  + * Decode the Context Update Cmd
  + * 
  + * 
+-----------------------------+---------------------------------+----------------------------+------------------+
  + * | CONTEXT UPDATE CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME 
(CString (*)) | UP/DOWN (1 byte) |
  + * 
+-----------------------------+---------------------------------+----------------------------+------------------+
  + * 
  + */
  +
  +int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
  +                                       jk_context_t *context,
  +                                       jk_logger_t *l)
  +{
  +     return (ajp14_unmarshal_context_state_reply(msg, context, l));
   }
  
  
  
  1.2       +6 -1      jakarta-tomcat-connectors/jk/src/native/common/jk_ajp14.h
  
  Index: jk_ajp14.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/src/native/common/jk_ajp14.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jk_ajp14.h        2001/05/18 16:47:05     1.1
  +++ jk_ajp14.h        2001/06/01 10:02:03     1.2
  @@ -56,7 +56,7 @@
   /***************************************************************************
    * Description: Next generation bi-directional protocol handler.           *
    * Author:      Henri Gomez <[EMAIL PROTECTED]>                               *
  - * Version:     $Revision: 1.1 $                                           *
  + * Version:     $Revision: 1.2 $                                           *
    ***************************************************************************/
   #ifndef JK_AJP14_H
   #define JK_AJP14_H
  @@ -249,7 +249,12 @@
       /*
         *  Pointer to web-server name
        */
  -    char * server_name;
  +    char * web_server_name;
  +
  +     /*
  +      * Pointer to servlet-engine name
  +      */
  +     char * servlet_engine_name;
   
        /*
         * Pointer to secret key
  
  
  

Reply via email to