Mercurial > hg > nginx
comparison src/http/modules/ngx_http_browser_module.c @ 7076:1b82e86dd3e7
Browser: style.
Removed custom variable type and renamed function that adds variables.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 01 Aug 2017 14:27:23 +0300 |
parents | f84a98a03d0d |
children | 2a288909abc6 |
comparison
equal
deleted
inserted
replaced
7075:72d3aefc2993 | 7076:1b82e86dd3e7 |
---|---|
36 u_char name[12]; | 36 u_char name[12]; |
37 } ngx_http_modern_browser_t; | 37 } ngx_http_modern_browser_t; |
38 | 38 |
39 | 39 |
40 typedef struct { | 40 typedef struct { |
41 ngx_str_t name; | |
42 ngx_http_get_variable_pt handler; | |
43 uintptr_t data; | |
44 } ngx_http_browser_variable_t; | |
45 | |
46 | |
47 typedef struct { | |
48 ngx_array_t *modern_browsers; | 41 ngx_array_t *modern_browsers; |
49 ngx_array_t *ancient_browsers; | 42 ngx_array_t *ancient_browsers; |
50 ngx_http_variable_value_t *modern_browser_value; | 43 ngx_http_variable_value_t *modern_browser_value; |
51 ngx_http_variable_value_t *ancient_browser_value; | 44 ngx_http_variable_value_t *ancient_browser_value; |
52 | 45 |
61 ngx_http_variable_value_t *v, uintptr_t data); | 54 ngx_http_variable_value_t *v, uintptr_t data); |
62 | 55 |
63 static ngx_uint_t ngx_http_browser(ngx_http_request_t *r, | 56 static ngx_uint_t ngx_http_browser(ngx_http_request_t *r, |
64 ngx_http_browser_conf_t *cf); | 57 ngx_http_browser_conf_t *cf); |
65 | 58 |
66 static ngx_int_t ngx_http_browser_add_variable(ngx_conf_t *cf); | 59 static ngx_int_t ngx_http_browser_add_variables(ngx_conf_t *cf); |
67 static void *ngx_http_browser_create_conf(ngx_conf_t *cf); | 60 static void *ngx_http_browser_create_conf(ngx_conf_t *cf); |
68 static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent, | 61 static char *ngx_http_browser_merge_conf(ngx_conf_t *cf, void *parent, |
69 void *child); | 62 void *child); |
70 static int ngx_libc_cdecl ngx_http_modern_browser_sort(const void *one, | 63 static int ngx_libc_cdecl ngx_http_modern_browser_sort(const void *one, |
71 const void *two); | 64 const void *two); |
112 ngx_null_command | 105 ngx_null_command |
113 }; | 106 }; |
114 | 107 |
115 | 108 |
116 static ngx_http_module_t ngx_http_browser_module_ctx = { | 109 static ngx_http_module_t ngx_http_browser_module_ctx = { |
117 ngx_http_browser_add_variable, /* preconfiguration */ | 110 ngx_http_browser_add_variables, /* preconfiguration */ |
118 NULL, /* postconfiguration */ | 111 NULL, /* postconfiguration */ |
119 | 112 |
120 NULL, /* create main configuration */ | 113 NULL, /* create main configuration */ |
121 NULL, /* init main configuration */ | 114 NULL, /* init main configuration */ |
122 | 115 |
216 { "", 0, 0, "" } | 209 { "", 0, 0, "" } |
217 | 210 |
218 }; | 211 }; |
219 | 212 |
220 | 213 |
221 static ngx_http_browser_variable_t ngx_http_browsers[] = { | 214 static ngx_http_variable_t ngx_http_browser_vars[] = { |
222 { ngx_string("msie"), ngx_http_msie_variable, 0 }, | 215 |
223 { ngx_string("modern_browser"), ngx_http_browser_variable, | 216 { ngx_string("msie"), NULL, ngx_http_msie_variable, |
224 NGX_HTTP_MODERN_BROWSER }, | 217 0, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
225 { ngx_string("ancient_browser"), ngx_http_browser_variable, | 218 |
226 NGX_HTTP_ANCIENT_BROWSER }, | 219 { ngx_string("modern_browser"), NULL, ngx_http_browser_variable, |
227 { ngx_null_string, NULL, 0 } | 220 NGX_HTTP_MODERN_BROWSER, NGX_HTTP_VAR_CHANGEABLE, 0 }, |
221 | |
222 { ngx_string("ancient_browser"), NULL, ngx_http_browser_variable, | |
223 NGX_HTTP_ANCIENT_BROWSER, NGX_HTTP_VAR_CHANGEABLE, 0 }, | |
224 | |
225 { ngx_null_string, NULL, NULL, 0, 0, 0 } | |
228 }; | 226 }; |
229 | 227 |
230 | 228 |
231 static ngx_int_t | 229 static ngx_int_t |
232 ngx_http_browser_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | 230 ngx_http_browser_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
395 return NGX_OK; | 393 return NGX_OK; |
396 } | 394 } |
397 | 395 |
398 | 396 |
399 static ngx_int_t | 397 static ngx_int_t |
400 ngx_http_browser_add_variable(ngx_conf_t *cf) | 398 ngx_http_browser_add_variables(ngx_conf_t *cf) |
401 { | 399 { |
402 ngx_http_browser_variable_t *var; | 400 ngx_http_variable_t *var, *v; |
403 ngx_http_variable_t *v; | 401 |
404 | 402 for (v = ngx_http_browser_vars; v->name.len; v++) { |
405 for (var = ngx_http_browsers; var->name.len; var++) { | 403 |
406 | 404 var = ngx_http_add_variable(cf, &v->name, v->flags); |
407 v = ngx_http_add_variable(cf, &var->name, NGX_HTTP_VAR_CHANGEABLE); | 405 if (var == NULL) { |
408 if (v == NULL) { | |
409 return NGX_ERROR; | 406 return NGX_ERROR; |
410 } | 407 } |
411 | 408 |
412 v->get_handler = var->handler; | 409 var->get_handler = v->get_handler; |
413 v->data = var->data; | 410 var->data = v->data; |
414 } | 411 } |
415 | 412 |
416 return NGX_OK; | 413 return NGX_OK; |
417 } | 414 } |
418 | 415 |