libnm/libnm-util: add VPN 'persistent' property

This property will indicate that the user wishes the VPN connection
to stay active until explicitly disconnected, even across link changes
or other interruptions.
This commit is contained in:
Dan Williams 2014-10-16 20:09:38 -05:00
parent 4b2935b9b8
commit 2b9e442013
5 changed files with 87 additions and 1 deletions

View file

@ -57,6 +57,11 @@ typedef struct {
*/
char *user_name;
/* Whether the VPN stays up across link changes, until the user
* explicitly disconnects it.
*/
gboolean persistent;
/* 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
@ -80,6 +85,7 @@ enum {
PROP_0,
PROP_SERVICE_TYPE,
PROP_USER_NAME,
PROP_PERSISTENT,
PROP_DATA,
PROP_SECRETS,
@ -130,6 +136,20 @@ nm_setting_vpn_get_user_name (NMSettingVpn *setting)
return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
}
/**
* nm_setting_vpn_get_persistent:
* @setting: the #NMSettingVpn
*
* Returns: the #NMSettingVpn:persistent property of the setting
**/
gboolean
nm_setting_vpn_get_persistent (NMSettingVpn *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
return NM_SETTING_VPN_GET_PRIVATE (setting)->persistent;
}
/**
* nm_setting_vpn_get_num_data_items:
* @setting: the #NMSettingVpn
@ -721,6 +741,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->user_name);
priv->user_name = g_value_dup_string (value);
break;
case PROP_PERSISTENT:
priv->persistent = g_value_get_boolean (value);
break;
case PROP_DATA:
g_hash_table_unref (priv->data);
priv->data = _nm_utils_copy_strdict (g_value_get_boxed (value));
@ -749,6 +772,9 @@ get_property (GObject *object, guint prop_id,
case PROP_USER_NAME:
g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
break;
case PROP_PERSISTENT:
g_value_set_boolean (value, priv->persistent);
break;
case PROP_DATA:
g_value_take_boxed (value, _nm_utils_copy_strdict (priv->data));
break;
@ -814,6 +840,20 @@ nm_setting_vpn_class_init (NMSettingVpnClass *setting_class)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVpn:persistent:
*
* If the VPN service supports persistence, and this property is %TRUE,
* the VPN will attempt to stay connected across link changes and outages,
* until explicitly disconnected.
**/
g_object_class_install_property
(object_class, PROP_PERSISTENT,
g_param_spec_boolean (NM_SETTING_VPN_PERSISTENT, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVpn:data:
*

View file

@ -42,6 +42,7 @@ G_BEGIN_DECLS
#define NM_SETTING_VPN_SERVICE_TYPE "service-type"
#define NM_SETTING_VPN_USER_NAME "user-name"
#define NM_SETTING_VPN_PERSISTENT "persistent"
#define NM_SETTING_VPN_DATA "data"
#define NM_SETTING_VPN_SECRETS "secrets"
@ -70,6 +71,7 @@ GType nm_setting_vpn_get_type (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);
gboolean nm_setting_vpn_get_persistent (NMSettingVpn *setting);
guint32 nm_setting_vpn_get_num_data_items (NMSettingVpn *setting);
void nm_setting_vpn_add_data_item (NMSettingVpn *setting,

View file

@ -81,6 +81,11 @@ typedef struct {
*/
char *user_name;
/* Whether the VPN stays up across link changes, until the user
* explicitly disconnects it.
*/
gboolean persistent;
/* 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
@ -104,6 +109,7 @@ enum {
PROP_0,
PROP_SERVICE_TYPE,
PROP_USER_NAME,
PROP_PERSISTENT,
PROP_DATA,
PROP_SECRETS,
@ -154,6 +160,20 @@ nm_setting_vpn_get_user_name (NMSettingVPN *setting)
return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
}
/**
* nm_setting_vpn_get_persistent:
* @setting: the #NMSettingVPN
*
* Returns: the #NMSettingVPN:persistent property of the setting
**/
gboolean
nm_setting_vpn_get_persistent (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
return NM_SETTING_VPN_GET_PRIVATE (setting)->persistent;
}
/**
* nm_setting_vpn_get_num_data_items:
* @setting: the #NMSettingVPN
@ -744,6 +764,9 @@ set_property (GObject *object, guint prop_id,
g_free (priv->user_name);
priv->user_name = g_value_dup_string (value);
break;
case PROP_PERSISTENT:
priv->persistent = g_value_get_boolean (value);
break;
case PROP_DATA:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (priv->data);
@ -778,6 +801,9 @@ get_property (GObject *object, guint prop_id,
case PROP_USER_NAME:
g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
break;
case PROP_PERSISTENT:
g_value_set_boolean (value, priv->persistent);
break;
case PROP_DATA:
g_value_set_boxed (value, priv->data);
break;
@ -843,6 +869,20 @@ nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVPN:persistent:
*
* If the VPN service supports persistence, and this property is %TRUE,
* the VPN will attempt to stay connected across link changes and outages,
* until explicitly disconnected.
**/
g_object_class_install_property
(object_class, PROP_PERSISTENT,
g_param_spec_boolean (NM_SETTING_VPN_PERSISTENT, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVPN:data:
*

View file

@ -54,6 +54,7 @@ GQuark nm_setting_vpn_error_quark (void);
#define NM_SETTING_VPN_SERVICE_TYPE "service-type"
#define NM_SETTING_VPN_USER_NAME "user-name"
#define NM_SETTING_VPN_PERSISTENT "persistent"
#define NM_SETTING_VPN_DATA "data"
#define NM_SETTING_VPN_SECRETS "secrets"
@ -85,6 +86,7 @@ GType nm_setting_vpn_get_type (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);
gboolean nm_setting_vpn_get_persistent (NMSettingVPN *setting);
guint32 nm_setting_vpn_get_num_data_items (NMSettingVPN *setting);
void nm_setting_vpn_add_data_item (NMSettingVPN *setting,

View file

@ -35,6 +35,7 @@
#include "reader.h"
#include "common.h"
#include "utils.h"
#include "nm-core-internal.h"
/* Some setting properties also contain setting names, such as
* NMSettingConnection's 'type' property (which specifies the base type of the
@ -616,7 +617,8 @@ read_hash_of_string (GKeyFile *file, NMSetting *setting, const char *key)
continue;
if (NM_IS_SETTING_VPN (setting)) {
if (strcmp (*iter, NM_SETTING_VPN_SERVICE_TYPE) && strcmp (*iter, NM_SETTING_VPN_USER_NAME))
/* Add any item that's not a class property to the data hash */
if (!g_object_class_find_property (G_OBJECT_GET_CLASS (setting), *iter))
nm_setting_vpn_add_data_item (NM_SETTING_VPN (setting), *iter, value);
}
if (NM_IS_SETTING_BOND (setting)) {