Commit 98375657 authored by Dan Winship's avatar Dan Winship

libnm-core: improve NMSettingIP4Config / NMSettingIP6Config property types

Make the :addresses and :routes properties be GPtrArrays of
NMIP4Address, etc, rather than just reflecting the D-Bus data.

Make the :dns properties be arrays of strings rather than arrays of
binary IP addresses (and update the corresponding APIs as well).
parent 9ed6bd2b
......@@ -789,9 +789,6 @@ vpn_data_item (const char *key, const char *value, gpointer user_data)
GValue val = G_VALUE_INIT; \
g_value_init (&val, G_TYPE_STRING); \
g_object_get_property (G_OBJECT (setting), property_name, &val); \
/* Getters return allocated values, and returning the string \
* the GValue copied from the object without unsetting the \
* GValue fulfills that requirement. */ \
s = g_value_dup_string (&val); \
g_value_unset (&val); \
return s; \
......@@ -1200,8 +1197,82 @@ DEFINE_GETTER (nmc_property_ib_get_parent, NM_SETTING_INFINIBAND_PARENT)
DEFINE_GETTER (nmc_property_ipv4_get_method, NM_SETTING_IP4_CONFIG_METHOD)
DEFINE_GETTER (nmc_property_ipv4_get_dns, NM_SETTING_IP4_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dns_search, NM_SETTING_IP4_CONFIG_DNS_SEARCH)
DEFINE_GETTER (nmc_property_ipv4_get_addresses, NM_SETTING_IP4_CONFIG_ADDRESSES)
DEFINE_GETTER (nmc_property_ipv4_get_routes, NM_SETTING_IP4_CONFIG_ROUTES)
static char *
nmc_property_ipv4_get_addresses (NMSetting *setting)
{
NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
GString *printable;
guint32 num_addresses, i;
NMIP4Address *addr;
char buf[INET_ADDRSTRLEN];
printable = g_string_new (NULL);
num_addresses = nm_setting_ip4_config_get_num_addresses (s_ip4);
for (i = 0; i < num_addresses; i++) {
addr = nm_setting_ip4_config_get_address (s_ip4, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), buf);
g_string_append_printf (printable, "ip = %s", buf);
g_string_append_printf (printable, "/%u", nm_ip4_address_get_prefix (addr));
if (nm_ip4_address_get_gateway (addr)) {
nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), buf);
g_string_append_printf (printable, ", gw = %s", buf);
}
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
}
static char *
nmc_property_ipv4_get_routes (NMSetting *setting)
{
NMSettingIP4Config *s_ip4 = NM_SETTING_IP4_CONFIG (setting);
GString *printable;
guint32 num_routes, i;
NMIP4Route *route;
char buf[INET_ADDRSTRLEN];
printable = g_string_new (NULL);
num_routes = nm_setting_ip4_config_get_num_routes (s_ip4);
for (i = 0; i < num_routes; i++) {
route = nm_setting_ip4_config_get_route (s_ip4, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), buf);
g_string_append_printf (printable, "ip = %s", buf);
g_string_append_printf (printable, "/%u", nm_ip4_route_get_prefix (route));
if (nm_ip4_route_get_next_hop (route)) {
nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), buf);
g_string_append_printf (printable, ", nh = %s", buf);
}
if (nm_ip4_route_get_metric (route))
g_string_append_printf (printable, ", mt = %u", nm_ip4_route_get_metric (route));
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
}
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_routes, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv4_get_ignore_auto_dns, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv4_get_dhcp_client_id, NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID)
......@@ -1214,8 +1285,82 @@ DEFINE_GETTER (nmc_property_ipv4_get_may_fail, NM_SETTING_IP4_CONFIG_MAY_FAIL)
DEFINE_GETTER (nmc_property_ipv6_get_method, NM_SETTING_IP6_CONFIG_METHOD)
DEFINE_GETTER (nmc_property_ipv6_get_dns, NM_SETTING_IP6_CONFIG_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_dns_search, NM_SETTING_IP6_CONFIG_DNS_SEARCH)
DEFINE_GETTER (nmc_property_ipv6_get_addresses, NM_SETTING_IP6_CONFIG_ADDRESSES)
DEFINE_GETTER (nmc_property_ipv6_get_routes, NM_SETTING_IP6_CONFIG_ROUTES)
static char *
nmc_property_ipv6_get_addresses (NMSetting *setting)
{
NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
GString *printable;
guint32 num_addresses, i;
NMIP6Address *addr;
char buf[INET6_ADDRSTRLEN];
printable = g_string_new (NULL);
num_addresses = nm_setting_ip6_config_get_num_addresses (s_ip6);
for (i = 0; i < num_addresses; i++) {
addr = nm_setting_ip6_config_get_address (s_ip6, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), buf);
g_string_append_printf (printable, "ip = %s", buf);
g_string_append_printf (printable, "/%u", nm_ip6_address_get_prefix (addr));
if (nm_ip6_address_get_gateway (addr)) {
nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), buf);
g_string_append_printf (printable, ", gw = %s", buf);
}
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
}
static char *
nmc_property_ipv6_get_routes (NMSetting *setting)
{
NMSettingIP6Config *s_ip6 = NM_SETTING_IP6_CONFIG (setting);
GString *printable;
guint32 num_routes, i;
NMIP6Route *route;
char buf[INET6_ADDRSTRLEN];
printable = g_string_new (NULL);
num_routes = nm_setting_ip6_config_get_num_routes (s_ip6);
for (i = 0; i < num_routes; i++) {
route = nm_setting_ip6_config_get_route (s_ip6, i);
if (printable->len > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), buf);
g_string_append_printf (printable, "ip = %s", buf);
g_string_append_printf (printable, "/%u", nm_ip6_route_get_prefix (route));
if (nm_ip6_route_get_next_hop (route)) {
nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), buf);
g_string_append_printf (printable, ", nh = %s", buf);
}
if (nm_ip6_route_get_metric (route))
g_string_append_printf (printable, ", mt = %u", nm_ip6_route_get_metric (route));
g_string_append (printable, " }");
}
return g_string_free (printable, FALSE);
}
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_routes, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES)
DEFINE_GETTER (nmc_property_ipv6_get_ignore_auto_dns, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS)
DEFINE_GETTER (nmc_property_ipv6_get_never_default, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT)
......@@ -2885,19 +3030,20 @@ DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv4_allowed_method, ipv4_valid_methods)
static gboolean
nmc_property_ipv4_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
char **strv = NULL, **iter, *addr;
guint32 ip4_addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
strv = nmc_strsplit_set (val, " \t,", 0);
for (iter = strv; iter && *iter; iter++) {
if (inet_pton (AF_INET, g_strstrip (*iter), &ip4_addr) < 1) {
g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), *iter);
addr = g_strstrip (*iter);
if (inet_pton (AF_INET, addr, &ip4_addr) < 1) {
g_set_error (error, 1, 0, _("invalid IPv4 address '%s'"), addr);
g_strfreev (strv);
return FALSE;
}
nm_setting_ip4_config_add_dns (NM_SETTING_IP4_CONFIG (setting), ip4_addr);
nm_setting_ip4_config_add_dns (NM_SETTING_IP4_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
......@@ -2916,7 +3062,7 @@ _validate_and_remove_ipv4_dns (NMSettingIP4Config *setting,
return FALSE;
}
ret = nm_setting_ip4_config_remove_dns_by_value (setting, ip4_addr);
ret = nm_setting_ip4_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
......@@ -3230,19 +3376,20 @@ DEFINE_ALLOWED_VAL_FUNC (nmc_property_ipv6_allowed_method, ipv6_valid_methods)
static gboolean
nmc_property_ipv6_set_dns (NMSetting *setting, const char *prop, const char *val, GError **error)
{
char **strv = NULL, **iter;
char **strv = NULL, **iter, *addr;
struct in6_addr ip6_addr;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
strv = nmc_strsplit_set (val, " \t,", 0);
for (iter = strv; iter && *iter; iter++) {
if (inet_pton (AF_INET6, g_strstrip (*iter), &ip6_addr) < 1) {
g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), *iter);
addr = g_strstrip (*iter);
if (inet_pton (AF_INET6, addr, &ip6_addr) < 1) {
g_set_error (error, 1, 0, _("invalid IPv6 address '%s'"), addr);
g_strfreev (strv);
return FALSE;
}
nm_setting_ip6_config_add_dns (NM_SETTING_IP6_CONFIG (setting), &ip6_addr);
nm_setting_ip6_config_add_dns (NM_SETTING_IP6_CONFIG (setting), addr);
}
g_strfreev (strv);
return TRUE;
......@@ -3261,7 +3408,7 @@ _validate_and_remove_ipv6_dns (NMSettingIP6Config *setting,
return FALSE;
}
ret = nm_setting_ip6_config_remove_dns_by_value (setting, &ip6_addr);
ret = nm_setting_ip6_config_remove_dns_by_value (setting, dns);
if (!ret)
g_set_error (error, 1, 0, _("the property doesn't contain DNS server '%s'"), dns);
return ret;
......
This diff is collapsed.
......@@ -47,7 +47,7 @@ typedef struct {
int ip_entry_width;
int metric_entry_width;
GSList *routes;
GPtrArray *routes;
NmtNewtWidget *list;
} NmtRouteTablePrivate;
......@@ -87,7 +87,7 @@ route_list_transform_to_route (GBinding *binding,
int n = GPOINTER_TO_INT (user_data);
gpointer route;
route = g_slist_nth_data (priv->routes, n);
route = priv->routes->pdata[n];
if (route)
g_value_set_boxed (target_value, route);
return route != NULL;
......@@ -102,31 +102,25 @@ route_list_transform_from_route (GBinding *binding,
NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
GSList *routes, *nth;
GPtrArray *routes;
gpointer route;
nth = g_slist_nth (priv->routes, n);
if (!nth)
if (n >= priv->routes->len)
return FALSE;
route = priv->routes->pdata[n];
routes = priv->routes;
priv->routes = NULL;
if (nth->data) {
if (route) {
if (priv->family == AF_INET)
nm_ip4_route_unref (nth->data);
nm_ip4_route_unref (route);
else if (priv->family == AF_INET6)
nm_ip6_route_unref (nth->data);
}
nth->data = g_value_dup_boxed (source_value);
if (priv->family == AF_INET) {
nm_utils_ip4_routes_to_gvalue (routes, target_value);
g_slist_free_full (routes, (GDestroyNotify) nm_ip4_route_unref);
} else if (priv->family == AF_INET6) {
nm_utils_ip6_routes_to_gvalue (routes, target_value);
g_slist_free_full (routes, (GDestroyNotify) nm_ip6_route_unref);
nm_ip6_route_unref (route);
}
routes->pdata[n] = g_value_dup_boxed (source_value);
g_value_take_boxed (target_value, routes);
return TRUE;
}
......@@ -171,16 +165,16 @@ add_route (NmtWidgetList *list,
route = nm_ip4_route_new ();
nm_ip4_route_set_prefix (route, 32);
priv->routes = g_slist_append (priv->routes, route);
nmt_widget_list_set_length (list, g_slist_length (priv->routes));
g_ptr_array_add (priv->routes, route);
nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip4-routes");
} else {
NMIP6Route *route;
route = nm_ip6_route_new ();
nm_ip6_route_set_prefix (route, 128);
priv->routes = g_slist_append (priv->routes, route);
nmt_widget_list_set_length (list, g_slist_length (priv->routes));
g_ptr_array_add (priv->routes, route);
nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip6-routes");
}
}
......@@ -191,16 +185,14 @@ remove_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
GSList *nth;
gpointer route;
nth = g_slist_nth (priv->routes, num);
if (!nth)
if (num >= priv->routes->len)
return;
route = nth->data;
priv->routes = g_slist_delete_link (priv->routes, nth);
nmt_widget_list_set_length (list, g_slist_length (priv->routes));
route = priv->routes->pdata[num];
g_ptr_array_remove_index (priv->routes, num);
nmt_widget_list_set_length (list, priv->routes->len);
if (priv->family == AF_INET) {
nm_ip4_route_unref (route);
......@@ -271,10 +263,7 @@ nmt_route_table_finalize (GObject *object)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (object);
if (priv->family == AF_INET)
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
else if (priv->family == AF_INET6)
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
g_ptr_array_unref (priv->routes);
G_OBJECT_CLASS (nmt_route_table_parent_class)->finalize (object);
}
......@@ -286,24 +275,36 @@ nmt_route_table_set_property (GObject *object,
GParamSpec *pspec)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (object);
GPtrArray *array;
int i;
switch (prop_id) {
case PROP_FAMILY:
priv->family = g_value_get_int (value);
if (priv->family == AF_INET)
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
else
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list),
g_slist_length (priv->routes));
array = g_value_get_boxed (value);
g_ptr_array_set_size (priv->routes, 0);
for (i = 0; i < array->len; i++) {
nm_ip4_route_ref (array->pdata[i]);
g_ptr_array_add (priv->routes, array->pdata[i]);
}
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list),
g_slist_length (priv->routes));
array = g_value_get_boxed (value);
g_ptr_array_set_size (priv->routes, 0);
for (i = 0; i < array->len; i++) {
nm_ip6_route_ref (array->pdata[i]);
g_ptr_array_add (priv->routes, array->pdata[i]);
}
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -325,11 +326,11 @@ nmt_route_table_get_property (GObject *object,
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
nm_utils_ip4_routes_to_gvalue (priv->routes, value);
g_value_set_boxed (value, priv->routes);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
nm_utils_ip6_routes_to_gvalue (priv->routes, value);
g_value_set_boxed (value, priv->routes);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -337,11 +338,6 @@ nmt_route_table_get_property (GObject *object,
}
}
#define DBUS_TYPE_G_ARRAY_OF_UINT (dbus_g_type_get_collection ("GArray", G_TYPE_UINT))
#define DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_ARRAY_OF_UINT))
#define DBUS_TYPE_G_IP6_ROUTE (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_IP6_ROUTE))
static void
nmt_route_table_class_init (NmtRouteTableClass *table_class)
{
......@@ -373,11 +369,13 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
* #NMSettingIP4Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET
*
* Element-type: NMIP4Route
*/
g_object_class_install_property
(object_class, PROP_IP4_ROUTES,
g_param_spec_boxed ("ip4-routes", "", "",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
......@@ -387,11 +385,13 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
* #NMSettingIP6Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET6
*
* Element-type: NMIP6Route
*/
g_object_class_install_property
(object_class, PROP_IP6_ROUTES,
g_param_spec_boxed ("ip6-routes", "", "",
DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
......@@ -65,5 +65,12 @@ GSList * _nm_utils_hash_values_to_slist (GHashTable *hash);
GHashTable *_nm_utils_copy_strdict (GHashTable *strdict);
typedef gpointer (*NMUtilsCopyFunc) (gpointer);
GPtrArray *_nm_utils_copy_slist_to_array (const GSList *list,
NMUtilsCopyFunc copy_func,
GDestroyNotify unref_func);
GSList *_nm_utils_copy_array_to_slist (const GPtrArray *array,
NMUtilsCopyFunc copy_func);
#endif
......@@ -68,7 +68,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_IP4_CONFIG)
typedef struct {
char *method;
GArray *dns; /* array of guint32; elements in network byte order */
GSList *dns; /* list of IP address strings */
GSList *dns_search; /* list of strings */
GSList *addresses; /* array of NMIP4Address */
GSList *address_labels; /* list of strings */
......@@ -139,7 +139,7 @@ nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
{
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns->len;
return g_slist_length (NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->dns);
}
/**
......@@ -147,26 +147,36 @@ nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting)
* @setting: the #NMSettingIP4Config
* @i: index number of the DNS server to return
*
* Returns: the IPv4 address (network byte order) of the DNS server at index
* @i
* Returns: the IPv4 address of the DNS server at index @i
**/
guint32
const char *
nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
{
NMSettingIP4ConfigPrivate *priv;
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 0);
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), NULL);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
g_return_val_if_fail (i <= priv->dns->len, 0);
g_return_val_if_fail (i < g_slist_length (priv->dns), NULL);
return (const char *) g_slist_nth_data (priv->dns, i);
}
return g_array_index (priv->dns, guint32, i);
static const char *
canonicalize_ip (const char *ip)
{
in_addr_t addr;
int ret;
ret = inet_pton (AF_INET, ip, &addr);
g_return_val_if_fail (ret == 1, NULL);
return nm_utils_inet4_ntop (addr, NULL);
}
/**
* nm_setting_ip4_config_add_dns:
* @setting: the #NMSettingIP4Config
* @dns: the IPv4 address (network byte order) of the DNS server to add
* @dns: the IPv4 address of the DNS server to add
*
* Adds a new DNS server to the setting.
*
......@@ -174,20 +184,27 @@ nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i)
* known
**/
gboolean
nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns)
nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, const char *dns)
{
NMSettingIP4ConfigPrivate *priv;
int i;
const char *dns_canonical;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
g_return_val_if_fail (dns != NULL, FALSE);
g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
for (i = 0; i < priv->dns->len; i++) {
if (dns == g_array_index (priv->dns, guint32, i))
dns_canonical = canonicalize_ip (dns);
g_return_val_if_fail (dns_canonical != NULL, FALSE);
for (iter = priv->dns; iter; iter = g_slist_next (iter)) {
if (!strcmp (dns_canonical, (char *) iter->data))
return FALSE;
}
g_array_append_val (priv->dns, dns);
priv->dns = g_slist_append (priv->dns, g_strdup (dns_canonical));
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
return TRUE;
}
......@@ -203,13 +220,16 @@ void
nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
{
NMSettingIP4ConfigPrivate *priv;
GSList *elt;
g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
g_return_if_fail (i <= priv->dns->len);
elt = g_slist_nth (priv->dns, i);
g_return_if_fail (elt != NULL);
g_array_remove_index (priv->dns, i);
g_free (elt->data);
priv->dns = g_slist_delete_link (priv->dns, elt);
g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS);
}
......@@ -221,20 +241,26 @@ nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i)
* Removes the DNS server @dns.
*
* Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not.
* domain was already known
**/
gboolean
nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns)
nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, const char *dns)
{
NMSettingIP4ConfigPrivate *priv;
int i;
const char *dns_canonical;
GSList *iter;
g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE);
g_return_val_if_fail (dns != NULL, FALSE);
g_return_val_if_fail (dns[0] != '\0', FALSE);
priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);