You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Behlendorf <br...@hyperreal.com> on 1997/06/06 22:19:39 UTC

1.2.0 directory handling patch: SuppressHTMLPreamble addition [������ ������ ]

---------- Forwarded message ----------
Date: Fri, 6 Jun 1997 17:56:31 +0400 (MSD)
From: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= <ac...@nagual.pp.ru>
To: "Roy T. Fielding" <fi...@kiwi.ICS.UCI.EDU>
cc: new-httpd@hyperreal.com, apache-bugs@apache.org
Subject: 1.2.0 directory handling patch: SuppressHTMLPreamble addition

On Tue, 25 Feb 1997, Roy T. Fielding wrote:

> >I've a feeling this has already been fixed.
>
> That's because I already proposed a (better) patch for it, based on
> his earlier patch, back in December.  It didn't make the feature freeze,
> so it will just have to wait until after 1.2 is final.  The patch is
> in the patch directory on www.apache.org.

I found it in dist/contrib/patches, but it not applies cleanly to
1.2.0 sources due to few small code changes.

To minimize your efforts I cleanup the thing by myself, here the patch which
applies cleanly to 1.2.0, so you can just put it into next beta.

*** src/mod_dir.c.orig	Tue May 13 08:01:50 1997
--- src/mod_dir.c	Sat May 31 23:43:09 1997
***************
*** 81,86 ****
--- 81,87 ----
  #define SUPPRESS_LAST_MOD 8
  #define SUPPRESS_SIZE 16
  #define SUPPRESS_DESC 32
+ #define SUPPRESS_HTML_PREAMBLE 64
  
  struct item {
      char *type;
***************
*** 203,208 ****
--- 204,211 ----
              opts |= SUPPRESS_SIZE;
          else if(!strcasecmp(w,"SuppressDescription"))
              opts |= SUPPRESS_DESC;
+         else if(!strcasecmp(w,"SuppressHTMLPreamble"))
+             opts |= SUPPRESS_HTML_PREAMBLE;
          else if(!strcasecmp(w,"None"))
              opts = 0;
  	else
***************
*** 403,409 ****
   */
  
  
! int insert_readme(char *name, char *readme_fname, int rule, request_rec *r) {
      char *fn;
      FILE *f;
      struct stat finfo;
--- 406,432 ----
   */
  
  
! static void html_preamble(request_rec *r, const int do_heading)
! {
!     char *title_name = escape_html(r->pool, r->uri);
!     char *title_endp;
! 
!     title_endp = title_name + strlen(title_name) - 1;
! 
!     while (title_endp > title_name && *title_endp == '/')
! 	*title_endp-- = '\0';
!     
!     rvputs(r, "<HTML><HEAD>\n", "<TITLE>Index of ", title_name, "</TITLE>\n",
!               "</HEAD><BODY>\n", NULL);
! 
!     if (do_heading)
!         rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
! }
! 
! 
! int insert_readme(char *name, char *readme_fname, int rule,
!                   int suppress_preamble, request_rec *r)
! {
      char *fn;
      FILE *f;
      struct stat finfo;
***************
*** 417,434 ****
          if(stat(fn,&finfo) == -1)
              return 0;
          plaintext=1;
-         if(rule) rputs("<HR>\n", r);
-         rputs("<PRE>\n", r);
      }
-     else if (rule) rputs("<HR>\n", r);
      if(!(f = pfopen(r->pool,fn,"r")))
          return 0;
!     if (!plaintext)
  	send_fd(f, r);
!     else
!     {
  	char buf[IOBUFSIZE+1];
  	int i, n, c, ch;
  	while (!feof(f))
  	{
  	    do n = fread(buf, sizeof(char), IOBUFSIZE, f);
--- 440,467 ----
          if(stat(fn,&finfo) == -1)
              return 0;
          plaintext=1;
      }
      if(!(f = pfopen(r->pool,fn,"r")))
          return 0;
!     if (!plaintext) {
!         if (rule)
!             rputs("<HR>\n", r);      /* README.html file, send separator */
!         else if (!suppress_preamble)
!             html_preamble(r, 0);     /* HEADER.html file, send preamble  */
! 
  	send_fd(f, r);
!     }
!     else {
  	char buf[IOBUFSIZE+1];
  	int i, n, c, ch;
+ 
+         if (rule)
+             rputs("<HR>\n", r);      /* README.txt file, send separator */
+         else
+             html_preamble(r, 0);     /* HEADER.txt file, send preamble  */
+ 
+         rputs("<PRE>\n", r);
+ 
  	while (!feof(f))
  	{
  	    do n = fread(buf, sizeof(char), IOBUFSIZE, f);
***************
*** 681,690 ****
      
  int index_directory(request_rec *r, dir_config_rec *dir_conf)
  {
-     char *title_name = escape_html(r->pool, r->uri);
-     char *title_endp;
      char *name = r->filename;
-     
      DIR *d;
      struct DIR_TYPE *dstruct;
      int num_ent=0,x;
--- 714,720 ----
***************
*** 708,731 ****
      }
      hard_timeout("send directory", r);
  
!     /* Spew HTML preamble */
!     
!     title_endp = title_name + strlen(title_name) - 1;
! 
!     while (title_endp > title_name && *title_endp == '/')
! 	*title_endp-- = '\0';
      
!     rvputs
! 	(
! 	    r,
! 	    "<HTML><HEAD>\n<TITLE>Index of ",
! 	    title_name,
! 	    "</TITLE>\n</HEAD><BODY>\n",
! 	    NULL
! 	);
! 
!     if((!(tmp = find_header(dir_conf,r))) || (!(insert_readme(name,tmp,0,r))))
!         rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
  
      /* 
       * Since we don't know how many dir. entries there are, put them into a 
--- 738,748 ----
      }
      hard_timeout("send directory", r);
  
!     /* Spew HTML preamble and/or HEADER file */
      
!     if (!((tmp = find_header(dir_conf, r)) &&
!           insert_readme(name,tmp,0,(dir_opts & SUPPRESS_HTML_PREAMBLE),r)))
!         html_preamble(r, 1);
  
      /* 
       * Since we don't know how many dir. entries there are, put them into a 
***************
*** 760,766 ****
  
      if (dir_opts & FANCY_INDEXING)
          if((tmp = find_readme(dir_conf, r)))
!             insert_readme(name,tmp,1,r);
      else {
          rputs("</UL>", r);
      }
--- 777,783 ----
  
      if (dir_opts & FANCY_INDEXING)
          if((tmp = find_readme(dir_conf, r)))
!             insert_readme(name,tmp,1,1,r);
      else {
          rputs("</UL>", r);
      }

-- 
Andrey A. Chernov
<ac...@null.net>
http://www.nagual.pp.ru/~ache/