diff options
| author | Michael Biebl <biebl@debian.org> | 2013-02-03 14:49:22 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2013-02-03 14:49:22 +0100 |
| commit | 9c202e3e860b3be9e1f8882630b69affbb130102 (patch) | |
| tree | 8202bf39f2129486971fa7d5ae0dee61a561aa53 /libnm-util/nm-setting-connection.c | |
| parent | 36cb2f364a821e1be50b23e03a18891ec55adb06 (diff) | |
Imported Upstream version 0.9.7.995 upstream/0.9.7.995
Diffstat (limited to 'libnm-util/nm-setting-connection.c')
| -rw-r--r-- | libnm-util/nm-setting-connection.c | 133 |
1 files changed, 117 insertions, 16 deletions
diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c index 80380f3c..1222f976 100644 --- a/libnm-util/nm-setting-connection.c +++ b/libnm-util/nm-setting-connection.c @@ -19,16 +19,16 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2011 Red Hat, Inc. + * (C) Copyright 2007 - 2012 Red Hat, Inc. * (C) Copyright 2007 - 2008 Novell, Inc. */ #include <string.h> -#include <ctype.h> #include "nm-utils.h" #include "nm-dbus-glib-types.h" #include "nm-param-spec-specialized.h" #include "nm-setting-connection.h" +#include "nm-setting-private.h" /** * SECTION:nm-setting-connection @@ -59,7 +59,12 @@ nm_setting_connection_error_quark (void) } -G_DEFINE_TYPE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING) +G_DEFINE_TYPE_WITH_CODE (NMSettingConnection, nm_setting_connection, NM_TYPE_SETTING, + _nm_register_setting (NM_SETTING_CONNECTION_SETTING_NAME, + g_define_type_id, + 0, + NM_SETTING_CONNECTION_ERROR)) +NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CONNECTION) #define NM_SETTING_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionPrivate)) @@ -83,6 +88,7 @@ typedef struct { guint64 timestamp; gboolean read_only; char *zone; + GSList *secondaries; /* secondary connections to activate with the base connection */ } NMSettingConnectionPrivate; enum { @@ -97,6 +103,7 @@ enum { PROP_ZONE, PROP_MASTER, PROP_SLAVE_TYPE, + PROP_SECONDARIES, LAST_PROP }; @@ -529,31 +536,103 @@ nm_setting_connection_is_slave_type (NMSettingConnection *setting, return !g_strcmp0 (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->slave_type, type); } -static gint -find_setting_by_name (gconstpointer a, gconstpointer b) +/** + * nm_setting_connection_get_num_secondaries: + * @setting: the #NMSettingConnection + * + * Returns: the number of configured secondary connection UUIDs + **/ +guint32 +nm_setting_connection_get_num_secondaries (NMSettingConnection *setting) { - NMSetting *setting = NM_SETTING (a); - const char *str = (const char *) b; + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), 0); - return strcmp (nm_setting_get_name (setting), str); + return g_slist_length (NM_SETTING_CONNECTION_GET_PRIVATE (setting)->secondaries); } -static gboolean -validate_uuid (const char *uuid) +/** + * nm_setting_connection_get_secondary: + * @setting: the #NMSettingConnection + * @idx: the zero-based index of the secondary connection UUID entry + * + * Returns: the secondary connection UUID at index @idx + **/ +const char * +nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx) { - int i; + NMSettingConnectionPrivate *priv; - if (!uuid || !strlen (uuid)) - return FALSE; + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL); + + priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting); + g_return_val_if_fail (idx <= g_slist_length (priv->secondaries), NULL); + + return (const char *) g_slist_nth_data (priv->secondaries, idx); +} + +/** + * nm_setting_connection_add_secondary: + * @setting: the #NMSettingConnection + * @sec_uuid: the secondary connection UUID to add + * + * Adds a new secondary connetion UUID to the setting. + * + * Returns: %TRUE if the secondary connection UUID was added; %FALSE if the UUID + * was already present + **/ +gboolean +nm_setting_connection_add_secondary (NMSettingConnection *setting, + const char *sec_uuid) +{ + NMSettingConnectionPrivate *priv; + GSList *iter; - for (i = 0; i < strlen (uuid); i++) { - if (!isxdigit (uuid[i]) && (uuid[i] != '-')) + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), FALSE); + g_return_val_if_fail (sec_uuid != NULL, FALSE); + g_return_val_if_fail (sec_uuid[0] != '\0', FALSE); + + priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting); + for (iter = priv->secondaries; iter; iter = g_slist_next (iter)) { + if (!strcmp (sec_uuid, (char *) iter->data)) return FALSE; } + priv->secondaries = g_slist_append (priv->secondaries, g_strdup (sec_uuid)); return TRUE; } +/** + * nm_setting_connection_remove_secondary: + * @setting: the #NMSettingConnection + * @idx: index number of the secondary connection UUID + * + * Removes the secondary coonnection UUID at index @idx. + **/ +void +nm_setting_connection_remove_secondary (NMSettingConnection *setting, guint32 idx) +{ + NMSettingConnectionPrivate *priv; + GSList *elt; + + g_return_if_fail (NM_IS_SETTING_CONNECTION (setting)); + + priv = NM_SETTING_CONNECTION_GET_PRIVATE (setting); + elt = g_slist_nth (priv->secondaries, idx); + g_return_if_fail (elt != NULL); + + g_free (elt->data); + priv->secondaries = g_slist_delete_link (priv->secondaries, elt); +} + +static gint +find_setting_by_name (gconstpointer a, gconstpointer b) +{ + NMSetting *setting = NM_SETTING (a); + const char *str = (const char *) b; + + return strcmp (nm_setting_get_name (setting), str); +} + static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { @@ -579,7 +658,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY, NM_SETTING_CONNECTION_UUID); return FALSE; - } else if (!validate_uuid (priv->uuid)) { + } else if (!nm_utils_is_uuid (priv->uuid)) { g_set_error (error, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, @@ -750,6 +829,10 @@ set_property (GObject *object, guint prop_id, g_free (priv->slave_type); priv->slave_type = g_value_dup_string (value); break; + case PROP_SECONDARIES: + nm_utils_slist_free (priv->secondaries, g_free); + priv->secondaries = g_value_dup_boxed (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -804,6 +887,9 @@ get_property (GObject *object, guint prop_id, case PROP_SLAVE_TYPE: g_value_set_string (value, nm_setting_connection_get_slave_type (setting)); break; + case PROP_SECONDARIES: + g_value_set_boxed (value, priv->secondaries); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1042,4 +1128,19 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) "connection is not a slave.", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE)); + + /** + * NMSettingConnection:secondaries: + * + * List of connection UUIDs that should be activated when the base connection + * itself is activated. + **/ + g_object_class_install_property + (object_class, PROP_SECONDARIES, + _nm_param_spec_specialized (NM_SETTING_CONNECTION_SECONDARIES, + "Secondaries", + "List of connection UUIDs that should be activated " + "when the base connection itself is activated.", + DBUS_TYPE_G_LIST_OF_STRING, + G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE)); } |