From 8ee4f58e9ee67df2ef761a691dec55c6008ad4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Wed, 22 Jan 2014 15:31:56 +0100 Subject: [PATCH] libnm-glib: additional functions to get nameservers (rh #1056146) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds two new functions for introspection users to get nameservers: guint32 nm_ip6_config_get_num_nameservers (NMIP6Config *config) const struct in6_addr *nm_ip6_config_get_nameserver (NMIP6Config *config, guint32 idx) The existing function can't be used due to GObject introspection limitations: const GSList *nm_ip6_config_get_nameservers (NMIP6Config *config); https://bugzilla.redhat.com/show_bug.cgi?id=1056146 Signed-off-by: Jiří Klimeš --- libnm-glib/libnm-glib.ver | 2 ++ libnm-glib/nm-ip6-config.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- libnm-glib/nm-ip6-config.h | 16 +++++++------- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver index bf69db4..9f0db93 100644 --- a/libnm-glib/libnm-glib.ver +++ b/libnm-glib/libnm-glib.ver @@ -227,7 +227,9 @@ global: nm_ip6_config_get_addresses; nm_ip6_config_get_domains; nm_ip6_config_get_gateway; + nm_ip6_config_get_nameserver; nm_ip6_config_get_nameservers; + nm_ip6_config_get_num_nameservers; nm_ip6_config_get_routes; nm_ip6_config_get_searches; nm_ip6_config_get_type; diff --git a/libnm-glib/nm-ip6-config.c b/libnm-glib/nm-ip6-config.c index 01e2cae..7c9cfca 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 @@ -192,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) diff --git a/libnm-glib/nm-ip6-config.h b/libnm-glib/nm-ip6-config.h index a71d74b..b6198fa 100644 --- a/libnm-glib/nm-ip6-config.h +++ b/libnm-glib/nm-ip6-config.h @@ -18,7 +18,7 @@ * Boston, MA 02110-1301 USA. * * Copyright (C) 2007 - 2008 Novell, Inc. - * Copyright (C) 2008 Red Hat, Inc. + * Copyright (C) 2008 - 2014 Red Hat, Inc. */ #ifndef NM_IP6_CONFIG_H @@ -65,12 +65,14 @@ GType nm_ip6_config_get_type (void); GObject *nm_ip6_config_new (DBusGConnection *connection, const char *object_path); -const char * nm_ip6_config_get_gateway (NMIP6Config *config); -const GSList * nm_ip6_config_get_addresses (NMIP6Config *config); -const GSList * nm_ip6_config_get_routes (NMIP6Config *config); -const GSList * nm_ip6_config_get_nameservers (NMIP6Config *config); -const GPtrArray *nm_ip6_config_get_domains (NMIP6Config *config); -const GPtrArray *nm_ip6_config_get_searches (NMIP6Config *config); +const char * nm_ip6_config_get_gateway (NMIP6Config *config); +const GSList * nm_ip6_config_get_addresses (NMIP6Config *config); +const GSList * nm_ip6_config_get_routes (NMIP6Config *config); +guint32 nm_ip6_config_get_num_nameservers (NMIP6Config *config); +const struct in6_addr *nm_ip6_config_get_nameserver (NMIP6Config *config, guint32 idx); +const GSList * nm_ip6_config_get_nameservers (NMIP6Config *config); +const GPtrArray * nm_ip6_config_get_domains (NMIP6Config *config); +const GPtrArray * nm_ip6_config_get_searches (NMIP6Config *config); G_END_DECLS -- 1.7.11.7