From 88c9c6a6acc0083d8b718a4878d85f21ea62dcb3 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 20 Nov 2014 16:00:34 -0600 Subject: 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. --- clients/cli/agent.c | 2 +- clients/cli/connections.c | 11 ++++------- clients/cli/devices.c | 5 ++--- clients/common/nm-secret-agent-simple.c | 33 +++++++++++++-------------------- clients/common/nm-secret-agent-simple.h | 3 +-- clients/tui/nmtui-connect.c | 11 ++++------- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/clients/cli/agent.c b/clients/cli/agent.c index 2a5a81e5a3..1695ed5961 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -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 { diff --git a/clients/cli/connections.c b/clients/cli/connections.c index dafb097f8c..70f20e7f6e 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -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))); } } diff --git a/clients/cli/devices.c b/clients/cli/devices.c index b5b04dc3ad..9c64c880d1 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -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); diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index cdfecfb473..fbc37436ce 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -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); } diff --git a/clients/common/nm-secret-agent-simple.h b/clients/common/nm-secret-agent-simple.h index a987dc28cc..a55bbe662f 100644 --- a/clients/common/nm-secret-agent-simple.h +++ b/clients/common/nm-secret-agent-simple.h @@ -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 diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c index d894828768..1c89114552 100644 --- a/clients/tui/nmtui-connect.c +++ b/clients/tui/nmtui-connect.c @@ -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))); } } -- cgit v1.2.1