core: avoid using DBusGMethodInvocation in auth API

While porting to GDBus, use opaque pointers. This allows us to include either a
DBusGMethodInvocation or a GDBusMethodInvocation in the 'context' pointer.

Once fully ported to GDBus, we can safely change it back to make the context be
a GDBusMethodInvocation.
This commit is contained in:
Aleksander Morgado
2011-09-02 20:28:12 +02:00
committed by Aleksander Morgado
parent 1e79a2d292
commit d47176a32c
16 changed files with 66 additions and 52 deletions

View File

@@ -55,20 +55,33 @@ static MMAuthRequest *
real_create_request (MMAuthProvider *provider, real_create_request (MMAuthProvider *provider,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify) GDestroyNotify notify)
{ {
MMAuthProviderPolkitPrivate *priv = MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE (provider); MMAuthProviderPolkitPrivate *priv = MM_AUTH_PROVIDER_POLKIT_GET_PRIVATE (provider);
MMAuthRequest *auth_request;
gchar *sender;
return (MMAuthRequest *) mm_auth_request_polkit_new (priv->authority, /* Ugly temporary hack... */
if (G_IS_DBUS_METHOD_INVOCATION (context)) {
sender = g_strdup (g_dbus_method_invocation_get_sender (context));
} else {
sender = dbus_g_method_get_sender (context);
}
auth_request = (MMAuthRequest *)mm_auth_request_polkit_new (priv->authority,
authorization, authorization,
owner, owner,
context, context,
sender,
callback, callback,
callback_data, callback_data,
notify); notify);
g_free (sender);
return auth_request;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -105,7 +105,7 @@ static MMAuthRequest *
real_create_request (MMAuthProvider *provider, real_create_request (MMAuthProvider *provider,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify) GDestroyNotify notify)
@@ -165,7 +165,7 @@ MMAuthRequest *
mm_auth_provider_request_auth (MMAuthProvider *self, mm_auth_provider_request_auth (MMAuthProvider *self,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify, GDestroyNotify notify,

View File

@@ -52,7 +52,7 @@ typedef struct {
MMAuthRequest * (*create_request) (MMAuthProvider *provider, MMAuthRequest * (*create_request) (MMAuthProvider *provider,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify); GDestroyNotify notify);
@@ -64,7 +64,7 @@ GType mm_auth_provider_get_type (void);
MMAuthRequest *mm_auth_provider_request_auth (MMAuthProvider *provider, MMAuthRequest *mm_auth_provider_request_auth (MMAuthProvider *provider,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify, GDestroyNotify notify,

View File

@@ -34,14 +34,14 @@ GObject *
mm_auth_request_polkit_new (PolkitAuthority *authority, mm_auth_request_polkit_new (PolkitAuthority *authority,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
const gchar *sender,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify) GDestroyNotify notify)
{ {
GObject *obj; GObject *obj;
MMAuthRequestPolkitPrivate *priv; MMAuthRequestPolkitPrivate *priv;
char *sender;
g_return_val_if_fail (authorization != NULL, NULL); g_return_val_if_fail (authorization != NULL, NULL);
g_return_val_if_fail (owner != NULL, NULL); g_return_val_if_fail (owner != NULL, NULL);
@@ -59,10 +59,7 @@ mm_auth_request_polkit_new (PolkitAuthority *authority,
priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (obj); priv = MM_AUTH_REQUEST_POLKIT_GET_PRIVATE (obj);
priv->authority = authority; priv->authority = authority;
priv->cancellable = g_cancellable_new (); priv->cancellable = g_cancellable_new ();
sender = dbus_g_method_get_sender (context);
priv->subject = polkit_system_bus_name_new (sender); priv->subject = polkit_system_bus_name_new (sender);
g_free (sender);
} }
return obj; return obj;

View File

@@ -42,7 +42,8 @@ GType mm_auth_request_polkit_get_type (void);
GObject *mm_auth_request_polkit_new (PolkitAuthority *authority, GObject *mm_auth_request_polkit_new (PolkitAuthority *authority,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
const gchar *sender,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify); GDestroyNotify notify);

View File

@@ -22,7 +22,7 @@ G_DEFINE_TYPE (MMAuthRequest, mm_auth_request, G_TYPE_OBJECT)
typedef struct { typedef struct {
GObject *owner; GObject *owner;
char *auth; char *auth;
DBusGMethodInvocation *context; gpointer context;
MMAuthRequestCb callback; MMAuthRequestCb callback;
gpointer callback_data; gpointer callback_data;
@@ -35,7 +35,7 @@ GObject *
mm_auth_request_new (GType atype, mm_auth_request_new (GType atype,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify) GDestroyNotify notify)

View File

@@ -47,15 +47,18 @@ typedef struct {
GType mm_auth_request_get_type (void); GType mm_auth_request_get_type (void);
/* TODO: Change the context gpointer to be a GDBusMethodInvocation when
* fully ported to GDBus, and remove all (MMAuthRequestCb) casts */
typedef void (*MMAuthRequestCb) (MMAuthRequest *req, typedef void (*MMAuthRequestCb) (MMAuthRequest *req,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
gpointer user_data); gpointer user_data);
GObject *mm_auth_request_new (GType atype, GObject *mm_auth_request_new (GType atype,
const char *authorization, const char *authorization,
GObject *owner, GObject *owner,
DBusGMethodInvocation *context, gpointer context,
MMAuthRequestCb callback, MMAuthRequestCb callback,
gpointer callback_data, gpointer callback_data,
GDestroyNotify notify); GDestroyNotify notify);

View File

@@ -1023,7 +1023,7 @@ impl_manager_scan_devices (MMManager *manager,
MM_AUTHORIZATION_MANAGER_CONTROL, MM_AUTHORIZATION_MANAGER_CONTROL,
G_OBJECT (manager), G_OBJECT (manager),
context, context,
scan_devices_auth_cb, (MMAuthRequestCb)scan_devices_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {

View File

@@ -219,7 +219,7 @@ impl_modem_cdma_get_esn (MMModemCdma *self, DBusGMethodInvocation *context)
if (!mm_modem_auth_request (MM_MODEM (self), if (!mm_modem_auth_request (MM_MODEM (self),
MM_AUTHORIZATION_DEVICE_INFO, MM_AUTHORIZATION_DEVICE_INFO,
context, context,
esn_auth_cb, (MMAuthRequestCb)esn_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {

View File

@@ -195,7 +195,7 @@ impl_modem_firmware_list (MMModemFirmware *modem, DBusGMethodInvocation *context
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE, MM_AUTHORIZATION_FIRMWARE,
context, context,
firmware_list_auth_cb, (MMAuthRequestCb)firmware_list_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -235,7 +235,7 @@ impl_modem_firmware_select (MMModemFirmware *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE, MM_AUTHORIZATION_FIRMWARE,
context, context,
firmware_select_auth_cb, (MMAuthRequestCb)firmware_select_auth_cb,
info, info,
firmware_auth_info_destroy, firmware_auth_info_destroy,
&error)) { &error)) {
@@ -277,7 +277,7 @@ impl_modem_firmware_install (MMModemFirmware *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_FIRMWARE, MM_AUTHORIZATION_FIRMWARE,
context, context,
firmware_install_auth_cb, (MMAuthRequestCb)firmware_install_auth_cb,
info, info,
firmware_auth_info_destroy, firmware_auth_info_destroy,
&error)) { &error)) {

View File

@@ -288,7 +288,7 @@ impl_gsm_modem_get_imei (MMModemGsmCard *modem, DBusGMethodInvocation *context)
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO, MM_AUTHORIZATION_DEVICE_INFO,
context, context,
imei_auth_cb, (MMAuthRequestCb)imei_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -325,7 +325,7 @@ impl_gsm_modem_get_imsi (MMModemGsmCard *modem, DBusGMethodInvocation *context)
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO, MM_AUTHORIZATION_DEVICE_INFO,
context, context,
imsi_auth_cb, (MMAuthRequestCb)imsi_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -362,7 +362,7 @@ impl_gsm_modem_get_spn (MMModemGsmCard *modem, DBusGMethodInvocation *context)
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO, MM_AUTHORIZATION_DEVICE_INFO,
context, context,
spn_auth_cb, (MMAuthRequestCb)spn_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -399,7 +399,7 @@ impl_gsm_modem_get_operator_id (MMModemGsmCard *modem, DBusGMethodInvocation *co
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_INFO, MM_AUTHORIZATION_DEVICE_INFO,
context, context,
operator_id_auth_cb, (MMAuthRequestCb)operator_id_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -480,7 +480,7 @@ impl_gsm_modem_send_puk (MMModemGsmCard *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
send_puk_auth_cb, (MMAuthRequestCb)send_puk_auth_cb,
info, info,
send_pin_puk_info_destroy, send_pin_puk_info_destroy,
&error)) { &error)) {
@@ -523,7 +523,7 @@ impl_gsm_modem_send_pin (MMModemGsmCard *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
send_pin_auth_cb, (MMAuthRequestCb)send_pin_auth_cb,
info, info,
send_pin_puk_info_destroy, send_pin_puk_info_destroy,
&error)) { &error)) {
@@ -567,7 +567,7 @@ impl_gsm_modem_enable_pin (MMModemGsmCard *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
enable_pin_auth_cb, (MMAuthRequestCb)enable_pin_auth_cb,
info, info,
send_pin_puk_info_destroy, send_pin_puk_info_destroy,
&error)) { &error)) {
@@ -611,7 +611,7 @@ impl_gsm_modem_change_pin (MMModemGsmCard *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
change_pin_auth_cb, (MMAuthRequestCb)change_pin_auth_cb,
info, info,
send_pin_puk_info_destroy, send_pin_puk_info_destroy,
&error)) { &error)) {

View File

@@ -452,7 +452,7 @@ impl_gsm_modem_scan (MMModemGsmNetwork *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
scan_auth_cb, (MMAuthRequestCb)scan_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {

View File

@@ -389,7 +389,7 @@ impl_gsm_modem_sms_delete (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_delete_auth_cb, (MMAuthRequestCb)sms_delete_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -435,7 +435,7 @@ impl_gsm_modem_sms_get (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_get_auth_cb, (MMAuthRequestCb)sms_get_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -501,7 +501,7 @@ impl_gsm_modem_sms_set_smsc (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_set_smsc_auth_cb, (MMAuthRequestCb)sms_set_smsc_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -539,7 +539,7 @@ impl_gsm_modem_sms_list (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_list_auth_cb, (MMAuthRequestCb)sms_list_auth_cb,
NULL, NULL,
NULL, NULL,
&error)) { &error)) {
@@ -581,7 +581,7 @@ impl_gsm_modem_sms_save (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_save_auth_cb, (MMAuthRequestCb)sms_save_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -676,7 +676,7 @@ impl_gsm_modem_sms_send (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_send_auth_cb, (MMAuthRequestCb)sms_send_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -718,7 +718,7 @@ impl_gsm_modem_sms_send_from_storage (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_send_from_storage_auth_cb, (MMAuthRequestCb)sms_send_from_storage_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {
@@ -764,7 +764,7 @@ impl_gsm_modem_sms_set_indication (MMModemGsmSms *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_SMS, MM_AUTHORIZATION_SMS,
context, context,
sms_set_indication_auth_cb, (MMAuthRequestCb)sms_set_indication_auth_cb,
info, info,
sms_auth_info_destroy, sms_auth_info_destroy,
&error)) { &error)) {

View File

@@ -232,7 +232,7 @@ impl_modem_gsm_ussd_initiate (MMModemGsmUssd *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD, MM_AUTHORIZATION_USSD,
context, context,
ussd_initiate_auth_cb, (MMAuthRequestCb)ussd_initiate_auth_cb,
info, info,
ussd_auth_info_destroy, ussd_auth_info_destroy,
&error)) { &error)) {
@@ -282,7 +282,7 @@ impl_modem_gsm_ussd_respond (MMModemGsmUssd *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD, MM_AUTHORIZATION_USSD,
context, context,
ussd_respond_auth_cb, (MMAuthRequestCb)ussd_respond_auth_cb,
info, info,
ussd_auth_info_destroy, ussd_auth_info_destroy,
&error)) { &error)) {
@@ -323,7 +323,7 @@ impl_modem_gsm_ussd_cancel (MMModemGsmUssd *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_USSD, MM_AUTHORIZATION_USSD,
context, context,
ussd_cancel_auth_cb, (MMAuthRequestCb)ussd_cancel_auth_cb,
info, info,
ussd_auth_info_destroy, ussd_auth_info_destroy,
&error)) { &error)) {

View File

@@ -137,7 +137,7 @@ impl_modem_location_enable (MMModemLocation *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_LOCATION, MM_AUTHORIZATION_LOCATION,
context, context,
loc_enable_auth_cb, (MMAuthRequestCb)loc_enable_auth_cb,
info, info,
loc_auth_info_destroy, loc_auth_info_destroy,
&error)) { &error)) {
@@ -232,7 +232,7 @@ impl_modem_location_get_location (MMModemLocation *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_LOCATION, MM_AUTHORIZATION_LOCATION,
context, context,
loc_get_auth_cb, (MMAuthRequestCb)loc_get_auth_cb,
info, info,
loc_auth_info_destroy, loc_auth_info_destroy,
&error)) { &error)) {

View File

@@ -491,7 +491,7 @@ impl_modem_reset (MMModem *modem, DBusGMethodInvocation *context)
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
reset_auth_cb, (MMAuthRequestCb)reset_auth_cb,
NULL, NULL, NULL, NULL,
&error)) { &error)) {
dbus_g_method_return_error (context, error); dbus_g_method_return_error (context, error);
@@ -544,7 +544,7 @@ impl_modem_factory_reset (MMModem *modem,
if (!mm_modem_auth_request (MM_MODEM (modem), if (!mm_modem_auth_request (MM_MODEM (modem),
MM_AUTHORIZATION_DEVICE_CONTROL, MM_AUTHORIZATION_DEVICE_CONTROL,
context, context,
factory_reset_auth_cb, (MMAuthRequestCb)factory_reset_auth_cb,
g_strdup (code), g_strdup (code),
g_free, g_free,
&error)) { &error)) {