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