settings: add nm_settings_get_connection_by_uuid()

This commit is contained in:
Dan Williams 2012-01-13 17:20:06 -06:00
parent c50def68ff
commit 0a18078b73
2 changed files with 33 additions and 17 deletions

View file

@ -228,36 +228,49 @@ impl_settings_list_connections (NMSettings *self,
return TRUE;
}
NMSettingsConnection *
nm_settings_get_connection_by_uuid (NMSettings *self, const char *uuid)
{
NMSettingsPrivate *priv;
NMSettingsConnection *candidate;
GHashTableIter iter;
g_return_val_if_fail (self != NULL, NULL);
g_return_val_if_fail (NM_IS_SETTINGS (self), NULL);
g_return_val_if_fail (uuid != NULL, NULL);
priv = NM_SETTINGS_GET_PRIVATE (self);
load_connections (self);
g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) {
if (g_strcmp0 (uuid, nm_connection_get_uuid (NM_CONNECTION (candidate))) == 0)
return candidate;
}
return NULL;
}
static gboolean
impl_settings_get_connection_by_uuid (NMSettings *self,
const char *uuid,
char **out_object_path,
GError **error)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GHashTableIter iter;
NMConnection *candidate = NULL;
gboolean found = FALSE;
NMSettingsConnection *connection = NULL;
load_connections (self);
g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) {
if (g_strcmp0 (uuid, nm_connection_get_uuid (candidate)) == 0) {
*out_object_path = g_strdup (nm_connection_get_path (candidate));
found = TRUE;
break;
}
}
if (!found) {
connection = nm_settings_get_connection_by_uuid (self, uuid);
if (connection)
*out_object_path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
else {
g_set_error_literal (error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_INVALID_CONNECTION,
"No connection with the UUID was found.");
}
return found;
return !!connection;
}
static int

View file

@ -108,6 +108,9 @@ GSList *nm_settings_get_connections (NMSettings *settings);
NMSettingsConnection *nm_settings_get_connection_by_path (NMSettings *settings,
const char *path);
NMSettingsConnection *nm_settings_get_connection_by_uuid (NMSettings *settings,
const char *uuid);
const GSList *nm_settings_get_unmanaged_specs (NMSettings *self);
char *nm_settings_get_hostname (NMSettings *self);