Index: trunk/debs/nginx/modules/nginx-udplog/ngx_http_udplog_module.c |
— | — | @@ -85,12 +85,16 @@ |
86 | 86 | ngx_http_variable_value_t *v, uintptr_t data); |
87 | 87 | static ngx_int_t ngx_http_udplog_sequence_variable(ngx_http_request_t *r, |
88 | 88 | ngx_http_variable_value_t *v, uintptr_t data); |
| 89 | +static ngx_int_t ngx_http_udplog_escaped_user_agent_variable(ngx_http_request_t *r, |
| 90 | + ngx_http_variable_value_t *v, uintptr_t data); |
89 | 91 | |
90 | 92 | static ngx_http_variable_t ngx_http_udplog_variables[] = { |
91 | 93 | { ngx_string("udplog_time"), NULL, ngx_http_udplog_time_variable, 0, |
92 | 94 | NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
93 | 95 | { ngx_string("udplog_sequence"), NULL, ngx_http_udplog_sequence_variable, 0, |
94 | 96 | NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
| 97 | + { ngx_string("udplog_escaped_user_agent"), NULL, ngx_http_udplog_escaped_user_agent_variable, 0, |
| 98 | + NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, |
95 | 99 | |
96 | 100 | { ngx_null_string, NULL, NULL, 0, 0, 0 } |
97 | 101 | }; |
— | — | @@ -204,6 +208,36 @@ |
205 | 209 | } |
206 | 210 | |
207 | 211 | static ngx_int_t |
| 212 | +ngx_http_udplog_escaped_user_agent_variable(ngx_http_request_t *r, |
| 213 | + ngx_http_variable_value_t *v, uintptr_t data) |
| 214 | +{ |
| 215 | + u_char *ua; |
| 216 | + u_char *eua; |
| 217 | + uintptr_t escape; |
| 218 | + size_t l; |
| 219 | + |
| 220 | + ua = r->headers_in.user_agent->value.data; |
| 221 | + l = ngx_strlen(ua); |
| 222 | + escape = 2 * ngx_escape_uri(NULL, ua, l, NGX_ESCAPE_URI); |
| 223 | + |
| 224 | + eua = ngx_pnalloc(r->pool, l + escape); |
| 225 | + if (eua == NULL) { |
| 226 | + return NGX_ERROR; |
| 227 | + } |
| 228 | + |
| 229 | + ngx_escape_uri(eua, ua, l, NGX_ESCAPE_URI); |
| 230 | + |
| 231 | + v->data = eua; |
| 232 | + v->len = ngx_strlen(eua); |
| 233 | + |
| 234 | + v->valid = 1; |
| 235 | + v->no_cacheable = 0; |
| 236 | + v->not_found = 0; |
| 237 | + |
| 238 | + return NGX_OK; |
| 239 | +} |
| 240 | + |
| 241 | +static ngx_int_t |
208 | 242 | ngx_http_udplog_add_variables(ngx_conf_t *cf) |
209 | 243 | { |
210 | 244 | ngx_http_variable_t *var, *v; |