commit 669ca3b710bf790efaaa85dad4561d7790713d88
parent 8268881562372a2d856c9d4a1a80e8ec72d60314
Author: Frederic Cambus <fred@statdns.com>
Date: Wed, 13 Jan 2016 18:36:44 +0100
Perform GeoIP lookup and HLL add in the same if block
Diffstat:
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -5,7 +5,7 @@
/* http://www.logswan.org */
/* */
/* Created: 2015-05-31 */
-/* Last Updated: 2016-01-10 */
+/* Last Updated: 2016-01-13 */
/* */
/* Logswan is released under the BSD 3-Clause license. */
/* See LICENSE file for details. */
@@ -141,15 +141,25 @@ int main (int argc, char *argv[]) {
}
if (isIPv4 || isIPv6) {
- /* Increment countries array */
- if (geoip && isIPv4) {
- countryId = GeoIP_id_by_addr(geoip, parsedLine.remoteHost);
+ if (isIPv4) {
+ /* Unique visitors */
+ hll_add(&uniqueIPv4, parsedLine.remoteHost, strlen(parsedLine.remoteHost));
+
+ if (geoip) {
+ countryId = GeoIP_id_by_addr(geoip, parsedLine.remoteHost);
+ }
}
- if (geoipv6 && isIPv6) {
- countryId = GeoIP_id_by_addr_v6(geoipv6, parsedLine.remoteHost);
+ if (isIPv6) {
+ /* Unique visitors */
+ hll_add(&uniqueIPv6, parsedLine.remoteHost, strlen(parsedLine.remoteHost));
+
+ if (geoipv6) {
+ countryId = GeoIP_id_by_addr_v6(geoipv6, parsedLine.remoteHost);
+ }
}
+ /* Increment countries array */
results.countries[countryId]++;
/* Increment continents array */
@@ -160,15 +170,6 @@ int main (int argc, char *argv[]) {
}
}
- /* Unique visitors */
- if (isIPv4) {
- hll_add(&uniqueIPv4, parsedLine.remoteHost, strlen(parsedLine.remoteHost));
- }
-
- if (isIPv6) {
- hll_add(&uniqueIPv6, parsedLine.remoteHost, strlen(parsedLine.remoteHost));
- }
-
/* Hourly distribution */
if (parsedLine.date) {
parseDate(&parsedDate, parsedLine.date);