[network-manager-openconnect/th/vpn-service-info-bgo767197: 2/2] properties: implement "get-service-info" call



commit 7073177b9e0ad622014bbdffea1d6ca1978630fa
Author: Thomas Haller <thaller redhat com>
Date:   Wed Jun 8 01:45:20 2016 +0200

    properties: implement "get-service-info" call
    
    This is needed by nm-connection-editor to provide the necessary
    information for adding new connections for the alternate service-types,
    that is, the aliases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767197

 properties/nm-openconnect.c |   68 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 67 insertions(+), 1 deletions(-)
---
diff --git a/properties/nm-openconnect.c b/properties/nm-openconnect.c
index ec1a3e8..dc28f04 100644
--- a/properties/nm-openconnect.c
+++ b/properties/nm-openconnect.c
@@ -595,9 +595,14 @@ update_connection (NMVpnEditor *iface,
        GtkTextIter iter_start, iter_end;
        GtkTextBuffer *buffer;
        const char *auth_type = NULL;
+       const char *service_type = NULL;
+
+       s_vpn = nm_connection_get_setting_vpn (connection);
+       if (s_vpn)
+               service_type = nm_setting_vpn_get_service_type (s_vpn);
 
        s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
-       g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_VPN_SERVICE_TYPE_OPENCONNECT, NULL);
+       g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type ?: NM_VPN_SERVICE_TYPE_OPENCONNECT, 
NULL);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
        str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
@@ -792,6 +797,63 @@ get_capabilities (NMVpnEditorPlugin *iface)
                NM_VPN_EDITOR_PLUGIN_CAPABILITY_IPV6);
 }
 
+#ifndef NM_OPENCONNECT_OLD
+static gboolean
+call_get_signature (NMVpnEditorPlugin *plugin,
+                    const char *request,
+                    gboolean *free_types,
+                    GType **types_in,
+                    GType **types_out)
+{
+       if (!strcmp (request, NM_VPN_EDITOR_PLUGIN_CALL_GET_SERVICE_INFO)) {
+               static GType t_in[] = { G_TYPE_STRING, 0 };
+               static GType t_out[] = { G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, 0 };
+
+               *types_in = t_in;
+               *types_out = t_out;
+               return TRUE;
+       }
+       return FALSE;
+}
+
+static gboolean
+call (NMVpnEditorPlugin *plugin,
+      const char *request,
+      GError **error,
+      const GValue *const*args_in,
+      GValue *const*args_out)
+{
+       const char *service_type;
+
+       if (!strcmp (request, NM_VPN_EDITOR_PLUGIN_CALL_GET_SERVICE_INFO)) {
+               service_type = g_value_get_string (args_in[0]);
+
+               if (!strcmp (service_type, NM_VPN_SERVICE_TYPE_OPENCONNECT)) {
+                       g_value_set_string (args_out[0], "openconnect");
+                       g_value_set_string (args_out[1], OPENCONNECT_PLUGIN_NAME);
+                       g_value_set_string (args_out[2], OPENCONNECT_PLUGIN_DESC);
+                       g_value_set_uint (args_out[3], NM_VPN_EDITOR_PLUGIN_SERVICE_FLAGS_CAN_ADD);
+                       return TRUE;
+               } else if (!strcmp (service_type, "org.freedesktop.NetworkManager.openconnect.nc")) {
+                       g_value_set_string (args_out[0], "openconnect.nc");
+                       g_value_set_string (args_out[1], _("Cisco AnyConnect Compatible VPN 
(openconnect.nc)"));
+                       g_value_set_string (args_out[2], _("Compatible with Cisco AnyConnect SSL VPN (nc)."));
+                       g_value_set_uint (args_out[3], NM_VPN_EDITOR_PLUGIN_SERVICE_FLAGS_CAN_ADD);
+                       return TRUE;
+               } else if (!strcmp (service_type, "org.freedesktop.NetworkManager.openconnect.anyconnect")) {
+                       g_value_set_string (args_out[0], "openconnect.anyconnect");
+                       g_value_set_string (args_out[1], _("Cisco AnyConnect Compatible VPN 
(openconnect.anyconnect)"));
+                       g_value_set_string (args_out[2], _("Compatible with Cisco AnyConnect SSL VPN 
(anyconnect)."));
+                       g_value_set_uint (args_out[3], NM_VPN_EDITOR_PLUGIN_SERVICE_FLAGS_CAN_ADD);
+                       return TRUE;
+               }
+               g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_CALL_INVALID_ARGUMENT,
+                            _("Unknown service-type '%s'"), service_type);
+       }
+       return FALSE;
+}
+#endif
+
 static NMVpnEditor *
 get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
 {
@@ -851,6 +913,10 @@ openconnect_editor_plugin_interface_init (NMVpnEditorPluginInterface *iface_clas
        iface_class->get_capabilities = get_capabilities;
        iface_class->import_from_file = import;
        iface_class->export_to_file = export;
+#ifndef NM_OPENCONNECT_OLD
+       iface_class->call_get_signature = call_get_signature;
+       iface_class->call = call;
+#endif
 }
 
 G_MODULE_EXPORT NMVpnEditorPlugin *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]