aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-27 12:23:05 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:16 +0100
commitb4bed06f985373acf6460aae61e3e0a167474e6e (patch)
tree19c5126e5cdabf5a5527c7600d890a4e6a422a31
parentcf0a4ae0ceb6c3ba30e94beb607f1d7afc2d4301 (diff)
bearer: include policy authorization checks
-rw-r--r--src/mm-bearer.c147
1 files changed, 117 insertions, 30 deletions
diff --git a/src/mm-bearer.c b/src/mm-bearer.c
index b14f4789..68f45a62 100644
--- a/src/mm-bearer.c
+++ b/src/mm-bearer.c
@@ -255,59 +255,77 @@ mm_bearer_connect (MMBearer *self,
result);
}
+typedef struct {
+ MMBearer *self;
+ MMBaseModem *modem;
+ GDBusMethodInvocation *invocation;
+} HandleConnectContext;
+
+static void
+handle_connect_context_free (HandleConnectContext *ctx)
+{
+ g_object_unref (ctx->invocation);
+ g_object_unref (ctx->modem);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
static void
handle_connect_ready (MMBearer *self,
GAsyncResult *res,
- GDBusMethodInvocation *invocation)
+ HandleConnectContext *ctx)
{
GError *error = NULL;
if (!mm_bearer_connect_finish (self, res, &error))
- g_dbus_method_invocation_take_error (invocation, error);
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
else
- mm_gdbus_bearer_complete_connect (MM_GDBUS_BEARER (self), invocation);
-
- g_object_unref (invocation);
-}
+ mm_gdbus_bearer_complete_connect (MM_GDBUS_BEARER (self), ctx->invocation);
-static gboolean
-handle_connect (MMBearer *self,
- GDBusMethodInvocation *invocation)
-{
- mm_bearer_connect (self,
- (GAsyncReadyCallback)handle_connect_ready,
- g_object_ref (invocation));
- return TRUE;
+ handle_connect_context_free (ctx);
}
-/*****************************************************************************/
-/* DISCONNECT */
-
static void
-handle_disconnect_ready (MMBearer *self,
- GAsyncResult *res,
- GDBusMethodInvocation *invocation)
+handle_connect_auth_ready (MMBaseModem *modem,
+ GAsyncResult *res,
+ HandleConnectContext *ctx)
{
GError *error = NULL;
- if (!mm_bearer_disconnect_finish (self, res, &error))
- g_dbus_method_invocation_take_error (invocation, error);
- else
- mm_gdbus_bearer_complete_disconnect (MM_GDBUS_BEARER (self), invocation);
- g_object_unref (invocation);
+ if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ handle_connect_context_free (ctx);
+ return;
+ }
+
+ mm_bearer_connect (ctx->self,
+ (GAsyncReadyCallback)handle_connect_ready,
+ ctx);
}
static gboolean
-handle_disconnect (MMBearer *self,
- GDBusMethodInvocation *invocation)
+handle_connect (MMBearer *self,
+ GDBusMethodInvocation *invocation)
{
- mm_bearer_disconnect (self,
- (GAsyncReadyCallback)handle_disconnect_ready,
- g_object_ref (invocation));
+ HandleConnectContext *ctx;
+
+ ctx = g_new0 (HandleConnectContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->invocation = g_object_ref (invocation);
+ g_object_get (self,
+ MM_BEARER_MODEM, &ctx->modem,
+ NULL);
+
+ mm_base_modem_authorize (ctx->modem,
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)handle_connect_auth_ready,
+ ctx);
return TRUE;
}
/*****************************************************************************/
+/* DISCONNECT */
gboolean
mm_bearer_disconnect_finish (MMBearer *self,
@@ -438,6 +456,75 @@ mm_bearer_disconnect (MMBearer *self,
simple); /* takes ownership */
}
+typedef struct {
+ MMBearer *self;
+ MMBaseModem *modem;
+ GDBusMethodInvocation *invocation;
+} HandleDisconnectContext;
+
+static void
+handle_disconnect_context_free (HandleDisconnectContext *ctx)
+{
+ g_object_unref (ctx->invocation);
+ g_object_unref (ctx->modem);
+ g_object_unref (ctx->self);
+ g_free (ctx);
+}
+
+static void
+handle_disconnect_ready (MMBearer *self,
+ GAsyncResult *res,
+ HandleDisconnectContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!mm_bearer_disconnect_finish (self, res, &error))
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ else
+ mm_gdbus_bearer_complete_disconnect (MM_GDBUS_BEARER (self), ctx->invocation);
+
+ handle_disconnect_context_free (ctx);
+}
+
+static void
+handle_disconnect_auth_ready (MMBaseModem *modem,
+ GAsyncResult *res,
+ HandleDisconnectContext *ctx)
+{
+ GError *error = NULL;
+
+ if (!mm_base_modem_authorize_finish (modem, res, &error)) {
+ g_dbus_method_invocation_take_error (ctx->invocation, error);
+ handle_disconnect_context_free (ctx);
+ return;
+ }
+
+ mm_bearer_disconnect (ctx->self,
+ (GAsyncReadyCallback)handle_disconnect_ready,
+ ctx);
+}
+
+static gboolean
+handle_disconnect (MMBearer *self,
+ GDBusMethodInvocation *invocation)
+{
+ HandleDisconnectContext *ctx;
+
+ ctx = g_new0 (HandleDisconnectContext, 1);
+ ctx->self = g_object_ref (self);
+ ctx->invocation = g_object_ref (invocation);
+ g_object_get (self,
+ MM_BEARER_MODEM, &ctx->modem,
+ NULL);
+
+ mm_base_modem_authorize (ctx->modem,
+ invocation,
+ MM_AUTHORIZATION_DEVICE_CONTROL,
+ (GAsyncReadyCallback)handle_disconnect_auth_ready,
+ ctx);
+ return TRUE;
+}
+
/*****************************************************************************/
static void