####################################################################
# Apache 1.3.9 mod_autoindex patch for configurable text, link and #
# background colors in directory listings.                         #
####################################################################

Copyright (C) 1999 Axel Beckert <axel@dagstuhl.de>

This patch is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This patch is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this patch; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

You can reach the author by snail-mail at the following address:

Axel Beckert
Saarbrücker Straße 267a
D-66125 Saarbrücken, Germany

Index: mod_autoindex.c

*** mod_autoindex.c	Thu Dec  9 23:48:50 1999
--- mod_autoindex.mod.c	Thu Dec  9 23:48:50 1999
***************
*** 62,67 ****
--- 62,70 ----
   * 3/23/93
   * 
   * Adapted to Apache by rst.
+  *
+  * Modified by Axel Beckert <axel@dagstuhl.de> 9-Dec-99 for
+  * configurable text, link and background colors.
   */
  
  #include "httpd.h"
***************
*** 76,81 ****
--- 79,94 ----
  
  module MODULE_VAR_EXPORT autoindex_module;
  
+ /* Advertising modified version */
+ 
+ static void modified_startup(server_rec * dummy1, pool * dummy2)
+ {
+ #if !defined(MOD_AUTOINDEX_NO_ADVERTISEMENT)
+     /* advertise the patched autoindex module;-) */
+     ap_add_version_component("mod_autoindex/color");
+ #endif
+ }
+ 
  /****************************************************************
   *
   * Handling configuration directives...
***************
*** 151,156 ****
--- 164,175 ----
      int icon_height;
      char *default_order;
  
+     array_header *bg_color;
+     array_header *text_color;
+     array_header *link_color;
+     array_header *vlink_color;
+     array_header *alink_color;
+ 
      array_header *icon_list;
      array_header *alt_list;
      array_header *desc_list;
***************
*** 190,200 ****
   * We include the DOCTYPE because we may be using features therefrom (i.e.,
   * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
   */
! static void emit_preamble(request_rec *r, char *title)
  {
      ap_rvputs(r, DOCTYPE_HTML_3_2,
  	      "<HTML>\n <HEAD>\n  <TITLE>Index of ", title,
! 	      "</TITLE>\n </HEAD>\n <BODY>\n", NULL);
  }
  
  static void push_item(array_header *arr, char *type, char *to, char *path,
--- 209,242 ----
   * We include the DOCTYPE because we may be using features therefrom (i.e.,
   * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
   */
! static void emit_preamble(request_rec *r, char *title, char *bg, char *text, 
! 			  char *link, char *vlink, char *alink)
  {
+     char *params = "";
+ 
+     if (bg != NULL) {
+         params = ap_pstrcat(r->pool, params, " BGCOLOR=\"", bg, "\"", NULL);
+     }
+ 
+     if (text != NULL) {
+         params = ap_pstrcat(r->pool, params, " TEXT=\"", text, "\"", NULL);
+     }
+ 
+     if (link != NULL) {
+         params = ap_pstrcat(r->pool, params, " LINK=\"", link, "\"", NULL);
+     }
+ 
+     if (vlink != NULL) {
+         params = ap_pstrcat(r->pool, params, " VLINK=\"", vlink, "\"", NULL);
+     }
+ 
+     if (alink != NULL) {
+         params = ap_pstrcat(r->pool, params, " ALINK=\"", alink, "\"", NULL);
+     }
+ 
      ap_rvputs(r, DOCTYPE_HTML_3_2,
  	      "<HTML>\n <HEAD>\n  <TITLE>Index of ", title,
! 	      "</TITLE>\n </HEAD>\n <BODY", params, ">\n", NULL);
  }
  
  static void push_item(array_header *arr, char *type, char *to, char *path,
***************
*** 334,339 ****
--- 376,418 ----
      return NULL;
  }
  
+ /* Colors of directory indexes */
+ 
+ static const char *add_bgcolor(cmd_parms *cmd, void *d, char *name)
+ {
+     push_item(((autoindex_config_rec *) d)->bg_color, 0, NULL, cmd->path,
+ 	      name);
+     return NULL;
+ }
+ 
+ static const char *add_textcolor(cmd_parms *cmd, void *d, char *name)
+ {
+     push_item(((autoindex_config_rec *) d)->text_color, 0, NULL, cmd->path,
+ 	      name);
+     return NULL;
+ }
+ 
+ static const char *add_linkcolor(cmd_parms *cmd, void *d, char *name)
+ {
+     push_item(((autoindex_config_rec *) d)->link_color, 0, NULL, cmd->path,
+ 	      name);
+     return NULL;
+ }
+ 
+ static const char *add_vlinkcolor(cmd_parms *cmd, void *d, char *name)
+ {
+     push_item(((autoindex_config_rec *) d)->vlink_color, 0, NULL, cmd->path,
+ 	      name);
+     return NULL;
+ }
+ 
+ static const char *add_alinkcolor(cmd_parms *cmd, void *d, char *name)
+ {
+     push_item(((autoindex_config_rec *) d)->alink_color, 0, NULL, cmd->path,
+ 	      name);
+     return NULL;
+ }
+ 
  /* A legacy directive, FancyIndexing is superseded by the IndexOptions
   * keyword.  But for compatibility..
   */
***************
*** 555,560 ****
--- 634,649 ----
       "Descriptive text followed by one or more filenames"},
      {"HeaderName", add_header, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
      {"ReadmeName", add_readme, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
+     {"DirectoryIndexTextColor", add_textcolor, NULL, DIR_CMD_PERMS, TAKE1, 
+      "a valid HTML color"},
+     {"DirectoryIndexBGColor", add_bgcolor, NULL, DIR_CMD_PERMS, TAKE1, 
+      "a valid HTML color"},
+     {"DirectoryIndexLinkColor", add_linkcolor, NULL, DIR_CMD_PERMS, TAKE1, 
+      "a valid HTML color"},
+     {"DirectoryIndexVLinkColor", add_vlinkcolor, NULL, DIR_CMD_PERMS, TAKE1, 
+      "a valid HTML color"},
+     {"DirectoryIndexALinkColor", add_alinkcolor, NULL, DIR_CMD_PERMS, TAKE1, 
+      "a valid HTML color"},
      {"FancyIndexing", fancy_indexing, NULL, DIR_CMD_PERMS, FLAG,
       "Limited to 'on' or 'off' (superseded by IndexOptions FancyIndexing)"},
      {"DefaultIcon", ap_set_string_slot,
***************
*** 583,588 ****
--- 672,683 ----
      new->decremented_opts = 0;
      new->default_order = NULL;
  
+     new->bg_color = ap_make_array(p, 4, sizeof(struct item));
+     new->text_color = ap_make_array(p, 4, sizeof(struct item));
+     new->link_color = ap_make_array(p, 4, sizeof(struct item));
+     new->vlink_color = ap_make_array(p, 4, sizeof(struct item));
+     new->alink_color = ap_make_array(p, 4, sizeof(struct item));
+ 
      return (void *) new;
  }
  
***************
*** 598,603 ****
--- 693,704 ----
      new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
      new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
  
+     new->bg_color = ap_append_arrays(p, add->bg_color, base->bg_color);
+     new->text_color = ap_append_arrays(p, add->text_color, base->text_color);
+     new->link_color = ap_append_arrays(p, add->link_color, base->link_color);
+     new->vlink_color = ap_append_arrays(p, add->vlink_color, base->vlink_color);
+     new->alink_color = ap_append_arrays(p, add->alink_color, base->alink_color);
+ 
      new->alt_list = ap_append_arrays(p, add->alt_list, base->alt_list);
      new->ign_list = ap_append_arrays(p, add->ign_list, base->ign_list);
      new->hdr_list = ap_append_arrays(p, add->hdr_list, base->hdr_list);
***************
*** 735,740 ****
--- 836,847 ----
  #define find_header(d,p) find_item(p,d->hdr_list,0)
  #define find_readme(d,p) find_item(p,d->rdme_list,0)
  
+ #define find_bg_color(d,p) find_item(p,d->bg_color,0)
+ #define find_text_color(d,p) find_item(p,d->text_color,0)
+ #define find_link_color(d,p) find_item(p,d->link_color,0)
+ #define find_vlink_color(d,p) find_item(p,d->vlink_color,0)
+ #define find_alink_color(d,p) find_item(p,d->alink_color,0)
+ 
  static char *find_default_icon(autoindex_config_rec *d, char *bogus_name)
  {
      request_rec r;
***************
*** 934,940 ****
   * oh well.
   */
  static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
! 		      char *title)
  {
      FILE *f;
      request_rec *rr = NULL;
--- 1041,1048 ----
   * oh well.
   */
  static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
! 		      char *title, char *bg, char *text, char *link, 
! 		      char *vlink, char *alink)
  {
      FILE *f;
      request_rec *rr = NULL;
***************
*** 964,970 ****
  		emit_H1 = 0;
  
  		if (! suppress_amble) {
! 		    emit_preamble(r, title);
  		}
  		/*
  		 * If there's a problem running the subrequest, display the
--- 1072,1078 ----
  		emit_H1 = 0;
  
  		if (! suppress_amble) {
! 		    emit_preamble(r, title, bg, text, link, vlink, alink);
  		}
  		/*
  		 * If there's a problem running the subrequest, display the
***************
*** 985,991 ****
  		 * where it belongs.
  		 */
  		if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
! 		    emit_preamble(r, title);
  		    emit_amble = 0;
  		    do_emit_plain(r, f);
  		    ap_pfclose(r->pool, f);
--- 1093,1099 ----
  		 * where it belongs.
  		 */
  		if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
! 		    emit_preamble(r, title, bg, text, link, vlink, alink);
  		    emit_amble = 0;
  		    do_emit_plain(r, f);
  		    ap_pfclose(r->pool, f);
***************
*** 996,1002 ****
      }
  
      if (emit_amble) {
! 	emit_preamble(r, title);
      }
      if (emit_H1) {
  	ap_rvputs(r, "<H1>Index of ", title, "</H1>\n", NULL);
--- 1104,1110 ----
      }
  
      if (emit_amble) {
! 	emit_preamble(r, title, bg, text, link, vlink, alink);
      }
      if (emit_H1) {
  	ap_rvputs(r, "<H1>Index of ", title, "</H1>\n", NULL);
***************
*** 1507,1512 ****
--- 1615,1626 ----
      char keyid;
      char direction;
  
+     array_header *bg = autoindex_conf->bg_color;
+     array_header *text = autoindex_conf->text_color;
+     array_header *link = autoindex_conf->link_color;
+     array_header *vlink = autoindex_conf->vlink_color;
+     array_header *alink = autoindex_conf->alink_color;
+ 
      if (!(d = ap_popendir(r->pool, name))) {
  	ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
  		    "Can't open directory for index: %s", r->filename);
***************
*** 1532,1538 ****
      }
  
      emit_head(r, find_header(autoindex_conf, r),
! 	      autoindex_opts & SUPPRESS_PREAMBLE, title_name);
  
      /*
       * Figure out what sort of indexing (if any) we're supposed to use.
--- 1646,1657 ----
      }
  
      emit_head(r, find_header(autoindex_conf, r),
! 	      autoindex_opts & SUPPRESS_PREAMBLE, title_name, 
! 	      find_bg_color(autoindex_conf, r),
! 	      find_text_color(autoindex_conf, r),
! 	      find_link_color(autoindex_conf, r),
! 	      find_vlink_color(autoindex_conf, r),
! 	      find_alink_color(autoindex_conf, r));
  
      /*
       * Figure out what sort of indexing (if any) we're supposed to use.
***************
*** 1652,1658 ****
  module MODULE_VAR_EXPORT autoindex_module =
  {
      STANDARD_MODULE_STUFF,
!     NULL,			/* initializer */
      create_autoindex_config,	/* dir config creater */
      merge_autoindex_configs,	/* dir merger --- default is to override */
      NULL,			/* server config */
--- 1771,1777 ----
  module MODULE_VAR_EXPORT autoindex_module =
  {
      STANDARD_MODULE_STUFF,
!     modified_startup,		/* initializer */
      create_autoindex_config,	/* dir config creater */
      merge_autoindex_configs,	/* dir merger --- default is to override */
      NULL,			/* server config */

