Project

General

Profile

Feature #2138 ยป mod_simple_vhost.patch

crypt, 2009-12-31 14:32

View differences:

lighttpd-1.4.23/src/mod_simple_vhost.c 2009-10-18 17:33:54.000000000 +0200
23 23
	buffer *docroot_cache_value;
24 24
	buffer *docroot_cache_servername;
25 25

  
26
	unsigned short strip_www;
27

  
26 28
	unsigned short debug;
27 29
} plugin_config;
28 30

  
......
87 89
		{ "simple-vhost.default-host",      NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
88 90
		{ "simple-vhost.document-root",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
89 91
		{ "simple-vhost.debug",             NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
92
		{ "simple-vhost.strip-www",         NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
90 93
		{ NULL,                             NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
91 94
	};
92 95

  
......
108 111
		s->docroot_cache_servername = buffer_init();
109 112

  
110 113
		s->debug = 0;
114
		s->strip_www = 1;
111 115

  
112 116
		cv[0].destination = s->server_root;
113 117
		cv[1].destination = s->default_host;
114 118
		cv[2].destination = s->document_root;
115 119
		cv[3].destination = &(s->debug);
120
		cv[4].destination = &(s->strip_www);
116 121

  
117 122

  
118 123
		p->config_storage[i] = s;
......
149 154
		}
150 155
		BUFFER_APPEND_SLASH(out);
151 156

  
152
		if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') {
153
			buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2);
157
		if (p->conf.strip_www) {
158

  
159
			int h = 0;
160

  
161
			if (host->used > 4 && host->ptr[0] == 'w' && host->ptr[3] == '.') {
162
				if (host->ptr[1] == 'w' && host->ptr[2] == 'w') {
163
					h = 4;
164
				}
165
			}
166

  
167
			if (NULL == (dp = strchr(host->ptr, ':'))) {
168
				buffer_append_string_len(out, host->ptr + h, host->used - h - 1);
169
			} else {
170
				buffer_append_string_len(out, host->ptr + h, dp - host->ptr - h - 1);
171
			}
172

  
154 173
		} else {
155
			buffer_append_string_buffer(out, p->conf.document_root);
156
			BUFFER_APPEND_SLASH(out);
174

  
175
			if (NULL == (dp = strchr(host->ptr, ':'))) {
176
				buffer_append_string_buffer(out, host);
177
			} else {
178
				buffer_append_string_len(out, host->ptr, dp - host->ptr);
179
			}
157 180
		}
181

  
158 182
	} else {
159 183
		buffer_copy_string_buffer(out, con->conf.document_root);
160 184
		BUFFER_APPEND_SLASH(out);
......
189 213
	PATCH(docroot_cache_servername);
190 214

  
191 215
	PATCH(debug);
216
	PATCH(strip_www);
192 217

  
193 218
	/* skip the first, the global context */
194 219
	for (i = 1; i < srv->config_context->used; i++) {
......
209 234
				PATCH(docroot_cache_servername);
210 235
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.default-host"))) {
211 236
				PATCH(default_host);
212
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
237
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.strip-www"))) {
238
                                PATCH(strip_www);
239
                        }else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
213 240
				PATCH(document_root);
214 241
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.debug"))) {
215 242
				PATCH(debug);
    (1-1/1)