On successful connect store the network identifier
authorMarcel Holtmann <marcel@holtmann.org>
Fri, 4 Apr 2008 04:14:31 +0000 (06:14 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 4 Apr 2008 04:14:31 +0000 (06:14 +0200)
src/connman.h
src/iface-storage.c
src/iface.c

index e8ca3e7..4232616 100644 (file)
@@ -79,6 +79,7 @@ char *__connman_iface_find_passphrase(struct connman_iface *iface,
                                                        const char *network);
 int __connman_iface_load(struct connman_iface *iface);
 int __connman_iface_store(struct connman_iface *iface);
+int __connman_iface_store_current_network(struct connman_iface *iface);
 
 const char *__connman_iface_type2string(enum connman_iface_type type);
 const char *__connman_iface_state2string(enum connman_iface_state state);
index 8d2895f..d73ef6a 100644 (file)
@@ -211,3 +211,50 @@ done:
 
        return 0;
 }
+
+int __connman_iface_store_current_network(struct connman_iface *iface)
+{
+       GKeyFile *keyfile;
+       gchar *pathname, *data = NULL;
+       gsize length;
+
+       DBG("iface %p", iface);
+
+       if (iface->identifier == NULL)
+               return -EIO;
+
+       pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR,
+                                                       iface->identifier);
+       if (pathname == NULL)
+               return -ENOMEM;
+
+       keyfile = g_key_file_new();
+
+       if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
+               goto update;
+
+       if (length > 0) {
+               if (g_key_file_load_from_data(keyfile, data, length,
+                               G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
+                       goto done;
+       }
+
+       g_free(data);
+
+update:
+       g_key_file_set_string(keyfile, GROUP_CONFIG,
+                               "LastNetwork", iface->network.identifier);
+
+       data = g_key_file_to_data(keyfile, &length, NULL);
+
+       g_file_set_contents(pathname, data, length, NULL);
+
+done:
+       g_free(data);
+
+       g_key_file_free(keyfile);
+
+       g_free(pathname);
+
+       return 0;
+}
index f5753d8..a1e136d 100644 (file)
@@ -306,6 +306,7 @@ void connman_iface_indicate_configured(struct connman_iface *iface)
        case CONNMAN_IFACE_STATE_CONFIGURE:
                iface->state = CONNMAN_IFACE_STATE_READY;
                state_changed(iface);
+               __connman_iface_store_current_network(iface);
                break;
        default:
                break;