summaryrefslogtreecommitdiff
path: root/libnm/nm-ip4-config.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm/nm-ip4-config.c')
-rw-r--r--libnm/nm-ip4-config.c79
1 files changed, 33 insertions, 46 deletions
diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c
index ce6c6660f8..02d5ff2569 100644
--- a/libnm/nm-ip4-config.c
+++ b/libnm/nm-ip4-config.c
@@ -24,7 +24,6 @@
#include <nm-setting-ip4-config.h>
#include "nm-ip4-config.h"
#include "nm-dbus-interface.h"
-#include "nm-types-private.h"
#include "nm-object-private.h"
#include "nm-utils.h"
@@ -33,11 +32,11 @@ G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_OBJECT)
#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
typedef struct {
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
char *gateway;
- GSList *addresses;
- GSList *routes;
+ GPtrArray *addresses;
+ GPtrArray *routes;
char **nameservers;
char **domains;
char **searches;
@@ -62,6 +61,8 @@ nm_ip4_config_init (NMIP4Config *config)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
+ priv->addresses = g_ptr_array_new ();
+ priv->routes = g_ptr_array_new ();
priv->nameservers = g_new0 (char *, 1);
priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1);
@@ -69,58 +70,39 @@ nm_ip4_config_init (NMIP4Config *config)
}
static gboolean
-demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- priv->addresses = NULL;
-
- priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
+ g_ptr_array_unref (priv->addresses);
+ priv->addresses = nm_utils_ip4_addresses_from_variant (value);
_nm_object_queue_notify (object, NM_IP4_CONFIG_ADDRESSES);
return TRUE;
}
static gboolean
-demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
- GArray *ip_array;
char ***obj_field;
- int i;
-
- if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY))
- return FALSE;
-
- ip_array = g_value_get_boxed (value);
obj_field = field;
if (*obj_field)
g_strfreev (*obj_field);
- *obj_field = g_new (char *, ip_array->len + 1);
- for (i = 0; i < ip_array->len; i++) {
- guint32 ip = g_array_index (ip_array, guint32, i);
- const char *str;
-
- str = nm_utils_inet4_ntop (ip, NULL);
- (*obj_field)[i] = g_strdup (str);
- }
- (*obj_field)[i] = NULL;
+ *obj_field = nm_utils_ip4_dns_from_variant (value);
_nm_object_queue_notify (object, pspec->name);
return TRUE;
}
static gboolean
-demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
- priv->routes = NULL;
-
- priv->routes = nm_utils_ip4_routes_from_gvalue (value);
+ g_ptr_array_unref (priv->routes);
+ priv->routes = nm_utils_ip4_routes_from_variant (value);
_nm_object_queue_notify (object, NM_IP4_CONFIG_ROUTES);
return TRUE;
@@ -156,8 +138,8 @@ finalize (GObject *object)
g_free (priv->gateway);
- g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
- g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
+ g_ptr_array_unref (priv->addresses);
+ g_ptr_array_unref (priv->routes);
g_strfreev (priv->nameservers);
g_strfreev (priv->domains);
@@ -176,17 +158,16 @@ get_property (GObject *object,
GParamSpec *pspec)
{
NMIP4Config *self = NM_IP4_CONFIG (object);
- NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (self);
switch (prop_id) {
case PROP_GATEWAY:
g_value_set_string (value, nm_ip4_config_get_gateway (self));
break;
case PROP_ADDRESSES:
- nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
+ g_value_set_boxed (value, nm_ip4_config_get_addresses (self));
break;
case PROP_ROUTES:
- nm_utils_ip4_routes_to_gvalue (priv->routes, value);
+ g_value_set_boxed (value, nm_ip4_config_get_routes (self));
break;
case PROP_NAMESERVERS:
g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self));
@@ -238,23 +219,29 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
* NMIP4Config:addresses:
*
* The #GPtrArray containing #NMIP4Address<!-- -->es of the configuration.
+ *
+ * Element-type: NMIP4Address
**/
g_object_class_install_property
(object_class, PROP_ADDRESSES,
- g_param_spec_pointer (NM_IP4_CONFIG_ADDRESSES, "", "",
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
+ g_param_spec_boxed (NM_IP4_CONFIG_ADDRESSES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
/**
* NMIP4Config:routes:
*
* The #GPtrArray containing #NMSettingIP4Routes of the configuration.
+ *
+ * Element-type: NMIP4Route
**/
g_object_class_install_property
(object_class, PROP_ROUTES,
- g_param_spec_pointer (NM_IP4_CONFIG_ROUTES, "", "",
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
+ g_param_spec_boxed (NM_IP4_CONFIG_ROUTES, "", "",
+ G_TYPE_PTR_ARRAY,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
/**
* NMIP4Config:nameservers:
@@ -327,10 +314,10 @@ nm_ip4_config_get_gateway (NMIP4Config *config)
*
* Gets the IP4 addresses (containing the address, prefix, and gateway).
*
- * Returns: (element-type NMIP4Address): the #GSList containing #NMIP4Address<!-- -->es.
+ * Returns: (element-type NMIP4Address): the #GPtrArray containing #NMIP4Address<!-- -->es.
* This is the internal copy used by the configuration and must not be modified.
**/
-const GSList *
+GPtrArray *
nm_ip4_config_get_addresses (NMIP4Config *config)
{
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
@@ -410,11 +397,11 @@ nm_ip4_config_get_wins_servers (NMIP4Config *config)
*
* Gets the routes.
*
- * Returns: (element-type NMIP4Route): the #GSList containing
+ * Returns: (element-type NMIP4Route): the #GPtrArray containing
* #NMIP4Routes. This is the internal copy used by the configuration,
* and must not be modified.
**/
-const GSList *
+GPtrArray *
nm_ip4_config_get_routes (NMIP4Config *config)
{
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);