Project

General

Profile

Feature #246 ยป patch-src_mod_dirlisting.c

patch -- marcus - Anonymous, 2005-09-03 15:26

 
1
--- src/mod_dirlisting.c.orig	Tue Aug 23 08:53:18 2005
2
+++ src/mod_dirlisting.c	Sat Sep  3 12:15:26 2005
3
@@ -52,6 +52,9 @@
4
 	unsigned short dir_listing;
5
 	unsigned short hide_dot_files;
6
 	unsigned short show_readme;
7
+	unsigned short hide_readme_file;
8
+	unsigned short show_header;
9
+	unsigned short hide_header_file;
10
 	
11
 	excludes_buffer *excludes;
12
 
13
@@ -229,13 +232,16 @@
14
 	size_t i = 0;
15
 	
16
 	config_values_t cv[] = { 
17
-		{ "dir-listing.exclude",	 NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION },   /* 0 */
18
-		{ "dir-listing.activate",        NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
19
-		{ "dir-listing.hide-dotfiles",   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
20
-		{ "dir-listing.external-css",    NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 3 */
21
-		{ "dir-listing.encoding",        NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 4 */
22
-		{ "dir-listing.show-readme",     NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 5 */
23
-		{ "server.dir-listing",          NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 6 */
24
+		{ "dir-listing.exclude",	  NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION },   /* 0 */
25
+		{ "dir-listing.activate",         NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
26
+		{ "dir-listing.hide-dotfiles",    NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
27
+		{ "dir-listing.external-css",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 3 */
28
+		{ "dir-listing.encoding",         NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },  /* 4 */
29
+		{ "dir-listing.show-readme",      NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 5 */
30
+		{ "dir-listing.hide-readme-file", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 6 */
31
+		{ "dir-listing.show-header",      NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 7 */
32
+		{ "dir-listing.hide-header-file", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 8 */
33
+		{ "server.dir-listing",           NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 9 */
34
 		
35
 		{ NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
36
 	};
37
@@ -254,6 +260,9 @@
38
 		s->external_css = buffer_init();
39
 		s->hide_dot_files = 0;
40
 		s->show_readme = 0;
41
+		s->hide_readme_file = 0;
42
+		s->show_header = 0;
43
+		s->hide_header_file = 0;
44
 		s->encoding = buffer_init();
45
 		
46
 		cv[0].destination = s->excludes;
47
@@ -262,7 +271,10 @@
48
 		cv[3].destination = s->external_css;
49
 		cv[4].destination = s->encoding;
50
 		cv[5].destination = &(s->show_readme);
51
-		cv[6].destination = &(s->dir_listing); /* old name */
52
+		cv[6].destination = &(s->hide_readme_file);
53
+		cv[7].destination = &(s->show_header);
54
+		cv[8].destination = &(s->hide_header_file);
55
+		cv[9].destination = &(s->dir_listing); /* old name */
56
 
57
 		p->config_storage[i] = s;
58
 		ca = ((data_config *)srv->config_context->data[i])->value;
59
@@ -288,6 +300,9 @@
60
 	PATCH(hide_dot_files);
61
 	PATCH(encoding);
62
 	PATCH(show_readme);
63
+	PATCH(hide_readme_file);
64
+	PATCH(show_header);
65
+	PATCH(hide_header_file);
66
 	PATCH(excludes);
67
 	
68
 	/* skip the first, the global context */
69
@@ -313,6 +328,12 @@
70
 				PATCH(encoding);
71
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.show-readme"))) {
72
 				PATCH(show_readme);
73
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.hide-readme-file"))) {
74
+				PATCH(hide_readme_file);
75
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.show-header"))) {
76
+				PATCH(show_header);
77
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.hide-header-file"))) {
78
+				PATCH(hide_header_file);
79
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("dir-listing.excludes"))) {
80
 				PATCH(excludes);
81
 			}
82
@@ -462,7 +483,26 @@
83
 		);
84
 	}
85
 
86
-	BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n<h2>Index of ");
87
+	BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n");
88
+
89
+	/* HEADER.txt */
90
+	if (p->conf.show_header) {
91
+		stream s;
92
+		/* if we have a HEADER.txt file, display it in <pre class="header"></pre> */
93
+		
94
+		buffer_copy_string_buffer(p->tmp_buf,  con->physical.path);
95
+		BUFFER_APPEND_SLASH(p->tmp_buf);
96
+		BUFFER_APPEND_STRING_CONST(p->tmp_buf, "HEADER.txt");
97
+		
98
+		if (-1 != stream_open(&s, p->tmp_buf)) {
99
+			BUFFER_APPEND_STRING_CONST(out, "<pre class=\"header\">");
100
+			buffer_append_string_html_encoded(out, s.start, s.size);
101
+			BUFFER_APPEND_STRING_CONST(out, "</pre>");
102
+		}
103
+		stream_close(&s);
104
+	}
105
+
106
+	BUFFER_APPEND_STRING_CONST(out, "<h2>Index of ");
107
 	buffer_append_string_html_encoded(out, CONST_BUF_LEN(con->uri.path));
108
 	BUFFER_APPEND_STRING_CONST(out,
109
 		"</h2>\n"
110
@@ -600,6 +640,15 @@
111
 			if (dent->d_name[1] == '\0')
112
 				continue;
113
 			if (dent->d_name[1] == '.' && dent->d_name[2] == '\0')
114
+				continue;
115
+		}
116
+
117
+		if (p->conf.hide_readme_file) {
118
+			if (strcmp(dent->d_name, "README.txt") == 0)
119
+				continue;
120
+		}
121
+		if (p->conf.hide_header_file) {
122
+			if (strcmp(dent->d_name, "HEADER.txt") == 0)
123
 				continue;
124
 		}
125
 
    (1-1/1)