50
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
78
|
12 #define NGX_HTTP_NO_CHARSET -2
|
|
13
|
|
14
|
50
|
15 typedef struct {
|
|
16 char **tables;
|
|
17 ngx_str_t name;
|
72
|
18
|
78
|
19 ngx_uint_t utf8; /* unsigned utf8:1; */
|
50
|
20 } ngx_http_charset_t;
|
|
21
|
|
22
|
|
23 typedef struct {
|
72
|
24 ngx_int_t src;
|
|
25 ngx_int_t dst;
|
78
|
26 } ngx_http_charset_recode_t;
|
|
27
|
|
28
|
|
29 typedef struct {
|
|
30 ngx_int_t src;
|
|
31 ngx_int_t dst;
|
72
|
32 char *src2dst;
|
|
33 char *dst2src;
|
50
|
34 } ngx_http_charset_tables_t;
|
|
35
|
|
36
|
|
37 typedef struct {
|
|
38 ngx_array_t charsets; /* ngx_http_charset_t */
|
|
39 ngx_array_t tables; /* ngx_http_charset_tables_t */
|
78
|
40 ngx_array_t recodes; /* ngx_http_charset_recode_t */
|
50
|
41 } ngx_http_charset_main_conf_t;
|
|
42
|
|
43
|
|
44 typedef struct {
|
78
|
45 ngx_int_t charset;
|
72
|
46 ngx_int_t source_charset;
|
50
|
47 } ngx_http_charset_loc_conf_t;
|
|
48
|
|
49
|
|
50 typedef struct {
|
72
|
51 ngx_int_t server;
|
|
52 ngx_int_t client;
|
50
|
53 } ngx_http_charset_ctx_t;
|
|
54
|
|
55
|
78
|
56 static ngx_uint_t ngx_http_charset_recode(ngx_buf_t *b, char *table);
|
50
|
57
|
|
58 static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
59 void *conf);
|
|
60 static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
|
|
61
|
|
62 static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
63 void *conf);
|
|
64 static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name);
|
|
65
|
|
66 static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle);
|
|
67
|
|
68 static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf);
|
|
69 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
|
|
70 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
|
|
71 void *parent, void *child);
|
78
|
72 static ngx_int_t ngx_http_charset_postconfiguration(ngx_conf_t *cf);
|
50
|
73
|
|
74
|
|
75 static ngx_command_t ngx_http_charset_filter_commands[] = {
|
|
76
|
78
|
77 { ngx_string("charset"),
|
|
78 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
|
|
79 |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
|
80 ngx_http_set_charset_slot,
|
|
81 NGX_HTTP_LOC_CONF_OFFSET,
|
|
82 offsetof(ngx_http_charset_loc_conf_t, charset),
|
|
83 NULL },
|
|
84
|
|
85 { ngx_string("source_charset"),
|
|
86 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
|
|
87 |NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
|
|
88 ngx_http_set_charset_slot,
|
|
89 NGX_HTTP_LOC_CONF_OFFSET,
|
|
90 offsetof(ngx_http_charset_loc_conf_t, source_charset),
|
|
91 NULL },
|
|
92
|
50
|
93 { ngx_string("charset_map"),
|
|
94 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
|
|
95 ngx_charset_map_block,
|
|
96 NGX_HTTP_MAIN_CONF_OFFSET,
|
|
97 0,
|
|
98 NULL },
|
|
99
|
|
100 ngx_null_command
|
|
101 };
|
|
102
|
|
103
|
|
104 static ngx_http_module_t ngx_http_charset_filter_module_ctx = {
|
58
|
105 NULL, /* preconfiguration */
|
78
|
106 ngx_http_charset_postconfiguration, /* postconfiguration */
|
50
|
107
|
|
108 ngx_http_charset_create_main_conf, /* create main configuration */
|
78
|
109 NULL, /* init main configuration */
|
50
|
110
|
|
111 NULL, /* create server configuration */
|
|
112 NULL, /* merge server configuration */
|
|
113
|
|
114 ngx_http_charset_create_loc_conf, /* create location configuration */
|
|
115 ngx_http_charset_merge_loc_conf /* merge location configuration */
|
|
116 };
|
|
117
|
|
118
|
|
119 ngx_module_t ngx_http_charset_filter_module = {
|
58
|
120 NGX_MODULE_V1,
|
50
|
121 &ngx_http_charset_filter_module_ctx, /* module context */
|
|
122 ngx_http_charset_filter_commands, /* module directives */
|
|
123 NGX_HTTP_MODULE, /* module type */
|
|
124 ngx_http_charset_filter_init, /* init module */
|
|
125 NULL /* init process */
|
|
126 };
|
|
127
|
|
128
|
|
129 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
|
130 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
|
|
131
|
|
132
|
|
133 static ngx_int_t
|
|
134 ngx_http_charset_header_filter(ngx_http_request_t *r)
|
|
135 {
|
|
136 ngx_http_charset_t *charsets;
|
|
137 ngx_http_charset_ctx_t *ctx;
|
|
138 ngx_http_charset_loc_conf_t *lcf;
|
|
139 ngx_http_charset_main_conf_t *mcf;
|
|
140
|
|
141 mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module);
|
|
142 lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module);
|
|
143
|
78
|
144 if (lcf->charset == NGX_HTTP_NO_CHARSET) {
|
50
|
145 return ngx_http_next_header_filter(r);
|
|
146 }
|
|
147
|
58
|
148 if (r->headers_out.content_type.len == 0) {
|
50
|
149 return ngx_http_next_header_filter(r);
|
|
150 }
|
|
151
|
58
|
152 if (ngx_strncasecmp(r->headers_out.content_type.data, "text/", 5) != 0
|
|
153 && ngx_strncasecmp(r->headers_out.content_type.data,
|
|
154 "application/x-javascript", 24) != 0)
|
50
|
155 {
|
|
156 return ngx_http_next_header_filter(r);
|
|
157 }
|
|
158
|
58
|
159 if (ngx_strstr(r->headers_out.content_type.data, "charset") != NULL)
|
50
|
160 {
|
|
161 return ngx_http_next_header_filter(r);
|
|
162 }
|
|
163
|
|
164 if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY
|
|
165 || r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
|
|
166 {
|
|
167 /*
|
|
168 * do not set charset for the redirect because NN 4.x uses this
|
|
169 * charset instead of the next page charset
|
|
170 */
|
|
171
|
|
172 r->headers_out.charset.len = 0;
|
|
173 return ngx_http_next_header_filter(r);
|
|
174 }
|
|
175
|
|
176 if (r->headers_out.charset.len) {
|
|
177 return ngx_http_next_header_filter(r);
|
|
178 }
|
|
179
|
|
180 charsets = mcf->charsets.elts;
|
78
|
181 r->headers_out.charset = charsets[lcf->charset].name;
|
|
182 r->utf8 = charsets[lcf->charset].utf8;
|
50
|
183
|
78
|
184 if (lcf->source_charset == NGX_CONF_UNSET
|
|
185 || lcf->source_charset == lcf->charset)
|
|
186 {
|
50
|
187 return ngx_http_next_header_filter(r);
|
|
188 }
|
|
189
|
|
190
|
|
191 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t));
|
|
192 if (ctx == NULL) {
|
|
193 return NGX_ERROR;
|
|
194 }
|
|
195
|
|
196 ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module);
|
|
197
|
|
198
|
|
199 r->filter_need_in_memory = 1;
|
|
200
|
|
201 return ngx_http_next_header_filter(r);
|
|
202 }
|
|
203
|
|
204
|
|
205 static ngx_int_t
|
|
206 ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|
207 {
|
|
208 char *table;
|
|
209 ngx_chain_t *cl;
|
|
210 ngx_http_charset_t *charsets;
|
|
211 ngx_http_charset_ctx_t *ctx;
|
|
212 ngx_http_charset_loc_conf_t *lcf;
|
|
213 ngx_http_charset_main_conf_t *mcf;
|
|
214
|
|
215 ctx = ngx_http_get_module_ctx(r, ngx_http_charset_filter_module);
|
|
216
|
|
217 if (ctx == NULL) {
|
|
218 return ngx_http_next_body_filter(r, in);
|
|
219 }
|
|
220
|
|
221 mcf = ngx_http_get_module_main_conf(r, ngx_http_charset_filter_module);
|
|
222 lcf = ngx_http_get_module_loc_conf(r, ngx_http_charset_filter_module);
|
|
223
|
|
224 charsets = mcf->charsets.elts;
|
78
|
225 table = charsets[lcf->source_charset].tables[lcf->charset];
|
50
|
226
|
|
227 for (cl = in; cl; cl = cl->next) {
|
78
|
228 ngx_http_charset_recode(cl->buf, table);
|
50
|
229 }
|
|
230
|
|
231 return ngx_http_next_body_filter(r, in);
|
|
232 }
|
|
233
|
|
234
|
|
235 static ngx_uint_t
|
78
|
236 ngx_http_charset_recode(ngx_buf_t *b, char *table)
|
50
|
237 {
|
|
238 u_char *p;
|
|
239 ngx_uint_t change;
|
|
240
|
|
241 change = 0;
|
|
242
|
|
243 for (p = b->pos; p < b->last; p++) {
|
|
244 if (*p != table[*p]) {
|
|
245 change = 1;
|
|
246 break;
|
|
247 }
|
|
248 }
|
|
249
|
|
250 if (change) {
|
|
251
|
|
252 while (p < b->last) {
|
|
253 *p = table[*p];
|
|
254 p++;
|
|
255 }
|
|
256
|
|
257 b->in_file = 0;
|
|
258 }
|
|
259
|
|
260 return change;
|
|
261 }
|
|
262
|
|
263
|
|
264 static char *
|
|
265 ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
266 {
|
|
267 ngx_http_charset_main_conf_t *mcf = conf;
|
|
268
|
|
269 char *rv;
|
|
270 ngx_int_t src, dst;
|
|
271 ngx_uint_t i;
|
|
272 ngx_str_t *value;
|
|
273 ngx_conf_t pvcf;
|
|
274 ngx_http_charset_tables_t *table;
|
|
275
|
|
276 value = cf->args->elts;
|
|
277
|
|
278 src = ngx_http_add_charset(&mcf->charsets, &value[1]);
|
|
279 if (src == NGX_ERROR) {
|
|
280 return NGX_CONF_ERROR;
|
|
281 }
|
|
282
|
|
283 dst = ngx_http_add_charset(&mcf->charsets, &value[2]);
|
|
284 if (dst == NGX_ERROR) {
|
|
285 return NGX_CONF_ERROR;
|
|
286 }
|
|
287
|
|
288 if (src == dst) {
|
|
289 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
290 "\"charset_map\" between the same charsets "
|
|
291 "\"%V\" and \"%V\"", &value[1], &value[2]);
|
|
292 return NGX_CONF_ERROR;
|
|
293 }
|
|
294
|
|
295 table = mcf->tables.elts;
|
|
296 for (i = 0; i < mcf->tables.nelts; i++) {
|
|
297 if ((src == table->src && dst == table->dst)
|
|
298 || (src == table->dst && dst == table->src))
|
|
299 {
|
|
300 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
301 "duplicate \"charset_map\" between "
|
|
302 "\"%V\" and \"%V\"", &value[1], &value[2]);
|
|
303 return NGX_CONF_ERROR;
|
|
304 }
|
|
305 }
|
|
306
|
|
307 table = ngx_array_push(&mcf->tables);
|
|
308 if (table == NULL) {
|
|
309 return NGX_CONF_ERROR;
|
|
310 }
|
|
311
|
|
312 table->src = src;
|
|
313 table->dst = dst;
|
|
314
|
|
315 table->src2dst = ngx_palloc(cf->pool, 256);
|
|
316 if (table->src2dst == NULL) {
|
|
317 return NGX_CONF_ERROR;
|
|
318 }
|
|
319
|
|
320 table->dst2src = ngx_palloc(cf->pool, 256);
|
|
321 if (table->dst2src == NULL) {
|
|
322 return NGX_CONF_ERROR;
|
|
323 }
|
|
324
|
|
325 for (i = 0; i < 128; i++) {
|
|
326 table->src2dst[i] = (char) i;
|
|
327 table->dst2src[i] = (char) i;
|
|
328 }
|
|
329
|
|
330 for (/* void */; i < 256; i++) {
|
|
331 table->src2dst[i] = '?';
|
|
332 table->dst2src[i] = '?';
|
|
333 }
|
|
334
|
|
335 pvcf = *cf;
|
|
336 cf->ctx = table;
|
|
337 cf->handler = ngx_charset_map;
|
|
338 cf->handler_conf = conf;
|
|
339
|
|
340 rv = ngx_conf_parse(cf, NULL);
|
|
341
|
|
342 *cf = pvcf;
|
|
343
|
|
344 return rv;
|
|
345 }
|
|
346
|
|
347
|
|
348 static char *
|
|
349 ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|
350 {
|
|
351 ngx_int_t src, dst;
|
|
352 ngx_str_t *value;
|
|
353 ngx_http_charset_tables_t *table;
|
|
354
|
|
355 if (cf->args->nelts != 2) {
|
|
356 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameters number");
|
|
357 return NGX_CONF_ERROR;
|
|
358 }
|
|
359
|
|
360 value = cf->args->elts;
|
|
361
|
|
362 src = ngx_hextoi(value[0].data, value[0].len);
|
|
363 if (src == NGX_ERROR || src > 255) {
|
|
364 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
365 "invalid value \"%V\"", &value[0]);
|
|
366 return NGX_CONF_ERROR;
|
|
367 }
|
|
368
|
|
369 dst = ngx_hextoi(value[1].data, value[1].len);
|
|
370 if (dst == NGX_ERROR || dst > 255) {
|
|
371 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
372 "invalid value \"%V\"", &value[1]);
|
|
373 return NGX_CONF_ERROR;
|
|
374 }
|
|
375
|
|
376 table = cf->ctx;
|
|
377
|
|
378 table->src2dst[src] = (char) dst;
|
|
379 table->dst2src[dst] = (char) src;
|
|
380
|
|
381 return NGX_CONF_OK;
|
|
382 }
|
|
383
|
|
384
|
|
385 static char *
|
|
386 ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
387 {
|
|
388 char *p = conf;
|
|
389
|
|
390 ngx_int_t *cp;
|
|
391 ngx_str_t *value;
|
|
392 ngx_http_charset_main_conf_t *mcf;
|
|
393
|
|
394 cp = (ngx_int_t *) (p + cmd->offset);
|
|
395
|
|
396 if (*cp != NGX_CONF_UNSET) {
|
|
397 return "is duplicate";
|
|
398 }
|
|
399
|
78
|
400 value = cf->args->elts;
|
|
401
|
|
402 if (cmd->offset == offsetof(ngx_http_charset_loc_conf_t, charset)
|
|
403 && ngx_strcmp(value[1].data, "off") == 0)
|
|
404 {
|
|
405 *cp = NGX_HTTP_NO_CHARSET;
|
|
406 return NGX_CONF_OK;
|
|
407 }
|
|
408
|
50
|
409 mcf = ngx_http_conf_get_module_main_conf(cf,
|
|
410 ngx_http_charset_filter_module);
|
|
411
|
|
412 *cp = ngx_http_add_charset(&mcf->charsets, &value[1]);
|
|
413 if (*cp == NGX_ERROR) {
|
|
414 return NGX_CONF_ERROR;
|
|
415 }
|
|
416
|
|
417 return NGX_CONF_OK;
|
|
418 }
|
|
419
|
|
420
|
|
421 static ngx_int_t
|
|
422 ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
|
|
423 {
|
|
424 ngx_uint_t i;
|
|
425 ngx_http_charset_t *c;
|
|
426
|
|
427 c = charsets->elts;
|
|
428 for (i = 0; i < charsets->nelts; i++) {
|
|
429 if (name->len != c[i].name.len) {
|
|
430 continue;
|
|
431 }
|
|
432
|
|
433 if (ngx_strcasecmp(name->data, c[i].name.data) == 0) {
|
|
434 break;
|
|
435 }
|
|
436 }
|
|
437
|
|
438 if (i < charsets->nelts) {
|
|
439 return i;
|
|
440 }
|
|
441
|
|
442 c = ngx_array_push(charsets);
|
|
443 if (c == NULL) {
|
|
444 return NGX_ERROR;
|
|
445 }
|
|
446
|
|
447 c->tables = NULL;
|
|
448 c->name = *name;
|
|
449
|
72
|
450 if (ngx_strcasecmp(name->data, "utf-8") == 0) {
|
|
451 c->utf8 = 1;
|
|
452 }
|
|
453
|
50
|
454 return i;
|
|
455 }
|
|
456
|
|
457
|
|
458 static ngx_int_t
|
|
459 ngx_http_charset_filter_init(ngx_cycle_t *cycle)
|
|
460 {
|
|
461 ngx_http_next_header_filter = ngx_http_top_header_filter;
|
|
462 ngx_http_top_header_filter = ngx_http_charset_header_filter;
|
|
463
|
|
464 ngx_http_next_body_filter = ngx_http_top_body_filter;
|
|
465 ngx_http_top_body_filter = ngx_http_charset_body_filter;
|
|
466
|
|
467 return NGX_OK;
|
|
468 }
|
|
469
|
|
470
|
|
471 static void *
|
|
472 ngx_http_charset_create_main_conf(ngx_conf_t *cf)
|
|
473 {
|
|
474 ngx_http_charset_main_conf_t *mcf;
|
|
475
|
|
476 mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t));
|
|
477 if (mcf == NULL) {
|
|
478 return NGX_CONF_ERROR;
|
|
479 }
|
|
480
|
|
481 if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t))
|
78
|
482 == NGX_ERROR)
|
50
|
483 {
|
|
484 return NGX_CONF_ERROR;
|
|
485 }
|
|
486
|
78
|
487 if (ngx_array_init(&mcf->tables, cf->pool, 1,
|
50
|
488 sizeof(ngx_http_charset_tables_t)) == NGX_ERROR)
|
|
489 {
|
|
490 return NGX_CONF_ERROR;
|
|
491 }
|
|
492
|
78
|
493 if (ngx_array_init(&mcf->recodes, cf->pool, 2,
|
|
494 sizeof(ngx_http_charset_recode_t)) == NGX_ERROR)
|
|
495 {
|
|
496 return NGX_CONF_ERROR;
|
|
497 }
|
|
498
|
50
|
499 return mcf;
|
|
500 }
|
|
501
|
|
502
|
|
503 static void *
|
|
504 ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
|
|
505 {
|
|
506 ngx_http_charset_loc_conf_t *lcf;
|
|
507
|
|
508 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t));
|
|
509 if (lcf == NULL) {
|
|
510 return NGX_CONF_ERROR;
|
|
511 }
|
|
512
|
78
|
513 lcf->charset = NGX_CONF_UNSET;
|
50
|
514 lcf->source_charset = NGX_CONF_UNSET;
|
|
515
|
|
516 return lcf;
|
|
517 }
|
|
518
|
|
519
|
|
520 static char *
|
|
521 ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
522 {
|
|
523 ngx_http_charset_loc_conf_t *prev = parent;
|
|
524 ngx_http_charset_loc_conf_t *conf = child;
|
|
525
|
78
|
526 ngx_uint_t i;
|
|
527 ngx_http_charset_recode_t *recode;
|
|
528 ngx_http_charset_main_conf_t *mcf;
|
50
|
529
|
78
|
530 ngx_conf_merge_value(conf->charset, prev->charset, NGX_HTTP_NO_CHARSET);
|
50
|
531
|
|
532 if (conf->source_charset == NGX_CONF_UNSET) {
|
|
533 conf->source_charset = prev->source_charset;
|
|
534 }
|
|
535
|
78
|
536 if (conf->charset == NGX_HTTP_NO_CHARSET
|
|
537 || conf->source_charset == NGX_CONF_UNSET
|
|
538 || conf->charset == conf->source_charset)
|
50
|
539 {
|
78
|
540 return NGX_CONF_OK;
|
50
|
541 }
|
|
542
|
78
|
543 mcf = ngx_http_conf_get_module_main_conf(cf,
|
|
544 ngx_http_charset_filter_module);
|
|
545 recode = mcf->recodes.elts;
|
|
546 for (i = 0; i < mcf->recodes.nelts; i++) {
|
|
547 if (conf->source_charset == recode[i].src
|
|
548 && conf->charset == recode[i].dst)
|
|
549 {
|
|
550 return NGX_CONF_OK;
|
|
551 }
|
50
|
552 }
|
|
553
|
78
|
554 recode = ngx_array_push(&mcf->recodes);
|
|
555 if (recode == NULL) {
|
50
|
556 return NGX_CONF_ERROR;
|
|
557 }
|
|
558
|
78
|
559 recode->src = conf->source_charset;
|
|
560 recode->dst = conf->charset;
|
|
561
|
50
|
562 return NGX_CONF_OK;
|
|
563 }
|
78
|
564
|
|
565
|
|
566 static ngx_int_t
|
|
567 ngx_http_charset_postconfiguration(ngx_conf_t *cf)
|
|
568 {
|
|
569 ngx_int_t c;
|
|
570 ngx_uint_t i, t;
|
|
571 ngx_http_charset_t *charset;
|
|
572 ngx_http_charset_recode_t *recode;
|
|
573 ngx_http_charset_tables_t *tables;
|
|
574 ngx_http_charset_main_conf_t *mcf;
|
|
575
|
|
576 mcf = ngx_http_conf_get_module_main_conf(cf,
|
|
577 ngx_http_charset_filter_module);
|
|
578
|
|
579 recode = mcf->recodes.elts;
|
|
580 tables = mcf->tables.elts;
|
|
581 charset = mcf->charsets.elts;
|
|
582
|
|
583 for (i = 0; i < mcf->recodes.nelts; i++) {
|
|
584
|
|
585 c = recode[i].src;
|
|
586
|
|
587 charset[c].tables = ngx_pcalloc(cf->pool,
|
|
588 sizeof(char *) * mcf->charsets.nelts);
|
|
589 if (charset[c].tables == NULL) {
|
|
590 return NGX_ERROR;
|
|
591 }
|
|
592
|
|
593 for (t = 0; t < mcf->tables.nelts; t++) {
|
|
594
|
|
595 if (c == tables[t].src && recode[i].dst == tables[t].dst) {
|
|
596 charset[c].tables[tables[t].dst] = tables[t].src2dst;
|
|
597 goto next;
|
|
598 }
|
|
599
|
|
600 if (c == tables[t].dst && recode[i].dst == tables[t].src) {
|
|
601 charset[c].tables[tables[t].src] = tables[t].dst2src;
|
|
602 goto next;
|
|
603 }
|
|
604 }
|
|
605
|
|
606 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
|
607 " no \"charset_map\" between the charsets "
|
|
608 "\"%V\" and \"%V\"",
|
|
609 &charset[c].name, &charset[recode[i].dst].name);
|
|
610 return NGX_ERROR;
|
|
611
|
|
612 next:
|
|
613 continue;
|
|
614 }
|
|
615
|
|
616 return NGX_OK;
|
|
617 }
|