void vpn_connection_new (GtkWindow *parent, const char *detail, NMRemoteSettings *settings, PageNewConnectionResultFunc result_func, gpointer user_data) { NMConnection *connection; NMSetting *s_vpn; if (!detail) { NewVpnInfo *info; /* This will happen if nm-c-e is launched from the command line * with "--create --type vpn". Dump the user back into the * new connection dialog to let them pick a subtype now. */ info = g_slice_new (NewVpnInfo); info->result_func = result_func; info->user_data = user_data; new_connection_dialog_full (parent, settings, NEW_VPN_CONNECTION_PRIMARY_LABEL, NEW_VPN_CONNECTION_SECONDARY_LABEL, vpn_type_filter_func, vpn_type_result_func, info); return; } connection = ce_page_new_connection (_("VPN connection %d"), NM_SETTING_VPN_SETTING_NAME, FALSE, settings, user_data); s_vpn = nm_setting_vpn_new (); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, detail, NULL); nm_connection_add_setting (connection, s_vpn); (*result_func) (connection, FALSE, NULL, user_data); }
void vpn_connection_new (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL, GtkWindow *parent, const char *detail, gpointer detail_data, NMConnection *connection, NMClient *client, PageNewConnectionResultFunc result_func, gpointer user_data) { NMSetting *s_vpn; const char *service_type; gs_free char *service_type_free = NULL; 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; gs_unref_object NMConnection *connection_tmp = NULL; if (!detail && !connection) { NewVpnInfo *info; /* This will happen if nm-c-e is launched from the command line * with "--create --type vpn". Dump the user back into the * new connection dialog to let them pick a subtype now. */ info = g_slice_new (NewVpnInfo); info->result_func = result_func; info->user_data = user_data; new_connection_dialog_full (parent, client, NEW_VPN_CONNECTION_PRIMARY_LABEL, NEW_VPN_CONNECTION_SECONDARY_LABEL, vpn_type_filter_func, vpn_type_result_func, info); return; } connection = _ensure_connection_other (connection, &connection_tmp); if (detail) { 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); if (service_type_free) service_type = service_type_free; else if (!vpn_data) { /* when called without @vpn_data, it means that @detail may contain "<SERVICE_TYPE>:<ADD_DETAIL>". * Try to parse them by spliting @detail at the colons and try to interpret the first part as * @service_type and the remainder as add-detail. */ l = strlen (detail); 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. 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; } } } if (!service_type) service_type = detail; s_vpn = nm_setting_vpn_new (); g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type, NULL); 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); } complete_vpn_connection (connection, client); (*result_func) (FUNC_TAG_PAGE_NEW_CONNECTION_RESULT_CALL, connection, FALSE, NULL, user_data); }