libnm: drop NM_TYPE_STRING_ARRAY, use G_TYPE_STRV

Make NMIP4Config and NMIP6Config's array-of-string properties be
G_TYPE_STRV, and update the corresponding APIs accordingly.
This commit is contained in:
Dan Winship 2014-07-02 14:25:43 -04:00
parent f71218d70a
commit 4eb04dbcf8
10 changed files with 60 additions and 177 deletions

View file

@ -81,7 +81,6 @@ print_ip4_config (NMIP4Config *cfg4,
{
GSList *list, *iter;
const GArray *array;
const GPtrArray *ptr_array;
char **addr_arr = NULL;
char **route_arr = NULL;
char **dns_arr = NULL;
@ -150,14 +149,7 @@ print_ip4_config (NMIP4Config *cfg4,
}
/* domains */
ptr_array = nm_ip4_config_get_domains (cfg4);
if (ptr_array) {
domain_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++)
domain_arr[i] = g_strdup (g_ptr_array_index (ptr_array, i));
domain_arr[i] = NULL;
}
domain_arr = g_strdupv ((char **) nm_ip4_config_get_domains (cfg4));
/* WINS */
array = nm_ip4_config_get_wins_servers (cfg4);
@ -193,7 +185,6 @@ print_ip6_config (NMIP6Config *cfg6,
const char *one_field)
{
GSList *list, *iter;
const GPtrArray *ptr_array;
char **addr_arr = NULL;
char **route_arr = NULL;
char **dns_arr = NULL;
@ -260,14 +251,7 @@ print_ip6_config (NMIP6Config *cfg6,
dns_arr[i] = NULL;
/* domains */
ptr_array = nm_ip6_config_get_domains (cfg6);
if (ptr_array) {
domain_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++)
domain_arr[i] = g_strdup (g_ptr_array_index (ptr_array, i));
domain_arr[i] = NULL;
}
domain_arr = g_strdupv ((char **) nm_ip6_config_get_domains (cfg6));
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);

View file

@ -864,7 +864,6 @@ global:
nm_simple_connection_new_from_dbus;
nm_ssid_get_type;
nm_state_get_type;
nm_string_array_get_type;
nm_uint_array_get_type;
nm_utils_ap_mode_security_valid;
nm_utils_bin2hexstr;

View file

@ -39,8 +39,8 @@ typedef struct {
GSList *addresses;
GSList *routes;
GArray *nameservers;
GPtrArray *domains;
GPtrArray *searches;
char **domains;
char **searches;
GArray *wins;
} NMIP4ConfigPrivate;
@ -60,6 +60,10 @@ enum {
static void
nm_ip4_config_init (NMIP4Config *config)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1);
}
static gboolean
@ -90,16 +94,6 @@ demarshal_ip4_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointe
return TRUE;
}
static gboolean
demarshal_string_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
return FALSE;
_nm_object_queue_notify (object, pspec->name);
return TRUE;
}
static gboolean
demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
@ -123,8 +117,8 @@ init_dbus (NMObject *object)
{ NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_address_array },
{ NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes_array },
{ NM_IP4_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip4_array },
{ NM_IP4_CONFIG_DOMAINS, &priv->domains, demarshal_string_array },
{ NM_IP4_CONFIG_SEARCHES, &priv->searches, demarshal_string_array },
{ NM_IP4_CONFIG_DOMAINS, &priv->domains, },
{ NM_IP4_CONFIG_SEARCHES, &priv->searches, },
{ NM_IP4_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip4_array },
{ NULL },
};
@ -153,15 +147,8 @@ finalize (GObject *object)
if (priv->wins)
g_array_free (priv->wins, TRUE);
if (priv->domains) {
g_ptr_array_set_free_func (priv->domains, g_free);
g_ptr_array_free (priv->domains, TRUE);
}
if (priv->searches) {
g_ptr_array_set_free_func (priv->searches, g_free);
g_ptr_array_free (priv->searches, TRUE);
}
g_strfreev (priv->domains);
g_strfreev (priv->searches);
g_object_unref (priv->proxy);
@ -191,10 +178,10 @@ get_property (GObject *object,
g_value_set_boxed (value, nm_ip4_config_get_nameservers (self));
break;
case PROP_DOMAINS:
g_value_set_boxed (value, nm_ip4_config_get_domains (self));
g_value_set_boxed (value, (char **) nm_ip4_config_get_domains (self));
break;
case PROP_SEARCHES:
g_value_set_boxed (value, nm_ip4_config_get_searches (self));
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));
@ -270,24 +257,24 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
/**
* NMIP4Config:domains:
*
* The #GPtrArray containing domain strings of the configuration.
* The array containing domain strings of the configuration.
**/
g_object_class_install_property
(object_class, PROP_DOMAINS,
g_param_spec_boxed (NM_IP4_CONFIG_DOMAINS, "", "",
NM_TYPE_STRING_ARRAY,
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMIP4Config:searches:
*
* The #GPtrArray containing dns search strings of the configuration.
* The array containing DNS search strings of the configuration.
**/
g_object_class_install_property
(object_class, PROP_SEARCHES,
g_param_spec_boxed (NM_IP4_CONFIG_SEARCHES, "", "",
NM_TYPE_STRING_ARRAY,
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@ -361,32 +348,30 @@ nm_ip4_config_get_nameservers (NMIP4Config *config)
*
* Gets the domain names.
*
* Returns: (element-type utf8): the #GPtrArray containing domains as strings. This is the
* internal copy used by the configuration, and must not be modified.
* Returns: the array of domains. (This is never %NULL, though it may be 0-length).
**/
const GPtrArray *
const char * const *
nm_ip4_config_get_domains (NMIP4Config *config)
{
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->domains);
return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->domains;
}
/**
* nm_ip4_config_get_searches:
* @config: a #NMIP4Config
*
* Gets the dns searches.
* Gets the DNS searches.
*
* Returns: (element-type utf8): the #GPtrArray containing dns searches as strings. This is the
* internal copy used by the configuration, and must not be modified.
* Returns: the array of DNS search strings. (This is never %NULL, though it may be 0-length).
**/
const GPtrArray *
const char * const *
nm_ip4_config_get_searches (NMIP4Config *config)
{
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
return handle_ptr_array_return (NM_IP4_CONFIG_GET_PRIVATE (config)->searches);
return (const char * const *) NM_IP4_CONFIG_GET_PRIVATE (config)->searches;
}
/**

View file

@ -60,13 +60,13 @@ typedef struct {
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 GPtrArray *nm_ip4_config_get_domains (NMIP4Config *config);
const GPtrArray *nm_ip4_config_get_searches (NMIP4Config *config);
const GArray * nm_ip4_config_get_wins_servers (NMIP4Config *config);
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_domains (NMIP4Config *config);
const char * const *nm_ip4_config_get_searches (NMIP4Config *config);
const GArray * nm_ip4_config_get_wins_servers (NMIP4Config *config);
G_END_DECLS

View file

@ -39,8 +39,8 @@ typedef struct {
GSList *addresses;
GSList *routes;
GSList *nameservers;
GPtrArray *domains;
GPtrArray *searches;
char **domains;
char **searches;
} NMIP6ConfigPrivate;
enum {
@ -81,26 +81,6 @@ demarshal_ip6_nameserver_array (NMObject *object, GParamSpec *pspec, GValue *val
return TRUE;
}
static gboolean
demarshal_domains (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
return FALSE;
_nm_object_queue_notify (object, NM_IP6_CONFIG_DOMAINS);
return TRUE;
}
static gboolean
demarshal_searches (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
if (!_nm_string_array_demarshal (value, (GPtrArray **) field))
return FALSE;
_nm_object_queue_notify (object, NM_IP6_CONFIG_SEARCHES);
return TRUE;
}
static gboolean
demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
@ -124,8 +104,8 @@ init_dbus (NMObject *object)
{ NM_IP6_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip6_address_array },
{ NM_IP6_CONFIG_ROUTES, &priv->routes, demarshal_ip6_routes_array },
{ NM_IP6_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip6_nameserver_array },
{ NM_IP6_CONFIG_DOMAINS, &priv->domains, demarshal_domains },
{ NM_IP6_CONFIG_SEARCHES, &priv->searches, demarshal_searches },
{ NM_IP6_CONFIG_DOMAINS, &priv->domains, },
{ NM_IP6_CONFIG_SEARCHES, &priv->searches, },
{ NULL },
};
@ -240,32 +220,30 @@ nm_ip6_config_get_nameservers (NMIP6Config *config)
*
* Gets the domain names.
*
* Returns: (element-type utf8): the #GPtrArray containing domains as strings.
* This is the internal copy used by the configuration, and must not be modified.
* Returns: the array of domains. (This is never %NULL, though it may be 0-length).
**/
const GPtrArray *
const char * const *
nm_ip6_config_get_domains (NMIP6Config *config)
{
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->domains);
return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->domains;
}
/**
* nm_ip6_config_get_searches:
* @config: a #NMIP6Config
*
* Gets the dns searches.
* Gets the DNS search strings.
*
* Returns: (element-type utf8): the #GPtrArray containing dns searches as strings.
* This is the internal copy used by the configuration, and must not be modified.
* Returns: the array of DNS search strings. (This is never %NULL, though it may be 0-length).
**/
const GPtrArray *
const char * const *
nm_ip6_config_get_searches (NMIP6Config *config)
{
g_return_val_if_fail (NM_IS_IP6_CONFIG (config), NULL);
return handle_ptr_array_return (NM_IP6_CONFIG_GET_PRIVATE (config)->searches);
return (const char * const *) NM_IP6_CONFIG_GET_PRIVATE (config)->searches;
}
/**
@ -297,15 +275,8 @@ finalize (GObject *object)
g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
g_slist_free_full (priv->nameservers, g_free);
if (priv->domains) {
g_ptr_array_set_free_func (priv->domains, g_free);
g_ptr_array_free (priv->domains, TRUE);
}
if (priv->searches) {
g_ptr_array_set_free_func (priv->searches, g_free);
g_ptr_array_free (priv->searches, TRUE);
}
g_strfreev (priv->domains);
g_strfreev (priv->searches);
g_object_unref (priv->proxy);
@ -335,10 +306,10 @@ get_property (GObject *object,
g_value_set_boxed (value, nm_ip6_config_get_nameservers (self));
break;
case PROP_DOMAINS:
g_value_set_boxed (value, nm_ip6_config_get_domains (self));
g_value_set_boxed (value, (char **) nm_ip6_config_get_domains (self));
break;
case PROP_SEARCHES:
g_value_set_boxed (value, nm_ip6_config_get_searches (self));
g_value_set_boxed (value, (char **) nm_ip6_config_get_searches (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -349,6 +320,10 @@ get_property (GObject *object,
static void
nm_ip6_config_init (NMIP6Config *config)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1);
}
static void
@ -428,7 +403,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
g_object_class_install_property
(object_class, PROP_DOMAINS,
g_param_spec_boxed (NM_IP6_CONFIG_DOMAINS, "", "",
NM_TYPE_STRING_ARRAY,
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@ -440,7 +415,7 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
g_object_class_install_property
(object_class, PROP_SEARCHES,
g_param_spec_boxed (NM_IP6_CONFIG_SEARCHES, "", "",
NM_TYPE_STRING_ARRAY,
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View file

@ -65,8 +65,8 @@ 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);
const char * const * nm_ip6_config_get_domains (NMIP6Config *config);
const char * const * nm_ip6_config_get_searches (NMIP6Config *config);
G_END_DECLS

View file

@ -1142,6 +1142,11 @@ demarshal_generic (NMObject *object,
success = FALSE;
goto done;
}
} else if (pspec->value_type == G_TYPE_STRV) {
char ***param = (char ***)field;
if (*param)
g_strfreev (*param);
*param = g_value_dup_boxed (value);
HANDLE_TYPE(BOOLEAN, boolean, boolean)
HANDLE_TYPE(CHAR, char, schar)
HANDLE_TYPE(UCHAR, uchar, uchar)

View file

@ -27,7 +27,6 @@
gboolean _nm_ssid_demarshal (GValue *value, GByteArray **dest);
gboolean _nm_uint_array_demarshal (GValue *value, GArray **dest);
gboolean _nm_string_array_demarshal (GValue *value, GPtrArray **dest);
gboolean _nm_object_array_demarshal (GValue *value,
GPtrArray **dest,
DBusGConnection *connection,

View file

@ -133,67 +133,6 @@ _nm_uint_array_demarshal (GValue *value, GArray **dest)
/*****************************/
static gpointer
_nm_string_array_copy (GPtrArray *src)
{
GPtrArray *dest;
int i;
dest = g_ptr_array_sized_new (src->len);
for (i = 0; i < src->len; i++)
g_ptr_array_add (dest, g_strdup (g_ptr_array_index (src, i)));
return dest;
}
static void
_nm_string_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_string_array_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("NMStringArray"),
(GBoxedCopyFunc) _nm_string_array_copy,
(GBoxedFreeFunc) _nm_string_array_free);
return our_type;
}
gboolean
_nm_string_array_demarshal (GValue *value, GPtrArray **dest)
{
char **array;
if (!G_VALUE_HOLDS (value, G_TYPE_STRV))
return FALSE;
if (*dest) {
g_boxed_free (NM_TYPE_STRING_ARRAY, *dest);
*dest = NULL;
}
array = (char **) g_value_get_boxed (value);
if (array && array[0]) {
int i;
*dest = g_ptr_array_new ();
for (i = 0; array[i]; i++)
g_ptr_array_add (*dest, g_strdup (array[i]));
}
return TRUE;
}
/*****************************/
static gpointer
_nm_object_array_copy (GPtrArray *src)
{

View file

@ -38,9 +38,6 @@ GType nm_ssid_get_type (void) G_GNUC_CONST;
#define NM_TYPE_UINT_ARRAY (nm_uint_array_get_type ())
GType nm_uint_array_get_type (void) G_GNUC_CONST;
#define NM_TYPE_STRING_ARRAY (nm_string_array_get_type ())
GType nm_string_array_get_type (void) G_GNUC_CONST;
#define NM_TYPE_OBJECT_ARRAY (nm_object_array_get_type ())
GType nm_object_array_get_type (void) G_GNUC_CONST;