Skip to content

Commit 70e2480

Browse files
committed
Fix various build scenarios with disabled upstream modules.
1 parent e447079 commit 70e2480

File tree

3 files changed

+140
-122
lines changed

3 files changed

+140
-122
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2010-08-11
2+
* Fix various build scenarios with disabled upstream modules.
3+
Reported by Johan Bergstroem.
4+
15
2010-06-08 VERSION 1.1
26
* Fix compatibility with nginx-0.8.40+.
37

config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
if [ "$HTTP_FASTCGI" = "YES" ]; then
2+
have=NGX_HTTP_FASTCGI . auto/have
3+
fi
4+
5+
if [ "$HTTP_UWSGI" = "YES" ]; then
6+
have=NGX_HTTP_UWSGI . auto/have
7+
fi
8+
19
ngx_addon_name=ngx_http_cache_purge_module
210
HTTP_MODULES="$HTTP_MODULES ngx_http_cache_purge_module"
311
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_cache_purge_module.c"

ngx_cache_purge_module.c

Lines changed: 128 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,31 @@
2626
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29+
#include <nginx.h>
2930
#include <ngx_config.h>
3031
#include <ngx_core.h>
3132
#include <ngx_http.h>
32-
#include <nginx.h>
33+
3334

3435
#if (NGX_HTTP_CACHE)
3536

37+
# if (NGX_HTTP_FASTCGI)
3638
char *ngx_http_fastcgi_cache_purge_conf(ngx_conf_t *cf,
3739
ngx_command_t *cmd, void *conf);
40+
ngx_int_t ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r);
41+
# endif /* NGX_HTTP_FASTCGI */
42+
43+
# if (NGX_HTTP_PROXY)
3844
char *ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf,
3945
ngx_command_t *cmd, void *conf);
40-
#if defined(nginx_version) && (nginx_version >= 8040)
46+
ngx_int_t ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r);
47+
# endif /* NGX_HTTP_PROXY */
48+
49+
# if (NGX_HTTP_UWSGI)
4150
char *ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf,
4251
ngx_command_t *cmd, void *conf);
43-
#endif
44-
45-
ngx_int_t ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r);
46-
ngx_int_t ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r);
47-
#if defined(nginx_version) && (nginx_version >= 8040)
4852
ngx_int_t ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r);
49-
#endif
53+
# endif /* NGX_HTTP_UWSGI */
5054

5155
ngx_int_t ngx_http_cache_purge_handler(ngx_http_request_t *r,
5256
ngx_http_file_cache_t *cache, ngx_http_complex_value_t *cache_key);
@@ -56,28 +60,32 @@ ngx_int_t ngx_http_file_cache_purge(ngx_http_request_t *r,
5660

5761
static ngx_command_t ngx_http_cache_purge_module_commands[] = {
5862

63+
# if (NGX_HTTP_FASTCGI)
5964
{ ngx_string("fastcgi_cache_purge"),
6065
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
6166
ngx_http_fastcgi_cache_purge_conf,
6267
NGX_HTTP_LOC_CONF_OFFSET,
6368
0,
6469
NULL },
70+
# endif /* NGX_HTTP_FASTCGI */
6571

72+
# if (NGX_HTTP_PROXY)
6673
{ ngx_string("proxy_cache_purge"),
6774
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
6875
ngx_http_proxy_cache_purge_conf,
6976
NGX_HTTP_LOC_CONF_OFFSET,
7077
0,
7178
NULL },
79+
# endif /* NGX_HTTP_PROXY */
7280

73-
#if defined(nginx_version) && (nginx_version >= 8040)
81+
# if (NGX_HTTP_UWSGI)
7482
{ ngx_string("uwsgi_cache_purge"),
7583
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
7684
ngx_http_uwsgi_cache_purge_conf,
7785
NGX_HTTP_LOC_CONF_OFFSET,
7886
0,
7987
NULL },
80-
#endif
88+
# endif /* NGX_HTTP_UWSGI */
8189

8290
ngx_null_command
8391
};
@@ -125,13 +133,9 @@ CRLF "</center>" CRLF
125133
"</html>" CRLF
126134
;
127135

136+
# if (NGX_HTTP_FASTCGI)
128137
extern ngx_module_t ngx_http_fastcgi_module;
129-
extern ngx_module_t ngx_http_proxy_module;
130-
#if defined(nginx_version) && (nginx_version >= 8040)
131-
extern ngx_module_t ngx_http_uwsgi_module;
132-
#endif
133138

134-
/* this is ugly workaround, find better solution... */
135139
typedef struct {
136140
ngx_http_upstream_conf_t upstream;
137141

@@ -146,88 +150,19 @@ typedef struct {
146150
ngx_array_t *fastcgi_lengths;
147151
ngx_array_t *fastcgi_values;
148152

149-
#if defined(nginx_version) && (nginx_version >= 8040)
153+
# if defined(nginx_version) && (nginx_version >= 8040)
150154
ngx_hash_t headers_hash;
151155
ngx_uint_t header_params;
152-
#endif
156+
# endif /* nginx_version >= 8040 */
153157

154158
ngx_http_complex_value_t cache_key;
155159

156-
#if (NGX_PCRE)
160+
# if (NGX_PCRE)
157161
ngx_regex_t *split_regex;
158162
ngx_str_t split_name;
159-
#endif
163+
# endif /* NGX_PCRE */
160164
} ngx_http_fastcgi_loc_conf_t;
161165

162-
typedef struct {
163-
ngx_str_t key_start;
164-
ngx_str_t schema;
165-
ngx_str_t host_header;
166-
ngx_str_t port;
167-
ngx_str_t uri;
168-
} ngx_http_proxy_vars_t;
169-
170-
typedef struct {
171-
ngx_http_upstream_conf_t upstream;
172-
173-
ngx_array_t *flushes;
174-
ngx_array_t *body_set_len;
175-
ngx_array_t *body_set;
176-
ngx_array_t *headers_set_len;
177-
ngx_array_t *headers_set;
178-
ngx_hash_t headers_set_hash;
179-
180-
ngx_array_t *headers_source;
181-
#if defined(nginx_version) && (nginx_version < 8040)
182-
ngx_array_t *headers_names;
183-
#endif
184-
185-
ngx_array_t *proxy_lengths;
186-
ngx_array_t *proxy_values;
187-
188-
ngx_array_t *redirects;
189-
190-
ngx_str_t body_source;
191-
192-
ngx_str_t method;
193-
ngx_str_t location;
194-
ngx_str_t url;
195-
196-
ngx_http_complex_value_t cache_key;
197-
198-
ngx_http_proxy_vars_t vars;
199-
200-
ngx_flag_t redirect;
201-
202-
ngx_uint_t headers_hash_max_size;
203-
ngx_uint_t headers_hash_bucket_size;
204-
} ngx_http_proxy_loc_conf_t;
205-
206-
#if defined(nginx_version) && (nginx_version >= 8040)
207-
typedef struct {
208-
ngx_http_upstream_conf_t upstream;
209-
210-
ngx_array_t *flushes;
211-
ngx_array_t *params_len;
212-
ngx_array_t *params;
213-
ngx_array_t *params_source;
214-
215-
ngx_hash_t headers_hash;
216-
ngx_uint_t header_params;
217-
218-
ngx_array_t *uwsgi_lengths;
219-
ngx_array_t *uwsgi_values;
220-
221-
ngx_http_complex_value_t cache_key;
222-
223-
ngx_str_t uwsgi_string;
224-
225-
ngx_uint_t modifier1;
226-
ngx_uint_t modifier2;
227-
} ngx_http_uwsgi_loc_conf_t;
228-
#endif
229-
/* end of ugly workaround */
230-
231166
char *
232167
ngx_http_fastcgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd,
233168
void *conf)
@@ -282,6 +217,69 @@ ngx_http_fastcgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd,
282217
return NGX_CONF_OK;
283218
}
284219

220+
ngx_int_t
221+
ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r)
222+
{
223+
ngx_http_fastcgi_loc_conf_t *flcf;
224+
225+
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_DELETE))) {
226+
return NGX_HTTP_NOT_ALLOWED;
227+
}
228+
229+
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
230+
231+
return ngx_http_cache_purge_handler(r, flcf->upstream.cache->data,
232+
&flcf->cache_key);
233+
}
234+
# endif /* NGX_HTTP_FASTCGI */
235+
236+
# if (NGX_HTTP_PROXY)
237+
extern ngx_module_t ngx_http_proxy_module;
238+
239+
typedef struct {
240+
ngx_str_t key_start;
241+
ngx_str_t schema;
242+
ngx_str_t host_header;
243+
ngx_str_t port;
244+
ngx_str_t uri;
245+
} ngx_http_proxy_vars_t;
246+
247+
typedef struct {
248+
ngx_http_upstream_conf_t upstream;
249+
250+
ngx_array_t *flushes;
251+
ngx_array_t *body_set_len;
252+
ngx_array_t *body_set;
253+
ngx_array_t *headers_set_len;
254+
ngx_array_t *headers_set;
255+
ngx_hash_t headers_set_hash;
256+
257+
ngx_array_t *headers_source;
258+
# if defined(nginx_version) && (nginx_version < 8040)
259+
ngx_array_t *headers_names;
260+
# endif /* nginx_version < 8040 */
261+
262+
ngx_array_t *proxy_lengths;
263+
ngx_array_t *proxy_values;
264+
265+
ngx_array_t *redirects;
266+
267+
ngx_str_t body_source;
268+
269+
ngx_str_t method;
270+
ngx_str_t location;
271+
ngx_str_t url;
272+
273+
ngx_http_complex_value_t cache_key;
274+
275+
ngx_http_proxy_vars_t vars;
276+
277+
ngx_flag_t redirect;
278+
279+
ngx_uint_t headers_hash_max_size;
280+
ngx_uint_t headers_hash_bucket_size;
281+
} ngx_http_proxy_loc_conf_t;
282+
285283
char *
286284
ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
287285
{
@@ -335,7 +333,47 @@ ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
335333
return NGX_CONF_OK;
336334
}
337335

338-
#if defined(nginx_version) && (nginx_version >= 8040)
336+
ngx_int_t
337+
ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
338+
{
339+
ngx_http_proxy_loc_conf_t *plcf;
340+
341+
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_DELETE))) {
342+
return NGX_HTTP_NOT_ALLOWED;
343+
}
344+
345+
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
346+
347+
return ngx_http_cache_purge_handler(r, plcf->upstream.cache->data,
348+
&plcf->cache_key);
349+
}
350+
# endif /* NGX_HTTP_PROXY */
351+
352+
# if (NGX_HTTP_UWSGI)
353+
extern ngx_module_t ngx_http_uwsgi_module;
354+
355+
typedef struct {
356+
ngx_http_upstream_conf_t upstream;
357+
358+
ngx_array_t *flushes;
359+
ngx_array_t *params_len;
360+
ngx_array_t *params;
361+
ngx_array_t *params_source;
362+
363+
ngx_hash_t headers_hash;
364+
ngx_uint_t header_params;
365+
366+
ngx_array_t *uwsgi_lengths;
367+
ngx_array_t *uwsgi_values;
368+
369+
ngx_http_complex_value_t cache_key;
370+
371+
ngx_str_t uwsgi_string;
372+
373+
ngx_uint_t modifier1;
374+
ngx_uint_t modifier2;
375+
} ngx_http_uwsgi_loc_conf_t;
376+
339377
char *
340378
ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
341379
{
@@ -388,39 +426,7 @@ ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
388426

389427
return NGX_CONF_OK;
390428
}
391-
#endif
392-
393-
ngx_int_t
394-
ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r)
395-
{
396-
ngx_http_fastcgi_loc_conf_t *flcf;
397-
398-
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_DELETE))) {
399-
return NGX_HTTP_NOT_ALLOWED;
400-
}
401-
402-
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
403-
404-
return ngx_http_cache_purge_handler(r, flcf->upstream.cache->data,
405-
&flcf->cache_key);
406-
}
407-
408-
ngx_int_t
409-
ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
410-
{
411-
ngx_http_proxy_loc_conf_t *plcf;
412-
413-
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_DELETE))) {
414-
return NGX_HTTP_NOT_ALLOWED;
415-
}
416-
417-
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
418-
419-
return ngx_http_cache_purge_handler(r, plcf->upstream.cache->data,
420-
&plcf->cache_key);
421-
}
422429

423-
#if defined(nginx_version) && (nginx_version >= 8040)
424430
ngx_int_t
425431
ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r)
426432
{
@@ -435,7 +441,7 @@ ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r)
435441
return ngx_http_cache_purge_handler(r, ulcf->upstream.cache->data,
436442
&ulcf->cache_key);
437443
}
438-
#endif
444+
# endif /* NGX_HTTP_UWSGI */
439445

440446
ngx_int_t
441447
ngx_http_cache_purge_handler(ngx_http_request_t *r,

0 commit comments

Comments
 (0)