Commit 8f6eb995 authored by Tambet Ingo's avatar Tambet Ingo

2008-10-29 Tambet Ingo <tambet@gmail.com>

	Half of it by Dan Williams <dcbw@redhat.com>

	* libnm-util/libnm-util.ver
	libnm-util/nm-setting-vpn.c
	libnm-util/nm-setting-vpn.h
		- Make properties private and add accessor functions.

	* src/vpn-manager/nm-vpn-connection.c
	src/vpn-manager/nm-vpn-manager.c
	system-settings/plugins/keyfile/reader.c
	vpn-daemons/openvpn/properties/auth-helpers.c
	vpn-daemons/openvpn/properties/import-export.c
	vpn-daemons/openvpn/properties/nm-openvpn.c
	vpn-daemons/openvpn/src/nm-openvpn-service.c
	vpn-daemons/pptp/auth-dialog/main.c
	vpn-daemons/pptp/properties/advanced-dialog.c
	vpn-daemons/pptp/properties/nm-pptp.c
	vpn-daemons/pptp/src/nm-pptp-service.c
	vpn-daemons/vpnc/properties/nm-vpnc.c
	vpn-daemons/vpnc/src/nm-vpnc-service.c
		- Use VPN setting accessors.

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4232 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 69713a8b
2008-10-29 Tambet Ingo <tambet@gmail.com>
Half of it by Dan Williams <dcbw@redhat.com>
* libnm-util/libnm-util.ver
libnm-util/nm-setting-vpn.c
libnm-util/nm-setting-vpn.h
- Make properties private and add accessor functions.
* src/vpn-manager/nm-vpn-connection.c
src/vpn-manager/nm-vpn-manager.c
system-settings/plugins/keyfile/reader.c
vpn-daemons/openvpn/properties/auth-helpers.c
vpn-daemons/openvpn/properties/import-export.c
vpn-daemons/openvpn/properties/nm-openvpn.c
vpn-daemons/openvpn/src/nm-openvpn-service.c
vpn-daemons/pptp/auth-dialog/main.c
vpn-daemons/pptp/properties/advanced-dialog.c
vpn-daemons/pptp/properties/nm-pptp.c
vpn-daemons/pptp/src/nm-pptp-service.c
vpn-daemons/vpnc/properties/nm-vpnc.c
vpn-daemons/vpnc/src/nm-vpnc-service.c
- Use VPN setting accessors.
2008-10-28 Dan Williams <dcbw@redhat.com>
Patch from Tambet Ingo <tambet@gmail.com>
......
......@@ -130,6 +130,16 @@ global:
nm_setting_vpn_error_quark;
nm_setting_vpn_get_type;
nm_setting_vpn_new;
nm_setting_vpn_get_service_type;
nm_setting_vpn_get_user_name;
nm_setting_vpn_add_data_item;
nm_setting_vpn_foreach_data_item;
nm_setting_vpn_get_data_item;
nm_setting_vpn_remove_data_item;
nm_setting_vpn_add_secret;
nm_setting_vpn_foreach_secret;
nm_setting_vpn_get_secret;
nm_setting_vpn_remove_secret;
nm_setting_wired_error_get_type;
nm_setting_wired_error_quark;
nm_setting_wired_get_type;
......
......@@ -66,6 +66,36 @@ nm_setting_vpn_error_get_type (void)
G_DEFINE_TYPE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING)
#define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVPNPrivate))
typedef struct {
char *service_type;
/* username of the user requesting this connection, thus
* it's really only valid for user connections, and it also
* should never be saved out to persistent config.
*/
char *user_name;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should not contain secrets.
*/
GHashTable *data;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should contain secrets only.
*/
GHashTable *secrets;
} NMSettingVPNPrivate;
enum {
PROP_0,
PROP_SERVICE_TYPE,
......@@ -82,12 +112,104 @@ nm_setting_vpn_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL);
}
const char *
nm_setting_vpn_get_service_type (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type;
}
const char *
nm_setting_vpn_get_user_name (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
}
void
nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
g_strdup (key), g_strdup (item));
}
const char *
nm_setting_vpn_get_data_item (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
void
nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
void
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_foreach (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
(GHFunc) func, user_data);
}
void
nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
g_strdup (key), g_strdup (secret));
}
const char *
nm_setting_vpn_get_secret (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
void
nm_setting_vpn_remove_secret (NMSettingVPN *setting, const char *key)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
void
nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_hash_table_foreach (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
(GHFunc) func, user_data);
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingVPN *self = NM_SETTING_VPN (setting);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
if (!self->service_type) {
if (!priv->service_type) {
g_set_error (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_MISSING_PROPERTY,
......@@ -95,7 +217,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
if (!strlen (self->service_type)) {
if (!strlen (priv->service_type)) {
g_set_error (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
......@@ -104,7 +226,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
/* default username can be NULL, but can't be zero-length */
if (self->user_name && !strlen (self->user_name)) {
if (priv->user_name && !strlen (priv->user_name)) {
g_set_error (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
......@@ -118,13 +240,13 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
static void
update_one_secret (NMSetting *setting, const char *key, GValue *value)
{
NMSettingVPN *self = NM_SETTING_VPN (setting);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
g_return_if_fail (key != NULL);
g_return_if_fail (value != NULL);
g_return_if_fail (G_VALUE_HOLDS_STRING (value));
g_hash_table_insert (self->secrets, g_strdup (key), g_value_dup_string (value));
g_hash_table_insert (priv->secrets, g_strdup (key), g_value_dup_string (value));
}
static void
......@@ -140,21 +262,22 @@ destroy_one_secret (gpointer data)
static void
nm_setting_vpn_init (NMSettingVPN *setting)
{
g_object_set (setting, NM_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME, NULL);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
setting->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
setting->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret);
g_object_set (setting, NM_SETTING_NAME, NM_SETTING_VPN_SETTING_NAME, NULL);
priv->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret);
}
static void
finalize (GObject *object)
{
NMSettingVPN *self = NM_SETTING_VPN (object);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
g_free (self->service_type);
g_free (self->user_name);
g_hash_table_destroy (self->data);
g_hash_table_destroy (self->secrets);
g_free (priv->service_type);
g_free (priv->user_name);
g_hash_table_destroy (priv->data);
g_hash_table_destroy (priv->secrets);
G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object);
}
......@@ -169,31 +292,31 @@ static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingVPN *setting = NM_SETTING_VPN (object);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
GHashTable *new_hash;
switch (prop_id) {
case PROP_SERVICE_TYPE:
g_free (setting->service_type);
setting->service_type = g_value_dup_string (value);
g_free (priv->service_type);
priv->service_type = g_value_dup_string (value);
break;
case PROP_USER_NAME:
g_free (setting->user_name);
setting->user_name = g_value_dup_string (value);
g_free (priv->user_name);
priv->user_name = g_value_dup_string (value);
break;
case PROP_DATA:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (setting->data);
g_hash_table_remove_all (priv->data);
new_hash = g_value_get_boxed (value);
if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, setting->data);
g_hash_table_foreach (new_hash, copy_hash, priv->data);
break;
case PROP_SECRETS:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (setting->secrets);
g_hash_table_remove_all (priv->secrets);
new_hash = g_value_get_boxed (value);
if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, setting->secrets);
g_hash_table_foreach (new_hash, copy_hash, priv->secrets);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -206,19 +329,20 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingVPN *setting = NM_SETTING_VPN (object);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_SERVICE_TYPE:
g_value_set_string (value, setting->service_type);
g_value_set_string (value, nm_setting_vpn_get_service_type (setting));
break;
case PROP_USER_NAME:
g_value_set_string (value, setting->user_name);
g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
break;
case PROP_DATA:
g_value_set_boxed (value, setting->data);
g_value_set_boxed (value, priv->data);
break;
case PROP_SECRETS:
g_value_set_boxed (value, setting->secrets);
g_value_set_boxed (value, priv->secrets);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -232,6 +356,8 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingVPNPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
......
......@@ -59,41 +59,41 @@ GQuark nm_setting_vpn_error_quark (void);
typedef struct {
NMSetting parent;
char *service_type;
/* username of the user requesting this connection, thus
* it's really only valid for user connections, and it also
* should never be saved out to persistent config.
*/
char *user_name;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should not contain secrets.
*/
GHashTable *data;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should contain secrets only.
*/
GHashTable *secrets;
} NMSettingVPN;
typedef struct {
NMSettingClass parent;
} NMSettingVPNClass;
typedef void (*VPNIterFunc) (const char *key, const char *value, gpointer user_data);
GType nm_setting_vpn_get_type (void);
NMSetting *nm_setting_vpn_new (void);
NMSetting *nm_setting_vpn_new (void);
const char *nm_setting_vpn_get_service_type (NMSettingVPN *setting);
const char *nm_setting_vpn_get_user_name (NMSettingVPN *setting);
void nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item);
const char * nm_setting_vpn_get_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_remove_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data);
void nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret);
const char * nm_setting_vpn_get_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_remove_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
VPNIterFunc func,
gpointer user_data);
G_END_DECLS
......
......@@ -224,14 +224,14 @@ nm_vpn_connection_new (NMConnection *connection,
return vpn_connection;
}
static char *
static const char *
nm_vpn_connection_get_service (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPN *setting;
setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_VPN);
return setting->service_type;
return nm_setting_vpn_get_service_type (setting);
}
static void
......
......@@ -152,6 +152,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
NMVPNService *service;
char *path = NULL;
NMVPNConnection *vpn;
const char *service_type;
g_return_val_if_fail (NM_IS_VPN_MANAGER (manager), NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
......@@ -181,9 +182,10 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
vpn = NULL;
}
service = nm_vpn_manager_get_service (manager, vpn_setting->service_type);
service_type = nm_setting_vpn_get_service_type (vpn_setting);
service = nm_vpn_manager_get_service (manager, service_type);
if (!service) {
service = nm_vpn_service_new (vpn_setting->service_type);
service = nm_vpn_service_new (service_type);
if (service)
nm_vpn_manager_add_service (manager, service);
}
......
......@@ -310,10 +310,8 @@ read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key)
continue;
if (NM_IS_SETTING_VPN (setting)) {
NMSettingVPN *s_vpn = NM_SETTING_VPN (setting);
if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE))
g_hash_table_insert (s_vpn->data, g_strdup (*iter), g_strdup (value));
nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), *iter, value);
}
g_free (value);
}
......@@ -493,8 +491,10 @@ read_vpn_secrets (GKeyFile *file, NMSettingVPN *s_vpn)
char *secret;
secret = g_key_file_get_string (file, VPN_SECRETS_GROUP, *iter, NULL);
if (secret)
g_hash_table_insert (s_vpn->secrets, g_strdup (*iter), secret);
if (secret) {
nm_setting_vpn_add_secret (s_vpn, *iter, secret);
g_free (secret);
}
}
g_strfreev (keys);
}
......
......@@ -75,8 +75,7 @@ fill_password (GladeXML *xml,
if (s_vpn) {
const char *tmp;
tmp = g_hash_table_lookup (s_vpn->secrets,
priv_key_password ? NM_OPENVPN_KEY_CERTPASS : NM_OPENVPN_KEY_PASSWORD);
tmp = nm_setting_vpn_get_secret (s_vpn, priv_key_password ? NM_OPENVPN_KEY_CERTPASS : NM_OPENVPN_KEY_PASSWORD);
if (tmp)
password = gnome_keyring_memory_strdup (tmp);
}
......@@ -161,8 +160,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose a Certificate Authority certificate..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CA);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CA);
if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
}
......@@ -180,8 +179,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose your personal certificate..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_CERT);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CERT);
if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
}
......@@ -198,8 +197,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
_("Choose your private key..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_KEY);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_KEY);
if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
}
......@@ -211,8 +210,8 @@ tls_pw_init_auth_widget (GladeXML *xml,
g_free (tmp);
gtk_size_group_add_widget (group, widget);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_USERNAME);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME);
if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value);
}
......@@ -251,16 +250,16 @@ sk_init_auth_widget (GladeXML *xml,
_("Choose an OpenVPN static key..."));
g_signal_connect (G_OBJECT (widget), "selection-changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY);
if (value && strlen (value))
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
}
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION);
if (value && strlen (value)) {
long int tmp;
......@@ -297,8 +296,8 @@ sk_init_auth_widget (GladeXML *xml,
widget = glade_xml_get_widget (xml, "sk_local_address_entry");
gtk_size_group_add_widget (group, widget);
g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), user_data);
if (s_vpn && s_vpn->data) {
value = g_hash_table_lookup (s_vpn->data, NM_OPENVPN_KEY_LOCAL_IP);
if (s_vpn) {
value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_LOCAL_IP);
if (value && strlen (value))
gtk_entry_set_text (GTK_ENTRY (widget), value);
}
......@@ -437,7 +436,6 @@ update_from_filechooser (GladeXML *xml,
g_return_if_fail (prefix != NULL);
g_return_if_fail (widget_name != NULL);
g_return_if_fail (s_vpn != NULL);
g_return_if_fail (s_vpn->data != NULL);
tmp = g_strdup_printf ("%s_%s", prefix, widget_name);
widget = glade_xml_get_widget (xml, tmp);
......@@ -448,7 +446,7 @@ update_from_filechooser (GladeXML *xml,
return;
if (strlen (filename))
g_hash_table_insert (s_vpn->data, g_strdup (key), g_strdup (filename));
nm_setting_vpn_add_data_item (s_vpn, key, filename);
g_free (filename);
}
......@@ -471,18 +469,14 @@ update_username (GladeXML *xml, const char *prefix, NMSettingVPN *s_vpn)
g_return_if_fail (xml != NULL);
g_return_if_fail (prefix != NULL);
g_return_if_fail (s_vpn != NULL);
g_return_if_fail (s_vpn->data != NULL);
tmp = g_strdup_printf ("%s_username_entry", prefix);
widget = glade_xml_get_widget (xml, tmp);
g_free (tmp);
str = gtk_entry_get_text (GTK_ENTRY (widget));
if (str && strlen (str)) {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_USERNAME),
g_strdup (str));
}
if (str && strlen (str))
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_USERNAME, str);
}
gboolean
......@@ -512,9 +506,9 @@ auth_widget_update_connection (GladeXML *xml,
gtk_tree_model_get (model, &iter, SK_DIR_COL_NUM, &direction, -1);
if (direction > -1) {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_STATIC_KEY_DIRECTION),
g_strdup_printf ("%d", direction));
char *tmp = g_strdup_printf ("%d", direction);
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_STATIC_KEY_DIRECTION, tmp);
g_free (tmp);
}
}
} else
......@@ -733,17 +727,16 @@ static const char *advanced_keys[] = {
};
static void
copy_values (gpointer key, gpointer data, gpointer user_data)
copy_values (const char *key, const char *value, gpointer user_data)
{
GHashTable *hash = (GHashTable *) user_data;
const char *value = (const char *) data;
const char **i;
for (i = &advanced_keys[0]; *i; i++) {
if (strcmp ((const char *) key, *i))
if (strcmp (key, *i))
continue;
g_hash_table_insert (hash, g_strdup ((const char *) key), g_strdup (value));
g_hash_table_insert (hash, g_strdup (key), g_strdup (value));
}
}
......@@ -757,9 +750,7 @@ advanced_dialog_new_hash_from_connection (NMConnection *connection,
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
s_vpn = (NMSettingVPN *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN);
if (s_vpn && s_vpn->data)
g_hash_table_foreach (s_vpn->data, copy_values, hash);
nm_setting_vpn_foreach_data_item (s_vpn, copy_values, hash);
return hash;
}
......
......@@ -60,11 +60,11 @@ static gboolean
handle_path_item (const char *line,
const char *tag,
const char *key,
GHashTable *hash,
NMSettingVPN *s_vpn,
const char *path,
char **leftover)
{
char *tmp, *file, *unquoted, *p, *full_path;
char *tmp, *file, *unquoted, *p, *full_path = NULL;
gboolean quoted = FALSE;
if (leftover)
......@@ -110,7 +110,7 @@ handle_path_item (const char *line,
if (leftover && *file)
*leftover = file + 1;
g_hash_table_insert (hash, g_strdup (key), g_strdup (unquoted));
nm_setting_vpn_add_data_item (s_vpn, key, unquoted);
g_free (unquoted);
out:
......@@ -138,7 +138,7 @@ get_args (const char *line)
}
static void
handle_direction (const char *tag, const char *key, char *leftover, GHashTable *hash)
handle_direction (const char *tag, const char *key, char *leftover, NMSettingVPN *s_vpn)
{
glong direction;
......@@ -153,9 +153,9 @@ handle_direction (const char *tag, const char *key, char *leftover, GHashTable *
direction = strtol (leftover, NULL, 10);
if (errno == 0) {
if (direction == 0)
g_hash_table_insert (hash, g_strdup (key), g_strdup ("0"));
nm_setting_vpn_add_data_item (s_vpn, key, "0");
else if (direction == 1)
g_hash_table_insert (hash, g_strdup (key), g_strdup ("1"));
nm_setting_vpn_add_data_item (s_vpn, key, "1");
} else
g_warning ("%s: unknown %s direction '%s'", __func__, tag, leftover);
}
......@@ -179,7 +179,8 @@ do_import (const char *path, char **lines, GError **error)
nm_connection_add_setting (connection, NM_SETTING (s_con));
s_vpn = NM_SETTING_VPN (nm_setting_vpn_new ());
s_vpn->service_type = g_strdup (NM_DBUS_SERVICE_OPENVPN);
g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, NM_DBUS_SERVICE_OPENVPN, NULL);
/* Get the default path for ca, cert, key file, these files maybe
* in same path with the configuration file */
......@@ -209,9 +210,7 @@ do_import (const char *path, char **lines, GError **error)
if (strstr (*line, "tun")) {
/* ignore; default is tun */
} else if (strstr (*line, "tap")) {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_TAP_DEV),
g_strdup ("yes"));
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_TAP_DEV, "yes");
} else
g_warning ("%s: unknown dev option '%s'", __func__, *line);
......@@ -222,9 +221,7 @@ do_import (const char *path, char **lines, GError **error)
if (strstr (*line, "udp")) {
/* ignore; udp is default */
} else if (strstr (*line, "tcp")) {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_PROTO_TCP),
g_strdup ("yes"));
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
} else
g_warning ("%s: unknown proto option '%s'", __func__, *line);
......@@ -232,9 +229,7 @@ do_import (const char *path, char **lines, GError **error)
}
if (!strncmp (*line, COMP_TAG, strlen (COMP_TAG))) {
g_hash_table_insert (s_vpn->data,
g_strdup (NM_OPENVPN_KEY_COMP_LZO),
g_strdup ("yes"));
nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO, "yes");
continue;
}
......@@ -244,9 +239,7 @@ do_import (const char *path, char **lines, GError **error)
continue;