Project

General

Profile

lighttpd-1.4.13-mod_geoip_redirect.patch

spillgroup, 2008-01-31 10:08

View differences:

lighttpd-1.4.13_mod_geoip/src/mod_redirect.c 2006-10-12 10:15:20.000000000 +0200
242 242

  
243 243
			pcre_free(list);
244 244

  
245
			// start environment variable replacement
246
			for (n = 0; n < con->environment->used; n++) {
247
				data_string *ds;
248

  
249
				ds = (data_string *)con->environment->data[n];
250

  
251
				if (ds->value->used && ds->key->used) {
252
					char key[200], *c;
253
					buffer *new_location, *tmp;
254
					int j, cnt;
255

  
256
					// Create KEY:
257
					tmp = buffer_init();
258
					buffer_prepare_append(tmp, ds->key->used + 2);
259
					for (j = 0; j < ds->key->used - 1; j++) {
260
						tmp->ptr[tmp->used++] = isalpha((unsigned char)ds->key->ptr[j]) ? toupper((unsigned char)ds->key->ptr[j]) : '_';
261
					}
262
					tmp->ptr[tmp->used++] = '\0';
263
					snprintf(key, 200, "#%s#", tmp->ptr);
264
					buffer_free(tmp);
265
					
266
					// Find environment variable in url:
267
					if((c = strstr(p->location->ptr, key)) == NULL) {
268
						continue;
269
					}
270

  
271
					cnt = c - p->location->ptr;
272

  
273
					// if find then replace this variable it's value:
274
					new_location = buffer_init();
275
					buffer_append_string_len(new_location, p->location->ptr, cnt);
276
					buffer_append_string_len(new_location, ds->value->ptr, strlen(ds->value->ptr));
277
					buffer_append_string_len(new_location, p->location->ptr+cnt+strlen(key), p->location->used-1-(cnt+strlen(key)));
278
					
279
					buffer_reset(p->location);
280
					buffer_copy_string_buffer(p->location, new_location);
281
					buffer_free(new_location);
282
				}
283
			}
284
			// end environment variable replacement
285

  
245 286
			response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(p->location));
246 287

  
247 288
			con->http_status = 301;