tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/include jk_map.h
Date Sat, 18 May 2002 22:34:01 GMT
nacho       02/05/18 15:34:01

  Modified:    jk/native2/common jk_config.c jk_map.c
               jk/native2/include jk_map.h
  Log:
  * Refactored reading of properties files into map object, this way arbitrary properties
files can be read, need for i_r2.dll
  
  Revision  Changes    Path
  1.19      +2 -141    jakarta-tomcat-connectors/jk/native2/common/jk_config.c
  
  Index: jk_config.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_config.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- jk_config.c	16 May 2002 21:03:44 -0000	1.18
  +++ jk_config.c	18 May 2002 22:34:01 -0000	1.19
  @@ -58,7 +58,7 @@
   /***************************************************************************
    * Description: General purpose config object                                 *
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
  - * Version:     $Revision: 1.18 $                                           *
  + * Version:     $Revision: 1.19 $                                           *
    ***************************************************************************/
   
   #include "jk_global.h"
  @@ -69,11 +69,6 @@
   #define CAPACITY_INC_SIZE (50)
   #define LENGTH_OF_LINE    (1024)
   
  -int jk2_config_read(struct jk_env *env, struct jk_config *cfg,
  -                    struct jk_map *map);
  -static void jk2_trim_prp_comment(char *prp);
  -static int  jk2_trim(char *s);
  -
   static int jk2_config_readFile(jk_env_t *env,
                                            jk_config_t *cfg,
                                            int *didReload, int firstTime);
  @@ -359,113 +354,6 @@
   
   
   
  -/* ==================== */
  -/*  Reading / parsing. 
  - */
  -int jk2_config_parseProperty(jk_env_t *env, jk_config_t *cfg, jk_map_t *m, char *prp )
  -{
  -    int rc = JK_ERR;
  -    char *v;
  -    jk_map_t *prefNode=NULL;
  -
  -    jk2_trim_prp_comment(prp);
  -    
  -    if( jk2_trim(prp)==0 )
  -        return JK_OK;
  -
  -    /* Support windows-style 'sections' - for cleaner config
  -     */
  -    if( prp[0] == '[' ) {
  -        v=strchr(prp, ']' );
  -        *v='\0';
  -        jk2_trim( v );
  -        prp++;
  -        
  -        cfg->section=cfg->pool->pstrdup(env, m->pool, prp);
  -
  -        jk2_map_default_create( env, &prefNode, m->pool );
  -
  -        m->add( env, m, cfg->section, prefNode);
  -
  -        return JK_OK;
  -    }
  -    
  -    v = strchr(prp, '=');
  -    if(v==NULL)
  -        return JK_OK;
  -        
  -    *v = '\0';
  -    v++;                        
  -
  -    if(strlen(v)==0 || strlen(prp)==0)
  -        return JK_OK;
  -
  -    prefNode=m->get( env, m, cfg->section);
  -    
  -    if( prefNode==NULL )
  -        return JK_ERR;
  -
  -    /* fprintf(stderr, "Adding [%s] %s=%s\n", cfg->section, prp, v ); */
  -    prefNode->add( env, prefNode, m->pool->pstrdup(env, m->pool, prp),
  -                   m->pool->pstrdup(env, m->pool, v));
  -
  -    return JK_OK;
  -}
  -
  -/** Read a query string into the map
  - */
  -int jk2_config_queryRead(jk_env_t *env, jk_config_t *cfg, jk_map_t *m, const char *query)
  -{
  -    char *sep;
  -    char *value;
  -    char *qry=cfg->pool->pstrdup( env, cfg->pool, query );
  -
  -    while( qry != NULL ) {
  -        sep=strchr( qry, '&');
  -        if( sep !=NULL ) { 
  -            *sep='\0';
  -            sep++;
  -        }
  -
  -        value = strchr(qry, '=');
  -        if(value==NULL) {
  -            value="";
  -        } else {
  -            *value = '\0';
  -            value++;
  -        }
  -        m->add( env, m, cfg->pool->pstrdup( env, cfg->pool, qry ),
  -                cfg->pool->pstrdup( env, cfg->pool, value ));
  -        qry=sep;
  -    }
  -    return JK_OK;
  -}
  -
  -/** Read the config file
  - */
  -int jk2_config_read(jk_env_t *env, jk_config_t *cfg, jk_map_t *m)
  -{
  -    FILE *fp;
  -    char buf[LENGTH_OF_LINE + 1];            
  -    char *prp;
  -    char *f=cfg->file;
  -        
  -    if(m==NULL || f==NULL )
  -        return JK_ERR;
  -
  -    fp= fopen(f, "r");
  -        
  -    if(fp==NULL)
  -        return JK_ERR;
  -
  -    cfg->section=NULL;
  -    while(NULL != (prp = fgets(buf, LENGTH_OF_LINE, fp))) {
  -        jk2_config_parseProperty( env, cfg, m, prp );
  -    }
  -
  -    fclose(fp);
  -    return JK_OK;
  -}
   
   
   
  @@ -667,7 +555,7 @@
       
       jk2_map_default_create(env, &cfgData, env->tmpPool);
   
  -    rc=jk2_config_read(env, cfg, cfgData );
  +    rc=jk2_map_read(env, cfgData , cfg->file );
       
       if( rc==JK_OK ) {
           env->l->jkLog(env, env->l, JK_LOG_INFO, 
  @@ -722,33 +610,6 @@
       return JK_OK;
   }
   
  -
  -static void jk2_trim_prp_comment(char *prp)
  -{
  -    char *comment = strchr(prp, '#');
  -    if(comment) {
  -        *comment = '\0';
  -    }
  -}
  -
  -static int jk2_trim(char *s)
  -{
  -    int i;
  -
  -    for(i = strlen(s) - 1 ; (i >= 0) && isspace(s[i]) ;  i--)
  -        ;
  -    
  -    s[i + 1] = '\0';
  -    
  -    for(i = 0 ; ('\0' !=  s[i]) && isspace(s[i]) ; i++)
  -        ;
  -    
  -    if(i > 0) {
  -        strcpy(s, &s[i]);
  -    }
  -
  -    return strlen(s);
  -}
   
   int JK_METHOD jk2_config_factory( jk_env_t *env, jk_pool_t *pool,
                           jk_bean_t *result,
  
  
  
  1.19      +146 -1    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- jk_map.c	25 Apr 2002 19:16:14 -0000	1.18
  +++ jk_map.c	18 May 2002 22:34:01 -0000	1.19
  @@ -58,7 +58,7 @@
   /***************************************************************************
    * Description: General purpose map object                                 *
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
  - * Version:     $Revision: 1.18 $                                           *
  + * Version:     $Revision: 1.19 $                                           *
    ***************************************************************************/
   
   #include "jk_global.h"
  @@ -79,6 +79,9 @@
   
   static int  jk2_map_default_realloc(jk_env_t *env, jk_map_t *m);
   
  +
  +
  +
   static void *jk2_map_default_get(jk_env_t *env, jk_map_t *m,
                                    const char *name)
   {
  @@ -239,6 +242,148 @@
       return JK_OK;
   }
                                  
  +
  +/* ==================== */
  +/*  Reading / parsing. 
  + */
  +
  +static void jk2_trim_prp_comment(char *prp)
  +{
  +    char *comment = strchr(prp, '#');
  +    if(comment) {
  +        *comment = '\0';
  +    }
  +}
  +
  +static int jk2_trim(char *s)
  +{
  +    int i;
  +
  +    for(i = strlen(s) - 1 ; (i >= 0) && isspace(s[i]) ;  i--)
  +        ;
  +    
  +    s[i + 1] = '\0';
  +    
  +    for(i = 0 ; ('\0' !=  s[i]) && isspace(s[i]) ; i++)
  +        ;
  +    
  +    if(i > 0) {
  +        strcpy(s, &s[i]);
  +    }
  +
  +    return strlen(s);
  +}
  +
  +
  +
  +int jk2_map_parseProperty(jk_env_t *env, jk_map_t *m, char **section, char *prp )
  +{
  +    int rc = JK_ERR;
  +    char *v;
  +    jk_map_t *prefNode=NULL;
  +
  +    jk2_trim_prp_comment(prp);
  +    
  +    if( jk2_trim(prp)==0 )
  +        return JK_OK;
  +
  +    /* Support windows-style 'sections' - for cleaner config
  +     */
  +    if( (prp[0] == '[') ) {
  +        v=strchr(prp, ']' );
  +        *v='\0';
  +        jk2_trim( v );
  +        prp++;
  +        
  +        *section=m->pool->pstrdup(env, m->pool, prp);
  +
  +        jk2_map_default_create( env, &prefNode, m->pool );
  +
  +        m->add( env, m, *section, prefNode);
  +
  +        return JK_OK;
  +    }
  +    
  +    v = strchr(prp, '=');
  +    if(v==NULL)
  +        return JK_OK;
  +        
  +    *v = '\0';
  +    v++;                        
  +
  +    if(strlen(v)==0 || strlen(prp)==0)
  +        return JK_OK;
  +
  +    if (*section!=NULL){
  +        prefNode=m->get( env, m, *section);
  +    }else{
  +        prefNode=m;
  +    }
  +    
  +    if( prefNode==NULL )
  +        return JK_ERR;
  +
  +    /* fprintf(stderr, "Adding [%s] %s=%s\n", cfg->section, prp, v ); */
  +    prefNode->add( env, prefNode, m->pool->pstrdup(env, m->pool, prp),
  +                   m->pool->pstrdup(env, m->pool, v));
  +
  +    return JK_OK;
  +}
  +
  +/** Read a query string into the map
  + */
  +int jk2_map_queryRead(jk_env_t *env, jk_map_t *m, const char *query)
  +{
  +    char *sep;
  +    char *value;
  +    char *qry=m->pool->pstrdup( env, m->pool, query );
  +
  +    while( qry != NULL ) {
  +        sep=strchr( qry, '&');
  +        if( sep !=NULL ) { 
  +            *sep='\0';
  +            sep++;
  +        }
  +
  +        value = strchr(qry, '=');
  +        if(value==NULL) {
  +            value="";
  +        } else {
  +            *value = '\0';
  +            value++;
  +        }
  +        m->add( env, m, m->pool->pstrdup( env, m->pool, qry ),
  +                m->pool->pstrdup( env, m->pool, value ));
  +        qry=sep;
  +    }
  +    return JK_OK;
  +}
  +
  +/** Read the config file
  + */
  +int jk2_map_read(jk_env_t *env, jk_map_t *m,const char *file)
  +{
  +    FILE *fp;
  +    char buf[LENGTH_OF_LINE + 1];            
  +    char *prp;
  +    char *section=NULL;
  +    if(m==NULL || file==NULL )
  +        return JK_ERR;
  +
  +    fp= fopen(file, "r");
  +        
  +    if(fp==NULL)
  +        return JK_ERR;
  +
  +    while(NULL != (prp = fgets(buf, LENGTH_OF_LINE, fp))) {
  +        jk2_map_parseProperty( env, m, &section, prp );
  +    }
  +
  +    fclose(fp);
  +    return JK_OK;
  +}
  +
  +
   /* ==================== */
   /* Internal utils */
   
  
  
  
  1.14      +2 -1      jakarta-tomcat-connectors/jk/native2/include/jk_map.h
  
  Index: jk_map.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/include/jk_map.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- jk_map.h	1 May 2002 23:10:17 -0000	1.13
  +++ jk_map.h	18 May 2002 22:34:01 -0000	1.14
  @@ -58,7 +58,7 @@
   /***************************************************************************
    * Description: Map object header file                                     *
    * Author:      Gal Shachor <shachor@il.ibm.com>                           *
  - * Version:     $Revision: 1.13 $                                           *
  + * Version:     $Revision: 1.14 $                                           *
    ***************************************************************************/
   
   #ifndef JK_MAP_H
  @@ -129,6 +129,7 @@
   int jk2_map_default_create(struct jk_env *env, jk_map_t **m, 
                             struct jk_pool *pool); 
   
  +int jk2_map_read(struct jk_env *env, jk_map_t *m,const char *file);
       
   #ifdef __cplusplus
   }
  
  
  

--
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