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:
Thomas Haller 2018-04-17 14:59:27 +02:00
parent dc138da420
commit 9abe3dc1a4
3 changed files with 28 additions and 48 deletions

View file

@ -67,8 +67,7 @@ typedef struct _NMActiveConnectionPrivate {
NMAuthManagerCallId *call_id_wifi_shared_permission;
NMActiveConnectionAuthResultFunc result_func;
gpointer user_data1;
gpointer user_data2;
gpointer user_data;
} auth;
} NMActiveConnectionPrivate;
@ -999,8 +998,7 @@ auth_cancel (NMActiveConnection *self)
nm_auth_manager_check_authorization_cancel (priv->auth.call_id_wifi_shared_permission);
}
priv->auth.result_func = NULL;
priv->auth.user_data1 = NULL;
priv->auth.user_data2 = NULL;
priv->auth.user_data = NULL;
}
static void
@ -1012,8 +1010,7 @@ auth_complete (NMActiveConnection *self, gboolean result, const char *message)
priv->auth.result_func (self,
result,
message,
priv->auth.user_data1,
priv->auth.user_data2);
priv->auth.user_data);
auth_cancel (self);
}
@ -1082,8 +1079,7 @@ auth_done (NMAuthManager *auth_mgr,
* is no @settings_connection available when creating the active connection.
* Instead pass an alternative connection.
* @result_func: function to be called on success or error
* @user_data1: pointer passed to @result_func
* @user_data2: additional pointer passed to @result_func
* @user_data: pointer passed to @result_func
*
* Checks whether the subject that initiated the active connection (read from
* the #NMActiveConnection::subject property) is authorized to complete this
@ -1093,8 +1089,7 @@ void
nm_active_connection_authorize (NMActiveConnection *self,
NMConnection *initial_connection,
NMActiveConnectionAuthResultFunc result_func,
gpointer user_data1,
gpointer user_data2)
gpointer user_data)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
const char *wifi_permission = NULL;
@ -1133,10 +1128,8 @@ nm_active_connection_authorize (NMActiveConnection *self,
self);
}
/* Wait for authorization */
priv->auth.result_func = result_func;
priv->auth.user_data1 = user_data1;
priv->auth.user_data2 = user_data2;
priv->auth.user_data = user_data;
}
/*****************************************************************************/

View file

@ -109,14 +109,12 @@ GType nm_active_connection_get_type (void);
typedef void (*NMActiveConnectionAuthResultFunc) (NMActiveConnection *self,
gboolean success,
const char *error_desc,
gpointer user_data1,
gpointer user_data2);
gpointer user_data);
void nm_active_connection_authorize (NMActiveConnection *self,
NMConnection *initial_connection,
NMActiveConnectionAuthResultFunc result_func,
gpointer user_data1,
gpointer user_data2);
gpointer user_data);
NMSettingsConnection *nm_active_connection_get_settings_connection (NMActiveConnection *self);
NMConnection *nm_active_connection_get_applied_connection (NMActiveConnection *self);

View file

@ -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)
/*****************************************************************************/
@ -4100,11 +4098,10 @@ static void
_internal_activation_auth_done (NMActiveConnection *active,
gboolean success,
const char *error_desc,
gpointer user_data1,
gpointer user_data2)
gpointer user_data)
{
_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);
NMActiveConnection *ac;
gs_free_error GError *error = NULL;
@ -4232,7 +4229,7 @@ nm_manager_activate_connection (NMManager *self,
return NULL;
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;
}
@ -4365,16 +4362,17 @@ static void
_activation_auth_done (NMActiveConnection *active,
gboolean success,
const char *error_desc,
gpointer user_data1,
gpointer user_data2)
gpointer user_data)
{
NMManager *self = user_data1;
GDBusMethodInvocation *context = user_data2;
NMManager *self;
GDBusMethodInvocation *context;
GError *error = NULL;
NMAuthSubject *subject;
NMSettingsConnection *connection;
_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);
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),
NULL,
_activation_auth_done,
self,
invocation);
nm_utils_user_data_pack (self, invocation));
return;
error:
@ -4578,18 +4575,16 @@ static void
_add_and_activate_auth_done (NMActiveConnection *active,
gboolean success,
const char *error_desc,
gpointer user_data1,
gpointer user_data2)
gpointer user_data)
{
NMManager *self = user_data1;
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
GDBusMethodInvocation *context = user_data2;
NMManager *self;
NMManagerPrivate *priv;
GDBusMethodInvocation *context;
gs_unref_object NMConnection *connection = NULL;
AddAndActivateInfo *info;
GError *error = NULL;
gs_unref_object NMConnection *connection = NULL;
connection = g_object_steal_qdata (G_OBJECT (active),
active_connection_add_and_activate_quark ());
nm_utils_user_data_unpack (user_data, &self, &context, &connection);
if (!success) {
error = g_error_new_literal (NM_MANAGER_ERROR,
@ -4606,6 +4601,8 @@ _add_and_activate_auth_done (NMActiveConnection *active,
return;
}
priv = NM_MANAGER_GET_PRIVATE (self);
info = g_slice_new (AddAndActivateInfo);
info->manager = self;
@ -4709,17 +4706,9 @@ impl_manager_add_and_activate_connection (NMDBusObject *obj,
if (!active)
goto error;
/* FIXME: nm_active_connection_authorize() already has two user-data pointers
* to piggyback additional data. Instead of attaching the third argument to
* @active's user-data, add a third paramter.
* 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);
nm_active_connection_authorize (active, connection,
_add_and_activate_auth_done,
nm_utils_user_data_pack (self, invocation, connection));
/* we passed the pointers on to the callback of authorize. */
g_steal_pointer (&connection);