X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/b2182a68d3b582e7d60fe1cfa193cadbf61be1be..f6ecfee93e749a205c09ff49005a7e47d053fe8d:/geoip/geoip.c diff --git a/geoip/geoip.c b/geoip/geoip.c index 38de7afe..9ea84edb 100644 --- a/geoip/geoip.c +++ b/geoip/geoip.c @@ -8,19 +8,24 @@ #include "../core/config.h" #include "../core/hooks.h" #include "../control/control.h" +#include "../lib/version.h" + +#include #include "libGeoIP/GeoIP.h" #include "geoip.h" +MODULE_VERSION(""); + int geoip_totals[COUNTRY_MAX + 1]; -int geoip_nickext = -1; -GeoIP *gi = NULL; +static int geoip_nickext = -1; +static GeoIP *gi = NULL; -void geoip_setupuser(nick *np); +static void geoip_setupuser(nick *np); -void geoip_new_nick(int hook, void *args); -void geoip_quit(int hook, void *args); -void geoip_whois_handler(int hooknum, void *arg); +static void geoip_new_nick(int hook, void *args); +static void geoip_quit(int hook, void *args); +static void geoip_whois_handler(int hooknum, void *arg); void _init(void) { int i; @@ -28,7 +33,7 @@ void _init(void) { sstring *filename; filename = getcopyconfigitem("geoip", "db", "GeoIP.dat", 256); - gi = GeoIP_new(GEOIP_MEMORY_CACHE, filename->content); + gi = GeoIP_open(filename->content, GEOIP_MEMORY_CACHE); freesstring(filename); if(!gi) @@ -63,8 +68,12 @@ void _fini(void) { deregisterhook(HOOK_CONTROL_WHOISREQUEST, &geoip_whois_handler); } -void geoip_setupuser(nick *np) { - int country = GeoIP_id_by_ipnum(gi, np->ipaddress); +static void geoip_setupuser(nick *np) { + if (!irc_in_addr_is_ipv4(&np->p_ipaddr)) + return; /* geoip only supports ipv4 */ + + unsigned int ip = irc_in_addr_v4_to_int(&np->p_ipaddr); + int country = GeoIP_id_by_ipnum(gi, ip); if((country < COUNTRY_MIN) || (country > COUNTRY_MAX)) return; @@ -72,11 +81,11 @@ void geoip_setupuser(nick *np) { np->exts[geoip_nickext] = (void *)(long)country; } -void geoip_new_nick(int hook, void *args) { +static void geoip_new_nick(int hook, void *args) { geoip_setupuser((nick *)args); } -void geoip_quit(int hook, void *args) { +static void geoip_quit(int hook, void *args) { int item; nick *np = (nick *)args; @@ -88,9 +97,10 @@ void geoip_quit(int hook, void *args) { geoip_totals[item]--; } -void geoip_whois_handler(int hooknum, void *arg) { +static void geoip_whois_handler(int hooknum, void *arg) { int item; - char message[512], *longcountry, *shortcountry, *shortcountry3; + char message[512]; + const char *longcountry, *shortcountry; nick *np = (nick *)arg; if(!np) @@ -100,9 +110,20 @@ void geoip_whois_handler(int hooknum, void *arg) { if((item < COUNTRY_MIN) || (item > COUNTRY_MAX)) return; - if(GeoIP_country_info_by_id(item, &shortcountry, &shortcountry3, &longcountry)) { + shortcountry = GeoIP_code_by_id(item); + longcountry = GeoIP_name_by_id(item); + + if(shortcountry && longcountry) { snprintf(message, sizeof(message), "Country : %s (%s)", shortcountry, longcountry); triggerhook(HOOK_CONTROL_WHOISREPLY, message); } } +int geoip_lookupcode(char *code) { + int i; + for(i=COUNTRY_MIN;i