Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_charset_filter_module.c @ 2535:ec5825afc7eb
use variable for often used field
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 24 Feb 2009 08:32:02 +0000 |
parents | cc13ff6d5c07 |
children | a6d6d762c554 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
5 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
657 | 12 #define NGX_HTTP_NO_CHARSET -2 |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
13 #define NGX_HTTP_CHARSET_VAR 0x10000 |
657 | 14 |
15 /* 1 byte length and up to 3 bytes for the UTF-8 encoding of the UCS-2 */ | |
16 #define NGX_UTF_LEN 4 | |
17 | |
18 #define NGX_HTML_ENTITY_LEN (sizeof("") - 1) | |
529 | 19 |
20 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 typedef struct { |
657 | 22 u_char **tables; |
23 ngx_str_t name; | |
523 | 24 |
657 | 25 unsigned length:16; |
26 unsigned utf8:1; | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
27 } ngx_http_charset_t; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
28 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
29 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
30 typedef struct { |
657 | 31 ngx_int_t src; |
32 ngx_int_t dst; | |
529 | 33 } ngx_http_charset_recode_t; |
34 | |
35 | |
36 typedef struct { | |
657 | 37 ngx_int_t src; |
38 ngx_int_t dst; | |
39 u_char *src2dst; | |
40 u_char *dst2src; | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
41 } ngx_http_charset_tables_t; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
42 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
43 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
44 typedef struct { |
657 | 45 ngx_array_t charsets; /* ngx_http_charset_t */ |
46 ngx_array_t tables; /* ngx_http_charset_tables_t */ | |
47 ngx_array_t recodes; /* ngx_http_charset_recode_t */ | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
48 } ngx_http_charset_main_conf_t; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
49 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
50 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
51 typedef struct { |
657 | 52 ngx_int_t charset; |
53 ngx_int_t source_charset; | |
54 ngx_flag_t override_charset; | |
2167 | 55 |
56 ngx_hash_t types; | |
57 ngx_array_t *types_keys; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 } ngx_http_charset_loc_conf_t; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
61 typedef struct { |
657 | 62 u_char *table; |
63 ngx_int_t charset; | |
64 | |
65 ngx_chain_t *busy; | |
66 ngx_chain_t *free_bufs; | |
67 ngx_chain_t *free_buffers; | |
68 | |
69 size_t saved_len; | |
70 u_char saved[NGX_UTF_LEN]; | |
71 | |
72 unsigned length:16; | |
73 unsigned from_utf8:1; | |
74 unsigned to_utf8:1; | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
75 } ngx_http_charset_ctx_t; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
76 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
77 |
657 | 78 typedef struct { |
79 ngx_http_charset_tables_t *table; | |
80 ngx_http_charset_t *charset; | |
81 ngx_uint_t characters; | |
82 } ngx_http_charset_conf_ctx_t; | |
83 | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
84 |
657 | 85 static ngx_int_t ngx_http_charset_get_charset(ngx_http_charset_t *charsets, |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
86 ngx_uint_t n, ngx_str_t *charset); |
657 | 87 static ngx_int_t ngx_http_charset_set_charset(ngx_http_request_t *r, |
88 ngx_http_charset_t *charsets, ngx_int_t charset, ngx_int_t source_charset); | |
89 static ngx_uint_t ngx_http_charset_recode(ngx_buf_t *b, u_char *table); | |
90 static ngx_chain_t *ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, | |
91 ngx_buf_t *buf, ngx_http_charset_ctx_t *ctx); | |
92 static ngx_chain_t *ngx_http_charset_recode_to_utf8(ngx_pool_t *pool, | |
93 ngx_buf_t *buf, ngx_http_charset_ctx_t *ctx); | |
94 | |
95 static ngx_chain_t *ngx_http_charset_get_buf(ngx_pool_t *pool, | |
96 ngx_http_charset_ctx_t *ctx); | |
97 static ngx_chain_t *ngx_http_charset_get_buffer(ngx_pool_t *pool, | |
98 ngx_http_charset_ctx_t *ctx, size_t size); | |
99 | |
100 static char *ngx_http_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, | |
501 | 101 void *conf); |
657 | 102 static char *ngx_http_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, |
103 void *conf); | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
104 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
105 static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
501 | 106 void *conf); |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
107 static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
108 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
109 static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf); |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
110 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf); |
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
111 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, |
501 | 112 void *parent, void *child); |
529 | 113 static ngx_int_t ngx_http_charset_postconfiguration(ngx_conf_t *cf); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 |
2167 | 116 ngx_str_t ngx_http_charset_default_types[] = { |
117 ngx_string("text/html"), | |
118 ngx_string("text/xml"), | |
119 ngx_string("text/plain"), | |
120 ngx_string("text/vnd.wap.wml"), | |
121 ngx_string("application/x-javascript"), | |
122 ngx_string("application/rss+xml"), | |
123 ngx_null_string | |
124 }; | |
125 | |
126 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 static ngx_command_t ngx_http_charset_filter_commands[] = { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 |
529 | 129 { ngx_string("charset"), |
559 | 130 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |
131 |NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, | |
529 | 132 ngx_http_set_charset_slot, |
133 NGX_HTTP_LOC_CONF_OFFSET, | |
134 offsetof(ngx_http_charset_loc_conf_t, charset), | |
135 NULL }, | |
136 | |
137 { ngx_string("source_charset"), | |
559 | 138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF |
139 |NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, | |
529 | 140 ngx_http_set_charset_slot, |
141 NGX_HTTP_LOC_CONF_OFFSET, | |
142 offsetof(ngx_http_charset_loc_conf_t, source_charset), | |
143 NULL }, | |
144 | |
635 | 145 { ngx_string("override_charset"), |
146 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF | |
147 |NGX_HTTP_LIF_CONF|NGX_CONF_FLAG, | |
148 ngx_conf_set_flag_slot, | |
149 NGX_HTTP_LOC_CONF_OFFSET, | |
150 offsetof(ngx_http_charset_loc_conf_t, override_charset), | |
151 NULL }, | |
152 | |
2167 | 153 { ngx_string("charset_types"), |
154 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | |
155 ngx_http_types_slot, | |
156 NGX_HTTP_LOC_CONF_OFFSET, | |
157 offsetof(ngx_http_charset_loc_conf_t, types_keys), | |
158 &ngx_http_charset_default_types[0] }, | |
159 | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
160 { ngx_string("charset_map"), |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
161 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, |
657 | 162 ngx_http_charset_map_block, |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
163 NGX_HTTP_MAIN_CONF_OFFSET, |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
164 0, |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
165 NULL }, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
167 ngx_null_command |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 static ngx_http_module_t ngx_http_charset_filter_module_ctx = { |
509 | 172 NULL, /* preconfiguration */ |
529 | 173 ngx_http_charset_postconfiguration, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
174 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
175 ngx_http_charset_create_main_conf, /* create main configuration */ |
529 | 176 NULL, /* init main configuration */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 ngx_http_charset_create_loc_conf, /* create location configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 ngx_http_charset_merge_loc_conf /* merge location configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 ngx_module_t ngx_http_charset_filter_module = { |
509 | 187 NGX_MODULE_V1, |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 &ngx_http_charset_filter_module_ctx, /* module context */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 ngx_http_charset_filter_commands, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 NGX_HTTP_MODULE, /* module type */ |
541 | 191 NULL, /* init master */ |
681 | 192 NULL, /* init module */ |
541 | 193 NULL, /* init process */ |
194 NULL, /* init thread */ | |
195 NULL, /* exit thread */ | |
196 NULL, /* exit process */ | |
197 NULL, /* exit master */ | |
198 NGX_MODULE_V1_PADDING | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
202 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
203 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
204 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 |
501 | 206 static ngx_int_t |
207 ngx_http_charset_header_filter(ngx_http_request_t *r) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 { |
635 | 209 ngx_int_t charset, source_charset; |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
210 ngx_str_t *mc, *from, *to, s; |
657 | 211 ngx_uint_t n; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
212 ngx_http_charset_t *charsets; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
213 ngx_http_charset_ctx_t *ctx; |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
214 ngx_http_variable_value_t *vv; |
653 | 215 ngx_http_charset_loc_conf_t *lcf, *mlcf; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
216 ngx_http_charset_main_conf_t *mcf; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
218 mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module); |
635 | 219 |
657 | 220 charsets = mcf->charsets.elts; |
221 n = mcf->charsets.nelts; | |
635 | 222 |
657 | 223 /* destination charset */ |
653 | 224 |
225 if (r == r->main) { | |
657 | 226 |
2050
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
227 if (r->headers_out.content_encoding |
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
228 && r->headers_out.content_encoding->value.len) |
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
229 { |
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
230 return ngx_http_next_header_filter(r); |
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
231 } |
c0bafb136d7b
disable charset if there is "Content-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
1944
diff
changeset
|
232 |
653 | 233 if (r->headers_out.content_type.len == 0) { |
234 return ngx_http_next_header_filter(r); | |
235 } | |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
236 |
657 | 237 if (r->headers_out.override_charset |
238 && r->headers_out.override_charset->len) | |
653 | 239 { |
657 | 240 charset = ngx_http_charset_get_charset(charsets, n, |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
241 r->headers_out.override_charset); |
657 | 242 |
243 if (charset == NGX_HTTP_NO_CHARSET) { | |
661 | 244 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
657 | 245 "unknown charset \"%V\" to override", |
659 | 246 r->headers_out.override_charset); |
657 | 247 |
248 return ngx_http_next_header_filter(r); | |
249 } | |
250 | |
251 } else { | |
252 mlcf = ngx_http_get_module_loc_conf(r, | |
253 ngx_http_charset_filter_module); | |
254 charset = mlcf->charset; | |
255 | |
256 if (charset == NGX_HTTP_NO_CHARSET) { | |
257 return ngx_http_next_header_filter(r); | |
258 } | |
259 | |
260 if (r->headers_out.charset.len) { | |
261 if (mlcf->override_charset == 0) { | |
262 return ngx_http_next_header_filter(r); | |
263 } | |
264 | |
265 } else { | |
2167 | 266 if (ngx_http_test_content_type(r, &mlcf->types) == NULL) { |
657 | 267 return ngx_http_next_header_filter(r); |
268 } | |
269 } | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
270 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
271 if (charset >= NGX_HTTP_CHARSET_VAR) { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
272 vv = ngx_http_get_indexed_variable(r, |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
273 charset - NGX_HTTP_CHARSET_VAR); |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
274 |
797
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
275 if (vv == NULL || vv->not_found) { |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
276 return NGX_ERROR; |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
277 } |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
278 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
279 s.len = vv->len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
280 s.data = vv->data; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
281 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
282 charset = ngx_http_charset_get_charset(charsets, n, &s); |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
283 } |
653 | 284 } |
285 | |
286 } else { | |
657 | 287 ctx = ngx_http_get_module_ctx(r->main, ngx_http_charset_filter_module); |
288 | |
289 if (ctx == NULL) { | |
290 | |
291 mc = &r->main->headers_out.charset; | |
292 | |
293 if (mc->len == 0) { | |
294 return ngx_http_next_header_filter(r); | |
295 } | |
296 | |
297 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t)); | |
298 if (ctx == NULL) { | |
299 return NGX_ERROR; | |
300 } | |
301 | |
302 ngx_http_set_ctx(r->main, ctx, ngx_http_charset_filter_module); | |
653 | 303 |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
304 charset = ngx_http_charset_get_charset(charsets, n, mc); |
657 | 305 |
306 ctx->charset = charset; | |
307 | |
661 | 308 } else { |
309 charset = ctx->charset; | |
653 | 310 } |
389
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
311 } |
537de4dca8ca
nginx-0.0.7-2004-07-13-21:59:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
312 |
657 | 313 /* source charset */ |
635 | 314 |
657 | 315 if (r->headers_out.charset.len == 0) { |
316 lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module); | |
635 | 317 |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
318 source_charset = lcf->source_charset; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
319 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
320 if (source_charset >= NGX_HTTP_CHARSET_VAR) { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
321 vv = ngx_http_get_indexed_variable(r, |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
322 source_charset - NGX_HTTP_CHARSET_VAR); |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
323 |
797
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
324 if (vv == NULL || vv->not_found) { |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
325 return NGX_ERROR; |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
326 } |
36f7b549f481
fix segfault if $server_addr failed
Igor Sysoev <igor@sysoev.ru>
parents:
752
diff
changeset
|
327 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
328 s.len = vv->len; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
329 s.data = vv->data; |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
330 |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
331 source_charset = ngx_http_charset_get_charset(charsets, n, &s); |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
332 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
333 |
661 | 334 if (charset != NGX_HTTP_NO_CHARSET) { |
335 return ngx_http_charset_set_charset(r, mcf->charsets.elts, charset, | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
336 source_charset); |
661 | 337 } |
338 | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
339 if (source_charset == NGX_CONF_UNSET) { |
661 | 340 return ngx_http_next_header_filter(r); |
341 } | |
342 | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
343 from = &charsets[source_charset].name; |
663 | 344 to = &r->main->headers_out.charset; |
661 | 345 |
663 | 346 goto no_charset_map; |
657 | 347 } |
635 | 348 |
657 | 349 source_charset = ngx_http_charset_get_charset(charsets, n, |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
350 &r->headers_out.charset); |
635 | 351 |
661 | 352 if (charset == NGX_HTTP_NO_CHARSET |
353 || source_charset == NGX_HTTP_NO_CHARSET) | |
354 { | |
355 if (charset != source_charset | |
356 || ngx_strcasecmp(r->main->headers_out.charset.data, | |
357 r->headers_out.charset.data) | |
358 != 0) | |
359 { | |
663 | 360 from = &r->headers_out.charset; |
361 to = (charset == NGX_HTTP_NO_CHARSET) ? | |
362 &r->main->headers_out.charset: | |
363 &charsets[charset].name; | |
364 | |
365 goto no_charset_map; | |
661 | 366 } |
635 | 367 |
657 | 368 return ngx_http_next_header_filter(r); |
369 } | |
635 | 370 |
657 | 371 if (source_charset != charset |
372 && (charsets[source_charset].tables == NULL | |
373 || charsets[source_charset].tables[charset] == NULL)) | |
374 { | |
663 | 375 from = &charsets[source_charset].name; |
376 to = &charsets[charset].name; | |
635 | 377 |
663 | 378 goto no_charset_map; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
379 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
380 |
657 | 381 r->headers_out.content_type.len = r->headers_out.content_type_len; |
382 | |
383 return ngx_http_charset_set_charset(r, mcf->charsets.elts, charset, | |
384 source_charset); | |
663 | 385 |
386 no_charset_map: | |
387 | |
388 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1587 | 389 "no \"charset_map\" between the charsets \"%V\" and \"%V\"", |
1589 | 390 from, to); |
663 | 391 |
392 return ngx_http_next_header_filter(r); | |
657 | 393 } |
394 | |
395 | |
396 static ngx_int_t | |
397 ngx_http_charset_get_charset(ngx_http_charset_t *charsets, ngx_uint_t n, | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
398 ngx_str_t *charset) |
657 | 399 { |
400 ngx_uint_t i; | |
401 | |
402 for (i = 0; i < n; i++) { | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
403 if (charsets[i].name.len != charset->len) { |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
404 continue; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
405 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
406 |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
407 if (ngx_strncasecmp(charsets[i].name.data, charset->data, charset->len) |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
408 == 0) |
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
409 { |
657 | 410 return i; |
411 } | |
412 } | |
413 | |
414 return NGX_HTTP_NO_CHARSET; | |
415 } | |
416 | |
417 | |
418 static ngx_int_t | |
419 ngx_http_charset_set_charset(ngx_http_request_t *r, | |
420 ngx_http_charset_t *charsets, ngx_int_t charset, ngx_int_t source_charset) | |
421 { | |
422 ngx_http_charset_ctx_t *ctx; | |
423 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
424 if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY |
501 | 425 || r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
426 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
427 /* |
635 | 428 * do not set charset for the redirect because NN 4.x |
429 * use this charset instead of the next page charset | |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
430 */ |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
431 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
432 r->headers_out.charset.len = 0; |
657 | 433 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
434 return ngx_http_next_header_filter(r); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
435 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
436 |
635 | 437 r->headers_out.charset = charsets[charset].name; |
438 r->utf8 = charsets[charset].utf8; | |
439 | |
440 if (source_charset == NGX_CONF_UNSET || source_charset == charset) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
441 return ngx_http_next_header_filter(r); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
442 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
443 |
501 | 444 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t)); |
445 if (ctx == NULL) { | |
446 return NGX_ERROR; | |
447 } | |
448 | |
449 ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module); | |
450 | |
635 | 451 ctx->table = charsets[source_charset].tables[charset]; |
452 ctx->charset = charset; | |
657 | 453 ctx->length = charsets[charset].length; |
454 ctx->from_utf8 = charsets[source_charset].utf8; | |
455 ctx->to_utf8 = charsets[charset].utf8; | |
456 | |
663 | 457 r->filter_need_in_memory = 1; |
458 | |
657 | 459 if ((ctx->to_utf8 || ctx->from_utf8) && r == r->main) { |
460 ngx_http_clear_content_length(r); | |
663 | 461 |
462 } else { | |
463 r->filter_need_temporary = 1; | |
657 | 464 } |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
465 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
466 return ngx_http_next_header_filter(r); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
467 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
468 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
469 |
501 | 470 static ngx_int_t |
471 ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
472 { |
657 | 473 ngx_int_t rc; |
474 ngx_buf_t *b; | |
475 ngx_chain_t *cl, *out, **ll; | |
635 | 476 ngx_http_charset_ctx_t *ctx; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
477 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
478 ctx = ngx_http_get_module_ctx(r, ngx_http_charset_filter_module); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
479 |
635 | 480 if (ctx == NULL || ctx->table == NULL) { |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
481 return ngx_http_next_body_filter(r, in); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
482 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
483 |
657 | 484 if ((ctx->to_utf8 || ctx->from_utf8) || ctx->busy) { |
485 | |
486 out = NULL; | |
487 ll = &out; | |
488 | |
489 for (cl = in; cl; cl = cl->next) { | |
490 b = cl->buf; | |
491 | |
492 if (ngx_buf_size(b) == 0) { | |
665 | 493 |
494 *ll = ngx_alloc_chain_link(r->pool); | |
495 if (*ll == NULL) { | |
496 return NGX_ERROR; | |
497 } | |
498 | |
499 (*ll)->buf = b; | |
500 (*ll)->next = NULL; | |
501 | |
502 ll = &(*ll)->next; | |
503 | |
657 | 504 continue; |
505 } | |
506 | |
507 if (ctx->to_utf8) { | |
508 *ll = ngx_http_charset_recode_to_utf8(r->pool, b, ctx); | |
509 | |
510 } else { | |
511 *ll = ngx_http_charset_recode_from_utf8(r->pool, b, ctx); | |
512 } | |
513 | |
514 if (*ll == NULL) { | |
515 return NGX_ERROR; | |
516 } | |
517 | |
518 while (*ll) { | |
519 ll = &(*ll)->next; | |
520 } | |
521 } | |
522 | |
523 rc = ngx_http_next_body_filter(r, out); | |
524 | |
525 if (out) { | |
526 if (ctx->busy == NULL) { | |
527 ctx->busy = out; | |
528 | |
529 } else { | |
530 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
531 cl->next = out; | |
532 } | |
533 } | |
534 | |
535 while (ctx->busy) { | |
536 | |
537 cl = ctx->busy; | |
538 b = cl->buf; | |
539 | |
540 if (ngx_buf_size(b) != 0) { | |
541 break; | |
542 } | |
543 | |
544 ctx->busy = cl->next; | |
545 | |
546 if (b->tag != (ngx_buf_tag_t) &ngx_http_charset_filter_module) { | |
547 continue; | |
548 } | |
549 | |
550 if (b->shadow) { | |
551 b->shadow->pos = b->shadow->last; | |
552 } | |
553 | |
554 if (b->pos) { | |
555 cl->next = ctx->free_buffers; | |
556 ctx->free_buffers = cl; | |
557 continue; | |
558 } | |
559 | |
560 cl->next = ctx->free_bufs; | |
561 ctx->free_bufs = cl; | |
562 } | |
563 | |
564 return rc; | |
565 } | |
566 | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
567 for (cl = in; cl; cl = cl->next) { |
635 | 568 (void) ngx_http_charset_recode(cl->buf, ctx->table); |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
569 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
570 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
571 return ngx_http_next_body_filter(r, in); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
572 } |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
573 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
574 |
501 | 575 static ngx_uint_t |
635 | 576 ngx_http_charset_recode(ngx_buf_t *b, u_char *table) |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
577 { |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
578 u_char *p, *last; |
635 | 579 |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
580 last = b->last; |
455 | 581 |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
582 for (p = b->pos; p < last; p++) { |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
583 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
584 if (*p != table[*p]) { |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
585 goto recode; |
455 | 586 } |
587 } | |
588 | |
635 | 589 return 0; |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
590 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
591 recode: |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
592 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
593 do { |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
594 if (*p != table[*p]) { |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
595 *p = table[*p]; |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
596 } |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
597 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
598 p++; |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
599 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
600 } while (p < last); |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
601 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
602 b->in_file = 0; |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
603 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
604 return 1; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
605 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
606 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
607 |
657 | 608 static ngx_chain_t * |
609 ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf, | |
610 ngx_http_charset_ctx_t *ctx) | |
611 { | |
612 size_t len, size; | |
613 u_char c, *p, *src, *dst, *saved, **table; | |
614 uint32_t n; | |
615 ngx_buf_t *b; | |
616 ngx_uint_t i; | |
617 ngx_chain_t *out, *cl, **ll; | |
618 | |
619 src = buf->pos; | |
620 | |
621 if (ctx->saved_len == 0) { | |
622 | |
623 for ( /* void */ ; src < buf->last; src++) { | |
624 | |
625 if (*src < 0x80) { | |
626 continue; | |
627 } | |
628 | |
629 len = src - buf->pos; | |
630 | |
631 if (len > 512) { | |
632 out = ngx_http_charset_get_buf(pool, ctx); | |
633 if (out == NULL) { | |
634 return NULL; | |
635 } | |
636 | |
637 b = out->buf; | |
638 | |
639 b->temporary = buf->temporary; | |
640 b->memory = buf->memory; | |
641 b->mmap = buf->mmap; | |
642 b->flush = buf->flush; | |
643 | |
644 b->pos = buf->pos; | |
645 b->last = src; | |
646 | |
647 out->buf = b; | |
648 out->next = NULL; | |
649 | |
650 size = buf->last - src; | |
651 | |
652 saved = src; | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
653 n = ngx_utf8_decode(&saved, size); |
657 | 654 |
655 if (n == 0xfffffffe) { | |
656 /* incomplete UTF-8 symbol */ | |
657 | |
658 ngx_memcpy(ctx->saved, src, size); | |
659 ctx->saved_len = size; | |
660 | |
661 b->shadow = buf; | |
662 | |
663 return out; | |
664 } | |
665 | |
666 } else { | |
667 out = NULL; | |
668 size = len + buf->last - src; | |
669 src = buf->pos; | |
670 } | |
671 | |
672 if (size < NGX_HTML_ENTITY_LEN) { | |
673 size += NGX_HTML_ENTITY_LEN; | |
674 } | |
675 | |
676 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
677 if (cl == NULL) { | |
678 return NULL; | |
679 } | |
680 | |
681 if (out) { | |
682 out->next = cl; | |
683 | |
684 } else { | |
685 out = cl; | |
686 } | |
687 | |
688 b = cl->buf; | |
689 dst = b->pos; | |
690 | |
691 goto recode; | |
692 } | |
693 | |
694 out = ngx_alloc_chain_link(pool); | |
695 if (out == NULL) { | |
696 return NULL; | |
697 } | |
698 | |
699 out->buf = buf; | |
700 out->next = NULL; | |
701 | |
702 return out; | |
703 } | |
704 | |
705 /* process incomplete UTF sequence from previous buffer */ | |
706 | |
707 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
708 "http charset utf saved: %z", ctx->saved_len); | |
709 | |
710 p = src; | |
711 | |
712 for (i = ctx->saved_len; i < NGX_UTF_LEN; i++) { | |
713 ctx->saved[i] = *p++; | |
714 | |
715 if (p == buf->last) { | |
716 break; | |
717 } | |
718 } | |
719 | |
720 saved = ctx->saved; | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
721 n = ngx_utf8_decode(&saved, i); |
657 | 722 |
723 c = '\0'; | |
724 | |
725 if (n < 0x10000) { | |
726 table = (u_char **) ctx->table; | |
727 p = table[n >> 8]; | |
728 | |
729 if (p) { | |
730 c = p[n & 0xff]; | |
731 } | |
732 | |
733 } else if (n == 0xfffffffe) { | |
734 | |
735 /* incomplete UTF-8 symbol */ | |
736 | |
737 if (i < NGX_UTF_LEN) { | |
738 out = ngx_http_charset_get_buf(pool, ctx); | |
739 if (out == NULL) { | |
740 return NULL; | |
741 } | |
742 | |
743 b = out->buf; | |
744 | |
745 b->pos = buf->pos; | |
746 b->last = buf->last; | |
747 b->sync = 1; | |
748 b->shadow = buf; | |
749 | |
750 ngx_memcpy(&ctx->saved[ctx->saved_len], src, i); | |
751 ctx->saved_len += i; | |
752 | |
753 return out; | |
754 } | |
755 } | |
756 | |
757 size = buf->last - buf->pos; | |
758 | |
759 if (size < NGX_HTML_ENTITY_LEN) { | |
760 size += NGX_HTML_ENTITY_LEN; | |
761 } | |
762 | |
763 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
764 if (cl == NULL) { | |
765 return NULL; | |
766 } | |
767 | |
768 out = cl; | |
769 | |
770 b = cl->buf; | |
771 dst = b->pos; | |
772 | |
773 if (c) { | |
774 *dst++ = c; | |
775 | |
776 } else if (n == 0xfffffffe) { | |
777 *dst++ = '?'; | |
778 | |
779 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
780 "http charset invalid utf 0"); | |
781 | |
782 saved = &ctx->saved[NGX_UTF_LEN]; | |
783 | |
784 } else if (n > 0x10ffff) { | |
785 *dst++ = '?'; | |
786 | |
787 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
788 "http charset invalid utf 1"); | |
789 | |
790 } else { | |
791 dst = ngx_sprintf(dst, "&#%uD;", n); | |
792 } | |
793 | |
794 src += (saved - ctx->saved) - ctx->saved_len; | |
795 ctx->saved_len = 0; | |
796 | |
797 recode: | |
798 | |
799 ll = &cl->next; | |
800 | |
801 table = (u_char **) ctx->table; | |
802 | |
803 while (src < buf->last) { | |
804 | |
805 if ((size_t) (b->end - dst) < NGX_HTML_ENTITY_LEN) { | |
806 b->last = dst; | |
807 | |
808 size = buf->last - src + NGX_HTML_ENTITY_LEN; | |
809 | |
810 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
811 if (cl == NULL) { | |
812 return NULL; | |
813 } | |
814 | |
815 *ll = cl; | |
816 ll = &cl->next; | |
817 | |
818 b = cl->buf; | |
819 dst = b->pos; | |
820 } | |
821 | |
822 if (*src < 0x80) { | |
823 *dst++ = *src++; | |
824 continue; | |
825 } | |
826 | |
827 len = buf->last - src; | |
828 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
829 n = ngx_utf8_decode(&src, len); |
657 | 830 |
831 if (n < 0x10000) { | |
832 | |
833 p = table[n >> 8]; | |
834 | |
835 if (p) { | |
836 c = p[n & 0xff]; | |
837 | |
838 if (c) { | |
839 *dst++ = c; | |
840 continue; | |
841 } | |
842 } | |
843 | |
844 dst = ngx_sprintf(dst, "&#%uD;", n); | |
845 | |
846 continue; | |
847 } | |
848 | |
849 if (n == 0xfffffffe) { | |
850 /* incomplete UTF-8 symbol */ | |
851 | |
852 ngx_memcpy(ctx->saved, src, len); | |
853 ctx->saved_len = len; | |
854 | |
855 if (b->pos == dst) { | |
856 b->sync = 1; | |
857 b->temporary = 0; | |
858 } | |
859 | |
860 break; | |
861 } | |
862 | |
863 if (n > 0x10ffff) { | |
864 *dst++ = '?'; | |
865 | |
866 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
867 "http charset invalid utf 2"); | |
868 | |
869 continue; | |
870 } | |
871 | |
872 /* n > 0xffff */ | |
873 | |
874 dst = ngx_sprintf(dst, "&#%uD;", n); | |
875 } | |
876 | |
877 b->last = dst; | |
878 | |
879 b->last_buf = buf->last_buf; | |
880 b->last_in_chain = buf->last_in_chain; | |
881 b->flush = buf->flush; | |
882 | |
883 b->shadow = buf; | |
884 | |
885 return out; | |
886 } | |
887 | |
888 | |
889 static ngx_chain_t * | |
890 ngx_http_charset_recode_to_utf8(ngx_pool_t *pool, ngx_buf_t *buf, | |
891 ngx_http_charset_ctx_t *ctx) | |
892 { | |
893 size_t len, size; | |
894 u_char *p, *src, *dst, *table; | |
895 ngx_buf_t *b; | |
896 ngx_chain_t *out, *cl, **ll; | |
897 | |
898 table = ctx->table; | |
899 | |
900 for (src = buf->pos; src < buf->last; src++) { | |
901 if (table[*src * NGX_UTF_LEN] == '\1') { | |
902 continue; | |
903 } | |
904 | |
905 goto recode; | |
906 } | |
907 | |
908 out = ngx_alloc_chain_link(pool); | |
909 if (out == NULL) { | |
910 return NULL; | |
911 } | |
912 | |
913 out->buf = buf; | |
914 out->next = NULL; | |
915 | |
916 return out; | |
917 | |
918 recode: | |
919 | |
920 /* | |
921 * we assume that there are about half of characters to be recoded, | |
922 * so we preallocate "size / 2 + size / 2 * ctx->length" | |
923 */ | |
924 | |
925 len = src - buf->pos; | |
926 | |
927 if (len > 512) { | |
928 out = ngx_http_charset_get_buf(pool, ctx); | |
929 if (out == NULL) { | |
930 return NULL; | |
931 } | |
932 | |
933 b = out->buf; | |
934 | |
935 b->temporary = buf->temporary; | |
936 b->memory = buf->memory; | |
937 b->mmap = buf->mmap; | |
938 b->flush = buf->flush; | |
939 | |
940 b->pos = buf->pos; | |
941 b->last = src; | |
942 | |
943 out->buf = b; | |
944 out->next = NULL; | |
945 | |
946 size = buf->last - src; | |
947 size = size / 2 + size / 2 * ctx->length; | |
948 | |
949 } else { | |
950 out = NULL; | |
951 | |
952 size = buf->last - src; | |
953 size = len + size / 2 + size / 2 * ctx->length; | |
954 | |
955 src = buf->pos; | |
956 } | |
957 | |
958 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
959 if (cl == NULL) { | |
960 return NULL; | |
961 } | |
962 | |
963 if (out) { | |
964 out->next = cl; | |
965 | |
966 } else { | |
967 out = cl; | |
968 } | |
969 | |
970 ll = &cl->next; | |
971 | |
972 b = cl->buf; | |
973 dst = b->pos; | |
974 | |
975 while (src < buf->last) { | |
976 | |
977 p = &table[*src++ * NGX_UTF_LEN]; | |
978 len = *p++; | |
979 | |
980 if ((size_t) (b->end - dst) < len) { | |
981 b->last = dst; | |
982 | |
983 size = buf->last - src; | |
984 size = len + size / 2 + size / 2 * ctx->length; | |
985 | |
986 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
987 if (cl == NULL) { | |
988 return NULL; | |
989 } | |
990 | |
991 *ll = cl; | |
992 ll = &cl->next; | |
993 | |
994 b = cl->buf; | |
995 dst = b->pos; | |
996 } | |
997 | |
998 while (len) { | |
999 *dst++ = *p++; | |
1000 len--; | |
1001 } | |
1002 } | |
1003 | |
1004 b->last = dst; | |
1005 | |
1006 b->last_buf = buf->last_buf; | |
1007 b->last_in_chain = buf->last_in_chain; | |
1008 b->flush = buf->flush; | |
1009 | |
1010 b->shadow = buf; | |
1011 | |
1012 return out; | |
1013 } | |
1014 | |
1015 | |
1016 static ngx_chain_t * | |
1017 ngx_http_charset_get_buf(ngx_pool_t *pool, ngx_http_charset_ctx_t *ctx) | |
1018 { | |
1019 ngx_chain_t *cl; | |
1020 | |
1021 cl = ctx->free_bufs; | |
1022 | |
1023 if (cl) { | |
1024 ctx->free_bufs = cl->next; | |
1025 | |
1026 cl->buf->shadow = NULL; | |
1027 cl->next = NULL; | |
1028 | |
1029 return cl; | |
1030 } | |
1031 | |
1032 cl = ngx_alloc_chain_link(pool); | |
1033 if (cl == NULL) { | |
1034 return NULL; | |
1035 } | |
1036 | |
1037 cl->buf = ngx_calloc_buf(pool); | |
1038 if (cl->buf == NULL) { | |
1039 return NULL; | |
1040 } | |
1041 | |
1042 cl->next = NULL; | |
1043 | |
1044 cl->buf->tag = (ngx_buf_tag_t) &ngx_http_charset_filter_module; | |
1045 | |
1046 return cl; | |
1047 } | |
1048 | |
1049 | |
1050 static ngx_chain_t * | |
1051 ngx_http_charset_get_buffer(ngx_pool_t *pool, ngx_http_charset_ctx_t *ctx, | |
1052 size_t size) | |
1053 { | |
1054 ngx_buf_t *b; | |
1055 ngx_chain_t *cl, **ll; | |
1056 | |
1057 for (ll = &ctx->free_buffers, cl = ctx->free_buffers; | |
1058 cl; | |
1059 ll = &cl->next, cl = cl->next) | |
1060 { | |
1061 b = cl->buf; | |
1062 | |
1063 if ((size_t) (b->end - b->start) >= size) { | |
1064 *ll = cl->next; | |
1065 cl->next = NULL; | |
1066 | |
1067 b->pos = b->start; | |
1068 b->temporary = 1; | |
1069 b->shadow = NULL; | |
1070 | |
1071 return cl; | |
1072 } | |
1073 } | |
1074 | |
1075 cl = ngx_alloc_chain_link(pool); | |
1076 if (cl == NULL) { | |
1077 return NULL; | |
1078 } | |
1079 | |
1080 cl->buf = ngx_create_temp_buf(pool, size); | |
1081 if (cl->buf == NULL) { | |
1082 return NULL; | |
1083 } | |
1084 | |
1085 cl->next = NULL; | |
1086 | |
1087 cl->buf->temporary = 1; | |
1088 cl->buf->tag = (ngx_buf_tag_t) &ngx_http_charset_filter_module; | |
1089 | |
1090 return cl; | |
1091 } | |
1092 | |
1093 | |
501 | 1094 static char * |
657 | 1095 ngx_http_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1096 { |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1097 ngx_http_charset_main_conf_t *mcf = conf; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1098 |
657 | 1099 char *rv; |
1100 u_char *p, *dst2src, **pp; | |
1101 ngx_int_t src, dst; | |
1102 ngx_uint_t i, n; | |
1103 ngx_str_t *value; | |
1104 ngx_conf_t pvcf; | |
1105 ngx_http_charset_t *charset; | |
1106 ngx_http_charset_tables_t *table; | |
1107 ngx_http_charset_conf_ctx_t ctx; | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1108 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1109 value = cf->args->elts; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1110 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1111 src = ngx_http_add_charset(&mcf->charsets, &value[1]); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1112 if (src == NGX_ERROR) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1113 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1114 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1115 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1116 dst = ngx_http_add_charset(&mcf->charsets, &value[2]); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1117 if (dst == NGX_ERROR) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1118 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1119 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1120 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1121 if (src == dst) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1122 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1123 "\"charset_map\" between the same charsets " |
461 | 1124 "\"%V\" and \"%V\"", &value[1], &value[2]); |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1125 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1126 } |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1127 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1128 table = mcf->tables.elts; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1129 for (i = 0; i < mcf->tables.nelts; i++) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1130 if ((src == table->src && dst == table->dst) |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1131 || (src == table->dst && dst == table->src)) |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1132 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1133 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1134 "duplicate \"charset_map\" between " |
461 | 1135 "\"%V\" and \"%V\"", &value[1], &value[2]); |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1136 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1137 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1138 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1139 |
501 | 1140 table = ngx_array_push(&mcf->tables); |
1141 if (table == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1142 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1143 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1144 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1145 table->src = src; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1146 table->dst = dst; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1147 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
1148 if (ngx_strcasecmp(value[2].data, (u_char *) "utf-8") == 0) { |
657 | 1149 table->src2dst = ngx_pcalloc(cf->pool, 256 * NGX_UTF_LEN); |
1150 if (table->src2dst == NULL) { | |
1151 return NGX_CONF_ERROR; | |
1152 } | |
1153 | |
1154 table->dst2src = ngx_pcalloc(cf->pool, 256 * sizeof(void *)); | |
1155 if (table->dst2src == NULL) { | |
1156 return NGX_CONF_ERROR; | |
1157 } | |
1158 | |
1159 dst2src = ngx_pcalloc(cf->pool, 256); | |
1160 if (dst2src == NULL) { | |
1161 return NGX_CONF_ERROR; | |
1162 } | |
1163 | |
1164 pp = (u_char **) &table->dst2src[0]; | |
1165 pp[0] = dst2src; | |
1166 | |
1167 for (i = 0; i < 128; i++) { | |
1168 p = &table->src2dst[i * NGX_UTF_LEN]; | |
1169 p[0] = '\1'; | |
1170 p[1] = (u_char) i; | |
1171 dst2src[i] = (u_char) i; | |
1172 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1173 |
657 | 1174 for (/* void */; i < 256; i++) { |
1175 p = &table->src2dst[i * NGX_UTF_LEN]; | |
1176 p[0] = '\1'; | |
1177 p[1] = '?'; | |
1178 } | |
1179 | |
1180 } else { | |
1181 table->src2dst = ngx_palloc(cf->pool, 256); | |
1182 if (table->src2dst == NULL) { | |
1183 return NGX_CONF_ERROR; | |
1184 } | |
1185 | |
1186 table->dst2src = ngx_palloc(cf->pool, 256); | |
1187 if (table->dst2src == NULL) { | |
1188 return NGX_CONF_ERROR; | |
1189 } | |
1190 | |
1191 for (i = 0; i < 128; i++) { | |
1192 table->src2dst[i] = (u_char) i; | |
1193 table->dst2src[i] = (u_char) i; | |
1194 } | |
1195 | |
1196 for (/* void */; i < 256; i++) { | |
1197 table->src2dst[i] = '?'; | |
1198 table->dst2src[i] = '?'; | |
1199 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1200 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1201 |
657 | 1202 charset = mcf->charsets.elts; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1203 |
657 | 1204 ctx.table = table; |
1205 ctx.charset = &charset[dst]; | |
1206 ctx.characters = 0; | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1207 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1208 pvcf = *cf; |
657 | 1209 cf->ctx = &ctx; |
1210 cf->handler = ngx_http_charset_map; | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1211 cf->handler_conf = conf; |
501 | 1212 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1213 rv = ngx_conf_parse(cf, NULL); |
501 | 1214 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1215 *cf = pvcf; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1216 |
657 | 1217 if (ctx.characters) { |
1218 n = ctx.charset->length; | |
1219 ctx.charset->length /= ctx.characters; | |
1220 | |
1221 if (((n * 10) / ctx.characters) % 10 > 4) { | |
1222 ctx.charset->length++; | |
1223 } | |
1224 } | |
1225 | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1226 return rv; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1227 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1228 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1229 |
501 | 1230 static char * |
657 | 1231 ngx_http_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1232 { |
657 | 1233 u_char *p, *dst2src, **pp; |
1234 uint32_t n; | |
1235 ngx_int_t src, dst; | |
1236 ngx_str_t *value; | |
1237 ngx_uint_t i; | |
1238 ngx_http_charset_tables_t *table; | |
1239 ngx_http_charset_conf_ctx_t *ctx; | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1240 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1241 if (cf->args->nelts != 2) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1242 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameters number"); |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1243 return NGX_CONF_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1244 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1245 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1246 value = cf->args->elts; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1247 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1248 src = ngx_hextoi(value[0].data, value[0].len); |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1249 if (src == NGX_ERROR || src > 255) { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1250 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
461 | 1251 "invalid value \"%V\"", &value[0]); |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1252 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1253 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1254 |
657 | 1255 ctx = cf->ctx; |
1256 table = ctx->table; | |
1257 | |
1258 if (ctx->charset->utf8) { | |
1259 p = &table->src2dst[src * NGX_UTF_LEN]; | |
1260 | |
1261 *p++ = (u_char) (value[1].len / 2); | |
1262 | |
1263 for (i = 0; i < value[1].len; i += 2) { | |
1264 dst = ngx_hextoi(&value[1].data[i], 2); | |
1265 if (dst == NGX_ERROR || dst > 255) { | |
1266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1267 "invalid value \"%V\"", &value[1]); | |
1268 return NGX_CONF_ERROR; | |
1269 } | |
1270 | |
1271 *p++ = (u_char) dst; | |
1272 } | |
1273 | |
1274 i /= 2; | |
1275 | |
1276 ctx->charset->length += i; | |
1277 ctx->characters++; | |
1278 | |
1279 p = &table->src2dst[src * NGX_UTF_LEN] + 1; | |
1280 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
1281 n = ngx_utf8_decode(&p, i); |
657 | 1282 |
1283 if (n > 0xffff) { | |
1284 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1285 "invalid value \"%V\"", &value[1]); | |
1286 return NGX_CONF_ERROR; | |
1287 } | |
1288 | |
1289 pp = (u_char **) &table->dst2src[0]; | |
1290 | |
1291 dst2src = pp[n >> 8]; | |
1292 | |
1293 if (dst2src == NULL) { | |
1294 dst2src = ngx_pcalloc(cf->pool, 256); | |
1295 if (dst2src == NULL) { | |
1296 return NGX_CONF_ERROR; | |
1297 } | |
1298 | |
1299 pp[n >> 8] = dst2src; | |
1300 } | |
1301 | |
1302 dst2src[n & 0xff] = (u_char) src; | |
1303 | |
1304 } else { | |
1305 dst = ngx_hextoi(value[1].data, value[1].len); | |
1306 if (dst == NGX_ERROR || dst > 255) { | |
1307 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1308 "invalid value \"%V\"", &value[1]); | |
1309 return NGX_CONF_ERROR; | |
1310 } | |
1311 | |
1312 table->src2dst[src] = (u_char) dst; | |
1313 table->dst2src[dst] = (u_char) src; | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1314 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1315 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1316 return NGX_CONF_OK; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1317 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1318 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1319 |
501 | 1320 static char * |
1321 ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1322 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1323 char *p = conf; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1324 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1325 ngx_int_t *cp; |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1326 ngx_str_t *value, var; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1327 ngx_http_charset_main_conf_t *mcf; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1328 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1329 cp = (ngx_int_t *) (p + cmd->offset); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1330 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1331 if (*cp != NGX_CONF_UNSET) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1332 return "is duplicate"; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1333 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1334 |
529 | 1335 value = cf->args->elts; |
1336 | |
1337 if (cmd->offset == offsetof(ngx_http_charset_loc_conf_t, charset) | |
1338 && ngx_strcmp(value[1].data, "off") == 0) | |
1339 { | |
1340 *cp = NGX_HTTP_NO_CHARSET; | |
1341 return NGX_CONF_OK; | |
1342 } | |
1343 | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1344 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1345 if (value[1].data[0] == '$') { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1346 var.len = value[1].len - 1; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1347 var.data = value[1].data + 1; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1348 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1349 *cp = ngx_http_get_variable_index(cf, &var); |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1350 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1351 if (*cp == NGX_ERROR) { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1352 return NGX_CONF_ERROR; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1353 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1354 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1355 *cp += NGX_HTTP_CHARSET_VAR; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1356 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1357 return NGX_CONF_OK; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1358 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1359 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
1360 mcf = ngx_http_conf_get_module_main_conf(cf, |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
1361 ngx_http_charset_filter_module); |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
1362 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1363 *cp = ngx_http_add_charset(&mcf->charsets, &value[1]); |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1364 if (*cp == NGX_ERROR) { |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1365 return NGX_CONF_ERROR; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1366 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1367 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1368 return NGX_CONF_OK; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1369 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1370 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1371 |
501 | 1372 static ngx_int_t |
1373 ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name) | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1374 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1375 ngx_uint_t i; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1376 ngx_http_charset_t *c; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1377 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1378 c = charsets->elts; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1379 for (i = 0; i < charsets->nelts; i++) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1380 if (name->len != c[i].name.len) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1381 continue; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1382 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1383 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1384 if (ngx_strcasecmp(name->data, c[i].name.data) == 0) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1385 break; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1386 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1387 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1388 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1389 if (i < charsets->nelts) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1390 return i; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1391 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1392 |
501 | 1393 c = ngx_array_push(charsets); |
1394 if (c == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1395 return NGX_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1396 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1397 |
455 | 1398 c->tables = NULL; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1399 c->name = *name; |
657 | 1400 c->length = 0; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1401 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
1402 if (ngx_strcasecmp(name->data, (u_char *) "utf-8") == 0) { |
523 | 1403 c->utf8 = 1; |
667 | 1404 |
1405 } else { | |
1406 c->utf8 = 0; | |
523 | 1407 } |
1408 | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1409 return i; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1410 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1411 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1412 |
501 | 1413 static void * |
1414 ngx_http_charset_create_main_conf(ngx_conf_t *cf) | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1415 { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1416 ngx_http_charset_main_conf_t *mcf; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1417 |
501 | 1418 mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)); |
1419 if (mcf == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1420 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1421 } |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1422 |
501 | 1423 if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t)) |
529 | 1424 == NGX_ERROR) |
501 | 1425 { |
1426 return NGX_CONF_ERROR; | |
1427 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1428 |
529 | 1429 if (ngx_array_init(&mcf->tables, cf->pool, 1, |
501 | 1430 sizeof(ngx_http_charset_tables_t)) == NGX_ERROR) |
1431 { | |
1432 return NGX_CONF_ERROR; | |
1433 } | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1434 |
529 | 1435 if (ngx_array_init(&mcf->recodes, cf->pool, 2, |
1436 sizeof(ngx_http_charset_recode_t)) == NGX_ERROR) | |
1437 { | |
1438 return NGX_CONF_ERROR; | |
1439 } | |
1440 | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1441 return mcf; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1442 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1443 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1444 |
501 | 1445 static void * |
1446 ngx_http_charset_create_loc_conf(ngx_conf_t *cf) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1447 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1448 ngx_http_charset_loc_conf_t *lcf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1449 |
501 | 1450 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)); |
1451 if (lcf == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1452 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1453 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1454 |
2167 | 1455 /* |
1456 * set by ngx_pcalloc(): | |
1457 * | |
1458 * lcf->types = { NULL }; | |
1459 * lcf->types_keys = NULL; | |
1460 */ | |
1461 | |
529 | 1462 lcf->charset = NGX_CONF_UNSET; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1463 lcf->source_charset = NGX_CONF_UNSET; |
635 | 1464 lcf->override_charset = NGX_CONF_UNSET; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1465 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1466 return lcf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1467 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1468 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1469 |
501 | 1470 static char * |
1471 ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1472 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1473 ngx_http_charset_loc_conf_t *prev = parent; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1474 ngx_http_charset_loc_conf_t *conf = child; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1475 |
529 | 1476 ngx_uint_t i; |
1477 ngx_http_charset_recode_t *recode; | |
1478 ngx_http_charset_main_conf_t *mcf; | |
477 | 1479 |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1480 if (ngx_http_merge_types(cf, conf->types_keys, &conf->types, |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1481 prev->types_keys, &prev->types, |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1482 ngx_http_charset_default_types) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1483 != NGX_OK) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1484 { |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1485 return NGX_CONF_ERROR; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1486 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1487 |
635 | 1488 ngx_conf_merge_value(conf->override_charset, prev->override_charset, 0); |
529 | 1489 ngx_conf_merge_value(conf->charset, prev->charset, NGX_HTTP_NO_CHARSET); |
477 | 1490 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1491 if (conf->source_charset == NGX_CONF_UNSET) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1492 conf->source_charset = prev->source_charset; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1493 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1494 |
529 | 1495 if (conf->charset == NGX_HTTP_NO_CHARSET |
1496 || conf->source_charset == NGX_CONF_UNSET | |
1497 || conf->charset == conf->source_charset) | |
477 | 1498 { |
529 | 1499 return NGX_CONF_OK; |
477 | 1500 } |
1501 | |
1590 | 1502 if (conf->source_charset >= NGX_HTTP_CHARSET_VAR |
1503 || conf->charset >= NGX_HTTP_CHARSET_VAR) | |
1504 { | |
1505 return NGX_CONF_OK; | |
1506 } | |
1507 | |
529 | 1508 mcf = ngx_http_conf_get_module_main_conf(cf, |
1509 ngx_http_charset_filter_module); | |
1510 recode = mcf->recodes.elts; | |
1511 for (i = 0; i < mcf->recodes.nelts; i++) { | |
1512 if (conf->source_charset == recode[i].src | |
1513 && conf->charset == recode[i].dst) | |
1514 { | |
1515 return NGX_CONF_OK; | |
1516 } | |
477 | 1517 } |
1518 | |
529 | 1519 recode = ngx_array_push(&mcf->recodes); |
1520 if (recode == NULL) { | |
477 | 1521 return NGX_CONF_ERROR; |
1522 } | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1523 |
529 | 1524 recode->src = conf->source_charset; |
1525 recode->dst = conf->charset; | |
1526 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1527 return NGX_CONF_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1528 } |
529 | 1529 |
1530 | |
1531 static ngx_int_t | |
1532 ngx_http_charset_postconfiguration(ngx_conf_t *cf) | |
1533 { | |
635 | 1534 u_char **src, **dst; |
529 | 1535 ngx_int_t c; |
1536 ngx_uint_t i, t; | |
1537 ngx_http_charset_t *charset; | |
1538 ngx_http_charset_recode_t *recode; | |
1539 ngx_http_charset_tables_t *tables; | |
1540 ngx_http_charset_main_conf_t *mcf; | |
1541 | |
1542 mcf = ngx_http_conf_get_module_main_conf(cf, | |
1543 ngx_http_charset_filter_module); | |
1544 | |
1545 recode = mcf->recodes.elts; | |
1546 tables = mcf->tables.elts; | |
1547 charset = mcf->charsets.elts; | |
1548 | |
1549 for (i = 0; i < mcf->recodes.nelts; i++) { | |
1550 | |
1551 c = recode[i].src; | |
1552 | |
1553 for (t = 0; t < mcf->tables.nelts; t++) { | |
1554 | |
1555 if (c == tables[t].src && recode[i].dst == tables[t].dst) { | |
1556 goto next; | |
1557 } | |
1558 | |
1559 if (c == tables[t].dst && recode[i].dst == tables[t].src) { | |
1560 goto next; | |
1561 } | |
1562 } | |
1563 | |
1564 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1588 | 1565 "no \"charset_map\" between the charsets \"%V\" and \"%V\"", |
1566 &charset[c].name, &charset[recode[i].dst].name); | |
529 | 1567 return NGX_ERROR; |
1568 | |
1569 next: | |
1570 continue; | |
1571 } | |
1572 | |
635 | 1573 |
1574 for (t = 0; t < mcf->tables.nelts; t++) { | |
1575 | |
1576 src = charset[tables[t].src].tables; | |
1577 | |
1578 if (src == NULL) { | |
1579 src = ngx_pcalloc(cf->pool, sizeof(u_char *) * mcf->charsets.nelts); | |
1580 if (src == NULL) { | |
1581 return NGX_ERROR; | |
1582 } | |
1583 | |
1584 charset[tables[t].src].tables = src; | |
1585 } | |
1586 | |
1587 dst = charset[tables[t].dst].tables; | |
1588 | |
1589 if (dst == NULL) { | |
1590 dst = ngx_pcalloc(cf->pool, sizeof(u_char *) * mcf->charsets.nelts); | |
1591 if (dst == NULL) { | |
1592 return NGX_ERROR; | |
1593 } | |
1594 | |
1595 charset[tables[t].dst].tables = dst; | |
1596 } | |
1597 | |
1598 src[tables[t].dst] = tables[t].src2dst; | |
1599 dst[tables[t].src] = tables[t].dst2src; | |
1600 } | |
1601 | |
681 | 1602 ngx_http_next_header_filter = ngx_http_top_header_filter; |
1603 ngx_http_top_header_filter = ngx_http_charset_header_filter; | |
1604 | |
1605 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1606 ngx_http_top_body_filter = ngx_http_charset_body_filter; | |
1607 | |
529 | 1608 return NGX_OK; |
1609 } |