This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathglib-network-monitor-Update-portal-implementation.patch
428 lines (405 loc) · 14.5 KB
/
glib-network-monitor-Update-portal-implementation.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
From 5ed808d7c497d6861c1588911edb1f1b4ff59d96 Mon Sep 17 00:00:00 2001
From: Matthias Clasen <[email protected]>
Date: Fri, 20 Jul 2018 18:53:57 -0400
Subject: [PATCH] network monitor: Update portal implementation
The network monitor portal interface is changing.
Version 2 is no longer using properties, but getters
instead (this lets the portal apply access control
and avoid sending information to non-networked
sandboxes).
To support both version 1 and 2 of the interface,
we stop using generated code and instead deal with
the api differences in our own code, which is not
too difficult.
Support version 1 as well
---
gio/gnetworkmonitorportal.c | 236 +++++++++++++++---
gio/org.freedesktop.portal.NetworkMonitor.xml | 81 +++++-
2 files changed, 278 insertions(+), 39 deletions(-)
diff --git a/gio/gnetworkmonitorportal.c b/gio/gnetworkmonitorportal.c
index 856f8aa5b..16249ac55 100644
--- a/gio/gnetworkmonitorportal.c
+++ b/gio/gnetworkmonitorportal.c
@@ -21,7 +21,6 @@
#include "gnetworkmonitorportal.h"
#include "ginitable.h"
#include "giomodule-priv.h"
-#include "gnetworkmonitor.h"
#include "xdp-dbus.h"
#include "gportalsupport.h"
@@ -39,8 +38,13 @@ enum
struct _GNetworkMonitorPortalPrivate
{
- GXdpNetworkMonitor *proxy;
- gboolean network_available;
+ GDBusProxy *proxy;
+ gboolean has_network;
+ int version;
+
+ gboolean available;
+ gboolean metered;
+ GNetworkConnectivity connectivity;
};
G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorPortal, g_network_monitor_portal, G_TYPE_NETWORK_MONITOR_BASE,
@@ -72,22 +76,15 @@ g_network_monitor_portal_get_property (GObject *object,
switch (prop_id)
{
case PROP_NETWORK_AVAILABLE:
- g_value_set_boolean (value,
- nm->priv->network_available &&
- gxdp_network_monitor_get_available (nm->priv->proxy));
+ g_value_set_boolean (value, nm->priv->available);
break;
case PROP_NETWORK_METERED:
- g_value_set_boolean (value,
- nm->priv->network_available &&
- gxdp_network_monitor_get_metered (nm->priv->proxy));
+ g_value_set_boolean (value, nm->priv->metered);
break;
case PROP_CONNECTIVITY:
- g_value_set_enum (value,
- nm->priv->network_available
- ? gxdp_network_monitor_get_connectivity (nm->priv->proxy)
- : G_NETWORK_CONNECTIVITY_LOCAL);
+ g_value_set_enum (value, nm->priv->connectivity);
break;
default:
@@ -97,22 +94,184 @@ g_network_monitor_portal_get_property (GObject *object,
}
static void
-proxy_changed (GXdpNetworkMonitor *proxy,
- gboolean available,
- GNetworkMonitorPortal *nm)
+got_available (GObject *source,
+ GAsyncResult *res,
+ gpointer data)
{
- if (nm->priv->network_available)
- g_signal_emit_by_name (nm, "network-changed", available);
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ GNetworkMonitorPortal *nm = G_NETWORK_MONITOR_PORTAL (data);
+ GError *error = NULL;
+ GVariant *ret;
+ gboolean available;
+
+ ret = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (ret == NULL)
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ g_variant_get (ret, "(b)", &available);
+ g_variant_unref (ret);
+
+ if (nm->priv->available != available)
+ {
+ nm->priv->available = available;
+ g_object_notify (G_OBJECT (nm), "network-available");
+ g_signal_emit_by_name (nm, "network-changed", available);
+ }
}
+static void
+got_metered (GObject *source,
+ GAsyncResult *res,
+ gpointer data)
+{
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ GNetworkMonitorPortal *nm = G_NETWORK_MONITOR_PORTAL (data);
+ GError *error = NULL;
+ GVariant *ret;
+ gboolean metered;
+
+ ret = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (ret == NULL)
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ g_variant_get (ret, "(b)", &metered);
+ g_variant_unref (ret);
+
+ if (nm->priv->metered != metered)
+ {
+ nm->priv->metered = metered;
+ g_object_notify (G_OBJECT (nm), "network-metered");
+ }
+}
+
+static void
+got_connectivity (GObject *source,
+ GAsyncResult *res,
+ gpointer data)
+{
+ GDBusProxy *proxy = G_DBUS_PROXY (source);
+ GNetworkMonitorPortal *nm = G_NETWORK_MONITOR_PORTAL (data);
+ GError *error = NULL;
+ GVariant *ret;
+ GNetworkConnectivity connectivity;
+
+ ret = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (ret == NULL)
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ g_variant_get (ret, "(u)", &connectivity);
+ g_variant_unref (ret);
+
+ if (nm->priv->connectivity != connectivity)
+ {
+ nm->priv->connectivity = connectivity;
+ g_object_notify (G_OBJECT (nm), "connectivity");
+ }
+}
+
+static void
+proxy_signal (GDBusProxy *proxy,
+ const char *sender,
+ const char *signal,
+ GVariant *parameters,
+ GNetworkMonitorPortal *nm)
+{
+ if (!nm->priv->has_network)
+ return;
+
+ if (nm->priv->version == 1)
+ {
+ gboolean available;
+
+ g_variant_get (parameters, "(b)", &available);
+ g_signal_emit_by_name (nm, "network-changed", available);
+ }
+ else if (nm->priv->version == 2)
+ {
+ g_dbus_proxy_call (proxy, "GetConnectivity", NULL, 0, -1, NULL, got_connectivity, nm);
+ g_dbus_proxy_call (proxy, "GetMetered", NULL, 0, -1, NULL, got_metered, nm);
+ g_dbus_proxy_call (proxy, "GetAvailable", NULL, 0, -1, NULL, got_available, nm);
+ }
+}
+
+static void
+proxy_properties_changed (GDBusProxy *proxy,
+ GVariant *changed,
+ GVariant *invalidated,
+ GNetworkMonitorPortal *nm)
+{
+ if (!nm->priv->has_network)
+ return;
+
+ if (nm->priv->version == 1)
+ {
+ GVariant *ret;
+
+ ret = g_dbus_proxy_get_cached_property (proxy, "connectivity");
+ if (ret)
+ {
+ GNetworkConnectivity connectivity = g_variant_get_uint32 (ret);
+ if (nm->priv->connectivity != connectivity)
+ {
+ nm->priv->connectivity = connectivity;
+ g_object_notify (G_OBJECT (nm), "connectivity");
+ }
+ g_variant_unref (ret);
+ }
+
+ ret = g_dbus_proxy_get_cached_property (proxy, "metered");
+ if (ret)
+ {
+ gboolean metered = g_variant_get_boolean (ret);
+ if (nm->priv->metered != metered)
+ {
+ nm->priv->metered = metered;
+ g_object_notify (G_OBJECT (nm), "network-metered");
+ }
+ g_variant_unref (ret);
+ }
+
+ ret = g_dbus_proxy_get_cached_property (proxy, "available");
+ if (ret)
+ {
+ gboolean available = g_variant_get_boolean (ret);
+ if (nm->priv->available != available)
+ {
+ nm->priv->available = available;
+ g_object_notify (G_OBJECT (nm), "network-available");
+ g_signal_emit_by_name (nm, "network-changed", available);
+ }
+ g_variant_unref (ret);
+ }
+ }
+}
+
static gboolean
g_network_monitor_portal_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
GNetworkMonitorPortal *nm = G_NETWORK_MONITOR_PORTAL (initable);
- GXdpNetworkMonitor *proxy;
+ GDBusProxy *proxy;
gchar *name_owner = NULL;
+ int version;
+ GVariant *ret;
+
+ nm->priv->available = FALSE;
+ nm->priv->metered = FALSE;
+ nm->priv->connectivity = G_NETWORK_CONNECTIVITY_LOCAL;
if (!glib_should_use_portal ())
{
@@ -120,17 +279,19 @@ g_network_monitor_portal_initable_init (GInitable *initable,
return FALSE;
}
- proxy = gxdp_network_monitor_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
- | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
- "org.freedesktop.portal.Desktop",
- "/org/freedesktop/portal/desktop",
- cancellable,
- error);
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
+ | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
+ NULL,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.NetworkMonitor",
+ cancellable,
+ error);
if (!proxy)
return FALSE;
- name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
+ name_owner = g_dbus_proxy_get_name_owner (proxy);
if (!name_owner)
{
@@ -144,9 +305,26 @@ g_network_monitor_portal_initable_init (GInitable *initable,
g_free (name_owner);
- g_signal_connect (proxy, "changed", G_CALLBACK (proxy_changed), nm);
+ ret = g_dbus_proxy_get_cached_property (proxy, "version");
+ g_variant_get (ret, "u", &version);
+ g_variant_unref (ret);
+
+ if (version != 1 && version != 2)
+ {
+ g_object_unref (proxy);
+ g_set_error (error,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "NetworkMonitor portal unsupported version: %d", version);
+ return FALSE;
+ }
+
+ g_signal_connect (proxy, "g-signal", G_CALLBACK (proxy_signal), nm);
+ g_signal_connect (proxy, "g-properties-changed", G_CALLBACK (proxy_properties_changed), nm);
+
nm->priv->proxy = proxy;
- nm->priv->network_available = glib_network_available_in_sandbox ();
+ nm->priv->has_network = glib_network_available_in_sandbox ();
+ nm->priv->version = version;
return initable_parent_iface->init (initable, cancellable, error);
}
diff --git a/gio/org.freedesktop.portal.NetworkMonitor.xml b/gio/org.freedesktop.portal.NetworkMonitor.xml
index 8d3a471d5..fb551d6ed 100644
--- a/gio/org.freedesktop.portal.NetworkMonitor.xml
+++ b/gio/org.freedesktop.portal.NetworkMonitor.xml
@@ -5,25 +5,86 @@
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
+ version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library. If not, see <http://www.gnu.org/licenses/>.
Author: Matthias Clasen <[email protected]>
-->
-<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" name="/">
+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
+ <!--
+ org.freedesktop.portal.NetworkMonitor:
+ @short_description: Network monitoring portal
+
+ The NetworkMonitor interface provides network status information
+ to sandboxed applications. It is not a portal in the strict sense,
+ since it does not involve user interaction. Applications are
+ expected to use this interface indirectly, via a library API
+ such as the GLib GNetworkMonitor interface.
+
+ This documentation describes version 2 of this interface.
+ -->
<interface name="org.freedesktop.portal.NetworkMonitor">
- <signal name="changed">
- <arg type="b" name="available"/>
- </signal>
- <property name="available" type="b" access="read"/>
- <property name="metered" type="b" access="read"/>
- <property name="connectivity" type="u" access="read"/>
+ <!--
+ changed:
+
+ Emitted when the network configuration changes.
+ -->
+ <signal name="changed"/>
+ <!--
+ GetAvailable:
+ @available: whether the network is available
+
+ Returns whether the network is considered available.
+ That is, whether the system as a default route for
+ at least one of IPv4 or IPv6.
+
+ This method was added in version 2 to replace
+ the available property.
+ -->
+ <method name="GetAvailable">
+ <arg type='b' name='available' direction='out'/>
+ </method>
+ <!--
+ GetMetered:
+ @metered: whether the network is metered
+
+ Returns whether the network is considered metered.
+ That is, whether the system as traffic flowing through
+ the default connection that is subject ot limitations
+ by service providers.
+
+ This method was added in version 2 to replace
+ the metered property.
+ -->
+ <method name="GetMetered">
+ <arg type='b' name='metered' direction='out'/>
+ </method>
+ <!--
+ GetConnectivity:
+ @connectivity: the level of connectivity
+
+ Returs more detailed information about the host's network
+ connectivity. The meaning of the value is:
+ <simplelist>
+ <member>1: Local only. The host is not configured with a route to the internet.</member>
+ <member>2: Limited connectivity. The host is connected to a network, but can't reach the full internet.</member>
+ <member>3: Captive portal. The host is behind a captive portal and cannot reach the full internet.</member>
+ <member>4: Full network. The host connected to a network, and can reach the full internet.</member>
+ </simplelist>
+
+ This method was added in version 2 to replace
+ the connectivity property.
+ -->
+ <method name="GetConnectivity">
+ <arg type='u' name='connectivity' direction='out'/>
+ </method>
+ <property name="version" type="u" access="read"/>
</interface>
</node>
--
2.17.1