Migrated NM frontend plugin to NetworkManager 0.9
[strongswan.git] / src / frontends / gnome / properties / nm-strongswan.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 * Copyright (C) 2005 David Zeuthen
5 * Copyright (C) 2005-2008 Dan Williams
6 *
7 * Based on NetworkManager's vpnc plugin
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <glib.h>
25 #include <glib/gi18n-lib.h>
26 #include <gtk/gtk.h>
27
28 #define NM_VPN_API_SUBJECT_TO_CHANGE
29
30 #include <nm-vpn-plugin-ui-interface.h>
31 #include <nm-setting-vpn.h>
32 #include <nm-setting-connection.h>
33 #include <nm-setting-ip4-config.h>
34
35 #include "nm-strongswan.h"
36
37 #define STRONGSWAN_PLUGIN_NAME _("IPsec/IKEv2 (strongswan)")
38 #define STRONGSWAN_PLUGIN_DESC _("IPsec with the IKEv2 key exchange protocol.")
39 #define STRONGSWAN_PLUGIN_SERVICE "org.freedesktop.NetworkManager.strongswan"
40 #define NM_DBUS_SERVICE_STRONGSWAN "org.freedesktop.NetworkManager.strongswan"
41
42 /************** plugin class **************/
43
44 static void strongswan_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class);
45
46 G_DEFINE_TYPE_EXTENDED (StrongswanPluginUi, strongswan_plugin_ui, G_TYPE_OBJECT, 0,
47 G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_INTERFACE,
48 strongswan_plugin_ui_interface_init))
49
50 /************** UI widget class **************/
51
52 static void strongswan_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class);
53
54 G_DEFINE_TYPE_EXTENDED (StrongswanPluginUiWidget, strongswan_plugin_ui_widget, G_TYPE_OBJECT, 0,
55 G_IMPLEMENT_INTERFACE (NM_TYPE_VPN_PLUGIN_UI_WIDGET_INTERFACE,
56 strongswan_plugin_ui_widget_interface_init))
57
58 #define STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), STRONGSWAN_TYPE_PLUGIN_UI_WIDGET, StrongswanPluginUiWidgetPrivate))
59
60 typedef struct {
61 GtkBuilder *builder;
62 GtkWidget *widget;
63 } StrongswanPluginUiWidgetPrivate;
64
65
66 #define STRONGSWAN_PLUGIN_UI_ERROR strongswan_plugin_ui_error_quark ()
67
68 static GQuark
69 strongswan_plugin_ui_error_quark (void)
70 {
71 static GQuark error_quark = 0;
72
73 if (G_UNLIKELY (error_quark == 0))
74 error_quark = g_quark_from_static_string ("strongswan-plugin-ui-error-quark");
75
76 return error_quark;
77 }
78
79 #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
80
81 GType
82 strongswan_plugin_ui_error_get_type (void)
83 {
84 static GType etype = 0;
85
86 if (etype == 0) {
87 static const GEnumValue values[] = {
88 /* Unknown error. */
89 ENUM_ENTRY (STRONGSWAN_PLUGIN_UI_ERROR_UNKNOWN, "UnknownError"),
90 /* The specified property was invalid. */
91 ENUM_ENTRY (STRONGSWAN_PLUGIN_UI_ERROR_INVALID_PROPERTY, "InvalidProperty"),
92 /* The specified property was missing and is required. */
93 ENUM_ENTRY (STRONGSWAN_PLUGIN_UI_ERROR_MISSING_PROPERTY, "MissingProperty"),
94 { 0, 0, 0 }
95 };
96 etype = g_enum_register_static ("StrongswanPluginUiError", values);
97 }
98 return etype;
99 }
100
101 static gboolean
102 check_validity (StrongswanPluginUiWidget *self, GError **error)
103 {
104 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
105 GtkWidget *widget;
106 char *str;
107
108 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "address-entry"));
109 str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
110 if (!str || !strlen (str)) {
111 g_set_error (error,
112 STRONGSWAN_PLUGIN_UI_ERROR,
113 STRONGSWAN_PLUGIN_UI_ERROR_INVALID_PROPERTY,
114 "address");
115 return FALSE;
116 }
117 return TRUE;
118 }
119
120 static void update_layout (GtkWidget *widget, StrongswanPluginUiWidgetPrivate *priv)
121 {
122 switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)))
123 {
124 default:
125 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
126 /* FALL */
127 case 0:
128 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-label")));
129 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button")));
130 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-label")));
131 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button")));
132 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-label")));
133 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry")));
134 break;
135 case 1:
136 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-label")));
137 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button")));
138 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-label")));
139 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry")));
140 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-label")));
141 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button")));
142 break;
143 case 2:
144 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-label")));
145 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button")));
146 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-label")));
147 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry")));
148 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-label")));
149 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button")));
150 break;
151 case 3:
152 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-label")));
153 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry")));
154 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-label")));
155 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button")));
156 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-label")));
157 gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button")));
158 break;
159 }
160
161 }
162
163 static void
164 settings_changed_cb (GtkWidget *widget, gpointer user_data)
165 {
166 StrongswanPluginUiWidget *self = STRONGSWAN_PLUGIN_UI_WIDGET (user_data);
167 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
168
169 if (widget == GTK_WIDGET (gtk_builder_get_object (priv->builder, "method-combo")))
170 {
171 update_layout(GTK_WIDGET (gtk_builder_get_object (priv->builder, "method-combo")), priv);
172 }
173 g_signal_emit_by_name (STRONGSWAN_PLUGIN_UI_WIDGET (user_data), "changed");
174 }
175
176 static gboolean
177 init_plugin_ui (StrongswanPluginUiWidget *self, NMConnection *connection, GError **error)
178 {
179 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
180 NMSettingVPN *settings;
181 GtkWidget *widget;
182 const char *value;
183
184 settings = NM_SETTING_VPN(nm_connection_get_setting(connection, NM_TYPE_SETTING_VPN));
185 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "address-entry"));
186 value = nm_setting_vpn_get_data_item (settings, "address");
187 if (value)
188 gtk_entry_set_text (GTK_ENTRY (widget), value);
189 g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (settings_changed_cb), self);
190
191 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "certificate-button"));
192 value = nm_setting_vpn_get_data_item (settings, "certificate");
193 if (value)
194 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
195 g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (settings_changed_cb), self);
196
197 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-label"));
198 gtk_widget_set_no_show_all (widget, TRUE);
199 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry"));
200 gtk_widget_set_no_show_all (widget, TRUE);
201 value = nm_setting_vpn_get_data_item (settings, "user");
202 if (value)
203 gtk_entry_set_text (GTK_ENTRY (widget), value);
204 g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (settings_changed_cb), self);
205
206 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "method-combo"));
207 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("Certificate/private key"));
208 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("Certificate/ssh-agent"));
209 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("Smartcard"));
210 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), _("EAP"));
211 value = nm_setting_vpn_get_data_item (settings, "method");
212 if (value) {
213 if (g_strcmp0 (value, "key") == 0) {
214 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
215 }
216 if (g_strcmp0 (value, "agent") == 0) {
217 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1);
218 }
219 if (g_strcmp0 (value, "smartcard") == 0) {
220 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2);
221 }
222 if (g_strcmp0 (value, "eap") == 0) {
223 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 3);
224 }
225 }
226 if (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == -1)
227 {
228 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
229 }
230 update_layout (widget, priv);
231 g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (settings_changed_cb), self);
232
233 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-label"));
234 gtk_widget_set_no_show_all (widget, TRUE);
235 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button"));
236 gtk_widget_set_no_show_all (widget, TRUE);
237 value = nm_setting_vpn_get_data_item (settings, "usercert");
238 if (value)
239 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
240 g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (settings_changed_cb), self);
241
242 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-label"));
243 gtk_widget_set_no_show_all (widget, TRUE);
244 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button"));
245 gtk_widget_set_no_show_all (widget, TRUE);
246 value = nm_setting_vpn_get_data_item (settings, "userkey");
247 if (value)
248 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
249 g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (settings_changed_cb), self);
250
251 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "virtual-check"));
252 value = nm_setting_vpn_get_data_item (settings, "virtual");
253 if (value && strcmp(value, "yes") == 0)
254 {
255 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
256 }
257 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (settings_changed_cb), self);
258
259 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "encap-check"));
260 value = nm_setting_vpn_get_data_item (settings, "encap");
261 if (value && strcmp(value, "yes") == 0)
262 {
263 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
264 }
265 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (settings_changed_cb), self);
266
267 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "ipcomp-check"));
268 value = nm_setting_vpn_get_data_item (settings, "ipcomp");
269 if (value && strcmp(value, "yes") == 0)
270 {
271 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
272 }
273 g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (settings_changed_cb), self);
274
275 return TRUE;
276 }
277
278 static GObject *
279 get_widget (NMVpnPluginUiWidgetInterface *iface)
280 {
281 StrongswanPluginUiWidget *self = STRONGSWAN_PLUGIN_UI_WIDGET (iface);
282 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
283
284 return G_OBJECT (priv->widget);
285 }
286
287 static gboolean
288 update_connection (NMVpnPluginUiWidgetInterface *iface,
289 NMConnection *connection,
290 GError **error)
291 {
292 StrongswanPluginUiWidget *self = STRONGSWAN_PLUGIN_UI_WIDGET (iface);
293 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
294 NMSettingVPN *settings;
295 GtkWidget *widget;
296 gboolean active;
297 char *str;
298
299 if (!check_validity (self, error))
300 return FALSE;
301 settings = NM_SETTING_VPN (nm_setting_vpn_new ());
302
303 g_object_set (settings, NM_SETTING_VPN_SERVICE_TYPE,
304 NM_DBUS_SERVICE_STRONGSWAN, NULL);
305
306 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "address-entry"));
307 str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
308 if (str && strlen (str)) {
309 nm_setting_vpn_add_data_item (settings, "address", str);
310 }
311
312 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "certificate-button"));
313 str = (char *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
314 if (str) {
315 nm_setting_vpn_add_data_item (settings, "certificate", str);
316 }
317
318 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "method-combo"));
319 switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)))
320 {
321 default:
322 case 0:
323 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "userkey-button"));
324 str = (char *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
325 if (str) {
326 nm_setting_vpn_add_data_item (settings, "userkey", str);
327 }
328 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button"));
329 str = (char *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
330 if (str) {
331 nm_setting_vpn_add_data_item (settings, "usercert", str);
332 }
333 str = "key";
334 break;
335 case 1:
336 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "usercert-button"));
337 str = (char *) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
338 if (str) {
339 nm_setting_vpn_add_data_item (settings, "usercert", str);
340 }
341 str = "agent";
342 break;
343 case 2:
344 str = "smartcard";
345 break;
346 case 3:
347 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user-entry"));
348 str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
349 if (str && strlen (str)) {
350 nm_setting_vpn_add_data_item (settings, "user", str);
351 }
352 str = "eap";
353 break;
354 }
355 nm_setting_vpn_add_data_item (settings, "method", str);
356
357 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "virtual-check"));
358 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
359 nm_setting_vpn_add_data_item (settings, "virtual", active ? "yes" : "no");
360
361 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "encap-check"));
362 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
363 nm_setting_vpn_add_data_item (settings, "encap", active ? "yes" : "no");
364
365 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "ipcomp-check"));
366 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
367 nm_setting_vpn_add_data_item (settings, "ipcomp", active ? "yes" : "no");
368
369
370 if (!nm_setting_set_secret_flags (NM_SETTING (settings),
371 "password", NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL))
372 {
373 fprintf(stderr, "no\n");
374 }
375 else
376 {
377 fprintf(stderr, "yes\n");
378 }
379
380 nm_connection_add_setting (connection, NM_SETTING (settings));
381 return TRUE;
382 }
383
384 static NMVpnPluginUiWidgetInterface *
385 nm_vpn_plugin_ui_widget_interface_new (NMConnection *connection, GError **error)
386 {
387 NMVpnPluginUiWidgetInterface *object;
388 StrongswanPluginUiWidgetPrivate *priv;
389 char *ui_file;
390
391 if (error)
392 g_return_val_if_fail (*error == NULL, NULL);
393
394 object = NM_VPN_PLUGIN_UI_WIDGET_INTERFACE (g_object_new (STRONGSWAN_TYPE_PLUGIN_UI_WIDGET, NULL));
395 if (!object) {
396 g_set_error (error, STRONGSWAN_PLUGIN_UI_ERROR, 0, "could not create strongswan object");
397 return NULL;
398 }
399
400 priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (object);
401 ui_file = g_strdup_printf ("%s/%s", UIDIR, "nm-strongswan-dialog.ui");
402 priv->builder = gtk_builder_new ();
403
404 gtk_builder_set_translation_domain (priv->builder, GETTEXT_PACKAGE);
405
406 if (!gtk_builder_add_from_file (priv->builder, ui_file, error)) {
407 g_warning ("Couldn't load builder file: %s",
408 error && *error ? (*error)->message : "(unknown)");
409 g_clear_error (error);
410 g_set_error (error, STRONGSWAN_PLUGIN_UI_ERROR, 0,
411 "could not load required resources at %s", ui_file);
412 g_free (ui_file);
413 g_object_unref (object);
414 return NULL;
415 }
416 g_free (ui_file);
417
418 priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "strongswan-vbox") );
419 if (!priv->widget) {
420 g_set_error (error, STRONGSWAN_PLUGIN_UI_ERROR, 0, "could not load UI widget");
421 g_object_unref (object);
422 return NULL;
423 }
424 g_object_ref_sink (priv->widget);
425
426 if (!init_plugin_ui (STRONGSWAN_PLUGIN_UI_WIDGET (object), connection, error)) {
427 g_object_unref (object);
428 return NULL;
429 }
430
431 return object;
432 }
433
434 static void
435 dispose (GObject *object)
436 {
437 StrongswanPluginUiWidget *plugin = STRONGSWAN_PLUGIN_UI_WIDGET (object);
438 StrongswanPluginUiWidgetPrivate *priv = STRONGSWAN_PLUGIN_UI_WIDGET_GET_PRIVATE (plugin);
439
440 if (priv->widget)
441 g_object_unref (priv->widget);
442
443 if (priv->builder)
444 g_object_unref (priv->builder);
445
446 G_OBJECT_CLASS (strongswan_plugin_ui_widget_parent_class)->dispose (object);
447 }
448
449 static void
450 strongswan_plugin_ui_widget_class_init (StrongswanPluginUiWidgetClass *req_class)
451 {
452 GObjectClass *object_class = G_OBJECT_CLASS (req_class);
453
454 g_type_class_add_private (req_class, sizeof (StrongswanPluginUiWidgetPrivate));
455
456 object_class->dispose = dispose;
457 }
458
459 static void
460 strongswan_plugin_ui_widget_init (StrongswanPluginUiWidget *plugin)
461 {
462 }
463
464 static void
465 strongswan_plugin_ui_widget_interface_init (NMVpnPluginUiWidgetInterface *iface_class)
466 {
467 /* interface implementation */
468 iface_class->get_widget = get_widget;
469 iface_class->update_connection = update_connection;
470 }
471
472 static guint32
473 get_capabilities (NMVpnPluginUiInterface *iface)
474 {
475 return 0;
476 }
477
478 static NMVpnPluginUiWidgetInterface *
479 ui_factory (NMVpnPluginUiInterface *iface, NMConnection *connection, GError **error)
480 {
481 return nm_vpn_plugin_ui_widget_interface_new (connection, error);
482 }
483
484 static void
485 get_property (GObject *object, guint prop_id,
486 GValue *value, GParamSpec *pspec)
487 {
488 switch (prop_id) {
489 case NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME:
490 g_value_set_string (value, STRONGSWAN_PLUGIN_NAME);
491 break;
492 case NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC:
493 g_value_set_string (value, STRONGSWAN_PLUGIN_DESC);
494 break;
495 case NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE:
496 g_value_set_string (value, STRONGSWAN_PLUGIN_SERVICE);
497 break;
498 default:
499 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
500 break;
501 }
502 }
503
504 static void
505 strongswan_plugin_ui_class_init (StrongswanPluginUiClass *req_class)
506 {
507 GObjectClass *object_class = G_OBJECT_CLASS (req_class);
508
509 object_class->get_property = get_property;
510
511 g_object_class_override_property (object_class,
512 NM_VPN_PLUGIN_UI_INTERFACE_PROP_NAME,
513 NM_VPN_PLUGIN_UI_INTERFACE_NAME);
514
515 g_object_class_override_property (object_class,
516 NM_VPN_PLUGIN_UI_INTERFACE_PROP_DESC,
517 NM_VPN_PLUGIN_UI_INTERFACE_DESC);
518
519 g_object_class_override_property (object_class,
520 NM_VPN_PLUGIN_UI_INTERFACE_PROP_SERVICE,
521 NM_VPN_PLUGIN_UI_INTERFACE_SERVICE);
522 }
523
524 static void
525 strongswan_plugin_ui_init (StrongswanPluginUi *plugin)
526 {
527 }
528
529 static void
530 strongswan_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
531 {
532 /* interface implementation */
533 iface_class->ui_factory = ui_factory;
534 iface_class->get_capabilities = get_capabilities;
535 /* TODO: implement delete_connection to purge associated secrets */
536 }
537
538
539 G_MODULE_EXPORT NMVpnPluginUiInterface *
540 nm_vpn_plugin_ui_factory (GError **error)
541 {
542 if (error)
543 g_return_val_if_fail (*error == NULL, NULL);
544
545 return NM_VPN_PLUGIN_UI_INTERFACE (g_object_new (STRONGSWAN_TYPE_PLUGIN_UI, NULL));
546 }
547