diff options
author | Dan Winship <danw@gnome.org> | 2014-07-02 14:25:43 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-09-03 16:46:25 -0400 |
commit | bb6a2e6e645c964bce76bad9b8a1bd991a9eb1f7 (patch) | |
tree | 95a27d6b9b0f003dce4047cd57ad087f5f301f18 | |
parent | 64f95386eaffbb07692de7cd131638acb91fe10b (diff) | |
download | NetworkManager-bb6a2e6e645c964bce76bad9b8a1bd991a9eb1f7.tar.gz |
libnm: drop libnm IP-address-array types, use G_TYPE_STRV
Make NMIP4Config:nameservers, NMIP4Config:wins-servers, and
NMIP6Config:nameservers be G_TYPE_STRV, with stringified IP addresses,
and update the APIs accordingly.
-rw-r--r-- | clients/cli/common.c | 27 | ||||
-rw-r--r-- | libnm/libnm.ver | 4 | ||||
-rw-r--r-- | libnm/nm-ip4-config.c | 64 | ||||
-rw-r--r-- | libnm/nm-ip4-config.h | 4 | ||||
-rw-r--r-- | libnm/nm-ip6-config.c | 89 | ||||
-rw-r--r-- | libnm/nm-ip6-config.h | 4 | ||||
-rw-r--r-- | libnm/nm-types-private.h | 1 | ||||
-rw-r--r-- | libnm/nm-types.c | 124 | ||||
-rw-r--r-- | libnm/nm-types.h | 6 |
9 files changed, 75 insertions, 248 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index 76867047aa..4472d4ac25 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -80,7 +80,6 @@ print_ip4_config (NMIP4Config *cfg4, const char *one_field) { GSList *list, *iter; - const GArray *array; char **addr_arr = NULL; char **route_arr = NULL; char **dns_arr = NULL; @@ -139,27 +138,13 @@ print_ip4_config (NMIP4Config *cfg4, route_arr[i] = NULL; /* DNS */ - array = nm_ip4_config_get_nameservers (cfg4); - if (array) { - dns_arr = g_new (char *, array->len + 1); - for (i = 0; i < array->len; i++) - dns_arr[i] = nmc_ip4_address_as_string (g_array_index (array, guint32, i), NULL); - - dns_arr[i] = NULL; - } + dns_arr = g_strdupv ((char **) nm_ip4_config_get_nameservers (cfg4)); /* domains */ domain_arr = g_strdupv ((char **) nm_ip4_config_get_domains (cfg4)); /* WINS */ - array = nm_ip4_config_get_wins_servers (cfg4); - if (array) { - wins_arr = g_new (char *, array->len + 1); - for (i = 0; i < array->len; i++) - wins_arr[i] = nmc_ip4_address_as_string (g_array_index (array, guint32, i), NULL); - - wins_arr[i] = NULL; - } + wins_arr = g_strdupv ((char **) nm_ip4_config_get_wins_servers (cfg4)); arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX); set_val_strc (arr, 0, group_prefix); @@ -242,13 +227,7 @@ print_ip6_config (NMIP6Config *cfg6, route_arr[i] = NULL; /* DNS */ - list = (GSList *) nm_ip6_config_get_nameservers (cfg6); - dns_arr = g_new (char *, g_slist_length (list) + 1); - i = 0; - for (iter = list; iter; iter = g_slist_next (iter)) - dns_arr[i++] = nmc_ip6_address_as_string (iter->data, NULL); - - dns_arr[i] = NULL; + dns_arr = g_strdupv ((char **) nm_ip6_config_get_nameservers (cfg6)); /* domains */ domain_arr = g_strdupv ((char **) nm_ip6_config_get_domains (cfg6)); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index d2dd6b8e4a..8d2b7101b1 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -299,7 +299,6 @@ global: nm_ip4_route_set_next_hop; nm_ip4_route_set_prefix; nm_ip4_route_unref; - nm_ip6_address_array_get_type; nm_ip6_address_compare; nm_ip6_address_dup; nm_ip6_address_get_address; @@ -316,9 +315,7 @@ 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; @@ -862,7 +859,6 @@ global: nm_simple_connection_new_clone; nm_simple_connection_new_from_dbus; nm_state_get_type; - nm_uint_array_get_type; nm_utils_ap_mode_security_valid; nm_utils_bin2hexstr; nm_utils_check_virtual_device_compatibility; diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index 8a545141dc..39a9b6b4dc 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -38,10 +38,10 @@ typedef struct { char *gateway; GSList *addresses; GSList *routes; - GArray *nameservers; + char **nameservers; char **domains; char **searches; - GArray *wins; + char **wins; } NMIP4ConfigPrivate; enum { @@ -62,8 +62,10 @@ nm_ip4_config_init (NMIP4Config *config) { NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config); + priv->nameservers = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1); + priv->wins = g_new0 (char *, 1); } static gboolean @@ -83,14 +85,30 @@ demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value, static gboolean demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) { - if (!_nm_uint_array_demarshal (value, (GArray **) field)) + GArray *ip_array; + char ***obj_field; + int i; + + if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)) return FALSE; - if (!strcmp (pspec->name, NM_IP4_CONFIG_NAMESERVERS)) - _nm_object_queue_notify (object, NM_IP4_CONFIG_NAMESERVERS); - else if (!strcmp (pspec->name, NM_IP4_CONFIG_WINS_SERVERS)) - _nm_object_queue_notify (object, NM_IP4_CONFIG_WINS_SERVERS); + 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; + + _nm_object_queue_notify (object, pspec->name); return TRUE; } @@ -141,14 +159,10 @@ finalize (GObject *object) g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref); g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref); - if (priv->nameservers) - g_array_free (priv->nameservers, TRUE); - - if (priv->wins) - g_array_free (priv->wins, TRUE); - + g_strfreev (priv->nameservers); g_strfreev (priv->domains); g_strfreev (priv->searches); + g_strfreev (priv->wins); g_object_unref (priv->proxy); @@ -175,7 +189,7 @@ get_property (GObject *object, nm_utils_ip4_routes_to_gvalue (priv->routes, value); break; case PROP_NAMESERVERS: - g_value_set_boxed (value, nm_ip4_config_get_nameservers (self)); + g_value_set_boxed (value, (char **) nm_ip4_config_get_nameservers (self)); break; case PROP_DOMAINS: g_value_set_boxed (value, (char **) nm_ip4_config_get_domains (self)); @@ -184,7 +198,7 @@ get_property (GObject *object, g_value_set_boxed (value, (char **) nm_ip4_config_get_searches (self)); break; case PROP_WINS_SERVERS: - g_value_set_boxed (value, nm_ip4_config_get_wins_servers (self)); + g_value_set_boxed (value, (char **) nm_ip4_config_get_wins_servers (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -245,12 +259,12 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) /** * NMIP4Config:nameservers: * - * The #GArray containing name servers (#guint32s) of the configuration. + * The array containing name server IP addresses of the configuration. **/ g_object_class_install_property (object_class, PROP_NAMESERVERS, g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS, "", "", - NM_TYPE_UINT_ARRAY, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); @@ -281,12 +295,12 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class) /** * NMIP4Config:wins-servers: * - * The #GArray containing WINS servers (#guint32s) of the configuration. + * The array containing WINS server IP addresses of the configuration. **/ g_object_class_install_property (object_class, PROP_WINS_SERVERS, g_param_spec_boxed (NM_IP4_CONFIG_WINS_SERVERS, "", "", - NM_TYPE_UINT_ARRAY, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); } @@ -330,16 +344,14 @@ nm_ip4_config_get_addresses (NMIP4Config *config) * * Gets the domain name servers (DNS). * - * Returns: (element-type guint32): the #GArray containing #guint32s. - * This is the internal copy used by the configuration and must not be - * modified. + * Returns: the array of nameserver IP addresses **/ -const GArray * +const char * const * nm_ip4_config_get_nameservers (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - return NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers; + return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->nameservers; } /** @@ -384,12 +396,12 @@ nm_ip4_config_get_searches (NMIP4Config *config) * This is the internal copy used by the configuration and must not be * modified. **/ -const GArray * +const char * const * nm_ip4_config_get_wins_servers (NMIP4Config *config) { g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL); - return NM_IP4_CONFIG_GET_PRIVATE (config)->wins; + return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->wins; } /** diff --git a/libnm/nm-ip4-config.h b/libnm/nm-ip4-config.h index 1a04e912cc..c07ea7cc06 100644 --- a/libnm/nm-ip4-config.h +++ b/libnm/nm-ip4-config.h @@ -63,10 +63,10 @@ GType nm_ip4_config_get_type (void); const char * nm_ip4_config_get_gateway (NMIP4Config *config); const GSList * nm_ip4_config_get_addresses (NMIP4Config *config); const GSList * nm_ip4_config_get_routes (NMIP4Config *config); -const GArray * nm_ip4_config_get_nameservers (NMIP4Config *config); +const char * const *nm_ip4_config_get_nameservers (NMIP4Config *config); const char * const *nm_ip4_config_get_domains (NMIP4Config *config); const char * const *nm_ip4_config_get_searches (NMIP4Config *config); -const GArray * nm_ip4_config_get_wins_servers (NMIP4Config *config); +const char * const *nm_ip4_config_get_wins_servers (NMIP4Config *config); G_END_DECLS diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index 74dc2b909e..202c7fb349 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -27,6 +27,7 @@ #include "nm-types-private.h" #include "nm-object-private.h" #include "nm-utils.h" +#include "nm-dbus-glib-types.h" G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_OBJECT) @@ -38,7 +39,7 @@ typedef struct { char *gateway; GSList *addresses; GSList *routes; - GSList *nameservers; + char **nameservers; char **domains; char **searches; } NMIP6ConfigPrivate; @@ -72,12 +73,30 @@ demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value, static gboolean demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field) { - if (!_nm_ip6_address_array_demarshal (value, (GSList **) field)) + GPtrArray *ip_array; + char ***obj_field; + int i; + + if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)) return FALSE; - if (pspec && !strcmp (pspec->name, NM_IP6_CONFIG_NAMESERVERS)) - _nm_object_queue_notify (object, NM_IP6_CONFIG_NAMESERVERS); + ip_array = g_value_get_boxed (value); + + obj_field = field; + if (*obj_field) + g_strfreev (*obj_field); + + *obj_field = g_new (char *, ip_array ? ip_array->len + 1 : 1); + for (i = 0; ip_array && i < ip_array->len; i++) { + GByteArray *ip = g_ptr_array_index (ip_array, i); + const char *str; + + str = nm_utils_inet6_ntop ((struct in6_addr *) ip->data, NULL); + (*obj_field)[i] = g_strdup (str); + } + (*obj_field)[i] = NULL; + _nm_object_queue_notify (object, pspec->name); return TRUE; } @@ -152,66 +171,19 @@ nm_ip6_config_get_addresses (NMIP6Config *config) } /** - * 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 - **/ -guint32 -nm_ip6_config_get_num_nameservers (NMIP6Config *config) -{ - g_return_val_if_fail (NM_IS_IP6_CONFIG (config), 0); - - 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 - **/ -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); - - 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) + * nm_ip6_config_get_nameservers: * @config: a #NMIP6Config * * Gets the domain name servers (DNS). * - * Returns: a #GSList containing elements of type 'struct in6_addr' which - * contain the addresses of nameservers of the configuration. This is the - * internal copy used by the configuration and must not be modified. + * Returns: the array of nameserver IP addresses **/ -const GSList * +const char * const * nm_ip6_config_get_nameservers (NMIP6Config *config) { g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL); - return NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers; + return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->nameservers; } /** @@ -273,8 +245,8 @@ finalize (GObject *object) 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); + g_strfreev (priv->nameservers); g_strfreev (priv->domains); g_strfreev (priv->searches); @@ -303,7 +275,7 @@ get_property (GObject *object, nm_utils_ip6_routes_to_gvalue (priv->routes, value); break; case PROP_NAMESERVERS: - g_value_set_boxed (value, nm_ip6_config_get_nameservers (self)); + g_value_set_boxed (value, (char **) nm_ip6_config_get_nameservers (self)); break; case PROP_DOMAINS: g_value_set_boxed (value, (char **) nm_ip6_config_get_domains (self)); @@ -322,6 +294,7 @@ nm_ip6_config_init (NMIP6Config *config) { NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config); + priv->nameservers = g_new0 (char *, 1); priv->domains = g_new0 (char *, 1); priv->searches = g_new0 (char *, 1); } @@ -391,7 +364,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class) g_object_class_install_property (object_class, PROP_NAMESERVERS, g_param_spec_boxed (NM_IP6_CONFIG_NAMESERVERS, "", "", - NM_TYPE_IP6_ADDRESS_ARRAY, + G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); diff --git a/libnm/nm-ip6-config.h b/libnm/nm-ip6-config.h index 467568cf6a..52320005fd 100644 --- a/libnm/nm-ip6-config.h +++ b/libnm/nm-ip6-config.h @@ -62,9 +62,7 @@ GType nm_ip6_config_get_type (void); 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 char * const * nm_ip6_config_get_nameservers (NMIP6Config *config); const char * const * nm_ip6_config_get_domains (NMIP6Config *config); const char * const * nm_ip6_config_get_searches (NMIP6Config *config); diff --git a/libnm/nm-types-private.h b/libnm/nm-types-private.h index 72c41b6920..50245d0a9d 100644 --- a/libnm/nm-types-private.h +++ b/libnm/nm-types-private.h @@ -25,7 +25,6 @@ #include "nm-types.h" #include "nm-object-private.h" -gboolean _nm_uint_array_demarshal (GValue *value, GArray **dest); gboolean _nm_ip6_address_array_demarshal (GValue *value, GSList **dest); #endif /* __NM_TYPES_PRIVATE_H__ */ diff --git a/libnm/nm-types.c b/libnm/nm-types.c index 6ca32b3b24..bd09a12e72 100644 --- a/libnm/nm-types.c +++ b/libnm/nm-types.c @@ -29,58 +29,6 @@ #include "nm-setting-ip6-config.h" static gpointer -_nm_uint_array_copy (GArray *src) -{ - GArray *dest; - - dest = g_array_sized_new (FALSE, TRUE, sizeof (guint32), src->len); - g_array_append_vals (dest, src->data, src->len); - return dest; -} - -static void -_nm_uint_array_free (GArray *array) -{ - g_array_free (array, TRUE); -} - -GType -nm_uint_array_get_type (void) -{ - static GType our_type = 0; - - if (our_type == 0) - our_type = g_boxed_type_register_static (g_intern_static_string ("NMUintArray"), - (GBoxedCopyFunc) _nm_uint_array_copy, - (GBoxedFreeFunc) _nm_uint_array_free); - return our_type; -} - -gboolean -_nm_uint_array_demarshal (GValue *value, GArray **dest) -{ - GArray *array; - - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)) - return FALSE; - - if (*dest) { - g_boxed_free (NM_TYPE_UINT_ARRAY, *dest); - *dest = NULL; - } - - array = (GArray *) g_value_get_boxed (value); - if (array && (array->len > 0)) { - *dest = g_array_sized_new (FALSE, TRUE, sizeof (guint32), array->len); - g_array_append_vals (*dest, array->data, array->len); - } - - return TRUE; -} - -/*****************************/ - -static gpointer _nm_ip6_address_object_array_copy (GPtrArray *src) { GPtrArray *dest; @@ -117,78 +65,6 @@ nm_ip6_address_object_array_get_type (void) /*****************************/ static gpointer -_nm_ip6_address_array_copy (GPtrArray *src) -{ - GPtrArray *dest; - int i; - - dest = g_ptr_array_sized_new (src->len); - for (i = 0; i < src->len; i++) { - struct in6_addr *addr = g_ptr_array_index (src, i); - struct in6_addr *copy; - - copy = g_malloc0 (sizeof (struct in6_addr)); - memcpy (copy, addr, sizeof (struct in6_addr)); - g_ptr_array_add (dest, copy); - } - return dest; -} - -static void -_nm_ip6_address_array_free (GPtrArray *array) -{ - int i; - - for (i = 0; i < array->len; i++) - g_free (g_ptr_array_index (array, i)); - g_ptr_array_free (array, TRUE); -} - -GType -nm_ip6_address_array_get_type (void) -{ - static GType our_type = 0; - - if (our_type == 0) - our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressArray"), - (GBoxedCopyFunc) _nm_ip6_address_array_copy, - (GBoxedFreeFunc) _nm_ip6_address_array_free); - return our_type; -} - -gboolean -_nm_ip6_address_array_demarshal (GValue *value, GSList **dest) -{ - GPtrArray *array; - - if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)) - return FALSE; - - if (*dest) { - g_slist_free_full (*dest, g_free); - *dest = NULL; - } - - array = (GPtrArray *) g_value_get_boxed (value); - if (array && array->len) { - int i; - - for (i = 0; i < array->len; i++) { - GByteArray *bytearray = (GByteArray *) g_ptr_array_index (array, i); - struct in6_addr *addr; - - addr = g_malloc0 (sizeof (struct in6_addr)); - memcpy (addr->s6_addr, bytearray->data, bytearray->len); - *dest = g_slist_append (*dest, addr); - } - } - - return TRUE; -} - -/*****************************/ - -static gpointer _nm_ip6_route_object_array_copy (GPtrArray *src) { GPtrArray *dest; diff --git a/libnm/nm-types.h b/libnm/nm-types.h index c55edf82be..3e22983248 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -32,15 +32,9 @@ G_BEGIN_DECLS -#define NM_TYPE_UINT_ARRAY (nm_uint_array_get_type ()) -GType nm_uint_array_get_type (void) G_GNUC_CONST; - #define NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY (nm_ip6_address_object_array_get_type ()) GType nm_ip6_address_object_array_get_type (void) G_GNUC_CONST; -#define NM_TYPE_IP6_ADDRESS_ARRAY (nm_ip6_address_array_get_type ()) -GType nm_ip6_address_array_get_type (void) G_GNUC_CONST; - #define NM_TYPE_IP6_ROUTE_OBJECT_ARRAY (nm_ip6_route_object_array_get_type ()) GType nm_ip6_route_object_array_get_type (void) G_GNUC_CONST; |