1 --- build-tree-apache/apache_1.3.34/src/modules/standard/mod_autoindex.c 2003-12-09 14:47:37.000000000 -0500
2 +++ build-tree-apache/apache_1.3.34/src/modules/standard/mod_autoindex.c 2004-02-19 13:16:31.000000000 -0500
6 * Adapted to Apache by rst.
7 + * StudlyIndexing by Johnie Ingram <johnie@netgod.net>
11 @@ -99,6 +100,7 @@ module MODULE_VAR_EXPORT autoindex_modul
12 #define FOLDERS_FIRST 512
13 #define TRACK_MODIFIED 1024
14 #define SORT_NOCASE 2048
15 +#define STUDLY_INDEXING 4096
19 @@ -163,6 +165,17 @@ typedef struct autoindex_config_struct {
20 array_header *ign_list;
21 array_header *hdr_list;
22 array_header *rdme_list;
23 + array_header *side_list;
24 + array_header *main_list;
25 + array_header *ftr_list;
35 } autoindex_config_rec;
37 @@ -196,11 +209,19 @@ static ap_inline int is_parent(const cha
38 * We include the DOCTYPE because we may be using features therefrom (i.e.,
39 * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
41 -static void emit_preamble(request_rec *r, char *title)
42 +static void emit_preamble(request_rec *r, char *title,
43 + autoindex_config_rec *autoindex_conf)
45 - ap_rvputs(r, DOCTYPE_HTML_3_2,
46 + ap_rvputs(r, DOCTYPE_HTML_4_0T,
47 "<HTML>\n <HEAD>\n <TITLE>Index of ", title,
48 - "</TITLE>\n </HEAD>\n <BODY>\n", NULL);
49 + "</TITLE>\n </HEAD>\n <BODY bgcolor=\"",
50 + autoindex_conf->body_col ?: "#ffffff", "\" text=\"",
51 + autoindex_conf->text_col ?: "#000000", "\"", NULL);
52 + if (autoindex_conf->opts & STUDLY_INDEXING) {
53 + ap_rvputs(r, " leftmargin=\"0\" topmargin=\"0\" \n "
54 + "marginwidth=\"0\" marginheight=\"0\"", NULL);
56 + ap_rputs(">\n\n", r);
59 static void push_item(array_header *arr, char *type, char *to, char *path,
60 @@ -340,6 +361,27 @@ static const char *add_readme(cmd_parms
64 +static const char *add_sidebar(cmd_parms *cmd, void *d, char *name)
66 + push_item(((autoindex_config_rec *) d)->side_list, 0, NULL, cmd->path,
71 +static const char *add_body(cmd_parms *cmd, void *d, char *name)
73 + push_item(((autoindex_config_rec *) d)->main_list, 0, NULL, cmd->path,
78 +static const char *add_footer(cmd_parms *cmd, void *d, char *name)
80 + push_item(((autoindex_config_rec *) d)->ftr_list, 0, NULL, cmd->path,
85 /* A legacy directive, FancyIndexing is superseded by the IndexOptions
86 * keyword. But for compatibility..
88 @@ -385,6 +427,12 @@ static const char *add_opts(cmd_parms *c
89 if (!strcasecmp(w, "FancyIndexing")) {
90 option = FANCY_INDEXING;
92 + else if (!strcasecmp(w, "StudlyIndexing")) {
93 + /* automatic FancyIndexing on, NameWidth=*, etc. */
94 + option = STUDLY_INDEXING + FANCY_INDEXING
95 + + ICONS_ARE_LINKS + SUPPRESS_DESC;
96 + d_cfg->name_adjust = K_ADJUST;
98 else if (!strcasecmp(w, "IconsAreLinks")) {
99 option = ICONS_ARE_LINKS;
101 @@ -406,16 +454,16 @@ static const char *add_opts(cmd_parms *c
102 else if (!strcasecmp(w, "SuppressColumnSorting")) {
103 option = SUPPRESS_COLSORT;
105 - else if (!strcasecmp(w, "FoldersFirst")) {
106 - option = FOLDERS_FIRST;
107 + else if (!strcasecmp(w, "FoldersFirst")) {
108 + option = FOLDERS_FIRST;
110 else if (!strcasecmp(w, "TrackModified")) {
111 - option = TRACK_MODIFIED;
112 + option = TRACK_MODIFIED;
114 else if (!strcasecmp(w, "IgnoreCase")) {
115 - option = SORT_NOCASE;
116 + option = SORT_NOCASE;
118 - else if (!strcasecmp(w, "None")) {
119 + else if (!strcasecmp(w, "None")) {
120 if (action != '\0') {
121 return "Cannot combine '+' or '-' with 'None' keyword";
123 @@ -501,7 +549,49 @@ static const char *add_opts(cmd_parms *c
124 d_cfg->desc_adjust = K_NOADJUST;
128 + else if (!strncasecmp(w, "BodyColor=", 10)) {
129 + if (action == '-') {
130 + return "Cannot combine '-' with BodyColor=#xxxxxx";
132 + d_cfg->body_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
134 + else if (!strncasecmp(w, "TextColor=", 10)) {
135 + if (action == '-') {
136 + return "Cannot combine '-' with TextColor=#xxxxxx";
138 + d_cfg->text_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
140 + else if (!strncasecmp(w, "HeaderColor=", 12)) {
141 + if (action == '-') {
142 + return "Cannot combine '-' with HeaderColor=#xxxxxx";
144 + d_cfg->hdr_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
146 + else if (!strncasecmp(w, "ReadmeColor=", 12)) {
147 + if (action == '-') {
148 + return "Cannot combine '-' with ReadmeColor=#xxxxxx";
150 + d_cfg->rdme_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
152 + else if (!strncasecmp(w, "SidebarColor=", 13)) {
153 + if (action == '-') {
154 + return "Cannot combine '-' with SidebarColor=#xxxxxx";
156 + d_cfg->side_col = ap_pstrdup(d_cfg->desc_list->pool, &w[13]);
158 + else if (!strncasecmp(w, "MainColor=", 10)) {
159 + if (action == '-') {
160 + return "Cannot combine '-' with MainColor=#xxxxxx";
162 + d_cfg->main_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
164 + else if (!strncasecmp(w, "FooterColor=", 12)) {
165 + if (action == '-') {
166 + return "Cannot combine '-' with FooterColor=#xxxxxx";
168 + d_cfg->ftr_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
171 return "Invalid directory indexing option";
173 if (action == '\0') {
174 @@ -595,6 +685,9 @@ static const command_rec autoindex_cmds[
175 "Descriptive text followed by one or more filenames"},
176 {"HeaderName", add_header, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
177 {"ReadmeName", add_readme, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
178 + {"SidebarName", add_sidebar, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
179 + {"BodyName", add_body, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
180 + {"FooterName", add_footer, NULL, DIR_CMD_PERMS, TAKE1, "a filename"},
181 {"FancyIndexing", fancy_indexing, NULL, DIR_CMD_PERMS, FLAG,
182 "Limited to 'on' or 'off' (superseded by IndexOptions FancyIndexing)"},
183 {"DefaultIcon", ap_set_string_slot,
184 @@ -620,6 +713,9 @@ static void *create_autoindex_config(poo
185 new->ign_list = ap_make_array(p, 4, sizeof(struct item));
186 new->hdr_list = ap_make_array(p, 4, sizeof(struct item));
187 new->rdme_list = ap_make_array(p, 4, sizeof(struct item));
188 + new->side_list = ap_make_array(p, 4, sizeof(struct item));
189 + new->main_list = ap_make_array(p, 4, sizeof(struct item));
190 + new->ftr_list = ap_make_array(p, 4, sizeof(struct item));
192 new->incremented_opts = 0;
193 new->decremented_opts = 0;
194 @@ -646,6 +742,9 @@ static void *merge_autoindex_configs(poo
195 new->desc_list = ap_append_arrays(p, add->desc_list, base->desc_list);
196 new->icon_list = ap_append_arrays(p, add->icon_list, base->icon_list);
197 new->rdme_list = ap_append_arrays(p, add->rdme_list, base->rdme_list);
198 + new->side_list = ap_append_arrays(p, add->side_list, base->side_list);
199 + new->main_list = ap_append_arrays(p, add->main_list, base->main_list);
200 + new->ftr_list = ap_append_arrays(p, add->ftr_list, base->ftr_list);
201 if (add->opts & NO_OPTIONS) {
203 * If the current directory says 'no options' then we also
204 @@ -715,6 +814,22 @@ static void *merge_autoindex_configs(poo
206 new->default_order = (add->default_order != NULL)
207 ? add->default_order : base->default_order;
209 + new->body_col = (add->body_col != NULL)
210 + ? add->body_col : base->body_col;
211 + new->text_col = (add->text_col != NULL)
212 + ? add->text_col : base->text_col;
213 + new->hdr_col = (add->hdr_col != NULL)
214 + ? add->hdr_col : base->hdr_col;
215 + new->rdme_col = (add->rdme_col != NULL)
216 + ? add->rdme_col : base->rdme_col;
217 + new->side_col = (add->side_col != NULL)
218 + ? add->side_col : base->side_col;
219 + new->main_col = (add->main_col != NULL)
220 + ? add->main_col : base->main_col;
221 + new->ftr_col = (add->ftr_col != NULL)
222 + ? add->ftr_col : base->ftr_col;
227 @@ -789,7 +904,10 @@ static char *find_item(request_rec *r, a
228 #define find_icon(d,p,t) find_item(p,d->icon_list,t)
229 #define find_alt(d,p,t) find_item(p,d->alt_list,t)
230 #define find_header(d,p) find_item(p,d->hdr_list,0)
231 +#define find_sidebar(d,p) find_item(p,d->side_list,0)
232 #define find_readme(d,p) find_item(p,d->rdme_list,0)
233 +#define find_main(d,p) find_item(p,d->main_list,0)
234 +#define find_footer(d,p) find_item(p,d->ftr_list,0)
236 static char *find_default_icon(autoindex_config_rec *d, char *bogus_name)
238 @@ -940,12 +1058,13 @@ static int ignore_entry(autoindex_config
240 * emit a plain text file
242 -static void do_emit_plain(request_rec *r, FILE *f)
243 +static void do_emit_plain(request_rec *r, FILE *f, int autoindex_opts)
245 char buf[IOBUFSIZE + 1];
248 - ap_rputs("<PRE>\n", r);
249 + if (! (autoindex_opts & STUDLY_INDEXING))
250 + ap_rputs("<PRE>\n", r);
253 n = fread(buf, sizeof(char), IOBUFSIZE, f);
254 @@ -977,7 +1096,50 @@ static void do_emit_plain(request_rec *r
258 - ap_rputs("</PRE>\n", r);
259 + if (! (autoindex_opts & STUDLY_INDEXING))
260 + ap_rputs("</PRE>\n", r);
264 + * If there's a file, send a subrequest to look for it. If it's
265 + * found and a text file, handle it and return 0, otherwise return -1.
267 +static int do_emit_fancy(request_rec *r, const char *fname, int autoindex_opts)
270 + request_rec *rr = NULL;
272 + if ((fname != NULL)
273 + && (rr = ap_sub_req_lookup_uri(fname, r))
274 + && (rr->status == HTTP_OK)
275 + && (rr->filename != NULL)
276 + && S_ISREG(rr->finfo.st_mode)) {
278 + * Check for the two specific cases we allow: text/html and
279 + * text/anything-else. The former is allowed to be processed for
282 + if (rr->content_type != NULL) {
283 + if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
285 + if (ap_run_sub_req(rr) == OK) {
290 + else if (!strncasecmp("text/", rr->content_type, 5)) {
291 + if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
292 + do_emit_plain(r, f, autoindex_opts);
293 + ap_pfclose(r->pool, f);
300 + ap_destroy_sub_req(rr);
305 /* See mod_include */
306 @@ -993,8 +1155,9 @@ static void do_emit_plain(request_rec *r
307 * instead of a text document, meaning nothing will be displayed, but
310 -static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
312 +static void emit_head(request_rec *r, char *header_fname,
313 + autoindex_config_rec *autoindex_conf,
314 + int autoindex_opts, char *title)
317 request_rec *rr = NULL;
318 @@ -1035,8 +1198,8 @@ static void emit_head(request_rec *r, ch
322 - if (! suppress_amble) {
323 - emit_preamble(r, title);
324 + if (! (autoindex_opts & SUPPRESS_PREAMBLE)) {
325 + emit_preamble(r, title, autoindex_conf);
328 /* See mod_include */
329 @@ -1050,7 +1213,7 @@ static void emit_head(request_rec *r, ch
331 if (ap_run_sub_req(rr) != OK) {
333 - emit_amble = suppress_amble;
334 + emit_amble = autoindex_opts & SUPPRESS_PREAMBLE;
337 ap_table_unset(r->notes, PARENT_STRING); /* cleanup */
338 @@ -1063,9 +1226,9 @@ static void emit_head(request_rec *r, ch
341 if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
342 - emit_preamble(r, title);
343 + emit_preamble(r, title, autoindex_conf);
345 - do_emit_plain(r, f);
346 + do_emit_plain(r, f, autoindex_opts);
347 ap_pfclose(r->pool, f);
350 @@ -1085,10 +1248,28 @@ static void emit_head(request_rec *r, ch
354 - emit_preamble(r, title);
355 + emit_preamble(r, title, autoindex_conf);
358 + if (autoindex_opts & STUDLY_INDEXING) {
359 + ap_rvputs(r, "<TABLE cellpadding=\"5\" cellspacing=\"5\" "
360 + "width=\"100%\">\n<tbody>\n", NULL);
364 - ap_rvputs(r, "<H1>Index of ", title, "</H1>\n", NULL);
365 + if (autoindex_opts & STUDLY_INDEXING)
366 + ap_rvputs(r, "\n<TR valign=\"top\">\n"
367 + "<TD class=\"header\" bgcolor=\"",
368 + autoindex_conf->hdr_col ?: "#ffffff",
369 + "\" colspan=\"2\">\n", NULL);
370 + ap_rputs("<TABLE><TR><TD bgcolor=\"#ffffff\" "
371 + "class=\"title\">\n", r);
372 + ap_rvputs(r, "<FONT size=\"+3\" "
373 + "face=\"Helvetica,Arial,sans-serif\">\n<B>Index of ",
374 + title, "</B></FONT>\n", NULL);
375 + ap_rputs("\n</TD></TR></TABLE>", r);
376 + if (autoindex_opts & STUDLY_INDEXING)
377 + ap_rvputs(r, "</TD>\n</TR>\n", NULL);
380 ap_destroy_sub_req(rr);
381 @@ -1105,7 +1286,8 @@ static void emit_head(request_rec *r, ch
382 * instead of a text document, meaning nothing will be displayed, but
385 -static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
386 +static void emit_tail(request_rec *r, char *readme_fname,
387 + autoindex_config_rec *autoindex_conf, int autoindex_opts)
390 request_rec *rr = NULL;
391 @@ -1150,7 +1332,7 @@ static void emit_tail(request_rec *r, ch
392 if (ap_run_sub_req(rr) == OK) {
395 - suppress_post = suppress_amble;
396 + suppress_post = autoindex_opts & SUPPRESS_PREAMBLE;
398 ap_table_unset(r->notes, PARENT_STRING); /* cleanup */
400 @@ -1159,7 +1341,7 @@ static void emit_tail(request_rec *r, ch
401 * If we can open the file, suppress the signature.
403 if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
404 - do_emit_plain(r, f);
405 + do_emit_plain(r, f, autoindex_opts & STUDLY_INDEXING);
406 ap_pfclose(r->pool, f);
409 @@ -1178,7 +1360,21 @@ static void emit_tail(request_rec *r, ch
410 ap_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
413 + if (autoindex_opts & STUDLY_INDEXING && !suppress_post) {
414 + ap_rvputs(r, "\n<TR valign=\"top\">\n<TD class=\"footer\" "
415 + "colspan=\"2\" bgcolor=\"",
416 + autoindex_conf->ftr_col ?: "#ffffff", "\">\n", NULL);
417 + if (do_emit_fancy (r, find_footer(autoindex_conf, r),
418 + autoindex_opts) == 0) {
421 + ap_rputs("</TD>\n</TR>\n\n</TBODY></TABLE>\n<P>\n", r);
424 + if (autoindex_opts & STUDLY_INDEXING)
425 + ap_rputs ("<BR><IMG src=\"/icons/linux-pengo-small.gif\"\n"
426 + "width=\"110\" height=\"44\" align=\"right\""
428 ap_rputs(ap_psignature("", r), r);
430 if (!suppress_post) {
431 @@ -1411,6 +1607,11 @@ static void output_directories(struct en
435 + if (autoindex_opts & STUDLY_INDEXING) {
436 + if (do_emit_fancy (r, find_main(d, r), autoindex_opts) == 0)
440 if (name[0] == '\0') {
443 @@ -1443,7 +1644,8 @@ static void output_directories(struct en
444 if (autoindex_opts & FANCY_INDEXING) {
445 ap_rputs("<PRE>", r);
446 if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
447 - ap_rvputs(r, "<IMG SRC=\"", ap_escape_html(scratch, tp),
448 + ap_rvputs(r, "<IMG border=\"0\" src=\"",
449 + ap_escape_html(scratch, tp),
450 "\" ALT=\" \"", NULL);
451 if (d->icon_width && d->icon_height) {
453 @@ -1475,7 +1677,7 @@ static void output_directories(struct en
454 emit_link(r, "Description", K_DESC, keyid, direction,
457 - ap_rputs("\n<HR>\n", r);
458 + ap_rputs("\n<HR noshade align=\"left\" width=\"80%\">\n", r);
462 @@ -1507,7 +1709,7 @@ static void output_directories(struct en
463 ap_rvputs(r, "<A HREF=\"", anchor, "\">", NULL);
465 if ((ar[x]->icon) || d->default_icon) {
466 - ap_rvputs(r, "<IMG SRC=\"",
467 + ap_rvputs(r, "<IMG border=\"0\" src=\"",
468 ap_escape_html(scratch,
469 ar[x]->icon ? ar[x]->icon
471 @@ -1717,7 +1919,7 @@ static int index_directory(request_rec *
472 *title_endp-- = '\0';
475 - emit_head(r, find_header(autoindex_conf, r),
476 + emit_head(r, find_header(autoindex_conf, r), autoindex_conf,
477 autoindex_opts & SUPPRESS_PREAMBLE, title_name);
480 @@ -1779,15 +1981,27 @@ static int index_directory(request_rec *
481 qsort((void *) ar, num_ent, sizeof(struct ent *),
482 (int (*)(const void *, const void *)) dsortf);
484 + if (autoindex_opts & STUDLY_INDEXING) {
485 + ap_rputs("\n<TR valign=\"top\">\n", r);
486 + ap_rvputs(r, "\n<TD class=\"sidebar\" bgcolor=\"",
487 + autoindex_conf->side_col ?: "#ffffff",
488 + "\" width=\"5%\">\n", NULL);
489 + do_emit_fancy (r, find_sidebar(autoindex_conf, r), autoindex_opts);
490 + ap_rputs("</TD>\n", r);
491 + ap_rvputs(r, "\n<TD class=\"body\" bgcolor=\"",
492 + autoindex_conf->main_col ?: "#ffffff", "\">\n", NULL);
494 output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid,
496 ap_pclosedir(r->pool, d);
498 - if (autoindex_opts & FANCY_INDEXING) {
499 - ap_rputs("<HR>\n", r);
500 + if (autoindex_opts & STUDLY_INDEXING) {
501 + ap_rputs("</TD class=\"body\">\n\n</TR>\n", r);
503 + else if (autoindex_opts & FANCY_INDEXING) {
504 + ap_rputs("<HR noshade align=\"left\" width=\"80%\">\n", r);
506 - emit_tail(r, find_readme(autoindex_conf, r),
507 - autoindex_opts & SUPPRESS_PREAMBLE);
508 + emit_tail(r, find_readme(autoindex_conf, r), autoindex_conf, autoindex_opts);