Mercurial > hg > nginx
annotate src/http/modules/ngx_http_sub_filter_module.c @ 6604:0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
No functional changes.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Sat, 02 Jul 2016 15:59:52 +0300 |
parents | f01ab2dbcfdc |
children | f379b32e4733 |
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, | |
86 ngx_http_sub_ctx_t *ctx); | |
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 ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
252 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 } |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
257 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 } |
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
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; |
1172 | 290 ngx_chain_t *cl; |
291 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
|
292 ngx_http_sub_match_t *match; |
1172 | 293 ngx_http_sub_loc_conf_t *slcf; |
294 | |
295 ctx = ngx_http_get_module_ctx(r, ngx_http_sub_filter_module); | |
296 | |
297 if (ctx == NULL) { | |
298 return ngx_http_next_body_filter(r, in); | |
299 } | |
300 | |
301 if ((in == NULL | |
302 && ctx->buf == NULL | |
303 && ctx->in == NULL | |
304 && ctx->busy == NULL)) | |
305 { | |
306 return ngx_http_next_body_filter(r, in); | |
307 } | |
308 | |
309 if (ctx->once && (ctx->buf == NULL || ctx->in == NULL)) { | |
310 | |
311 if (ctx->busy) { | |
312 if (ngx_http_sub_output(r, ctx) == NGX_ERROR) { | |
313 return NGX_ERROR; | |
314 } | |
315 } | |
316 | |
317 return ngx_http_next_body_filter(r, in); | |
318 } | |
319 | |
320 /* add the incoming chain to the chain ctx->in */ | |
321 | |
322 if (in) { | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2414
diff
changeset
|
323 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) { |
1172 | 324 return NGX_ERROR; |
325 } | |
326 } | |
327 | |
328 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
329 "http sub filter \"%V\"", &r->uri); | |
330 | |
331 while (ctx->in || ctx->buf) { | |
332 | |
3642 | 333 if (ctx->buf == NULL) { |
1172 | 334 ctx->buf = ctx->in->buf; |
335 ctx->in = ctx->in->next; | |
336 ctx->pos = ctx->buf->pos; | |
337 } | |
338 | |
339 b = NULL; | |
340 | |
341 while (ctx->pos < ctx->buf->last) { | |
342 | |
343 rc = ngx_http_sub_parse(r, ctx); | |
344 | |
345 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
6480 | 346 "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
|
347 rc, &ctx->looked, ctx->copy_start, ctx->copy_end); |
1172 | 348 |
349 if (rc == NGX_ERROR) { | |
350 return rc; | |
351 } | |
352 | |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
353 if (ctx->saved.len) { |
1172 | 354 |
355 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
|
356 "saved: \"%V\"", &ctx->saved); |
1172 | 357 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
358 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
|
359 if (cl == NULL) { |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
360 return NGX_ERROR; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
361 } |
1172 | 362 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
363 b = cl->buf; |
1172 | 364 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
365 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 366 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
367 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
|
368 if (b->pos == NULL) { |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
369 return NGX_ERROR; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
370 } |
3675
08d7165b6be1
fix case of partially matched patterns on buffer border in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
3642
diff
changeset
|
371 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
372 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
|
373 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
|
374 b->memory = 1; |
1172 | 375 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
376 *ctx->last_out = cl; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
377 ctx->last_out = &cl->next; |
1172 | 378 |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
379 ctx->saved.len = 0; |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
380 } |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
381 |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
382 if (ctx->copy_start != ctx->copy_end) { |
1172 | 383 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
384 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
|
385 if (cl == NULL) { |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
386 return NGX_ERROR; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
387 } |
1172 | 388 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
389 b = cl->buf; |
1172 | 390 |
391 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t)); | |
392 | |
393 b->pos = ctx->copy_start; | |
394 b->last = ctx->copy_end; | |
395 b->shadow = NULL; | |
396 b->last_buf = 0; | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
397 b->last_in_chain = 0; |
1172 | 398 b->recycled = 0; |
399 | |
400 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
|
401 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
|
402 b->file_pos += b->pos - ctx->buf->pos; |
1172 | 403 } |
404 | |
405 *ctx->last_out = cl; | |
406 ctx->last_out = &cl->next; | |
407 } | |
408 | |
409 if (rc == NGX_AGAIN) { | |
410 continue; | |
411 } | |
412 | |
413 | |
414 /* rc == NGX_OK */ | |
415 | |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
416 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
|
417 if (cl == NULL) { |
1172 | 418 return NGX_ERROR; |
419 } | |
420 | |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
421 b = cl->buf; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
422 |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
423 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 424 |
425 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module); | |
426 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
427 if (ctx->sub == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
428 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
|
429 * ctx->matches->nelts); |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
430 if (ctx->sub == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
431 return NGX_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
432 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
433 } |
1172 | 434 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
435 sub = &ctx->sub[ctx->index]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
436 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
437 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
|
438 match = ctx->matches->elts; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
439 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
440 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
|
441 != NGX_OK) |
1172 | 442 { |
443 return NGX_ERROR; | |
444 } | |
445 } | |
446 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
447 if (sub->len) { |
1555
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
448 b->memory = 1; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
449 b->pos = sub->data; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
450 b->last = sub->data + sub->len; |
1555
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
451 |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
452 } else { |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
453 b->sync = 1; |
76fe59c6fafb
fix empty string replacement in sub_filter
Igor Sysoev <igor@sysoev.ru>
parents:
1172
diff
changeset
|
454 } |
1172 | 455 |
456 *ctx->last_out = cl; | |
457 ctx->last_out = &cl->next; | |
458 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
459 ctx->index = 0; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
460 ctx->once = slcf->once && (++ctx->applied == ctx->matches->nelts); |
1172 | 461 |
462 continue; | |
463 } | |
464 | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
465 if (ctx->looked.len |
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
466 && (ctx->buf->last_buf || ctx->buf->last_in_chain)) |
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
467 { |
5287
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
468 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
|
469 if (cl == NULL) { |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
470 return NGX_ERROR; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
471 } |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
472 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
473 b = cl->buf; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
474 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
475 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
|
476 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
477 b->pos = ctx->looked.data; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
478 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
|
479 b->memory = 1; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
480 |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
481 *ctx->last_out = cl; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
482 ctx->last_out = &cl->next; |
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 ctx->looked.len = 0; |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
485 } |
2dbc5e38b65d
Sub filter: fixed incomplete last buffer on partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5286
diff
changeset
|
486 |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
487 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
|
488 || ngx_buf_in_memory(ctx->buf)) |
819c5b53d8b5
Sub filter: flush buffers handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5285
diff
changeset
|
489 { |
1172 | 490 if (b == NULL) { |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
491 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
|
492 if (cl == NULL) { |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
493 return NGX_ERROR; |
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
494 } |
1172 | 495 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
496 b = cl->buf; |
1172 | 497 |
5285
d47ef93134e5
Sub filter: switched to ngx_chain_get_free_buf().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5284
diff
changeset
|
498 ngx_memzero(b, sizeof(ngx_buf_t)); |
1172 | 499 |
500 b->sync = 1; | |
501 | |
502 *ctx->last_out = cl; | |
503 ctx->last_out = &cl->next; | |
504 } | |
505 | |
506 b->last_buf = ctx->buf->last_buf; | |
5710
9e9c1310d17c
Sub filter: fixed subrequests handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5288
diff
changeset
|
507 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
|
508 b->flush = ctx->buf->flush; |
1172 | 509 b->shadow = ctx->buf; |
510 | |
511 b->recycled = ctx->buf->recycled; | |
512 } | |
513 | |
514 ctx->buf = NULL; | |
515 } | |
516 | |
517 if (ctx->out == NULL && ctx->busy == NULL) { | |
518 return NGX_OK; | |
519 } | |
520 | |
521 return ngx_http_sub_output(r, ctx); | |
522 } | |
523 | |
524 | |
525 static ngx_int_t | |
526 ngx_http_sub_output(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx) | |
527 { | |
528 ngx_int_t rc; | |
529 ngx_buf_t *b; | |
530 ngx_chain_t *cl; | |
531 | |
532 #if 1 | |
533 b = NULL; | |
534 for (cl = ctx->out; cl; cl = cl->next) { | |
535 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
536 "sub out: %p %p", cl->buf, cl->buf->pos); | |
537 if (cl->buf == b) { | |
538 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
539 "the same buf was used in sub"); | |
540 ngx_debug_point(); | |
541 return NGX_ERROR; | |
542 } | |
543 b = cl->buf; | |
544 } | |
545 #endif | |
546 | |
547 rc = ngx_http_next_body_filter(r, ctx->out); | |
548 | |
549 if (ctx->busy == NULL) { | |
550 ctx->busy = ctx->out; | |
551 | |
552 } else { | |
553 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
554 cl->next = ctx->out; | |
555 } | |
556 | |
557 ctx->out = NULL; | |
558 ctx->last_out = &ctx->out; | |
559 | |
560 while (ctx->busy) { | |
561 | |
562 cl = ctx->busy; | |
563 b = cl->buf; | |
564 | |
565 if (ngx_buf_size(b) != 0) { | |
566 break; | |
567 } | |
568 | |
569 if (b->shadow) { | |
570 b->shadow->pos = b->shadow->last; | |
571 } | |
572 | |
573 ctx->busy = cl->next; | |
574 | |
575 if (ngx_buf_in_memory(b) || b->in_file) { | |
576 /* add data bufs only to the free buf chain */ | |
577 | |
578 cl->next = ctx->free; | |
579 ctx->free = cl; | |
580 } | |
581 } | |
582 | |
583 if (ctx->in || ctx->buf) { | |
584 r->buffered |= NGX_HTTP_SUB_BUFFERED; | |
585 | |
586 } else { | |
587 r->buffered &= ~NGX_HTTP_SUB_BUFFERED; | |
588 } | |
589 | |
590 return rc; | |
591 } | |
592 | |
593 | |
594 static ngx_int_t | |
595 ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx) | |
596 { | |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
597 u_char *p, c; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
598 ngx_str_t *m; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
599 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
|
600 ngx_uint_t shift, i, j; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
601 ngx_http_sub_match_t *match; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
602 ngx_http_sub_tables_t *tables; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
603 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
|
604 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
605 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
|
606 tables = ctx->tables; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
607 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
608 offset = ctx->offset; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
609 end = ctx->buf->last - ctx->pos; |
1172 | 610 |
611 if (ctx->once) { | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
612 /* sets start and next to end */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
613 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
|
614 goto again; |
1172 | 615 } |
616 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
617 while (offset < end) { |
1172 | 618 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
619 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
|
620 : ctx->pos[offset]; |
5810
5322be87fc02
Sub filter: fixed matching for a single character.
Valentin Bartenev <vbart@nginx.com>
parents:
5733
diff
changeset
|
621 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
622 c = ngx_tolower(c); |
1172 | 623 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
624 shift = tables->shift[c]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
625 if (shift > 0) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
626 offset += shift; |
1172 | 627 continue; |
628 } | |
629 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
630 /* a potential match */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
631 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
632 start = offset - (ngx_int_t) tables->min_match_len + 1; |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
633 match = ctx->matches->elts; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
634 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
635 i = ngx_max(tables->index[c], ctx->index); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
636 j = tables->index[c + 1]; |
1172 | 637 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
638 while (i != j) { |
1172 | 639 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
640 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
|
641 goto next; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
642 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
643 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
644 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
|
645 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
646 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
|
647 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
648 if (rc == NGX_DECLINED) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
649 goto next; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
650 } |
1172 | 651 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
652 ctx->index = i; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
653 |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
654 if (rc == NGX_AGAIN) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
655 goto again; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
656 } |
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
657 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
658 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
|
659 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
|
660 end = ngx_max(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
661 rc = NGX_OK; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
662 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
663 goto done; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
664 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
665 next: |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
666 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
667 i++; |
1172 | 668 } |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
669 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
670 offset++; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
671 ctx->index = 0; |
1172 | 672 } |
673 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
674 again: |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
675 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
676 ctx->offset = offset; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
677 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
|
678 next = start; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
679 rc = NGX_AGAIN; |
5288
102d7117ffb8
Sub filter: fixed matching after a partial match.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5287
diff
changeset
|
680 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
681 done: |
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 /* send [ - looked.len, start ] to client */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
684 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
685 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
|
686 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
|
687 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
688 ctx->copy_start = ctx->pos; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
689 ctx->copy_end = ctx->pos + ngx_max(start, 0); |
1172 | 690 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
691 /* save [ next, end ] in looked */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
692 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
693 len = ngx_min(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
694 p = ctx->looked.data; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
695 p = ngx_movemem(p, p + ctx->looked.len + len, - len); |
1172 | 696 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
697 len = ngx_max(next, 0); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
698 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
|
699 ctx->looked.len = p - ctx->looked.data; |
1172 | 700 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
701 /* update position */ |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
702 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
703 ctx->pos += end; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
704 ctx->offset -= end; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
705 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
706 return rc; |
1172 | 707 } |
708 | |
709 | |
6604
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
710 static ngx_int_t |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
711 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
|
712 { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
713 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
|
714 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
715 pat = m->data; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
716 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
|
717 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
718 if (start >= 0) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
719 p = ctx->pos + start; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
720 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
721 } else { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
722 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
|
723 p = last + start; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
724 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
725 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
|
726 if (ngx_tolower(*p) != *pat) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
727 return NGX_DECLINED; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
728 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
729 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
730 p++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
731 pat++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
732 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
733 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
734 p = ctx->pos; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
735 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
736 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
737 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
|
738 if (ngx_tolower(*p) != *pat) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
739 return NGX_DECLINED; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
740 } |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
741 |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
742 p++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
743 pat++; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
744 } |
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 if (pat != pat_end) { |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
747 /* partial match */ |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
748 return NGX_AGAIN; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
749 } |
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 return NGX_OK; |
0e0adbbc8752
Sub filter: introduced the ngx_http_sub_match() function.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
752 } |
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 |
1172 | 755 static char * |
756 ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
757 { | |
758 ngx_http_sub_loc_conf_t *slcf = conf; | |
759 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
760 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
|
761 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
|
762 ngx_http_compile_complex_value_t ccv; |
1172 | 763 |
764 value = cf->args->elts; | |
765 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
766 if (value[1].len == 0) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
767 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
|
768 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
769 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
770 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
771 if (slcf->pairs == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
772 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
|
773 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
|
774 if (slcf->pairs == NULL) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
775 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
776 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
777 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
778 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
779 if (slcf->pairs->nelts == 255) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
780 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
|
781 "number of search patterns exceeds 255"); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
782 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
783 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
784 |
2135 | 785 ngx_strlow(value[1].data, value[1].data, value[1].len); |
1172 | 786 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
787 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
|
788 if (pair == NULL) { |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
789 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
790 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
791 |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
792 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
|
793 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
794 ccv.cf = cf; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
795 ccv.value = &value[1]; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
796 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
|
797 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
798 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
|
799 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
800 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
801 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
802 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
|
803 slcf->dynamic = 1; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
804 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
805 } else { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
806 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
|
807 pair->match.value.len); |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
808 } |
1172 | 809 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
810 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
1172 | 811 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
812 ccv.cf = cf; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
813 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
|
814 ccv.complex_value = &pair->value; |
1172 | 815 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
816 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
1172 | 817 return NGX_CONF_ERROR; |
818 } | |
819 | |
820 return NGX_CONF_OK; | |
821 } | |
822 | |
823 | |
824 static void * | |
825 ngx_http_sub_create_conf(ngx_conf_t *cf) | |
826 { | |
827 ngx_http_sub_loc_conf_t *slcf; | |
828 | |
829 slcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_sub_loc_conf_t)); | |
830 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
|
831 return NULL; |
1172 | 832 } |
833 | |
834 /* | |
835 * set by ngx_pcalloc(): | |
836 * | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
837 * conf->dynamic = 0; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
838 * conf->pairs = NULL; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
839 * 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
|
840 * conf->types = { NULL }; |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
841 * conf->types_keys = NULL; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
842 * conf->matches = NULL; |
1172 | 843 */ |
844 | |
845 slcf->once = NGX_CONF_UNSET; | |
5229
4c1a604b0285
Sub filter: sub_filter_last_modified directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4947
diff
changeset
|
846 slcf->last_modified = NGX_CONF_UNSET; |
1172 | 847 |
848 return slcf; | |
849 } | |
850 | |
851 | |
852 static char * | |
853 ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
854 { | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
855 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
|
856 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
|
857 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
|
858 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
|
859 ngx_http_sub_loc_conf_t *conf = child; |
1172 | 860 |
861 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
|
862 ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0); |
1172 | 863 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
864 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
|
865 &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
|
866 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
|
867 != NGX_OK) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
868 { |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2135
diff
changeset
|
869 return NGX_CONF_ERROR; |
1172 | 870 } |
871 | |
6229
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
872 if (conf->pairs == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
873 conf->dynamic = prev->dynamic; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
874 conf->pairs = prev->pairs; |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
875 conf->matches = prev->matches; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
876 conf->tables = prev->tables; |
6247
fbbb1c1ce1eb
Sub filter: fixed initialization in http{} level (ticket #791).
Roman Arutyunyan <arut@nginx.com>
parents:
6229
diff
changeset
|
877 } |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
878 |
6247
fbbb1c1ce1eb
Sub filter: fixed initialization in http{} level (ticket #791).
Roman Arutyunyan <arut@nginx.com>
parents:
6229
diff
changeset
|
879 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
|
880 pairs = conf->pairs->elts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
881 n = conf->pairs->nelts; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
882 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
883 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
|
884 if (matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
885 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
886 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
887 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
892 |
6464
088ef087a011
Sub filter: fixed allocation alignment.
Roman Arutyunyan <arut@nginx.com>
parents:
6247
diff
changeset
|
893 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
|
894 if (conf->matches == NULL) { |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
895 return NGX_CONF_ERROR; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
896 } |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
897 |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
898 conf->matches->elts = matches; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
899 conf->matches->nelts = n; |
2c045e5b8291
Sub filter: support of variables in the strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6228
diff
changeset
|
900 |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
901 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
|
902 if (conf->tables == NULL) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
903 return NGX_CONF_ERROR; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
904 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
905 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
906 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
|
907 conf->matches->nelts); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
908 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
909 |
1172 | 910 return NGX_CONF_OK; |
911 } | |
912 | |
913 | |
6228
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
914 static void |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
915 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
|
916 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
|
917 { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
918 u_char c; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
919 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
|
920 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
921 min = match[0].match.len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
922 max = match[0].match.len; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
923 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
924 for (i = 1; i < n; i++) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
925 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
|
926 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
|
927 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
928 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
929 tables->min_match_len = min; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
930 tables->max_match_len = max; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
931 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
932 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
|
933 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
|
934 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
935 min = ngx_min(min, 255); |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
936 ngx_memset(tables->shift, min, 256); |
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 ch = 0; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
939 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
940 for (i = 0; i < n; i++) { |
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 for (j = 0; j < min; j++) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
943 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
|
944 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
|
945 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
946 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
947 c = match[i].match.data[tables->min_match_len - 1]; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
948 while (ch <= c) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
949 tables->index[ch++] = (u_char) i; |
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 } |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
952 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
953 while (ch < 257) { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
954 tables->index[ch++] = (u_char) n; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
955 } |
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 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
958 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
959 static ngx_int_t |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
960 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
|
961 { |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
962 ngx_int_t c1, c2; |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
963 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
|
964 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
965 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
|
966 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
|
967 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
968 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
|
969 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
|
970 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
971 return c1 - c2; |
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 |
b9447fc457b4
Sub filter: support of multiple strings to replace.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
5810
diff
changeset
|
974 |
1172 | 975 static ngx_int_t |
976 ngx_http_sub_filter_init(ngx_conf_t *cf) | |
977 { | |
978 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
979 ngx_http_top_header_filter = ngx_http_sub_header_filter; | |
980 | |
981 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
982 ngx_http_top_body_filter = ngx_http_sub_body_filter; | |
983 | |
984 return NGX_OK; | |
985 } |