mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 04:48:10 +02:00
core: rework passing user-data to nm_active_connection_authorize()
Previously, nm_active_connection_authorize() accepts two user-data pointers for convenience. nm_active_connection_authorize() has three callers. One only requires one user-data, one passes two user-data pointers, and one requires three pointer. Also, the way how the third passes the user data (via g_object_set_qdata_full()) is not great. Let's only use one user-data pointer. We commonly do that, and it's easy enough to allocate a buffer to pack multiple pointers together.
This commit is contained in:
parent
dc138da420
commit
9abe3dc1a4
3 changed files with 28 additions and 48 deletions
|
|
@ -67,8 +67,7 @@ typedef struct _NMActiveConnectionPrivate {
|
||||||
NMAuthManagerCallId *call_id_wifi_shared_permission;
|
NMAuthManagerCallId *call_id_wifi_shared_permission;
|
||||||
|
|
||||||
NMActiveConnectionAuthResultFunc result_func;
|
NMActiveConnectionAuthResultFunc result_func;
|
||||||
gpointer user_data1;
|
gpointer user_data;
|
||||||
gpointer user_data2;
|
|
||||||
} auth;
|
} auth;
|
||||||
|
|
||||||
} NMActiveConnectionPrivate;
|
} NMActiveConnectionPrivate;
|
||||||
|
|
@ -999,8 +998,7 @@ auth_cancel (NMActiveConnection *self)
|
||||||
nm_auth_manager_check_authorization_cancel (priv->auth.call_id_wifi_shared_permission);
|
nm_auth_manager_check_authorization_cancel (priv->auth.call_id_wifi_shared_permission);
|
||||||
}
|
}
|
||||||
priv->auth.result_func = NULL;
|
priv->auth.result_func = NULL;
|
||||||
priv->auth.user_data1 = NULL;
|
priv->auth.user_data = NULL;
|
||||||
priv->auth.user_data2 = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1012,8 +1010,7 @@ auth_complete (NMActiveConnection *self, gboolean result, const char *message)
|
||||||
priv->auth.result_func (self,
|
priv->auth.result_func (self,
|
||||||
result,
|
result,
|
||||||
message,
|
message,
|
||||||
priv->auth.user_data1,
|
priv->auth.user_data);
|
||||||
priv->auth.user_data2);
|
|
||||||
auth_cancel (self);
|
auth_cancel (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1082,8 +1079,7 @@ auth_done (NMAuthManager *auth_mgr,
|
||||||
* is no @settings_connection available when creating the active connection.
|
* is no @settings_connection available when creating the active connection.
|
||||||
* Instead pass an alternative connection.
|
* Instead pass an alternative connection.
|
||||||
* @result_func: function to be called on success or error
|
* @result_func: function to be called on success or error
|
||||||
* @user_data1: pointer passed to @result_func
|
* @user_data: pointer passed to @result_func
|
||||||
* @user_data2: additional pointer passed to @result_func
|
|
||||||
*
|
*
|
||||||
* Checks whether the subject that initiated the active connection (read from
|
* Checks whether the subject that initiated the active connection (read from
|
||||||
* the #NMActiveConnection::subject property) is authorized to complete this
|
* the #NMActiveConnection::subject property) is authorized to complete this
|
||||||
|
|
@ -1093,8 +1089,7 @@ void
|
||||||
nm_active_connection_authorize (NMActiveConnection *self,
|
nm_active_connection_authorize (NMActiveConnection *self,
|
||||||
NMConnection *initial_connection,
|
NMConnection *initial_connection,
|
||||||
NMActiveConnectionAuthResultFunc result_func,
|
NMActiveConnectionAuthResultFunc result_func,
|
||||||
gpointer user_data1,
|
gpointer user_data)
|
||||||
gpointer user_data2)
|
|
||||||
{
|
{
|
||||||
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
|
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
|
||||||
const char *wifi_permission = NULL;
|
const char *wifi_permission = NULL;
|
||||||
|
|
@ -1133,10 +1128,8 @@ nm_active_connection_authorize (NMActiveConnection *self,
|
||||||
self);
|
self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for authorization */
|
|
||||||
priv->auth.result_func = result_func;
|
priv->auth.result_func = result_func;
|
||||||
priv->auth.user_data1 = user_data1;
|
priv->auth.user_data = user_data;
|
||||||
priv->auth.user_data2 = user_data2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -109,14 +109,12 @@ GType nm_active_connection_get_type (void);
|
||||||
typedef void (*NMActiveConnectionAuthResultFunc) (NMActiveConnection *self,
|
typedef void (*NMActiveConnectionAuthResultFunc) (NMActiveConnection *self,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
const char *error_desc,
|
const char *error_desc,
|
||||||
gpointer user_data1,
|
gpointer user_data);
|
||||||
gpointer user_data2);
|
|
||||||
|
|
||||||
void nm_active_connection_authorize (NMActiveConnection *self,
|
void nm_active_connection_authorize (NMActiveConnection *self,
|
||||||
NMConnection *initial_connection,
|
NMConnection *initial_connection,
|
||||||
NMActiveConnectionAuthResultFunc result_func,
|
NMActiveConnectionAuthResultFunc result_func,
|
||||||
gpointer user_data1,
|
gpointer user_data);
|
||||||
gpointer user_data2);
|
|
||||||
|
|
||||||
NMSettingsConnection *nm_active_connection_get_settings_connection (NMActiveConnection *self);
|
NMSettingsConnection *nm_active_connection_get_settings_connection (NMActiveConnection *self);
|
||||||
NMConnection *nm_active_connection_get_applied_connection (NMActiveConnection *self);
|
NMConnection *nm_active_connection_get_applied_connection (NMActiveConnection *self);
|
||||||
|
|
|
||||||
|
|
@ -333,8 +333,6 @@ static NMConnectivity *concheck_get_mgr (NMManager *self);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static NM_CACHED_QUARK_FCN ("active-connection-add-and-activate", active_connection_add_and_activate_quark)
|
|
||||||
|
|
||||||
static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
|
static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
@ -4100,11 +4098,10 @@ static void
|
||||||
_internal_activation_auth_done (NMActiveConnection *active,
|
_internal_activation_auth_done (NMActiveConnection *active,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
const char *error_desc,
|
const char *error_desc,
|
||||||
gpointer user_data1,
|
gpointer user_data)
|
||||||
gpointer user_data2)
|
|
||||||
{
|
{
|
||||||
_nm_unused gs_unref_object NMActiveConnection *active_to_free = active;
|
_nm_unused gs_unref_object NMActiveConnection *active_to_free = active;
|
||||||
NMManager *self = user_data1;
|
NMManager *self = user_data;
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
||||||
NMActiveConnection *ac;
|
NMActiveConnection *ac;
|
||||||
gs_free_error GError *error = NULL;
|
gs_free_error GError *error = NULL;
|
||||||
|
|
@ -4232,7 +4229,7 @@ nm_manager_activate_connection (NMManager *self,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
priv->authorizing_connections = g_slist_prepend (priv->authorizing_connections, active);
|
priv->authorizing_connections = g_slist_prepend (priv->authorizing_connections, active);
|
||||||
nm_active_connection_authorize (active, NULL, _internal_activation_auth_done, self, NULL);
|
nm_active_connection_authorize (active, NULL, _internal_activation_auth_done, self);
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4365,16 +4362,17 @@ static void
|
||||||
_activation_auth_done (NMActiveConnection *active,
|
_activation_auth_done (NMActiveConnection *active,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
const char *error_desc,
|
const char *error_desc,
|
||||||
gpointer user_data1,
|
gpointer user_data)
|
||||||
gpointer user_data2)
|
|
||||||
{
|
{
|
||||||
NMManager *self = user_data1;
|
NMManager *self;
|
||||||
GDBusMethodInvocation *context = user_data2;
|
GDBusMethodInvocation *context;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
NMAuthSubject *subject;
|
NMAuthSubject *subject;
|
||||||
NMSettingsConnection *connection;
|
NMSettingsConnection *connection;
|
||||||
_nm_unused gs_unref_object NMActiveConnection *active_free = active;
|
_nm_unused gs_unref_object NMActiveConnection *active_free = active;
|
||||||
|
|
||||||
|
nm_utils_user_data_pack (user_data, &self, &context);
|
||||||
|
|
||||||
subject = nm_active_connection_get_subject (active);
|
subject = nm_active_connection_get_subject (active);
|
||||||
connection = nm_active_connection_get_settings_connection (active);
|
connection = nm_active_connection_get_settings_connection (active);
|
||||||
|
|
||||||
|
|
@ -4496,8 +4494,7 @@ impl_manager_activate_connection (NMDBusObject *obj,
|
||||||
nm_active_connection_authorize (g_steal_pointer (&active),
|
nm_active_connection_authorize (g_steal_pointer (&active),
|
||||||
NULL,
|
NULL,
|
||||||
_activation_auth_done,
|
_activation_auth_done,
|
||||||
self,
|
nm_utils_user_data_pack (self, invocation));
|
||||||
invocation);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
@ -4578,18 +4575,16 @@ static void
|
||||||
_add_and_activate_auth_done (NMActiveConnection *active,
|
_add_and_activate_auth_done (NMActiveConnection *active,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
const char *error_desc,
|
const char *error_desc,
|
||||||
gpointer user_data1,
|
gpointer user_data)
|
||||||
gpointer user_data2)
|
|
||||||
{
|
{
|
||||||
NMManager *self = user_data1;
|
NMManager *self;
|
||||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
|
NMManagerPrivate *priv;
|
||||||
GDBusMethodInvocation *context = user_data2;
|
GDBusMethodInvocation *context;
|
||||||
|
gs_unref_object NMConnection *connection = NULL;
|
||||||
AddAndActivateInfo *info;
|
AddAndActivateInfo *info;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gs_unref_object NMConnection *connection = NULL;
|
|
||||||
|
|
||||||
connection = g_object_steal_qdata (G_OBJECT (active),
|
nm_utils_user_data_unpack (user_data, &self, &context, &connection);
|
||||||
active_connection_add_and_activate_quark ());
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
error = g_error_new_literal (NM_MANAGER_ERROR,
|
error = g_error_new_literal (NM_MANAGER_ERROR,
|
||||||
|
|
@ -4606,6 +4601,8 @@ _add_and_activate_auth_done (NMActiveConnection *active,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv = NM_MANAGER_GET_PRIVATE (self);
|
||||||
|
|
||||||
info = g_slice_new (AddAndActivateInfo);
|
info = g_slice_new (AddAndActivateInfo);
|
||||||
info->manager = self;
|
info->manager = self;
|
||||||
|
|
||||||
|
|
@ -4709,17 +4706,9 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
|
||||||
if (!active)
|
if (!active)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* FIXME: nm_active_connection_authorize() already has two user-data pointers
|
nm_active_connection_authorize (active, connection,
|
||||||
* to piggyback additional data. Instead of attaching the third argument to
|
_add_and_activate_auth_done,
|
||||||
* @active's user-data, add a third paramter.
|
nm_utils_user_data_pack (self, invocation, connection));
|
||||||
* Or alternatively, allocate a data structure to pass on additional data.
|
|
||||||
* Then we don't need two user-data pointers. */
|
|
||||||
g_object_set_qdata_full (G_OBJECT (active),
|
|
||||||
active_connection_add_and_activate_quark (),
|
|
||||||
connection,
|
|
||||||
g_object_unref);
|
|
||||||
|
|
||||||
nm_active_connection_authorize (active, connection, _add_and_activate_auth_done, self, invocation);
|
|
||||||
|
|
||||||
/* we passed the pointers on to the callback of authorize. */
|
/* we passed the pointers on to the callback of authorize. */
|
||||||
g_steal_pointer (&connection);
|
g_steal_pointer (&connection);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue