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