[network-manager-openconnect] Add support for importing/exporting/changing/displaying protocol field



commit 44103eddf255320d755939217b6800c3cb57f363
Author: David Woodhouse <David Woodhouse intel com>
Date:   Tue Jul 12 15:12:52 2016 +0100

    Add support for importing/exporting/changing/displaying protocol field

 properties/nm-openconnect-dialog.ui       |  102 +++++++++++++++++++++++++----
 properties/nm-openconnect-editor-plugin.c |   12 ++++
 properties/nm-openconnect-editor.c        |   79 ++++++++++++++++++++++
 src/nm-openconnect-service.c              |    1 +
 4 files changed, 180 insertions(+), 14 deletions(-)
---
diff --git a/properties/nm-openconnect-dialog.ui b/properties/nm-openconnect-dialog.ui
index 4643b73..94d3dcf 100644
--- a/properties/nm-openconnect-dialog.ui
+++ b/properties/nm-openconnect-dialog.ui
@@ -51,12 +51,45 @@
                 <child>
                   <object class="GtkTable" id="table2">
                     <property name="visible">True</property>
-                    <property name="n_rows">3</property>
+                    <property name="n_rows">4</property>
                     <property name="n_columns">2</property>
                     <property name="homogeneous">False</property>
                     <property name="row_spacing">6</property>
                     <property name="column_spacing">6</property>
                     <child>
+                      <object class="GtkAlignment" id="alignment17">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="yalign">0.5</property>
+                        <property name="xscale">0</property>
+                        <property name="yscale">1</property>
+                        <property name="top_padding">0</property>
+                        <property name="bottom_padding">0</property>
+                        <property name="left_padding">0</property>
+                        <property name="right_padding">0</property>
+                        <child>
+                         <object class="GtkComboBox" id="protocol_combo">
+                            <property name="visible">True</property>
+                            <property name="model">protocol_combo_list</property>
+                            <property name="active">0</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="renderer"/>
+                              <attributes>
+                               <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                         </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">0</property>
+                        <property name="bottom_attach">1</property>
+                        <property name="y_options"/>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkAlignment" id="alignment2">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
@@ -84,8 +117,8 @@
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">0</property>
-                        <property name="bottom_attach">1</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
                         <property name="y_options"/>
                       </packing>
                     </child>
@@ -117,8 +150,8 @@
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="x_options">fill</property>
                       </packing>
                     </child>
@@ -148,8 +181,35 @@
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="y_options"/>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label24">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_VPN Protocol:</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_markup">False</property>
+                        <property name="justify">GTK_JUSTIFY_LEFT</property>
+                        <property name="wrap">False</property>
+                        <property name="selectable">False</property>
+                        <property name="xalign">0</property>
+                        <property name="yalign">0.5</property>
+                        <property name="xpad">0</property>
+                        <property name="ypad">0</property>
+                        <property name="mnemonic_widget">protocol_combo</property>
+                        <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                        <property name="width_chars">-1</property>
+                        <property name="single_line_mode">False</property>
+                        <property name="angle">0</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="right_attach">1</property>
+                        <property name="top_attach">0</property>
+                        <property name="bottom_attach">1</property>
                         <property name="y_options"/>
                       </packing>
                     </child>
@@ -175,8 +235,8 @@
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="right_attach">1</property>
-                        <property name="top_attach">0</property>
-                        <property name="bottom_attach">1</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
                         <property name="y_options"/>
                       </packing>
                     </child>
@@ -202,8 +262,8 @@
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="right_attach">1</property>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="y_options"/>
                       </packing>
                     </child>
@@ -229,8 +289,8 @@
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="right_attach">1</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="y_options"/>
                       </packing>
                     </child>
@@ -617,7 +677,7 @@
                         <property name="model">token_mode_list</property>
                         <property name="active">0</property>
                         <child>
-                          <object class="GtkCellRendererText" id="renderer"/>
+                          <object class="GtkCellRendererText" id="renderer2"/>
                           <attributes>
                             <attribute name="text">0</attribute>
                           </attributes>
@@ -774,4 +834,18 @@
           </row>
         </data>
       </object>
+      <object class="GtkListStore" id="protocol_combo_list">
+        <columns>
+          <!-- column-name legible -->
+          <column type="gchararray"/>
+          <!-- column-name protocol_value -->
+          <column type="gchararray"/>
+        </columns>
+        <data>
+          <row>
+            <col id="0" translatable="yes">Cisco AnyConnect</col>
+            <col id="1" translatable="no">anyconnect</col>
+          </row>
+        </data>
+      </object>
 </interface>
diff --git a/properties/nm-openconnect-editor-plugin.c b/properties/nm-openconnect-editor-plugin.c
index ecd79c1..f578000 100644
--- a/properties/nm-openconnect-editor-plugin.c
+++ b/properties/nm-openconnect-editor-plugin.c
@@ -158,6 +158,11 @@ import (NMVpnEditorPlugin *iface, const char *path, GError **error)
        if (buf)
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CACERT, buf);
 
+       /* Protocol */
+       buf = g_key_file_get_string (keyfile, "openconnect", "Protocol", NULL);
+       if (buf)
+               nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROTOCOL, buf);
+
        /* Proxy */
        buf = g_key_file_get_string (keyfile, "openconnect", "Proxy", NULL);
        if (buf)
@@ -212,6 +217,7 @@ export (NMVpnEditorPlugin *iface,
        const char *value;
        const char *gateway = NULL;
        const char *cacert = NULL;
+       const char *protocol = NULL;
        const char *proxy = NULL;
        gboolean csd_enable = FALSE;
        const char *csd_wrapper = NULL;
@@ -251,6 +257,10 @@ export (NMVpnEditorPlugin *iface,
        if (value && strlen (value))
                cacert = value;
 
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PROTOCOL);
+       if (value && strlen (value))
+               protocol = value;
+
        value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY);
        if (value && strlen (value))
                proxy = value;
@@ -293,6 +303,7 @@ export (NMVpnEditorPlugin *iface,
                 "Description=%s\n"
                 "Host=%s\n"
                 "CACert=%s\n"
+                "Protocol=%s\n"
                 "Proxy=%s\n"
                 "CSDEnable=%s\n"
                 "CSDWrapper=%s\n"
@@ -304,6 +315,7 @@ export (NMVpnEditorPlugin *iface,
                 /* Description */           nm_setting_connection_get_id (s_con),
                 /* Host */                  gateway,
                 /* CA Certificate */        cacert,
+                /* Protocol */              protocol ? protocol : "anyconnect",
                 /* Proxy */                 proxy ? proxy : "",
                 /* Cisco Secure Desktop */  csd_enable ? "1" : "0",
                 /* CSD Wrapper Script */    csd_wrapper ? csd_wrapper : "",
diff --git a/properties/nm-openconnect-editor.c b/properties/nm-openconnect-editor.c
index 1a9e17e..e3db7aa 100644
--- a/properties/nm-openconnect-editor.c
+++ b/properties/nm-openconnect-editor.c
@@ -210,6 +210,74 @@ init_token_ui (OpenconnectEditor *self,
 }
 
 static gboolean
+init_protocol_combo_options (GtkComboBox *protocol_combo)
+{
+#if OPENCONNECT_CHECK_VER(5,1)
+       GtkListStore *protocol_combo_list = GTK_LIST_STORE (gtk_combo_box_get_model (protocol_combo));
+       GtkTreeIter iter;
+
+       gtk_list_store_append(protocol_combo_list, &iter);
+       gtk_list_store_set(protocol_combo_list, &iter,
+                                          0, _("Juniper/Pulse Network Connect"),
+                                          1, "nc",
+                                          -1);
+       return TRUE;
+#else
+       return FALSE;
+#endif
+}
+
+static gboolean
+init_protocol_ui (OpenconnectEditor *self,
+                                 OpenconnectEditorPrivate *priv,
+                                 NMSettingVpn *s_vpn)
+{
+       GtkComboBox *protocol_combo;
+       const char *value;
+
+       protocol_combo = GTK_COMBO_BOX (gtk_builder_get_object (priv->builder, "protocol_combo"));
+       if (!protocol_combo)
+               return FALSE;
+       if (!init_protocol_combo_options (protocol_combo))
+               return TRUE;
+
+#if 0
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "token_vbox"));
+       if (!widget)
+               return FALSE;
+       gtk_box_pack_start (GTK_BOX (priv->widget), widget, FALSE, FALSE, 0);
+#endif
+
+       if (s_vpn) {
+               GtkTreeModel *model = gtk_combo_box_get_model (protocol_combo);
+               int active_option = 0;
+
+               value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PROTOCOL);
+               if (value) {
+                       int i;
+                       GtkTreeIter iter;
+
+                       if (!gtk_tree_model_get_iter_first (model, &iter))
+                               return FALSE;
+                       for (i = 0; ; i++) {
+                               char *pref_value;
+
+                               gtk_tree_model_get (model, &iter, 1, &pref_value, -1);
+                               if (!strcmp (value, pref_value))
+                                       active_option = i;
+                               g_free (pref_value);
+                               if (!gtk_tree_model_iter_next (model, &iter))
+                                       break;
+                       }
+               }
+               gtk_combo_box_set_active (protocol_combo, active_option);
+       }
+       g_signal_connect (G_OBJECT (protocol_combo), "changed", G_CALLBACK (stuff_changed_cb), self);
+
+       return TRUE;
+}
+
+static gboolean
 init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **error)
 {
        OpenconnectEditorPrivate *priv = OPENCONNECT_EDITOR_GET_PRIVATE (self);
@@ -276,6 +344,9 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (init_token_ui (self, priv, s_vpn) == FALSE)
                return FALSE;
 
+       if (init_protocol_ui (self, priv, s_vpn) == FALSE)
+               return FALSE;
+
        tls_pw_init_auth_widget (priv->builder, priv->group, s_vpn, stuff_changed_cb, self);
 
        return TRUE;
@@ -318,6 +389,14 @@ update_connection (NMVpnEditor *iface,
        if (protocol)
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROTOCOL, protocol);
 
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "protocol_combo"));
+       model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+       if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
+               gtk_tree_model_get (model, &iter, 1, &str, -1);
+               nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROTOCOL, str);
+               g_free(str);
+       }
+
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
        str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
        if (str && strlen (str))
diff --git a/src/nm-openconnect-service.c b/src/nm-openconnect-service.c
index cbcf82c..b20fdbd 100644
--- a/src/nm-openconnect-service.c
+++ b/src/nm-openconnect-service.c
@@ -86,6 +86,7 @@ static const ValidProperty valid_properties[] = {
        { NM_OPENCONNECT_KEY_PRIVKEY,     G_TYPE_STRING, 0, 0 },
        { NM_OPENCONNECT_KEY_MTU,         G_TYPE_STRING, 0, 0 },
        { NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID, G_TYPE_BOOLEAN, 0, 0 },
+       { NM_OPENCONNECT_KEY_PROTOCOL,    G_TYPE_STRING, 0, 0 },
        { NM_OPENCONNECT_KEY_PROXY,       G_TYPE_STRING, 0, 0 },
        { NM_OPENCONNECT_KEY_CSD_ENABLE,  G_TYPE_BOOLEAN, 0, 0 },
        { NM_OPENCONNECT_KEY_CSD_WRAPPER, G_TYPE_STRING, 0, 0 },


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