comparison src/http/modules/ngx_http_geoip_module.c @ 3737:18ae5f09a53d

$geoip_region_name
author Igor Sysoev <igor@sysoev.ru>
date Tue, 03 Aug 2010 15:01:34 +0000
parents 257785918797
children 0f9b2d285bfc
comparison
equal deleted inserted replaced
3736:257785918797 3737:18ae5f09a53d
27 typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr); 27 typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
28 28
29 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r, 29 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r,
30 ngx_http_variable_value_t *v, uintptr_t data); 30 ngx_http_variable_value_t *v, uintptr_t data);
31 static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r, 31 static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r,
32 ngx_http_variable_value_t *v, uintptr_t data);
33 static ngx_int_t ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
32 ngx_http_variable_value_t *v, uintptr_t data); 34 ngx_http_variable_value_t *v, uintptr_t data);
33 static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r, 35 static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
34 ngx_http_variable_value_t *v, uintptr_t data); 36 ngx_http_variable_value_t *v, uintptr_t data);
35 static ngx_int_t ngx_http_geoip_city_int_variable(ngx_http_request_t *r, 37 static ngx_int_t ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
36 ngx_http_variable_value_t *v, uintptr_t data); 38 ngx_http_variable_value_t *v, uintptr_t data);
128 130
129 { ngx_string("geoip_region"), NULL, 131 { ngx_string("geoip_region"), NULL,
130 ngx_http_geoip_city_variable, 132 ngx_http_geoip_city_variable,
131 offsetof(GeoIPRecord, region), 0, 0 }, 133 offsetof(GeoIPRecord, region), 0, 0 },
132 134
135 { ngx_string("geoip_region_name"), NULL,
136 ngx_http_geoip_region_name_variable,
137 0, 0, 0 },
138
133 { ngx_string("geoip_city"), NULL, 139 { ngx_string("geoip_city"), NULL,
134 ngx_http_geoip_city_variable, 140 ngx_http_geoip_city_variable,
135 offsetof(GeoIPRecord, city), 0, 0 }, 141 offsetof(GeoIPRecord, city), 0, 0 },
136 142
137 { ngx_string("geoip_postal_code"), NULL, 143 { ngx_string("geoip_postal_code"), NULL,
253 return NGX_OK; 259 return NGX_OK;
254 } 260 }
255 261
256 262
257 static ngx_int_t 263 static ngx_int_t
264 ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
265 ngx_http_variable_value_t *v, uintptr_t data)
266 {
267 size_t len;
268 const char *val;
269 GeoIPRecord *gr;
270
271 gr = ngx_http_geoip_get_city_record(r);
272 if (gr == NULL) {
273 goto not_found;
274 }
275
276 val = GeoIP_region_name_by_code(gr->country_code, gr->region);
277
278 len = ngx_strlen(val);
279 v->data = ngx_pnalloc(r->pool, len);
280
281 if (v->data == NULL) {
282 GeoIPRecord_delete(gr);
283 return NGX_ERROR;
284 }
285
286 ngx_memcpy(v->data, val, len);
287
288 v->len = len;
289 v->valid = 1;
290 v->no_cacheable = 0;
291 v->not_found = 0;
292
293 GeoIPRecord_delete(gr);
294
295 return NGX_OK;
296
297 not_found:
298
299 v->not_found = 1;
300
301 return NGX_OK;
302 }
303
304
305 static ngx_int_t
258 ngx_http_geoip_city_float_variable(ngx_http_request_t *r, 306 ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
259 ngx_http_variable_value_t *v, uintptr_t data) 307 ngx_http_variable_value_t *v, uintptr_t data)
260 { 308 {
261 float val; 309 float val;
262 GeoIPRecord *gr; 310 GeoIPRecord *gr;