[network-manager-applet/th/vpn-service-info-bgo767197: 8/8] c-e: handle add-details from command line to create VPN connection
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/th/vpn-service-info-bgo767197: 8/8] c-e: handle add-details from command line to create VPN connection
- Date: Mon, 13 Jun 2016 11:54:10 +0000 (UTC)
commit d01ee94b24985c6058511b40aa921a6e34adc464
Author: Thomas Haller <thaller redhat com>
Date: Mon Jun 13 13:35:13 2016 +0200
c-e: handle add-details from command line to create VPN connection
Now supports:
$ nm-connection-editor -c -t vpn:openconnect:nc
src/connection-editor/nm-connection-list.c | 26 +++++++++----
src/connection-editor/page-vpn.c | 53 +++++++++++++++++++++++++--
src/connection-editor/page-vpn.h | 1 +
3 files changed, 68 insertions(+), 12 deletions(-)
---
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 5c092dc..ea1f8a8 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -33,6 +33,7 @@
#include "nm-connection-list.h"
#include "ce-polkit-button.h"
#include "connection-helpers.h"
+#include "page-vpn.h"
extern gboolean nm_ce_keep_above;
@@ -895,6 +896,8 @@ void
nm_connection_list_create (NMConnectionList *self, GType ctype, const char *detail)
{
ConnectionTypeData *types;
+ gpointer detail_data = NULL;
+ CEPageVpnDetailData vpn_data;
int i;
g_return_if_fail (NM_IS_CONNECTION_LIST (self));
@@ -914,15 +917,22 @@ nm_connection_list_create (NMConnectionList *self, GType ctype, const char *deta
nm_connection_editor_error (NULL, _("Error creating connection"),
_("Don't know how to create '%s' connections"),
g_type_name (ctype));
}
- } else {
- new_connection_of_type (GTK_WINDOW (self->dialog),
- detail,
- NULL,
- self->client,
- types[i].new_connection_func,
- really_add_connection,
- self);
+ return;
}
+
+ if (ctype == NM_TYPE_SETTING_VPN) {
+ memset (&vpn_data, 0, sizeof (vpn_data));
+ vpn_data.parse_detail = TRUE;
+ detail_data = &vpn_data;
+ }
+
+ new_connection_of_type (GTK_WINDOW (self->dialog),
+ detail,
+ detail_data,
+ self->client,
+ types[i].new_connection_func,
+ really_add_connection,
+ self);
}
void
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 3d379ec..2c2d71d 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -28,6 +28,7 @@
#include "connection-helpers.h"
#include "nm-connection-editor.h"
#include "vpn-helpers.h"
+#include "nm-vpn-editor-plugin-call.h"
G_DEFINE_TYPE (CEPageVpn, ce_page_vpn, CE_TYPE_PAGE)
@@ -290,7 +291,12 @@ vpn_connection_new (GtkWindow *parent,
NMSetting *s_vpn;
const char *service_type;
gs_free char *service_type_free = NULL;
- const CEPageVpnDetailData *data = detail_data;
+ gs_free char *add_detail_key_free = NULL;
+ gs_free char *add_detail_val_free = NULL;
+ const CEPageVpnDetailData *vpn_data = detail_data;
+ gssize split_idx, l;
+ const char *add_detail_key = NULL;
+ const char *add_detail_val = NULL;
if (!detail) {
NewVpnInfo *info;
@@ -310,8 +316,47 @@ vpn_connection_new (GtkWindow *parent,
return;
}
+ service_type = detail;
+ add_detail_key = vpn_data ? vpn_data->add_detail_key : NULL;
+ add_detail_val = vpn_data ? vpn_data->add_detail_val : NULL;
+
service_type_free = nm_vpn_plugin_info_list_find_service_type (vpn_get_plugin_infos (), detail);
- service_type = service_type_free ?: detail;
+ if (service_type_free)
+ service_type = service_type_free;
+ else if ( vpn_data
+ && vpn_data->parse_detail
+ && (l = strlen (detail)) >= 3) {
+
+ /* "detail" was not found as a shortname for a service-type. It might contain
"<SERVICE_TYPE>:<ADD_DETAIL>".
+ * Try to parse that by spliting @detail at the colons. */
+ for (split_idx = 1; split_idx < l - 1; split_idx++) {
+ if (detail[split_idx] == ':') {
+ gs_free char *detail_main = g_strndup (detail, split_idx);
+ NMVpnEditorPlugin *plugin;
+
+ service_type_free = nm_vpn_plugin_info_list_find_service_type
(vpn_get_plugin_infos (), detail_main);
+ if (!service_type_free)
+ continue;
+ plugin = vpn_get_plugin_by_service (service_type_free);
+ if (!plugin) {
+ g_clear_pointer (&service_type_free, g_free);
+ continue;
+ }
+
+ /* we found a service_type. The try to use the remainder as add-detail. */
+ service_type = service_type_free;
+ if (nm_vpn_editor_plugin_get_service_add_detail (plugin, service_type,
&detail[split_idx + 1],
+ NULL, NULL,
+ &add_detail_key_free,
&add_detail_val_free, NULL)
+ && add_detail_key_free && add_detail_key_free[0]
+ && add_detail_val_free && add_detail_val_free[0]) {
+ add_detail_key = add_detail_key_free;
+ add_detail_val = add_detail_val_free;
+ }
+ break;
+ }
+ }
+ }
connection = ce_page_new_connection (_("VPN connection %d"),
NM_SETTING_VPN_SETTING_NAME,
@@ -321,8 +366,8 @@ vpn_connection_new (GtkWindow *parent,
s_vpn = nm_setting_vpn_new ();
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type, NULL);
- if (data && data->add_detail_key)
- nm_setting_vpn_add_data_item ((NMSettingVpn *) s_vpn, data->add_detail_key,
data->add_detail_val);
+ if (add_detail_key)
+ nm_setting_vpn_add_data_item ((NMSettingVpn *) s_vpn, add_detail_key, add_detail_val);
nm_connection_add_setting (connection, s_vpn);
diff --git a/src/connection-editor/page-vpn.h b/src/connection-editor/page-vpn.h
index 4564efd..c3e7210 100644
--- a/src/connection-editor/page-vpn.h
+++ b/src/connection-editor/page-vpn.h
@@ -44,6 +44,7 @@ typedef struct {
} CEPageVpnClass;
typedef struct {
+ gboolean parse_detail;
char *add_detail_key;
char *add_detail_val;
} CEPageVpnDetailData;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]