X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/47217d7bef39ecfc1387708f2604027a88bd8aa5..7e032dc63479ed3d0b76fe71c05303fbe7dbc53a:/geoip/geoip.c diff --git a/geoip/geoip.c b/geoip/geoip.c index 1a3cae61..d159cfa0 100644 --- a/geoip/geoip.c +++ b/geoip/geoip.c @@ -10,22 +10,22 @@ #include "../control/control.h" #include "../lib/version.h" +#include + #include "libGeoIP/GeoIP.h" #include "geoip.h" -#warning This module is GPL'ed. Load/link at your peril. - 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; @@ -33,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) @@ -68,11 +68,11 @@ void _fini(void) { deregisterhook(HOOK_CONTROL_WHOISREQUEST, &geoip_whois_handler); } -void geoip_setupuser(nick *np) { - if (!irc_in_addr_is_ipv4(&np->p_ipaddr)) +static void geoip_setupuser(nick *np) { + if (!irc_in_addr_is_ipv4(&np->ipaddress)) return; /* geoip only supports ipv4 */ - unsigned int ip = irc_in_addr_v4_to_int(&np->p_ipaddr); + unsigned int ip = irc_in_addr_v4_to_int(&np->ipaddress); int country = GeoIP_id_by_ipnum(gi, ip); if((country < COUNTRY_MIN) || (country > COUNTRY_MAX)) return; @@ -81,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; @@ -97,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) @@ -109,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