Project

General

Profile

mod_dirlisting_layout_patch-0_1.diff

hr, 2007-11-15 17:10

View differences:

lighttpd-1.4.18/src/mod_dirlisting.c 2007-11-15 17:51:11.000000000 +0100
52 52
	unsigned short hide_dot_files;
53 53
	unsigned short show_readme;
54 54
	unsigned short hide_readme_file;
55
	unsigned short encode_readme;
55 56
	unsigned short show_header;
56 57
	unsigned short hide_header_file;
58
	unsigned short encode_header;
59
	unsigned short auto_layout;
60
	unsigned short pre_list;
57 61

  
58 62
	excludes_buffer *excludes;
59 63

  
......
243 247
#define CONFIG_HIDE_HEADER_FILE "dir-listing.hide-header-file"
244 248
#define CONFIG_DIR_LISTING      "server.dir-listing"
245 249
#define CONFIG_SET_FOOTER       "dir-listing.set-footer"
250
#define CONFIG_ENCODE_README    "dir-listing.encode-readme"
251
#define CONFIG_ENCODE_HEADER    "dir-listing.encode-header"
252
#define CONFIG_AUTO_LAYOUT      "dir-listing.auto-layout"
253
#define CONFIG_PRE_LIST         "dir-listing.pre-list"
246 254

  
247 255

  
248 256
SETDEFAULTS_FUNC(mod_dirlisting_set_defaults) {
......
261 269
		{ CONFIG_HIDE_HEADER_FILE, NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 8 */
262 270
		{ CONFIG_DIR_LISTING,      NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 9 */
263 271
		{ CONFIG_SET_FOOTER,       NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 10 */
272
		{ CONFIG_ENCODE_README,   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 11 */
273
		{ CONFIG_ENCODE_HEADER,   NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 12 */
274
		{ CONFIG_AUTO_LAYOUT,     NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
275
		{ CONFIG_PRE_LIST,        NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
264 276

  
265 277
		{ NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
266 278
	};
......
284 296
		s->hide_header_file = 0;
285 297
		s->encoding = buffer_init();
286 298
		s->set_footer = buffer_init();
299
		s->encode_readme = 1;
300
		s->encode_header = 1;
301
		s->auto_layout = 1;
302
		s->pre_list = 0;
287 303

  
288 304
		cv[0].destination = s->excludes;
289 305
		cv[1].destination = &(s->dir_listing);
......
296 312
		cv[8].destination = &(s->hide_header_file);
297 313
		cv[9].destination = &(s->dir_listing); /* old name */
298 314
		cv[10].destination = s->set_footer;
315
		cv[11].destination = &(s->encode_readme);
316
		cv[12].destination = &(s->encode_header);
317
		cv[13].destination = &(s->auto_layout);
318
		cv[14].destination = &(s->pre_list);
299 319

  
300 320
		p->config_storage[i] = s;
301 321
		ca = ((data_config *)srv->config_context->data[i])->value;
......
326 346
	PATCH(hide_header_file);
327 347
	PATCH(excludes);
328 348
	PATCH(set_footer);
349
	PATCH(encode_readme);
350
	PATCH(encode_header);
351
	PATCH(auto_layout);
352
	PATCH(pre_list);
329 353

  
330 354
	/* skip the first, the global context */
331 355
	for (i = 1; i < srv->config_context->used; i++) {
......
358 382
				PATCH(hide_header_file);
359 383
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_SET_FOOTER))) {
360 384
				PATCH(set_footer);
385
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_ENCODE_README))) {
386
				PATCH(encode_readme);
387
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_ENCODE_HEADER))) {
388
				PATCH(encode_header);
389
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_AUTO_LAYOUT))) {
390
				PATCH(auto_layout);
391
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_PRE_LIST))) {
392
				PATCH(pre_list);
361 393
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN(CONFIG_EXCLUDE))) {
362 394
				PATCH(excludes);
363 395
			}
......
454 486
static void http_list_directory_header(server *srv, connection *con, plugin_data *p, buffer *out) {
455 487
	UNUSED(srv);
456 488

  
457
	BUFFER_APPEND_STRING_CONST(out,
458
		"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
459
		"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
460
		"<head>\n"
461
		"<title>Index of "
462
	);
463
	buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
464
	BUFFER_APPEND_STRING_CONST(out, "</title>\n");
465

  
466
	if (p->conf.external_css->used > 1) {
467
		BUFFER_APPEND_STRING_CONST(out, "<link rel=\"stylesheet\" type=\"text/css\" href=\"");
468
		buffer_append_string_buffer(out, p->conf.external_css);
469
		BUFFER_APPEND_STRING_CONST(out, "\" />\n");
470
	} else {
471
		BUFFER_APPEND_STRING_CONST(out,
472
			"<style type=\"text/css\">\n"
473
			"a, a:active {text-decoration: none; color: blue;}\n"
474
			"a:visited {color: #48468F;}\n"
475
			"a:hover, a:focus {text-decoration: underline; color: red;}\n"
476
			"body {background-color: #F5F5F5;}\n"
477
			"h2 {margin-bottom: 12px;}\n"
478
			"table {margin-left: 12px;}\n"
479
			"th, td {"
480
			" font: 90% monospace;"
481
			" text-align: left;"
482
			"}\n"
483
			"th {"
484
			" font-weight: bold;"
485
			" padding-right: 14px;"
486
			" padding-bottom: 3px;"
487
			"}\n"
488
		);
489
    if (p->conf.auto_layout) {
489 490
		BUFFER_APPEND_STRING_CONST(out,
490
			"td {padding-right: 14px;}\n"
491
			"td.s, th.s {text-align: right;}\n"
492
			"div.list {"
493
			" background-color: white;"
494
			" border-top: 1px solid #646464;"
495
			" border-bottom: 1px solid #646464;"
496
			" padding-top: 10px;"
497
			" padding-bottom: 14px;"
498
			"}\n"
499
			"div.foot {"
500
			" font: 90% monospace;"
501
			" color: #787878;"
502
			" padding-top: 4px;"
503
			"}\n"
504
			"</style>\n"
491
			"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
492
			"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n"
493
			"<head>\n"
494
			"<title>Index of "
505 495
		);
506
	}
496
		buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
497
		BUFFER_APPEND_STRING_CONST(out, "</title>\n");
507 498

  
508
	BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n");
499
		if (p->conf.external_css->used > 1) {
500
			BUFFER_APPEND_STRING_CONST(out, "<link rel=\"stylesheet\" type=\"text/css\" href=\"");
501
			buffer_append_string_buffer(out, p->conf.external_css);
502
			BUFFER_APPEND_STRING_CONST(out, "\" />\n");
503
		} else {
504
			BUFFER_APPEND_STRING_CONST(out,
505
				"<style type=\"text/css\">\n"
506
				"a, a:active {text-decoration: none; color: blue;}\n"
507
				"a:visited {color: #48468F;}\n"
508
				"a:hover, a:focus {text-decoration: underline; color: red;}\n"
509
				"body {background-color: #F5F5F5;}\n"
510
				"h2 {margin-bottom: 12px;}\n"
511
				"table {margin-left: 12px;}\n"
512
				"th, td {"
513
				" font: 90% monospace;"
514
				" text-align: left;"
515
				"}\n"
516
				"th {"
517
				" font-weight: bold;"
518
				" padding-right: 14px;"
519
				" padding-bottom: 3px;"
520
				"}\n"
521
			);
522
			BUFFER_APPEND_STRING_CONST(out,
523
				"td {padding-right: 14px;}\n"
524
				"td.s, th.s {text-align: right;}\n"
525
				"div.list {"
526
				" background-color: white;"
527
				" border-top: 1px solid #646464;"
528
				" border-bottom: 1px solid #646464;"
529
				" padding-top: 10px;"
530
				" padding-bottom: 14px;"
531
				"}\n"
532
				"div.foot {"
533
				" font: 90% monospace;"
534
				" color: #787878;"
535
				" padding-top: 4px;"
536
				"}\n"
537
				"</style>\n"
538
			);
539
		}
540
	
541
		BUFFER_APPEND_STRING_CONST(out, "</head>\n<body>\n");
542
	}
509 543

  
510 544
	/* HEADER.txt */
511 545
	if (p->conf.show_header) {
......
517 551
		BUFFER_APPEND_STRING_CONST(p->tmp_buf, "HEADER.txt");
518 552

  
519 553
		if (-1 != stream_open(&s, p->tmp_buf)) {
520
			BUFFER_APPEND_STRING_CONST(out, "<pre class=\"header\">");
521
			buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
522
			BUFFER_APPEND_STRING_CONST(out, "</pre>");
554
			if (p->conf.encode_header) {
555
				BUFFER_APPEND_STRING_CONST(out, "<pre class=\"header\">");
556
				buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
557
				BUFFER_APPEND_STRING_CONST(out, "</pre>");
558
			} else {
559
				buffer_append_string_len(out, s.start, s.size);
560
			}
523 561
		}
524 562
		stream_close(&s);
525 563
	}
......
528 566
	buffer_append_string_encoded(out, CONST_BUF_LEN(con->uri.path), ENCODING_MINIMAL_XML);
529 567
	BUFFER_APPEND_STRING_CONST(out,
530 568
		"</h2>\n"
531
		"<div class=\"list\">\n"
569
	);
570
	if (p->conf.pre_list) {
571
		BUFFER_APPEND_STRING_CONST(out,
572
			"<pre class=\"list\">\n"
573
		);
574
	} else {
575
		BUFFER_APPEND_STRING_CONST(out,
576
			"<div class=\"list\">\n"
577
		);
578
	}
579
	BUFFER_APPEND_STRING_CONST(out,
532 580
		"<table summary=\"Directory Listing\" cellpadding=\"0\" cellspacing=\"0\">\n"
533 581
		"<thead>"
534 582
		"<tr>"
......
554 602
	BUFFER_APPEND_STRING_CONST(out,
555 603
		"</tbody>\n"
556 604
		"</table>\n"
557
		"</div>\n"
558 605
	);
606
	if (p->conf.pre_list) {
607
		BUFFER_APPEND_STRING_CONST(out,
608
			"</pre>\n"
609
		);
610
	} else {
611
		BUFFER_APPEND_STRING_CONST(out,
612
			"</div>\n"
613
		);
614
	}
559 615

  
560 616
	if (p->conf.show_readme) {
561 617
		stream s;
......
566 622
		BUFFER_APPEND_STRING_CONST(p->tmp_buf, "README.txt");
567 623

  
568 624
		if (-1 != stream_open(&s, p->tmp_buf)) {
569
			BUFFER_APPEND_STRING_CONST(out, "<pre class=\"readme\">");
570
			buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
571
			BUFFER_APPEND_STRING_CONST(out, "</pre>");
625
			if (p->conf.encode_readme) {
626
				BUFFER_APPEND_STRING_CONST(out, "<pre class=\"readme\">");
627
				buffer_append_string_encoded(out, s.start, s.size, ENCODING_MINIMAL_XML);
628
				BUFFER_APPEND_STRING_CONST(out, "</pre>");
629
			} else {
630
				buffer_append_string_len(out, s.start, s.size);
631
			}
572 632
		}
573 633
		stream_close(&s);
574 634
	}
......
587 647

  
588 648
	BUFFER_APPEND_STRING_CONST(out,
589 649
		"</div>\n"
590
		"</body>\n"
591
		"</html>\n"
592 650
	);
651

  
652
    if (p->conf.auto_layout) {
653
		BUFFER_APPEND_STRING_CONST(out,
654
			"</body>\n"
655
			"</html>\n"
656
		);
657
	}
593 658
}
594 659

  
595 660
static int http_list_directory(server *srv, connection *con, plugin_data *p, buffer *dir) {