summaryrefslogtreecommitdiff
path: root/package/lighttpd/lighttpd-changeset-r2683.patch
blob: aacabad08b4315b5dc2a3aaa182843199627f475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
diff -Nura lighttpd-1.4.24/src/mod_rewrite.c lighttpd-1.4.24-changeset-r2683/src/mod_rewrite.c
--- lighttpd-1.4.24/src/mod_rewrite.c	2009-10-12 18:48:47.000000000 -0300
+++ lighttpd-1.4.24-changeset-r2683/src/mod_rewrite.c	2009-11-10 13:56:22.000000000 -0300
@@ -9,10 +9,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-typedef struct {
 #ifdef HAVE_PCRE_H
+typedef struct {
 	pcre *key;
-#endif
 
 	buffer *value;
 
@@ -70,7 +69,6 @@
 }
 
 static int rewrite_rule_buffer_append(rewrite_rule_buffer *kvb, buffer *key, buffer *value, int once) {
-#ifdef HAVE_PCRE_H
 	size_t i;
 	const char *errptr;
 	int erroff;
@@ -109,18 +107,9 @@
 	kvb->used++;
 
 	return 0;
-#else
-	UNUSED(kvb);
-	UNUSED(value);
-	UNUSED(once);
-	UNUSED(key);
-
-	return -1;
-#endif
 }
 
 static void rewrite_rule_buffer_free(rewrite_rule_buffer *kvb) {
-#ifdef HAVE_PCRE_H
 	size_t i;
 
 	for (i = 0; i < kvb->size; i++) {
@@ -130,7 +119,6 @@
 	}
 
 	if (kvb->ptr) free(kvb->ptr);
-#endif
 
 	free(kvb);
 }
@@ -201,24 +189,29 @@
 							    ((data_string *)(da->value->data[j]))->key,
 							    ((data_string *)(da->value->data[j]))->value,
 							    once)) {
-#ifdef HAVE_PCRE_H
 				log_error_write(srv, __FILE__, __LINE__, "sb",
 						"pcre-compile failed for", da->value->data[j]->key);
-#else
-				log_error_write(srv, __FILE__, __LINE__, "s",
-						"pcre support is missing, please install libpcre and the headers");
-#endif
 			}
 		}
 	}
 
 	return 0;
 }
+#else
+static int parse_config_entry(server *srv, array *ca, const char *option) {
+	static int logged_message = 0;
+	if (logged_message) return 0;
+	if (NULL != array_get_element(ca, option)) {
+		logged_message = 1;
+		log_error_write(srv, __FILE__, __LINE__, "s",
+			"pcre support is missing, please install libpcre and the headers");
+	}
+	return 0;
+}
+#endif
 
 SETDEFAULTS_FUNC(mod_rewrite_set_defaults) {
-	plugin_data *p = p_d;
 	size_t i = 0;
-
 	config_values_t cv[] = {
 		{ "url.rewrite-repeat",        NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
 		{ "url.rewrite-once",          NULL, T_CONFIG_LOCAL, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
@@ -243,33 +236,37 @@
 		{ NULL,                        NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
 	};
 
+#ifdef HAVE_PCRE_H
+	plugin_data *p = p_d;
+
 	if (!p) return HANDLER_ERROR;
 
 	/* 0 */
 	p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
+#else
+	UNUSED(p_d);
+#endif
 
 	for (i = 0; i < srv->config_context->used; i++) {
-		plugin_config *s;
 		array *ca;
+#ifdef HAVE_PCRE_H
+		plugin_config *s;
 
 		s = calloc(1, sizeof(plugin_config));
 		s->rewrite = rewrite_rule_buffer_init();
 		s->rewrite_NF = rewrite_rule_buffer_init();
-
-		cv[0].destination = s->rewrite;
-		cv[1].destination = s->rewrite;
-		cv[2].destination = s->rewrite_NF;
-		cv[3].destination = s->rewrite_NF;
-		cv[4].destination = s->rewrite;
-		cv[5].destination = s->rewrite;
-
 		p->config_storage[i] = s;
+#endif
+
 		ca = ((data_config *)srv->config_context->data[i])->value;
 
 		if (0 != config_insert_values_global(srv, ca, cv)) {
 			return HANDLER_ERROR;
 		}
 
+#ifndef HAVE_PCRE_H
+# define parse_config_entry(srv, ca, x, option, y) parse_config_entry(srv, ca, option)
+#endif
 		parse_config_entry(srv, ca, s->rewrite, "url.rewrite-once",      1);
 		parse_config_entry(srv, ca, s->rewrite, "url.rewrite-final",     1);
 		parse_config_entry(srv, ca, s->rewrite_NF, "url.rewrite-if-not-file",   1);
@@ -280,7 +277,9 @@
 
 	return HANDLER_GO_ON;
 }
+
 #ifdef HAVE_PCRE_H
+
 #define PATCH(x) \
 	p->conf.x = s->x;
 static int mod_rewrite_patch_connection(server *srv, connection *con, plugin_data *p) {
@@ -330,7 +329,7 @@
 
 	return 0;
 }
-#endif
+
 URIHANDLER_FUNC(mod_rewrite_con_reset) {
 	plugin_data *p = p_d;
 
@@ -345,7 +344,6 @@
 }
 
 static int process_rewrite_rules(server *srv, connection *con, plugin_data *p, rewrite_rule_buffer *kvb) {
-#ifdef HAVE_PCRE_H
 	size_t i;
 	handler_ctx *hctx;
 
@@ -444,19 +442,11 @@
 		}
 #undef N
 	}
-#else
-	UNUSED(srv);
-	UNUSED(con);
-	UNUSED(p);
-	UNUSED(hctx);
-	UNUSED(kvb);
-#endif
 
 	return HANDLER_GO_ON;
 }
 
 URIHANDLER_FUNC(mod_rewrite_physical) {
-#ifdef HAVE_PCRE_H
 	plugin_data *p = p_d;
 	handler_t r;
 	stat_cache_entry *sce;
@@ -480,17 +470,11 @@
 	default:
 		return r;
 	}
-#else
-	UNUSED(srv);
-	UNUSED(con);
-	UNUSED(p_d);
-#endif
 
 	return HANDLER_GO_ON;
 }
 
 URIHANDLER_FUNC(mod_rewrite_uri_handler) {
-#ifdef HAVE_PCRE_H
 	plugin_data *p = p_d;
 
 	mod_rewrite_patch_connection(srv, con, p);
@@ -498,29 +482,27 @@
 	if (!p->conf.rewrite) return HANDLER_GO_ON;
 
 	return process_rewrite_rules(srv, con, p, p->conf.rewrite);
-#else
-	UNUSED(srv);
-	UNUSED(con);
-	UNUSED(p_d);
-#endif
 
 	return HANDLER_GO_ON;
 }
+#endif
 
 int mod_rewrite_plugin_init(plugin *p);
 int mod_rewrite_plugin_init(plugin *p) {
 	p->version     = LIGHTTPD_VERSION_ID;
 	p->name        = buffer_init_string("rewrite");
 
+#ifdef HAVE_PCRE_H
 	p->init        = mod_rewrite_init;
 	/* it has to stay _raw as we are matching on uri + querystring
 	 */
 
 	p->handle_uri_raw = mod_rewrite_uri_handler;
 	p->handle_physical = mod_rewrite_physical;
-	p->set_defaults = mod_rewrite_set_defaults;
 	p->cleanup     = mod_rewrite_free;
 	p->connection_reset = mod_rewrite_con_reset;
+#endif
+	p->set_defaults = mod_rewrite_set_defaults;
 
 	p->data        = NULL;