Mercurial > hg > nginx
annotate src/http/modules/ngx_http_sub_filter_module.c @ 7347:b9b3518fa93b
Uwsgi: style.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 03 Sep 2018 19:17:01 +0300 |
parents | 201038680680 |
children |
rev | line source |
---|---|
1172 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
1172 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
14 ngx_http_complex_value_t match; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
15 ngx_http_complex_value_t value; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
16 } ngx_http_sub_pair_t; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
17 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
18 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
19 typedef struct { |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
20 ngx_str_t match; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
21 ngx_http_complex_value_t *value; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
22 } ngx_http_sub_match_t; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
23 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
24 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
25 typedef struct { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
26 ngx_uint_t min_match_len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
27 ngx_uint_t max_match_len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
28 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
29 u_char index[257]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
30 u_char shift[256]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
31 } ngx_http_sub_tables_t; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
32 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
33 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
34 typedef struct { |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
35 ngx_uint_t dynamic; /* unsigned dynamic:1; */ |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
36 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
37 ngx_array_t *pairs; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
38 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
39 ngx_http_sub_tables_t *tables; |
1172 | 40 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
41 ngx_hash_t types; |
1172 | 42 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
43 ngx_flag_t once; |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
44 ngx_flag_t last_modified; |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
45 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
46 ngx_array_t *types_keys; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
47 ngx_array_t *matches; |
1172 | 48 } ngx_http_sub_loc_conf_t; |
49 | |
50 | |
51 typedef struct { | |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
52 ngx_str_t saved; |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
53 ngx_str_t looked; |
1172 | 54 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
55 ngx_uint_t once; /* unsigned once:1 */ |
1172 | 56 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
57 ngx_buf_t *buf; |
1172 | 58 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
59 u_char *pos; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
60 u_char *copy_start; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
61 u_char *copy_end; |
1172 | 62 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
63 ngx_chain_t *in; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
64 ngx_chain_t *out; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
65 ngx_chain_t **last_out; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
66 ngx_chain_t *busy; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
67 ngx_chain_t *free; |
1172 | 68 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
69 ngx_str_t *sub; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
70 ngx_uint_t applied; |
1172 | 71 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
72 ngx_int_t offset; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
73 ngx_uint_t index; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
74 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
75 ngx_http_sub_tables_t *tables; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
76 ngx_array_t *matches; |
1172 | 77 } ngx_http_sub_ctx_t; |
78 | |
79 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
80 static ngx_uint_t ngx_http_sub_cmp_index; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
81 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
82 |
1172 | 83 static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r, |
84 ngx_http_sub_ctx_t *ctx); | |
85 static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r, | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
86 ngx_http_sub_ctx_t *ctx, ngx_uint_t flush); |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
87 static ngx_int_t ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start, |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
88 ngx_str_t *m); |
1172 | 89 |
90 static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, | |
91 void *conf); | |
92 static void *ngx_http_sub_create_conf(ngx_conf_t *cf); | |
93 static char *ngx_http_sub_merge_conf(ngx_conf_t *cf, | |
94 void *parent, void *child); | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
95 static void ngx_http_sub_init_tables(ngx_http_sub_tables_t *tables, |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
96 ngx_http_sub_match_t *match, ngx_uint_t n); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
97 static ngx_int_t ngx_http_sub_cmp_matches(const void *one, const void *two); |
1172 | 98 static ngx_int_t ngx_http_sub_filter_init(ngx_conf_t *cf); |
99 | |
100 | |
101 static ngx_command_t ngx_http_sub_filter_commands[] = { | |
102 | |
103 { ngx_string("sub_filter"), | |
104 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
105 ngx_http_sub_filter, | |
106 NGX_HTTP_LOC_CONF_OFFSET, | |
107 0, | |
108 NULL }, | |
109 | |
110 { ngx_string("sub_filter_types"), | |
111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
112 ngx_http_types_slot, |
1172 | 113 NGX_HTTP_LOC_CONF_OFFSET, |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
114 offsetof(ngx_http_sub_loc_conf_t, types_keys), |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
115 &ngx_http_html_default_types[0] }, |
1172 | 116 |
117 { ngx_string("sub_filter_once"), | |
118 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
119 ngx_conf_set_flag_slot, | |
120 NGX_HTTP_LOC_CONF_OFFSET, | |
121 offsetof(ngx_http_sub_loc_conf_t, once), | |
122 NULL }, | |
123 | |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
124 { ngx_string("sub_filter_last_modified"), |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
125 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
126 ngx_conf_set_flag_slot, |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
127 NGX_HTTP_LOC_CONF_OFFSET, |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
128 offsetof(ngx_http_sub_loc_conf_t, last_modified), |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
129 NULL }, |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
130 |
1172 | 131 ngx_null_command |
132 }; | |
133 | |
134 | |
135 static ngx_http_module_t ngx_http_sub_filter_module_ctx = { | |
136 NULL, /* preconfiguration */ | |
137 ngx_http_sub_filter_init, /* postconfiguration */ | |
138 | |
139 NULL, /* create main configuration */ | |
140 NULL, /* init main configuration */ | |
141 | |
142 NULL, /* create server configuration */ | |
143 NULL, /* merge server configuration */ | |
144 | |
145 ngx_http_sub_create_conf, /* create location configuration */ | |
146 ngx_http_sub_merge_conf /* merge location configuration */ | |
147 }; | |
148 | |
149 | |
150 ngx_module_t ngx_http_sub_filter_module = { | |
151 NGX_MODULE_V1, | |
152 &ngx_http_sub_filter_module_ctx, /* module context */ | |
153 ngx_http_sub_filter_commands, /* module directives */ | |
154 NGX_HTTP_MODULE, /* module type */ | |
155 NULL, /* init master */ | |
156 NULL, /* init module */ | |
157 NULL, /* init process */ | |
158 NULL, /* init thread */ | |
159 NULL, /* exit thread */ | |
160 NULL, /* exit process */ | |
161 NULL, /* exit master */ | |
162 NGX_MODULE_V1_PADDING | |
163 }; | |
164 | |
165 | |
166 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
167 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
168 | |
169 | |
170 static ngx_int_t | |
171 ngx_http_sub_header_filter(ngx_http_request_t *r) | |
172 { | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
173 ngx_str_t *m; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
174 ngx_uint_t i, j, n; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
175 ngx_http_sub_ctx_t *ctx; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
176 ngx_http_sub_pair_t *pairs; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
177 ngx_http_sub_match_t *matches; |
1172 | 178 ngx_http_sub_loc_conf_t *slcf; |
179 | |
180 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module); | |
181 | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
182 if (slcf->pairs == NULL |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
183 || r->headers_out.content_length_n == 0 |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
184 || ngx_http_test_content_type(r, &slcf->types) == NULL) |
1172 | 185 { |
186 return ngx_http_next_header_filter(r); | |
187 } | |
188 | |
189 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_sub_ctx_t)); | |
190 if (ctx == NULL) { | |
191 return NGX_ERROR; | |
192 } | |
193 | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
194 if (slcf->dynamic == 0) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
195 ctx->tables = slcf->tables; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
196 ctx->matches = slcf->matches; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
197 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
198 } else { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
199 pairs = slcf->pairs->elts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
200 n = slcf->pairs->nelts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
201 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
202 matches = ngx_pcalloc(r->pool, sizeof(ngx_http_sub_match_t) * n); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
203 if (matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
204 return NGX_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
205 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
206 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
207 j = 0; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
208 for (i = 0; i < n; i++) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
209 matches[j].value = &pairs[i].value; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
210 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
211 if (pairs[i].match.lengths == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
212 matches[j].match = pairs[i].match.value; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
213 j++; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
214 continue; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
215 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
216 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
217 m = &matches[j].match; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
218 if (ngx_http_complex_value(r, &pairs[i].match, m) != NGX_OK) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
219 return NGX_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
220 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
221 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
222 if (m->len == 0) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
223 continue; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
224 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
225 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
226 ngx_strlow(m->data, m->data, m->len); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
227 j++; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
228 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
229 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
230 if (j == 0) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
231 return ngx_http_next_header_filter(r); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
232 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
233 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
234 ctx->matches = ngx_palloc(r->pool, sizeof(ngx_array_t)); |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
235 if (ctx->matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
236 return NGX_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
237 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
238 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
239 ctx->matches->elts = matches; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
240 ctx->matches->nelts = j; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
241 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
242 ctx->tables = ngx_palloc(r->pool, sizeof(ngx_http_sub_tables_t)); |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
243 if (ctx->tables == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
244 return NGX_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
245 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
246 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
247 ngx_http_sub_init_tables(ctx->tables, ctx->matches->elts, |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
248 ctx->matches->nelts); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
249 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
250 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
251 ctx->saved.data = ngx_pnalloc(r->pool, ctx->tables->max_match_len - 1); |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
252 if (ctx->saved.data == NULL) { |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
253 return NGX_ERROR; |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
254 } |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
255 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
256 ctx->looked.data = ngx_pnalloc(r->pool, ctx->tables->max_match_len - 1); |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
257 if (ctx->looked.data == NULL) { |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
258 return NGX_ERROR; |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
259 } |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
260 |
6984
201038680680
Sub filter: restored ngx_http_set_ctx() at the proper place.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6860
diff
changeset
|
261 ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module); |
201038680680
Sub filter: restored ngx_http_set_ctx() at the proper place.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6860
diff
changeset
|
262 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
263 ctx->offset = ctx->tables->min_match_len - 1; |
1172 | 264 ctx->last_out = &ctx->out; |
265 | |
266 r->filter_need_in_memory = 1; | |
267 | |
268 if (r == r->main) { | |
269 ngx_http_clear_content_length(r); | |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
270 |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
271 if (!slcf->last_modified) { |
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
272 ngx_http_clear_last_modified(r); |
5733
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5710
diff
changeset
|
273 ngx_http_clear_etag(r); |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5710
diff
changeset
|
274 |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5710
diff
changeset
|
275 } else { |
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5710
diff
changeset
|
276 ngx_http_weak_etag(r); |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
277 } |
1172 | 278 } |
279 | |
280 return ngx_http_next_header_filter(r); | |
281 } | |
282 | |
283 | |
284 static ngx_int_t | |
285 ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
286 { | |
287 ngx_int_t rc; | |
288 ngx_buf_t *b; | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
289 ngx_str_t *sub; |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
290 ngx_uint_t flush, last; |
1172 | 291 ngx_chain_t *cl; |
292 ngx_http_sub_ctx_t *ctx; | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
293 ngx_http_sub_match_t *match; |
1172 | 294 ngx_http_sub_loc_conf_t *slcf; |
295 | |
296 ctx = ngx_http_get_module_ctx(r, ngx_http_sub_filter_module); | |
297 | |
298 if (ctx == NULL) { | |
299 return ngx_http_next_body_filter(r, in); | |
300 } | |
301 | |
302 if ((in == NULL | |
303 && ctx->buf == NULL | |
304 && ctx->in == NULL | |
305 && ctx->busy == NULL)) | |
306 { | |
307 return ngx_http_next_body_filter(r, in); | |
308 } | |
309 | |
310 if (ctx->once && (ctx->buf == NULL || ctx->in == NULL)) { | |
311 | |
312 if (ctx->busy) { | |
313 if (ngx_http_sub_output(r, ctx) == NGX_ERROR) { | |
314 return NGX_ERROR; | |
315 } | |
316 } | |
317 | |
318 return ngx_http_next_body_filter(r, in); | |
319 } | |
320 | |
321 /* add the incoming chain to the chain ctx->in */ | |
322 | |
323 if (in) { | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2414
diff
changeset
|
324 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) { |
1172 | 325 return NGX_ERROR; |
326 } | |
327 } | |
328 | |
329 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
330 "http sub filter \"%V\"", &r->uri); | |
331 | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
332 flush = 0; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
333 last = 0; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
334 |
1172 | 335 while (ctx->in || ctx->buf) { |
336 | |
3642 | 337 if (ctx->buf == NULL) { |
1172 | 338 ctx->buf = ctx->in->buf; |
339 ctx->in = ctx->in->next; | |
340 ctx->pos = ctx->buf->pos; | |
341 } | |
342 | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
343 if (ctx->buf->flush || ctx->buf->recycled) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
344 flush = 1; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
345 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
346 |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
347 if (ctx->in == NULL) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
348 last = flush; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
349 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
350 |
1172 | 351 b = NULL; |
352 | |
353 while (ctx->pos < ctx->buf->last) { | |
354 | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
355 rc = ngx_http_sub_parse(r, ctx, last); |
1172 | 356 |
357 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
6480 | 358 "parse: %i, looked: \"%V\" %p-%p", |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
359 rc, &ctx->looked, ctx->copy_start, ctx->copy_end); |
1172 | 360 |
361 if (rc == NGX_ERROR) { | |
362 return rc; | |
363 } | |
364 | |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
365 if (ctx->saved.len) { |
1172 | 366 |
367 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
368 "saved: \"%V\"", &ctx->saved); |
1172 | 369 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
370 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
371 if (cl == NULL) { |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
372 return NGX_ERROR; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
373 } |
1172 | 374 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
375 b = cl->buf; |
1172 | 376 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
377 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 378 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
379 b->pos = ngx_pnalloc(r->pool, ctx->saved.len); |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
380 if (b->pos == NULL) { |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
381 return NGX_ERROR; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
382 } |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
383 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
384 ngx_memcpy(b->pos, ctx->saved.data, ctx->saved.len); |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
385 b->last = b->pos + ctx->saved.len; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
386 b->memory = 1; |
1172 | 387 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
388 *ctx->last_out = cl; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
389 ctx->last_out = &cl->next; |
1172 | 390 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
391 ctx->saved.len = 0; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
392 } |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
393 |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
394 if (ctx->copy_start != ctx->copy_end) { |
1172 | 395 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
396 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
397 if (cl == NULL) { |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
398 return NGX_ERROR; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
399 } |
1172 | 400 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
401 b = cl->buf; |
1172 | 402 |
403 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t)); | |
404 | |
405 b->pos = ctx->copy_start; | |
406 b->last = ctx->copy_end; | |
407 b->shadow = NULL; | |
408 b->last_buf = 0; | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
409 b->last_in_chain = 0; |
1172 | 410 b->recycled = 0; |
411 | |
412 if (b->in_file) { | |
2079
333ef9e18a59
fix error when response parsed by sub filter, then by SSI filter
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
413 b->file_last = b->file_pos + (b->last - ctx->buf->pos); |
333ef9e18a59
fix error when response parsed by sub filter, then by SSI filter
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
414 b->file_pos += b->pos - ctx->buf->pos; |
1172 | 415 } |
416 | |
417 *ctx->last_out = cl; | |
418 ctx->last_out = &cl->next; | |
419 } | |
420 | |
421 if (rc == NGX_AGAIN) { | |
422 continue; | |
423 } | |
424 | |
425 | |
426 /* rc == NGX_OK */ | |
427 | |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
428 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
429 if (cl == NULL) { |
1172 | 430 return NGX_ERROR; |
431 } | |
432 | |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
433 b = cl->buf; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
434 |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
435 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 436 |
437 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module); | |
438 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
439 if (ctx->sub == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
440 ctx->sub = ngx_pcalloc(r->pool, sizeof(ngx_str_t) |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
441 * ctx->matches->nelts); |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
442 if (ctx->sub == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
443 return NGX_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
444 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
445 } |
1172 | 446 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
447 sub = &ctx->sub[ctx->index]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
448 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
449 if (sub->data == NULL) { |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
450 match = ctx->matches->elts; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
451 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
452 if (ngx_http_complex_value(r, match[ctx->index].value, sub) |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
453 != NGX_OK) |
1172 | 454 { |
455 return NGX_ERROR; | |
456 } | |
457 } | |
458 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
459 if (sub->len) { |
1555
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
460 b->memory = 1; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
461 b->pos = sub->data; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
462 b->last = sub->data + sub->len; |
1555
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
463 |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
464 } else { |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
465 b->sync = 1; |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
466 } |
1172 | 467 |
468 *ctx->last_out = cl; | |
469 ctx->last_out = &cl->next; | |
470 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
471 ctx->index = 0; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
472 ctx->once = slcf->once && (++ctx->applied == ctx->matches->nelts); |
1172 | 473 |
474 continue; | |
475 } | |
476 | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
477 if (ctx->looked.len |
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
478 && (ctx->buf->last_buf || ctx->buf->last_in_chain)) |
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
479 { |
5287
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
480 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
481 if (cl == NULL) { |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
482 return NGX_ERROR; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
483 } |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
484 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
485 b = cl->buf; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
486 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
487 ngx_memzero(b, sizeof(ngx_buf_t)); |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
488 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
489 b->pos = ctx->looked.data; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
490 b->last = b->pos + ctx->looked.len; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
491 b->memory = 1; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
492 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
493 *ctx->last_out = cl; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
494 ctx->last_out = &cl->next; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
495 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
496 ctx->looked.len = 0; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
497 } |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
498 |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
499 if (ctx->buf->last_buf || ctx->buf->flush || ctx->buf->sync |
5286
819c5b53d8b5
Sub filter: flush buffers handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5285
diff
changeset
|
500 || ngx_buf_in_memory(ctx->buf)) |
819c5b53d8b5
Sub filter: flush buffers handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5285
diff
changeset
|
501 { |
1172 | 502 if (b == NULL) { |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
503 cl = ngx_chain_get_free_buf(r->pool, &ctx->free); |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
504 if (cl == NULL) { |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
505 return NGX_ERROR; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
506 } |
1172 | 507 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
508 b = cl->buf; |
1172 | 509 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
510 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 511 |
512 b->sync = 1; | |
513 | |
514 *ctx->last_out = cl; | |
515 ctx->last_out = &cl->next; | |
516 } | |
517 | |
518 b->last_buf = ctx->buf->last_buf; | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
519 b->last_in_chain = ctx->buf->last_in_chain; |
5286
819c5b53d8b5
Sub filter: flush buffers handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5285
diff
changeset
|
520 b->flush = ctx->buf->flush; |
1172 | 521 b->shadow = ctx->buf; |
522 | |
523 b->recycled = ctx->buf->recycled; | |
524 } | |
525 | |
526 ctx->buf = NULL; | |
527 } | |
528 | |
529 if (ctx->out == NULL && ctx->busy == NULL) { | |
530 return NGX_OK; | |
531 } | |
532 | |
533 return ngx_http_sub_output(r, ctx); | |
534 } | |
535 | |
536 | |
537 static ngx_int_t | |
538 ngx_http_sub_output(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx) | |
539 { | |
540 ngx_int_t rc; | |
541 ngx_buf_t *b; | |
542 ngx_chain_t *cl; | |
543 | |
544 #if 1 | |
545 b = NULL; | |
546 for (cl = ctx->out; cl; cl = cl->next) { | |
547 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
548 "sub out: %p %p", cl->buf, cl->buf->pos); | |
549 if (cl->buf == b) { | |
550 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
551 "the same buf was used in sub"); | |
552 ngx_debug_point(); | |
553 return NGX_ERROR; | |
554 } | |
555 b = cl->buf; | |
556 } | |
557 #endif | |
558 | |
559 rc = ngx_http_next_body_filter(r, ctx->out); | |
560 | |
561 if (ctx->busy == NULL) { | |
562 ctx->busy = ctx->out; | |
563 | |
564 } else { | |
565 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
566 cl->next = ctx->out; | |
567 } | |
568 | |
569 ctx->out = NULL; | |
570 ctx->last_out = &ctx->out; | |
571 | |
572 while (ctx->busy) { | |
573 | |
574 cl = ctx->busy; | |
575 b = cl->buf; | |
576 | |
577 if (ngx_buf_size(b) != 0) { | |
578 break; | |
579 } | |
580 | |
581 if (b->shadow) { | |
582 b->shadow->pos = b->shadow->last; | |
583 } | |
584 | |
585 ctx->busy = cl->next; | |
586 | |
587 if (ngx_buf_in_memory(b) || b->in_file) { | |
588 /* add data bufs only to the free buf chain */ | |
589 | |
590 cl->next = ctx->free; | |
591 ctx->free = cl; | |
592 } | |
593 } | |
594 | |
595 if (ctx->in || ctx->buf) { | |
596 r->buffered |= NGX_HTTP_SUB_BUFFERED; | |
597 | |
598 } else { | |
599 r->buffered &= ~NGX_HTTP_SUB_BUFFERED; | |
600 } | |
601 | |
602 return rc; | |
603 } | |
604 | |
605 | |
606 static ngx_int_t | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
607 ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx, |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
608 ngx_uint_t flush) |
1172 | 609 { |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
610 u_char *p, c; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
611 ngx_str_t *m; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
612 ngx_int_t offset, start, next, end, len, rc; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
613 ngx_uint_t shift, i, j; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
614 ngx_http_sub_match_t *match; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
615 ngx_http_sub_tables_t *tables; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
616 ngx_http_sub_loc_conf_t *slcf; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
617 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
618 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module); |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
619 tables = ctx->tables; |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
620 match = ctx->matches->elts; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
621 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
622 offset = ctx->offset; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
623 end = ctx->buf->last - ctx->pos; |
1172 | 624 |
625 if (ctx->once) { | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
626 /* sets start and next to end */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
627 offset = end + (ngx_int_t) tables->min_match_len - 1; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
628 goto again; |
1172 | 629 } |
630 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
631 while (offset < end) { |
1172 | 632 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
633 c = offset < 0 ? ctx->looked.data[ctx->looked.len + offset] |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
634 : ctx->pos[offset]; |
5810
5322be87fc02
Sub filter: fixed matching for a single character.
Valentin Bartenev <vbart@nginx.com>
parents:
5733
diff
changeset
|
635 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
636 c = ngx_tolower(c); |
1172 | 637 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
638 shift = tables->shift[c]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
639 if (shift > 0) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
640 offset += shift; |
1172 | 641 continue; |
642 } | |
643 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
644 /* a potential match */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
645 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
646 start = offset - (ngx_int_t) tables->min_match_len + 1; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
647 |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6605
diff
changeset
|
648 i = ngx_max((ngx_uint_t) tables->index[c], ctx->index); |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
649 j = tables->index[c + 1]; |
1172 | 650 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
651 while (i != j) { |
1172 | 652 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
653 if (slcf->once && ctx->sub && ctx->sub[i].data) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
654 goto next; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
655 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
656 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
657 m = &match[i].match; |
1557
9d094e581587
*) add sub_filter parser fix similar to r1261 in SSI parser
Igor Sysoev <igor@sysoev.ru>
parents:
1555
diff
changeset
|
658 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
659 rc = ngx_http_sub_match(ctx, start, m); |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
660 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
661 if (rc == NGX_DECLINED) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
662 goto next; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
663 } |
1172 | 664 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
665 ctx->index = i; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
666 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
667 if (rc == NGX_AGAIN) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
668 goto again; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
669 } |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
670 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
671 ctx->offset = offset + (ngx_int_t) m->len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
672 next = start + (ngx_int_t) m->len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
673 end = ngx_max(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
674 rc = NGX_OK; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
675 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
676 goto done; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
677 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
678 next: |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
679 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
680 i++; |
1172 | 681 } |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
682 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
683 offset++; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
684 ctx->index = 0; |
1172 | 685 } |
686 | |
6605
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
687 if (flush) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
688 for ( ;; ) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
689 start = offset - (ngx_int_t) tables->min_match_len + 1; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
690 |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
691 if (start >= end) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
692 break; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
693 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
694 |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
695 for (i = 0; i < ctx->matches->nelts; i++) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
696 m = &match[i].match; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
697 |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
698 if (ngx_http_sub_match(ctx, start, m) == NGX_AGAIN) { |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
699 goto again; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
700 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
701 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
702 |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
703 offset++; |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
704 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
705 } |
f379b32e4733
Sub filter: eliminate unnecessary buffering.
Roman Arutyunyan <arut@nginx.com>
parents:
6604
diff
changeset
|
706 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
707 again: |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
708 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
709 ctx->offset = offset; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
710 start = offset - (ngx_int_t) tables->min_match_len + 1; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
711 next = start; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
712 rc = NGX_AGAIN; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
713 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
714 done: |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
715 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
716 /* send [ - looked.len, start ] to client */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
717 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
718 ctx->saved.len = ctx->looked.len + ngx_min(start, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
719 ngx_memcpy(ctx->saved.data, ctx->looked.data, ctx->saved.len); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
720 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
721 ctx->copy_start = ctx->pos; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
722 ctx->copy_end = ctx->pos + ngx_max(start, 0); |
1172 | 723 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
724 /* save [ next, end ] in looked */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
725 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
726 len = ngx_min(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
727 p = ctx->looked.data; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
728 p = ngx_movemem(p, p + ctx->looked.len + len, - len); |
1172 | 729 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
730 len = ngx_max(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
731 p = ngx_cpymem(p, ctx->pos + len, end - len); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
732 ctx->looked.len = p - ctx->looked.data; |
1172 | 733 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
734 /* update position */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
735 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
736 ctx->pos += end; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
737 ctx->offset -= end; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
738 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
739 return rc; |
1172 | 740 } |
741 | |
742 | |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
743 static ngx_int_t |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
744 ngx_http_sub_match(ngx_http_sub_ctx_t *ctx, ngx_int_t start, ngx_str_t *m) |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
745 { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
746 u_char *p, *last, *pat, *pat_end; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
747 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
748 pat = m->data; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
749 pat_end = m->data + m->len; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
750 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
751 if (start >= 0) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
752 p = ctx->pos + start; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
753 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
754 } else { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
755 last = ctx->looked.data + ctx->looked.len; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
756 p = last + start; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
757 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
758 while (p < last && pat < pat_end) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
759 if (ngx_tolower(*p) != *pat) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
760 return NGX_DECLINED; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
761 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
762 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
763 p++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
764 pat++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
765 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
766 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
767 p = ctx->pos; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
768 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
769 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
770 while (p < ctx->buf->last && pat < pat_end) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
771 if (ngx_tolower(*p) != *pat) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
772 return NGX_DECLINED; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
773 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
774 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
775 p++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
776 pat++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
777 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
778 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
779 if (pat != pat_end) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
780 /* partial match */ |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
781 return NGX_AGAIN; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
782 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
783 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
784 return NGX_OK; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
785 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
786 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
787 |
1172 | 788 static char * |
789 ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
790 { | |
791 ngx_http_sub_loc_conf_t *slcf = conf; | |
792 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
793 ngx_str_t *value; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
794 ngx_http_sub_pair_t *pair; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
795 ngx_http_compile_complex_value_t ccv; |
1172 | 796 |
797 value = cf->args->elts; | |
798 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
799 if (value[1].len == 0) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
800 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "empty search pattern"); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
801 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
802 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
803 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
804 if (slcf->pairs == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
805 slcf->pairs = ngx_array_create(cf->pool, 1, |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
806 sizeof(ngx_http_sub_pair_t)); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
807 if (slcf->pairs == NULL) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
808 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
809 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
810 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
811 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
812 if (slcf->pairs->nelts == 255) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
813 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
814 "number of search patterns exceeds 255"); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
815 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
816 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
817 |
2135 | 818 ngx_strlow(value[1].data, value[1].data, value[1].len); |
1172 | 819 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
820 pair = ngx_array_push(slcf->pairs); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
821 if (pair == NULL) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
822 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
823 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
824 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
825 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
826 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
827 ccv.cf = cf; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
828 ccv.value = &value[1]; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
829 ccv.complex_value = &pair->match; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
830 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
831 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
832 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
833 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
834 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
835 if (ccv.complex_value->lengths != NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
836 slcf->dynamic = 1; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
837 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
838 } else { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
839 ngx_strlow(pair->match.value.data, pair->match.value.data, |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
840 pair->match.value.len); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
841 } |
1172 | 842 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
843 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
1172 | 844 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
845 ccv.cf = cf; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
846 ccv.value = &value[2]; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
847 ccv.complex_value = &pair->value; |
1172 | 848 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
849 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
1172 | 850 return NGX_CONF_ERROR; |
851 } | |
852 | |
853 return NGX_CONF_OK; | |
854 } | |
855 | |
856 | |
857 static void * | |
858 ngx_http_sub_create_conf(ngx_conf_t *cf) | |
859 { | |
860 ngx_http_sub_loc_conf_t *slcf; | |
861 | |
862 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_sub_loc_conf_t)); | |
863 if (slcf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
864 return NULL; |
1172 | 865 } |
866 | |
867 /* | |
868 * set by ngx_pcalloc(): | |
869 * | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
870 * conf->dynamic = 0; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
871 * conf->pairs = NULL; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
872 * conf->tables = NULL; |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
873 * conf->types = { NULL }; |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
874 * conf->types_keys = NULL; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
875 * conf->matches = NULL; |
1172 | 876 */ |
877 | |
878 slcf->once = NGX_CONF_UNSET; | |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
879 slcf->last_modified = NGX_CONF_UNSET; |
1172 | 880 |
881 return slcf; | |
882 } | |
883 | |
884 | |
885 static char * | |
886 ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
887 { | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
888 ngx_uint_t i, n; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
889 ngx_http_sub_pair_t *pairs; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
890 ngx_http_sub_match_t *matches; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
891 ngx_http_sub_loc_conf_t *prev = parent; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
892 ngx_http_sub_loc_conf_t *conf = child; |
1172 | 893 |
894 ngx_conf_merge_value(conf->once, prev->once, 1); | |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
895 ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0); |
1172 | 896 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
897 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types, |
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
898 &prev->types_keys, &prev->types, |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
899 ngx_http_html_default_types) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
900 != NGX_OK) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
901 { |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
902 return NGX_CONF_ERROR; |
1172 | 903 } |
904 | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
905 if (conf->pairs == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
906 conf->dynamic = prev->dynamic; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
907 conf->pairs = prev->pairs; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
908 conf->matches = prev->matches; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
909 conf->tables = prev->tables; |
6247
fbbb1c1ce1eb
Sub filter: fixed initialization in http{} level (ticket #791).
Roman Arutyunyan <arut@nginx.com>
parents:
6229
diff
changeset
|
910 } |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
911 |
6247
fbbb1c1ce1eb
Sub filter: fixed initialization in http{} level (ticket #791).
Roman Arutyunyan <arut@nginx.com>
parents:
6229
diff
changeset
|
912 if (conf->pairs && conf->dynamic == 0 && conf->tables == NULL) { |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
913 pairs = conf->pairs->elts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
914 n = conf->pairs->nelts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
915 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
916 matches = ngx_palloc(cf->pool, sizeof(ngx_http_sub_match_t) * n); |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
917 if (matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
918 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
919 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
920 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
921 for (i = 0; i < n; i++) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
922 matches[i].match = pairs[i].match.value; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
923 matches[i].value = &pairs[i].value; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
924 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
925 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
926 conf->matches = ngx_palloc(cf->pool, sizeof(ngx_array_t)); |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
927 if (conf->matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
928 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
929 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
930 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
931 conf->matches->elts = matches; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
932 conf->matches->nelts = n; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
933 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
934 conf->tables = ngx_palloc(cf->pool, sizeof(ngx_http_sub_tables_t)); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
935 if (conf->tables == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
936 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
937 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
938 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
939 ngx_http_sub_init_tables(conf->tables, conf->matches->elts, |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
940 conf->matches->nelts); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
941 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
942 |
1172 | 943 return NGX_CONF_OK; |
944 } | |
945 | |
946 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
947 static void |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
948 ngx_http_sub_init_tables(ngx_http_sub_tables_t *tables, |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
949 ngx_http_sub_match_t *match, ngx_uint_t n) |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
950 { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
951 u_char c; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
952 ngx_uint_t i, j, min, max, ch; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
953 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
954 min = match[0].match.len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
955 max = match[0].match.len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
956 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
957 for (i = 1; i < n; i++) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
958 min = ngx_min(min, match[i].match.len); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
959 max = ngx_max(max, match[i].match.len); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
960 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
961 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
962 tables->min_match_len = min; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
963 tables->max_match_len = max; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
964 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
965 ngx_http_sub_cmp_index = tables->min_match_len - 1; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
966 ngx_sort(match, n, sizeof(ngx_http_sub_match_t), ngx_http_sub_cmp_matches); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
967 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
968 min = ngx_min(min, 255); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
969 ngx_memset(tables->shift, min, 256); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
970 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
971 ch = 0; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
972 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
973 for (i = 0; i < n; i++) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
974 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
975 for (j = 0; j < min; j++) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
976 c = match[i].match.data[tables->min_match_len - 1 - j]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
977 tables->shift[c] = ngx_min(tables->shift[c], (u_char) j); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
978 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
979 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
980 c = match[i].match.data[tables->min_match_len - 1]; |
6860
f18c285c2e59
Win32: fixed some warnings reported by Borland C.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6605
diff
changeset
|
981 while (ch <= (ngx_uint_t) c) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
982 tables->index[ch++] = (u_char) i; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
983 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
984 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
985 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
986 while (ch < 257) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
987 tables->index[ch++] = (u_char) n; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
988 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
989 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
990 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
991 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
992 static ngx_int_t |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
993 ngx_http_sub_cmp_matches(const void *one, const void *two) |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
994 { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
995 ngx_int_t c1, c2; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
996 ngx_http_sub_match_t *first, *second; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
997 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
998 first = (ngx_http_sub_match_t *) one; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
999 second = (ngx_http_sub_match_t *) two; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1000 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1001 c1 = first->match.data[ngx_http_sub_cmp_index]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1002 c2 = second->match.data[ngx_http_sub_cmp_index]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1003 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1004 return c1 - c2; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1005 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1006 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
1007 |
1172 | 1008 static ngx_int_t |
1009 ngx_http_sub_filter_init(ngx_conf_t *cf) | |
1010 { | |
1011 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
1012 ngx_http_top_header_filter = ngx_http_sub_header_filter; | |
1013 | |
1014 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1015 ngx_http_top_body_filter = ngx_http_sub_body_filter; | |
1016 | |
1017 return NGX_OK; | |
1018 } |