summary refs log tree commit diff
path: root/libnm-glib/nm-ip6-config.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
committerMichael Biebl <biebl@debian.org>2014-07-06 02:16:10 +0200
commit33491bc4279481db8ae47213e34a6d695a0e8830 (patch)
tree097d2b0fdff3fae6885381ae5e57a182cd8cbbba /libnm-glib/nm-ip6-config.c
parent59c3714a494c3b3765657c0551ad82842d98a7d2 (diff)
Imported Upstream version 0.9.10.0 upstream/0.9.10.0
Diffstat (limited to 'libnm-glib/nm-ip6-config.c')
-rw-r--r--libnm-glib/nm-ip6-config.c248
1 files changed, 191 insertions, 57 deletions
diff --git a/libnm-glib/nm-ip6-config.c b/libnm-glib/nm-ip6-config.c
index 9efc32ee..7c9cfca7 100644
--- a/libnm-glib/nm-ip6-config.c
+++ b/libnm-glib/nm-ip6-config.c
@@ -18,7 +18,7 @@
  * Boston, MA 02110-1301 USA.
  *
  * Copyright (C) 2007 - 2008 Novell, Inc.
- * Copyright (C) 2008 - 2011 Red Hat, Inc.
+ * Copyright (C) 2008 - 2014 Red Hat, Inc.
  */
 
 #include <string.h>
@@ -37,18 +37,22 @@ G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT)
 typedef struct {
 	DBusGProxy *proxy;
 
+	char *gateway;
 	GSList *addresses;
+	GSList *routes;
 	GSList *nameservers;
 	GPtrArray *domains;
-	GSList *routes;
+	GPtrArray *searches;
 } NMIP6ConfigPrivate;
 
 enum {
 	PROP_0,
+	PROP_GATEWAY,
 	PROP_ADDRESSES,
+	PROP_ROUTES,
 	PROP_NAMESERVERS,
 	PROP_DOMAINS,
-	PROP_ROUTES,
+	PROP_SEARCHES,
 
 	LAST_PROP
 };
@@ -76,8 +80,7 @@ demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value,
 {
 	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
 
-	g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
-	g_slist_free (priv->addresses);
+	g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
 	priv->addresses = NULL;
 
 	priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
@@ -109,12 +112,21 @@ demarshal_domains (NMObject *object, GParamSpec *pspec, GValue *value, gpointer
 }
 
 static gboolean
+demarshal_searches (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+{
+	if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
+		return FALSE;
+
+	_nm_object_queue_notify (object, NM_IP6_CONFIG_SEARCHES);
+	return TRUE;
+}
+
+static gboolean
 demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
 {
 	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
 
-	g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
-	g_slist_free (priv->routes);
+	g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
 	priv->routes = NULL;
 
 	priv->routes = nm_utils_ip6_routes_from_gvalue (value);
@@ -128,10 +140,12 @@ register_properties (NMIP6Config *config)
 {
 	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
 	const NMPropertiesInfo property_info[] = {
+		{ NM_IP6_CONFIG_GATEWAY,      &priv->gateway, },
 		{ NM_IP6_CONFIG_ADDRESSES,    &priv->addresses, demarshal_ip6_address_array },
+		{ NM_IP6_CONFIG_ROUTES,       &priv->routes, demarshal_ip6_routes_array },
 		{ NM_IP6_CONFIG_NAMESERVERS,  &priv->nameservers, demarshal_ip6_nameserver_array },
 		{ NM_IP6_CONFIG_DOMAINS,      &priv->domains, demarshal_domains },
-		{ NM_IP6_CONFIG_ROUTES,       &priv->routes, demarshal_ip6_routes_array },
+		{ NM_IP6_CONFIG_SEARCHES,     &priv->searches, demarshal_searches },
 		{ NULL },
 	};
 
@@ -141,6 +155,25 @@ register_properties (NMIP6Config *config)
 }
 
 /**
+ * nm_ip6_config_get_gateway:
+ * @config: a #NMIP6Config
+ *
+ * Gets the IP6 gateway.
+ *
+ * Returns: the IPv6 gateway of the configuration.
+ *
+ * Since: 0.9.10
+ **/
+const char *
+nm_ip6_config_get_gateway (NMIP6Config *config)
+{
+	g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (config));
+	return NM_IP6_CONFIG_GET_PRIVATE (config)->gateway;
+}
+
+/**
  * nm_ip6_config_get_addresses:
  * @config: a #NMIP6Config
  *
@@ -159,6 +192,56 @@ nm_ip6_config_get_addresses (NMIP6Config *config)
 	return NM_IP6_CONFIG_GET_PRIVATE (config)->addresses;
 }
 
+/**
+ * nm_ip6_config_get_num_nameservers:
+ * @config: a #NMIP6Config
+ *
+ * Gets the number of the domain name servers in the configuration.
+ *
+ * Returns: the number of domain name servers
+ *
+ * Since: 0.9.10
+ **/
+guint32
+nm_ip6_config_get_num_nameservers (NMIP6Config *config)
+{
+	g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0);
+
+	_nm_object_ensure_inited (NM_OBJECT (config));
+	return g_slist_length (NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers);
+}
+
+/**
+ * nm_ip6_config_get_nameserver:
+ * @config: a #NMIP6Config
+ * @idx: index of the nameserver to return
+ *
+ * Gets the domain name server at index @idx in the configuration.
+ *
+ * Returns: (array fixed-size=16) (element-type guint8) (transfer none):
+ *          the IPv6 address of domain name server at index @iidx
+ *
+ * Since: 0.9.10
+ **/
+const struct in6_addr *
+nm_ip6_config_get_nameserver (NMIP6Config *config, guint32 idx)
+{
+	NMIP6ConfigPrivate *priv;
+	GSList *item;
+	guint32 i = 0;
+
+	g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (config));
+	priv = NM_IP6_CONFIG_GET_PRIVATE (config);
+
+	for (item = priv->nameservers; item && i < idx; i++)
+		item = item->next;
+
+	g_return_val_if_fail (item, NULL);
+	return item ? (const struct in6_addr *) item->data : NULL;
+}
+
 /* FIXME: like in libnm_util, in6_addr is not introspectable, so skipping here */
 /**
  * nm_ip6_config_get_nameservers: (skip)
@@ -198,13 +281,33 @@ nm_ip6_config_get_domains (NMIP6Config *config)
 }
 
 /**
+ * nm_ip6_config_get_searches:
+ * @config: a #NMIP6Config
+ *
+ * Gets the dns searches.
+ *
+ * Returns: (element-type utf8): the #GPtrArray containing dns searches as strings.
+ * This is the internal copy used by the configuration, and must not be modified.
+ *
+ * Since: 0.9.10
+ **/
+const GPtrArray *
+nm_ip6_config_get_searches (NMIP6Config *config)
+{
+	g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (config));
+	return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->searches);
+}
+
+/**
  * nm_ip6_config_get_routes:
  * @config: a #NMIP6Config
  *
  * Gets the routes.
  *
  * Returns: (element-type NetworkManager.IP6Route): the #GSList containing
- * #NMIP6Route<!-- -->s. This is the internal copy used by the configuration,
+ * #NMIP6Routes. This is the internal copy used by the configuration,
  * and must not be modified.
  **/
 const GSList *
@@ -219,19 +322,11 @@ nm_ip6_config_get_routes (NMIP6Config *config)
 static void
 constructed (GObject *object)
 {
-	DBusGConnection *connection;
-	NMIP6ConfigPrivate *priv;
+	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
 
 	G_OBJECT_CLASS (nm_ip6_config_parent_class)->constructed (object);
 
-	priv = NM_IP6_CONFIG_GET_PRIVATE (object);
-	connection = nm_object_get_connection (NM_OBJECT (object));
-
-	priv->proxy = dbus_g_proxy_new_for_name (connection,
-	                                         NM_DBUS_SERVICE,
-	                                         nm_object_get_path (NM_OBJECT (object)),
-	                                         NM_DBUS_INTERFACE_IP6_CONFIG);
-
+	priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_IP6_CONFIG);
 	register_properties (NM_IP6_CONFIG (object));
 }
 
@@ -240,20 +335,22 @@ finalize (GObject *object)
 {
 	NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
 
-	g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
-	g_slist_free (priv->addresses);
-
-	g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
-	g_slist_free (priv->routes);
+	g_free (priv->gateway);
 
-	g_slist_foreach (priv->nameservers, (GFunc) g_free, NULL);
-	g_slist_free (priv->nameservers);
+	g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
+	g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
+	g_slist_free_full (priv->nameservers, g_free);
 
 	if (priv->domains) {
-		g_ptr_array_foreach (priv->domains, (GFunc) g_free, NULL);
+		g_ptr_array_set_free_func (priv->domains, g_free);
 		g_ptr_array_free (priv->domains, TRUE);
 	}
 
+	if (priv->searches) {
+		g_ptr_array_set_free_func (priv->searches, g_free);
+		g_ptr_array_free (priv->searches, TRUE);
+	}
+
 	g_object_unref (priv->proxy);
 
 	G_OBJECT_CLASS (nm_ip6_config_parent_class)->finalize (object);
@@ -271,17 +368,23 @@ get_property (GObject *object,
 	_nm_object_ensure_inited (NM_OBJECT (object));
 
 	switch (prop_id) {
+	case PROP_GATEWAY:
+		g_value_set_string (value, nm_ip6_config_get_gateway (self));
+		break;
 	case PROP_ADDRESSES:
 		nm_utils_ip6_addresses_to_gvalue (priv->addresses, value);
 		break;
+	case PROP_ROUTES:
+		nm_utils_ip6_routes_to_gvalue (priv->routes, value);
+		break;
 	case PROP_NAMESERVERS:
 		g_value_set_boxed (value, nm_ip6_config_get_nameservers (self));
 		break;
 	case PROP_DOMAINS:
 		g_value_set_boxed (value, nm_ip6_config_get_domains (self));
 		break;
-	case PROP_ROUTES:
-		nm_utils_ip6_routes_to_gvalue (priv->routes, value);
+	case PROP_SEARCHES:
+		g_value_set_boxed (value, nm_ip6_config_get_searches (self));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -309,6 +412,21 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
 	/* properties */
 
 	/**
+	 * NMIP6Config:gateway:
+	 *
+	 * The IPv6 gateway as string
+	 *
+	 * Since: 0.9.10
+	 **/
+	g_object_class_install_property
+	    (object_class, PROP_GATEWAY,
+	     g_param_spec_string (NM_IP6_CONFIG_GATEWAY,
+	                          "Gateway",
+	                          "Gateway",
+	                          NULL,
+	                          G_PARAM_READABLE));
+
+	/**
 	 * NMIP6Config:addresses:
 	 *
 	 * The #GPtrArray containing the IPv6 addresses;  use
@@ -316,12 +434,27 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
 	 * #NMSettingIP6Address objects that is more usable than the raw data.
 	 **/
 	g_object_class_install_property
-		(object_class, PROP_ADDRESSES,
-		 g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES,
-						     "Addresses",
-						     "Addresses",
-						     NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY,
-						     G_PARAM_READABLE));
+	    (object_class, PROP_ADDRESSES,
+	     g_param_spec_boxed (NM_IP6_CONFIG_ADDRESSES,
+	                         "Addresses",
+	                         "Addresses",
+	                         NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY,
+	                         G_PARAM_READABLE));
+
+	/**
+	 * NMIP6Config:routes:
+	 *
+	 * The #GPtrArray containing the IPv6 routes;  use
+	 * nm_utils_ip6_routes_from_gvalue() to return a #GSList of
+	 * #NMSettingIP6Address objects that is more usable than the raw data.
+	 **/
+	g_object_class_install_property
+	    (object_class, PROP_ROUTES,
+	     g_param_spec_boxed (NM_IP6_CONFIG_ROUTES,
+	                         "Routes",
+	                         "Routes",
+	                         NM_TYPE_IP6_ROUTE_OBJECT_ARRAY,
+	                         G_PARAM_READABLE));
 
 	/**
 	 * NMIP6Config:nameservers:
@@ -330,12 +463,12 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
 	 * contain the addresses of nameservers of the configuration.
 	 **/
 	g_object_class_install_property
-		(object_class, PROP_NAMESERVERS,
-		 g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS,
-						    "Nameservers",
-						    "Nameservers",
-						    NM_TYPE_IP6_ADDRESS_ARRAY,
-						    G_PARAM_READABLE));
+	    (object_class, PROP_NAMESERVERS,
+	     g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS,
+	                        "Nameservers",
+	                        "Nameservers",
+	                        NM_TYPE_IP6_ADDRESS_ARRAY,
+	                        G_PARAM_READABLE));
 
 	/**
 	 * NMIP6Config:domains:
@@ -343,26 +476,27 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
 	 * The #GPtrArray containing domain strings of the configuration.
 	 **/
 	g_object_class_install_property
-		(object_class, PROP_DOMAINS,
-		 g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS,
-						    "Domains",
-						    "Domains",
-						    NM_TYPE_STRING_ARRAY,
-						    G_PARAM_READABLE));
+	    (object_class, PROP_DOMAINS,
+	     g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS,
+	                        "Domains",
+	                        "Domains",
+	                        NM_TYPE_STRING_ARRAY,
+	                        G_PARAM_READABLE));
 
 	/**
-	 * NMIP6Config:routes:
+	 * NMIP6Config:searches:
 	 *
-	 * The #GPtrArray containing the IPv6 routes;  use
-	 * nm_utils_ip6_routes_from_gvalue() to return a #GSList of
-	 * #NMSettingIP6Address objects that is more usable than the raw data.
+	 * The #GPtrArray containing dns search strings of the configuration.
+	 *
+	 * Since: 0.9.10
 	 **/
 	g_object_class_install_property
-		(object_class, PROP_ROUTES,
-		 g_param_spec_boxed (NM_IP6_CONFIG_ROUTES,
-		                     "Routes",
-		                     "Routes",
-		                     NM_TYPE_IP6_ROUTE_OBJECT_ARRAY,
-		                     G_PARAM_READABLE));
+	    (object_class, PROP_SEARCHES,
+	     g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES,
+	                        "Searches",
+	                        "DNS Searches",
+	                        NM_TYPE_STRING_ARRAY,
+	                        G_PARAM_READABLE));
+
 }