diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2015-12-03 12:01:00 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2015-12-03 12:01:14 +0100 |
commit | 4c036eb8f96cae06da1f968fb9eb48f6faa12796 (patch) | |
tree | db8555c15360759df792e0c485c6922d98c296c7 /src/mm-iface-modem.c | |
parent | ea3cb005b8e276178187654bd1aadbe8b33abf63 (diff) |
iface-modem: explicitly disconnect bearer before removing it
https://bugs.freedesktop.org/show_bug.cgi?id=90408
Diffstat (limited to 'src/mm-iface-modem.c')
-rw-r--r-- | src/mm-iface-modem.c | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 87dace2f..516ed78e 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -760,11 +760,14 @@ typedef struct { MMIfaceModem *self; MMBearerList *list; gchar *bearer_path; + MMBaseBearer *bearer; } HandleDeleteBearerContext; static void handle_delete_bearer_context_free (HandleDeleteBearerContext *ctx) { + if (ctx->bearer) + g_object_unref (ctx->bearer); g_object_unref (ctx->skeleton); g_object_unref (ctx->invocation); g_object_unref (ctx->self); @@ -775,6 +778,26 @@ handle_delete_bearer_context_free (HandleDeleteBearerContext *ctx) } static void +delete_bearer_disconnect_ready (MMBaseBearer *bearer, + GAsyncResult *res, + HandleDeleteBearerContext *ctx) +{ + GError *error = NULL; + + if (!mm_base_bearer_disconnect_finish (bearer, res, &error)) { + g_dbus_method_invocation_take_error (ctx->invocation, error); + handle_delete_bearer_context_free (ctx); + return; + } + + if (!mm_bearer_list_delete_bearer (ctx->list, ctx->bearer_path, &error)) + g_dbus_method_invocation_take_error (ctx->invocation, error); + else + mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); + handle_delete_bearer_context_free (ctx); +} + +static void handle_delete_bearer_auth_ready (MMBaseModem *self, GAsyncResult *res, HandleDeleteBearerContext *ctx) @@ -787,14 +810,30 @@ handle_delete_bearer_auth_ready (MMBaseModem *self, return; } - if (!ctx->list) - mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); - else if (!mm_bearer_list_delete_bearer (ctx->list, ctx->bearer_path, &error)) - g_dbus_method_invocation_take_error (ctx->invocation, error); - else - mm_gdbus_modem_complete_delete_bearer (ctx->skeleton, ctx->invocation); + if (!g_str_has_prefix (ctx->bearer_path, MM_DBUS_BEARER_PREFIX)) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Cannot delete bearer: invalid path '%s'", + ctx->bearer_path); + handle_delete_bearer_context_free (ctx); + return; + } - handle_delete_bearer_context_free (ctx); + ctx->bearer = mm_bearer_list_find_by_path (ctx->list, ctx->bearer_path); + if (!ctx->bearer) { + g_dbus_method_invocation_return_error (ctx->invocation, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Cannot delete bearer: no bearer found with path '%s'", + ctx->bearer_path); + handle_delete_bearer_context_free (ctx); + return; + } + + mm_base_bearer_disconnect (ctx->bearer, + (GAsyncReadyCallback)delete_bearer_disconnect_ready, + ctx); } static gboolean |