home *** CD-ROM | disk | FTP | other *** search
- Subject: SuppressHTMLPreamble fix/feature
- Date: Wed Feb 26 08:46:49 1997
- From: "Roy T. Fielding" <fielding@kiwi.ICS.UCI.EDU>
-
- Two people have asked for this change this month, and I've wanted it for
- a long time, so I went ahead and coded it for 1.2b7 along the lines
- suggested by Andrey A. Chernov (ache@nagual.ru), but using better code IMHO.
- In his words:
-
- >Situation:
- >It is impossible to suppress initial HTML preamble for directories, i.e.
- ><HEAD><TITLE>Index of dir</TITLE></HEAD><BODY>
- >It means that it is impossible to change <TITLE> or add any
- ><META HTTP-EQUIV...> tags to <HEAD> section or change <BODY>
- >attributes without HTML syntax violation (.asis, cern_meta, etc.
- >not helps here too).
- >
- >Fix:
- >I add "SuppressHTMLPreamble" option to "IndexOptions". When this option
- >is set _and_ HEADER.html (or what you set as it) is present and readable,
- >standard <HEAD><TITLE>Index of dir</TITLE></HEAD><BODY> preamble
- >will be suppressed [with the assumption being that] you have right HTML
- >preamble in your HEADER.html. It solves all problems mentioned above.
-
- [Updated to 1.2.0 by Andrey A. Chernov]
-
- *** mod_dir.c Tue May 13 08:01:50 1997
- --- 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);
- }
-