network-manager-applet r568 - in trunk: . src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r568 - in trunk: . src
- Date: Thu, 28 Feb 2008 21:39:31 +0000 (GMT)
Author: dcbw
Date: Thu Feb 28 21:39:31 2008
New Revision: 568
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=568&view=rev
Log:
2008-02-28 Dan Williams <dcbw redhat com>
* src/applet-dbus-settings.c
- (applet_dbus_settings_user_get_by_dbus_path): don't segfault on
bad path
- (applet_dbus_settings_get_by_gconf_path): don't segfault on bad path
- (applet_exported_connection_new): don't leak a connection; the
g_object_new() will reference the connection
* src/applet-device-wired.c
- (add_default_wired_connection): don't leak a connection; exporting
the connection references it
* src/applet.c
- (applet_menu_item_activate_helper): don't leak a connection; exporting
the connection references it
* src/applet-device-wireless.c
- (wireless_dialog_response_cb): find a compatible exported connection
before creating a new one; don't leak connections either, and be
sure to reference any connection passed to nma_wireless_dialog_new()
since it will get unreffed on the dialog response.
Modified:
trunk/ChangeLog
trunk/src/applet-dbus-settings.c
trunk/src/applet-device-wired.c
trunk/src/applet-device-wireless.c
trunk/src/applet.c
Modified: trunk/src/applet-dbus-settings.c
==============================================================================
--- trunk/src/applet-dbus-settings.c (original)
+++ trunk/src/applet-dbus-settings.c Thu Feb 28 21:39:31 2008
@@ -535,6 +535,11 @@
connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (exported));
sc_path = nm_connection_get_path (connection);
+ if (!sc_path) {
+ g_warning ("%s: connection in exported list didn't have a D-Bus path.", __func__);
+ continue;
+ }
+
if (!strcmp (sc_path, path))
return exported;
}
@@ -615,8 +620,10 @@
for (elt = applet_settings->connections; elt; elt = g_slist_next (elt)) {
AppletExportedConnection *exported = APPLET_EXPORTED_CONNECTION (elt->data);
+ const char *gconf_path;
- if (!strcmp (applet_exported_connection_get_gconf_path (exported), path))
+ gconf_path = applet_exported_connection_get_gconf_path (exported);
+ if (gconf_path && !strcmp (gconf_path, path))
return exported;
}
@@ -929,7 +936,7 @@
{
AppletExportedConnection *exported;
AppletDBusManager *manager;
- NMConnection *gconf_connection;
+ NMConnection *gconf_connection = NULL;
g_return_val_if_fail (conf_client != NULL, NULL);
g_return_val_if_fail (conf_dir != NULL, NULL);
@@ -952,7 +959,7 @@
utils_clear_filled_connection_certs (gconf_connection);
g_warning ("Invalid connection read from GConf at %s.", conf_dir);
g_object_unref (exported);
- return NULL;
+ goto out;
}
utils_clear_filled_connection_certs (gconf_connection);
@@ -964,6 +971,8 @@
applet_dbus_manager_get_connection (manager));
g_object_unref (manager);
+out:
+ g_object_unref (gconf_connection);
return exported;
}
Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c (original)
+++ trunk/src/applet-device-wired.c Thu Feb 28 21:39:31 2008
@@ -267,6 +267,7 @@
nm_connection_add_setting (connection, (NMSetting *) s_con);
applet_dbus_settings_user_add_connection (settings, connection);
+ g_object_unref (connection);
}
NMADeviceClass *
Modified: trunk/src/applet-device-wireless.c
==============================================================================
--- trunk/src/applet-device-wireless.c (original)
+++ trunk/src/applet-device-wireless.c Thu Feb 28 21:39:31 2008
@@ -1067,10 +1067,9 @@
gpointer user_data)
{
NMApplet *applet = NM_APPLET (user_data);
- NMConnection *connection = NULL;
+ NMConnection *connection = NULL, *fuzzy_match = NULL;
NMDevice *device = NULL;
NMAccessPoint *ap = NULL;
- NMSettingConnection *s_con;
AppletExportedConnection *exported = NULL;
gboolean ignored = FALSE;
@@ -1097,35 +1096,74 @@
connection = nma_wireless_dialog_get_connection (GTK_WIDGET (dialog), &device, &ap);
g_assert (connection);
g_assert (device);
- // FIXME: find a compatible connection in the current connection list before adding
- // a new connection
-
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
- if (!s_con->id) {
- NMSettingWireless *s_wireless;
- char *ssid;
-
- s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
- ssid = nm_utils_ssid_to_utf8 ((const char *) s_wireless->ssid->data, s_wireless->ssid->len);
- s_con->id = g_strdup_printf ("Auto %s", ssid);
- g_free (ssid);
-
- // FIXME: don't autoconnect until the connection is successful at least once
- /* Don't autoconnect adhoc networks by default for now */
- if (!s_wireless->mode || !strcmp (s_wireless->mode, "infrastructure"))
- s_con->autoconnect = TRUE;
- }
exported = applet_dbus_settings_user_get_by_connection (applet->settings, connection);
- if (!exported) {
- exported = applet_dbus_settings_user_add_connection (applet->settings, connection);
- if (!exported) {
- nm_warning ("Couldn't create other network connection.");
- goto done;
- }
- } else {
- /* Save the updated settings to GConf */
+ if (exported) {
+ /* Not a new or system connection, save the updated settings to GConf */
applet_exported_connection_save (exported);
+ } else {
+ GSList *all, *iter;
+
+ /* Find a similar connection and use that instead */
+ all = applet_dbus_settings_get_all_connections (applet->settings);
+ for (iter = all; iter; iter = g_slist_next (iter)) {
+ if (nm_connection_compare (connection,
+ NM_CONNECTION (iter->data),
+ (COMPARE_FLAGS_FUZZY | COMPARE_FLAGS_IGNORE_ID))) {
+ fuzzy_match = g_object_ref (NM_CONNECTION (iter->data));
+ break;
+ }
+ }
+ g_slist_free (all);
+
+ if (fuzzy_match) {
+ if (nm_connection_get_scope (fuzzy_match) == NM_CONNECTION_SCOPE_SYSTEM) {
+ // FIXME: do something other than just use the system connection?
+ } else {
+ NMSettingWirelessSecurity *s_wireless_sec;
+
+ /* Copy secrets & wireless security */
+ s_wireless_sec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
+ if (s_wireless_sec) {
+ GHashTable *hash;
+ NMSetting *dup_setting;
+
+ hash = nm_setting_to_hash (NM_SETTING (s_wireless_sec));
+ dup_setting = nm_setting_from_hash (NM_TYPE_SETTING_WIRELESS_SECURITY, hash);
+ g_hash_table_destroy (hash);
+ nm_connection_add_setting (fuzzy_match, dup_setting);
+ }
+ }
+
+ /* Balance the caller of wireless_dialog_new () */
+ g_object_unref (connection);
+
+ connection = g_object_ref (fuzzy_match);
+ } else {
+ /* Entirely new connection */
+ NMSettingConnection *s_con;
+
+ /* Update a new connection's name and autoconnect status */
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ if (!s_con->id) {
+ NMSettingWireless *s_wireless;
+
+ s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
+ s_con->id = nm_utils_ssid_to_utf8 ((const char *) s_wireless->ssid->data, s_wireless->ssid->len);
+
+ // FIXME: don't autoconnect until the connection is successful at least once
+ /* Don't autoconnect adhoc networks by default for now */
+ if (!s_wireless->mode || !strcmp (s_wireless->mode, "infrastructure"))
+ s_con->autoconnect = TRUE;
+ }
+
+ /* Export it over D-Bus */
+ exported = applet_dbus_settings_user_add_connection (applet->settings, connection);
+ if (!exported) {
+ nm_warning ("Couldn't create other network connection.");
+ goto done;
+ }
+ }
}
nm_client_activate_device (applet->nm_client,
@@ -1137,6 +1175,10 @@
applet);
done:
+ /* Balance the caller of wireless_dialog_new () */
+ if (connection)
+ g_object_unref (connection);
+
gtk_widget_hide (GTK_WIDGET (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
}
@@ -1152,7 +1194,7 @@
dialog = nma_wireless_dialog_new (applet->glade_file,
applet->nm_client,
- connection,
+ g_object_ref (connection),
device,
info->ap,
FALSE);
@@ -1286,7 +1328,7 @@
dialog = nma_wireless_dialog_new (applet->glade_file,
applet->nm_client,
- connection,
+ g_object_ref (connection),
device,
ap,
FALSE);
Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c (original)
+++ trunk/src/applet.c Thu Feb 28 21:39:31 2008
@@ -163,13 +163,14 @@
*/
nm_warning ("Invalid connection; asking for more information.");
- if (dclass->get_more_info) {
+ if (dclass->get_more_info)
dclass->get_more_info (device, connection, applet, user_data);
- }
+ g_object_unref (connection);
return;
}
con_path = (char *) nm_connection_get_path (connection);
+ g_object_unref (connection);
}
g_assert (con_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]