Project

General

Profile

mod_ssi_recursion-1.4.15.2.patch

recursive SSI for 1.4.15 (minus whitespace garbage from previous patch) -- dustin - Anonymous, 2007-05-11 19:34

View differences:

src/mod_ssi.c Fri May 11 10:03:02 2007 -0700 → src/mod_ssi.c Fri May 11 12:28:36 2007 -0700
36 36
#include <sys/filio.h>
37 37
#endif
38 38

  
39
#define DEFAULT_MAX_SSI_RECURSION 25
40

  
39 41
/* init the plugin data */
40 42
INIT_FUNC(mod_ssi_init) {
41 43
	plugin_data *p;
......
94 96
#endif
95 97

  
96 98
	config_values_t cv[] = {
97
		{ "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
98
		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
99
		{ "ssi.extension",				NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },		 /* 0 */
100
		{ "ssi.max_recursion",			NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },		 /* 1 */
101
		{ NULL,							NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
99 102
	};
100 103

  
101 104
	if (!p) return HANDLER_ERROR;
......
107 110

  
108 111
		s = calloc(1, sizeof(plugin_config));
109 112
		s->ssi_extension  = array_init();
113
		s->ssi_max_recursion  = DEFAULT_MAX_SSI_RECURSION;
110 114

  
111 115
		cv[0].destination = s->ssi_extension;
116
		cv[1].destination = &(s->ssi_max_recursion);
112 117

  
113 118
		p->config_storage[i] = s;
114 119

  
......
546 551
		}
547 552

  
548 553
		if (0 == stat(p->stat_fn->ptr, &st)) {
554
			buffer *tmp = NULL;
549 555
			time_t t = st.st_mtime;
550 556

  
551 557
			switch (ssicmd) {
......
574 580
				}
575 581
				break;
576 582
			case SSI_INCLUDE:
577
				chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size);
583
				/* do recursive SSI expansion */
584

  
585
				/* prevents infinite loop */
586
				if (buffer_is_equal(con->physical.path, p->stat_fn)) {
587
					buffer_copy_string(srv->tmp_buf, "<!-- your include directives create an infinite loop; aborting -->");
588
					chunkqueue_append_buffer(con->write_queue, srv->tmp_buf);
589
					break;
590
				}
591

  
592
				/* only allow predefined recursion depth */
593
				if (con->loops_per_request > p->conf.ssi_max_recursion) {
594
					buffer_copy_string(srv->tmp_buf, "<!-- your include directives recurse deeper than pre-defined max_recursion; aborting -->");
595
					chunkqueue_append_buffer(con->write_queue, srv->tmp_buf);
596
					break;
597
				}
598

  
599
				tmp = buffer_init();
600
				/* save path of current document */
601
				buffer_copy_string_buffer(tmp, con->physical.path);
602
				/* next sub-document to parse */
603
				buffer_copy_string_buffer(con->physical.path, p->stat_fn);
604
				if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) {
605
					/* the document was not processed, so write it as is */
606
					chunkqueue_append_file(con->write_queue, con->physical.path, 0, st.st_size);
607
				}
608
				/* restore saved path */
609
				buffer_copy_string_buffer(con->physical.path, tmp);
610
				buffer_free(tmp);
578 611
				break;
579 612
			}
580 613
		} else {
......
1023 1056
	plugin_config *s = p->config_storage[0];
1024 1057

  
1025 1058
	PATCH(ssi_extension);
1059
	PATCH(ssi_max_recursion);
1026 1060

  
1027 1061
	/* skip the first, the global context */
1028 1062
	for (i = 1; i < srv->config_context->used; i++) {
......
1039 1073
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
1040 1074
				PATCH(ssi_extension);
1041 1075
			}
1076
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) {
1077
				PATCH(ssi_max_recursion);
1078
			}
1042 1079
		}
1043 1080
	}
1044 1081

  
......
1051 1088
	size_t k;
1052 1089

  
1053 1090
	if (con->physical.path->used == 0) return HANDLER_GO_ON;
1091

  
1092
	con->loops_per_request++;
1054 1093

  
1055 1094
	mod_ssi_patch_connection(srv, con, p);
1056 1095

  
src/mod_ssi.h Fri May 11 10:03:02 2007 -0700 → src/mod_ssi.h Fri May 11 12:28:36 2007 -0700
15 15

  
16 16
typedef struct {
17 17
	array *ssi_extension;
18
	unsigned short ssi_max_recursion;
18 19
} plugin_config;
19 20

  
20 21
typedef struct {