Mercurial > hg > nginx
annotate src/http/modules/ngx_http_browser_module.c @ 2509:b4661481f198
the $ancient_browser variables did not treat as an ancient browser
listed in modern_browser, but has lower version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 18 Feb 2009 09:23:47 +0000 |
parents | 4c43e25d11ea |
children | fa03c3846ca4 |
rev | line source |
---|---|
700 | 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 | |
12 /* | |
13 * The module can check browser versions conforming to the following formats: | |
14 * X, X.X, X.X.X, and X.X.X.X. The maximum values of each format may be | |
15 * 4000, 4000.99, 4000.99.99, and 4000.99.99.99. | |
16 */ | |
17 | |
18 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
19 #define NGX_HTTP_MODERN_BROWSER 0 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
20 #define NGX_HTTP_ANCIENT_BROWSER 1 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
21 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
22 |
700 | 23 typedef struct { |
24 u_char browser[12]; | |
25 size_t skip; | |
26 size_t add; | |
27 u_char name[12]; | |
28 } ngx_http_modern_browser_mask_t; | |
29 | |
30 | |
31 typedef struct { | |
32 ngx_uint_t version; | |
33 size_t skip; | |
34 size_t add; | |
35 u_char name[12]; | |
36 } ngx_http_modern_browser_t; | |
37 | |
38 | |
39 typedef struct { | |
40 ngx_str_t name; | |
41 ngx_http_get_variable_pt handler; | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
42 uintptr_t data; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
43 } ngx_http_browser_variable_t; |
700 | 44 |
45 | |
46 typedef struct { | |
47 ngx_array_t *modern_browsers; | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
48 ngx_array_t *ancient_browsers; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
49 ngx_http_variable_value_t *modern_browser_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
50 ngx_http_variable_value_t *ancient_browser_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
51 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
52 unsigned modern_unlisted_browsers:1; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
53 unsigned netscape4:1; |
700 | 54 } ngx_http_browser_conf_t; |
55 | |
56 | |
57 static ngx_int_t ngx_http_msie_variable(ngx_http_request_t *r, | |
58 ngx_http_variable_value_t *v, uintptr_t data); | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
59 static ngx_int_t ngx_http_browser_variable(ngx_http_request_t *r, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
60 ngx_http_variable_value_t *v, uintptr_t data); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
61 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
62 static ngx_uint_t ngx_http_browser(ngx_http_request_t *r, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
63 ngx_http_browser_conf_t *cf); |
754
4ac89c5aa10d
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
718
diff
changeset
|
64 |
700 | 65 static ngx_int_t ngx_http_browser_add_variable(ngx_conf_t *cf); |
66 static void *ngx_http_browser_create_conf(ngx_conf_t *cf); | |
67 static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent, | |
68 void *child); | |
69 static int ngx_libc_cdecl ngx_http_modern_browser_sort(const void *one, | |
70 const void *two); | |
71 static char *ngx_http_modern_browser(ngx_conf_t *cf, ngx_command_t *cmd, | |
72 void *conf); | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
73 static char *ngx_http_ancient_browser(ngx_conf_t *cf, ngx_command_t *cmd, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
74 void *conf); |
700 | 75 static char *ngx_http_modern_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, |
76 void *conf); | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
77 static char *ngx_http_ancient_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
78 void *conf); |
700 | 79 |
80 | |
81 static ngx_command_t ngx_http_browser_commands[] = { | |
82 | |
83 { ngx_string("modern_browser"), | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
84 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
700 | 85 ngx_http_modern_browser, |
86 NGX_HTTP_LOC_CONF_OFFSET, | |
87 0, | |
88 NULL }, | |
89 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
90 { ngx_string("ancient_browser"), |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
91 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
92 ngx_http_ancient_browser, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
93 NGX_HTTP_LOC_CONF_OFFSET, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
94 0, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
95 NULL }, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
96 |
700 | 97 { ngx_string("modern_browser_value"), |
98 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
99 ngx_http_modern_browser_value, | |
100 NGX_HTTP_LOC_CONF_OFFSET, | |
101 0, | |
102 NULL }, | |
103 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
104 { ngx_string("ancient_browser_value"), |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
105 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
106 ngx_http_ancient_browser_value, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
107 NGX_HTTP_LOC_CONF_OFFSET, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
108 0, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
109 NULL }, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
110 |
700 | 111 ngx_null_command |
112 }; | |
113 | |
114 | |
115 static ngx_http_module_t ngx_http_browser_module_ctx = { | |
116 ngx_http_browser_add_variable, /* preconfiguration */ | |
117 NULL, /* postconfiguration */ | |
118 | |
119 NULL, /* create main configuration */ | |
120 NULL, /* init main configuration */ | |
121 | |
122 NULL, /* create server configuration */ | |
123 NULL, /* merge server configuration */ | |
124 | |
125 ngx_http_browser_create_conf, /* create location configuration */ | |
126 ngx_http_browser_merge_conf /* merge location configuration */ | |
127 }; | |
128 | |
129 | |
130 ngx_module_t ngx_http_browser_module = { | |
131 NGX_MODULE_V1, | |
132 &ngx_http_browser_module_ctx, /* module context */ | |
133 ngx_http_browser_commands, /* module directives */ | |
134 NGX_HTTP_MODULE, /* module type */ | |
135 NULL, /* init master */ | |
136 NULL, /* init module */ | |
137 NULL, /* init process */ | |
138 NULL, /* init thread */ | |
139 NULL, /* exit thread */ | |
140 NULL, /* exit process */ | |
141 NULL, /* exit master */ | |
142 NGX_MODULE_V1_PADDING | |
143 }; | |
144 | |
145 | |
146 static ngx_http_modern_browser_mask_t ngx_http_modern_browser_masks[] = { | |
147 | |
148 /* Opera must be the first browser to check */ | |
149 | |
150 /* | |
151 * "Opera/7.50 (X11; FreeBSD i386; U) [en]" | |
152 * "Mozilla/5.0 (X11; FreeBSD i386; U) Opera 7.50 [en]" | |
153 * "Mozilla/4.0 (compatible; MSIE 6.0; X11; FreeBSD i386) Opera 7.50 [en]" | |
154 * "Opera/8.0 (Windows NT 5.1; U; ru)" | |
155 * "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; en) Opera 8.0" | |
156 * "Opera/9.01 (X11; FreeBSD 6 i386; U; en)" | |
157 */ | |
158 | |
159 { "opera", | |
160 0, | |
161 sizeof("Opera ") - 1, | |
162 "Opera"}, | |
163 | |
164 /* "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" */ | |
165 | |
166 { "msie", | |
167 sizeof("Mozilla/4.0 (compatible; ") - 1, | |
168 sizeof("MSIE ") - 1, | |
169 "MSIE "}, | |
170 | |
171 /* | |
172 * "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020610" | |
173 * "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.5) Gecko/20031006" | |
174 * "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.6) Gecko/20040206 | |
175 * Firefox/0.8" | |
176 * "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.7.8) | |
177 * Gecko/20050511 Firefox/1.0.4" | |
178 * "Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.0.5) Gecko/20060729 | |
179 * Firefox/1.5.0.5" | |
180 */ | |
181 | |
182 { "gecko", | |
183 sizeof("Mozilla/5.0 (") - 1, | |
184 sizeof("rv:") - 1, | |
185 "rv:"}, | |
186 | |
187 /* | |
188 * "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ru-ru) AppleWebKit/125.2 | |
189 * (KHTML, like Gecko) Safari/125.7" | |
190 * "Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 | |
191 * (KHTML, like Gecko) Safari/413" | |
192 * "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 | |
193 * (KHTML, like Gecko) Safari/417.9.3" | |
194 * "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ru-ru) AppleWebKit/418.8 | |
195 * (KHTML, like Gecko) Safari/419.3" | |
196 */ | |
197 | |
198 { "safari", | |
199 sizeof("Mozilla/5.0 (") - 1, | |
200 sizeof("Safari/") - 1, | |
201 "Safari/"}, | |
202 | |
203 /* | |
204 * "Mozilla/5.0 (compatible; Konqueror/3.1; Linux)" | |
205 * "Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.2 (like Gecko)" | |
206 * "Mozilla/5.0 (compatible; Konqueror/3.5; FreeBSD) KHTML/3.5.1 | |
207 * (like Gecko)" | |
208 */ | |
209 | |
210 { "konqueror", | |
211 sizeof("Mozilla/5.0 (compatible; ") - 1, | |
212 sizeof("Konqueror/") - 1, | |
213 "Konqueror/"}, | |
214 | |
215 { "", 0, 0, "" } | |
216 | |
217 }; | |
218 | |
219 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
220 static ngx_http_browser_variable_t ngx_http_browsers[] = { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
221 { ngx_string("msie"), ngx_http_msie_variable, 0 }, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
222 { ngx_string("modern_browser"), ngx_http_browser_variable, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
223 NGX_HTTP_MODERN_BROWSER }, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
224 { ngx_string("ancient_browser"), ngx_http_browser_variable, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
225 NGX_HTTP_ANCIENT_BROWSER }, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
226 { ngx_null_string, NULL, 0 } |
700 | 227 }; |
228 | |
229 | |
230 static ngx_int_t | |
231 ngx_http_browser_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
232 uintptr_t data) | |
233 { | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
234 ngx_uint_t rc; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
235 ngx_http_browser_conf_t *cf; |
700 | 236 |
237 cf = ngx_http_get_module_loc_conf(r, ngx_http_browser_module); | |
238 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
239 rc = ngx_http_browser(r, cf); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
240 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
241 if (data == NGX_HTTP_MODERN_BROWSER && rc == NGX_HTTP_MODERN_BROWSER) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
242 *v = *cf->modern_browser_value; |
700 | 243 return NGX_OK; |
244 } | |
245 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
246 if (data == NGX_HTTP_ANCIENT_BROWSER && rc == NGX_HTTP_ANCIENT_BROWSER) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
247 *v = *cf->ancient_browser_value; |
700 | 248 return NGX_OK; |
249 } | |
250 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
251 *v = ngx_http_variable_null_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
252 return NGX_OK; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
253 } |
700 | 254 |
255 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
256 static ngx_uint_t |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
257 ngx_http_browser(ngx_http_request_t *r, ngx_http_browser_conf_t *cf) |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
258 { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
259 size_t len; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
260 u_char *name, *ua, *last, c; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
261 ngx_str_t *ancient; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
262 ngx_uint_t i, version, ver, scale; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
263 ngx_http_modern_browser_t *modern; |
700 | 264 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
265 if (r->headers_in.user_agent == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
266 if (cf->modern_unlisted_browsers) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
267 return NGX_HTTP_MODERN_BROWSER; |
700 | 268 } |
269 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
270 return NGX_HTTP_ANCIENT_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
271 } |
700 | 272 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
273 ua = r->headers_in.user_agent->value.data; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
274 len = r->headers_in.user_agent->value.len; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
275 last = ua + len; |
700 | 276 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
277 if (cf->modern_browsers) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
278 modern = cf->modern_browsers->elts; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
279 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
280 for (i = 0; i < cf->modern_browsers->nelts; i++) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
281 name = ua + modern[i].skip; |
700 | 282 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
283 if (name >= last) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
284 continue; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
285 } |
700 | 286 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
287 name = (u_char *) ngx_strstr(name, modern[i].name); |
700 | 288 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
289 if (name == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
290 continue; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
291 } |
700 | 292 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
293 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
294 "browser: \"%s\"", name); |
700 | 295 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
296 name += modern[i].add; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
297 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
298 if (name >= last) { |
700 | 299 continue; |
300 } | |
301 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
302 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
303 "version: \"%ui\" \"%s\"", modern[i].version, name); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
304 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
305 version = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
306 ver = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
307 scale = 1000000; |
700 | 308 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
309 while (name < last) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
310 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
311 c = *name++; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
312 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
313 if (c >= '0' && c <= '9') { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
314 ver = ver * 10 + (c - '0'); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
315 continue; |
700 | 316 } |
317 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
318 if (c == '.') { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
319 version += ver * scale; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
320 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
321 if (version > modern[i].version) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
322 return NGX_HTTP_MODERN_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
323 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
324 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
325 ver = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
326 scale /= 100; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
327 continue; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
328 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
329 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
330 break; |
700 | 331 } |
332 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
333 version += ver * scale; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
334 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
335 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
336 "version: \"%ui\" \"%ui\"", |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
337 modern[i].version, version); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
338 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
339 if (version >= modern[i].version) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
340 return NGX_HTTP_MODERN_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
341 } |
2509
b4661481f198
the $ancient_browser variables did not treat as an ancient browser
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
342 |
b4661481f198
the $ancient_browser variables did not treat as an ancient browser
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
343 return NGX_HTTP_ANCIENT_BROWSER; |
700 | 344 } |
345 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
346 if (!cf->modern_unlisted_browsers) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
347 return NGX_HTTP_ANCIENT_BROWSER; |
700 | 348 } |
349 } | |
350 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
351 if (cf->netscape4) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
352 if (len > sizeof("Mozilla/4.72 ") - 1 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
353 && ngx_strncmp(ua, "Mozilla/", sizeof("Mozilla/") - 1) == 0 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
354 && ua[8] > '0' && ua[8] < '5') |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
355 { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
356 return NGX_HTTP_ANCIENT_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
357 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
358 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
359 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
360 if (cf->ancient_browsers) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
361 ancient = cf->ancient_browsers->elts; |
700 | 362 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
363 for (i = 0; i < cf->ancient_browsers->nelts; i++) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
364 if (len >= ancient[i].len |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
365 && ngx_strstr(ua, ancient[i].data) != NULL) |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
366 { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
367 return NGX_HTTP_ANCIENT_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
368 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
369 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
370 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
371 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
372 if (cf->modern_unlisted_browsers) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
373 return NGX_HTTP_MODERN_BROWSER; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
374 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
375 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
376 return NGX_HTTP_ANCIENT_BROWSER; |
700 | 377 } |
378 | |
379 | |
380 static ngx_int_t | |
381 ngx_http_msie_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
382 uintptr_t data) | |
383 { | |
384 if (r->headers_in.msie) { | |
385 *v = ngx_http_variable_true_value; | |
386 return NGX_OK; | |
387 } | |
388 | |
389 *v = ngx_http_variable_null_value; | |
390 return NGX_OK; | |
391 } | |
392 | |
393 | |
394 static ngx_int_t | |
395 ngx_http_browser_add_variable(ngx_conf_t *cf) | |
396 { | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
397 ngx_http_browser_variable_t *var; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
398 ngx_http_variable_t *v; |
700 | 399 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
400 for (var = ngx_http_browsers; var->name.len; var++) { |
700 | 401 |
1565 | 402 v = ngx_http_add_variable(cf, &var->name, NGX_HTTP_VAR_CHANGEABLE); |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
403 if (v == NULL) { |
700 | 404 return NGX_ERROR; |
405 } | |
406 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
407 v->get_handler = var->handler; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
408 v->data = var->data; |
700 | 409 } |
410 | |
411 return NGX_OK; | |
412 } | |
413 | |
414 | |
415 static void * | |
416 ngx_http_browser_create_conf(ngx_conf_t *cf) | |
417 { | |
418 ngx_http_browser_conf_t *conf; | |
419 | |
420 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_browser_conf_t)); | |
421 if (conf == NULL) { | |
422 return NGX_CONF_ERROR; | |
423 } | |
424 | |
425 /* | |
426 * set by ngx_pcalloc(): | |
427 * | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
428 * conf->modern_browsers = NULL; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
429 * conf->ancient_browsers = NULL; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
430 * conf->modern_browser_value = NULL; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
431 * conf->ancient_browser_value = NULL; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
432 * |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
433 * conf->modern_unlisted_browsers = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
434 * conf->netscape4 = 0; |
700 | 435 */ |
436 | |
437 return conf; | |
438 } | |
439 | |
440 | |
441 static char * | |
442 ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
443 { | |
444 ngx_http_browser_conf_t *prev = parent; | |
445 ngx_http_browser_conf_t *conf = child; | |
446 | |
447 ngx_uint_t i, n; | |
448 ngx_http_modern_browser_t *browsers, *opera; | |
449 | |
450 /* | |
451 * At the merge the skip field is used to store the browser slot, | |
452 * it will be used in sorting and then will overwritten | |
453 * with a real skip value. The zero value means Opera. | |
454 */ | |
455 | |
456 if (conf->modern_browsers == NULL) { | |
457 conf->modern_browsers = prev->modern_browsers; | |
458 | |
459 } else { | |
460 browsers = conf->modern_browsers->elts; | |
461 | |
462 for (i = 0; i < conf->modern_browsers->nelts; i++) { | |
463 if (browsers[i].skip == 0) { | |
464 goto found; | |
465 } | |
466 } | |
467 | |
468 /* | |
469 * Opera may contain MSIE string, so if Opera was not enumerated | |
470 * as modern browsers, then add it and set a unreachable version | |
471 */ | |
472 | |
473 opera = ngx_array_push(conf->modern_browsers); | |
474 if (opera == NULL) { | |
475 return NGX_CONF_ERROR; | |
476 } | |
477 | |
478 opera->skip = 0; | |
479 opera->version = 4001000000U; | |
480 | |
481 browsers = conf->modern_browsers->elts; | |
482 | |
483 found: | |
484 | |
485 ngx_qsort(browsers, (size_t) conf->modern_browsers->nelts, | |
486 sizeof(ngx_http_modern_browser_t), | |
487 ngx_http_modern_browser_sort); | |
488 | |
489 for (i = 0; i < conf->modern_browsers->nelts; i++) { | |
490 n = browsers[i].skip; | |
491 | |
492 browsers[i].skip = ngx_http_modern_browser_masks[n].skip; | |
493 browsers[i].add = ngx_http_modern_browser_masks[n].add; | |
494 (void) ngx_cpystrn(browsers[i].name, | |
495 ngx_http_modern_browser_masks[n].name, 12); | |
496 } | |
497 } | |
498 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
499 if (conf->ancient_browsers == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
500 conf->ancient_browsers = prev->ancient_browsers; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
501 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
502 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
503 if (conf->modern_browser_value == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
504 conf->modern_browser_value = prev->modern_browser_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
505 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
506 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
507 if (conf->modern_browser_value == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
508 conf->modern_browser_value = &ngx_http_variable_true_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
509 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
510 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
511 if (conf->ancient_browser_value == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
512 conf->ancient_browser_value = prev->ancient_browser_value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
513 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
514 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
515 if (conf->ancient_browser_value == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
516 conf->ancient_browser_value = &ngx_http_variable_true_value; |
700 | 517 } |
518 | |
519 return NGX_CONF_OK; | |
520 } | |
521 | |
522 | |
523 static int ngx_libc_cdecl | |
524 ngx_http_modern_browser_sort(const void *one, const void *two) | |
525 { | |
526 ngx_http_modern_browser_t *first = (ngx_http_modern_browser_t *) one; | |
527 ngx_http_modern_browser_t *second = (ngx_http_modern_browser_t *) two; | |
528 | |
529 return (first->skip - second->skip); | |
530 } | |
531 | |
532 | |
533 static char * | |
534 ngx_http_modern_browser(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
535 { | |
536 ngx_http_browser_conf_t *bcf = conf; | |
537 | |
538 u_char c; | |
539 ngx_str_t *value; | |
540 ngx_uint_t i, n, version, ver, scale; | |
541 ngx_http_modern_browser_t *browser; | |
542 ngx_http_modern_browser_mask_t *mask; | |
543 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
544 value = cf->args->elts; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
545 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
546 if (cf->args->nelts == 2) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
547 if (ngx_strcmp(value[1].data, "unlisted") == 0) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
548 bcf->modern_unlisted_browsers = 1; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
549 return NGX_CONF_OK; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
550 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
551 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
552 return NGX_CONF_ERROR; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
553 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
554 |
700 | 555 if (bcf->modern_browsers == NULL) { |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
556 bcf->modern_browsers = ngx_array_create(cf->pool, 5, |
700 | 557 sizeof(ngx_http_modern_browser_t)); |
558 if (bcf->modern_browsers == NULL) { | |
559 return NGX_CONF_ERROR; | |
560 } | |
561 } | |
562 | |
563 browser = ngx_array_push(bcf->modern_browsers); | |
564 if (browser == NULL) { | |
565 return NGX_CONF_ERROR; | |
566 } | |
567 | |
568 mask = ngx_http_modern_browser_masks; | |
569 | |
570 for (n = 0; mask[n].browser[0] != '\0'; n++) { | |
571 if (ngx_strcasecmp(mask[n].browser, value[1].data) == 0) { | |
572 goto found; | |
573 } | |
574 } | |
575 | |
576 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
577 "unknown browser name \"%V\"", &value[1]); | |
578 | |
579 return NGX_CONF_ERROR; | |
580 | |
581 found: | |
582 | |
583 /* | |
584 * at this stage the skip field is used to store the browser slot, | |
585 * it will be used in sorting in merge stage and then will overwritten | |
586 * with a real value | |
587 */ | |
588 | |
589 browser->skip = n; | |
590 | |
591 version = 0; | |
592 ver = 0; | |
593 scale = 1000000; | |
594 | |
595 for (i = 0; i < value[2].len; i++) { | |
596 | |
597 c = value[2].data[i]; | |
598 | |
599 if (c >= '0' && c <= '9') { | |
600 ver = ver * 10 + (c - '0'); | |
601 continue; | |
602 } | |
603 | |
604 if (c == '.') { | |
605 version += ver * scale; | |
606 ver = 0; | |
607 scale /= 100; | |
608 continue; | |
609 } | |
610 | |
611 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
612 "invalid browser version \"%V\"", &value[2]); | |
613 | |
614 return NGX_CONF_ERROR; | |
615 } | |
616 | |
617 version += ver * scale; | |
618 | |
619 browser->version = version; | |
620 | |
621 return NGX_CONF_OK; | |
622 } | |
623 | |
624 | |
625 static char * | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
626 ngx_http_ancient_browser(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
627 { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
628 ngx_http_browser_conf_t *bcf = conf; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
629 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
630 ngx_str_t *value, *browser; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
631 ngx_uint_t i; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
632 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
633 value = cf->args->elts; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
634 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
635 for (i = 1; i < cf->args->nelts; i++) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
636 if (ngx_strcmp(value[i].data, "netscape4") == 0) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
637 bcf->netscape4 = 1; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
638 continue; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
639 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
640 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
641 if (bcf->ancient_browsers == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
642 bcf->ancient_browsers = ngx_array_create(cf->pool, 4, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
643 sizeof(ngx_str_t)); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
644 if (bcf->ancient_browsers == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
645 return NGX_CONF_ERROR; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
646 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
647 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
648 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
649 browser = ngx_array_push(bcf->ancient_browsers); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
650 if (browser == NULL) { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
651 return NGX_CONF_ERROR; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
652 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
653 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
654 *browser = value[i]; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
655 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
656 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
657 return NGX_CONF_OK; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
658 } |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
659 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
660 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
661 static char * |
700 | 662 ngx_http_modern_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
663 { | |
664 ngx_http_browser_conf_t *bcf = conf; | |
665 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
666 ngx_str_t *value; |
700 | 667 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
668 bcf->modern_browser_value = ngx_palloc(cf->pool, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
669 sizeof(ngx_http_variable_value_t)); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
670 if (bcf->modern_browser_value == NULL) { |
700 | 671 return NGX_CONF_ERROR; |
672 } | |
673 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
674 value = cf->args->elts; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
675 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
676 bcf->modern_browser_value->len = value[1].len; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
677 bcf->modern_browser_value->valid = 1; |
1565 | 678 bcf->modern_browser_value->no_cacheable = 0; |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
679 bcf->modern_browser_value->not_found = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
680 bcf->modern_browser_value->data = value[1].data; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
681 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
682 return NGX_CONF_OK; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
683 } |
700 | 684 |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
685 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
686 static char * |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
687 ngx_http_ancient_browser_value(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
688 { |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
689 ngx_http_browser_conf_t *bcf = conf; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
690 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
691 ngx_str_t *value; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
692 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
693 bcf->ancient_browser_value = ngx_palloc(cf->pool, |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
694 sizeof(ngx_http_variable_value_t)); |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
695 if (bcf->ancient_browser_value == NULL) { |
700 | 696 return NGX_CONF_ERROR; |
697 } | |
698 | |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
699 value = cf->args->elts; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
700 |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
701 bcf->ancient_browser_value->len = value[1].len; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
702 bcf->ancient_browser_value->valid = 1; |
1565 | 703 bcf->ancient_browser_value->no_cacheable = 0; |
718
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
704 bcf->ancient_browser_value->not_found = 0; |
d488926182ea
ancient browsers support in ngx_http_browser_module
Igor Sysoev <igor@sysoev.ru>
parents:
713
diff
changeset
|
705 bcf->ancient_browser_value->data = value[1].data; |
700 | 706 |
707 return NGX_CONF_OK; | |
708 } |