~ubuntu-branches/ubuntu/precise/network-manager/precise

« back to all changes in this revision

Viewing changes to libnm-glib/nm-remote-connection.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-02-09 16:45:41 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20120209164541-4h90zknlsfdb7x35
Tags: 0.9.2.0+git201202091925.c721477-0ubuntu1
* upstream snapshot 2012-02-09 19:25:59 (GMT)
  + c721477d11d4fe144111d6d2eec8f93f2e9186c9
* debian/patches/avoid-periodic-disk-wakeups.patch: refreshed.
* debian/patches/nl3-default-ip6-route.patch: refreshed.
* debian/libnm-glib4.symbols: add symbols:
  + nm_active_connection_get_master@Base
  + nm_client_new_async@Base
  + nm_client_new_finish@Base
  + nm_remote_settings_new_async@Base
  + nm_remote_settings_new_finish@Base
  + nm_device_get_state_reason@Base
* debian/libnm-util2.symbols: add symbols:
  + nm_setting_802_1x_get_pac_file@Base
  + nm_setting_infiniband_get_transport_mode@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 */
23
23
 
24
24
#include <string.h>
 
25
#include <gio/gio.h>
25
26
 
26
27
#include <NetworkManager.h>
27
28
#include <nm-utils.h>
29
30
#include "nm-remote-connection.h"
30
31
#include "nm-remote-connection-private.h"
31
32
#include "nm-dbus-glib-types.h"
32
 
#include "nm-settings-connection-bindings.h"
 
33
#include "nm-glib-compat.h"
33
34
 
34
35
#define NM_REMOTE_CONNECTION_BUS "bus"
35
36
 
36
 
G_DEFINE_TYPE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION)
 
37
static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
 
38
static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface);
 
39
 
 
40
G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION,
 
41
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init);
 
42
                         G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init);
 
43
                         )
37
44
 
38
45
enum {
39
46
        PROP_0,
40
47
        PROP_BUS,
41
 
        PROP_INIT_RESULT,
42
48
 
43
49
        LAST_PROP
44
50
};
65
71
        DBusGProxy *proxy;
66
72
        GSList *calls;
67
73
 
68
 
        NMRemoteConnectionInitResult init_result;
69
74
        gboolean visible;
70
75
        gboolean disposed;
71
76
} NMRemoteConnectionPrivate;
89
94
}
90
95
 
91
96
static void
92
 
update_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
 
97
update_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
93
98
{
94
99
        RemoteCall *call = user_data;
95
100
        NMRemoteConnectionCommitFunc func = (NMRemoteConnectionCommitFunc) call->callback;
 
101
        GError *error = NULL;
96
102
 
 
103
        dbus_g_proxy_end_call (proxy, proxy_call, &error,
 
104
                               G_TYPE_INVALID);
97
105
        if (func != NULL)
98
106
                (*func)(call->self, error, call->user_data);
 
107
        g_clear_error (&error);
99
108
        remote_call_complete (call->self, call);
100
109
}
101
110
 
131
140
 
132
141
        settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL);
133
142
 
134
 
        call->call = org_freedesktop_NetworkManager_Settings_Connection_update_async (priv->proxy,
135
 
                                                                                      settings,
136
 
                                                                                      update_cb,
137
 
                                                                                      call);
 
143
        call->call = dbus_g_proxy_begin_call (priv->proxy, "Update",
 
144
                                              update_cb, call, NULL,
 
145
                                              DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
 
146
                                              G_TYPE_INVALID);
138
147
        g_assert (call->call);
139
148
        priv->calls = g_slist_append (priv->calls, call);
140
149
 
142
151
}
143
152
 
144
153
static void
145
 
delete_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
 
154
delete_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
146
155
{
147
156
        RemoteCall *call = user_data;
148
157
        NMRemoteConnectionDeleteFunc func = (NMRemoteConnectionDeleteFunc) call->callback;
 
158
        GError *error = NULL;
149
159
 
 
160
        dbus_g_proxy_end_call (proxy, proxy_call, &error,
 
161
                               G_TYPE_INVALID);
150
162
        if (func != NULL)
151
163
                (*func)(call->self, error, call->user_data);
 
164
        g_clear_error (&error);
152
165
        remote_call_complete (call->self, call);
153
166
}
154
167
 
178
191
        call->callback = (GFunc) callback;
179
192
        call->user_data = user_data;
180
193
 
181
 
        call->call = org_freedesktop_NetworkManager_Settings_Connection_delete_async (priv->proxy,
182
 
                                                                                      delete_cb,
183
 
                                                                                      call);
 
194
        call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete",
 
195
                                              delete_cb, call, NULL,
 
196
                                              G_TYPE_INVALID);
184
197
        g_assert (call->call);
185
198
        priv->calls = g_slist_append (priv->calls, call);
186
199
}
187
200
 
188
201
static void
189
 
get_secrets_cb (DBusGProxy *proxy, GHashTable *secrets, GError *error, gpointer user_data)
 
202
get_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
190
203
{
191
204
        RemoteCall *call = user_data;
192
205
        NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
 
206
        GHashTable *secrets;
 
207
        GError *error = NULL;
193
208
 
 
209
        dbus_g_proxy_end_call (proxy, proxy_call, &error,
 
210
                               DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets,
 
211
                               G_TYPE_INVALID);
194
212
        (*func)(call->self, error ? NULL : secrets, error, call->user_data);
 
213
        g_clear_error (&error);
195
214
        remote_call_complete (call->self, call);
196
215
}
197
216
 
225
244
        call->callback = (GFunc) callback;
226
245
        call->user_data = user_data;
227
246
 
228
 
        call->call = org_freedesktop_NetworkManager_Settings_Connection_get_secrets_async (priv->proxy,
229
 
                                                                                           setting_name,
230
 
                                                                                           get_secrets_cb,
231
 
                                                                                           call);
 
247
        call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets",
 
248
                                              get_secrets_cb, call, NULL,
 
249
                                              G_TYPE_STRING, setting_name,
 
250
                                              G_TYPE_INVALID);
232
251
        g_assert (call->call);
233
252
        priv->calls = g_slist_append (priv->calls, call);
234
253
}
255
274
}
256
275
 
257
276
static void
258
 
init_get_settings_cb (DBusGProxy *proxy,
259
 
                      GHashTable *new_settings,
260
 
                      GError *error,
261
 
                      gpointer user_data)
262
 
{
263
 
        NMRemoteConnection *self = user_data;
264
 
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
265
 
 
266
 
        if (error) {
267
 
                /* Connection doesn't exist, or isn't visible to this user */
268
 
                if (dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied"))
269
 
                        priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE;
270
 
                else
271
 
                        priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_ERROR;
272
 
 
273
 
                g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
274
 
        } else {
275
 
                priv->visible = TRUE;
276
 
                replace_settings (self, new_settings);
277
 
                g_hash_table_destroy (new_settings);
278
 
                priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS;
279
 
                g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
280
 
        }
281
 
}
282
 
 
283
 
static void
284
277
updated_get_settings_cb (DBusGProxy *proxy,
285
 
                         GHashTable *new_settings,
286
 
                         GError *error,
 
278
                         DBusGProxyCall *call,
287
279
                         gpointer user_data)
288
280
{
289
281
        NMRemoteConnection *self = user_data;
290
282
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
 
283
        GHashTable *new_settings;
 
284
        GError *error = NULL;
291
285
 
 
286
        dbus_g_proxy_end_call (proxy, call, &error,
 
287
                               DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
 
288
                               G_TYPE_INVALID);
292
289
        if (error) {
293
290
                GHashTable *hash;
294
291
 
 
292
                g_error_free (error);
 
293
 
295
294
                /* Connection is no longer visible to this user.  Let the settings
296
295
                 * service handle this via 'visible'.  The settings service will emit
297
296
                 * the "removed" signal for us since it handles the lifetime of this
322
321
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
323
322
 
324
323
        /* The connection got updated; request the replacement settings */
325
 
        org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
326
 
                                                                               updated_get_settings_cb,
327
 
                                                                               self);
 
324
        dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
 
325
                                 updated_get_settings_cb, self, NULL,
 
326
                                 G_TYPE_INVALID);
328
327
}
329
328
 
330
329
static void
357
356
                                                    NULL);
358
357
}
359
358
 
360
 
static GObject *
361
 
constructor (GType type,
362
 
             guint n_construct_params,
363
 
             GObjectConstructParam *construct_params)
 
359
static void
 
360
constructed (GObject *object)
364
361
{
365
 
        GObject *object;
366
362
        NMRemoteConnectionPrivate *priv;
367
363
 
368
 
        object = G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructor (type, n_construct_params, construct_params);
369
 
        if (!object)
370
 
                return NULL;
371
 
 
372
364
        priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
373
365
        g_assert (priv->bus);
374
366
        g_assert (nm_connection_get_path (NM_CONNECTION (object)));
385
377
 
386
378
        dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID);
387
379
        dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL);
388
 
 
389
 
        org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
390
 
                                                                               init_get_settings_cb,
391
 
                                                                               object);
392
 
        return object;
 
380
}
 
381
 
 
382
static gboolean
 
383
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
 
384
{
 
385
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
 
386
        GHashTable *settings;
 
387
 
 
388
        if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
 
389
                                G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS,
 
390
                                G_TYPE_INVALID,
 
391
                                DBUS_TYPE_G_MAP_OF_VARIANT, &settings,
 
392
                                G_TYPE_INVALID))
 
393
                return FALSE;
 
394
 
 
395
        priv->visible = TRUE;
 
396
        replace_settings (NM_REMOTE_CONNECTION (initable), settings);
 
397
        g_hash_table_destroy (settings);
 
398
        return TRUE;
 
399
}
 
400
 
 
401
typedef struct {
 
402
        NMRemoteConnection *connection;
 
403
        GSimpleAsyncResult *result;
 
404
} NMRemoteConnectionInitData;
 
405
 
 
406
static void
 
407
init_get_settings_cb (DBusGProxy *proxy,
 
408
                      DBusGProxyCall *call,
 
409
                      gpointer user_data)
 
410
{
 
411
        NMRemoteConnectionInitData *init_data = user_data;
 
412
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
 
413
        GHashTable *settings;
 
414
        GError *error = NULL;
 
415
 
 
416
        dbus_g_proxy_end_call (proxy, call, &error,
 
417
                               DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
 
418
                               G_TYPE_INVALID);
 
419
        if (error) {
 
420
                g_simple_async_result_take_error (init_data->result, error);
 
421
        } else {
 
422
                priv->visible = TRUE;
 
423
                replace_settings (init_data->connection, settings);
 
424
                g_hash_table_destroy (settings);
 
425
                g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
 
426
        }
 
427
 
 
428
        g_simple_async_result_complete (init_data->result);
 
429
        g_slice_free (NMRemoteConnectionInitData, init_data);
 
430
}
 
431
 
 
432
static void
 
433
init_async (GAsyncInitable *initable, int io_priority,
 
434
                        GCancellable *cancellable, GAsyncReadyCallback callback,
 
435
                        gpointer user_data)
 
436
{
 
437
        NMRemoteConnectionInitData *init_data;
 
438
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
 
439
 
 
440
 
 
441
        init_data = g_slice_new0 (NMRemoteConnectionInitData);
 
442
        init_data->connection = NM_REMOTE_CONNECTION (initable);
 
443
        init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
 
444
                                                       user_data, init_async);
 
445
 
 
446
        dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
 
447
                                 init_get_settings_cb, init_data, NULL,
 
448
                                 G_TYPE_INVALID);
 
449
 
393
450
}
394
451
 
395
452
static void
415
472
}
416
473
 
417
474
static void
418
 
get_property (GObject *object, guint prop_id,
419
 
              GValue *value, GParamSpec *pspec)
420
 
{
421
 
        NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
422
 
        NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
423
 
 
424
 
        switch (prop_id) {
425
 
        case PROP_INIT_RESULT:
426
 
                g_value_set_uint (value, priv->init_result);
427
 
                break;
428
 
        default:
429
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
430
 
                break;
431
 
        }
432
 
}
433
 
 
434
 
static void
435
475
dispose (GObject *object)
436
476
{
437
477
        NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
459
499
 
460
500
        /* virtual methods */
461
501
        object_class->set_property = set_property;
462
 
        object_class->get_property = get_property;
463
502
        object_class->dispose = dispose;
464
 
        object_class->constructor = constructor;
 
503
        object_class->constructed = constructed;
465
504
 
466
505
        /* Properties */
467
506
        g_object_class_install_property
472
511
                                                 DBUS_TYPE_G_CONNECTION,
473
512
                                                 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
474
513
 
475
 
        g_object_class_install_property
476
 
                (object_class, PROP_INIT_RESULT,
477
 
                 g_param_spec_uint (NM_REMOTE_CONNECTION_INIT_RESULT,
478
 
                                    "Initialization result (PRIVATE)",
479
 
                                    "Initialization result (PRIVATE)",
480
 
                                    NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
481
 
                                    NM_REMOTE_CONNECTION_INIT_RESULT_ERROR,
482
 
                                    NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
483
 
                                    G_PARAM_READABLE));
484
 
 
485
514
        /* Signals */
486
515
        /**
487
516
         * NMRemoteConnection::updated:
524
553
                              g_cclosure_marshal_VOID__BOOLEAN,
525
554
                              G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
526
555
}
 
556
 
 
557
static void
 
558
nm_remote_connection_initable_iface_init (GInitableIface *iface)
 
559
{
 
560
        iface->init = init_sync;
 
561
}
 
562
 
 
563
static void
 
564
nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface)
 
565
{
 
566
        iface->init_async = init_async;
 
567
}