From 9a8bf2be311ed832a169cd998dfa24b2b8bf366f Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 21 Oct 2019 19:34:29 +0200 Subject: [PATCH] auth: Add helpers dbus helpers for sending webflow signals --- common/flatpak-auth-private.h | 43 +++++++++++++++++++---------------- common/flatpak-auth.c | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/common/flatpak-auth-private.h b/common/flatpak-auth-private.h index 19ffaf22..42d96ca2 100644 --- a/common/flatpak-auth-private.h +++ b/common/flatpak-auth-private.h @@ -42,24 +42,29 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (AutoFlatpakAuthenticator, g_object_unref) typedef FlatpakAuthenticatorRequest AutoFlatpakAuthenticatorRequest; G_DEFINE_AUTOPTR_CLEANUP_FUNC (AutoFlatpakAuthenticatorRequest, g_object_unref) -FlatpakAuthenticator * flatpak_auth_new_for_remote (FlatpakDir *dir, - const char *remote, - GCancellable *cancellable, - GError **error); -FlatpakAuthenticatorRequest *flatpak_auth_create_request (FlatpakAuthenticator *authenticator, - GCancellable *cancellable, - GError **error); -gboolean flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator, - FlatpakAuthenticatorRequest *request, - const char **refs, - GCancellable *cancellable, - GError **error); -char * flatpak_auth_create_request_path (const char *peer, - const char *token, - GError **error); -void flatpak_auth_request_emit_response (FlatpakAuthenticatorRequest *request, - const gchar *destination_bus_name, - guint arg_response, - GVariant *arg_results); +FlatpakAuthenticator * flatpak_auth_new_for_remote (FlatpakDir *dir, + const char *remote, + GCancellable *cancellable, + GError **error); +FlatpakAuthenticatorRequest *flatpak_auth_create_request (FlatpakAuthenticator *authenticator, + GCancellable *cancellable, + GError **error); +gboolean flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator, + FlatpakAuthenticatorRequest *request, + const char **refs, + GCancellable *cancellable, + GError **error); +char * flatpak_auth_create_request_path (const char *peer, + const char *token, + GError **error); +void flatpak_auth_request_emit_response (FlatpakAuthenticatorRequest *request, + const gchar *destination_bus_name, + guint arg_response, + GVariant *arg_results); +void flatpak_auth_request_emit_webflow (FlatpakAuthenticatorRequest *request, + const gchar *destination_bus_name, + const char *arg_uri); +void flatpak_auth_request_emit_webflow_done (FlatpakAuthenticatorRequest *request, + const gchar *destination_bus_name); #endif /* __FLATPAK_AUTH_H__ */ diff --git a/common/flatpak-auth.c b/common/flatpak-auth.c index 7ecf69bd..1ec6432a 100644 --- a/common/flatpak-auth.c +++ b/common/flatpak-auth.c @@ -178,3 +178,46 @@ flatpak_auth_request_emit_response (FlatpakAuthenticatorRequest *request, } g_list_free_full (connections, g_object_unref); } + +void +flatpak_auth_request_emit_webflow (FlatpakAuthenticatorRequest *request, + const gchar *destination_bus_name, + const char *arg_uri) +{ + FlatpakAuthenticatorRequestSkeleton *skeleton = FLATPAK_AUTHENTICATOR_REQUEST_SKELETON (request); + GList *connections, *l; + g_autoptr(GVariant) signal_variant = NULL; + connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton)); + + signal_variant = g_variant_ref_sink (g_variant_new ("(s)", arg_uri)); + for (l = connections; l != NULL; l = l->next) + { + GDBusConnection *connection = l->data; + g_dbus_connection_emit_signal (connection, destination_bus_name, + g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), + "org.freedesktop.Flatpak.AuthenticatorRequest", "Webflow", + signal_variant, NULL); + } + g_list_free_full (connections, g_object_unref); +} + +void +flatpak_auth_request_emit_webflow_done (FlatpakAuthenticatorRequest *request, + const gchar *destination_bus_name) +{ + FlatpakAuthenticatorRequestSkeleton *skeleton = FLATPAK_AUTHENTICATOR_REQUEST_SKELETON (request); + GList *connections, *l; + g_autoptr(GVariant) signal_variant = NULL; + connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton)); + + signal_variant = g_variant_ref_sink (g_variant_new ("()")); + for (l = connections; l != NULL; l = l->next) + { + GDBusConnection *connection = l->data; + g_dbus_connection_emit_signal (connection, destination_bus_name, + g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), + "org.freedesktop.Flatpak.AuthenticatorRequest", "WebflowDone", + signal_variant, NULL); + } + g_list_free_full (connections, g_object_unref); +}