| 1 | /* |
| 2 | * Copyright © 2024 Red Hat, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Authors: |
| 20 | * Jonas Ådahl <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 24 | |
| 25 | #include "registry.h"cxx . . $ `<file>/src/registry.h`/ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | #include "xdp-app-info-registry.h"cxx . . $ `<file>/src/xdp-app-info-registry.h`/ |
| 30 | #include "xdp-app-info.h"cxx . . $ `<file>/src/xdp-app-info.h`/ |
| 31 | #include "xdp-context.h"cxx . . $ `<file>/src/xdp-context.h`/ |
| 32 | #include "xdp-host-dbus.h"cxx . . $ `<file>/build/src/xdp-host-dbus.h`/ |
| 33 | #include "xdp-utils.h"cxx . . $ `<file>/src/xdp-utils.h`/ |
| 34 | |
| 35 | typedef struct _Registrycxx . . $ _Registry# Registrycxx . . $ Registry#; |
| 36 | typedef struct _RegistryClasscxx . . $ _RegistryClass# RegistryClasscxx . . $ RegistryClass#; |
| 37 | |
| 38 | struct _Registrycxx . . $ _Registry# |
| 39 | { |
| 40 | XdpDbusHostRegistrySkeletoncxx . . $ XdpDbusHostRegistrySkeleton# parent_instancecxx . . $ _Registry#parent_instance.; |
| 41 | |
| 42 | XdpAppInfoRegistrycxx . . $ XdpAppInfoRegistry# *app_info_registrycxx . . $ _Registry#app_info_registry.; |
| 43 | }; |
| 44 | |
| 45 | struct _RegistryClasscxx . . $ _RegistryClass# |
| 46 | { |
| 47 | XdpDbusHostRegistrySkeletonClasscxx . . $ XdpDbusHostRegistrySkeletonClass# parent_classcxx . . $ _RegistryClass#parent_class.; |
| 48 | }; |
| 49 | |
| 50 | GTypecxx . . $ GType# registry_get_typecxx . . $ registry_get_type(f708dce9a8856c70). (void) G_GNUC_CONSTcxx . . $ `<external>/12741050725406041920/gmacros.h:640:9`!; |
| 51 | static void registry_iface_initcxx . . $ registry_iface_init(dc6078a7837537d1). (XdpDbusHostRegistryIfacecxx . . $ XdpDbusHostRegistryIface# *iface); |
| 52 | |
| 53 | G_DEFINE_TYPE_WITH_CODEcxx . . $ `<external>/9567554376676449156/gtype.h:1850:9`! (Registry, registry, |
| 54 | XDP_DBUS_HOST_TYPE_REGISTRY_SKELETONcxx . . $ `build/src/xdp-host-dbus.h:161:9`!, |
| 55 | G_IMPLEMENT_INTERFACEcxx . . $ `<external>/9567554376676449156/gtype.h:2115:9`! (XDP_DBUS_HOST_TYPE_REGISTRYcxx . . $ `build/src/xdp-host-dbus.h:20:9`!, |
| 56 | registry_iface_init)); |
| 57 | |
| 58 | G_DEFINE_AUTOPTR_CLEANUP_FUNCcxx . . $ `<external>/12741050725406041920/gmacros.h:1414:9`! (Registry, g_object_unref) |
| 59 | |
| 60 | static XdpAppInfocxx . . $ XdpAppInfo# * |
| 61 | register_host_app_info_synccxx . . $ register_host_app_info_sync(473aab957c475781). (Registrycxx . . $ Registry# *registry, |
| 62 | GDBusMethodInvocationcxx . . $ GDBusMethodInvocation# *invocation, |
| 63 | const char *app_id, |
| 64 | GCancellablecxx . . $ GCancellable# *cancellable, |
| 65 | GErrorcxx . . $ GError# **error) |
| 66 | { |
| 67 | XdpAppInfoRegistrycxx . . $ XdpAppInfoRegistry# *app_info_registry = registry->app_info_registrycxx . . $ _Registry#app_info_registry.; |
| 68 | const char *sender = g_dbus_method_invocation_get_sendercxx . . $ g_dbus_method_invocation_get_sender(fb2cbbb785aa0d4d). (invocation); |
| 69 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(XdpAppInfo) detected_app_info = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 70 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(XdpAppInfo) app_info = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 71 | |
| 72 | if (xdp_app_info_registry_has_sendercxx . . $ xdp_app_info_registry_has_sender(859c0d8b1599e1). (app_info_registry, sender)) |
| 73 | { |
| 74 | g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error, G_IO_ERRORcxx . . $ `<external>/13894955190784973534/gioerror.h:42:9`!, G_IO_ERROR_FAILEDcxx . . $ G_IO_ERROR_FAILED., |
| 75 | "Connection already associated with an application ID"); |
| 76 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | } |
| 78 | |
| 79 | detected_app_info = xdp_app_info_new_for_invocation_synccxx . . $ xdp_app_info_new_for_invocation_sync(7df874a0e17f464e). (invocation, |
| 80 | cancellable, |
| 81 | error); |
| 82 | if (!detected_app_info) |
| 83 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | |
| 85 | if (!xdp_app_info_is_hostcxx . . $ xdp_app_info_is_host(ac6b23a20a03546d). (detected_app_info)) |
| 86 | { |
| 87 | g_set_errorcxx . . $ g_set_error(ca0c191bc68fc328). (error, G_IO_ERRORcxx . . $ `<external>/13894955190784973534/gioerror.h:42:9`!, G_IO_ERROR_FAILEDcxx . . $ G_IO_ERROR_FAILED., |
| 88 | "Can't manually register a %s application", |
| 89 | xdp_app_info_get_engine_display_namecxx . . $ xdp_app_info_get_engine_display_name(b9a768ac644c9329). (detected_app_info)); |
| 90 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 91 | } |
| 92 | |
| 93 | app_info = xdp_app_info_new_for_registered_synccxx . . $ xdp_app_info_new_for_registered_sync(b491a54df00c9fc2). (invocation, |
| 94 | app_id, |
| 95 | cancellable, |
| 96 | error); |
| 97 | if (!app_info) |
| 98 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 99 | |
| 100 | g_debugcxx . . $ `<external>/5169755362661750954/gmessages.h:371:9`! ("Adding registered host app '%s'", xdp_app_info_get_id (app_info)); |
| 101 | |
| 102 | xdp_app_info_registry_insertcxx . . $ xdp_app_info_registry_insert(14db9cfcf10eb8b7). (app_info_registry, app_info); |
| 103 | |
| 104 | return g_steal_pointercxx . . $ `<external>/1123956534522462559/gmem.h:250:9`! (&app_info); |
| 105 | } |
| 106 | |
| 107 | static gbooleancxx . . $ gboolean# |
| 108 | handle_registercxx . . $ handle_register(58174fb911022649). (XdpDbusHostRegistrycxx . . $ XdpDbusHostRegistry# *object, |
| 109 | GDBusMethodInvocationcxx . . $ GDBusMethodInvocation# *invocation, |
| 110 | const char *arg_app_id, |
| 111 | GVariantcxx . . $ GVariant# *arg_options) |
| 112 | { |
| 113 | Registrycxx . . $ Registry# *registry = (Registrycxx . . $ Registry# *) object; |
| 114 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(XdpAppInfo) app_info = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 115 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(GError) error = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 116 | |
| 117 | app_info = register_host_app_info_synccxx . . $ register_host_app_info_sync(473aab957c475781). (registry, |
| 118 | invocation, |
| 119 | arg_app_id, |
| 120 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 121 | &error); |
| 122 | if (!app_info) |
| 123 | { |
| 124 | g_dbus_method_invocation_return_errorcxx . . $ g_dbus_method_invocation_return_error(2860f9a06c72d77e). (invocation, |
| 125 | XDG_DESKTOP_PORTAL_ERRORcxx . . $ `src/xdp-utils.h:115:9`!, |
| 126 | XDG_DESKTOP_PORTAL_ERROR_FAILEDcxx . . $ XDG_DESKTOP_PORTAL_ERROR_FAILED., |
| 127 | "Could not register app ID: %s", |
| 128 | error->messagecxx . . $ _GError#message.); |
| 129 | return G_DBUS_METHOD_INVOCATION_HANDLEDcxx . . $ `<external>/7877694576918326146/gdbusmethodinvocation.h:56:9`!; |
| 130 | } |
| 131 | |
| 132 | if (g_strcmp0cxx . . $ g_strcmp0(5ae29d726ae57f88). (xdp_app_info_get_idcxx . . $ xdp_app_info_get_id(b9a768ac644c9329). (app_info), arg_app_id) != 0) |
| 133 | { |
| 134 | g_dbus_method_invocation_return_errorcxx . . $ g_dbus_method_invocation_return_error(2860f9a06c72d77e). (invocation, |
| 135 | XDG_DESKTOP_PORTAL_ERRORcxx . . $ `src/xdp-utils.h:115:9`!, |
| 136 | XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENTcxx . . $ XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT., |
| 137 | "Registered too late"); |
| 138 | return G_DBUS_METHOD_INVOCATION_HANDLEDcxx . . $ `<external>/7877694576918326146/gdbusmethodinvocation.h:56:9`!; |
| 139 | } |
| 140 | |
| 141 | xdp_dbus_host_registry_complete_registercxx . . $ xdp_dbus_host_registry_complete_register(49b676f31f8df841). (object, invocation); |
| 142 | |
| 143 | return G_DBUS_METHOD_INVOCATION_HANDLEDcxx . . $ `<external>/7877694576918326146/gdbusmethodinvocation.h:56:9`!; |
| 144 | } |
| 145 | |
| 146 | static void |
| 147 | registry_iface_initcxx . . $ registry_iface_init(dc6078a7837537d1). (XdpDbusHostRegistryIfacecxx . . $ XdpDbusHostRegistryIface# *iface) |
| 148 | { |
| 149 | iface->handle_registercxx . . $ _XdpDbusHostRegistryIface#handle_register. = handle_registercxx . . $ handle_register(58174fb911022649).; |
| 150 | } |
| 151 | |
| 152 | static void |
| 153 | registry_disposecxx . . $ registry_dispose(6087475fa43034d3). (GObjectcxx . . $ GObject# *object) |
| 154 | { |
| 155 | Registrycxx . . $ Registry# *registry = (Registrycxx . . $ Registry# *) object; |
| 156 | |
| 157 | g_clear_objectcxx . . $ `<external>/1341695927569185362/gobject.h:695:9`! (®istry->app_info_registry); |
| 158 | |
| 159 | G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (registry_parent_class)->disposecxx . . $ _GObjectClass#dispose. (object); |
| 160 | } |
| 161 | |
| 162 | static void |
| 163 | registry_initcxx . . $ registry_init(86fa14a7b5184672). (Registrycxx . . $ Registry# *registry) |
| 164 | { |
| 165 | } |
| 166 | |
| 167 | static void |
| 168 | registry_class_initcxx . . $ registry_class_init(1cf434604a717f60). (RegistryClasscxx . . $ RegistryClass# *klass) |
| 169 | { |
| 170 | GObjectClasscxx . . $ GObjectClass# *object_class = G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (klass); |
| 171 | |
| 172 | object_class->disposecxx . . $ _GObjectClass#dispose. = registry_disposecxx . . $ registry_dispose(6087475fa43034d3).; |
| 173 | } |
| 174 | |
| 175 | static Registrycxx . . $ Registry# * |
| 176 | registry_newcxx . . $ registry_new(f6a74a63cc9cae5a). (XdpAppInfoRegistrycxx . . $ XdpAppInfoRegistry# *app_info_registry) |
| 177 | { |
| 178 | Registrycxx . . $ Registry# *registry; |
| 179 | |
| 180 | registry = g_object_newcxx . . $ g_object_new(8485fe61b4be4c78). (registry_get_typecxx . . $ registry_get_type(f708dce9a8856c70). (), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 181 | registry->app_info_registrycxx . . $ _Registry#app_info_registry. = g_object_refcxx . . $ `<external>/1341695927569185362/gobject.h:533:9`! (app_info_registry); |
| 182 | |
| 183 | xdp_dbus_host_registry_set_versioncxx . . $ xdp_dbus_host_registry_set_version(5a65e79fe5c6ce0). (XDP_DBUS_HOST_REGISTRYcxx . . $ `build/src/xdp-host-dbus.h:21:9`! (registry), 1); |
| 184 | |
| 185 | return registry; |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | init_registrycxx . . $ init_registry(7d190a42f72e5c4f). (XdpContextcxx . . $ XdpContext# *context) |
| 190 | { |
| 191 | g_autoptrcxx . . $ `<external>/12741050725406041920/gmacros.h:1424:9`!(Registry) registry = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 192 | XdpAppInfoRegistrycxx . . $ XdpAppInfoRegistry# *app_info_registry = |
| 193 | xdp_context_get_app_info_registrycxx . . $ xdp_context_get_app_info_registry(1aaec1ac2d18e9a2). (context); |
| 194 | |
| 195 | registry = registry_newcxx . . $ registry_new(f6a74a63cc9cae5a). (app_info_registry); |
| 196 | |
| 197 | xdp_context_take_and_export_portalcxx . . $ xdp_context_take_and_export_portal(54303e2939dd494f). (context, |
| 198 | G_DBUS_INTERFACE_SKELETONcxx . . $ `<external>/1991948168568871819/gdbusinterfaceskeleton.h:32:9`! (g_steal_pointercxx . . $ `<external>/1123956534522462559/gmem.h:250:9`! (®istry)), |
| 199 | XDP_CONTEXT_EXPORT_FLAGS_HOST_PORTALcxx . . $ XDP_CONTEXT_EXPORT_FLAGS_HOST_PORTAL.); |
| 200 | } |