telize

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

commit 1b014cb7e5d88ea20ee8af9c5b7fba2eeca99898
parent ade7a1e929a8ac8c22adc5fb13d0515aaf4231b1
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Oct 2018 09:24:28 +0200

Perform GeoLite2 City lookup

Diffstat:
Msrc/location.c | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/location.c b/src/location.c @@ -51,6 +51,10 @@ location(struct http_request *req) char *answer, *callback, *json, *ip, addr[INET6_ADDRSTRLEN]; json_t *output = json_object(); + int gai_error, mmdb_error; + MMDB_lookup_result_s lookup; + MMDB_entry_data_s entry_data; + http_populate_get(req); if (req->owner->addrtype == AF_INET) { @@ -66,6 +70,10 @@ location(struct http_request *req) } json_object_set_new(output, "ip", json_string(ip)); + + /* GeoLite2 City lookup */ + lookup = MMDB_lookup_string(&city, ip, &gai_error, &mmdb_error); + json = json_dumps(output, JSON_INDENT(3)); if (http_argument_get_string(req, "callback", &callback)) {