r109722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109721‎ | r109722 | r109723 >
Date:05:21, 22 January 2012
Author:abemusic
Status:deferred
Tags:
Comment:
- Added URL-encoded user agent variable. You may now use this in your log formats with $udplog_escaped_user_agent.
Modified paths:
  • /trunk/debs/nginx/modules/nginx-udplog/ngx_http_udplog_module.c (modified) (history)

Diff [purge]

Index: trunk/debs/nginx/modules/nginx-udplog/ngx_http_udplog_module.c
@@ -85,12 +85,16 @@
8686 ngx_http_variable_value_t *v, uintptr_t data);
8787 static ngx_int_t ngx_http_udplog_sequence_variable(ngx_http_request_t *r,
8888 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);
8991
9092 static ngx_http_variable_t ngx_http_udplog_variables[] = {
9193 { ngx_string("udplog_time"), NULL, ngx_http_udplog_time_variable, 0,
9294 NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
9395 { ngx_string("udplog_sequence"), NULL, ngx_http_udplog_sequence_variable, 0,
9496 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 },
9599
96100 { ngx_null_string, NULL, NULL, 0, 0, 0 }
97101 };
@@ -204,6 +208,36 @@
205209 }
206210
207211 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
208242 ngx_http_udplog_add_variables(ngx_conf_t *cf)
209243 {
210244 ngx_http_variable_t *var, *v;