/* process data based on a unique key, this includes the following * modules, VISITORS, BROWSERS, OS */ static void process_unique_data (char *host, char *date, char *agent) { #ifdef HAVE_LIBGEOIP char city[CITY_LEN] = ""; char continent[CONTINENT_LEN] = ""; char country[COUNTRY_LEN] = ""; #endif char *a = NULL, *browser_key = NULL, *browser = NULL; char *os_key = NULL, *opsys = NULL; char visitor_key[UKEY_BUFFER]; char os_type[OPESYS_TYPE_LEN], browser_type[BROWSER_TYPE_LEN]; a = deblank (xstrdup (agent)); snprintf (visitor_key, sizeof (visitor_key), "%s|%s|%s", host, date, a); (visitor_key)[sizeof (visitor_key) - 1] = '\0'; free (a); /* Check if the unique visitor key exists, if not, * process hit as unique visitor. Includes, BROWSERS, OSs, VISITORS. */ if (process_generic_data (ht_unique_visitors, visitor_key) == -1) { process_generic_data (ht_unique_vis, date); browser_key = xstrdup (agent); os_key = xstrdup (agent); /* extract browser & OS from agent */ browser = verify_browser (browser_key, browser_type); if (browser != NULL) process_browser (ht_browsers, browser, browser_type); opsys = verify_os (os_key, os_type); if (opsys != NULL) process_opesys (ht_os, opsys, os_type); #ifdef HAVE_LIBGEOIP if (geo_location_data != NULL) { if (conf.geoip_city_data) geoip_get_city (host, city); geoip_get_country (host, country); geoip_get_continent (host, continent); process_geolocation (ht_countries, country, continent, city); } #endif } if (browser != NULL) free (browser); if (browser_key != NULL) free (browser_key); if (os_key != NULL) free (os_key); if (opsys != NULL) free (opsys); }
/* Entry point to set GeoIP location into the corresponding buffers, * (continent, country, city). * * On error, 1 is returned * On success, buffers are set and 0 is returned */ int set_geolocation (char *host, char *continent, char *country, char *city) { int type_ip = 0; if (geo_location_data == NULL) return 1; if (invalid_ipaddr (host, &type_ip)) return 1; geoip_get_country (host, country, type_ip); geoip_get_continent (host, continent, type_ip); if (conf.geoip_database) geoip_get_city (host, city, type_ip); return 0; }