Project

General

Profile

mod_ssi.patch

Add missing mod_ssi.h modifications -- marc - Anonymous, 2007-02-28 18:23

View differences:

mod_ssi.c (working copy)
98 98

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

  
......
110 111

  
111 112
		s = calloc(1, sizeof(plugin_config));
112 113
		s->ssi_extension  = array_init();
114
		s->ssi_max_recursion  = 0;
113 115

  
114 116
		cv[0].destination = s->ssi_extension;
117
		cv[1].destination = s->ssi_max_recursion;
115 118

  
116 119
		p->config_storage[i] = s;
117 120

  
......
289 292
	return 0;
290 293
}
291 294

  
295
URIHANDLER_FUNC(mod_ssi_physical_path);
296

  
292 297
static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
293 298
			    const char **l, size_t n) {
294 299
	size_t i, ssicmd = 0;
......
549 554
		}
550 555

  
551 556
		if (0 == stat(p->stat_fn->ptr, &st)) {
557
			buffer *tmp = NULL;
552 558
			time_t t = st.st_mtime;
553 559

  
554 560
			switch (ssicmd) {
......
577 583
				}
578 584
				break;
579 585
			case SSI_INCLUDE:
580
				chunkqueue_append_file(con->send, p->stat_fn, 0, st.st_size);
586
				// do recursive SSI expansion
587

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

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

  
602
				tmp = buffer_init();
603
				buffer_copy_string_buffer(tmp, con->physical.path); // save path of current document
604
				buffer_copy_string_buffer(con->physical.path, p->stat_fn); // next sub-document to parse
605
				if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) {
606
					// the document was not processed, so write it as is
607
					chunkqueue_append_file(con->send, con->physical.path, 0, st.st_size);
608
				}
609
				buffer_copy_string_buffer(con->physical.path, tmp); // restore saved path
610
				buffer_free(tmp);
581 611
				break;
582 612
			}
583 613
		} else {
......
1017 1047
	plugin_config *s = p->config_storage[0];
1018 1048

  
1019 1049
	PATCH_OPTION(ssi_extension);
1050
	PATCH_OPTION(ssi_max_recursion);
1020 1051

  
1021 1052
	/* skip the first, the global context */
1022 1053
	for (i = 1; i < srv->config_context->used; i++) {
......
1033 1064
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
1034 1065
				PATCH_OPTION(ssi_extension);
1035 1066
			}
1067
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) {
1068
				PATCH_OPTION(ssi_max_recursion);
1069
			}
1036 1070
		}
1037 1071
	}
1038 1072

  
......
1045 1079

  
1046 1080
	if (con->physical.path->used == 0) return HANDLER_GO_ON;
1047 1081

  
1082
	con->loops_per_request++;
1083

  
1048 1084
	mod_ssi_patch_connection(srv, con, p);
1049 1085

  
1050 1086
	for (k = 0; k < p->conf.ssi_extension->used; k++) {
mod_ssi.h (working copy)
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 {