comparison src/http/modules/ngx_http_geoip_module.c @ 3736:257785918797

$geoip_dma_code and $geoip_area_code
author Igor Sysoev <igor@sysoev.ru>
date Tue, 03 Aug 2010 14:19:49 +0000
parents 236634d2b603
children 18ae5f09a53d
comparison
equal deleted inserted replaced
3735:1ba712d077d1 3736:257785918797
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); 32 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, 33 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);
35 static ngx_int_t ngx_http_geoip_city_int_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 GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r); 37 static GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r);
36 38
37 static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf); 39 static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf);
38 static void *ngx_http_geoip_create_conf(ngx_conf_t *cf); 40 static void *ngx_http_geoip_create_conf(ngx_conf_t *cf);
142 144
143 { ngx_string("geoip_longitude"), NULL, 145 { ngx_string("geoip_longitude"), NULL,
144 ngx_http_geoip_city_float_variable, 146 ngx_http_geoip_city_float_variable,
145 offsetof(GeoIPRecord, longitude), 0, 0 }, 147 offsetof(GeoIPRecord, longitude), 0, 0 },
146 148
149 { ngx_string("geoip_dma_code"), NULL,
150 ngx_http_geoip_city_int_variable,
151 offsetof(GeoIPRecord, dma_code), 0, 0 },
152
153 { ngx_string("geoip_area_code"), NULL,
154 ngx_http_geoip_city_int_variable,
155 offsetof(GeoIPRecord, area_code), 0, 0 },
156
147 { ngx_null_string, NULL, NULL, 0, 0, 0 } 157 { ngx_null_string, NULL, NULL, 0, 0, 0 }
148 }; 158 };
149 159
150 160
151 static ngx_int_t 161 static ngx_int_t
271 281
272 return NGX_OK; 282 return NGX_OK;
273 } 283 }
274 284
275 285
286 static ngx_int_t
287 ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
288 ngx_http_variable_value_t *v, uintptr_t data)
289 {
290 int val;
291 GeoIPRecord *gr;
292
293 gr = ngx_http_geoip_get_city_record(r);
294 if (gr == NULL) {
295 v->not_found = 1;
296 return NGX_OK;
297 }
298
299 v->data = ngx_pnalloc(r->pool, NGX_INT64_LEN);
300 if (v->data == NULL) {
301 GeoIPRecord_delete(gr);
302 return NGX_ERROR;
303 }
304
305 val = *(int *) ((char *) gr + data);
306
307 v->len = ngx_sprintf(v->data, "%d", val) - v->data;
308
309 GeoIPRecord_delete(gr);
310
311 return NGX_OK;
312 }
313
314
276 static GeoIPRecord * 315 static GeoIPRecord *
277 ngx_http_geoip_get_city_record(ngx_http_request_t *r) 316 ngx_http_geoip_get_city_record(ngx_http_request_t *r)
278 { 317 {
279 u_long addr; 318 u_long addr;
280 struct sockaddr_in *sin; 319 struct sockaddr_in *sin;