home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / patches / 1.2 / SuppressHTMLPreamble.patch < prev    next >
Encoding:
Internet Message Format  |  1998-06-11  |  5.6 KB

  1. Subject: SuppressHTMLPreamble fix/feature
  2. Date: Wed Feb 26 08:46:49 1997
  3. From: "Roy T. Fielding" <fielding@kiwi.ICS.UCI.EDU>
  4.  
  5. Two people have asked for this change this month, and I've wanted it for
  6. a long time, so I went ahead and coded it for 1.2b7 along the lines
  7. suggested by Andrey A. Chernov (ache@nagual.ru), but using better code IMHO.
  8. In his words:
  9.  
  10. >Situation:
  11. >It is impossible to suppress initial HTML preamble for directories, i.e.
  12. ><HEAD><TITLE>Index of dir</TITLE></HEAD><BODY>
  13. >It means that it is impossible to change <TITLE> or add any
  14. ><META HTTP-EQUIV...> tags to <HEAD> section or change <BODY>
  15. >attributes without HTML syntax violation (.asis, cern_meta, etc.
  16. >not helps here too).
  17. >
  18. >Fix:
  19. >I add "SuppressHTMLPreamble" option to "IndexOptions". When this option
  20. >is set _and_ HEADER.html (or what you set as it) is present and readable,
  21. >standard <HEAD><TITLE>Index of dir</TITLE></HEAD><BODY> preamble
  22. >will be suppressed [with the assumption being that] you have right HTML
  23. >preamble in your HEADER.html. It solves all problems mentioned above.
  24.  
  25. [Updated to 1.2.0 by Andrey A. Chernov]
  26.  
  27. *** mod_dir.c    Tue May 13 08:01:50 1997
  28. --- mod_dir.c    Sat May 31 23:43:09 1997
  29. ***************
  30. *** 81,86 ****
  31. --- 81,87 ----
  32.   #define SUPPRESS_LAST_MOD 8
  33.   #define SUPPRESS_SIZE 16
  34.   #define SUPPRESS_DESC 32
  35. + #define SUPPRESS_HTML_PREAMBLE 64
  36.   
  37.   struct item {
  38.       char *type;
  39. ***************
  40. *** 203,208 ****
  41. --- 204,211 ----
  42.               opts |= SUPPRESS_SIZE;
  43.           else if(!strcasecmp(w,"SuppressDescription"))
  44.               opts |= SUPPRESS_DESC;
  45. +         else if(!strcasecmp(w,"SuppressHTMLPreamble"))
  46. +             opts |= SUPPRESS_HTML_PREAMBLE;
  47.           else if(!strcasecmp(w,"None"))
  48.               opts = 0;
  49.       else
  50. ***************
  51. *** 403,409 ****
  52.    */
  53.   
  54.   
  55. ! int insert_readme(char *name, char *readme_fname, int rule, request_rec *r) {
  56.       char *fn;
  57.       FILE *f;
  58.       struct stat finfo;
  59. --- 406,432 ----
  60.    */
  61.   
  62.   
  63. ! static void html_preamble(request_rec *r, const int do_heading)
  64. ! {
  65. !     char *title_name = escape_html(r->pool, r->uri);
  66. !     char *title_endp;
  67. !     title_endp = title_name + strlen(title_name) - 1;
  68. !     while (title_endp > title_name && *title_endp == '/')
  69. !     *title_endp-- = '\0';
  70. !     
  71. !     rvputs(r, "<HTML><HEAD>\n", "<TITLE>Index of ", title_name, "</TITLE>\n",
  72. !               "</HEAD><BODY>\n", NULL);
  73. !     if (do_heading)
  74. !         rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
  75. ! }
  76. ! int insert_readme(char *name, char *readme_fname, int rule,
  77. !                   int suppress_preamble, request_rec *r)
  78. ! {
  79.       char *fn;
  80.       FILE *f;
  81.       struct stat finfo;
  82. ***************
  83. *** 417,434 ****
  84.           if(stat(fn,&finfo) == -1)
  85.               return 0;
  86.           plaintext=1;
  87. -         if(rule) rputs("<HR>\n", r);
  88. -         rputs("<PRE>\n", r);
  89.       }
  90. -     else if (rule) rputs("<HR>\n", r);
  91.       if(!(f = pfopen(r->pool,fn,"r")))
  92.           return 0;
  93. !     if (!plaintext)
  94.       send_fd(f, r);
  95. !     else
  96. !     {
  97.       char buf[IOBUFSIZE+1];
  98.       int i, n, c, ch;
  99.       while (!feof(f))
  100.       {
  101.           do n = fread(buf, sizeof(char), IOBUFSIZE, f);
  102. --- 440,467 ----
  103.           if(stat(fn,&finfo) == -1)
  104.               return 0;
  105.           plaintext=1;
  106.       }
  107.       if(!(f = pfopen(r->pool,fn,"r")))
  108.           return 0;
  109. !     if (!plaintext) {
  110. !         if (rule)
  111. !             rputs("<HR>\n", r);      /* README.html file, send separator */
  112. !         else if (!suppress_preamble)
  113. !             html_preamble(r, 0);     /* HEADER.html file, send preamble  */
  114.       send_fd(f, r);
  115. !     }
  116. !     else {
  117.       char buf[IOBUFSIZE+1];
  118.       int i, n, c, ch;
  119. +         if (rule)
  120. +             rputs("<HR>\n", r);      /* README.txt file, send separator */
  121. +         else
  122. +             html_preamble(r, 0);     /* HEADER.txt file, send preamble  */
  123. +         rputs("<PRE>\n", r);
  124.       while (!feof(f))
  125.       {
  126.           do n = fread(buf, sizeof(char), IOBUFSIZE, f);
  127. ***************
  128. *** 681,690 ****
  129.       
  130.   int index_directory(request_rec *r, dir_config_rec *dir_conf)
  131.   {
  132. -     char *title_name = escape_html(r->pool, r->uri);
  133. -     char *title_endp;
  134.       char *name = r->filename;
  135. -     
  136.       DIR *d;
  137.       struct DIR_TYPE *dstruct;
  138.       int num_ent=0,x;
  139. --- 714,720 ----
  140. ***************
  141. *** 708,731 ****
  142.       }
  143.       hard_timeout("send directory", r);
  144.   
  145. !     /* Spew HTML preamble */
  146. !     
  147. !     title_endp = title_name + strlen(title_name) - 1;
  148. !     while (title_endp > title_name && *title_endp == '/')
  149. !     *title_endp-- = '\0';
  150.       
  151. !     rvputs
  152. !     (
  153. !         r,
  154. !         "<HTML><HEAD>\n<TITLE>Index of ",
  155. !         title_name,
  156. !         "</TITLE>\n</HEAD><BODY>\n",
  157. !         NULL
  158. !     );
  159. !     if((!(tmp = find_header(dir_conf,r))) || (!(insert_readme(name,tmp,0,r))))
  160. !         rvputs(r, "<H1>Index of ", title_name, "</H1>\n", NULL);
  161.   
  162.       /* 
  163.        * Since we don't know how many dir. entries there are, put them into a 
  164. --- 738,748 ----
  165.       }
  166.       hard_timeout("send directory", r);
  167.   
  168. !     /* Spew HTML preamble and/or HEADER file */
  169.       
  170. !     if (!((tmp = find_header(dir_conf, r)) &&
  171. !           insert_readme(name,tmp,0,(dir_opts & SUPPRESS_HTML_PREAMBLE),r)))
  172. !         html_preamble(r, 1);
  173.   
  174.       /* 
  175.        * Since we don't know how many dir. entries there are, put them into a 
  176. ***************
  177. *** 760,766 ****
  178.   
  179.       if (dir_opts & FANCY_INDEXING)
  180.           if((tmp = find_readme(dir_conf, r)))
  181. !             insert_readme(name,tmp,1,r);
  182.       else {
  183.           rputs("</UL>", r);
  184.       }
  185. --- 777,783 ----
  186.   
  187.       if (dir_opts & FANCY_INDEXING)
  188.           if((tmp = find_readme(dir_conf, r)))
  189. !             insert_readme(name,tmp,1,1,r);
  190.       else {
  191.           rputs("</UL>", r);
  192.       }
  193.