maxmind / geoip-api-mod_geoip2

DEPRECATED GeoIP Legacy module for Apache 2
Other
50 stars 22 forks source link

Possible to get country name and continent code from the Region file? #5

Closed jaydiablo closed 11 years ago

jaydiablo commented 11 years ago

We're using the maxmind region file with the apache module and noticed that it only returns the region code, country code and region name, even though the country file returns country name and continent code.

It would be nice if the region file would return at least as much information as the country file.

It looks like the country lookup is given an integer id, which is then used to get the country code, country name and continent code:

https://github.com/maxmind/geoip-api-mod_geoip2/blob/master/mod_geoip.c#L579

But in the region lookup, it's given the region code and country code (rather than id). Is there a function in the C library that would return the country id from the code? Then it would be possible to lookup the country name and continent code with that.

Thanks!

oschwald commented 11 years ago

Unfortunately this isn't supported right now. Although I haven't looked at the code closely, I think adding this might require exposing the data in libGeoIP and then modifying this module. We would happily accept a reasonable pull request that does this.

borisz commented 11 years ago

It is possible if you translate the country_code to country_id in a first step. I pushed an untested example bz/add-region-country-name.

Basically it works like

country_id = GeoIP_id_by_code(giregion->country_code[0]);
country_name = GeoIP_country_name[country_id];
apr_table_setn(r->subprocess_env, "GEOIP_COUNTRY_NAME", country_name);