mirror of
https://github.com/nginx/nginx.git
synced 2025-01-19 01:42:58 +08:00
$geoip_region_name
This commit is contained in:
parent
dc87ab5a69
commit
395f35e5fa
@ -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 },
|
||||
@ -254,6 +260,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)
|
||||
|
Loading…
Reference in New Issue
Block a user