telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit ade7a1e929a8ac8c22adc5fb13d0515aaf4231b1
parent e033f89b4e73e3a36c9939fef25051189234175f
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Oct 2018 09:17:15 +0200

Add an init function to load GeoLite2 City and ASN databases

Diffstat:
Mconf/telize.conf | 2+-
Msrc/location.c | 22++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/conf/telize.conf b/conf/telize.conf @@ -1,7 +1,7 @@ # telize configuration bind 127.0.0.1 8888 -load ./telize.so +load ./telize.so init tls_dhparam dh2048.pem diff --git a/src/location.c b/src/location.c @@ -20,9 +20,31 @@ #include <jansson.h> #include <maxminddb.h> +MMDB_s asn; +MMDB_s city; + +int init(int); int location(struct http_request *); int +init(int state) +{ + if (MMDB_open("/var/db/GeoIP/GeoLite2-City.mmdb", + MMDB_MODE_MMAP, &city) != MMDB_SUCCESS) { + kore_log(LOG_ERR, "can't open GeoLite2 City database: %s", errno_s); + return (KORE_RESULT_ERROR); + } + + if (MMDB_open("/var/db/GeoIP/GeoLite2-ASN.mmdb", + MMDB_MODE_MMAP, &asn) != MMDB_SUCCESS) { + kore_log(LOG_ERR, "can't open GeoLite2 ASN database: %s", errno_s); + return (KORE_RESULT_ERROR); + } + + return (KORE_RESULT_OK); +} + +int location(struct http_request *req) { const char *visitor_ip;