Project

General

Profile

0002-Optimized-mod_redirect_patch_connection.patch

mkoloberdin, 2009-05-12 02:38

View differences:

src/mod_redirect.c
15 15

  
16 16
typedef struct {
17 17
	pcre_keyvalue_buffer *redirect;
18
	int redirect_defined;
18 19
#ifdef HAVE_GLIB_H
19 20
	GHashTable  *redirect_simple;
20 21
#endif
22
	int redirect_simple_defined;
21 23
	data_config *context; /* to which apply me */
22 24

  
23 25
	unsigned short redirect_code;
......
112 114

  
113 115
		s = calloc(1, sizeof(plugin_config));
114 116
		s->redirect   = pcre_keyvalue_buffer_init();
117
#ifdef HAVE_GLIB_H
115 118
		s->redirect_simple = g_hash_table_new(buffer_key_hash, buffer_key_equal);
119
#endif
116 120

  
117 121
		cv[0].destination = s->redirect;
118 122
		cv[1].destination = s->redirect_simple;
......
127 131

  
128 132
		if (NULL != (du = array_get_element(ca, CONST_STR_LEN("url.redirect")))) {
129 133
			/* url.redirect defined */
134
			s->redirect_defined = 1;
130 135
			if (du->type != TYPE_ARRAY) {
131 136
				log_error_write(srv, __FILE__, __LINE__, "sss",
132 137
						"unexpected type for key: ", "url.redirect", "array of strings");
......
155 160
				}
156 161
			}
157 162
		}
163
#ifdef HAVE_GLIB_H
158 164
		if (NULL != (du = array_get_element(ca, CONST_STR_LEN("url.redirect-simple")))) {
159 165
			/* url.redirect-simple defined */
166
			s->redirect_simple_defined = 1;
160 167
			if (du->type != TYPE_ARRAY) {
161 168
				log_error_write(srv, __FILE__, __LINE__, "sss",
162 169
						"unexpected type for key: ", "url.redirect-simple", "array of strings");
......
186 193
						);
187 194
			}
188 195
		}
196
#endif
189 197
	}
190 198

  
191 199
	return HANDLER_GO_ON;
192 200
}
193 201
#if defined (HAVE_PCRE_H) || defined (HAVE_GLIB_H)
194 202
static int mod_redirect_patch_connection(server *srv, connection *con, plugin_data *p) {
195
	size_t i, j;
203
	size_t i;
196 204
	plugin_config *s = p->config_storage[0];
197 205

  
198 206
#ifdef HAVE_PCRE_H
......
208 216
		data_config *dc = (data_config *)srv->config_context->data[i];
209 217
		s = p->config_storage[i];
210 218

  
219
		/* do not bother to check the condition if nothing defined in this context */
220
		if (!s->redirect_defined && !s->redirect_simple_defined) continue;
221

  
211 222
		/* condition didn't match */
212 223
		if (!config_check_cond(srv, con, dc)) continue;
213 224

  
214 225
		/* merge config */
215
		for (j = 0; j < dc->value->used; j++) {
216
			data_unset *du = dc->value->data[j];
217

  
218
			if
219 226
#ifdef HAVE_PCRE_H
220
               (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect"))) {
221
				PATCH_OPTION(redirect);
222
				p->conf.context = dc;
223
			} else if
227
		if (s->redirect_defined) {
228
			PATCH_OPTION(redirect);
229
			p->conf.context = dc;
230
		}
224 231
#endif
225 232
#ifdef HAVE_GLIB_H
226
                      (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect-simple"))) {
227
				PATCH_OPTION(redirect_simple);
228
				p->conf.context = dc;
229
			} else if
233
		if (s->redirect_simple_defined) {
234
			PATCH_OPTION(redirect_simple);
235
			p->conf.context = dc;
236
		}
230 237
#endif
231
                      (buffer_is_equal_string(du->key, CONST_STR_LEN("url.redirect-code"))) {
232
				PATCH_OPTION(redirect_code);
233
			}
238
		if (s->redirect_code) {
239
			PATCH_OPTION(redirect_code);
234 240
		}
235 241
	}
236 242

  
237
-