iface-modem-3gpp-ussd: include policy authorization checks
This commit is contained in:
@@ -47,10 +47,10 @@ typedef struct {
|
|||||||
MmGdbusModem3gppUssd *skeleton;
|
MmGdbusModem3gppUssd *skeleton;
|
||||||
GDBusMethodInvocation *invocation;
|
GDBusMethodInvocation *invocation;
|
||||||
MMIfaceModem3gppUssd *self;
|
MMIfaceModem3gppUssd *self;
|
||||||
} DbusCallContext;
|
} HandleCancelContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dbus_call_context_free (DbusCallContext *ctx)
|
handle_cancel_context_free (HandleCancelContext *ctx)
|
||||||
{
|
{
|
||||||
g_object_unref (ctx->skeleton);
|
g_object_unref (ctx->skeleton);
|
||||||
g_object_unref (ctx->invocation);
|
g_object_unref (ctx->invocation);
|
||||||
@@ -58,92 +58,120 @@ dbus_call_context_free (DbusCallContext *ctx)
|
|||||||
g_free (ctx);
|
g_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DbusCallContext *
|
|
||||||
dbus_call_context_new (MmGdbusModem3gppUssd *skeleton,
|
|
||||||
GDBusMethodInvocation *invocation,
|
|
||||||
MMIfaceModem3gppUssd *self)
|
|
||||||
{
|
|
||||||
DbusCallContext *ctx;
|
|
||||||
|
|
||||||
ctx = g_new (DbusCallContext, 1);
|
|
||||||
ctx->skeleton = g_object_ref (skeleton);
|
|
||||||
ctx->invocation = g_object_ref (invocation);
|
|
||||||
ctx->self = g_object_ref (self);
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cancel_ready (MMIfaceModem3gppUssd *self,
|
handle_cancel_ready (MMIfaceModem3gppUssd *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DbusCallContext *ctx)
|
HandleCancelContext *ctx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel_finish (self,
|
if (!MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel_finish (self, res, &error))
|
||||||
res,
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
&error))
|
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
|
||||||
error);
|
|
||||||
else
|
else
|
||||||
mm_gdbus_modem3gpp_ussd_complete_cancel (ctx->skeleton,
|
mm_gdbus_modem3gpp_ussd_complete_cancel (ctx->skeleton, ctx->invocation);
|
||||||
ctx->invocation);
|
|
||||||
dbus_call_context_free (ctx);
|
handle_cancel_context_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_cancel_auth_ready (MMBaseModem *self,
|
||||||
|
GAsyncResult *res,
|
||||||
|
HandleCancelContext *ctx)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_base_modem_authorize_finish (self, res, &error)) {
|
||||||
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
|
handle_cancel_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel != NULL);
|
||||||
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel_finish != NULL);
|
||||||
|
|
||||||
|
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel (
|
||||||
|
MM_IFACE_MODEM_3GPP_USSD (self),
|
||||||
|
(GAsyncReadyCallback)handle_cancel_ready,
|
||||||
|
ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_cancel (MmGdbusModem3gppUssd *skeleton,
|
handle_cancel (MmGdbusModem3gppUssd *skeleton,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
const gchar *command,
|
|
||||||
MMIfaceModem3gppUssd *self)
|
MMIfaceModem3gppUssd *self)
|
||||||
{
|
{
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel != NULL);
|
HandleCancelContext *ctx;
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel_finish != NULL);
|
|
||||||
|
|
||||||
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cancel (
|
ctx = g_new (HandleCancelContext, 1);
|
||||||
self,
|
ctx->skeleton = g_object_ref (skeleton);
|
||||||
(GAsyncReadyCallback)cancel_ready,
|
ctx->invocation = g_object_ref (invocation);
|
||||||
dbus_call_context_new (skeleton,
|
ctx->self = g_object_ref (self);
|
||||||
|
|
||||||
|
mm_base_modem_authorize (MM_BASE_MODEM (self),
|
||||||
invocation,
|
invocation,
|
||||||
self));
|
MM_AUTHORIZATION_USSD,
|
||||||
|
(GAsyncReadyCallback)handle_cancel_auth_ready,
|
||||||
|
ctx);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MmGdbusModem3gppUssd *skeleton;
|
||||||
|
GDBusMethodInvocation *invocation;
|
||||||
|
MMIfaceModem3gppUssd *self;
|
||||||
|
gchar *command;
|
||||||
|
} HandleRespondContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
respond_send_ready (MMIfaceModem3gppUssd *self,
|
handle_respond_context_free (HandleRespondContext *ctx)
|
||||||
|
{
|
||||||
|
g_object_unref (ctx->skeleton);
|
||||||
|
g_object_unref (ctx->invocation);
|
||||||
|
g_object_unref (ctx->self);
|
||||||
|
g_free (ctx->command);
|
||||||
|
g_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_respond_ready (MMIfaceModem3gppUssd *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DbusCallContext *ctx)
|
HandleRespondContext *ctx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
const gchar *reply;
|
const gchar *reply;
|
||||||
|
|
||||||
reply = MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish (self,
|
reply = MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish (self, res,&error);
|
||||||
res,
|
|
||||||
&error);
|
|
||||||
if (!reply)
|
if (!reply)
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
error);
|
|
||||||
else
|
else
|
||||||
mm_gdbus_modem3gpp_ussd_complete_respond (ctx->skeleton,
|
mm_gdbus_modem3gpp_ussd_complete_respond (ctx->skeleton,
|
||||||
ctx->invocation,
|
ctx->invocation,
|
||||||
reply);
|
reply);
|
||||||
dbus_call_context_free (ctx);
|
handle_respond_context_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
handle_respond (MmGdbusModem3gppUssd *skeleton,
|
handle_respond_auth_ready (MMBaseModem *self,
|
||||||
GDBusMethodInvocation *invocation,
|
GAsyncResult *res,
|
||||||
const gchar *command,
|
HandleRespondContext *ctx)
|
||||||
MMIfaceModem3gppUssd *self)
|
|
||||||
{
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_base_modem_authorize_finish (self, res, &error)) {
|
||||||
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
|
handle_respond_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send != NULL);
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send != NULL);
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish != NULL);
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish != NULL);
|
||||||
|
|
||||||
switch (mm_gdbus_modem3gpp_ussd_get_state (skeleton)) {
|
switch (mm_gdbus_modem3gpp_ussd_get_state (ctx->skeleton)) {
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE:
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE:
|
||||||
g_dbus_method_invocation_return_error (invocation,
|
g_dbus_method_invocation_return_error (ctx->invocation,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_WRONG_STATE,
|
MM_CORE_ERROR_WRONG_STATE,
|
||||||
"Cannot respond USSD: "
|
"Cannot respond USSD: "
|
||||||
@@ -152,13 +180,11 @@ handle_respond (MmGdbusModem3gppUssd *skeleton,
|
|||||||
|
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE:
|
||||||
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send (
|
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send (
|
||||||
self,
|
MM_IFACE_MODEM_3GPP_USSD (self),
|
||||||
command,
|
ctx->command,
|
||||||
(GAsyncReadyCallback)respond_send_ready,
|
(GAsyncReadyCallback)handle_respond_ready,
|
||||||
dbus_call_context_new (skeleton,
|
ctx);
|
||||||
invocation,
|
return;
|
||||||
self));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
@@ -167,45 +193,88 @@ handle_respond (MmGdbusModem3gppUssd *skeleton,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_respond_context_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
handle_respond (MmGdbusModem3gppUssd *skeleton,
|
||||||
|
GDBusMethodInvocation *invocation,
|
||||||
|
const gchar *command,
|
||||||
|
MMIfaceModem3gppUssd *self)
|
||||||
|
{
|
||||||
|
HandleRespondContext *ctx;
|
||||||
|
|
||||||
|
ctx = g_new (HandleRespondContext, 1);
|
||||||
|
ctx->skeleton = g_object_ref (skeleton);
|
||||||
|
ctx->invocation = g_object_ref (invocation);
|
||||||
|
ctx->self = g_object_ref (self);
|
||||||
|
ctx->command = g_strdup (command);
|
||||||
|
|
||||||
|
mm_base_modem_authorize (MM_BASE_MODEM (self),
|
||||||
|
invocation,
|
||||||
|
MM_AUTHORIZATION_USSD,
|
||||||
|
(GAsyncReadyCallback)handle_respond_auth_ready,
|
||||||
|
ctx);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MmGdbusModem3gppUssd *skeleton;
|
||||||
|
GDBusMethodInvocation *invocation;
|
||||||
|
MMIfaceModem3gppUssd *self;
|
||||||
|
gchar *command;
|
||||||
|
} HandleInitiateContext;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initiate_send_ready (MMIfaceModem3gppUssd *self,
|
handle_initiate_context_free (HandleInitiateContext *ctx)
|
||||||
|
{
|
||||||
|
g_object_unref (ctx->skeleton);
|
||||||
|
g_object_unref (ctx->invocation);
|
||||||
|
g_object_unref (ctx->self);
|
||||||
|
g_free (ctx->command);
|
||||||
|
g_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_initiate_ready (MMIfaceModem3gppUssd *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
DbusCallContext *ctx)
|
HandleInitiateContext *ctx)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
const gchar *reply;
|
const gchar *reply;
|
||||||
|
|
||||||
reply = MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish (self,
|
reply = MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish (self, res, &error);
|
||||||
res,
|
|
||||||
&error);
|
|
||||||
if (!reply)
|
if (!reply)
|
||||||
g_dbus_method_invocation_take_error (ctx->invocation,
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
error);
|
|
||||||
else
|
else
|
||||||
mm_gdbus_modem3gpp_ussd_complete_initiate (ctx->skeleton,
|
mm_gdbus_modem3gpp_ussd_complete_initiate (ctx->skeleton,
|
||||||
ctx->invocation,
|
ctx->invocation,
|
||||||
reply);
|
reply);
|
||||||
dbus_call_context_free (ctx);
|
handle_initiate_context_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
handle_initiate (MmGdbusModem3gppUssd *skeleton,
|
handle_initiate_auth_ready (MMBaseModem *self,
|
||||||
GDBusMethodInvocation *invocation,
|
GAsyncResult *res,
|
||||||
const gchar *command,
|
HandleInitiateContext *ctx)
|
||||||
MMIfaceModem3gppUssd *self)
|
|
||||||
{
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_base_modem_authorize_finish (self, res, &error)) {
|
||||||
|
g_dbus_method_invocation_take_error (ctx->invocation, error);
|
||||||
|
handle_initiate_context_free (ctx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send != NULL);
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send != NULL);
|
||||||
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish != NULL);
|
g_assert (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send_finish != NULL);
|
||||||
|
|
||||||
switch (mm_gdbus_modem3gpp_ussd_get_state (skeleton)) {
|
switch (mm_gdbus_modem3gpp_ussd_get_state (ctx->skeleton)) {
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_ACTIVE:
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_USER_RESPONSE:
|
||||||
g_dbus_method_invocation_return_error (invocation,
|
g_dbus_method_invocation_return_error (ctx->invocation,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_WRONG_STATE,
|
MM_CORE_ERROR_WRONG_STATE,
|
||||||
"Cannot initiate USSD: "
|
"Cannot initiate USSD: "
|
||||||
@@ -214,13 +283,11 @@ handle_initiate (MmGdbusModem3gppUssd *skeleton,
|
|||||||
|
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_IDLE:
|
||||||
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send (
|
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->send (
|
||||||
self,
|
MM_IFACE_MODEM_3GPP_USSD (self),
|
||||||
command,
|
ctx->command,
|
||||||
(GAsyncReadyCallback)initiate_send_ready,
|
(GAsyncReadyCallback)handle_initiate_ready,
|
||||||
dbus_call_context_new (skeleton,
|
ctx);
|
||||||
invocation,
|
return;
|
||||||
self));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN:
|
case MM_MODEM_3GPP_USSD_SESSION_STATE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
@@ -229,6 +296,28 @@ handle_initiate (MmGdbusModem3gppUssd *skeleton,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_initiate_context_free (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
handle_initiate (MmGdbusModem3gppUssd *skeleton,
|
||||||
|
GDBusMethodInvocation *invocation,
|
||||||
|
const gchar *command,
|
||||||
|
MMIfaceModem3gppUssd *self)
|
||||||
|
{
|
||||||
|
HandleInitiateContext *ctx;
|
||||||
|
|
||||||
|
ctx = g_new (HandleInitiateContext, 1);
|
||||||
|
ctx->skeleton = g_object_ref (skeleton);
|
||||||
|
ctx->invocation = g_object_ref (invocation);
|
||||||
|
ctx->self = g_object_ref (self);
|
||||||
|
ctx->command = g_strdup (command);
|
||||||
|
|
||||||
|
mm_base_modem_authorize (MM_BASE_MODEM (self),
|
||||||
|
invocation,
|
||||||
|
MM_AUTHORIZATION_USSD,
|
||||||
|
(GAsyncReadyCallback)handle_initiate_auth_ready,
|
||||||
|
ctx);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user