Mercurial > hg > nginx
comparison src/http/modules/ngx_http_charset_filter.c @ 338:0376cffa29e6
nginx-0.0.3-2004-05-20-21:33:52 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 20 May 2004 17:33:52 +0000 |
parents | ce375c313e96 |
children | 8c5b69141dfd |
comparison
equal
deleted
inserted
replaced
337:4feff829a849 | 338:0376cffa29e6 |
---|---|
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_http.h> | 4 #include <ngx_http.h> |
5 | 5 |
6 | 6 |
7 typedef struct { | 7 typedef struct { |
8 ngx_str_t from; | |
9 ngx_str_t to; | |
10 char *table; | |
11 } ngx_http_charset_table_t; | |
12 | |
13 | |
14 typedef struct { | |
15 ngx_array_t tables; /* ngx_http_charset_table_t */ | |
16 } ngx_http_charset_main_conf_t; | |
17 | |
18 | |
19 typedef struct { | |
8 ngx_str_t default_charset; | 20 ngx_str_t default_charset; |
9 } ngx_http_charset_loc_conf_t; | 21 } ngx_http_charset_loc_conf_t; |
10 | 22 |
11 | 23 |
24 static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, | |
25 void *conf); | |
26 static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf); | |
27 | |
12 static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); | 28 static int ngx_http_charset_filter_init(ngx_cycle_t *cycle); |
29 | |
30 static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf); | |
13 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf); | 31 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf); |
14 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, | 32 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, |
15 void *parent, void *child); | 33 void *parent, void *child); |
16 | 34 |
17 | 35 |
18 static ngx_command_t ngx_http_charset_filter_commands[] = { | 36 static ngx_command_t ngx_http_charset_filter_commands[] = { |
19 | 37 |
20 {ngx_string("default_charset"), | 38 { ngx_string("charset_map"), |
21 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 39 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2, |
22 ngx_conf_set_str_slot, | 40 ngx_charset_map_block, |
23 NGX_HTTP_LOC_CONF_OFFSET, | 41 NGX_HTTP_MAIN_CONF_OFFSET, |
24 offsetof(ngx_http_charset_loc_conf_t, default_charset), | 42 0, |
25 NULL}, | 43 NULL }, |
26 | 44 |
27 ngx_null_command | 45 { ngx_string("default_charset"), |
46 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
47 ngx_conf_set_str_slot, | |
48 NGX_HTTP_LOC_CONF_OFFSET, | |
49 offsetof(ngx_http_charset_loc_conf_t, default_charset), | |
50 NULL }, | |
51 | |
52 ngx_null_command | |
28 }; | 53 }; |
29 | 54 |
30 | 55 |
31 static ngx_http_module_t ngx_http_charset_filter_module_ctx = { | 56 static ngx_http_module_t ngx_http_charset_filter_module_ctx = { |
32 NULL, /* pre conf */ | 57 NULL, /* pre conf */ |
33 | 58 |
34 NULL, /* create main configuration */ | 59 ngx_http_charset_create_main_conf, /* create main configuration */ |
35 NULL, /* init main configuration */ | 60 NULL, /* init main configuration */ |
36 | 61 |
37 NULL, /* create server configuration */ | 62 NULL, /* create server configuration */ |
38 NULL, /* merge server configuration */ | 63 NULL, /* merge server configuration */ |
39 | 64 |
104 return ngx_http_next_body_filter(r, in); | 129 return ngx_http_next_body_filter(r, in); |
105 } | 130 } |
106 #endif | 131 #endif |
107 | 132 |
108 | 133 |
134 static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, | |
135 void *conf) | |
136 { | |
137 char *rv; | |
138 ngx_conf_t pcf; | |
139 | |
140 pcf = *cf; | |
141 cf->handler = ngx_charset_map; | |
142 cf->handler_conf = conf; | |
143 rv = ngx_conf_parse(cf, NULL); | |
144 *cf = pcf; | |
145 | |
146 return rv; | |
147 } | |
148 | |
149 | |
150 static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | |
151 { | |
152 ngx_http_charset_main_conf_t *mcf = conf; | |
153 | |
154 ngx_int_t src, dst; | |
155 ngx_str_t *args; | |
156 | |
157 if (cf->args->nelts != 2) { | |
158 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameters number"); | |
159 return NGX_CONF_ERROR; | |
160 } | |
161 | |
162 args = cf->args->elts; | |
163 | |
164 src = ngx_hextoi(args[0].data, args[0].len); | |
165 if (src == NGX_ERROR || src > 255) { | |
166 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
167 "invalid value \"%s\"", args[0].data); | |
168 return NGX_CONF_ERROR; | |
169 } | |
170 | |
171 dst = ngx_hextoi(args[1].data, args[1].len); | |
172 if (dst == NGX_ERROR || dst > 255) { | |
173 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
174 "invalid value \"%s\"", args[1].data); | |
175 return NGX_CONF_ERROR; | |
176 } | |
177 | |
178 #if 0 | |
179 mcf->tables[src] = dst; | |
180 #endif | |
181 | |
182 return NGX_CONF_OK; | |
183 } | |
184 | |
185 | |
109 static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) | 186 static int ngx_http_charset_filter_init(ngx_cycle_t *cycle) |
110 { | 187 { |
111 ngx_http_next_header_filter = ngx_http_top_header_filter; | 188 ngx_http_next_header_filter = ngx_http_top_header_filter; |
112 ngx_http_top_header_filter = ngx_http_charset_header_filter; | 189 ngx_http_top_header_filter = ngx_http_charset_header_filter; |
113 | 190 |
115 ngx_http_next_body_filter = ngx_http_top_body_filter; | 192 ngx_http_next_body_filter = ngx_http_top_body_filter; |
116 ngx_http_top_body_filter = ngx_http_charset_body_filter; | 193 ngx_http_top_body_filter = ngx_http_charset_body_filter; |
117 #endif | 194 #endif |
118 | 195 |
119 return NGX_OK; | 196 return NGX_OK; |
197 } | |
198 | |
199 | |
200 static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf) | |
201 { | |
202 ngx_http_charset_main_conf_t *mcf; | |
203 | |
204 ngx_test_null(mcf, | |
205 ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)), | |
206 NGX_CONF_ERROR); | |
207 | |
208 ngx_init_array(mcf->tables, cf->pool, 10, sizeof(ngx_http_charset_table_t), | |
209 NGX_CONF_ERROR); | |
210 | |
211 return mcf; | |
120 } | 212 } |
121 | 213 |
122 | 214 |
123 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf) | 215 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf) |
124 { | 216 { |