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

  Modified:    jk/native2/common jk_logger_file.c jk_map.c
  Log:
  Updates, use pools, etc.
  
  Revision  Changes    Path
  1.5       +7 -6      jakarta-tomcat-connectors/jk/native2/common/jk_logger_file.c
  
  Index: jk_logger_file.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_logger_file.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jk_logger_file.c	2001/12/04 19:11:56	1.4
  +++ jk_logger_file.c	2001/12/06 22:59:52	1.5
  @@ -59,7 +59,7 @@
    * Description: Utility functions (mainly configuration)                   *
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
    * Author:      Henri Gomez <hgomez@slib.fr>                               *
  - * Version:     $Revision: 1.4 $                                           *
  + * Version:     $Revision: 1.5 $                                           *
    ***************************************************************************/
   
   #include "jk_env.h"
  @@ -72,8 +72,8 @@
   #define HUGE_BUFFER_SIZE (8*1024)
   #define LOG_LINE_SIZE    (1024)
   
  -int JK_METHOD jk_logger_file_factory(jk_env_t *env, void **result,
  -                                     char *type, char *name);
  +int JK_METHOD jk_logger_file_factory(jk_env_t *env, jk_pool_t *pool, void **result,
  +                                     const char *type, const char *name);
   
   
   /* 
  @@ -260,11 +260,12 @@
   
   
   int jk_logger_file_factory(jk_env_t *env,
  +                           jk_pool_t *pool, 
                              void **result,
  -                           char *type,
  -                           char *name)
  +                           const char *type,
  +                           const char *name)
   {
  -    jk_logger_t *l = (jk_logger_t *)malloc(sizeof(jk_logger_t));
  +    jk_logger_t *l = (jk_logger_t *)pool->alloc(pool, sizeof(jk_logger_t));
   
       if(l==NULL ) {
           return JK_FALSE;
  
  
  
  1.5       +121 -110  jakarta-tomcat-connectors/jk/native2/common/jk_map.c
  
  Index: jk_map.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_map.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- jk_map.c	2001/12/05 20:48:20	1.4
  +++ jk_map.c	2001/12/06 22:59:52	1.5
  @@ -58,7 +58,7 @@
   /***************************************************************************
    * Description: General purpose map object                                 *
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
  - * Version:     $Revision: 1.4 $                                           *
  + * Version:     $Revision: 1.5 $                                           *
    ***************************************************************************/
   
   #include "jk_global.h"
  @@ -70,8 +70,7 @@
   #define LENGTH_OF_LINE    (1024)
   
   struct jk_map {
  -    jk_pool_t p;
  -    jk_pool_atom_t buf[SMALL_POOL_SIZE];
  +    jk_pool_t *pool;
   
       const char **names;
       const void **values;
  @@ -84,53 +83,39 @@
   static int trim(char *s);
   static int map_realloc(jk_map_t *m);
   
  -int map_alloc(jk_map_t **m)
  +int map_alloc(jk_map_t **m, jk_pool_t *pool )
   {
  -    if(m) {
  -        return map_open(*m = (jk_map_t *)malloc(sizeof(jk_map_t)));
  -    }
  -    
  -    return JK_FALSE;
  -}
  -
  -int map_free(jk_map_t **m)
  -{
  -    int rc = JK_FALSE;
  +    jk_map_t *_this;
   
  -    if(m && *m) {
  -        map_close(*m);  
  -        free(*m);
  -        *m = NULL;
  -    }
  +    if( m== NULL )
  +        return JK_FALSE;
       
  -    return rc;
  -}
  -
  -int map_open(jk_map_t *m)
  -{
  -    int rc = JK_FALSE;
  +    _this=(jk_map_t *)pool->alloc(pool, sizeof(jk_map_t));
  +    *m=_this;
   
  -    if(m) {
  -        jk_open_pool(&m->p, m->buf, sizeof(jk_pool_atom_t) * SMALL_POOL_SIZE);
  -        m->capacity = 0;
  -        m->size     = 0;
  -        m->names    = NULL;
  -        m->values   = NULL;
  -        rc = JK_TRUE;
  -    }
  +    if( _this == NULL )
  +        return JK_FALSE;
       
  -    return rc;
  +    _this->pool = pool;
  +    
  +    _this->capacity = 0;
  +    _this->size     = 0;
  +    _this->names    = NULL;
  +    _this->values   = NULL;
  +
  +    return JK_TRUE;
   }
   
  -int map_close(jk_map_t *m)
  +int map_free(jk_map_t **m)
   {
       int rc = JK_FALSE;
   
  -    if(m) {
  -        m->p.close(&m->p);
  +    if(m && *m) {
  +        (*m)->pool->close((*m)->pool);
           rc = JK_TRUE;
  +        /*  free(*m); */
  +        *m = NULL;
       }
  -    
       return rc;
   }
   
  @@ -204,49 +189,53 @@
   }
   
   char **map_get_string_list(jk_map_t *m,
  +                           jk_pool_t *pool,
                              const char *name,
                              unsigned *list_len,
                              const char *def)
   {
  -    char *l = map_get_string(m, name, def);
  +    char *listStr = map_get_string(m, name, def);
       char **ar = NULL;
  +    unsigned capacity = 0;
  +    unsigned idex = 0;    
  +    char *v;
  +    char *l;
   
  +    if( pool == NULL )
  +        pool=m->pool;
  +    
       *list_len = 0;
   
  -    if(l) {
  -        unsigned capacity = 0;
  -        unsigned idex = 0;    
  -        char *v = m->p.pstrdup(&m->p, l);
  -        
  -        if(!v) {
  -            return NULL;
  -        }
  +    if(listStr==NULL)
  +        return NULL;
   
  -        /*
  -         * GS, in addition to VG's patch, we now need to 
  -         * strtok also by a "*"
  -         */
  -
  -        for(l = strtok(v, " \t,*") ; 
  -            l ; 
  -            l = strtok(NULL, " \t,*")) {
  -        
  -            if(idex == capacity) {
  -                ar = m->p.realloc(&m->p, 
  -                                     sizeof(char *) * (capacity + 5),
  -                                     ar,
  -                                     sizeof(char *) * capacity);
  -                if(!ar) {
  -                    return JK_FALSE;
  -                }
  -                capacity += 5;
  +    v = pool->pstrdup( pool, listStr);
  +    
  +    if(v==NULL) {
  +        return NULL;
  +    }
  +
  +    /*
  +     * GS, in addition to VG's patch, we now need to 
  +     * strtok also by a "*"
  +     */
  +
  +    for(l = strtok(v, " \t,*") ; l ; l = strtok(NULL, " \t,*")) {
  +        if(idex == capacity) {
  +            ar = pool->realloc(pool, 
  +                               sizeof(char *) * (capacity + 5),
  +                               ar,
  +                               sizeof(char *) * capacity);
  +            if(!ar) {
  +                return NULL;
               }
  -            ar[idex] = m->p.pstrdup(&m->p, l);
  -            idex ++;
  +            capacity += 5;
           }
  -        
  -        *list_len = idex;
  +        ar[idex] = pool->pstrdup(pool, l);
  +        idex ++;
       }
  +        
  +    *list_len = idex;
   
       return ar;
   }
  @@ -257,32 +246,33 @@
               void **old)
   {
       int rc = JK_FALSE;
  -
  -    if(m && name ) {
  -        unsigned i;
  -        for(i = 0 ; i < m->size ; i++) {
  -            if(0 == strcmp(m->names[i], name)) {
  -                break;
  -            }
  -        }
  +    int i;
   
  -        if(i < m->size) {
  -            if( old!=NULL )
  -                *old = (void *) m->values[i]; /* DIRTY */
  -            m->values[i] = value;
  -            rc = JK_TRUE;
  -        } else {
  -            map_realloc(m);
  +    if(m==NULL ||  name==NULL )
  +        return JK_FALSE;
   
  -            if(m->size < m->capacity) {
  -                m->values[m->size] = value;
  -                m->names[m->size] = m->p.pstrdup(&m->p, name);
  -                m->size ++;
  -                rc = JK_TRUE;
  -            }
  -        }       
  +    for(i = 0 ; i < m->size ; i++) {
  +        if(0 == strcmp(m->names[i], name)) {
  +            break;
  +        }
       }
   
  +    /* Old value found */
  +    if(i < m->size) {
  +        if( old!=NULL )
  +            *old = (void *) m->values[i]; /* DIRTY */
  +        m->values[i] = value;
  +        return JK_TRUE;
  +    }
  +    
  +    map_realloc(m);
  +    
  +    if(m->size < m->capacity) {
  +        m->values[m->size] = value;
  +        m->names[m->size] = m->pool->pstrdup(m->pool, name);
  +        m->size ++;
  +        rc = JK_TRUE;
  +    }
       return rc;
   }
   
  @@ -292,13 +282,13 @@
   int jk_is_some_property(const char *prp_name, const char *suffix)
   {
       if (prp_name && suffix) {
  -		size_t prp_name_len = strlen(prp_name);
  -		size_t suffix_len = strlen(suffix);
  -		if (prp_name_len >= suffix_len) {
  -			const char *prp_suffix = prp_name + prp_name_len - suffix_len;
  -			if(0 == strcmp(suffix, prp_suffix)) {
  -		        return JK_TRUE;
  -			}
  +        size_t prp_name_len = strlen(prp_name);
  +        size_t suffix_len = strlen(suffix);
  +        if (prp_name_len >= suffix_len) {
  +            const char *prp_suffix = prp_name + prp_name_len - suffix_len;
  +            if(0 == strcmp(suffix, prp_suffix)) {
  +                return JK_TRUE;
  +            }
           }
       }
   
  @@ -331,8 +321,8 @@
                               v = map_replace_properties(v, m);
   
                               if(oldv) {
  -                                char *tmpv = m->p.alloc(&m->p, 
  -                                                        strlen(v) + strlen(oldv) + 3);
  +                                char *tmpv = m->pool->alloc(m->pool, 
  +                                                            strlen(v) + strlen(oldv) +
3);
                                   if(tmpv) {
                                       char sep = '*';
                                       if(jk_is_some_property(prp, "path")) {
  @@ -346,8 +336,9 @@
                                   }                                
                                   v = tmpv;
                               } else {
  -                                v = m->p.pstrdup(&m->p, v);
  +                                v = m->pool->pstrdup(m->pool, v);
                               }
  +                            
                               if(v) {
                                   void *old = NULL;
                                   map_put(m, prp, v, &old);
  @@ -431,8 +422,8 @@
           void **values;
           int  capacity = m->capacity + CAPACITY_INC_SIZE;
   
  -        names = (char **)m->p.alloc(&m->p, sizeof(char *) * capacity);
  -        values = (void **)m->p.alloc(&m->p, sizeof(void *) * capacity);
  +        names = (char **)m->pool->alloc(m->pool, sizeof(char *) * capacity);
  +        values = (void **)m->pool->alloc(m->pool, sizeof(void *) * capacity);
           
           if(values && names) {
               if (m->capacity && m->names) 
  @@ -479,8 +470,8 @@
   	    }
               if(env_value) {
                   int offset=0;
  -                char *new_value = m->p.alloc(&m->p, 
  -                                                (sizeof(char) * (strlen(rc) + strlen(env_value))));
  +                char *new_value = m->pool->alloc(m->pool, 
  +                                                 (sizeof(char) * (strlen(rc) + strlen(env_value))));
                   if(!new_value) {
                       break;
                   }
  @@ -566,10 +557,10 @@
   }
   
   char **map_getListProp(jk_map_t *m,
  -                    const char *objType,
  -                    const char *objName,
  -                    const char *pname, 
  -                    unsigned *size)
  +                       const char *objType,
  +                       const char *objName,
  +                       const char *pname, 
  +                       unsigned *size)
   {
       char buf[1024];
   
  @@ -581,7 +572,27 @@
       }
   
       sprintf(buf, "%s.%s.%s", objType, objName, pname);
  +
  +    return map_get_string_list(m, m->pool, buf, size, NULL);
  +}
   
  -    return map_get_string_list(m, buf, size, NULL);
  +/** Utility - copy a map . XXX Should move to jk_map, it's generic code.
  + */
  +int map_copy(jk_pool_t *pool, jk_map_t * src, jk_map_t * dst )
  +{   
  +    int sz = map_size(src);
  +    int i;
  +    for(i = 0 ; i < sz ; i++) {
  +        void *old;
  +        char *name = map_name_at(src, i);
  +        if(map_get(src, name, NULL) == NULL) {
  +            if(!map_put(dst, name, 
  +                        pool->pstrdup(pool, map_get_string(src, name, NULL)), 
  +                        &old)) {
  +                return JK_FALSE;
  +            }
  +        } 
  +    }
  +    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