config: Check individual service entries for removal
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Tue, 5 Jun 2012 08:24:16 +0000 (11:24 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 11 Jun 2012 10:04:54 +0000 (13:04 +0300)
Check if we need to remove a service if user removes
an entry from config file.
If user changes entry name in config file, then we
remove the service and then try to provision the service
again because the SSID might still be found.

src/config.c

index c3024c6..6af979d 100644 (file)
@@ -873,9 +873,45 @@ int __connman_config_provision_service_ident(struct connman_service *service,
                return -ENOSYS;
 
        config = g_hash_table_lookup(config_table, ident);
-       if(config != NULL)
+       if(config != NULL) {
+               GHashTableIter iter;
+               gpointer value, key;
+               gboolean found = FALSE;
+
+               g_hash_table_iter_init(&iter, config->service_table);
+
+               /*
+                * Check if we need to remove individual service if it
+                * is missing from config file.
+                */
+               if (file != NULL && entry != NULL) {
+                       while (g_hash_table_iter_next(&iter, &key,
+                                                       &value) == TRUE) {
+                               struct connman_config_service *config = value;
+
+                               if (g_strcmp0(config->config_ident,
+                                                               file) == 0 &&
+                                               g_strcmp0(config->config_entry,
+                                                               entry) == 0) {
+                                       found = TRUE;
+                                       break;
+                               }
+                       }
+
+                       DBG("found %d ident %s file %s entry %s", found, ident,
+                                                               file, entry);
+
+                       if (found == FALSE)
+                               /*
+                                * The entry+8 will skip "service_" prefix
+                                */
+                               g_hash_table_remove(config->service_table,
+                                               entry + 8);
+               }
+
                g_hash_table_foreach(config->service_table,
                                                provision_service, service);
+       }
 
        return 0;
 }