mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 11:20:07 +01:00
clients: merge nm_secret_agent_simple_set_connection_path() into nm_secret_agent_simple_enable()
set_connection_path() is almost always called right before enable(), and it's unclear why it would be called anywhere else. So just merge the two methods.
This commit is contained in:
parent
a1f746351a
commit
88c9c6a6ac
6 changed files with 25 additions and 40 deletions
|
|
@ -147,7 +147,7 @@ do_agent_secret (NmCli *nmc, int argc, char **argv)
|
|||
/* We keep running */
|
||||
nmc->should_wait = TRUE;
|
||||
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), NULL);
|
||||
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
|
||||
g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1768,10 +1768,9 @@ active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpoin
|
|||
|
||||
if (nmc->secret_agent) {
|
||||
NMRemoteConnection *connection = nm_active_connection_get_connection (active);
|
||||
const gchar *path = nm_connection_get_path (NM_CONNECTION (connection));
|
||||
|
||||
nm_secret_agent_simple_set_connection_path (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), path);
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
|
||||
nm_connection_get_path (NM_CONNECTION (connection)));
|
||||
}
|
||||
|
||||
devices = nm_active_connection_get_devices (active);
|
||||
|
|
@ -2092,10 +2091,8 @@ nmc_activate_connection (NmCli *nmc,
|
|||
if (nmc->secret_agent) {
|
||||
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (nmc_secrets_requested), nmc);
|
||||
if (connection) {
|
||||
const gchar *path = nm_object_get_path (NM_OBJECT (connection));
|
||||
|
||||
nm_secret_agent_simple_set_connection_path (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), path);
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1520,10 +1520,9 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
|
|||
} else {
|
||||
if (nmc->secret_agent) {
|
||||
NMRemoteConnection *connection = nm_active_connection_get_connection (active);
|
||||
const char *path = nm_connection_get_path (NM_CONNECTION (connection));
|
||||
|
||||
nm_secret_agent_simple_set_connection_path (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), path);
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
|
||||
nm_connection_get_path (NM_CONNECTION (connection)));
|
||||
}
|
||||
|
||||
g_object_ref (device);
|
||||
|
|
|
|||
|
|
@ -582,35 +582,28 @@ nm_secret_agent_simple_delete_secrets (NMSecretAgent *agent,
|
|||
callback (agent, connection, NULL, callback_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_secret_agent_simple_set_connection_path:
|
||||
* @self: the #NMSecretAgentSimple
|
||||
* @path: the path of the connection the agent handle secrets for
|
||||
*
|
||||
* Sets the path for a new #NMSecretAgentSimple.
|
||||
*/
|
||||
void
|
||||
nm_secret_agent_simple_set_connection_path (NMSecretAgentSimple *self, const char *path)
|
||||
{
|
||||
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
|
||||
|
||||
g_free (priv->path);
|
||||
priv->path = g_strdup (path);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_secret_agent_simple_enable:
|
||||
* @self: the #NMSecretAgentSimple
|
||||
* @path: (allow-none): the path of the connection (if any) to handle secrets
|
||||
* for. If %NULL, secrets for any connection will be handled.
|
||||
*
|
||||
* Enables servicing the requests including the already queued ones.
|
||||
* Enables servicing the requests including the already queued ones. If @path
|
||||
* is given, the agent will only handle requests for connections that match
|
||||
* @path.
|
||||
*/
|
||||
void
|
||||
nm_secret_agent_simple_enable (NMSecretAgentSimple *self)
|
||||
nm_secret_agent_simple_enable (NMSecretAgentSimple *self, const char *path)
|
||||
{
|
||||
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
|
||||
GList *requests, *iter;
|
||||
GError *error;
|
||||
|
||||
if (g_strcmp0 (path, priv->path) != 0) {
|
||||
g_free (priv->path);
|
||||
priv->path = g_strdup (path);
|
||||
}
|
||||
|
||||
if (priv->enabled)
|
||||
return;
|
||||
priv->enabled = TRUE;
|
||||
|
|
@ -627,7 +620,7 @@ nm_secret_agent_simple_enable (NMSecretAgentSimple *self)
|
|||
error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED,
|
||||
"Request for %s secrets doesn't match path %s",
|
||||
request->request_id, priv->path);
|
||||
request->callback (agent, request->connection, NULL, error, request->callback_data);
|
||||
request->callback (NM_SECRET_AGENT (self), request->connection, NULL, error, request->callback_data);
|
||||
g_hash_table_remove (priv->requests, request->request_id);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
|
@ -697,6 +690,6 @@ NMSecretAgent *
|
|||
nm_secret_agent_simple_new (const char *name)
|
||||
{
|
||||
return g_initable_new (NM_TYPE_SECRET_AGENT_SIMPLE, NULL, NULL,
|
||||
NM_SECRET_AGENT_OLD_IDENTIFIER, name,
|
||||
NM_SECRET_AGENT_IDENTIFIER, name,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,9 +53,8 @@ void nm_secret_agent_simple_response (NMSecretAgentSimple *
|
|||
const char *request_id,
|
||||
GPtrArray *secrets);
|
||||
|
||||
void nm_secret_agent_simple_set_connection_path (NMSecretAgentSimple *self,
|
||||
void nm_secret_agent_simple_enable (NMSecretAgentSimple *self,
|
||||
const char *path);
|
||||
void nm_secret_agent_simple_enable (NMSecretAgentSimple *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -148,9 +148,8 @@ activate_connection (NMConnection *connection,
|
|||
agent = nm_secret_agent_simple_new ("nmtui");
|
||||
if (agent) {
|
||||
if (connection) {
|
||||
nm_secret_agent_simple_set_connection_path (NM_SECRET_AGENT_SIMPLE (agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
}
|
||||
g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL);
|
||||
}
|
||||
|
|
@ -192,10 +191,8 @@ activate_connection (NMConnection *connection,
|
|||
if (!connection) {
|
||||
connection = NM_CONNECTION (nm_active_connection_get_connection (ac));
|
||||
if (connection) {
|
||||
const gchar *path = nm_object_get_path (NM_OBJECT (connection));
|
||||
|
||||
nm_secret_agent_simple_set_connection_path (NM_SECRET_AGENT_SIMPLE (agent), path);
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent));
|
||||
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
|
||||
nm_object_get_path (NM_OBJECT (connection)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue