Mercurial > hg > nginx
annotate src/http/modules/ngx_http_charset_filter_module.c @ 2890:a4302032b831
fix the previous commit
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 25 May 2009 19:57:25 +0000 |
parents | 0bb8c54f4c45 |
children | 76dfc19dcd49 |
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) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
255 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
256 if (r == r->main) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
257 ngx_http_set_charset(r, &dst); |
661 | 258 } |
635 | 259 |
657 | 260 return ngx_http_next_header_filter(r); |
261 } | |
635 | 262 |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
263 if (charset == NGX_HTTP_NO_CHARSET |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
264 || source_charset == NGX_HTTP_NO_CHARSET) |
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 if (source_charset != charset |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
267 || 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
|
268 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
269 goto no_charset_map; |
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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
272 ngx_http_set_charset(r, &dst); |
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 return ngx_http_next_header_filter(r); |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
275 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
276 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
277 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
|
278 charsets = mcf->charsets.elts; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
279 |
657 | 280 if (source_charset != charset |
281 && (charsets[source_charset].tables == NULL | |
282 || charsets[source_charset].tables[charset] == NULL)) | |
283 { | |
663 | 284 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
|
285 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
286 |
657 | 287 r->headers_out.content_type.len = r->headers_out.content_type_len; |
288 | |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
289 ngx_http_set_charset(r, &dst); |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
290 |
2890 | 291 if (source_charset != charset) { |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
292 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
|
293 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
294 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
295 return ngx_http_next_header_filter(r); |
663 | 296 |
297 no_charset_map: | |
298 | |
299 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1587 | 300 "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
|
301 &src, &dst); |
663 | 302 |
303 return ngx_http_next_header_filter(r); | |
657 | 304 } |
305 | |
306 | |
307 static ngx_int_t | |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
308 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
|
309 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
310 ngx_int_t charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
311 ngx_http_charset_t *charsets; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
312 ngx_http_variable_value_t *vv; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
313 ngx_http_charset_loc_conf_t *mlcf; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
314 ngx_http_charset_main_conf_t *mcf; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
315 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
316 if (!r->ignore_content_encoding |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
317 && r->headers_out.content_encoding |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
318 && r->headers_out.content_encoding->value.len) |
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 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
321 } |
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 if (r->headers_out.content_type.len == 0) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
324 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
325 } |
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 if (r->headers_out.override_charset |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
328 && r->headers_out.override_charset->len) |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
329 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
330 *name = *r->headers_out.override_charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
331 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
332 charset = ngx_http_get_charset(r, name); |
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 if (charset != NGX_HTTP_NO_CHARSET) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
335 return charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
336 } |
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 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
|
339 "unknown charset \"%V\" to override", name); |
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 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
342 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
343 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
344 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
|
345 charset = mlcf->charset; |
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 if (charset == NGX_HTTP_CHARSET_OFF) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
348 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
349 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
350 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
351 if (r->headers_out.charset.len) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
352 if (mlcf->override_charset == 0) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
353 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
354 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
355 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
356 } else { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
357 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
|
358 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
359 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
360 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
361 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
362 if (charset < NGX_HTTP_CHARSET_VAR) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
363 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
|
364 charsets = mcf->charsets.elts; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
365 *name = charsets[charset].name; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
366 return charset; |
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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
369 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
|
370 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
371 if (vv == NULL || vv->not_found) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
372 return NGX_ERROR; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
373 } |
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 name->len = vv->len; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
376 name->data = vv->data; |
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 return ngx_http_get_charset(r, name); |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
379 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
380 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
381 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
382 static ngx_int_t |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
383 ngx_http_main_request_charset(ngx_http_request_t *r, ngx_str_t *src) |
657 | 384 { |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
385 ngx_int_t charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
386 ngx_str_t *main_charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
387 ngx_http_charset_ctx_t *ctx; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
388 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
389 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
|
390 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
391 if (ctx) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
392 *src = ctx->charset_name; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
393 return ctx->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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
396 main_charset = &r->main->headers_out.charset; |
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 if (main_charset->len == 0) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
399 return NGX_DECLINED; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
400 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
401 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
402 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
|
403 if (ctx == NULL) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
404 return NGX_ERROR; |
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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
407 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
|
408 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
409 charset = ngx_http_get_charset(r, main_charset); |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
410 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
411 ctx->charset = charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
412 ctx->charset_name = *main_charset; |
2890 | 413 *src = *main_charset; |
2889
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 return charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
416 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
417 |
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 static ngx_int_t |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
420 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
|
421 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
422 ngx_int_t charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
423 ngx_http_charset_t *charsets; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
424 ngx_http_variable_value_t *vv; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
425 ngx_http_charset_loc_conf_t *lcf; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
426 ngx_http_charset_main_conf_t *mcf; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
427 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
428 if (r->headers_out.charset.len) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
429 *name = r->headers_out.charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
430 return ngx_http_get_charset(r, name); |
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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
433 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
|
434 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
435 charset = lcf->source_charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
436 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
437 if (charset == NGX_HTTP_CHARSET_OFF) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
438 name->len = 0; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
439 return charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
440 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
441 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
442 if (charset < NGX_HTTP_CHARSET_VAR) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
443 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
|
444 charsets = mcf->charsets.elts; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
445 *name = charsets[charset].name; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
446 return charset; |
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 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
449 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
|
450 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
451 if (vv == NULL || vv->not_found) { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
452 return NGX_ERROR; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
453 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
454 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
455 name->len = vv->len; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
456 name->data = vv->data; |
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 return ngx_http_get_charset(r, name); |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
459 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
460 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
461 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
462 static ngx_int_t |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
463 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
|
464 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
465 ngx_uint_t i, n; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
466 ngx_http_charset_t *charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
467 ngx_http_charset_main_conf_t *mcf; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
468 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
469 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
|
470 |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
471 charset = mcf->charsets.elts; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
472 n = mcf->charsets.nelts; |
657 | 473 |
474 for (i = 0; i < n; i++) { | |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
475 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
|
476 continue; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
477 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
478 |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
479 if (ngx_strncasecmp(charset[i].name.data, name->data, name->len) == 0) { |
657 | 480 return i; |
481 } | |
482 } | |
483 | |
484 return NGX_HTTP_NO_CHARSET; | |
485 } | |
486 | |
487 | |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
488 static ngx_inline void |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
489 ngx_http_set_charset(ngx_http_request_t *r, ngx_str_t *charset) |
657 | 490 { |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
491 if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY |
501 | 492 || 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
|
493 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
494 /* |
635 | 495 * do not set charset for the redirect because NN 4.x |
496 * 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
|
497 */ |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
498 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
499 r->headers_out.charset.len = 0; |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
500 return; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
501 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
502 |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
503 r->headers_out.charset = *charset; |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
504 } |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
505 |
635 | 506 |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
507 static ngx_int_t |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
508 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
|
509 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
|
510 { |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
511 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
|
512 |
501 | 513 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t)); |
514 if (ctx == NULL) { | |
515 return NGX_ERROR; | |
516 } | |
517 | |
518 ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module); | |
519 | |
635 | 520 ctx->table = charsets[source_charset].tables[charset]; |
521 ctx->charset = charset; | |
2890 | 522 ctx->charset_name = charsets[charset].name; |
657 | 523 ctx->length = charsets[charset].length; |
524 ctx->from_utf8 = charsets[source_charset].utf8; | |
525 ctx->to_utf8 = charsets[charset].utf8; | |
526 | |
663 | 527 r->filter_need_in_memory = 1; |
528 | |
657 | 529 if ((ctx->to_utf8 || ctx->from_utf8) && r == r->main) { |
530 ngx_http_clear_content_length(r); | |
663 | 531 |
532 } else { | |
533 r->filter_need_temporary = 1; | |
657 | 534 } |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
535 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
536 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
|
537 } |
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 |
501 | 540 static ngx_int_t |
541 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
|
542 { |
657 | 543 ngx_int_t rc; |
544 ngx_buf_t *b; | |
545 ngx_chain_t *cl, *out, **ll; | |
635 | 546 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
|
547 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
548 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
|
549 |
635 | 550 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
|
551 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
|
552 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
553 |
657 | 554 if ((ctx->to_utf8 || ctx->from_utf8) || ctx->busy) { |
555 | |
556 out = NULL; | |
557 ll = &out; | |
558 | |
559 for (cl = in; cl; cl = cl->next) { | |
560 b = cl->buf; | |
561 | |
562 if (ngx_buf_size(b) == 0) { | |
665 | 563 |
564 *ll = ngx_alloc_chain_link(r->pool); | |
565 if (*ll == NULL) { | |
566 return NGX_ERROR; | |
567 } | |
568 | |
569 (*ll)->buf = b; | |
570 (*ll)->next = NULL; | |
571 | |
572 ll = &(*ll)->next; | |
573 | |
657 | 574 continue; |
575 } | |
576 | |
577 if (ctx->to_utf8) { | |
578 *ll = ngx_http_charset_recode_to_utf8(r->pool, b, ctx); | |
579 | |
580 } else { | |
581 *ll = ngx_http_charset_recode_from_utf8(r->pool, b, ctx); | |
582 } | |
583 | |
584 if (*ll == NULL) { | |
585 return NGX_ERROR; | |
586 } | |
587 | |
588 while (*ll) { | |
589 ll = &(*ll)->next; | |
590 } | |
591 } | |
592 | |
593 rc = ngx_http_next_body_filter(r, out); | |
594 | |
595 if (out) { | |
596 if (ctx->busy == NULL) { | |
597 ctx->busy = out; | |
598 | |
599 } else { | |
600 for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ } | |
601 cl->next = out; | |
602 } | |
603 } | |
604 | |
605 while (ctx->busy) { | |
606 | |
607 cl = ctx->busy; | |
608 b = cl->buf; | |
609 | |
610 if (ngx_buf_size(b) != 0) { | |
611 break; | |
612 } | |
613 | |
614 ctx->busy = cl->next; | |
615 | |
616 if (b->tag != (ngx_buf_tag_t) &ngx_http_charset_filter_module) { | |
617 continue; | |
618 } | |
619 | |
620 if (b->shadow) { | |
621 b->shadow->pos = b->shadow->last; | |
622 } | |
623 | |
624 if (b->pos) { | |
625 cl->next = ctx->free_buffers; | |
626 ctx->free_buffers = cl; | |
627 continue; | |
628 } | |
629 | |
630 cl->next = ctx->free_bufs; | |
631 ctx->free_bufs = cl; | |
632 } | |
633 | |
634 return rc; | |
635 } | |
636 | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
637 for (cl = in; cl; cl = cl->next) { |
635 | 638 (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
|
639 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
640 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
139
diff
changeset
|
641 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
|
642 } |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
643 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
644 |
501 | 645 static ngx_uint_t |
635 | 646 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
|
647 { |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
648 u_char *p, *last; |
635 | 649 |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
650 last = b->last; |
455 | 651 |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
652 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
|
653 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
654 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
|
655 goto recode; |
455 | 656 } |
657 } | |
658 | |
635 | 659 return 0; |
1944
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
660 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
661 recode: |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
662 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
663 do { |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
664 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
|
665 *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 } |
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 p++; |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
669 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
670 } while (p < last); |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
671 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
672 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
|
673 |
be6c9033a798
speed up ngx_http_charset_recode() for 25%: google-perftools reported
Igor Sysoev <igor@sysoev.ru>
parents:
1590
diff
changeset
|
674 return 1; |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
675 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
676 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
677 |
657 | 678 static ngx_chain_t * |
679 ngx_http_charset_recode_from_utf8(ngx_pool_t *pool, ngx_buf_t *buf, | |
680 ngx_http_charset_ctx_t *ctx) | |
681 { | |
682 size_t len, size; | |
683 u_char c, *p, *src, *dst, *saved, **table; | |
684 uint32_t n; | |
685 ngx_buf_t *b; | |
686 ngx_uint_t i; | |
687 ngx_chain_t *out, *cl, **ll; | |
688 | |
689 src = buf->pos; | |
690 | |
691 if (ctx->saved_len == 0) { | |
692 | |
693 for ( /* void */ ; src < buf->last; src++) { | |
694 | |
695 if (*src < 0x80) { | |
696 continue; | |
697 } | |
698 | |
699 len = src - buf->pos; | |
700 | |
701 if (len > 512) { | |
702 out = ngx_http_charset_get_buf(pool, ctx); | |
703 if (out == NULL) { | |
704 return NULL; | |
705 } | |
706 | |
707 b = out->buf; | |
708 | |
709 b->temporary = buf->temporary; | |
710 b->memory = buf->memory; | |
711 b->mmap = buf->mmap; | |
712 b->flush = buf->flush; | |
713 | |
714 b->pos = buf->pos; | |
715 b->last = src; | |
716 | |
717 out->buf = b; | |
718 out->next = NULL; | |
719 | |
720 size = buf->last - src; | |
721 | |
722 saved = src; | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
723 n = ngx_utf8_decode(&saved, size); |
657 | 724 |
725 if (n == 0xfffffffe) { | |
726 /* incomplete UTF-8 symbol */ | |
727 | |
728 ngx_memcpy(ctx->saved, src, size); | |
729 ctx->saved_len = size; | |
730 | |
731 b->shadow = buf; | |
732 | |
733 return out; | |
734 } | |
735 | |
736 } else { | |
737 out = NULL; | |
738 size = len + buf->last - src; | |
739 src = buf->pos; | |
740 } | |
741 | |
742 if (size < NGX_HTML_ENTITY_LEN) { | |
743 size += NGX_HTML_ENTITY_LEN; | |
744 } | |
745 | |
746 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
747 if (cl == NULL) { | |
748 return NULL; | |
749 } | |
750 | |
751 if (out) { | |
752 out->next = cl; | |
753 | |
754 } else { | |
755 out = cl; | |
756 } | |
757 | |
758 b = cl->buf; | |
759 dst = b->pos; | |
760 | |
761 goto recode; | |
762 } | |
763 | |
764 out = ngx_alloc_chain_link(pool); | |
765 if (out == NULL) { | |
766 return NULL; | |
767 } | |
768 | |
769 out->buf = buf; | |
770 out->next = NULL; | |
771 | |
772 return out; | |
773 } | |
774 | |
775 /* process incomplete UTF sequence from previous buffer */ | |
776 | |
777 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
778 "http charset utf saved: %z", ctx->saved_len); | |
779 | |
780 p = src; | |
781 | |
782 for (i = ctx->saved_len; i < NGX_UTF_LEN; i++) { | |
783 ctx->saved[i] = *p++; | |
784 | |
785 if (p == buf->last) { | |
786 break; | |
787 } | |
788 } | |
789 | |
790 saved = ctx->saved; | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
791 n = ngx_utf8_decode(&saved, i); |
657 | 792 |
793 c = '\0'; | |
794 | |
795 if (n < 0x10000) { | |
796 table = (u_char **) ctx->table; | |
797 p = table[n >> 8]; | |
798 | |
799 if (p) { | |
800 c = p[n & 0xff]; | |
801 } | |
802 | |
803 } else if (n == 0xfffffffe) { | |
804 | |
805 /* incomplete UTF-8 symbol */ | |
806 | |
807 if (i < NGX_UTF_LEN) { | |
808 out = ngx_http_charset_get_buf(pool, ctx); | |
809 if (out == NULL) { | |
810 return NULL; | |
811 } | |
812 | |
813 b = out->buf; | |
814 | |
815 b->pos = buf->pos; | |
816 b->last = buf->last; | |
817 b->sync = 1; | |
818 b->shadow = buf; | |
819 | |
820 ngx_memcpy(&ctx->saved[ctx->saved_len], src, i); | |
821 ctx->saved_len += i; | |
822 | |
823 return out; | |
824 } | |
825 } | |
826 | |
827 size = buf->last - buf->pos; | |
828 | |
829 if (size < NGX_HTML_ENTITY_LEN) { | |
830 size += NGX_HTML_ENTITY_LEN; | |
831 } | |
832 | |
833 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
834 if (cl == NULL) { | |
835 return NULL; | |
836 } | |
837 | |
838 out = cl; | |
839 | |
840 b = cl->buf; | |
841 dst = b->pos; | |
842 | |
843 if (c) { | |
844 *dst++ = c; | |
845 | |
846 } else if (n == 0xfffffffe) { | |
847 *dst++ = '?'; | |
848 | |
849 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
850 "http charset invalid utf 0"); | |
851 | |
852 saved = &ctx->saved[NGX_UTF_LEN]; | |
853 | |
854 } else if (n > 0x10ffff) { | |
855 *dst++ = '?'; | |
856 | |
857 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
858 "http charset invalid utf 1"); | |
859 | |
860 } else { | |
861 dst = ngx_sprintf(dst, "&#%uD;", n); | |
862 } | |
863 | |
864 src += (saved - ctx->saved) - ctx->saved_len; | |
865 ctx->saved_len = 0; | |
866 | |
867 recode: | |
868 | |
869 ll = &cl->next; | |
870 | |
871 table = (u_char **) ctx->table; | |
872 | |
873 while (src < buf->last) { | |
874 | |
875 if ((size_t) (b->end - dst) < NGX_HTML_ENTITY_LEN) { | |
876 b->last = dst; | |
877 | |
878 size = buf->last - src + NGX_HTML_ENTITY_LEN; | |
879 | |
880 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
881 if (cl == NULL) { | |
882 return NULL; | |
883 } | |
884 | |
885 *ll = cl; | |
886 ll = &cl->next; | |
887 | |
888 b = cl->buf; | |
889 dst = b->pos; | |
890 } | |
891 | |
892 if (*src < 0x80) { | |
893 *dst++ = *src++; | |
894 continue; | |
895 } | |
896 | |
897 len = buf->last - src; | |
898 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
899 n = ngx_utf8_decode(&src, len); |
657 | 900 |
901 if (n < 0x10000) { | |
902 | |
903 p = table[n >> 8]; | |
904 | |
905 if (p) { | |
906 c = p[n & 0xff]; | |
907 | |
908 if (c) { | |
909 *dst++ = c; | |
910 continue; | |
911 } | |
912 } | |
913 | |
914 dst = ngx_sprintf(dst, "&#%uD;", n); | |
915 | |
916 continue; | |
917 } | |
918 | |
919 if (n == 0xfffffffe) { | |
920 /* incomplete UTF-8 symbol */ | |
921 | |
922 ngx_memcpy(ctx->saved, src, len); | |
923 ctx->saved_len = len; | |
924 | |
925 if (b->pos == dst) { | |
926 b->sync = 1; | |
927 b->temporary = 0; | |
928 } | |
929 | |
930 break; | |
931 } | |
932 | |
933 if (n > 0x10ffff) { | |
934 *dst++ = '?'; | |
935 | |
936 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pool->log, 0, | |
937 "http charset invalid utf 2"); | |
938 | |
939 continue; | |
940 } | |
941 | |
942 /* n > 0xffff */ | |
943 | |
944 dst = ngx_sprintf(dst, "&#%uD;", n); | |
945 } | |
946 | |
947 b->last = dst; | |
948 | |
949 b->last_buf = buf->last_buf; | |
950 b->last_in_chain = buf->last_in_chain; | |
951 b->flush = buf->flush; | |
952 | |
953 b->shadow = buf; | |
954 | |
955 return out; | |
956 } | |
957 | |
958 | |
959 static ngx_chain_t * | |
960 ngx_http_charset_recode_to_utf8(ngx_pool_t *pool, ngx_buf_t *buf, | |
961 ngx_http_charset_ctx_t *ctx) | |
962 { | |
963 size_t len, size; | |
964 u_char *p, *src, *dst, *table; | |
965 ngx_buf_t *b; | |
966 ngx_chain_t *out, *cl, **ll; | |
967 | |
968 table = ctx->table; | |
969 | |
970 for (src = buf->pos; src < buf->last; src++) { | |
971 if (table[*src * NGX_UTF_LEN] == '\1') { | |
972 continue; | |
973 } | |
974 | |
975 goto recode; | |
976 } | |
977 | |
978 out = ngx_alloc_chain_link(pool); | |
979 if (out == NULL) { | |
980 return NULL; | |
981 } | |
982 | |
983 out->buf = buf; | |
984 out->next = NULL; | |
985 | |
986 return out; | |
987 | |
988 recode: | |
989 | |
990 /* | |
991 * we assume that there are about half of characters to be recoded, | |
992 * so we preallocate "size / 2 + size / 2 * ctx->length" | |
993 */ | |
994 | |
995 len = src - buf->pos; | |
996 | |
997 if (len > 512) { | |
998 out = ngx_http_charset_get_buf(pool, ctx); | |
999 if (out == NULL) { | |
1000 return NULL; | |
1001 } | |
1002 | |
1003 b = out->buf; | |
1004 | |
1005 b->temporary = buf->temporary; | |
1006 b->memory = buf->memory; | |
1007 b->mmap = buf->mmap; | |
1008 b->flush = buf->flush; | |
1009 | |
1010 b->pos = buf->pos; | |
1011 b->last = src; | |
1012 | |
1013 out->buf = b; | |
1014 out->next = NULL; | |
1015 | |
1016 size = buf->last - src; | |
1017 size = size / 2 + size / 2 * ctx->length; | |
1018 | |
1019 } else { | |
1020 out = NULL; | |
1021 | |
1022 size = buf->last - src; | |
1023 size = len + size / 2 + size / 2 * ctx->length; | |
1024 | |
1025 src = buf->pos; | |
1026 } | |
1027 | |
1028 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
1029 if (cl == NULL) { | |
1030 return NULL; | |
1031 } | |
1032 | |
1033 if (out) { | |
1034 out->next = cl; | |
1035 | |
1036 } else { | |
1037 out = cl; | |
1038 } | |
1039 | |
1040 ll = &cl->next; | |
1041 | |
1042 b = cl->buf; | |
1043 dst = b->pos; | |
1044 | |
1045 while (src < buf->last) { | |
1046 | |
1047 p = &table[*src++ * NGX_UTF_LEN]; | |
1048 len = *p++; | |
1049 | |
1050 if ((size_t) (b->end - dst) < len) { | |
1051 b->last = dst; | |
1052 | |
1053 size = buf->last - src; | |
1054 size = len + size / 2 + size / 2 * ctx->length; | |
1055 | |
1056 cl = ngx_http_charset_get_buffer(pool, ctx, size); | |
1057 if (cl == NULL) { | |
1058 return NULL; | |
1059 } | |
1060 | |
1061 *ll = cl; | |
1062 ll = &cl->next; | |
1063 | |
1064 b = cl->buf; | |
1065 dst = b->pos; | |
1066 } | |
1067 | |
1068 while (len) { | |
1069 *dst++ = *p++; | |
1070 len--; | |
1071 } | |
1072 } | |
1073 | |
1074 b->last = dst; | |
1075 | |
1076 b->last_buf = buf->last_buf; | |
1077 b->last_in_chain = buf->last_in_chain; | |
1078 b->flush = buf->flush; | |
1079 | |
1080 b->shadow = buf; | |
1081 | |
1082 return out; | |
1083 } | |
1084 | |
1085 | |
1086 static ngx_chain_t * | |
1087 ngx_http_charset_get_buf(ngx_pool_t *pool, ngx_http_charset_ctx_t *ctx) | |
1088 { | |
1089 ngx_chain_t *cl; | |
1090 | |
1091 cl = ctx->free_bufs; | |
1092 | |
1093 if (cl) { | |
1094 ctx->free_bufs = cl->next; | |
1095 | |
1096 cl->buf->shadow = NULL; | |
1097 cl->next = NULL; | |
1098 | |
1099 return cl; | |
1100 } | |
1101 | |
1102 cl = ngx_alloc_chain_link(pool); | |
1103 if (cl == NULL) { | |
1104 return NULL; | |
1105 } | |
1106 | |
1107 cl->buf = ngx_calloc_buf(pool); | |
1108 if (cl->buf == NULL) { | |
1109 return NULL; | |
1110 } | |
1111 | |
1112 cl->next = NULL; | |
1113 | |
1114 cl->buf->tag = (ngx_buf_tag_t) &ngx_http_charset_filter_module; | |
1115 | |
1116 return cl; | |
1117 } | |
1118 | |
1119 | |
1120 static ngx_chain_t * | |
1121 ngx_http_charset_get_buffer(ngx_pool_t *pool, ngx_http_charset_ctx_t *ctx, | |
1122 size_t size) | |
1123 { | |
1124 ngx_buf_t *b; | |
1125 ngx_chain_t *cl, **ll; | |
1126 | |
1127 for (ll = &ctx->free_buffers, cl = ctx->free_buffers; | |
1128 cl; | |
1129 ll = &cl->next, cl = cl->next) | |
1130 { | |
1131 b = cl->buf; | |
1132 | |
1133 if ((size_t) (b->end - b->start) >= size) { | |
1134 *ll = cl->next; | |
1135 cl->next = NULL; | |
1136 | |
1137 b->pos = b->start; | |
1138 b->temporary = 1; | |
1139 b->shadow = NULL; | |
1140 | |
1141 return cl; | |
1142 } | |
1143 } | |
1144 | |
1145 cl = ngx_alloc_chain_link(pool); | |
1146 if (cl == NULL) { | |
1147 return NULL; | |
1148 } | |
1149 | |
1150 cl->buf = ngx_create_temp_buf(pool, size); | |
1151 if (cl->buf == NULL) { | |
1152 return NULL; | |
1153 } | |
1154 | |
1155 cl->next = NULL; | |
1156 | |
1157 cl->buf->temporary = 1; | |
1158 cl->buf->tag = (ngx_buf_tag_t) &ngx_http_charset_filter_module; | |
1159 | |
1160 return cl; | |
1161 } | |
1162 | |
1163 | |
501 | 1164 static char * |
657 | 1165 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
|
1166 { |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1167 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
|
1168 |
657 | 1169 char *rv; |
1170 u_char *p, *dst2src, **pp; | |
1171 ngx_int_t src, dst; | |
1172 ngx_uint_t i, n; | |
1173 ngx_str_t *value; | |
1174 ngx_conf_t pvcf; | |
1175 ngx_http_charset_t *charset; | |
1176 ngx_http_charset_tables_t *table; | |
1177 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
|
1178 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1179 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
|
1180 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1181 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
|
1182 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
|
1183 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
|
1184 } |
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 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
|
1187 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
|
1188 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
|
1189 } |
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 if (src == dst) { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1192 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
|
1193 "\"charset_map\" between the same charsets " |
461 | 1194 "\"%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
|
1195 return NGX_CONF_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1196 } |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1197 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1198 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
|
1199 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
|
1200 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
|
1201 || (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
|
1202 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1203 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
|
1204 "duplicate \"charset_map\" between " |
461 | 1205 "\"%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
|
1206 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
|
1207 } |
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 |
501 | 1210 table = ngx_array_push(&mcf->tables); |
1211 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
|
1212 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
|
1213 } |
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 table->src = src; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1216 table->dst = dst; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1217 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
1218 if (ngx_strcasecmp(value[2].data, (u_char *) "utf-8") == 0) { |
657 | 1219 table->src2dst = ngx_pcalloc(cf->pool, 256 * NGX_UTF_LEN); |
1220 if (table->src2dst == NULL) { | |
1221 return NGX_CONF_ERROR; | |
1222 } | |
1223 | |
1224 table->dst2src = ngx_pcalloc(cf->pool, 256 * sizeof(void *)); | |
1225 if (table->dst2src == NULL) { | |
1226 return NGX_CONF_ERROR; | |
1227 } | |
1228 | |
1229 dst2src = ngx_pcalloc(cf->pool, 256); | |
1230 if (dst2src == NULL) { | |
1231 return NGX_CONF_ERROR; | |
1232 } | |
1233 | |
1234 pp = (u_char **) &table->dst2src[0]; | |
1235 pp[0] = dst2src; | |
1236 | |
1237 for (i = 0; i < 128; i++) { | |
1238 p = &table->src2dst[i * NGX_UTF_LEN]; | |
1239 p[0] = '\1'; | |
1240 p[1] = (u_char) i; | |
1241 dst2src[i] = (u_char) i; | |
1242 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1243 |
657 | 1244 for (/* void */; i < 256; i++) { |
1245 p = &table->src2dst[i * NGX_UTF_LEN]; | |
1246 p[0] = '\1'; | |
1247 p[1] = '?'; | |
1248 } | |
1249 | |
1250 } else { | |
1251 table->src2dst = ngx_palloc(cf->pool, 256); | |
1252 if (table->src2dst == NULL) { | |
1253 return NGX_CONF_ERROR; | |
1254 } | |
1255 | |
1256 table->dst2src = ngx_palloc(cf->pool, 256); | |
1257 if (table->dst2src == NULL) { | |
1258 return NGX_CONF_ERROR; | |
1259 } | |
1260 | |
1261 for (i = 0; i < 128; i++) { | |
1262 table->src2dst[i] = (u_char) i; | |
1263 table->dst2src[i] = (u_char) i; | |
1264 } | |
1265 | |
1266 for (/* void */; i < 256; i++) { | |
1267 table->src2dst[i] = '?'; | |
1268 table->dst2src[i] = '?'; | |
1269 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1270 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1271 |
657 | 1272 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
|
1273 |
657 | 1274 ctx.table = table; |
1275 ctx.charset = &charset[dst]; | |
1276 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
|
1277 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1278 pvcf = *cf; |
657 | 1279 cf->ctx = &ctx; |
1280 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
|
1281 cf->handler_conf = conf; |
501 | 1282 |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1283 rv = ngx_conf_parse(cf, NULL); |
501 | 1284 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1285 *cf = pvcf; |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1286 |
657 | 1287 if (ctx.characters) { |
1288 n = ctx.charset->length; | |
1289 ctx.charset->length /= ctx.characters; | |
1290 | |
1291 if (((n * 10) / ctx.characters) % 10 > 4) { | |
1292 ctx.charset->length++; | |
1293 } | |
1294 } | |
1295 | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1296 return rv; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1297 } |
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 |
501 | 1300 static char * |
657 | 1301 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
|
1302 { |
657 | 1303 u_char *p, *dst2src, **pp; |
1304 uint32_t n; | |
1305 ngx_int_t src, dst; | |
1306 ngx_str_t *value; | |
1307 ngx_uint_t i; | |
1308 ngx_http_charset_tables_t *table; | |
1309 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
|
1310 |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1311 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
|
1312 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
|
1313 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
|
1314 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1315 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1316 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
|
1317 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1318 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
|
1319 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
|
1320 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
461 | 1321 "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
|
1322 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
|
1323 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1324 |
657 | 1325 ctx = cf->ctx; |
1326 table = ctx->table; | |
1327 | |
1328 if (ctx->charset->utf8) { | |
1329 p = &table->src2dst[src * NGX_UTF_LEN]; | |
1330 | |
1331 *p++ = (u_char) (value[1].len / 2); | |
1332 | |
1333 for (i = 0; i < value[1].len; i += 2) { | |
1334 dst = ngx_hextoi(&value[1].data[i], 2); | |
1335 if (dst == NGX_ERROR || dst > 255) { | |
1336 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1337 "invalid value \"%V\"", &value[1]); | |
1338 return NGX_CONF_ERROR; | |
1339 } | |
1340 | |
1341 *p++ = (u_char) dst; | |
1342 } | |
1343 | |
1344 i /= 2; | |
1345 | |
1346 ctx->charset->length += i; | |
1347 ctx->characters++; | |
1348 | |
1349 p = &table->src2dst[src * NGX_UTF_LEN] + 1; | |
1350 | |
2125
8e4b9d2acde8
rename ngx_utf_...() to ngx_utf8_...()
Igor Sysoev <igor@sysoev.ru>
parents:
2050
diff
changeset
|
1351 n = ngx_utf8_decode(&p, i); |
657 | 1352 |
1353 if (n > 0xffff) { | |
1354 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1355 "invalid value \"%V\"", &value[1]); | |
1356 return NGX_CONF_ERROR; | |
1357 } | |
1358 | |
1359 pp = (u_char **) &table->dst2src[0]; | |
1360 | |
1361 dst2src = pp[n >> 8]; | |
1362 | |
1363 if (dst2src == NULL) { | |
1364 dst2src = ngx_pcalloc(cf->pool, 256); | |
1365 if (dst2src == NULL) { | |
1366 return NGX_CONF_ERROR; | |
1367 } | |
1368 | |
1369 pp[n >> 8] = dst2src; | |
1370 } | |
1371 | |
1372 dst2src[n & 0xff] = (u_char) src; | |
1373 | |
1374 } else { | |
1375 dst = ngx_hextoi(value[1].data, value[1].len); | |
1376 if (dst == NGX_ERROR || dst > 255) { | |
1377 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1378 "invalid value \"%V\"", &value[1]); | |
1379 return NGX_CONF_ERROR; | |
1380 } | |
1381 | |
1382 table->src2dst[src] = (u_char) dst; | |
1383 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
|
1384 } |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1385 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1386 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
|
1387 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1388 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1389 |
501 | 1390 static char * |
1391 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
|
1392 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1393 char *p = conf; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1394 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1395 ngx_int_t *cp; |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1396 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
|
1397 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
|
1398 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1399 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
|
1400 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1401 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
|
1402 return "is duplicate"; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1403 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1404 |
529 | 1405 value = cf->args->elts; |
1406 | |
1407 if (cmd->offset == offsetof(ngx_http_charset_loc_conf_t, charset) | |
1408 && ngx_strcmp(value[1].data, "off") == 0) | |
1409 { | |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
1410 *cp = NGX_HTTP_CHARSET_OFF; |
529 | 1411 return NGX_CONF_OK; |
1412 } | |
1413 | |
752
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1414 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1415 if (value[1].data[0] == '$') { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1416 var.len = value[1].len - 1; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1417 var.data = value[1].data + 1; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1418 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1419 *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
|
1420 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1421 if (*cp == NGX_ERROR) { |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1422 return NGX_CONF_ERROR; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1423 } |
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 *cp += NGX_HTTP_CHARSET_VAR; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1426 |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1427 return NGX_CONF_OK; |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1428 } |
907361d07f25
ngx_http_charset_module supports the variables
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
1429 |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
389
diff
changeset
|
1430 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
|
1431 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
|
1432 |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1433 *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
|
1434 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
|
1435 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
|
1436 } |
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 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
|
1439 } |
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 |
501 | 1442 static ngx_int_t |
1443 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
|
1444 { |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1445 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
|
1446 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
|
1447 |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1448 c = charsets->elts; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1449 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
|
1450 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
|
1451 continue; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1452 } |
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 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
|
1455 break; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1456 } |
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 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
|
1460 return i; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1461 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1462 |
501 | 1463 c = ngx_array_push(charsets); |
1464 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
|
1465 return NGX_ERROR; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1466 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1467 |
455 | 1468 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
|
1469 c->name = *name; |
657 | 1470 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
|
1471 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
797
diff
changeset
|
1472 if (ngx_strcasecmp(name->data, (u_char *) "utf-8") == 0) { |
523 | 1473 c->utf8 = 1; |
667 | 1474 |
1475 } else { | |
1476 c->utf8 = 0; | |
523 | 1477 } |
1478 | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1479 return i; |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1480 } |
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 |
501 | 1483 static void * |
1484 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
|
1485 { |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1486 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
|
1487 |
501 | 1488 mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)); |
1489 if (mcf == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1490 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
|
1491 } |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1492 |
501 | 1493 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
|
1494 != NGX_OK) |
501 | 1495 { |
1496 return NGX_CONF_ERROR; | |
1497 } | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1498 |
529 | 1499 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
|
1500 sizeof(ngx_http_charset_tables_t)) |
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2414
diff
changeset
|
1501 != NGX_OK) |
501 | 1502 { |
1503 return NGX_CONF_ERROR; | |
1504 } | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1505 |
529 | 1506 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
|
1507 sizeof(ngx_http_charset_recode_t)) |
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2414
diff
changeset
|
1508 != NGX_OK) |
529 | 1509 { |
1510 return NGX_CONF_ERROR; | |
1511 } | |
1512 | |
338
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1513 return mcf; |
0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
307
diff
changeset
|
1514 } |
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 |
501 | 1517 static void * |
1518 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
|
1519 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1520 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
|
1521 |
501 | 1522 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)); |
1523 if (lcf == NULL) { | |
339
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1524 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
|
1525 } |
8c5b69141dfd
nginx-0.0.3-2004-05-21-20:12:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
338
diff
changeset
|
1526 |
2167 | 1527 /* |
1528 * set by ngx_pcalloc(): | |
1529 * | |
1530 * lcf->types = { NULL }; | |
1531 * lcf->types_keys = NULL; | |
1532 */ | |
1533 | |
529 | 1534 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
|
1535 lcf->source_charset = NGX_CONF_UNSET; |
635 | 1536 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
|
1537 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1538 return lcf; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1539 } |
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 |
501 | 1542 static char * |
1543 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
|
1544 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1545 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
|
1546 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
|
1547 |
529 | 1548 ngx_uint_t i; |
1549 ngx_http_charset_recode_t *recode; | |
1550 ngx_http_charset_main_conf_t *mcf; | |
477 | 1551 |
2175
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1552 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
|
1553 prev->types_keys, &prev->types, |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1554 ngx_http_charset_default_types) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1555 != NGX_OK) |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1556 { |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1557 return NGX_CONF_ERROR; |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1558 } |
a69886fc2864
*) fix segfaults in types hash
Igor Sysoev <igor@sysoev.ru>
parents:
2167
diff
changeset
|
1559 |
635 | 1560 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
|
1561 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
|
1562 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
|
1563 NGX_HTTP_CHARSET_OFF); |
477 | 1564 |
2889
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
1565 if (conf->charset == NGX_HTTP_CHARSET_OFF |
0bb8c54f4c45
refactor ngx_http_charset_header_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2877
diff
changeset
|
1566 || conf->source_charset == NGX_HTTP_CHARSET_OFF |
529 | 1567 || conf->charset == conf->source_charset) |
477 | 1568 { |
529 | 1569 return NGX_CONF_OK; |
477 | 1570 } |
1571 | |
1590 | 1572 if (conf->source_charset >= NGX_HTTP_CHARSET_VAR |
1573 || conf->charset >= NGX_HTTP_CHARSET_VAR) | |
1574 { | |
1575 return NGX_CONF_OK; | |
1576 } | |
1577 | |
529 | 1578 mcf = ngx_http_conf_get_module_main_conf(cf, |
1579 ngx_http_charset_filter_module); | |
1580 recode = mcf->recodes.elts; | |
1581 for (i = 0; i < mcf->recodes.nelts; i++) { | |
1582 if (conf->source_charset == recode[i].src | |
1583 && conf->charset == recode[i].dst) | |
1584 { | |
1585 return NGX_CONF_OK; | |
1586 } | |
477 | 1587 } |
1588 | |
529 | 1589 recode = ngx_array_push(&mcf->recodes); |
1590 if (recode == NULL) { | |
477 | 1591 return NGX_CONF_ERROR; |
1592 } | |
340
0bf903191ceb
nginx-0.0.3-2004-05-25-19:28:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
339
diff
changeset
|
1593 |
529 | 1594 recode->src = conf->source_charset; |
1595 recode->dst = conf->charset; | |
1596 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1597 return NGX_CONF_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1598 } |
529 | 1599 |
1600 | |
1601 static ngx_int_t | |
1602 ngx_http_charset_postconfiguration(ngx_conf_t *cf) | |
1603 { | |
635 | 1604 u_char **src, **dst; |
529 | 1605 ngx_int_t c; |
1606 ngx_uint_t i, t; | |
1607 ngx_http_charset_t *charset; | |
1608 ngx_http_charset_recode_t *recode; | |
1609 ngx_http_charset_tables_t *tables; | |
1610 ngx_http_charset_main_conf_t *mcf; | |
1611 | |
1612 mcf = ngx_http_conf_get_module_main_conf(cf, | |
1613 ngx_http_charset_filter_module); | |
1614 | |
1615 recode = mcf->recodes.elts; | |
1616 tables = mcf->tables.elts; | |
1617 charset = mcf->charsets.elts; | |
1618 | |
1619 for (i = 0; i < mcf->recodes.nelts; i++) { | |
1620 | |
1621 c = recode[i].src; | |
1622 | |
1623 for (t = 0; t < mcf->tables.nelts; t++) { | |
1624 | |
1625 if (c == tables[t].src && recode[i].dst == tables[t].dst) { | |
1626 goto next; | |
1627 } | |
1628 | |
1629 if (c == tables[t].dst && recode[i].dst == tables[t].src) { | |
1630 goto next; | |
1631 } | |
1632 } | |
1633 | |
1634 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1588 | 1635 "no \"charset_map\" between the charsets \"%V\" and \"%V\"", |
1636 &charset[c].name, &charset[recode[i].dst].name); | |
529 | 1637 return NGX_ERROR; |
1638 | |
1639 next: | |
1640 continue; | |
1641 } | |
1642 | |
635 | 1643 |
1644 for (t = 0; t < mcf->tables.nelts; t++) { | |
1645 | |
1646 src = charset[tables[t].src].tables; | |
1647 | |
1648 if (src == NULL) { | |
1649 src = ngx_pcalloc(cf->pool, sizeof(u_char *) * mcf->charsets.nelts); | |
1650 if (src == NULL) { | |
1651 return NGX_ERROR; | |
1652 } | |
1653 | |
1654 charset[tables[t].src].tables = src; | |
1655 } | |
1656 | |
1657 dst = charset[tables[t].dst].tables; | |
1658 | |
1659 if (dst == NULL) { | |
1660 dst = ngx_pcalloc(cf->pool, sizeof(u_char *) * mcf->charsets.nelts); | |
1661 if (dst == NULL) { | |
1662 return NGX_ERROR; | |
1663 } | |
1664 | |
1665 charset[tables[t].dst].tables = dst; | |
1666 } | |
1667 | |
1668 src[tables[t].dst] = tables[t].src2dst; | |
1669 dst[tables[t].src] = tables[t].dst2src; | |
1670 } | |
1671 | |
681 | 1672 ngx_http_next_header_filter = ngx_http_top_header_filter; |
1673 ngx_http_top_header_filter = ngx_http_charset_header_filter; | |
1674 | |
1675 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1676 ngx_http_top_body_filter = ngx_http_charset_body_filter; | |
1677 | |
529 | 1678 return NGX_OK; |
1679 } |