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_discovery.c
Date Thu, 06 Dec 2001 22:57:14 GMT
costin      01/12/06 14:57:14

  Modified:    jk/native2/common jk_handler_discovery.c
  Log:
  Some massive changes. This is now probably broken ( but it's an optional piece ).
  
  The idea is that status notifications and messages about new apps could be sent
  by tomcat at any time - not only at startup time. The original code did a RPC-style
  request for discovery - that didn't worked if tomcat was started after apache,
  and doesn't allow for dynamic updates.
  
  The way ( I think ) it should operate is to accept messages at any time using
  the common loop and dispatch on message type.
  
  Revision  Changes    Path
  1.6       +120 -612  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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- jk_handler_discovery.c	2001/12/05 20:48:20	1.5
  +++ jk_handler_discovery.c	2001/12/06 22:57:13	1.6
  @@ -58,7 +58,7 @@
   /**
    * Description: AJP14 Discovery handler
    * Author:      Henri Gomez <hgomez@slib.fr>
  - * Version:     $Revision: 1.5 $                                          
  + * Version:     $Revision: 1.6 $                                          
    */
   
   #include "jk_global.h"
  @@ -68,105 +68,30 @@
   #include "jk_logger.h"
   #include "jk_service.h"
   #include "jk_handler.h"
  +#include "jk_webapp.h"
  +#include "jk_workerEnv.h"
   
  -#define CBASE_INC_SIZE   (8)    /* Allocate memory by step of 8 URIs : ie 8 URI by context
*/
  -#define URI_INC_SIZE (8)        /* Allocate memory by step of 8 CONTEXTs : ie 8 contexts
by worker */
  +int JK_METHOD jk_handler_discovery_factory( jk_env_t *env, jk_pool_t *pool, void **result,
  +                                            const char *type, const char *name);
   
  -/** XXX XXX MERGE into jk_uriMap / jk_uriEnv */
  -
  -typedef struct {
  -    char *      cbase;
  -    int         status;
  -    int         size;
  -    int         capacity;
  -    char **     uris;
  -} jk_context_item_t;
  -
  -
  -typedef struct {
  -
  -    /*
  -     * Memory Pool
  -     */
  -
  -    jk_pool_t       p;
  -    jk_pool_atom_t  buf[SMALL_POOL_SIZE];
  -
  -	/*
  -	 * Virtual Server (if use)
  -	 */
  -
  -	char *		            virtual;
  -
  -    /*
  -     * Num of context handled (ie: examples, admin...)
  -     */
  -
  -    int                     size;
  -
  -    /*
  -     * Capacity
  -     */
  -
  -    int                     capacity; 
  -
  -    /*
  -     * Context list, context / URIs
  -     */
  -
  -    jk_context_item_t **    contexts;
  -} 
  -jk_context_t;
  -
  -
  -/*
  - * functions defined here 
  - */
  -
  -int context_set_virtual(jk_context_t *c, char *virtual);
  -
  -int context_open(jk_context_t *c, char *virtual);
  -
  -int context_free(jk_context_t **c);
  -
  -jk_context_item_t *context_find_base(jk_context_t *c, char *cbase);
  -
  -char *context_item_find_uri(jk_context_item_t *ci, char *uri);
  -
  -void context_dump_uris(jk_context_t *c, char *cbase, FILE *f);
  -
  -jk_context_item_t *context_add_base(jk_context_t *c, char *cbase);
  -
  -int context_add_uri(jk_context_t *c, char *cbase, char *uri);
  -
  -static int jk_handler_discovery_init( jk_worker_t *w );
  -
  -static int jk_handler_discovery_discovery(jk_endpoint_t *ae,jk_workerEnv_t *we,
  -                                          jk_logger_t *l);
  -
  -static int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,
  -                                                 char         *virtual,
  -                                                 jk_logger_t  *l);
  -
  -static int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
  -                                        jk_context_t *c,
  -                                        jk_logger_t  *l);
  -
  -static int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,
  -                                                 jk_context_t *c,
  -                                                 char         *cname,
  -                                                 jk_logger_t  *l);
  -
  -static int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
  -                                               jk_context_t *c,
  -                                               jk_logger_t  *l);
  -
  -static int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
  -                                              jk_context_t *c,
  +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_METHOD jk_handler_discovery_factory( jk_env_t *env, void **result,
  -                                            char *type, char *name);
  +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
?
  @@ -194,12 +119,17 @@
    */
   #define AJP14_CONTEXT_STATE_REP_CMD	(unsigned char)0x1D
   
  +#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, void **result,
  -                                            char *type, char *name)
  +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 *)malloc( sizeof( jk_handler_t));
  +    jk_handler_t *h=(jk_handler_t *)pool->alloc( pool, sizeof( jk_handler_t));
   
       h->init=jk_handler_discovery_init;
       *result=h;
  @@ -211,211 +141,36 @@
       return JK_TRUE;
   }
   
  -
  -static int context_realloc(jk_context_t *c)
  -{
  -    if (c->size == c->capacity) {
  -        jk_context_item_t **contexts;
  -        int  capacity = c->capacity + CBASE_INC_SIZE;
  -        
  -        contexts = (jk_context_item_t **)c->p.alloc(&c->p, sizeof(jk_context_item_t
*) * capacity);
  -
  -        if (! contexts)
  -            return JK_FALSE;
  -
  -        if (c->capacity && c->contexts)
  -            memcpy(contexts, c->contexts, sizeof(jk_context_item_t *) * c->capacity);
  -
  -        c->contexts = contexts;
  -        c->capacity = capacity;
  -    }
  -
  -    return JK_TRUE;
  -}
  -
  -
  -static int context_item_realloc(jk_context_t *c, jk_context_item_t *ci)
  -{
  -    if (ci->size == ci->capacity) {
  -            char **uris;
  -            int capacity = ci->capacity + URI_INC_SIZE;
  -
  -            uris = (char **)c->p.alloc(&c->p, sizeof(char *) * capacity);
  -
  -        if (! uris)
  -            return JK_FALSE;
  -
  -        memcpy(uris, ci->uris, sizeof(char *) * ci->capacity);
  -
  -        ci->uris     = uris;
  -        ci->capacity = capacity;
  -    }
  -    
  -    return JK_TRUE;
  -}
  -
  -/*
  - * Init the context info struct
  - */
   
  -int context_open(jk_context_t *c, char *virtual)
  -{
  -    if (c) {
  -        jk_open_pool(&c->p, c->buf, sizeof(jk_pool_atom_t) * SMALL_POOL_SIZE);
  -        c->size  	= 0;
  -        c->capacity = 0;
  -        c->contexts = NULL;
  -
  -        if( virtual ) {
  -            c->virtual=c->p.pstrdup(&c->p, virtual);
  -        }
  -        return JK_TRUE;
  -    }
  -
  -    return JK_FALSE;
  -}
  -
  -
  -/*
  - * AJP14 Autoconf Phase
  +/** Send a 'discovery' message. This is a request for tomcat to
  + *  report all configured webapps and mappings.
    *
  - * CONTEXT QUERY / REPLY
  + * Build the Context Query Cmd (autoconf)
  + *
  + * +--------------------------+-
  + * | CONTEXT QRY CMD (1 byte) | 
  + * +--------------------------+-
  + *
    */
  -
  -#define MAX_URI_SIZE    512
  -
  -static int handle_discovery(jk_endpoint_t  *ae,
  -                            jk_workerEnv_t *we,
  -                            jk_msg_buf_t    *msg,
  -                            jk_logger_t     *l)
  +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_context_item_t   *ci;
  -    jk_context_t        *c;  
  +    jk_webapp_t   *ci;
  +    jk_webapp_t         *webapp;  
       char                *buf;
   
  -#ifndef TESTME
  -
  -    ajp14_marshal_context_query_into_msgb(msg, we->virtual, l);
  -    
  -    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;
  -    
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:discovery - wait context 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_CONTEXT_INFO_CMD) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14:discovery - awaited command %d, received %d\n",
  -               AJP14_CONTEXT_INFO_CMD, cmd);
  -        return JK_FALSE;
  -    }
  -
  -    c=(jk_context_t *)malloc( sizeof(jk_context_t));
  -    if (context_open(c, we->virtual) != JK_TRUE) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14:discovery - can't allocate context room\n");
  -        return JK_FALSE;
  -    }
  - 
  -    if (ajp14_unmarshal_context_info(msg, c, l) != JK_TRUE) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14:discovery - can't get context reply\n");
  -        return JK_FALSE;
  -    }
  -
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:discovery - received context\n");
   
  -    buf = malloc(MAX_URI_SIZE);      /* Really a very long URI */
  -    
  -    if (! buf) {
  -        l->jkLog(l, JK_LOG_ERROR, "Error ajp14:discovery - can't alloc buf\n");
  -        return JK_FALSE;
  -    }
  -    
  -    for (i = 0; i < c->size; i++) {
  -        ci = c->contexts[i];
  -        for (j = 0; j < ci->size; j++) {
  -            
  -#ifndef USE_SPRINTF
  -            snprintf(buf, MAX_URI_SIZE - 1, "/%s/%s", ci->cbase, ci->uris[j]);
  -#else
  -            sprintf(buf, "/%s/%s", ci->cbase, ci->uris[j]);
  -#endif
  -            
  -            l->jkLog(l, JK_LOG_INFO,
  -                   "Into ajp14:discovery "
  -                   "- worker %s will handle uri %s in context %s [%s]\n",
  -                   ae->worker->name, ci->uris[j], ci->cbase, buf);
  -            
  -/* XXX UPDATE             uri_worker_map_add(we->uri_to_worker, buf, ae->worker->name,
l); */
  -        }
  -    }
  -    
  -    free(buf);
  -    c->p.close(&c->p);
  -    free(c);
  -    c = NULL;
  -#else 
  -    
  -    uri_worker_map_add(we->uri_to_worker,
  -                       "/examples/servlet/*",
  -                       ae->worker->name, l);
  -    uri_worker_map_add(we->uri_to_worker,
  -                       "/examples/*.jsp",
  -                       ae->worker->name, l);
  -    uri_worker_map_add(we->uri_to_worker,
  -                       "/examples/*.gif",
  -                       ae->worker->name, l);
  -
  -#endif 
  -    return JK_TRUE;
  -}
  - 
  -static int jk_handler_discovery_discovery(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;
  -
       l->jkLog(l, JK_LOG_DEBUG, "Into ajp14:discovery\n");
       
       msg = jk_b_new(p);
       jk_b_set_buffer_size(msg, DEF_BUFFER_SZ);
  -    
  -    if ((rc = handle_discovery(ae, we, msg, l)) == JK_FALSE)
  -        ajp_close_endpoint(ae, l);
  -
  -    return rc;
  -}
  -
  -/* -------------------- private utils/marshaling -------------------- */
  -
  -/*
  - * Build the Context Query Cmd (autoconf)
  - *
  - * +--------------------------+---------------------------------+
  - * | CONTEXT QRY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) |
  - * +--------------------------+---------------------------------+
  - *
  - */
  -static int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,
  -                                                 char         *virtual,
  -                                                 jk_logger_t  *l)
  -{
  -    l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_query_into_msgb\n");
  -    
  -    /* To be on the safe side */
       jk_b_reset(msg);
       
       /*
  @@ -424,22 +179,20 @@
       if (jk_b_append_byte(msg, AJP14_CONTEXT_QRY_CMD))
           return JK_FALSE;
       
  -    /*
  -     * VIRTUAL HOST CSTRING
  -     */
  -    if (jk_b_append_string(msg, virtual)) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_marshal_context_query_into_msgb "
  -               "- Error appending the virtual host string\n");
  +    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;
  -    }
       
  -    return JK_TRUE;
  +    jk_b_reset(msg);
  +    
  +    return rc;
   }
   
  +/* -------------------- private utils/marshaling -------------------- */
   
   /*
  - * Decode the Context Info Cmd (Autoconf)
  + * Decode the ContextList Cmd (Autoconf)
    *
    * The Autoconf feature of AJP14, let us know which URL/URI could
    * be handled by the servlet-engine
  @@ -452,89 +205,66 @@
    *CONTEXT NAME (CString (*)) | URL1 [\n] URL2 [\n] URL3 [\n] | NEXT CTX. |
    *-------------------+-------------------------------+-----------+
    */
  -
  -static int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
  -                                        jk_context_t *c,
  -                                        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)
   {
       char *vname;
       char *cname;
       char *uri;
  -    
  -    vname  = (char *)jk_b_get_string(msg);
  -
  -    l->jkLog(l, JK_LOG_DEBUG,
  -           "ajp14_unmarshal_context_info - get virtual %s for virtual %s\n",
  -             vname, c->virtual);
  +    int                 cmd;
  +    int                 i,j;
  +    jk_login_service_t  *jl = ae->worker->login;
  +    jk_webapp_t   *ci;
  +    jk_webapp_t         *webapp;  
  +    char                *buf;
   
  -    if (! vname) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_context_info "
  -               "- can't get virtual hostname\n");
  +    /*     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",
  +                 AJP14_CONTEXT_INFO_CMD, cmd);
           return JK_FALSE;
       }
  -    
  -    /* Check if we get the correct virtual host */
  -    if (c->virtual != NULL && 
  -	vname != NULL &&
  -	strcmp(c->virtual, vname)) {
  -        /* set the virtual name, better to add to a virtual list ? */
   
  -        if( vname != NULL ) {
  -            c->virtual=  c->p.pstrdup(&c->p, vname);
  -        }
  -    }
  -    
       for (;;) {
  -        
  +        vname  = (char *)jk_b_get_string(msg);
           cname  = (char *)jk_b_get_string(msg); 
   
  -        if (! cname) {
  -            l->jkLog(l, JK_LOG_ERROR,
  -                   "Error ajp14_unmarshal_context_info - can't get context\n");
  -            return JK_FALSE;
  +        if (cname==NULL || strlen( cname ) == 0 ) {
  +            l->jkLog(l, JK_LOG_DEBUG, "End of contest list\n");
  +            return JK_TRUE;
           }   
  -        
  -        l->jkLog(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_info "
  -               "- get context %s for virtual %s\n", cname, vname);
           
  -        /* grab all contexts up to empty one which indicate end of contexts */
  -        if (! strlen(cname)) 
  -            break;
  +        l->jkLog(l, JK_LOG_DEBUG,
  +                 "contextList - Context: %s:%s \n", vname, cname);
   
  -        /* create new context base (if needed) */
  -        
  -        if (context_add_base(c, cname) == JK_FALSE) {
  -            l->jkLog(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info"
  -                   "- can't add/set context %s\n", cname);
  +        webapp = we->createWebapp( we, vname, cname, NULL );
  +        if( webapp==NULL ) {
  +            l->jkLog(l, JK_LOG_ERROR,
  +                     "discoveryHandler: can't create webapp\n");
               return JK_FALSE;
           }
  -        
  +         
           for (;;) {
  -            
               uri  = (char *)jk_b_get_string(msg);
  -            
  -            if (!uri) {
  -                l->jkLog(l, JK_LOG_ERROR,
  -                       "Error ajp14_unmarshal_context_info - can't get URI\n");
  -                return JK_FALSE;
  -            }
               
  -            if (! strlen(uri)) {
  +            if (uri==NULL || strlen( uri ) == 0 ) {
                   l->jkLog(l, JK_LOG_DEBUG, "No more URI for context %s", cname);
                   break;
               }
               
               l->jkLog(l, JK_LOG_INFO,
  -                   "Got URI (%s) for virtualhost %s and context %s\n",
  -                   uri, vname, cname);
  +                   "Got URI %s for %s:%s\n", uri, vname, cname);
               
  -            if (context_add_uri(c, cname, uri) == JK_FALSE) {
  -                l->jkLog(l, JK_LOG_ERROR,
  -                       "Error ajp14_unmarshal_context_info - "
  -                       "can't add/set uri (%s) for context %s\n", uri, cname);
  -                return JK_FALSE;
  -            } 
  +/*             if (context_add_uri(c, cname, uri) == JK_FALSE) { */
  +/*                 l->jkLog(l, JK_LOG_ERROR, */
  +/*                        "Error ajp14_unmarshal_context_info - " */
  +/*                        "can't add/set uri (%s) for context %s\n", uri, cname); */
  +/*                 return JK_FALSE; */
  +/*             }  */
           }
       }
       return JK_TRUE;
  @@ -554,12 +284,13 @@
    * +----------------------------+----------------------------------+----------
    *
    */
  -static int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,
  -                                                 jk_context_t *c,
  -                                                 char         *cname,
  -                                                 jk_logger_t  *l)
  +int jk_handler_discovery_sendGetContextaState(jk_msg_buf_t *msg,
  +                                              jk_workerEnv_t *we,
  +                                              char *vhost, 
  +                                              char  *cname,
  +                                              jk_logger_t  *l)
   {
  -    jk_context_item_t *ci;
  +    jk_webapp_t *ci;
       int                i;
       
       l->jkLog(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_state_into_msgb\n");
  @@ -576,53 +307,19 @@
       /*
        * VIRTUAL HOST CSTRING
        */
  -     if (jk_b_append_string(msg, c->virtual)) {
  +     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;
        }
  -     
  -     if (cname) {
  -         
  -         ci = context_find_base(c, cname);
  -         
  -         if (! ci) {
  -             l->jkLog(l, JK_LOG_ERROR,
  -                    "Warning ajp14_marshal_context_state_into_msgb"
  -                    "- unknown context %s\n", cname);
  -            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;
  -         }
  -     } else { /* Grab all contexts name */
  -         for (i = 0; i < c->size; i++) {
  -            /*
  -             * CONTEXT CSTRING
  -             */
  -             if (jk_b_append_string(msg, c->contexts[i]->cbase )) {
  -                 l->jkLog(l, JK_LOG_ERROR,
  -                        "Error ajp14_marshal_context_state_into_msgb "
  -                        "- Error appending the context string\n");
  -                 return JK_FALSE;
  -             }
  -         }
  -     }
  -     
  -     /* End of context list, an empty string */ 
        
  -     if (jk_b_append_string(msg, "")) {
  +     /*
  +      * CONTEXT CSTRING
  +      */
  +     if (jk_b_append_string(msg, cname )) {
            l->jkLog(l, JK_LOG_ERROR,
  -                "Error ajp14_marshal_context_state_into_msgb "
  -                "- Error appending end of contexts\n");
  +                  "Error ajp14_marshal_context_state_into_msgb"
  +                  "- Error appending the context string %s\n", cname);
            return JK_FALSE;
        }
        
  @@ -643,233 +340,44 @@
    *CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) | .. |
    * ------------------------+------------------+----+
    */
  -static int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
  -                                               jk_context_t *c,
  -                                               jk_logger_t  *l)
  +int jk_handler_discovery_handleContextState(jk_msg_buf_t *msg,
  +                                            jk_workerEnv_t *c,
  +                                            jk_logger_t  *l)
   {
       char                *vname;
       char                *cname;
  -    jk_context_item_t   *ci;
  +    jk_webapp_t   *ci = NULL;
   
       /* get virtual name */
       vname  = (char *)jk_b_get_string(msg);
       
  -    if (! vname) {
  -        l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_context_state_reply "
  -               "- can't get virtual hostname\n");
  -        return JK_FALSE;
  +    /* get context name */
  +    cname  = (char *)jk_b_get_string(msg);
  +        
  +    if (! cname || ! strlen(cname)) {
  +        return JK_TRUE;
       }
  -    
  -    /* Check if we speak about the correct virtual */
  -    if (strcmp(c->virtual, vname)) {
  +        
  +    /* ci = context_find_base(c, cname); */
  +        
  +    if (! ci) {
           l->jkLog(l, JK_LOG_ERROR,
  -               "Error ajp14_unmarshal_context_state_reply"
  -               "- incorrect virtual %s instead of %s\n",
  -               vname, c->virtual);
  +                 "Error ajp14_unmarshal_context_state_reply "
  +                 "- unknow context %s for virtual %s\n", 
  +                 cname, vname);
           return JK_FALSE;
       }
  -    
  -    for (;;) {
  -        /* get context name */
  -        cname  = (char *)jk_b_get_string(msg);
  -        
  -        if (! cname) {
  -            l->jkLog(l, JK_LOG_ERROR,
  -                   "Error ajp14_unmarshal_context_state_reply"
  -                   "- can't get context\n");
  -            return JK_FALSE;
  -        }	
  -        
  -        if (! strlen(cname))
  -            break;
  -        
  -        ci = context_find_base(c, cname);
  -        
  -        if (! ci) {
  -            l->jkLog(l, JK_LOG_ERROR,
  -                   "Error ajp14_unmarshal_context_state_reply "
  -                   "- unknow context %s for virtual %s\n", 
  -                   cname, vname);
  -            return JK_FALSE;
  -        }
           
  -        ci->status = jk_b_get_int(msg);
  +    ci->status = jk_b_get_int(msg);
           
  -        l->jkLog(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_state_reply "
  -               "- updated context %s to state %d\n", cname, ci->status);
  -    }
  -    
  +    l->jkLog(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_state_reply "
  +             "- updated context %s to state %d\n", cname, ci->status);
       return JK_TRUE;
   }
   
  -/*
  - * Decode the Context Update Cmd
  - * 
  - * +-----------------------------+---------------------------------+------
  - * | CONTEXT UPDATE CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | 
  - * +-----------------------------+---------------------------------+------
  - *
  - * ----------------------+------------------+
  - * CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) |
  - * ----------------------+------------------+
  - * 
  - */
  -static int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
  -                                              jk_context_t *c,
  -                                              jk_logger_t  *l)
  -{
  -    return (ajp14_unmarshal_context_state_reply(msg, c, l));
  -}
  -
  - /*
  - * Set the virtual name of the context 
  - */
  -
  -int context_set_virtual(jk_context_t *c, char *virtual)
  -{
  -    if (c) {
  -
  -        if (virtual) {
  -            c->virtual = c->p.pstrdup(&c->p, virtual);
  -
  -            if (! c->virtual)
  -                return JK_FALSE;
  -        }
  -
  -        return JK_TRUE;
  -    }
  -
  -    return JK_FALSE;
  -}
  -
  -/*
  - * Locate a context base in context list
  - */
  -
  -jk_context_item_t * context_find_base(jk_context_t *c, char *cbase)
  -{
  -    int                 i;
  -    jk_context_item_t * ci;
  -
  -    if (! c || ! cbase)
  -        return NULL;
  -
  -    for (i = 0 ; i < c->size ; i++) {
  -        
  -        ci = c->contexts[i];
  -
  -        if (! ci)
  -            continue;
  -
  -        if (! strcmp(ci->cbase, cbase))
  -            return ci;
  -    }
  -
  -    return NULL;
  -}
  -
  -/*
  - * Locate an URI in a context item
  - */
  -
  -char * context_item_find_uri(jk_context_item_t *ci, char *uri)
  -{
  -    int i;
  -
  -    if (! ci || ! uri)
  -        return NULL;
  -
  -    for (i = 0 ; i < ci->size ; i++) {
  -        if (! strcmp(ci->uris[i], uri))
  -            return ci->uris[i];
  -    }
  -
  -    return NULL;
  -}
  -
  -void context_dump_uris(jk_context_t *c, char *cbase, FILE * f)
  -{
  -    jk_context_item_t * ci;
  -    int                 i;
  -
  -    ci = context_find_base(c, cbase);
  -
  -    if (! ci)
  -        return;
  -
  -    for (i = 0; i < ci->size; i++)
  -        fprintf(f, "/%s/%s\n", ci->cbase, ci->uris[i]);
  -
  -    fflush(f); 
  -}
  -
  -
  -/*
  - * Add a new context item to context
  - */
  -
  -jk_context_item_t * context_add_base(jk_context_t *c, char *cbase)
  -{
  -    jk_context_item_t *  ci;
  -
  -    if (! c || !cbase)
  -        return NULL;
  -
  -    /* Check if the context base was not allready created */
  -    ci = context_find_base(c, cbase);
  -
  -    if (ci)
  -        return ci;
  -
  -    if (context_realloc(c) != JK_TRUE)
  -        return NULL;
  -
  -    ci = (jk_context_item_t *)c->p.alloc(&c->p, sizeof(jk_context_item_t));
  -
  -    if (! ci)
  -        return NULL;
   
  -    c->contexts[c->size] = ci;
  -    c->size++;
  -    ci->cbase       = c->p.pstrdup(&c->p, cbase);
  -    ci->status      = 0;
  -    ci->size        = 0;
  -    ci->capacity    = 0;
  -    ci->uris        = NULL;
   
  -    return ci;
  -}
  -
  -/*
  - * Add a new URI to a context item
  - */
  -
  -int context_add_uri(jk_context_t *c, char *cbase, char * uri)
  -{
  -    jk_context_item_t *  ci;
  -
  -    if (! uri)
  -        return JK_FALSE;
  -
  -    /* Get/Create the context base */
  -    ci = context_add_base(c, cbase);
  -        
  -    if (! ci)
  -        return JK_FALSE;
   
  -    if (context_item_find_uri(ci, uri) != NULL)
  -        return JK_TRUE;
  -
  -    if (context_item_realloc(c, ci) == JK_FALSE)
  -        return JK_FALSE;
   
  -    ci->uris[ci->size] = c->p.pstrdup(&c->p, uri);
   
  -    if (ci->uris[ci->size] == NULL)
  -        return JK_FALSE;
  -
  -    ci->size++;
  -    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