mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 16:30:07 +01:00
settings: remove callback from nm_sysconfig_connection_get_secrets()
No reason it needs to use the callback pattern anymore.
This commit is contained in:
parent
e716e7507b
commit
ff101f4946
3 changed files with 53 additions and 123 deletions
|
|
@ -304,36 +304,6 @@ nm_sysconfig_connection_delete (NMSysconfigConnection *connection,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nm_sysconfig_connection_get_secrets (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
NMSysconfigConnectionGetSecretsFunc callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (NM_IS_SYSCONFIG_CONNECTION (connection));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
if (NM_SYSCONFIG_CONNECTION_GET_CLASS (connection)->get_secrets) {
|
||||
NM_SYSCONFIG_CONNECTION_GET_CLASS (connection)->get_secrets (connection,
|
||||
setting_name,
|
||||
hints,
|
||||
request_new,
|
||||
callback,
|
||||
user_data);
|
||||
} else {
|
||||
GError *error = g_error_new (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_INTERNAL_ERROR,
|
||||
"%s: %s:%d get_secrets() unimplemented", __func__, __FILE__, __LINE__);
|
||||
callback (connection, NULL, error, user_data);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
static void
|
||||
commit_changes (NMSysconfigConnection *connection,
|
||||
NMSysconfigConnectionCommitFunc callback,
|
||||
|
|
@ -357,6 +327,15 @@ do_delete (NMSysconfigConnection *connection,
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
|
||||
static gboolean
|
||||
supports_secrets (NMSysconfigConnection *connection, const char *setting_name)
|
||||
{
|
||||
/* All secrets supported */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
string_to_gvalue (const char *str)
|
||||
{
|
||||
|
|
@ -411,7 +390,7 @@ add_secrets (NMSetting *setting,
|
|||
if (tmp)
|
||||
g_hash_table_insert (secrets, g_strdup (key), string_to_gvalue (tmp));
|
||||
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) {
|
||||
/* Flatten the string hash by pulling its keys/values out */
|
||||
/* Flatten the string hash by pulling its keys/values out; for VPN secrets */
|
||||
g_hash_table_foreach (g_value_get_boxed (value), copy_one_secret, secrets);
|
||||
} else if (G_VALUE_TYPE (value) == DBUS_TYPE_G_UCHAR_ARRAY) {
|
||||
GByteArray *array;
|
||||
|
|
@ -431,19 +410,17 @@ destroy_gvalue (gpointer data)
|
|||
g_slice_free (GValue, value);
|
||||
}
|
||||
|
||||
static void
|
||||
get_secrets (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
NMSysconfigConnectionGetSecretsFunc callback,
|
||||
gpointer user_data)
|
||||
GHashTable *
|
||||
nm_sysconfig_connection_get_secrets (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
GError **error)
|
||||
{
|
||||
NMSysconfigConnectionPrivate *priv = NM_SYSCONFIG_CONNECTION_GET_PRIVATE (connection);
|
||||
GHashTable *settings = NULL;
|
||||
GHashTable *secrets = NULL;
|
||||
NMSetting *setting;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Use priv->secrets to work around the fact that nm_connection_clear_secrets()
|
||||
* will clear secrets on this object's settings. priv->secrets should be
|
||||
|
|
@ -451,24 +428,18 @@ get_secrets (NMSysconfigConnection *connection,
|
|||
* nm_sysconfig_connection_replace_settings().
|
||||
*/
|
||||
if (!priv->secrets) {
|
||||
error = g_error_new (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||
"%s.%d - Internal error; secrets cache invalid.",
|
||||
__FILE__, __LINE__);
|
||||
(*callback) (connection, NULL, error, user_data);
|
||||
g_error_free (error);
|
||||
return;
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||
"%s.%d - Internal error; secrets cache invalid.",
|
||||
__FILE__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
setting = nm_connection_get_setting_by_name (priv->secrets, setting_name);
|
||||
if (!setting) {
|
||||
error = g_error_new (NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_INVALID_SETTING,
|
||||
"%s.%d - Connection didn't have requested setting '%s'.",
|
||||
__FILE__, __LINE__, setting_name);
|
||||
(*callback) (connection, NULL, error, user_data);
|
||||
g_error_free (error);
|
||||
return;
|
||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_SETTING,
|
||||
"%s.%d - Connection didn't have requested setting '%s'.",
|
||||
__FILE__, __LINE__, setting_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
|
||||
|
|
@ -482,8 +453,8 @@ get_secrets (NMSysconfigConnection *connection,
|
|||
nm_setting_enumerate_values (setting, add_secrets, secrets);
|
||||
|
||||
g_hash_table_insert (settings, g_strdup (setting_name), secrets);
|
||||
callback (connection, settings, NULL, user_data);
|
||||
g_hash_table_destroy (settings);
|
||||
|
||||
return secrets;
|
||||
}
|
||||
|
||||
/**** User authorization **************************************/
|
||||
|
|
@ -774,20 +745,6 @@ typedef struct {
|
|||
gboolean request_new;
|
||||
} GetSecretsInfo;
|
||||
|
||||
static void
|
||||
con_secrets_cb (NMSysconfigConnection *connection,
|
||||
GHashTable *secrets,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
DBusGMethodInvocation *context = user_data;
|
||||
|
||||
if (error)
|
||||
dbus_g_method_return_error (context, error);
|
||||
else
|
||||
dbus_g_method_return (context, secrets);
|
||||
}
|
||||
|
||||
static void
|
||||
secrets_auth_cb (NMSysconfigConnection *self,
|
||||
DBusGMethodInvocation *context,
|
||||
|
|
@ -795,18 +752,26 @@ secrets_auth_cb (NMSysconfigConnection *self,
|
|||
gpointer data)
|
||||
{
|
||||
GetSecretsInfo *info = data;
|
||||
GHashTable *secrets;
|
||||
GError *local = NULL;
|
||||
|
||||
if (error) {
|
||||
dbus_g_method_return_error (context, error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
nm_sysconfig_connection_get_secrets (self,
|
||||
info->setting_name,
|
||||
(const char **) info->hints,
|
||||
info->request_new,
|
||||
con_secrets_cb,
|
||||
context);
|
||||
secrets = nm_sysconfig_connection_get_secrets (self,
|
||||
info->setting_name,
|
||||
(const char **) info->hints,
|
||||
info->request_new,
|
||||
&error);
|
||||
if (secrets) {
|
||||
dbus_g_method_return (context, secrets);
|
||||
g_hash_table_destroy (secrets);
|
||||
} else {
|
||||
dbus_g_method_return_error (context, local);
|
||||
g_clear_error (&local);
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (info->setting_name);
|
||||
|
|
@ -917,7 +882,7 @@ nm_sysconfig_connection_class_init (NMSysconfigConnectionClass *class)
|
|||
|
||||
class->commit_changes = commit_changes;
|
||||
class->delete = do_delete;
|
||||
class->get_secrets = get_secrets;
|
||||
class->supports_secrets = supports_secrets;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
|
|
|
|||
|
|
@ -50,11 +50,6 @@ typedef void (*NMSysconfigConnectionDeleteFunc) (NMSysconfigConnection *connecti
|
|||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
typedef void (*NMSysconfigConnectionGetSecretsFunc) (NMSysconfigConnection *connection,
|
||||
GHashTable *secrets,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
struct _NMSysconfigConnection {
|
||||
NMConnection parent;
|
||||
};
|
||||
|
|
@ -70,12 +65,8 @@ struct _NMSysconfigConnectionClass {
|
|||
NMSysconfigConnectionDeleteFunc callback,
|
||||
gpointer user_data);
|
||||
|
||||
void (*get_secrets) (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
NMSysconfigConnectionGetSecretsFunc callback,
|
||||
gpointer user_data);
|
||||
gboolean (*supports_secrets) (NMSysconfigConnection *connection,
|
||||
const char *setting_name);
|
||||
};
|
||||
|
||||
GType nm_sysconfig_connection_get_type (void);
|
||||
|
|
@ -97,12 +88,11 @@ void nm_sysconfig_connection_delete (NMSysconfigConnection *connection,
|
|||
NMSysconfigConnectionDeleteFunc callback,
|
||||
gpointer user_data);
|
||||
|
||||
void nm_sysconfig_connection_get_secrets (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
NMSysconfigConnectionGetSecretsFunc callback,
|
||||
gpointer user_data);
|
||||
GHashTable *nm_sysconfig_connection_get_secrets (NMSysconfigConnection *connection,
|
||||
const char *setting_name,
|
||||
const char **hints,
|
||||
gboolean request_new,
|
||||
GError **error);
|
||||
|
||||
gboolean nm_sysconfig_connection_is_visible (NMSysconfigConnection *self);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,37 +57,12 @@ nm_ifupdown_connection_new (if_block *block)
|
|||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
get_secrets (NMSysconfigConnection *connection,
|
||||
const gchar *setting_name,
|
||||
const gchar **hints,
|
||||
gboolean request_new,
|
||||
NMSysconfigConnectionGetSecretsFunc callback,
|
||||
gpointer user_data)
|
||||
static gboolean
|
||||
supports_secrets (NMSysconfigConnection *connection, const char *setting_name)
|
||||
{
|
||||
GError *error = NULL;
|
||||
PLUGIN_PRINT ("SCPlugin-Ifupdown", "supports_secrets() for setting_name: '%s'", setting_name);
|
||||
|
||||
PLUGIN_PRINT ("SCPlugin-Ifupdown", "get_secrets() for setting_name:'%s'", setting_name);
|
||||
|
||||
/* FIXME: Only wifi secrets are supported for now */
|
||||
if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) {
|
||||
g_set_error (&error,
|
||||
NM_SETTINGS_ERROR,
|
||||
NM_SETTINGS_ERROR_GENERAL,
|
||||
"%s.%d - security setting name not supported '%s'.",
|
||||
__FILE__, __LINE__, setting_name);
|
||||
PLUGIN_PRINT ("SCPlugin-Ifupdown", "%s", error->message);
|
||||
callback (connection, NULL, error, user_data);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
NM_SYSCONFIG_CONNECTION_CLASS (nm_ifupdown_connection_parent_class)->get_secrets (connection,
|
||||
setting_name,
|
||||
hints,
|
||||
request_new,
|
||||
callback,
|
||||
user_data);
|
||||
return (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -180,7 +155,7 @@ nm_ifupdown_connection_class_init (NMIfupdownConnectionClass *ifupdown_connectio
|
|||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
|
||||
connection_class->get_secrets = get_secrets;
|
||||
connection_class->supports_secrets = supports_secrets;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue