httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@hyperreal.org
Subject cvs commit: apache-1.3/src/modules/standard mod_autoindex.c
Date Mon, 03 May 1999 19:05:23 GMT
coar        99/05/03 12:05:19

  Modified:    src      CHANGES
               src/modules/standard mod_autoindex.c
  Log:
  	Rip loose another piece of mod_autoindex's configuration hairball,
  	breaking the description handling free from the path/filename
  	paradigm used for most of the stuff.  Make AddDescription work
  	as documented.
  
  PR:		1898, 3072
  
  Revision  Changes    Path
  1.1342    +3 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1341
  retrieving revision 1.1342
  diff -u -r1.1341 -r1.1342
  --- CHANGES	1999/05/03 15:09:04	1.1341
  +++ CHANGES	1999/05/03 19:05:11	1.1342
  @@ -1,5 +1,8 @@
   Changes with Apache 1.3.7
   
  +  *) Modify mod_autoindex's handling of AddDescription so that the
  +     behaviour matches the documentation.  [Ken Coar] PR#1898, 3072.
  +
     *) Add functionality to the install-bindist.sh script created by
        binbuild.sh to use tar when copying distribution files to the
        serverroot. This allows upgrading an existing installation
  
  
  
  1.105     +76 -6     apache-1.3/src/modules/standard/mod_autoindex.c
  
  Index: mod_autoindex.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- mod_autoindex.c	1999/05/01 17:13:04	1.104
  +++ mod_autoindex.c	1999/05/03 19:05:17	1.105
  @@ -72,6 +72,7 @@
   #include "http_log.h"
   #include "http_main.h"
   #include "util_script.h"
  +#include "fnmatch.h"
   
   module MODULE_VAR_EXPORT autoindex_module;
   
  @@ -131,6 +132,12 @@
       char *data;
   };
   
  +typedef struct ai_desc_t {
  +    char *pattern;
  +    char *description;
  +    int full_path;
  +} ai_desc_t;
  +
   typedef struct autoindex_config_struct {
   
       char *default_icon;
  @@ -143,8 +150,12 @@
       int icon_height;
       char *default_order;
   
  -    array_header *icon_list, *alt_list, *desc_list, *ign_list;
  -    array_header *hdr_list, *rdme_list;
  +    array_header *icon_list;
  +    array_header *alt_list;
  +    array_header *desc_list;
  +    array_header *ign_list;
  +    array_header *hdr_list;
  +    array_header *rdme_list;
   
   } autoindex_config_rec;
   
  @@ -257,10 +268,31 @@
       return NULL;
   }
   
  +/*
  + * Add description text for a filename pattern.  Prefix the pattern
  + * with a wildcard unless it begins with '/' signifying an absolute
  + * path.  If the pattern contains a '/' anywhere, add a slash to the
  + * prefix so that "bar/bletch" won't be matched by "foobar/bletch",
  + * and make a note that there's a delimiter; the matching routine
  + * simplifies to just the actual filename whenever it can.  This allows
  + * definitions in parent directories to be made for files in subordinate
  + * ones using relative paths.  Always postfix with a wildard so that
  + * partial or leading names will match.
  + */
   static const char *add_desc(cmd_parms *cmd, void *d, char *desc, char *to)
   {
  -    push_item(((autoindex_config_rec *) d)->desc_list, cmd->info, to,
  -	      cmd->path, desc);
  +    autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
  +    ai_desc_t *desc_entry;
  +    char *prefix = "";
  +
  +    desc_entry = (ai_desc_t *) ap_push_array(dcfg->desc_list);
  +    desc_entry->full_path = (strchr(to, '/') == NULL) ? 0 : 1;
  +    if (*to != '/') {
  +	prefix = desc_entry->full_path ? "*/" : "*";
  +    }
  +    desc_entry->pattern = ap_pstrcat(dcfg->desc_list->pool,
  +				     prefix, to, "*", NULL);
  +    desc_entry->description = ap_pstrdup(dcfg->desc_list->pool, desc);
       return NULL;
   }
   
  @@ -530,7 +562,7 @@
       new->name_adjust = K_UNSET;
       new->icon_list = ap_make_array(p, 4, sizeof(struct item));
       new->alt_list = ap_make_array(p, 4, sizeof(struct item));
  -    new->desc_list = ap_make_array(p, 4, sizeof(struct item));
  +    new->desc_list = ap_make_array(p, 4, sizeof(ai_desc_t));
       new->ign_list = ap_make_array(p, 4, sizeof(struct item));
       new->hdr_list = ap_make_array(p, 4, sizeof(struct item));
       new->rdme_list = ap_make_array(p, 4, sizeof(struct item));
  @@ -688,7 +720,6 @@
   
   #define find_icon(d,p,t) find_item(p,d->icon_list,t)
   #define find_alt(d,p,t) find_item(p,d->alt_list,t)
  -#define find_desc(d,p) find_item(p,d->desc_list,0)
   #define find_header(d,p) find_item(p,d->hdr_list,0)
   #define find_readme(d,p) find_item(p,d->rdme_list,0)
   
  @@ -705,6 +736,45 @@
       r.content_type = r.content_encoding = NULL;
   
       return find_item(&r, d->icon_list, 1);
  +}
  +
  +/*
  + * Look through the list of pattern/description pairs and return the first one
  + * if any) that matches the filename in the request.  If multiple patterns
  + * match, only the first one is used; since the order in the array is the
  + * same as the order in which directives were processed, earlier matching
  + * directives will dominate.
  + */
  +static char *find_desc(autoindex_config_rec *dcfg, request_rec *r)
  +{
  +    int i;
  +    ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
  +    const char *filename_full = r->filename;
  +    const char *filename_only;
  +    const char *filename;
  +
  +    /*
  +     * If the filename includes a path, extract just the name itself
  +     * for the simple matches.
  +     */
  +    if ((filename_only = strrchr(filename_full, '/')) == NULL) {
  +	filename_only = filename_full;
  +    }
  +    else {
  +	filename_only++;
  +    }
  +    for (i = 0; i < dcfg->desc_list->nelts; ++i) {
  +	ai_desc_t *tuple = &list[i];
  +
  +	/*
  +	 * Only use the full-path filename if the pattern contains '/'s.
  +	 */
  +	filename = (tuple->full_path) ? filename_full : filename_only;
  +	if (ap_fnmatch(tuple->pattern, filename, 0) == 0) {
  +	    return tuple->description;
  +	}
  +    }
  +    return NULL;
   }
   
   static int ignore_entry(autoindex_config_rec *d, char *path)
  
  
  

Mime
View raw message