Mercurial > hg > nginx
annotate src/http/modules/ngx_http_geoip_module.c @ 3915:e3645e338937
geoip_org
patch by Alexander Uskov
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 11 May 2011 09:34:21 +0000 |
parents | 2b92090d8a43 |
children | 0dceaa117e0d |
rev | line source |
---|---|
2985 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 #include <GeoIP.h> | |
12 #include <GeoIPCity.h> | |
13 | |
14 | |
15 typedef struct { | |
16 GeoIP *country; | |
3915 | 17 GeoIP *org; |
2985 | 18 GeoIP *city; |
19 } ngx_http_geoip_conf_t; | |
20 | |
21 | |
22 typedef struct { | |
23 ngx_str_t *name; | |
24 uintptr_t data; | |
25 } ngx_http_geoip_var_t; | |
26 | |
27 | |
28 typedef const char *(*ngx_http_geoip_variable_handler_pt)(GeoIP *, u_long addr); | |
29 | |
30 static ngx_int_t ngx_http_geoip_country_variable(ngx_http_request_t *r, | |
31 ngx_http_variable_value_t *v, uintptr_t data); | |
3915 | 32 static ngx_int_t ngx_http_geoip_org_variable(ngx_http_request_t *r, |
33 ngx_http_variable_value_t *v, uintptr_t data); | |
2985 | 34 static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r, |
35 ngx_http_variable_value_t *v, uintptr_t data); | |
3737 | 36 static ngx_int_t ngx_http_geoip_region_name_variable(ngx_http_request_t *r, |
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 static GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r); |
2985 | 43 |
44 static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf); | |
45 static void *ngx_http_geoip_create_conf(ngx_conf_t *cf); | |
46 static char *ngx_http_geoip_country(ngx_conf_t *cf, ngx_command_t *cmd, | |
47 void *conf); | |
3915 | 48 static char *ngx_http_geoip_org(ngx_conf_t *cf, ngx_command_t *cmd, |
49 void *conf); | |
2985 | 50 static char *ngx_http_geoip_city(ngx_conf_t *cf, ngx_command_t *cmd, |
51 void *conf); | |
52 static void ngx_http_geoip_cleanup(void *data); | |
53 | |
54 | |
55 static ngx_command_t ngx_http_geoip_commands[] = { | |
56 | |
57 { ngx_string("geoip_country"), | |
3859
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
58 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE12, |
2985 | 59 ngx_http_geoip_country, |
60 NGX_HTTP_MAIN_CONF_OFFSET, | |
61 0, | |
62 NULL }, | |
63 | |
3915 | 64 { ngx_string("geoip_org"), |
65 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE12, | |
66 ngx_http_geoip_org, | |
67 NGX_HTTP_MAIN_CONF_OFFSET, | |
68 0, | |
69 NULL }, | |
70 | |
2985 | 71 { ngx_string("geoip_city"), |
3859
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
72 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE12, |
2985 | 73 ngx_http_geoip_city, |
74 NGX_HTTP_MAIN_CONF_OFFSET, | |
75 0, | |
76 NULL }, | |
77 | |
78 ngx_null_command | |
79 }; | |
80 | |
81 | |
82 static ngx_http_module_t ngx_http_geoip_module_ctx = { | |
83 ngx_http_geoip_add_variables, /* preconfiguration */ | |
84 NULL, /* postconfiguration */ | |
85 | |
86 ngx_http_geoip_create_conf, /* create main configuration */ | |
87 NULL, /* init main configuration */ | |
88 | |
89 NULL, /* create server configuration */ | |
90 NULL, /* merge server configuration */ | |
91 | |
92 NULL, /* create location configuration */ | |
93 NULL /* merge location configuration */ | |
94 }; | |
95 | |
96 | |
97 ngx_module_t ngx_http_geoip_module = { | |
98 NGX_MODULE_V1, | |
99 &ngx_http_geoip_module_ctx, /* module context */ | |
100 ngx_http_geoip_commands, /* module directives */ | |
101 NGX_HTTP_MODULE, /* module type */ | |
102 NULL, /* init master */ | |
103 NULL, /* init module */ | |
104 NULL, /* init process */ | |
105 NULL, /* init thread */ | |
106 NULL, /* exit thread */ | |
107 NULL, /* exit process */ | |
108 NULL, /* exit master */ | |
109 NGX_MODULE_V1_PADDING | |
110 }; | |
111 | |
112 | |
113 static ngx_http_variable_t ngx_http_geoip_vars[] = { | |
114 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
115 { ngx_string("geoip_country_code"), NULL, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
116 ngx_http_geoip_country_variable, |
2985 | 117 (uintptr_t) GeoIP_country_code_by_ipnum, 0, 0 }, |
118 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
119 { ngx_string("geoip_country_code3"), NULL, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
120 ngx_http_geoip_country_variable, |
2985 | 121 (uintptr_t) GeoIP_country_code3_by_ipnum, 0, 0 }, |
122 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
123 { ngx_string("geoip_country_name"), NULL, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
124 ngx_http_geoip_country_variable, |
2985 | 125 (uintptr_t) GeoIP_country_name_by_ipnum, 0, 0 }, |
126 | |
3915 | 127 { ngx_string("geoip_org"), NULL, |
128 ngx_http_geoip_org_variable, | |
129 (uintptr_t) GeoIP_name_by_ipnum, 0, 0 }, | |
130 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
131 { 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
|
132 ngx_http_geoip_city_variable, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
133 offsetof(GeoIPRecord, continent_code), 0, 0 }, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
134 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
135 { 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
|
136 ngx_http_geoip_city_variable, |
2985 | 137 offsetof(GeoIPRecord, country_code), 0, 0 }, |
138 | |
139 { ngx_string("geoip_city_country_code3"), NULL, | |
140 ngx_http_geoip_city_variable, | |
141 offsetof(GeoIPRecord, country_code3), 0, 0 }, | |
142 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
143 { 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
|
144 ngx_http_geoip_city_variable, |
2985 | 145 offsetof(GeoIPRecord, country_name), 0, 0 }, |
146 | |
147 { ngx_string("geoip_region"), NULL, | |
148 ngx_http_geoip_city_variable, | |
149 offsetof(GeoIPRecord, region), 0, 0 }, | |
150 | |
3737 | 151 { ngx_string("geoip_region_name"), NULL, |
152 ngx_http_geoip_region_name_variable, | |
153 0, 0, 0 }, | |
154 | |
2985 | 155 { ngx_string("geoip_city"), NULL, |
156 ngx_http_geoip_city_variable, | |
157 offsetof(GeoIPRecord, city), 0, 0 }, | |
158 | |
159 { ngx_string("geoip_postal_code"), NULL, | |
160 ngx_http_geoip_city_variable, | |
161 offsetof(GeoIPRecord, postal_code), 0, 0 }, | |
162 | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
163 { ngx_string("geoip_latitude"), NULL, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
164 ngx_http_geoip_city_float_variable, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
165 offsetof(GeoIPRecord, latitude), 0, 0 }, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
166 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
167 { ngx_string("geoip_longitude"), NULL, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
168 ngx_http_geoip_city_float_variable, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
169 offsetof(GeoIPRecord, longitude), 0, 0 }, |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
170 |
3736
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
171 { ngx_string("geoip_dma_code"), NULL, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
172 ngx_http_geoip_city_int_variable, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
173 offsetof(GeoIPRecord, dma_code), 0, 0 }, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
174 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
175 { ngx_string("geoip_area_code"), NULL, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
176 ngx_http_geoip_city_int_variable, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
177 offsetof(GeoIPRecord, area_code), 0, 0 }, |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
178 |
2985 | 179 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
180 }; | |
181 | |
182 | |
183 static ngx_int_t | |
184 ngx_http_geoip_country_variable(ngx_http_request_t *r, | |
185 ngx_http_variable_value_t *v, uintptr_t data) | |
186 { | |
187 ngx_http_geoip_variable_handler_pt handler = | |
188 (ngx_http_geoip_variable_handler_pt) data; | |
189 | |
190 u_long addr; | |
191 const char *val; | |
192 struct sockaddr_in *sin; | |
193 ngx_http_geoip_conf_t *gcf; | |
194 | |
195 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); | |
196 | |
197 if (gcf->country == NULL) { | |
198 goto not_found; | |
199 } | |
200 | |
201 if (r->connection->sockaddr->sa_family != AF_INET) { | |
202 goto not_found; | |
203 } | |
204 | |
205 sin = (struct sockaddr_in *) r->connection->sockaddr; | |
206 addr = ntohl(sin->sin_addr.s_addr); | |
207 | |
208 val = handler(gcf->country, addr); | |
209 | |
210 if (val == NULL) { | |
211 goto not_found; | |
212 } | |
213 | |
214 v->len = ngx_strlen(val); | |
215 v->valid = 1; | |
216 v->no_cacheable = 0; | |
217 v->not_found = 0; | |
218 v->data = (u_char *) val; | |
219 | |
220 return NGX_OK; | |
221 | |
222 not_found: | |
223 | |
224 v->not_found = 1; | |
225 | |
226 return NGX_OK; | |
227 } | |
228 | |
229 | |
230 static ngx_int_t | |
3915 | 231 ngx_http_geoip_org_variable(ngx_http_request_t *r, |
232 ngx_http_variable_value_t *v, uintptr_t data) | |
233 { | |
234 ngx_http_geoip_variable_handler_pt handler = | |
235 (ngx_http_geoip_variable_handler_pt) data; | |
236 | |
237 u_long addr; | |
238 const char *val; | |
239 struct sockaddr_in *sin; | |
240 ngx_http_geoip_conf_t *gcf; | |
241 | |
242 gcf = ngx_http_get_module_main_conf(r, ngx_http_geoip_module); | |
243 | |
244 if (gcf->org == NULL) { | |
245 goto not_found; | |
246 } | |
247 | |
248 if (r->connection->sockaddr->sa_family != AF_INET) { | |
249 goto not_found; | |
250 } | |
251 | |
252 sin = (struct sockaddr_in *) r->connection->sockaddr; | |
253 addr = ntohl(sin->sin_addr.s_addr); | |
254 | |
255 val = handler(gcf->org, addr); | |
256 | |
257 if (val == NULL) { | |
258 goto not_found; | |
259 } | |
260 | |
261 v->len = ngx_strlen(val); | |
262 v->valid = 1; | |
263 v->no_cacheable = 0; | |
264 v->not_found = 0; | |
265 v->data = (u_char *) val; | |
266 | |
267 return NGX_OK; | |
268 | |
269 not_found: | |
270 | |
271 v->not_found = 1; | |
272 | |
273 return NGX_OK; | |
274 } | |
275 | |
276 | |
277 static ngx_int_t | |
2985 | 278 ngx_http_geoip_city_variable(ngx_http_request_t *r, |
279 ngx_http_variable_value_t *v, uintptr_t data) | |
280 { | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
281 char *val; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
282 size_t len; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
283 GeoIPRecord *gr; |
2985 | 284 |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
285 gr = ngx_http_geoip_get_city_record(r); |
2985 | 286 if (gr == NULL) { |
287 goto not_found; | |
288 } | |
289 | |
290 val = *(char **) ((char *) gr + data); | |
291 if (val == NULL) { | |
3031
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
292 goto no_value; |
2985 | 293 } |
294 | |
3031
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
295 len = ngx_strlen(val); |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
296 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
|
297 if (v->data == NULL) { |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
298 GeoIPRecord_delete(gr); |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
299 return NGX_ERROR; |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
300 } |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
301 |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
302 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
|
303 |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
304 v->len = len; |
2985 | 305 v->valid = 1; |
306 v->no_cacheable = 0; | |
307 v->not_found = 0; | |
3031
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
308 |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
309 GeoIPRecord_delete(gr); |
2985 | 310 |
311 return NGX_OK; | |
312 | |
3031
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
313 no_value: |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
314 |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
315 GeoIPRecord_delete(gr); |
98a8336c5b7c
fix memory leak if GeoIP City database was used
Igor Sysoev <igor@sysoev.ru>
parents:
2985
diff
changeset
|
316 |
2985 | 317 not_found: |
318 | |
319 v->not_found = 1; | |
320 | |
321 return NGX_OK; | |
322 } | |
323 | |
324 | |
325 static ngx_int_t | |
3737 | 326 ngx_http_geoip_region_name_variable(ngx_http_request_t *r, |
327 ngx_http_variable_value_t *v, uintptr_t data) | |
328 { | |
329 size_t len; | |
330 const char *val; | |
331 GeoIPRecord *gr; | |
332 | |
333 gr = ngx_http_geoip_get_city_record(r); | |
334 if (gr == NULL) { | |
335 goto not_found; | |
336 } | |
337 | |
338 val = GeoIP_region_name_by_code(gr->country_code, gr->region); | |
3742
01691af60f94
we can free GeoIPRecord just after GeoIP_region_name_by_code(),
Igor Sysoev <igor@sysoev.ru>
parents:
3741
diff
changeset
|
339 |
01691af60f94
we can free GeoIPRecord just after GeoIP_region_name_by_code(),
Igor Sysoev <igor@sysoev.ru>
parents:
3741
diff
changeset
|
340 GeoIPRecord_delete(gr); |
01691af60f94
we can free GeoIPRecord just after GeoIP_region_name_by_code(),
Igor Sysoev <igor@sysoev.ru>
parents:
3741
diff
changeset
|
341 |
3741
0f9b2d285bfc
fix segfault, the bug has been introduced in r3738
Igor Sysoev <igor@sysoev.ru>
parents:
3737
diff
changeset
|
342 if (val == NULL) { |
3742
01691af60f94
we can free GeoIPRecord just after GeoIP_region_name_by_code(),
Igor Sysoev <igor@sysoev.ru>
parents:
3741
diff
changeset
|
343 goto not_found; |
3741
0f9b2d285bfc
fix segfault, the bug has been introduced in r3738
Igor Sysoev <igor@sysoev.ru>
parents:
3737
diff
changeset
|
344 } |
3737 | 345 |
346 len = ngx_strlen(val); | |
347 v->data = ngx_pnalloc(r->pool, len); | |
348 if (v->data == NULL) { | |
349 return NGX_ERROR; | |
350 } | |
351 | |
352 ngx_memcpy(v->data, val, len); | |
353 | |
354 v->len = len; | |
355 v->valid = 1; | |
356 v->no_cacheable = 0; | |
357 v->not_found = 0; | |
358 | |
359 return NGX_OK; | |
360 | |
361 not_found: | |
362 | |
363 v->not_found = 1; | |
364 | |
365 return NGX_OK; | |
366 } | |
367 | |
368 | |
369 static ngx_int_t | |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
370 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
|
371 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
|
372 { |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
373 float val; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
374 GeoIPRecord *gr; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
375 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
376 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
|
377 if (gr == NULL) { |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
378 v->not_found = 1; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
379 return NGX_OK; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
380 } |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
381 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
382 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
|
383 if (v->data == NULL) { |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
384 GeoIPRecord_delete(gr); |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
385 return NGX_ERROR; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
386 } |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
387 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
388 val = *(float *) ((char *) gr + data); |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
389 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
390 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
|
391 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
392 GeoIPRecord_delete(gr); |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
393 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
394 return NGX_OK; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
395 } |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
396 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
397 |
3736
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
398 static ngx_int_t |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
399 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
|
400 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
|
401 { |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
402 int val; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
403 GeoIPRecord *gr; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
404 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
405 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
|
406 if (gr == NULL) { |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
407 v->not_found = 1; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
408 return NGX_OK; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
409 } |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
410 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
411 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
|
412 if (v->data == NULL) { |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
413 GeoIPRecord_delete(gr); |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
414 return NGX_ERROR; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
415 } |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
416 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
417 val = *(int *) ((char *) gr + data); |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
418 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
419 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
|
420 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
421 GeoIPRecord_delete(gr); |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
422 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
423 return NGX_OK; |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
424 } |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
425 |
257785918797
$geoip_dma_code and $geoip_area_code
Igor Sysoev <igor@sysoev.ru>
parents:
3398
diff
changeset
|
426 |
3398
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
427 static GeoIPRecord * |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
428 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
|
429 { |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
430 u_long addr; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
431 struct sockaddr_in *sin; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
432 ngx_http_geoip_conf_t *gcf; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
433 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
434 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
|
435 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
436 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
|
437 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
438 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
|
439 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
|
440 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
441 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
|
442 } |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
443 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
444 return NULL; |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
445 } |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
446 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
447 |
236634d2b603
$geoip_city_continent_code, $geoip_latitude, $geoip_longitude
Igor Sysoev <igor@sysoev.ru>
parents:
3031
diff
changeset
|
448 static ngx_int_t |
2985 | 449 ngx_http_geoip_add_variables(ngx_conf_t *cf) |
450 { | |
451 ngx_http_variable_t *var, *v; | |
452 | |
453 for (v = ngx_http_geoip_vars; v->name.len; v++) { | |
454 var = ngx_http_add_variable(cf, &v->name, v->flags); | |
455 if (var == NULL) { | |
456 return NGX_ERROR; | |
457 } | |
458 | |
459 var->get_handler = v->get_handler; | |
460 var->data = v->data; | |
461 } | |
462 | |
463 return NGX_OK; | |
464 } | |
465 | |
466 | |
467 static void * | |
468 ngx_http_geoip_create_conf(ngx_conf_t *cf) | |
469 { | |
470 ngx_pool_cleanup_t *cln; | |
471 ngx_http_geoip_conf_t *conf; | |
472 | |
473 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_geoip_conf_t)); | |
474 if (conf == NULL) { | |
475 return NULL; | |
476 } | |
477 | |
478 cln = ngx_pool_cleanup_add(cf->pool, 0); | |
479 if (cln == NULL) { | |
480 return NULL; | |
481 } | |
482 | |
483 cln->handler = ngx_http_geoip_cleanup; | |
484 cln->data = conf; | |
485 | |
486 return conf; | |
487 } | |
488 | |
489 | |
490 static char * | |
491 ngx_http_geoip_country(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
492 { | |
493 ngx_http_geoip_conf_t *gcf = conf; | |
494 | |
495 ngx_str_t *value; | |
496 | |
497 if (gcf->country) { | |
498 return "is duplicate"; | |
499 } | |
500 | |
501 value = cf->args->elts; | |
502 | |
503 gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE); | |
504 | |
505 if (gcf->country == NULL) { | |
506 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3914 | 507 "GeoIP_open(\"%V\") failed", &value[1]); |
2985 | 508 |
509 return NGX_CONF_ERROR; | |
510 } | |
511 | |
3859
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
512 if (cf->args->nelts == 3) { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
513 if (ngx_strcmp(value[2].data, "utf8") == 0) { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
514 GeoIP_set_charset (gcf->country, GEOIP_CHARSET_UTF8); |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
515 |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
516 } else { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
517 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
518 "invalid parameter \"%V\"", &value[2]); |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
519 return NGX_CONF_ERROR; |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
520 } |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
521 } |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
522 |
2985 | 523 switch (gcf->country->databaseType) { |
524 | |
525 case GEOIP_COUNTRY_EDITION: | |
526 case GEOIP_PROXY_EDITION: | |
527 case GEOIP_NETSPEED_EDITION: | |
528 | |
529 return NGX_CONF_OK; | |
530 | |
531 default: | |
532 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
533 "invalid GeoIP database \"%V\" type:%d", | |
534 &value[1], gcf->country->databaseType); | |
535 return NGX_CONF_ERROR; | |
536 } | |
537 } | |
538 | |
539 | |
540 static char * | |
3915 | 541 ngx_http_geoip_org(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
542 { | |
543 ngx_http_geoip_conf_t *gcf = conf; | |
544 | |
545 ngx_str_t *value; | |
546 | |
547 if (gcf->org) { | |
548 return "is duplicate"; | |
549 } | |
550 | |
551 value = cf->args->elts; | |
552 | |
553 gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE); | |
554 | |
555 if (gcf->org == NULL) { | |
556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
557 "GeoIP_open(\"%V\") failed", &value[1]); | |
558 | |
559 return NGX_CONF_ERROR; | |
560 } | |
561 | |
562 if (cf->args->nelts == 3) { | |
563 if (ngx_strcmp(value[2].data, "utf8") == 0) { | |
564 GeoIP_set_charset (gcf->org, GEOIP_CHARSET_UTF8); | |
565 | |
566 } else { | |
567 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
568 "invalid parameter \"%V\"", &value[2]); | |
569 return NGX_CONF_ERROR; | |
570 } | |
571 } | |
572 | |
573 switch (gcf->org->databaseType) { | |
574 | |
575 case GEOIP_ISP_EDITION: | |
576 case GEOIP_ORG_EDITION: | |
577 case GEOIP_DOMAIN_EDITION: | |
578 case GEOIP_ASNUM_EDITION: | |
579 | |
580 return NGX_CONF_OK; | |
581 | |
582 default: | |
583 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
584 "invalid GeoIP database \"%V\" type:%d", | |
585 &value[1], gcf->org->databaseType); | |
586 return NGX_CONF_ERROR; | |
587 } | |
588 } | |
589 | |
590 | |
591 static char * | |
2985 | 592 ngx_http_geoip_city(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
593 { | |
594 ngx_http_geoip_conf_t *gcf = conf; | |
595 | |
596 ngx_str_t *value; | |
597 | |
598 if (gcf->city) { | |
599 return "is duplicate"; | |
600 } | |
601 | |
602 value = cf->args->elts; | |
603 | |
604 gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE); | |
605 | |
606 if (gcf->city == NULL) { | |
607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3914 | 608 "GeoIP_open(\"%V\") failed", &value[1]); |
2985 | 609 |
610 return NGX_CONF_ERROR; | |
611 } | |
612 | |
3859
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
613 if (cf->args->nelts == 3) { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
614 if (ngx_strcmp(value[2].data, "utf8") == 0) { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
615 GeoIP_set_charset (gcf->city, GEOIP_CHARSET_UTF8); |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
616 |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
617 } else { |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
618 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
619 "invalid parameter \"%V\"", &value[2]); |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
620 return NGX_CONF_ERROR; |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
621 } |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
622 } |
30d4d6187316
utf8 parameter of geoip_country and geoip_city
Igor Sysoev <igor@sysoev.ru>
parents:
3742
diff
changeset
|
623 |
2985 | 624 switch (gcf->city->databaseType) { |
625 | |
626 case GEOIP_CITY_EDITION_REV0: | |
627 case GEOIP_CITY_EDITION_REV1: | |
628 | |
629 return NGX_CONF_OK; | |
630 | |
631 default: | |
632 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
633 "invalid GeoIP City database \"%V\" type:%d", | |
634 &value[1], gcf->city->databaseType); | |
635 return NGX_CONF_ERROR; | |
636 } | |
637 } | |
638 | |
639 | |
640 static void | |
641 ngx_http_geoip_cleanup(void *data) | |
642 { | |
643 ngx_http_geoip_conf_t *gcf = data; | |
644 | |
645 if (gcf->country) { | |
646 GeoIP_delete(gcf->country); | |
647 } | |
648 | |
3915 | 649 if (gcf->org) { |
650 GeoIP_delete(gcf->org); | |
651 } | |
652 | |
2985 | 653 if (gcf->city) { |
654 GeoIP_delete(gcf->city); | |
655 } | |
656 } |