diff options
author | Igor Sysoev <igor@sysoev.ru> | 2010-08-03 15:01:34 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2010-08-03 15:01:34 +0000 |
commit | 395f35e5fa636c44773dec0e6f6d2cce7c0374b8 (patch) | |
tree | 0791c843104f875ef1e0cb374111ba3e1069fdae /src | |
parent | dc87ab5a69c7689a284cf48baf08efb8848dfc50 (diff) | |
download | nginx-395f35e5fa636c44773dec0e6f6d2cce7c0374b8.tar.gz nginx-395f35e5fa636c44773dec0e6f6d2cce7c0374b8.zip |
$geoip_region_name
Diffstat (limited to 'src')
-rw-r--r-- | src/http/modules/ngx_http_geoip_module.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c index e93b08dfd..e248d01b0 100644 --- a/src/http/modules/ngx_http_geoip_module.c +++ b/src/http/modules/ngx_http_geoip_module.c @@ -30,6 +30,8 @@ static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); 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_region_name_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, @@ -130,6 +132,10 @@ static ngx_http_variable_t ngx_http_geoip_vars[] = { ngx_http_geoip_city_variable, offsetof(GeoIPRecord, region), 0, 0 }, + { ngx_string("geoip_region_name"), NULL, + ngx_http_geoip_region_name_variable, + 0, 0, 0 }, + { ngx_string("geoip_city"), NULL, ngx_http_geoip_city_variable, offsetof(GeoIPRecord, city), 0, 0 }, @@ -255,6 +261,48 @@ not_found: static ngx_int_t +ngx_http_geoip_region_name_variable(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data) +{ + size_t len; + const char *val; + GeoIPRecord *gr; + + gr = ngx_http_geoip_get_city_record(r); + if (gr == NULL) { + goto not_found; + } + + val = GeoIP_region_name_by_code(gr->country_code, gr->region); + + len = ngx_strlen(val); + v->data = ngx_pnalloc(r->pool, len); + + if (v->data == NULL) { + GeoIPRecord_delete(gr); + return NGX_ERROR; + } + + ngx_memcpy(v->data, val, len); + + v->len = len; + v->valid = 1; + v->no_cacheable = 0; + v->not_found = 0; + + GeoIPRecord_delete(gr); + + return NGX_OK; + +not_found: + + v->not_found = 1; + + return NGX_OK; +} + + +static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) { |