aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-08-03 14:19:49 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-08-03 14:19:49 +0000
commitdc87ab5a69c7689a284cf48baf08efb8848dfc50 (patch)
tree318eb99c60dba1a694e1d229bd19f4dcd796dc55 /src
parent41212d27fa0b5f0aa61fa97b020cc47f5cc74904 (diff)
downloadnginx-dc87ab5a69c7689a284cf48baf08efb8848dfc50.tar.gz
nginx-dc87ab5a69c7689a284cf48baf08efb8848dfc50.zip
$geoip_dma_code and $geoip_area_code
Diffstat (limited to 'src')
-rw-r--r--src/http/modules/ngx_http_geoip_module.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
index 2c50909f6..e93b08dfd 100644
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -32,6 +32,8 @@ static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r);
static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf);
@@ -144,6 +146,14 @@ static ngx_http_variable_t ngx_http_geoip_vars[] = {
ngx_http_geoip_city_float_variable,
offsetof(GeoIPRecord, longitude), 0, 0 },
+ { ngx_string("geoip_dma_code"), NULL,
+ ngx_http_geoip_city_int_variable,
+ offsetof(GeoIPRecord, dma_code), 0, 0 },
+
+ { ngx_string("geoip_area_code"), NULL,
+ ngx_http_geoip_city_int_variable,
+ offsetof(GeoIPRecord, area_code), 0, 0 },
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
@@ -273,6 +283,35 @@ ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
}
+static ngx_int_t
+ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ int val;
+ GeoIPRecord *gr;
+
+ gr = ngx_http_geoip_get_city_record(r);
+ if (gr == NULL) {
+ v->not_found = 1;
+ return NGX_OK;
+ }
+
+ v->data = ngx_pnalloc(r->pool, NGX_INT64_LEN);
+ if (v->data == NULL) {
+ GeoIPRecord_delete(gr);
+ return NGX_ERROR;
+ }
+
+ val = *(int *) ((char *) gr + data);
+
+ v->len = ngx_sprintf(v->data, "%d", val) - v->data;
+
+ GeoIPRecord_delete(gr);
+
+ return NGX_OK;
+}
+
+
static GeoIPRecord *
ngx_http_geoip_get_city_record(ngx_http_request_t *r)
{