logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

commit 35b45b3c582c96e6d6fd198c4aa7daf0df579586
parent cc1f0b4ed66c0b8e3ef4bd8ab397402899fc6f27
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri, 16 Mar 2018 11:33:23 +0100

Add back GeoIP country lookups

Diffstat:
Msrc/logswan.c | 20+++++++++++++++-----
Msrc/output.c | 8+++-----
2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/logswan.c b/src/logswan.c @@ -5,7 +5,7 @@ /* https://www.logswan.org */ /* */ /* Created: 2015-05-31 */ -/* Last Updated: 2018-01-21 */ +/* Last Updated: 2018-03-16 */ /* */ /* Logswan is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -191,14 +191,24 @@ main(int argc, char *argv[]) { if (geoip) { lookup = MMDB_lookup_string(&geoip2, parsedLine.remoteHost, &gai_error, &mmdb_error); - // Increment countries array - //results.countries[countryId]++; - MMDB_entry_data_s entry_data; + + MMDB_get_value(&lookup.entry, &entry_data, "country", "iso_code", NULL); + + if (entry_data.has_data) { + /* Increment countries array */ + for (size_t loop = 0; loop < COUNTRIES; loop++) { + if (!strncmp(countriesId[loop], entry_data.utf8_string, 2)) { + results.countries[loop]++; + break; + } + } + } + MMDB_get_value(&lookup.entry, &entry_data, "continent", "code", NULL); if (entry_data.has_data) { - // Increment continents array + /* Increment continents array */ for (size_t loop = 0; loop < CONTINENTS; loop++) { if (!strncmp(continentsId[loop], entry_data.utf8_string, 2)) { results.continents[loop]++; diff --git a/src/output.c b/src/output.c @@ -5,7 +5,7 @@ /* https://www.logswan.org */ /* */ /* Created: 2015-05-31 */ -/* Last Updated: 2018-01-21 */ +/* Last Updated: 2018-03-16 */ /* */ /* Logswan is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -42,18 +42,16 @@ char } } -/* for (size_t loop = 0; loop < COUNTRIES; loop++) { if (results->countries[loop]) { json_array_append_new( countries, json_pack("{s:s, s:s, s:i}", - "data", GeoIP_code_by_id(loop), - "name", GeoIP_name_by_id(loop), + "data", countriesId[loop], + "name", countriesNames[loop], "hits", results->countries[loop])); } } -*/ for (size_t loop = 0; loop < 24; loop++) { if (results->hours[loop]) {