diff --git a/clients/cli/common.c b/clients/cli/common.c index d860d6386d..76867047aa 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -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); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 326a6f15ad..7645af98dc 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -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; diff --git a/libnm/nm-ip4-config.c b/libnm/nm-ip4-config.c index 298a2198a2..8a545141dc 100644 --- a/libnm/nm-ip4-config.c +++ b/libnm/nm-ip4-config.c @@ -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; } /** diff --git a/libnm/nm-ip4-config.h b/libnm/nm-ip4-config.h index 7c1f039345..1a04e912cc 100644 --- a/libnm/nm-ip4-config.h +++ b/libnm/nm-ip4-config.h @@ -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 diff --git a/libnm/nm-ip6-config.c b/libnm/nm-ip6-config.c index 7d34171601..74dc2b909e 100644 --- a/libnm/nm-ip6-config.c +++ b/libnm/nm-ip6-config.c @@ -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)); diff --git a/libnm/nm-ip6-config.h b/libnm/nm-ip6-config.h index ed664b1010..467568cf6a 100644 --- a/libnm/nm-ip6-config.h +++ b/libnm/nm-ip6-config.h @@ -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 diff --git a/libnm/nm-object.c b/libnm/nm-object.c index a8544a1100..c48ce1d4ba 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -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) diff --git a/libnm/nm-types-private.h b/libnm/nm-types-private.h index 9979f6c9fd..8626e0d1f6 100644 --- a/libnm/nm-types-private.h +++ b/libnm/nm-types-private.h @@ -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, diff --git a/libnm/nm-types.c b/libnm/nm-types.c index cb0ff8ba6c..5e482accc5 100644 --- a/libnm/nm-types.c +++ b/libnm/nm-types.c @@ -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) { diff --git a/libnm/nm-types.h b/libnm/nm-types.h index a50f83c7c7..3a71f879d4 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -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;