annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 #include <GeoIP.h>
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <GeoIPCity.h>
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 typedef struct {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 GeoIP *country;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 GeoIP *city;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 } ngx_http_geoip_conf_t;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 typedef struct {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 ngx_str_t *name;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 uintptr_t data;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 } ngx_http_geoip_var_t;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 ngx_http_variable_value_t *v, uintptr_t data);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 ngx_http_variable_value_t *v, uintptr_t data);
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
33 static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
34 ngx_http_variable_value_t *v, uintptr_t data);
3736
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
35 static ngx_int_t ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
36 ngx_http_variable_value_t *v, uintptr_t data);
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
37 static GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r);
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 static void *ngx_http_geoip_create_conf(ngx_conf_t *cf);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 static char *ngx_http_geoip_country(ngx_conf_t *cf, ngx_command_t *cmd,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 void *conf);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 static char *ngx_http_geoip_city(ngx_conf_t *cf, ngx_command_t *cmd,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 void *conf);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 static void ngx_http_geoip_cleanup(void *data);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 static ngx_command_t ngx_http_geoip_commands[] = {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 { ngx_string("geoip_country"),
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 ngx_http_geoip_country,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 NGX_HTTP_MAIN_CONF_OFFSET,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 NULL },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 { ngx_string("geoip_city"),
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 ngx_http_geoip_city,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 NGX_HTTP_MAIN_CONF_OFFSET,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 NULL },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 ngx_null_command
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 };
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 static ngx_http_module_t ngx_http_geoip_module_ctx = {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 ngx_http_geoip_add_variables, /* preconfiguration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 NULL, /* postconfiguration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 ngx_http_geoip_create_conf, /* create main configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 NULL, /* init main configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 NULL, /* create server configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 NULL, /* merge server configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NULL, /* create location configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 NULL /* merge location configuration */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 };
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 ngx_module_t ngx_http_geoip_module = {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 NGX_MODULE_V1,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 &ngx_http_geoip_module_ctx, /* module context */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_http_geoip_commands, /* module directives */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 NGX_HTTP_MODULE, /* module type */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 NULL, /* init master */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 NULL, /* init module */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 NULL, /* init process */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 NULL, /* init thread */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 NULL, /* exit thread */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 NULL, /* exit process */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 NULL, /* exit master */
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 NGX_MODULE_V1_PADDING
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 };
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 static ngx_http_variable_t ngx_http_geoip_vars[] = {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
101 { ngx_string("geoip_country_code"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
102 ngx_http_geoip_country_variable,
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 (uintptr_t) GeoIP_country_code_by_ipnum, 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
105 { ngx_string("geoip_country_code3"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
106 ngx_http_geoip_country_variable,
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 (uintptr_t) GeoIP_country_code3_by_ipnum, 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
109 { ngx_string("geoip_country_name"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
110 ngx_http_geoip_country_variable,
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 (uintptr_t) GeoIP_country_name_by_ipnum, 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
113 { ngx_string("geoip_city_continent_code"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
114 ngx_http_geoip_city_variable,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
115 offsetof(GeoIPRecord, continent_code), 0, 0 },
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
116
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
117 { ngx_string("geoip_city_country_code"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
118 ngx_http_geoip_city_variable,
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 offsetof(GeoIPRecord, country_code), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 { ngx_string("geoip_city_country_code3"), NULL,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 ngx_http_geoip_city_variable,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 offsetof(GeoIPRecord, country_code3), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
125 { ngx_string("geoip_city_country_name"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
126 ngx_http_geoip_city_variable,
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 offsetof(GeoIPRecord, country_name), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 { ngx_string("geoip_region"), NULL,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 ngx_http_geoip_city_variable,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 offsetof(GeoIPRecord, region), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 { ngx_string("geoip_city"), NULL,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 ngx_http_geoip_city_variable,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 offsetof(GeoIPRecord, city), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 { ngx_string("geoip_postal_code"), NULL,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 ngx_http_geoip_city_variable,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 offsetof(GeoIPRecord, postal_code), 0, 0 },
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
141 { ngx_string("geoip_latitude"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
142 ngx_http_geoip_city_float_variable,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
143 offsetof(GeoIPRecord, latitude), 0, 0 },
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
144
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
145 { ngx_string("geoip_longitude"), NULL,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
146 ngx_http_geoip_city_float_variable,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
147 offsetof(GeoIPRecord, longitude), 0, 0 },
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
148
3736
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
149 { ngx_string("geoip_dma_code"), NULL,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
150 ngx_http_geoip_city_int_variable,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
151 offsetof(GeoIPRecord, dma_code), 0, 0 },
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
152
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
153 { ngx_string("geoip_area_code"), NULL,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
154 ngx_http_geoip_city_int_variable,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
155 offsetof(GeoIPRecord, area_code), 0, 0 },
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
156
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 { ngx_null_string, NULL, NULL, 0, 0, 0 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 };
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 static ngx_int_t
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 ngx_http_geoip_country_variable(ngx_http_request_t *r,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 ngx_http_variable_value_t *v, uintptr_t data)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 ngx_http_geoip_variable_handler_pt handler =
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 (ngx_http_geoip_variable_handler_pt) data;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 u_long addr;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 const char *val;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 struct sockaddr_in *sin;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 ngx_http_geoip_conf_t *gcf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 if (gcf->country == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 goto not_found;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 if (r->connection->sockaddr->sa_family != AF_INET) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 goto not_found;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 sin = (struct sockaddr_in *) r->connection->sockaddr;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 addr = ntohl(sin->sin_addr.s_addr);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 val = handler(gcf->country, addr);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 if (val == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 goto not_found;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 v->len = ngx_strlen(val);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 v->valid = 1;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 v->no_cacheable = 0;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 v->not_found = 0;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 v->data = (u_char *) val;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 return NGX_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 not_found:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 v->not_found = 1;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 return NGX_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 static ngx_int_t
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 ngx_http_geoip_city_variable(ngx_http_request_t *r,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 ngx_http_variable_value_t *v, uintptr_t data)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 {
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
212 char *val;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
213 size_t len;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
214 GeoIPRecord *gr;
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
216 gr = ngx_http_geoip_get_city_record(r);
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 if (gr == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 goto not_found;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 val = *(char **) ((char *) gr + data);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 if (val == NULL) {
3031
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
223 goto no_value;
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225
3031
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
226 len = ngx_strlen(val);
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
227 v->data = ngx_pnalloc(r->pool, len);
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
228
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
229 if (v->data == NULL) {
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
230 GeoIPRecord_delete(gr);
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
231 return NGX_ERROR;
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
232 }
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
233
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
234 ngx_memcpy(v->data, val, len);
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
235
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
236 v->len = len;
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 v->valid = 1;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 v->no_cacheable = 0;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 v->not_found = 0;
3031
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
240
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
241 GeoIPRecord_delete(gr);
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 return NGX_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
3031
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
245 no_value:
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
246
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
247 GeoIPRecord_delete(gr);
98a8336c5b7c fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents: 2985
diff changeset
248
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 not_found:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251 v->not_found = 1;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253 return NGX_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 static ngx_int_t
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
258 ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
259 ngx_http_variable_value_t *v, uintptr_t data)
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
260 {
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
261 float val;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
262 GeoIPRecord *gr;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
263
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
264 gr = ngx_http_geoip_get_city_record(r);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
265 if (gr == NULL) {
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
266 v->not_found = 1;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
267 return NGX_OK;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
268 }
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
269
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
270 v->data = ngx_pnalloc(r->pool, NGX_INT64_LEN + 5);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
271 if (v->data == NULL) {
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
272 GeoIPRecord_delete(gr);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
273 return NGX_ERROR;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
274 }
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
275
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
276 val = *(float *) ((char *) gr + data);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
277
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
278 v->len = ngx_sprintf(v->data, "%.4f", val) - v->data;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
279
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
280 GeoIPRecord_delete(gr);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
281
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
282 return NGX_OK;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
283 }
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
284
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
285
3736
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
286 static ngx_int_t
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
287 ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
288 ngx_http_variable_value_t *v, uintptr_t data)
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
289 {
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
290 int val;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
291 GeoIPRecord *gr;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
292
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
293 gr = ngx_http_geoip_get_city_record(r);
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
294 if (gr == NULL) {
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
295 v->not_found = 1;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
296 return NGX_OK;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
297 }
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
298
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
299 v->data = ngx_pnalloc(r->pool, NGX_INT64_LEN);
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
300 if (v->data == NULL) {
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
301 GeoIPRecord_delete(gr);
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
302 return NGX_ERROR;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
303 }
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
304
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
305 val = *(int *) ((char *) gr + data);
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
306
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
307 v->len = ngx_sprintf(v->data, "%d", val) - v->data;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
308
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
309 GeoIPRecord_delete(gr);
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
310
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
311 return NGX_OK;
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
312 }
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
313
257785918797 $geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents: 3398
diff changeset
314
3398
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
315 static GeoIPRecord *
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
316 ngx_http_geoip_get_city_record(ngx_http_request_t *r)
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
317 {
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
318 u_long addr;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
319 struct sockaddr_in *sin;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
320 ngx_http_geoip_conf_t *gcf;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
321
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
322 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
323
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
324 if (gcf->city && r->connection->sockaddr->sa_family == AF_INET) {
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
325
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
326 sin = (struct sockaddr_in *) r->connection->sockaddr;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
327 addr = ntohl(sin->sin_addr.s_addr);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
328
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
329 return GeoIP_record_by_ipnum(gcf->city, addr);
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
330 }
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
331
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
332 return NULL;
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
333 }
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
334
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
335
236634d2b603 $geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents: 3031
diff changeset
336 static ngx_int_t
2985
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 ngx_http_geoip_add_variables(ngx_conf_t *cf)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339 ngx_http_variable_t *var, *v;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
340
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 for (v = ngx_http_geoip_vars; v->name.len; v++) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 var = ngx_http_add_variable(cf, &v->name, v->flags);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343 if (var == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 return NGX_ERROR;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 var->get_handler = v->get_handler;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 var->data = v->data;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 return NGX_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 static void *
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 ngx_http_geoip_create_conf(ngx_conf_t *cf)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 ngx_pool_cleanup_t *cln;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359 ngx_http_geoip_conf_t *conf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip_conf_t));
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 if (conf == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363 return NULL;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366 cln = ngx_pool_cleanup_add(cf->pool, 0);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 if (cln == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 return NULL;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371 cln->handler = ngx_http_geoip_cleanup;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 cln->data = conf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 return conf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
378 static char *
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379 ngx_http_geoip_country(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 ngx_http_geoip_conf_t *gcf = conf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 ngx_str_t *value;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 if (gcf->country) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 return "is duplicate";
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389 value = cf->args->elts;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393 if (gcf->country == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 "GeoIO_open(\"%V\") failed", &value[1]);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 return NGX_CONF_ERROR;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400 switch (gcf->country->databaseType) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 case GEOIP_COUNTRY_EDITION:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 case GEOIP_PROXY_EDITION:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404 case GEOIP_NETSPEED_EDITION:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 return NGX_CONF_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
407
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
408 default:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 "invalid GeoIP database \"%V\" type:%d",
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 &value[1], gcf->country->databaseType);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412 return NGX_CONF_ERROR;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 static char *
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 ngx_http_geoip_city(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 ngx_http_geoip_conf_t *gcf = conf;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422 ngx_str_t *value;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 if (gcf->city) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
425 return "is duplicate";
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
426 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 value = cf->args->elts;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430 gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 if (gcf->city == NULL) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434 "GeoIO_open(\"%V\") failed", &value[1]);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 return NGX_CONF_ERROR;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 switch (gcf->city->databaseType) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 case GEOIP_CITY_EDITION_REV0:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 case GEOIP_CITY_EDITION_REV1:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 return NGX_CONF_OK;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 default:
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448 "invalid GeoIP City database \"%V\" type:%d",
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
449 &value[1], gcf->city->databaseType);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450 return NGX_CONF_ERROR;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 static void
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 ngx_http_geoip_cleanup(void *data)
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457 {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 ngx_http_geoip_conf_t *gcf = data;
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 if (gcf->country) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461 GeoIP_delete(gcf->country);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464 if (gcf->city) {
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 GeoIP_delete(gcf->city);
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 }
31af2d1a742e ngx_http_geoip_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467 }