diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver index 60614d2e4a..b3c74aaca3 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -361,9 +361,13 @@ global: nm_setting_ip4_config_get_type; nm_setting_ip4_config_new; nm_setting_ip4_config_remove_address; + nm_setting_ip4_config_remove_address_by_value; nm_setting_ip4_config_remove_dns; + nm_setting_ip4_config_remove_dns_by_value; nm_setting_ip4_config_remove_dns_search; + nm_setting_ip4_config_remove_dns_search_by_value; nm_setting_ip4_config_remove_route; + nm_setting_ip4_config_remove_route_by_value; nm_setting_ip6_config_add_address; nm_setting_ip6_config_add_dns; nm_setting_ip6_config_add_dns_search; @@ -393,9 +397,13 @@ global: nm_setting_ip6_config_new; nm_setting_ip6_config_privacy_get_type; nm_setting_ip6_config_remove_address; + nm_setting_ip6_config_remove_address_by_value; nm_setting_ip6_config_remove_dns; + nm_setting_ip6_config_remove_dns_by_value; nm_setting_ip6_config_remove_dns_search; + nm_setting_ip6_config_remove_dns_search_by_value; nm_setting_ip6_config_remove_route; + nm_setting_ip6_config_remove_route_by_value; nm_setting_need_secrets; nm_setting_new_from_hash; nm_setting_olpc_mesh_error_get_type; diff --git a/libnm-util/nm-setting-ip4-config.c b/libnm-util/nm-setting-ip4-config.c index 8a07293e40..bdb77783e8 100644 --- a/libnm-util/nm-setting-ip4-config.c +++ b/libnm-util/nm-setting-ip4-config.c @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2013 Red Hat, Inc. + * (C) Copyright 2007 - 2014 Red Hat, Inc. * (C) Copyright 2007 - 2008 Novell, Inc. */ @@ -218,6 +218,37 @@ nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS); } +/** + * nm_setting_ip4_config_remove_dns_by_value: + * @setting: the #NMSettingIP4Config + * @dns: the DNS server to remove + * + * Removes the DNS server @dns. + * + * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not. + * domain was already known + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns) +{ + NMSettingIP4ConfigPrivate *priv; + int i; + + g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), 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)) { + g_array_remove_index (priv->dns, i); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip4_config_clear_dns: * @setting: the #NMSettingIP4Config @@ -326,6 +357,39 @@ nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH); } +/** + * nm_setting_ip4_config_remove_dns_search_by_value: + * @setting: the #NMSettingIP4Config + * @dns_search: the search domain to remove + * + * Removes the DNS search domain @dns_search. + * + * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not. + * + * Since 0.9.10 + **/ +gboolean +nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting, + const char *dns_search) +{ + NMSettingIP4ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE); + g_return_val_if_fail (dns_search != NULL, FALSE); + g_return_val_if_fail (dns_search[0] != '\0', FALSE); + + priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting); + for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) { + if (!strcmp (dns_search, (char *) iter->data)) { + priv->dns_search = g_slist_delete_link (priv->dns_search, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_DNS_SEARCH); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip4_config_clear_dns_searches: * @setting: the #NMSettingIP4Config @@ -436,6 +500,39 @@ nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES); } +/** + * nm_setting_ip4_config_remove_address_by_value: + * @setting: the #NMSettingIP4Config + * @address: the IP address to remove + * + * Removes the address @address. + * + * Returns: %TRUE if the address was found and removed; %FALSE if it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, + NMIP4Address *address) +{ + NMSettingIP4ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE); + g_return_val_if_fail (address != NULL, FALSE); + + priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting); + for (iter = priv->addresses; iter; iter = g_slist_next (iter)) { + if (nm_ip4_address_compare ((NMIP4Address *) iter->data, address)) { + nm_ip4_address_unref ((NMIP4Address *) iter->data); + priv->addresses = g_slist_delete_link (priv->addresses, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ADDRESSES); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip4_config_clear_addresses: * @setting: the #NMSettingIP4Config @@ -547,6 +644,39 @@ nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES); } +/** + * nm_setting_ip4_config_remove_route_by_value: + * @setting: the #NMSettingIP4Config + * @route: the route to remove + * + * Removes the route @route. + * + * Returns: %TRUE if the route was found and removed; %FALSE if it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, + NMIP4Route *route) +{ + NMSettingIP4ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP4_CONFIG (setting), FALSE); + g_return_val_if_fail (route != NULL, FALSE); + + priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting); + for (iter = priv->routes; iter; iter = g_slist_next (iter)) { + if (nm_ip4_route_compare ((NMIP4Route *) iter->data, route)) { + nm_ip4_route_unref ((NMIP4Route *) iter->data); + priv->routes = g_slist_delete_link (priv->routes, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP4_CONFIG_ROUTES); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip4_config_clear_routes: * @setting: the #NMSettingIP4Config diff --git a/libnm-util/nm-setting-ip4-config.h b/libnm-util/nm-setting-ip4-config.h index 5f7f3d0017..3f0d006bfa 100644 --- a/libnm-util/nm-setting-ip4-config.h +++ b/libnm-util/nm-setting-ip4-config.h @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2010 Red Hat, Inc. + * (C) Copyright 2007 - 2014 Red Hat, Inc. * (C) Copyright 2007 - 2008 Novell, Inc. */ @@ -189,24 +189,32 @@ guint32 nm_setting_ip4_config_get_num_dns (NMSettingIP4Config * guint32 nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i); gboolean nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns); void nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns); void nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting); -guint32 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting); -const char * nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i); -gboolean nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting, const char *dns_search); -void nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i); -void nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting); +guint32 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting); +const char * nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i); +gboolean nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting, const char *dns_search); +void nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting, const char *dns_search); +void nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting); -guint32 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting); -NMIP4Address *nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i); -gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address); -void nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i); -void nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting); +guint32 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting); +NMIP4Address *nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i); +gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address); +void nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, NMIP4Address *address); +void nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting); guint32 nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting); NMIP4Route * nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i); gboolean nm_setting_ip4_config_add_route (NMSettingIP4Config *setting, NMIP4Route *route); void nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route); void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting); gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting); diff --git a/libnm-util/nm-setting-ip6-config.c b/libnm-util/nm-setting-ip6-config.c index 563e2b0c7e..d421d39ce6 100644 --- a/libnm-util/nm-setting-ip6-config.c +++ b/libnm-util/nm-setting-ip6-config.c @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2013 Red Hat, Inc. + * (C) Copyright 2007 - 2014 Red Hat, Inc. */ #include @@ -241,6 +241,37 @@ nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS); } +/** + * nm_setting_ip6_config_remove_dns_by_value: + * @setting: the #NMSettingIP6Config + * @dns: the IPv6 address of the DNS server to remove + * + * Removes the DNS server at index @i. + * + * Returns: %TRUE if the DNS server was found and removed; %FALSE if it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, + const struct in6_addr *addr) +{ + NMSettingIP6ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); + + priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting); + for (iter = priv->dns; iter; iter = g_slist_next (iter)) { + if (!memcmp (addr, (struct in6_addr *) iter->data, sizeof (struct in6_addr))) { + priv->dns = g_slist_delete_link (priv->dns, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip6_config_clear_dns: * @setting: the #NMSettingIP6Config @@ -347,6 +378,39 @@ nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH); } +/** + * nm_setting_ip6_config_remove_dns_search_by_value: + * @setting: the #NMSettingIP6Config + * @dns_search: the search domain to remove + * + * Removes the DNS search domain @dns_search. + * + * Returns: %TRUE if the DNS search domain was found and removed; %FALSE if it was not. + * + * Since 0.9.10 + **/ +gboolean +nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting, + const char *dns_search) +{ + NMSettingIP6ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); + g_return_val_if_fail (dns_search != NULL, FALSE); + g_return_val_if_fail (dns_search[0] != '\0', FALSE); + + priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting); + for (iter = priv->dns_search; iter; iter = g_slist_next (iter)) { + if (!strcmp (dns_search, (char *) iter->data)) { + priv->dns_search = g_slist_delete_link (priv->dns_search, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_DNS_SEARCH); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip6_config_clear_dns_searches: * @setting: the #NMSettingIP6Config @@ -457,6 +521,38 @@ nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES); } +/** + * nm_setting_ip6_config_remove_address_by_value: + * @setting: the #NMSettingIP6Config + * @address: the address to remove + * + * Removes the address @address. + * + * Returns: %TRUE if the address was found and removed; %FALSE if it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, + NMIP6Address *address) +{ + NMSettingIP6ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); + g_return_val_if_fail (address != NULL, FALSE); + + priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting); + for (iter = priv->addresses; iter; iter = g_slist_next (iter)) { + if (nm_ip6_address_compare ((NMIP6Address *) iter->data, address)) { + priv->addresses = g_slist_delete_link (priv->addresses, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ADDRESSES); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip6_config_clear_addresses: * @setting: the #NMSettingIP6Config @@ -568,6 +664,39 @@ nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i) g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES); } +/** + * nm_setting_ip6_config_remove_route_by_value: + * @setting: the #NMSettingIP6Config + * @route: the route to remove + * + * Removes the route @route. + * + * Returns: %TRUE if the route was found and removed; %FALSE if it was not. + * + * Since: 0.9.10 + **/ +gboolean +nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, + NMIP6Route *route) +{ + NMSettingIP6ConfigPrivate *priv; + GSList *iter; + + g_return_val_if_fail (NM_IS_SETTING_IP6_CONFIG (setting), FALSE); + g_return_val_if_fail (route != NULL, FALSE); + + priv = NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting); + for (iter = priv->routes; iter; iter = g_slist_next (iter)) { + if (nm_ip6_route_compare ((NMIP6Route *) iter->data, route)) { + nm_ip6_route_unref ((NMIP6Route *) iter->data); + priv->routes = g_slist_delete_link (priv->routes, iter); + g_object_notify (G_OBJECT (setting), NM_SETTING_IP6_CONFIG_ROUTES); + return TRUE; + } + } + return FALSE; +} + /** * nm_setting_ip6_config_clear_routes: * @setting: the #NMSettingIP6Config diff --git a/libnm-util/nm-setting-ip6-config.h b/libnm-util/nm-setting-ip6-config.h index 29650486c2..d1f4ca842c 100644 --- a/libnm-util/nm-setting-ip6-config.h +++ b/libnm-util/nm-setting-ip6-config.h @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2007 - 2012 Red Hat, Inc. + * (C) Copyright 2007 - 2014 Red Hat, Inc. */ #ifndef NM_SETTING_IP6_CONFIG_H @@ -219,24 +219,32 @@ guint32 nm_setting_ip6_config_get_num_dns (NMSettingIP const struct in6_addr *nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i); gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *dns); void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, const struct in6_addr *dns); void nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting); -guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting); -const char * nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting, const char *dns_search); -void nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting); +guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting); +const char * nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting, const char *dns_search); +void nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting, const char *dns_search); +void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting); -guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting); -NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i); -gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address); -void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i); -void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting); +guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting); +NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i); +gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address); +void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, NMIP6Address *address); +void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting); guint32 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting); NMIP6Route * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i); gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIP6Route *route); void nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i); +NM_AVAILABLE_IN_0_9_10 +gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, NMIP6Route *route); void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting); gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting);