From ae4b0728707a9f55f1f330da17212b3a415dc6dc Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Date: Sat, 15 Sep 2018 19:34:09 -0400 Subject: service: Allow disabling of all sources through config Fixes #46. --- data/geoclue.conf.in | 21 +++++++++++ src/gclue-config.c | 99 ++++++++++++++++++++++++++++++++++++++++++++-------- src/gclue-config.h | 5 +++ src/gclue-locator.c | 35 ++++++++++++------- 4 files changed, 133 insertions(+), 27 deletions(-) diff --git a/data/geoclue.conf.in b/data/geoclue.conf.in index 061c8c5..38dd1b5 100644 --- a/data/geoclue.conf.in +++ b/data/geoclue.conf.in @@ -13,9 +13,30 @@ whitelist=@demo_agent@gnome-shell;io.elementary.desktop.agent-geoclue2 # Fetch location from NMEA sources on local network? enable=true +# 3G source configuration options +[3g] + +# Enable 3G source +enable=true + +# CDMA source configuration options +[cdma] + +# Enable CDMA source +enable=true + +# Modem GPS source configuration options +[modem-gps] + +# Enable Modem-GPS source +enable=true + # WiFi source configuration options [wifi] +# Enable WiFi source +enable=true + # URL to the wifi geolocation service. The key can currenty be anything, just # needs to be present but that is likely going to change in future. url=https://location.services.mozilla.com/v1/geolocate?key=geoclue diff --git a/src/gclue-config.c b/src/gclue-config.c index 32bfc88..de352ba 100644 --- a/src/gclue-config.c +++ b/src/gclue-config.c @@ -58,6 +58,10 @@ struct _GClueConfigPrivate char *wifi_url; gboolean wifi_submit; gboolean enable_nmea_source; + gboolean enable_3g_source; + gboolean enable_cdma_source; + gboolean enable_modem_gps_source; + gboolean enable_wifi_source; char *wifi_submit_url; char *wifi_submit_nick; @@ -113,7 +117,9 @@ load_agent_config (GClueConfig *config) static void load_app_configs (GClueConfig *config) { - const char *known_groups[] = { "agent", "wifi", "network-nmea", NULL }; + const char *known_groups[] = { "agent", "wifi", "3g", "cdma", + "modem-gps", "network-nmea", + NULL }; GClueConfigPrivate *priv = config->priv; gsize num_groups = 0, i; char **groups; @@ -182,6 +188,32 @@ error_out: g_strfreev (groups); } +static gboolean +load_enable_source_config (GClueConfig *config, + const char *source_name) +{ + GClueConfigPrivate *priv = config->priv; + GError *error = NULL; + gboolean enable; + + enable = g_key_file_get_boolean (priv->key_file, + source_name, + "enable", + &error); + if (error != NULL) { + g_debug ("Failed to get config %s/enable:" + " %s", + source_name, + error->message); + g_error_free (error); + + /* Source should be enabled by default */ + return TRUE; + } + + return enable; +} + #define DEFAULT_WIFI_URL "https://location.services.mozilla.com/v1/geolocate?key=geoclue" #define DEFAULT_WIFI_SUBMIT_URL "https://location.services.mozilla.com/v1/submit?key=geoclue" @@ -191,6 +223,8 @@ load_wifi_config (GClueConfig *config) GClueConfigPrivate *priv = config->priv; GError *error = NULL; + priv->enable_wifi_source = load_enable_source_config (config, "wifi"); + priv->wifi_url = g_key_file_get_string (priv->key_file, "wifi", "url", @@ -234,23 +268,31 @@ load_wifi_config (GClueConfig *config) } static void -load_network_nmea_config (GClueConfig *config) +load_3g_config (GClueConfig *config) { - GClueConfigPrivate *priv = config->priv; - GError *error = NULL; + config->priv->enable_3g_source = + load_enable_source_config (config, "3g"); +} - priv->enable_nmea_source = g_key_file_get_boolean (priv->key_file, - "network-nmea", - "enable", - &error); - if (error != NULL) { - g_debug ("Failed to get config network-nmea/enable:" - " %s", - error->message); - g_error_free (error); +static void +load_cdma_config (GClueConfig *config) +{ + config->priv->enable_cdma_source = + load_enable_source_config (config, "cdma"); +} - return; - } +static void +load_modem_gps_config (GClueConfig *config) +{ + config->priv->enable_modem_gps_source = + load_enable_source_config (config, "modem-gps"); +} + +static void +load_network_nmea_config (GClueConfig *config) +{ + config->priv->enable_nmea_source = + load_enable_source_config (config, "network-nmea"); } static void @@ -278,6 +320,9 @@ gclue_config_init (GClueConfig *config) load_agent_config (config); load_app_configs (config); load_wifi_config (config); + load_3g_config (config); + load_cdma_config (config); + load_modem_gps_config (config); load_network_nmea_config (config); } @@ -412,6 +457,30 @@ gclue_config_get_wifi_submit_data (GClueConfig *config) return config->priv->wifi_submit; } +gboolean +gclue_config_get_enable_wifi_source (GClueConfig *config) +{ + return config->priv->enable_wifi_source; +} + +gboolean +gclue_config_get_enable_3g_source (GClueConfig *config) +{ + return config->priv->enable_3g_source; +} + +gboolean +gclue_config_get_enable_modem_gps_source (GClueConfig *config) +{ + return config->priv->enable_modem_gps_source; +} + +gboolean +gclue_config_get_enable_cdma_source (GClueConfig *config) +{ + return config->priv->enable_cdma_source; +} + gboolean gclue_config_get_enable_nmea_source (GClueConfig *config) { diff --git a/src/gclue-config.h b/src/gclue-config.h index 88f6c3e..6dc10c9 100644 --- a/src/gclue-config.h +++ b/src/gclue-config.h @@ -79,6 +79,11 @@ const char * gclue_config_get_wifi_submit_nick (GClueConfig *config void gclue_config_set_wifi_submit_nick (GClueConfig *config, const char *nick); gboolean gclue_config_get_wifi_submit_data (GClueConfig *config); +gboolean gclue_config_get_enable_wifi_source (GClueConfig *config); +gboolean gclue_config_get_enable_3g_source (GClueConfig *config); +gboolean gclue_config_get_enable_cdma_source (GClueConfig *config); +gboolean gclue_config_get_enable_modem_gps_source + (GClueConfig *config); gboolean gclue_config_get_enable_nmea_source (GClueConfig *config); void gclue_config_set_wifi_submit_data (GClueConfig *config, gboolean submit); diff --git a/src/gclue-locator.c b/src/gclue-locator.c index 731c33a..c89ee0b 100644 --- a/src/gclue-locator.c +++ b/src/gclue-locator.c @@ -332,29 +332,40 @@ gclue_locator_constructed (GObject *object) { GClueLocator *locator = GCLUE_LOCATOR (object); GClueLocationSource *submit_source = NULL; -#if GCLUE_USE_NMEA_SOURCE GClueConfig *gconfig = gclue_config_get_singleton (); -#endif + GClueWifi *wifi; GList *node; GClueMinUINT *threshold; G_OBJECT_CLASS (gclue_locator_parent_class)->constructed (object); #if GCLUE_USE_3G_SOURCE - GClue3G *source = gclue_3g_get_singleton (); - locator->priv->sources = g_list_append (locator->priv->sources, source); + if (gclue_config_get_enable_3g_source (gconfig)) { + GClue3G *source = gclue_3g_get_singleton (); + locator->priv->sources = g_list_append (locator->priv->sources, + source); + } #endif #if GCLUE_USE_CDMA_SOURCE - GClueCDMA *cdma = gclue_cdma_get_singleton (); - locator->priv->sources = g_list_append (locator->priv->sources, cdma); + if (gclue_config_get_enable_cdma_source (gconfig)) { + GClueCDMA *cdma = gclue_cdma_get_singleton (); + locator->priv->sources = g_list_append (locator->priv->sources, + cdma); + } #endif - GClueWifi *wifi = gclue_wifi_get_singleton (locator->priv->accuracy_level); - locator->priv->sources = g_list_append (locator->priv->sources, - wifi); + if (gclue_config_get_enable_wifi_source (gconfig)) + wifi = gclue_wifi_get_singleton (locator->priv->accuracy_level); + else + /* City-level accuracy will give us GeoIP-only source */ + wifi = gclue_wifi_get_singleton (GCLUE_ACCURACY_LEVEL_CITY); + locator->priv->sources = g_list_append (locator->priv->sources, wifi); #if GCLUE_USE_MODEM_GPS_SOURCE - GClueModemGPS *gps = gclue_modem_gps_get_singleton (); - locator->priv->sources = g_list_append (locator->priv->sources, gps); - submit_source = GCLUE_LOCATION_SOURCE (gps); + if (gclue_config_get_enable_modem_gps_source (gconfig)) { + GClueModemGPS *gps = gclue_modem_gps_get_singleton (); + locator->priv->sources = g_list_append (locator->priv->sources, + gps); + submit_source = GCLUE_LOCATION_SOURCE (gps); + } #endif #if GCLUE_USE_NMEA_SOURCE if (gclue_config_get_enable_nmea_source (gconfig)) { -- cgit v1.2.1