libnm-glib: add function nm_remote_settings_get_connection_by_id()

Utility function, to search the list of connections for a connection
with a matching id/name. Returns the first match.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-01-03 23:49:29 +01:00 committed by Dan Winship
parent 36ed2e91bb
commit f76934de15
3 changed files with 43 additions and 0 deletions

View file

@ -255,6 +255,7 @@ global:
nm_remote_settings_add_connection_unsaved;
nm_remote_settings_error_get_type;
nm_remote_settings_error_quark;
nm_remote_settings_get_connection_by_id;
nm_remote_settings_get_connection_by_path;
nm_remote_settings_get_connection_by_uuid;
nm_remote_settings_get_type;

View file

@ -173,6 +173,45 @@ add_connection_info_complete (NMRemoteSettings *self,
add_connection_info_dispose (self, info);
}
/**
* nm_remote_settings_get_connection_by_id:
* @settings: the %NMRemoteSettings
* @id: the id of the remote connection
*
* Returns the first matching %NMRemoteConnection matching a given @id.
*
* Returns: (transfer none): the remote connection object on success, or %NULL if no
* matching object was found.
*
* Since: 0.9.10
**/
NMRemoteConnection *
nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char *id)
{
NMRemoteSettingsPrivate *priv;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
g_return_val_if_fail (id != NULL, NULL);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
_nm_remote_settings_ensure_inited (settings);
if (priv->service_running) {
GHashTableIter iter;
NMConnection *candidate;
g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &candidate)) {
if (!strcmp (id, nm_connection_get_id (candidate)))
return NM_REMOTE_CONNECTION (candidate);
}
}
return NULL;
}
/**
* nm_remote_settings_get_connection_by_path:
* @settings: the %NMRemoteSettings

View file

@ -124,6 +124,9 @@ NMRemoteSettings *nm_remote_settings_new_finish (GAsyncResult *result,
GSList *nm_remote_settings_list_connections (NMRemoteSettings *settings);
NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings,
const char *id);
NMRemoteConnection * nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings,
const char *path);