]> git.pld-linux.org Git - packages/apache1.git/blame - apache1-autoindex_studly.patch
rel 15; builds
[packages/apache1.git] / apache1-autoindex_studly.patch
CommitLineData
bfc879b9
ER
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
3@@ -63,6 +63,7 @@
4 * 3/23/93
5 *
6 * Adapted to Apache by rst.
7+ * StudlyIndexing by Johnie Ingram <johnie@netgod.net>
8 */
9
10 #include "httpd.h"
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
16
17 #define K_PAD 1
18 #define K_NOPAD 0
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;
26+
27+ char *body_col;
28+ char *text_col;
29+ char *hdr_col;
30+ char *rdme_col;
31+ char *side_col;
32+ char *main_col;
33+ char *ftr_col;
34
35 } autoindex_config_rec;
36
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).
40 */
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)
44 {
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);
55+ }
56+ ap_rputs(">\n\n", r);
57 }
58
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
61 return NULL;
62 }
63
64+static const char *add_sidebar(cmd_parms *cmd, void *d, char *name)
65+{
66+ push_item(((autoindex_config_rec *) d)->side_list, 0, NULL, cmd->path,
67+ name);
68+ return NULL;
69+}
70+
71+static const char *add_body(cmd_parms *cmd, void *d, char *name)
72+{
73+ push_item(((autoindex_config_rec *) d)->main_list, 0, NULL, cmd->path,
74+ name);
75+ return NULL;
76+}
77+
78+static const char *add_footer(cmd_parms *cmd, void *d, char *name)
79+{
80+ push_item(((autoindex_config_rec *) d)->ftr_list, 0, NULL, cmd->path,
81+ name);
82+ return NULL;
83+}
84+
85 /* A legacy directive, FancyIndexing is superseded by the IndexOptions
86 * keyword. But for compatibility..
87 */
88@@ -385,6 +427,12 @@ static const char *add_opts(cmd_parms *c
89 if (!strcasecmp(w, "FancyIndexing")) {
90 option = FANCY_INDEXING;
91 }
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;
97+ }
98 else if (!strcasecmp(w, "IconsAreLinks")) {
99 option = ICONS_ARE_LINKS;
100 }
101@@ -406,16 +454,16 @@ static const char *add_opts(cmd_parms *c
102 else if (!strcasecmp(w, "SuppressColumnSorting")) {
103 option = SUPPRESS_COLSORT;
104 }
105- else if (!strcasecmp(w, "FoldersFirst")) {
106- option = FOLDERS_FIRST;
107+ else if (!strcasecmp(w, "FoldersFirst")) {
108+ option = FOLDERS_FIRST;
109 }
110 else if (!strcasecmp(w, "TrackModified")) {
111- option = TRACK_MODIFIED;
112+ option = TRACK_MODIFIED;
113 }
114 else if (!strcasecmp(w, "IgnoreCase")) {
115- option = SORT_NOCASE;
116+ option = SORT_NOCASE;
117 }
118- else if (!strcasecmp(w, "None")) {
119+ else if (!strcasecmp(w, "None")) {
120 if (action != '\0') {
121 return "Cannot combine '+' or '-' with 'None' keyword";
122 }
123@@ -501,7 +549,49 @@ static const char *add_opts(cmd_parms *c
124 d_cfg->desc_adjust = K_NOADJUST;
125 }
126 }
127- else {
128+ else if (!strncasecmp(w, "BodyColor=", 10)) {
129+ if (action == '-') {
130+ return "Cannot combine '-' with BodyColor=#xxxxxx";
131+ }
132+ d_cfg->body_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
133+ }
134+ else if (!strncasecmp(w, "TextColor=", 10)) {
135+ if (action == '-') {
136+ return "Cannot combine '-' with TextColor=#xxxxxx";
137+ }
138+ d_cfg->text_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
139+ }
140+ else if (!strncasecmp(w, "HeaderColor=", 12)) {
141+ if (action == '-') {
142+ return "Cannot combine '-' with HeaderColor=#xxxxxx";
143+ }
144+ d_cfg->hdr_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
145+ }
146+ else if (!strncasecmp(w, "ReadmeColor=", 12)) {
147+ if (action == '-') {
148+ return "Cannot combine '-' with ReadmeColor=#xxxxxx";
149+ }
150+ d_cfg->rdme_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
151+ }
152+ else if (!strncasecmp(w, "SidebarColor=", 13)) {
153+ if (action == '-') {
154+ return "Cannot combine '-' with SidebarColor=#xxxxxx";
155+ }
156+ d_cfg->side_col = ap_pstrdup(d_cfg->desc_list->pool, &w[13]);
157+ }
158+ else if (!strncasecmp(w, "MainColor=", 10)) {
159+ if (action == '-') {
160+ return "Cannot combine '-' with MainColor=#xxxxxx";
161+ }
162+ d_cfg->main_col = ap_pstrdup(d_cfg->desc_list->pool, &w[10]);
163+ }
164+ else if (!strncasecmp(w, "FooterColor=", 12)) {
165+ if (action == '-') {
166+ return "Cannot combine '-' with FooterColor=#xxxxxx";
167+ }
168+ d_cfg->ftr_col = ap_pstrdup(d_cfg->desc_list->pool, &w[12]);
169+ }
170+ else {
171 return "Invalid directory indexing option";
172 }
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));
191 new->opts = 0;
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) {
202 /*
203 * If the current directory says 'no options' then we also
204@@ -715,6 +814,22 @@ static void *merge_autoindex_configs(poo
205
206 new->default_order = (add->default_order != NULL)
207 ? add->default_order : base->default_order;
208+
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;
223+
224 return new;
225 }
226
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)
235
236 static char *find_default_icon(autoindex_config_rec *d, char *bogus_name)
237 {
238@@ -940,12 +1058,13 @@ static int ignore_entry(autoindex_config
239 /*
240 * emit a plain text file
241 */
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)
244 {
245 char buf[IOBUFSIZE + 1];
246 int i, n, c, ch;
247
248- ap_rputs("<PRE>\n", r);
249+ if (! (autoindex_opts & STUDLY_INDEXING))
250+ ap_rputs("<PRE>\n", r);
251 while (!feof(f)) {
252 do {
253 n = fread(buf, sizeof(char), IOBUFSIZE, f);
254@@ -977,7 +1096,50 @@ static void do_emit_plain(request_rec *r
255 c = i + 1;
256 }
257 }
258- ap_rputs("</PRE>\n", r);
259+ if (! (autoindex_opts & STUDLY_INDEXING))
260+ ap_rputs("</PRE>\n", r);
261+}
262+
263+/*
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.
266+ */
267+static int do_emit_fancy(request_rec *r, const char *fname, int autoindex_opts)
268+{
269+ FILE *f;
270+ request_rec *rr = NULL;
271+
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)) {
277+ /*
278+ * Check for the two specific cases we allow: text/html and
279+ * text/anything-else. The former is allowed to be processed for
280+ * SSIs.
281+ */
282+ if (rr->content_type != NULL) {
283+ if (!strcasecmp(ap_field_noparam(r->pool, rr->content_type),
284+ "text/html")) {
285+ if (ap_run_sub_req(rr) == OK) {
286+ /* worked... */
287+ return 0;
288+ }
289+ }
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);
294+ return 0;
295+ }
296+ }
297+ }
298+ }
299+ if (rr != NULL) {
300+ ap_destroy_sub_req(rr);
301+ }
302+ return -1;
303 }
304
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
308 * oh well.
309 */
310-static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
311- char *title)
312+static void emit_head(request_rec *r, char *header_fname,
313+ autoindex_config_rec *autoindex_conf,
314+ int autoindex_opts, char *title)
315 {
316 FILE *f;
317 request_rec *rr = NULL;
318@@ -1035,8 +1198,8 @@ static void emit_head(request_rec *r, ch
319 emit_amble = 0;
320 emit_H1 = 0;
321
322- if (! suppress_amble) {
323- emit_preamble(r, title);
324+ if (! (autoindex_opts & SUPPRESS_PREAMBLE)) {
325+ emit_preamble(r, title, autoindex_conf);
326 }
327
328 /* See mod_include */
329@@ -1050,7 +1213,7 @@ static void emit_head(request_rec *r, ch
330 */
331 if (ap_run_sub_req(rr) != OK) {
332 /* It didn't work */
333- emit_amble = suppress_amble;
334+ emit_amble = autoindex_opts & SUPPRESS_PREAMBLE;
335 emit_H1 = 1;
336 }
337 ap_table_unset(r->notes, PARENT_STRING); /* cleanup */
338@@ -1063,9 +1226,9 @@ static void emit_head(request_rec *r, ch
339 * where it belongs.
340 */
341 if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) {
342- emit_preamble(r, title);
343+ emit_preamble(r, title, autoindex_conf);
344 emit_amble = 0;
345- do_emit_plain(r, f);
346+ do_emit_plain(r, f, autoindex_opts);
347 ap_pfclose(r->pool, f);
348 emit_H1 = 0;
349 }
350@@ -1085,10 +1248,28 @@ static void emit_head(request_rec *r, ch
351 }
352
353 if (emit_amble) {
354- emit_preamble(r, title);
355+ emit_preamble(r, title, autoindex_conf);
356 }
357+
358+ if (autoindex_opts & STUDLY_INDEXING) {
359+ ap_rvputs(r, "<TABLE cellpadding=\"5\" cellspacing=\"5\" "
360+ "width=\"100%\">\n<tbody>\n", NULL);
361+ }
362+
363 if (emit_H1) {
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);
378 }
379 if (rr != 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
383 * oh well.
384 */
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)
388 {
389 FILE *f;
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) {
393 /* worked... */
394 suppress_sig = 1;
395- suppress_post = suppress_amble;
396+ suppress_post = autoindex_opts & SUPPRESS_PREAMBLE;
397 }
398 ap_table_unset(r->notes, PARENT_STRING); /* cleanup */
399 }
400@@ -1159,7 +1341,7 @@ static void emit_tail(request_rec *r, ch
401 * If we can open the file, suppress the signature.
402 */
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);
407 suppress_sig = 1;
408 }
409@@ -1178,7 +1360,21 @@ static void emit_tail(request_rec *r, ch
410 ap_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
411 }
412
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) {
419+ suppress_sig = 1;
420+ }
421+ ap_rputs("</TD>\n</TR>\n\n</TBODY></TABLE>\n<P>\n", r);
422+ }
423 if (!suppress_sig) {
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\""
427+ "alt=\"\">", r);
428 ap_rputs(ap_psignature("", r), r);
429 }
430 if (!suppress_post) {
431@@ -1411,6 +1607,11 @@ static void output_directories(struct en
432 char *name_scratch;
433 char *pad_scratch;
434
435+ if (autoindex_opts & STUDLY_INDEXING) {
436+ if (do_emit_fancy (r, find_main(d, r), autoindex_opts) == 0)
437+ return;
438+ }
439+
440 if (name[0] == '\0') {
441 name = "/";
442 }
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) {
452 ap_rprintf
453@@ -1475,7 +1677,7 @@ static void output_directories(struct en
454 emit_link(r, "Description", K_DESC, keyid, direction,
455 static_columns);
456 }
457- ap_rputs("\n<HR>\n", r);
458+ ap_rputs("\n<HR noshade align=\"left\" width=\"80%\">\n", r);
459 }
460 else {
461 ap_rputs("<UL>", r);
462@@ -1507,7 +1709,7 @@ static void output_directories(struct en
463 ap_rvputs(r, "<A HREF=\"", anchor, "\">", NULL);
464 }
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
470 : d->default_icon),
471@@ -1717,7 +1919,7 @@ static int index_directory(request_rec *
472 *title_endp-- = '\0';
473 }
474
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);
478
479 /*
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);
483 }
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);
493+ }
494 output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid,
495 direction);
496 ap_pclosedir(r->pool, d);
497
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);
502+ }
503+ else if (autoindex_opts & FANCY_INDEXING) {
504+ ap_rputs("<HR noshade align=\"left\" width=\"80%\">\n", r);
505 }
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);
509
510 ap_kill_timeout(r);
511 return 0;
This page took 0.145322 seconds and 4 git commands to generate.