--- lighttpd-1.4.18.orig/src/mod_dirlisting.c 2007-11-15 14:16:44.000000000 +0100 +++ lighttpd-1.4.18/src/mod_dirlisting.c 2007-11-15 17:51:11.000000000 +0100 @@ -52,8 +52,12 @@ unsigned short hide_dot_files; unsigned short show_readme; unsigned short hide_readme_file; + unsigned short encode_readme; unsigned short show_header; unsigned short hide_header_file; + unsigned short encode_header; + unsigned short auto_layout; + unsigned short pre_list; excludes_buffer *excludes; @@ -243,6 +247,10 @@ #define CONFIG_HIDE_HEADER_FILE "dir-listing.hide-header-file" #define CONFIG_DIR_LISTING "server.dir-listing" #define CONFIG_SET_FOOTER "dir-listing.set-footer" +#define CONFIG_ENCODE_README "dir-listing.encode-readme" +#define CONFIG_ENCODE_HEADER "dir-listing.encode-header" +#define CONFIG_AUTO_LAYOUT "dir-listing.auto-layout" +#define CONFIG_PRE_LIST "dir-listing.pre-list" SETDEFAULTS_FUNC(mod_dirlisting_set_defaults) { @@ -261,6 +269,10 @@ { CONFIG_HIDE_HEADER_FILE, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 8 */ { CONFIG_DIR_LISTING, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 9 */ { CONFIG_SET_FOOTER, NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 10 */ + { CONFIG_ENCODE_README, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 11 */ + { CONFIG_ENCODE_HEADER, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 12 */ + { CONFIG_AUTO_LAYOUT, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */ + { CONFIG_PRE_LIST, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } }; @@ -284,6 +296,10 @@ s->hide_header_file = 0; s->encoding = buffer_init(); s->set_footer = buffer_init(); + s->encode_readme = 1; + s->encode_header = 1; + s->auto_layout = 1; + s->pre_list = 0; cv[0].destination = s->excludes; cv[1].destination = &(s->dir_listing); @@ -296,6 +312,10 @@ cv[8].destination = &(s->hide_header_file); cv[9].destination = &(s->dir_listing); /* old name */ cv[10].destination = s->set_footer; + cv[11].destination = &(s->encode_readme); + cv[12].destination = &(s->encode_header); + cv[13].destination = &(s->auto_layout); + cv[14].destination = &(s->pre_list); p->config_storage[i] = s; ca = ((data_config *)srv->config_context->data[i])->value; @@ -326,6 +346,10 @@ PATCH(hide_header_file); PATCH(excludes); PATCH(set_footer); + PATCH(encode_readme); + PATCH(encode_header); + PATCH(auto_layout); + PATCH(pre_list); /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { @@ -358,6 +382,14 @@ PATCH(hide_header_file); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_SET_FOOTER))) { PATCH(set_footer); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_ENCODE_README))) { + PATCH(encode_readme); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_ENCODE_HEADER))) { + PATCH(encode_header); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_AUTO_LAYOUT))) { + PATCH(auto_layout); + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_PRE_LIST))) { + PATCH(pre_list); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_EXCLUDE))) { PATCH(excludes); } @@ -454,58 +486,60 @@ static void http_list_directory_header(server *srv, connection *con, plugin_data *p, buffer *out) { UNUSED(srv); - BUFFER_APPEND_STRING_CONST(out, - "\n" - "\n" - "\n" - "Index of " - ); - buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML); - BUFFER_APPEND_STRING_CONST(out, "\n"); - - if (p->conf.external_css->used > 1) { - BUFFER_APPEND_STRING_CONST(out, "conf.external_css); - BUFFER_APPEND_STRING_CONST(out, "\" />\n"); - } else { - BUFFER_APPEND_STRING_CONST(out, - "\n" + "\n" + "\n" + "\n" + "Index of " ); - } + buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML); + BUFFER_APPEND_STRING_CONST(out, "\n"); - BUFFER_APPEND_STRING_CONST(out, "\n\n"); + if (p->conf.external_css->used > 1) { + BUFFER_APPEND_STRING_CONST(out, "conf.external_css); + BUFFER_APPEND_STRING_CONST(out, "\" />\n"); + } else { + BUFFER_APPEND_STRING_CONST(out, + "\n" + ); + } + + BUFFER_APPEND_STRING_CONST(out, "\n\n"); + } /* HEADER.txt */ if (p->conf.show_header) { @@ -517,9 +551,13 @@ BUFFER_APPEND_STRING_CONST(p->tmp_buf, "HEADER.txt"); if (-1 != stream_open(&s, p->tmp_buf)) { - BUFFER_APPEND_STRING_CONST(out, "
");
-			buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
-			BUFFER_APPEND_STRING_CONST(out, "
"); + if (p->conf.encode_header) { + BUFFER_APPEND_STRING_CONST(out, "
");
+				buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
+				BUFFER_APPEND_STRING_CONST(out, "
"); + } else { + buffer_append_string_len(out, s.start, s.size); + } } stream_close(&s); } @@ -528,7 +566,17 @@ buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML); BUFFER_APPEND_STRING_CONST(out, "\n" - "
\n" + ); + if (p->conf.pre_list) { + BUFFER_APPEND_STRING_CONST(out, + "
\n"
+		);
+	} else {
+		BUFFER_APPEND_STRING_CONST(out,
+			"
\n" + ); + } + BUFFER_APPEND_STRING_CONST(out, "\n" "" "" @@ -554,8 +602,16 @@ BUFFER_APPEND_STRING_CONST(out, "\n" "
\n" - "
\n" ); + if (p->conf.pre_list) { + BUFFER_APPEND_STRING_CONST(out, + "
\n" + ); + } else { + BUFFER_APPEND_STRING_CONST(out, + "
\n" + ); + } if (p->conf.show_readme) { stream s; @@ -566,9 +622,13 @@ BUFFER_APPEND_STRING_CONST(p->tmp_buf, "README.txt"); if (-1 != stream_open(&s, p->tmp_buf)) { - BUFFER_APPEND_STRING_CONST(out, "
");
-			buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
-			BUFFER_APPEND_STRING_CONST(out, "
"); + if (p->conf.encode_readme) { + BUFFER_APPEND_STRING_CONST(out, "
");
+				buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
+				BUFFER_APPEND_STRING_CONST(out, "
"); + } else { + buffer_append_string_len(out, s.start, s.size); + } } stream_close(&s); } @@ -587,9 +647,14 @@ BUFFER_APPEND_STRING_CONST(out, "\n" - "\n" - "\n" ); + + if (p->conf.auto_layout) { + BUFFER_APPEND_STRING_CONST(out, + "\n" + "\n" + ); + } } static int http_list_directory(server *srv, connection *con, plugin_data *p, buffer *dir) {