Docs ModGeoip » mod_geoip-for-1.4.39.patch
mod_geoip.c 2016-02-29 17:25:17.875915448 -0500 | ||
---|---|---|
#include "base.h"
|
||
#include "log.h"
|
||
#include "buffer.h"
|
||
#include "inet_ntop_cache.h"
|
||
|
||
#include "plugin.h"
|
||
|
||
... | ... | |
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
|
||
|
||
for (i = 0; i < srv->config_context->used; i++) {
|
||
data_config const* config = (data_config const*)srv->config_context->data[i];
|
||
plugin_config *s;
|
||
int mode;
|
||
|
||
... | ... | |
|
||
p->config_storage[i] = s;
|
||
|
||
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
|
||
if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) {
|
||
return HANDLER_ERROR;
|
||
}
|
||
|
||
... | ... | |
|
||
if (!buffer_is_empty(p->conf.db_name)) {
|
||
const char *remote_ip;
|
||
GeoIP *gi;
|
||
data_string *ds;
|
||
GeoIPRecord *gir;
|
||
const char *returnedCountry;
|
||
|
||
remote_ip = inet_ntop_cache_get_ip(srv, &(con->dst_addr));
|
||
... | ... | |
}
|
||
|
||
/* if we are here, geo city is in use */
|
||
GeoIPRecord * gir;
|
||
|
||
if (NULL != (gir = GeoIP_record_by_addr(p->conf.gi, remote_ip))) {
|
||
/* get the country code 2 chars */
|
||
... | ... | |
|
||
/* get the latitude */
|
||
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_LATITUDE"))) {
|
||
char latitude[32];
|
||
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
||
ds = data_string_init();
|
||
}
|
||
|
||
char latitude[32];
|
||
sprintf(&latitude, "%f", gir->latitude);
|
||
snprintf(latitude, sizeof(latitude), "%f", gir->latitude);
|
||
buffer_copy_string(ds->key, "GEOIP_CITY_LATITUDE");
|
||
buffer_copy_string(ds->value, latitude);
|
||
array_insert_unique(con->environment, (data_unset *)ds);
|
||
... | ... | |
|
||
/* get the long latitude */
|
||
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_LONG_LATITUDE"))) {
|
||
char long_latitude[32];
|
||
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
||
ds = data_string_init();
|
||
}
|
||
|
||
char long_latitude[32];
|
||
sprintf(&long_latitude, "%f", gir->longitude);
|
||
snprintf(long_latitude, sizeof(long_latitude), "%f", gir->longitude);
|
||
buffer_copy_string(ds->key, "GEOIP_CITY_LONG_LATITUDE");
|
||
buffer_copy_string(ds->value, long_latitude);
|
||
array_insert_unique(con->environment, (data_unset *)ds);
|
||
... | ... | |
|
||
/* get the dma code */
|
||
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_DMA_CODE"))) {
|
||
char dc[5];
|
||
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
||
ds = data_string_init();
|
||
}
|
||
|
||
char dc[5];
|
||
sprintf(&dc, "%i", gir->dma_code);
|
||
snprintf(dc, sizeof(dc), "%i", gir->dma_code);
|
||
buffer_copy_string(ds->key, "GEOIP_CITY_DMA_CODE");
|
||
buffer_copy_string(ds->value, dc);
|
||
array_insert_unique(con->environment, (data_unset *)ds);
|
||
... | ... | |
|
||
/* get the area code */
|
||
if (NULL == (ds = (data_string *)array_get_element(con->environment, "GEOIP_CITY_AREA_CODE"))) {
|
||
char ac[5];
|
||
if (NULL == (ds = (data_string *)array_get_unused_element(con->environment, TYPE_STRING))) {
|
||
ds = data_string_init();
|
||
}
|
||
|
||
char ac[5];
|
||
sprintf(&ac, "%i", gir->area_code);
|
||
snprintf(ac, sizeof(ac), "%i", gir->area_code);
|
||
buffer_copy_string(ds->key, "GEOIP_CITY_AREA_CODE");
|
||
buffer_copy_string(ds->value, ac);
|
||
array_insert_unique(con->environment, (data_unset *)ds);
|
||
... | ... | |
|
||
/* this function is called at dlopen() time and inits the callbacks */
|
||
|
||
int mod_geoip_plugin_init(plugin *p);
|
||
int mod_geoip_plugin_init(plugin *p) {
|
||
p->version = LIGHTTPD_VERSION_ID;
|
||
p->name = buffer_init_string("geoip");
|