tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hgo...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native/common jk_context.c jk_context.h
Date Fri, 29 Jun 2001 14:55:22 GMT
hgomez      01/06/29 07:55:22

  Modified:    jk/native/common jk_context.c jk_context.h
  Log:
  Complete refactory of context, virutal is the key
  
  Revision  Changes    Path
  1.5       +179 -60   jakarta-tomcat-connectors/jk/native/common/jk_context.c
  
  Index: jk_context.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_context.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jk_context.c	2001/06/18 14:15:37	1.4
  +++ jk_context.c	2001/06/29 14:55:22	1.5
  @@ -58,47 +58,52 @@
   /***************************************************************************
    * Description: Context handling (Autoconf)                                *
    * Author:      Henri Gomez <hgomez@slib.fr>                               *
  - * Version:     $Revision: 1.4 $                                           *
  + * Version:     $Revision: 1.5 $                                           *
    ***************************************************************************/
   
   #include "jk_global.h"
   #include "jk_context.h"
   #include "jk_ajp_common.h"
   
  +
   /*
  - * Init the context info struct
  + * Set the virtual name of the context 
    */
   
  -int context_open(jk_context_t *c)
  +int context_set_virtual(jk_context_t *c, char *virtual)
   {
       if (c) {
  -        jk_open_pool(&c->p, c->buf, sizeof(jk_pool_atom_t) * SMALL_POOL_SIZE);
  -		c->virtual  = NULL;
  -		c->cbase  	= NULL,
  -        c->status   = AJP14_CONTEXT_DOWN;
  -        c->size  	= 0;
  -        c->capacity = 0;
  -        c->uris     = NULL;
  +
  +        if (virtual) {
  +            c->virtual = jk_pool_strdup(&c->p, virtual);
  +
  +            if (! c->virtual)
  +                return JK_FALSE;
  +        }
  +
           return JK_TRUE;
       }
   
       return JK_FALSE;
   }
   
  -
   /*
  - * Create the context info struct
  + * Init the context info struct
    */
   
  -int context_alloc(jk_context_t **c)
  +int context_open(jk_context_t *c, char *virtual)
   {
       if (c) {
  -        return context_open(*c = (jk_context_t *)malloc(sizeof(jk_context_t)));
  +        jk_open_pool(&c->p, c->buf, sizeof(jk_pool_atom_t) * SMALL_POOL_SIZE);
  +        c->size  	= 0;
  +        c->capacity = 0;
  +        c->contexts = NULL;
  +
  +        return context_set_virtual(c, virtual);
       }
  -    
  +
       return JK_FALSE;
   }
  - 
   
   /*
    * Close the context info struct
  @@ -107,6 +112,7 @@
   int context_close(jk_context_t *c)
   {
       if (c) {
  +
           jk_close_pool(&c->p);
           return JK_TRUE;
       }
  @@ -114,9 +120,20 @@
       return JK_FALSE;
   }
   
  +/*
  + * Allocate and open context
  + */
   
  +int context_alloc(jk_context_t **c, char * virtual)
  +{
  +    if (c) 
  +        return context_open(*c = (jk_context_t *)malloc(sizeof(jk_context_t)), virtual);
  +  
  +    return JK_FALSE;
  +}
  + 
   /*
  - * Delete the context info struct
  + * Close and destroy context
    */
   
   int context_free(jk_context_t **c)
  @@ -125,8 +142,7 @@
           context_close(*c);  
           free(*c);
           *c = NULL;
  -		return JK_TRUE;
  -
  +        return JK_TRUE;
       }
       
       return JK_FALSE;
  @@ -134,79 +150,182 @@
   
   
   /*
  - * Find a context in the Contextes List
  + * Ensure there will be memory in context info to store Context Bases
    */
   
  -jk_context_t * context_find(jk_context_list_t *l, char * virtual, char * cbase)
  +static int context_realloc(jk_context_t *c)
   {
  -	int	i;
  +    if (c->size == c->capacity) {
  +        jk_context_item_t **contexts;
  +        int  capacity = c->capacity + CBASE_INC_SIZE;
  +        
  +        contexts = (jk_context_item_t **)jk_pool_alloc(&c->p, sizeof(jk_context_item_t
*) * capacity);
   
  -	if (! l)
  -		return NULL;
  +        if (! contexts)
  +            return JK_FALSE;
   
  -	for (i = 0; i < l->ncontext; i++) {
  -		if (virtual) 
  -			if (strcmp(l->contexts[i]->virtual, virtual))
  -				continue;
  +        memcpy(contexts, c->contexts, sizeof(jk_context_item_t *) * c->capacity);
   
  -		if (cbase) 
  -			if (! strcmp(l->contexts[i]->cbase, cbase))
  -				return (l->contexts[i]);
  -	}
  +        c->contexts = contexts;
  +        c->capacity = capacity;
  +    }
   
  -	return NULL;
  +    return JK_TRUE;
   }
   
   /*
  - * Context Memory Managment
  + * Ensure there will be memory in context info to URIS
    */
  -
  -static int context_realloc(jk_context_t *c)
  + 
  +static int context_item_realloc(jk_context_t *c, jk_context_item_t *ci)
   {
  -    if (c->size == c->capacity) {
  -        char **uris;
  -        int  capacity = c->capacity + CONTEXT_INC_SIZE;
  +    if (ci->size == ci->capacity) {
  +            char **uris;
  +            int capacity = ci->capacity + URI_INC_SIZE;
   
  -        uris = (char **)jk_pool_alloc(&c->p, sizeof(char *) * capacity);
  +            uris = (char **)jk_pool_alloc(&c->p, sizeof(char *) * capacity);
   
           if (! uris)
  -			return JK_FALSE;
  +            return JK_FALSE;
   
  -		memcpy(uris, c->uris, sizeof(char *) * c->capacity);
  +        memcpy(uris, ci->uris, sizeof(char *) * ci->capacity);
   
  -        c->uris = uris;
  -        c->capacity = capacity;
  +        ci->uris     = uris;
  +        ci->capacity = capacity;
       }
  -
  +    
       return JK_TRUE;
   }
   
  +        
  +/*
  + * 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;
  +}
  +
   /*
  - * Add an URI to context
  + * Locate an URI in a context item
    */
   
  -int  context_add_uri(jk_context_t *c, char * uri)
  +char * context_item_find_uri(jk_context_item_t *ci, char *uri)
   {
       int i;
   
  -    if (! c || ! uri)
  -        return JK_FALSE;
  +    if (! ci || ! uri)
  +        return NULL;
   
  -	for (i = 0 ; i < c->size ; i++) {
  -		if (! strcmp(c->uris[i], uri)) {
  -                return JK_TRUE;
  -            }
  -        }
  +    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);
   
  -	context_realloc(c);
  +    if (! ci)
  +        return;
   
  -	if (c->size >= c->capacity) 
  -		return JK_FALSE;
  +    for (i = 0; i < ci->size; i++)
  +        fprintf(f, "/%s/%s\n", ci->cbase, ci->uris[i]);
   
  -	c->uris[c->size] = jk_pool_strdup(&c->p, uri);
  -	c->size++;
  -	return JK_TRUE;
  +    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;
  +    int                  i;
  +
  +    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 *)jk_pool_alloc(&c->p, sizeof(jk_context_item_t));
  +
  +    if (! ci)
  +        return NULL;
  +
  +    c->contexts[c->size] = ci;
  +    c->size++;
  +    ci->cbase       = jk_pool_strdup(&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] = jk_pool_strdup(&c->p, uri);
  +
  +    if (ci->uris[ci->size] == NULL)
  +        return JK_FALSE;
  +
  +    ci->size++;
  +    return JK_TRUE;
  +}
   
  
  
  
  1.4       +69 -55    jakarta-tomcat-connectors/jk/native/common/jk_context.h
  
  Index: jk_context.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_context.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- jk_context.h	2001/06/18 14:15:39	1.3
  +++ jk_context.h	2001/06/29 14:55:22	1.4
  @@ -58,7 +58,7 @@
   /***************************************************************************
    * Description: Context Stuff (Autoconf)                                   *
    * Author:      Henri Gomez <hgomez@slib.fr>                               *
  - * Version:     $Revision: 1.3 $                                           *
  + * Version:     $Revision: 1.4 $                                           *
    ***************************************************************************/
   #ifndef JK_CONTEXT_H
   #define JK_CONTEXT_H
  @@ -69,90 +69,104 @@
   extern "C" {
   #endif /* __cplusplus */
   
  -#define CONTEXT_INC_SIZE (50)
  +#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 */
   
   typedef struct {
   
  -	/*
  -	 * Memory Pool
  -	 */
  +    /*
  +     * Context base (ie examples) 
  +     */
  + 
  +    char *      cbase;
  + 
  +    /*
  +     * Status (Up/Down)
  +     */
  + 
  +    int         status;
  +
  +    /*
  +     * Num of URI handled 
  +     */
  +    
  +    int         size;
  +
  +    /*
  +     * Capacity
  +     */
  +   
  +    int         capacity;
  +
  +    /*
  +     * URL/URIs (autoconf)
  +     */
   
  -	jk_pool_t 		p;
  -	jk_pool_atom_t	buf[SMALL_POOL_SIZE];
  +    char **     uris;
  +}
  +jk_context_item_t;
   
  -	/*
  -	 * Virtual Server (if use)
  -	 */
   
  -	char *		virtual;
  +typedef struct {
   
  -	/*
  -	 * Context base (ie examples)
  -	 */
  +    /*
  +     * Memory Pool
  +     */
   
  -	char *		cbase;
  +    jk_pool_t       p;
  +    jk_pool_atom_t  buf[SMALL_POOL_SIZE];
   
   	/*
  -	 * Status (Up/Down)
  +	 * Virtual Server (if use)
   	 */
   
  -	int			status;
  +	char *		            virtual;
   
  -	/*
  -	 * Num of URI handled 
  -	 */
  -	
  -	int			size;
  +    /*
  +     * Num of context handled (ie: examples, admin...)
  +     */
   
  -	/*
  -	 * Capacity
  -	 */
  -	
  -	int			capacity;
  +    int                     size;
   
  -	/*
  -	 * URL/URIs (autoconf)
  -	 */
  +    /*
  +     * Capacity
  +     */
   
  -	char ** 	uris;
  +    int                     capacity; 
  +
  +    /*
  +     * Context list, context / URIs
  +     */
  +
  +    jk_context_item_t **    contexts;
   } 
   jk_context_t;
   
   
  -typedef struct {
  +/*
  + * functions defined here 
  + */
   
  -	/*
  -	 * Context List 
  -	 */
  +int context_set_virtual(jk_context_t *c, char *virtual);
   
  -	jk_context_t	**contexts;
  +int context_open(jk_context_t *c, char *virtual);
   
  -	/*
  -	 * Num of Contextes
  -	 */
  -	
  -	int				ncontext;
  -}
  -jk_context_list_t;
  +int context_close(jk_context_t *c);
   
  -/*
  - * functions defined here 
  - */
  +int context_alloc(jk_context_t **c, char *virtual);
  +
  +int context_free(jk_context_t **c);
   
  -int 			context_open(jk_context_t *c);
  +jk_context_item_t *context_find_base(jk_context_t *c, char *cbase);
   
  -int 			context_alloc(jk_context_t **c);
  +char *context_item_find_uri(jk_context_item_t *ci, char *uri);
   
  -int 			context_close(jk_context_t *c);
  +void context_dump_uris(jk_context_t *c, char *cbase, FILE *f);
   
  -int 			context_free(jk_context_t **c);
  +jk_context_item_t *context_add_base(jk_context_t *c, char *cbase);
   
  -jk_context_t *	context_find(jk_context_list_t *l,
  -							 char * virtual,
  -							 char * cbase);
  +int context_add_uri(jk_context_t *c, char *cbase, char *uri);
   
  -int				context_add_uri(jk_context_t *c, 
  -								char * uri);
   
   #ifdef __cplusplus
   }
  
  
  

Mime
View raw message