service: Add flag that tells if the service is hidden or not
[framework/connectivity/connman.git] / src / config.c
index b2b7904..781427d 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
@@ -377,12 +378,12 @@ static int load_config(struct connman_config *config)
        gsize length;
        char **groups;
        char *str;
-       gboolean protected;
+       gboolean protected, found = FALSE;
        int i;
 
        DBG("config %p", config);
 
-       keyfile = __connman_storage_open_config(config->ident);
+       keyfile = __connman_storage_load_config(config->ident);
        if (keyfile == NULL)
                return -EIO;
 
@@ -411,13 +412,20 @@ static int load_config(struct connman_config *config)
        groups = g_key_file_get_groups(keyfile, &length);
 
        for (i = 0; groups[i] != NULL; i++) {
-               if (g_str_has_prefix(groups[i], "service_") == TRUE)
-                       load_service(keyfile, groups[i], config);
+               if (g_str_has_prefix(groups[i], "service_") == TRUE) {
+                       if (load_service(keyfile, groups[i], config) == 0)
+                               found = TRUE;
+               }
        }
 
+       if (found == FALSE)
+               connman_warn("Config file %s/%s.config does not contain any "
+                       "configuration that can be provisioned!",
+                       STORAGEDIR, config->ident);
+
        g_strfreev(groups);
 
-       __connman_storage_close_config(config->ident, keyfile, FALSE);
+       g_key_file_free(keyfile);
 
        return 0;
 }
@@ -452,7 +460,7 @@ int __connman_config_load_service(GKeyFile *keyfile, const char *group,
 {
        struct connman_config *config;
        const char *service_name;
-       char *ident, *filename = NULL, *content = NULL;
+       char *ident, *content = NULL;
        gsize content_length;
        int err;
 
@@ -490,26 +498,15 @@ int __connman_config_load_service(GKeyFile *keyfile, const char *group,
                goto out;
        }
 
-       filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
-       if (filename == NULL) {
-               err = -ENOMEM;
-               goto out;
-       }
-
        DBG("Saving %zu bytes to %s", content_length, service_name);
 
-       if (g_file_set_contents(filename, content,
-                               content_length, NULL) == FALSE) {
-               err = -EIO;
-               goto out;
-       }
+       __connman_storage_save_config(keyfile, ident);
 
        return 0;
 
 out:
        g_free(ident);
        g_free(content);
-       g_free(filename);
 
        return err;
 }
@@ -650,6 +647,7 @@ static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
                        if (config != NULL) {
                                g_hash_table_remove_all(config->service_table);
                                load_config(config);
+                               __connman_service_provision_changed(ident);
                        }
                }
 
@@ -869,3 +867,24 @@ int __connman_config_provision_service(struct connman_service *service)
 
        return 0;
 }
+
+int __connman_config_provision_service_ident(struct connman_service *service,
+                                                       const char *ident)
+{
+       enum connman_service_type type;
+       struct connman_config *config;
+
+       DBG("service %p", service);
+
+       /* For now only WiFi services are supported */
+       type = connman_service_get_type(service);
+       if (type != CONNMAN_SERVICE_TYPE_WIFI)
+               return -ENOSYS;
+
+       config = g_hash_table_lookup(config_table, ident);
+       if(config != NULL)
+               g_hash_table_foreach(config->service_table,
+                                               provision_service, service);
+
+       return 0;
+}