8 |
8 |
#include "base.h"
|
9 |
9 |
#include "log.h"
|
10 |
10 |
#include "buffer.h"
|
|
11 |
#include "inet_ntop_cache.h"
|
11 |
12 |
|
12 |
13 |
#include "plugin.h"
|
13 |
14 |
|
... | ... | |
131 |
132 |
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
|
132 |
133 |
|
133 |
134 |
for (i = 0; i < srv->config_context->used; i++) {
|
|
135 |
data_config const* config = (data_config const*)srv->config_context->data[i];
|
134 |
136 |
plugin_config *s;
|
135 |
137 |
int mode;
|
136 |
138 |
|
... | ... | |
145 |
147 |
|
146 |
148 |
p->config_storage[i] = s;
|
147 |
149 |
|
148 |
|
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
|
|
150 |
if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) {
|
149 |
151 |
return HANDLER_ERROR;
|
150 |
152 |
}
|
151 |
153 |
|
... | ... | |
221 |
223 |
|
222 |
224 |
if (!buffer_is_empty(p->conf.db_name)) {
|
223 |
225 |
const char *remote_ip;
|
224 |
|
GeoIP *gi;
|
225 |
226 |
data_string *ds;
|
|
227 |
GeoIPRecord *gir;
|
226 |
228 |
const char *returnedCountry;
|
227 |
229 |
|
228 |
230 |
remote_ip = inet_ntop_cache_get_ip(srv, &(con->dst_addr));
|
... | ... | |
272 |
274 |
}
|
273 |
275 |
|
274 |
276 |
/* if we are here, geo city is in use */
|
275 |
|
GeoIPRecord * gir;
|
276 |
277 |
|
277 |
278 |
if (NULL != (gir = GeoIP_record_by_addr(p->conf.gi, remote_ip))) {
|
278 |
279 |
/* get the country code 2 chars */
|
... | ... | |
343 |
344 |
|
344 |
345 |
/* get the latitude */
|
345 |
346 |
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_LATITUDE"))) {
|
|
347 |
char latitude[32];
|
346 |
348 |
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
347 |
349 |
ds = data_string_init();
|
348 |
350 |
}
|
349 |
351 |
|
350 |
|
char latitude[32];
|
351 |
|
sprintf(&latitude, "%f", gir->latitude);
|
|
352 |
snprintf(latitude, sizeof(latitude), "%f", gir->latitude);
|
352 |
353 |
buffer_copy_string(ds->key, "GEOIP_CITY_LATITUDE");
|
353 |
354 |
buffer_copy_string(ds->value, latitude);
|
354 |
355 |
array_insert_unique(con->environment, (data_unset *)ds);
|
... | ... | |
356 |
357 |
|
357 |
358 |
/* get the long latitude */
|
358 |
359 |
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_LONG_LATITUDE"))) {
|
|
360 |
char long_latitude[32];
|
359 |
361 |
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
360 |
362 |
ds = data_string_init();
|
361 |
363 |
}
|
362 |
364 |
|
363 |
|
char long_latitude[32];
|
364 |
|
sprintf(&long_latitude, "%f", gir->longitude);
|
|
365 |
snprintf(long_latitude, sizeof(long_latitude), "%f", gir->longitude);
|
365 |
366 |
buffer_copy_string(ds->key, "GEOIP_CITY_LONG_LATITUDE");
|
366 |
367 |
buffer_copy_string(ds->value, long_latitude);
|
367 |
368 |
array_insert_unique(con->environment, (data_unset *)ds);
|
... | ... | |
369 |
370 |
|
370 |
371 |
/* get the dma code */
|
371 |
372 |
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_DMA_CODE"))) {
|
|
373 |
char dc[5];
|
372 |
374 |
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
373 |
375 |
ds = data_string_init();
|
374 |
376 |
}
|
375 |
377 |
|
376 |
|
char dc[5];
|
377 |
|
sprintf(&dc, "%i", gir->dma_code);
|
|
378 |
snprintf(dc, sizeof(dc), "%i", gir->dma_code);
|
378 |
379 |
buffer_copy_string(ds->key, "GEOIP_CITY_DMA_CODE");
|
379 |
380 |
buffer_copy_string(ds->value, dc);
|
380 |
381 |
array_insert_unique(con->environment, (data_unset *)ds);
|
... | ... | |
382 |
383 |
|
383 |
384 |
/* get the area code */
|
384 |
385 |
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_AREA_CODE"))) {
|
|
386 |
char ac[5];
|
385 |
387 |
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
386 |
388 |
ds = data_string_init();
|
387 |
389 |
}
|
388 |
390 |
|
389 |
|
char ac[5];
|
390 |
|
sprintf(&ac, "%i", gir->area_code);
|
|
391 |
snprintf(ac, sizeof(ac), "%i", gir->area_code);
|
391 |
392 |
buffer_copy_string(ds->key, "GEOIP_CITY_AREA_CODE");
|
392 |
393 |
buffer_copy_string(ds->value, ac);
|
393 |
394 |
array_insert_unique(con->environment, (data_unset *)ds);
|
... | ... | |
401 |
402 |
|
402 |
403 |
/* this function is called at dlopen() time and inits the callbacks */
|
403 |
404 |
|
|
405 |
int mod_geoip_plugin_init(plugin *p);
|
404 |
406 |
int mod_geoip_plugin_init(plugin *p) {
|
405 |
407 |
p->version = LIGHTTPD_VERSION_ID;
|
406 |
408 |
p->name = buffer_init_string("geoip");
|