summaryrefslogtreecommitdiff
path: root/libnm-core/nm-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-core/nm-utils.c')
-rw-r--r--libnm-core/nm-utils.c613
1 files changed, 0 insertions, 613 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index 3054b3722f..617b0b4df8 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -30,7 +30,6 @@
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-glib-compat.h"
-#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
#include "crypto.h"
@@ -439,54 +438,6 @@ nm_utils_same_ssid (const guint8 *ssid1, gsize len1,
return memcmp (ssid1, ssid2, len1) == 0 ? TRUE : FALSE;
}
-static void
-value_destroy (gpointer data)
-{
- GValue *value = (GValue *) data;
-
- g_value_unset (value);
- g_slice_free (GValue, value);
-}
-
-static void
-value_dup (gpointer key, gpointer val, gpointer user_data)
-{
- GHashTable *table = (GHashTable *) user_data;
- GValue *value = (GValue *) val;
- GValue *dup_value;
-
- dup_value = g_slice_new0 (GValue);
- g_value_init (dup_value, G_VALUE_TYPE (val));
- g_value_copy (value, dup_value);
-
- g_hash_table_insert (table, g_strdup ((char *) key), dup_value);
-}
-
-/**
- * nm_utils_gvalue_hash_dup:
- * @hash: a #GHashTable mapping string:GValue
- *
- * Utility function to duplicate a hash table of #GValues.
- *
- * Returns: (transfer container) (element-type utf8 GObject.Value): a newly allocated duplicated #GHashTable, caller must free the
- * returned hash with g_hash_table_unref() or g_hash_table_destroy()
- **/
-GHashTable *
-nm_utils_gvalue_hash_dup (GHashTable *hash)
-{
- GHashTable *table;
-
- g_return_val_if_fail (hash != NULL, NULL);
-
- table = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- value_destroy);
-
- g_hash_table_foreach (hash, value_dup, table);
-
- return table;
-}
-
gboolean
_nm_utils_string_in_list (const char *str, const char **valid_strings)
{
@@ -512,30 +463,6 @@ _nm_utils_string_slist_validate (GSList *list, const char **valid_values)
return TRUE;
}
-gboolean
-_nm_utils_gvalue_array_validate (GValueArray *elements, guint n_expected, ...)
-{
- va_list args;
- GValue *tmp;
- int i;
- gboolean valid = FALSE;
-
- if (n_expected != elements->n_values)
- return FALSE;
-
- va_start (args, n_expected);
- for (i = 0; i < n_expected; i++) {
- tmp = g_value_array_get_nth (elements, i);
- if (G_VALUE_TYPE (tmp) != va_arg (args, GType))
- goto done;
- }
- valid = TRUE;
-
-done:
- va_end (args);
- return valid;
-}
-
/**
* _nm_utils_hash_values_to_slist:
* @hash: a #GHashTable
@@ -564,47 +491,6 @@ _nm_utils_hash_values_to_slist (GHashTable *hash)
return list;
}
-/**
- * _nm_utils_connection_hash_to_dict:
- * @hash: a hashed #NMConnection
- *
- * Returns: a (floating) #GVariant equivalent to @hash.
- */
-GVariant *
-_nm_utils_connection_hash_to_dict (GHashTable *hash)
-{
- GValue val = { 0, };
- GVariant *variant;
-
- if (!hash)
- return NULL;
-
- g_value_init (&val, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT);
- g_value_set_boxed (&val, hash);
- variant = dbus_g_value_build_g_variant (&val);
- g_value_unset (&val);
-
- return variant;
-}
-
-/**
- * _nm_utils_connection_dict_to_hash:
- * @dict: a #GVariant-serialized #NMConnection
- *
- * Returns: a #GHashTable equivalent to @dict.
- */
-GHashTable *
-_nm_utils_connection_dict_to_hash (GVariant *dict)
-{
- GValue val = { 0, };
-
- if (!dict)
- return NULL;
-
- dbus_g_value_parse_g_variant (dict, &val);
- return g_value_get_boxed (&val);
-}
-
GVariant *
_nm_utils_strdict_to_dbus (const GValue *prop_value)
{
@@ -1144,174 +1030,6 @@ nm_utils_wpa_psk_valid (const char *psk)
}
/**
- * nm_utils_ip4_addresses_from_gvalue:
- * @value: #GValue containing a #GPtrArray of #GArrays of #guint32s
- *
- * Utility function to convert a #GPtrArray of #GArrays of #guint32s representing
- * a list of NetworkManager IPv4 addresses (which is a tuple of address, gateway,
- * and prefix) into a #GSList of #NMIP4Address objects. The specific format of
- * this serialization is not guaranteed to be stable and the #GArray may be
- * extended in the future.
- *
- * Returns: (transfer full) (element-type NMIP4Address): a newly allocated #GSList of #NMIP4Address objects
- **/
-GSList *
-nm_utils_ip4_addresses_from_gvalue (const GValue *value)
-{
- GPtrArray *addresses;
- int i;
- GSList *list = NULL;
-
- addresses = (GPtrArray *) g_value_get_boxed (value);
- for (i = 0; addresses && (i < addresses->len); i++) {
- GArray *array = (GArray *) g_ptr_array_index (addresses, i);
- NMIP4Address *addr;
-
- if (array->len < 3) {
- g_warning ("Ignoring invalid IP4 address");
- continue;
- }
-
- addr = nm_ip4_address_new ();
- nm_ip4_address_set_address (addr, g_array_index (array, guint32, 0));
- nm_ip4_address_set_prefix (addr, g_array_index (array, guint32, 1));
- nm_ip4_address_set_gateway (addr, g_array_index (array, guint32, 2));
- list = g_slist_prepend (list, addr);
- }
-
- return g_slist_reverse (list);
-}
-
-/**
- * nm_utils_ip4_addresses_to_gvalue:
- * @list: (element-type NMIP4Address): a list of #NMIP4Address objects
- * @value: a pointer to a #GValue into which to place the converted addresses,
- * which should be unset by the caller (when no longer needed) with
- * g_value_unset().
- *
- * Utility function to convert a #GSList of #NMIP4Address objects into a
- * #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4
- * addresses (which is a tuple of address, gateway, and prefix). The specific
- * format of this serialization is not guaranteed to be stable and may be
- * extended in the future.
- **/
-void
-nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *addresses;
- GSList *iter;
-
- addresses = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- NMIP4Address *addr = (NMIP4Address *) iter->data;
- GArray *array;
- guint32 tmp;
-
- array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
-
- tmp = nm_ip4_address_get_address (addr);
- g_array_append_val (array, tmp);
-
- tmp = nm_ip4_address_get_prefix (addr);
- g_array_append_val (array, tmp);
-
- tmp = nm_ip4_address_get_gateway (addr);
- g_array_append_val (array, tmp);
-
- g_ptr_array_add (addresses, array);
- }
-
- g_value_take_boxed (value, addresses);
-}
-
-/**
- * nm_utils_ip4_routes_from_gvalue:
- * @value: #GValue containing a #GPtrArray of #GArrays of #guint32s
- *
- * Utility function to convert a #GPtrArray of #GArrays of #guint32s representing
- * a list of NetworkManager IPv4 routes (which is a tuple of route, next hop,
- * prefix, and metric) into a #GSList of #NMIP4Route objects. The specific
- * format of this serialization is not guaranteed to be stable and may be
- * extended in the future.
- *
- * Returns: (transfer full) (element-type NMIP4Route): a newly allocated #GSList of #NMIP4Route objects
- **/
-GSList *
-nm_utils_ip4_routes_from_gvalue (const GValue *value)
-{
- GPtrArray *routes;
- int i;
- GSList *list = NULL;
-
- routes = (GPtrArray *) g_value_get_boxed (value);
- for (i = 0; routes && (i < routes->len); i++) {
- GArray *array = (GArray *) g_ptr_array_index (routes, i);
- NMIP4Route *route;
-
- if (array->len < 4) {
- g_warning ("Ignoring invalid IP4 route");
- continue;
- }
-
- route = nm_ip4_route_new ();
- nm_ip4_route_set_dest (route, g_array_index (array, guint32, 0));
- nm_ip4_route_set_prefix (route, g_array_index (array, guint32, 1));
- nm_ip4_route_set_next_hop (route, g_array_index (array, guint32, 2));
- nm_ip4_route_set_metric (route, g_array_index (array, guint32, 3));
- list = g_slist_prepend (list, route);
- }
-
- return g_slist_reverse (list);
-}
-
-/**
- * nm_utils_ip4_routes_to_gvalue:
- * @list: (element-type NMIP4Route): a list of #NMIP4Route objects
- * @value: a pointer to a #GValue into which to place the converted routes,
- * which should be unset by the caller (when no longer needed) with
- * g_value_unset().
- *
- * Utility function to convert a #GSList of #NMIP4Route objects into a
- * #GPtrArray of #GArrays of #guint32s representing a list of NetworkManager IPv4
- * routes (which is a tuple of route, next hop, prefix, and metric). The
- * specific format of this serialization is not guaranteed to be stable and may
- * be extended in the future.
- **/
-void
-nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *routes;
- GSList *iter;
-
- routes = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- NMIP4Route *route = (NMIP4Route *) iter->data;
- GArray *array;
- guint32 tmp;
-
- array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 3);
-
- tmp = nm_ip4_route_get_dest (route);
- g_array_append_val (array, tmp);
-
- tmp = nm_ip4_route_get_prefix (route);
- g_array_append_val (array, tmp);
-
- tmp = nm_ip4_route_get_next_hop (route);
- g_array_append_val (array, tmp);
-
- tmp = nm_ip4_route_get_metric (route);
- g_array_append_val (array, tmp);
-
- g_ptr_array_add (routes, array);
- }
-
- g_value_take_boxed (value, routes);
-}
-
-/**
* nm_utils_ip4_dns_to_variant:
* @dns: (type utf8): an array of IP address strings
*
@@ -1609,337 +1327,6 @@ nm_utils_ip4_get_default_prefix (guint32 ip)
}
/**
- * nm_utils_ip6_addresses_from_gvalue:
- * @value: gvalue containing a GPtrArray of GValueArrays of (GArray of guchars) and #guint32
- *
- * Utility function to convert a #GPtrArray of #GValueArrays of (#GArray of guchars) and #guint32
- * representing a list of NetworkManager IPv6 addresses (which is a tuple of address,
- * prefix, and gateway), into a #GSList of #NMIP6Address objects. The specific format of
- * this serialization is not guaranteed to be stable and the #GValueArray may be
- * extended in the future.
- *
- * Returns: (transfer full) (element-type NMIP6Address): a newly allocated #GSList of #NMIP6Address objects
- **/
-GSList *
-nm_utils_ip6_addresses_from_gvalue (const GValue *value)
-{
- GPtrArray *addresses;
- int i;
- GSList *list = NULL;
-
- addresses = (GPtrArray *) g_value_get_boxed (value);
-
- for (i = 0; addresses && (i < addresses->len); i++) {
- GValueArray *elements = (GValueArray *) g_ptr_array_index (addresses, i);
- GValue *tmp;
- GByteArray *ba_addr;
- GByteArray *ba_gw = NULL;
- NMIP6Address *addr;
- guint32 prefix;
-
- if (elements->n_values < 2 || elements->n_values > 3) {
- g_warning ("%s: ignoring invalid IP6 address structure", __func__);
- continue;
- }
-
- /* Third element (gateway) is optional */
- if ( !_nm_utils_gvalue_array_validate (elements, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)
- && !_nm_utils_gvalue_array_validate (elements, 3, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, DBUS_TYPE_G_UCHAR_ARRAY)) {
- g_warning ("%s: ignoring invalid IP6 address structure", __func__);
- continue;
- }
-
- tmp = g_value_array_get_nth (elements, 0);
- ba_addr = g_value_get_boxed (tmp);
- if (ba_addr->len != 16) {
- g_warning ("%s: ignoring invalid IP6 address of length %d",
- __func__, ba_addr->len);
- continue;
- }
-
- tmp = g_value_array_get_nth (elements, 1);
- prefix = g_value_get_uint (tmp);
- if (prefix > 128) {
- g_warning ("%s: ignoring invalid IP6 prefix %d",
- __func__, prefix);
- continue;
- }
-
- if (elements->n_values == 3) {
- tmp = g_value_array_get_nth (elements, 2);
- ba_gw = g_value_get_boxed (tmp);
- if (ba_gw->len != 16) {
- g_warning ("%s: ignoring invalid IP6 gateway address of length %d",
- __func__, ba_gw->len);
- continue;
- }
- }
-
- addr = nm_ip6_address_new ();
- nm_ip6_address_set_prefix (addr, prefix);
- nm_ip6_address_set_address (addr, (const struct in6_addr *) ba_addr->data);
- if (ba_gw)
- nm_ip6_address_set_gateway (addr, (const struct in6_addr *) ba_gw->data);
-
- list = g_slist_prepend (list, addr);
- }
-
- return g_slist_reverse (list);
-}
-
-/**
- * nm_utils_ip6_addresses_to_gvalue:
- * @list: (element-type NMIP6Address): a list of #NMIP6Address objects
- * @value: a pointer to a #GValue into which to place the converted addresses,
- * which should be unset by the caller (when no longer needed) with
- * g_value_unset().
- *
- * Utility function to convert a #GSList of #NMIP6Address objects into a
- * #GPtrArray of #GValueArrays representing a list of NetworkManager IPv6 addresses
- * (which is a tuple of address, prefix, and gateway). The specific format of
- * this serialization is not guaranteed to be stable and may be extended in the
- * future.
- **/
-void
-nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *addresses;
- GSList *iter;
-
- addresses = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- NMIP6Address *addr = (NMIP6Address *) iter->data;
- GValueArray *array;
- GValue element = G_VALUE_INIT;
- GByteArray *ba;
-
- array = g_value_array_new (3);
-
- /* IP address */
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_address (addr), 16);
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- /* Prefix */
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, nm_ip6_address_get_prefix (addr));
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- /* Gateway */
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guint8 *) nm_ip6_address_get_gateway (addr), 16);
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_ptr_array_add (addresses, array);
- }
-
- g_value_take_boxed (value, addresses);
-}
-
-/**
- * nm_utils_ip6_routes_from_gvalue:
- * @value: #GValue containing a #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32,
- * (#GArray of #guchars), and #guint32
- *
- * Utility function #GPtrArray of #GValueArrays of (#GArray of #guchars), #guint32,
- * (#GArray of #guchars), and #guint32 representing a list of NetworkManager IPv6
- * routes (which is a tuple of destination, prefix, next hop, and metric)
- * into a #GSList of #NMIP6Route objects. The specific format of this serialization
- * is not guaranteed to be stable and may be extended in the future.
- *
- * Returns: (transfer full) (element-type NMIP6Route): a newly allocated #GSList of #NMIP6Route objects
- **/
-GSList *
-nm_utils_ip6_routes_from_gvalue (const GValue *value)
-{
- GPtrArray *routes;
- int i;
- GSList *list = NULL;
-
- routes = (GPtrArray *) g_value_get_boxed (value);
- for (i = 0; routes && (i < routes->len); i++) {
- GValueArray *route_values = (GValueArray *) g_ptr_array_index (routes, i);
- GByteArray *dest, *next_hop;
- guint prefix, metric;
- NMIP6Route *route;
-
- if (!_nm_utils_gvalue_array_validate (route_values, 4,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UINT,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UINT)) {
- g_warning ("Ignoring invalid IP6 route");
- continue;
- }
-
- dest = g_value_get_boxed (g_value_array_get_nth (route_values, 0));
- if (dest->len != 16) {
- g_warning ("%s: ignoring invalid IP6 dest address of length %d",
- __func__, dest->len);
- continue;
- }
-
- prefix = g_value_get_uint (g_value_array_get_nth (route_values, 1));
-
- next_hop = g_value_get_boxed (g_value_array_get_nth (route_values, 2));
- if (next_hop->len != 16) {
- g_warning ("%s: ignoring invalid IP6 next_hop address of length %d",
- __func__, next_hop->len);
- continue;
- }
-
- metric = g_value_get_uint (g_value_array_get_nth (route_values, 3));
-
- route = nm_ip6_route_new ();
- nm_ip6_route_set_dest (route, (struct in6_addr *)dest->data);
- nm_ip6_route_set_prefix (route, prefix);
- nm_ip6_route_set_next_hop (route, (struct in6_addr *)next_hop->data);
- nm_ip6_route_set_metric (route, metric);
- list = g_slist_prepend (list, route);
- }
-
- return g_slist_reverse (list);
-}
-
-/**
- * nm_utils_ip6_routes_to_gvalue:
- * @list: (element-type NMIP6Route): a list of #NMIP6Route objects
- * @value: a pointer to a #GValue into which to place the converted routes,
- * which should be unset by the caller (when no longer needed) with
- * g_value_unset().
- *
- * Utility function to convert a #GSList of #NMIP6Route objects into a #GPtrArray of
- * #GValueArrays of (#GArray of #guchars), #guint32, (#GArray of #guchars), and #guint32
- * representing a list of NetworkManager IPv6 routes (which is a tuple of destination,
- * prefix, next hop, and metric). The specific format of this serialization is not
- * guaranteed to be stable and may be extended in the future.
- **/
-void
-nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *routes;
- GSList *iter;
-
- routes = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- NMIP6Route *route = (NMIP6Route *) iter->data;
- GValueArray *array;
- const struct in6_addr *addr;
- GByteArray *ba;
- GValue element = G_VALUE_INIT;
-
- array = g_value_array_new (4);
-
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- addr = nm_ip6_route_get_dest (route);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, nm_ip6_route_get_prefix (route));
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
- addr = nm_ip6_route_get_next_hop (route);
- ba = g_byte_array_new ();
- g_byte_array_append (ba, (guchar *)addr, sizeof (*addr));
- g_value_take_boxed (&element, ba);
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_value_init (&element, G_TYPE_UINT);
- g_value_set_uint (&element, nm_ip6_route_get_metric (route));
- g_value_array_append (array, &element);
- g_value_unset (&element);
-
- g_ptr_array_add (routes, array);
- }
-
- g_value_take_boxed (value, routes);
-}
-
-/**
- * nm_utils_ip6_dns_from_gvalue: (skip)
- * @value: a #GValue
- *
- * Converts a #GValue containing a #GPtrArray of IP6 DNS, represented as
- * #GByteArrays into a #GSList of IP address strings.
- *
- * Returns: a #GSList of IP6 addresses.
- */
-GSList *
-nm_utils_ip6_dns_from_gvalue (const GValue *value)
-{
- GPtrArray *dns;
- int i;
- GSList *list = NULL;
-
- dns = (GPtrArray *) g_value_get_boxed (value);
- for (i = 0; dns && (i < dns->len); i++) {
- GByteArray *bytearray = (GByteArray *) g_ptr_array_index (dns, i);
- const char *str;
-
- if (bytearray->len != 16) {
- g_warning ("%s: ignoring invalid IP6 address of length %d",
- __func__, bytearray->len);
- continue;
- }
-
- str = nm_utils_inet6_ntop ((struct in6_addr *) bytearray->data, NULL);
- list = g_slist_prepend (list, g_strdup (str));
- }
-
- return g_slist_reverse (list);
-}
-
-/**
- * nm_utils_ip6_dns_to_gvalue: (skip)
- * @list: a list of #NMIP6Route objects
- * @value: a pointer to a #GValue into which to place the converted DNS server
- * addresses, which should be unset by the caller (when no longer needed) with
- * g_value_unset().
- *
- * Utility function to convert a #GSList of <literal><type>struct
- * in6_addr</type></literal> structs into a #GPtrArray of #GByteArrays
- * representing each server's IPv6 addresses in network byte order.
- * The specific format of this serialization is not guaranteed to be
- * stable and may be extended in the future.
- */
-void
-nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value)
-{
- GPtrArray *dns;
- GSList *iter;
-
- dns = g_ptr_array_new ();
-
- for (iter = list; iter; iter = iter->next) {
- const char *str = iter->data;
- GByteArray *bytearray;
-
- bytearray = g_byte_array_new ();
- g_byte_array_set_size (bytearray, 16);
- inet_pton (AF_INET6, str, bytearray->data);
- g_ptr_array_add (dns, bytearray);
- }
-
- g_value_take_boxed (value, dns);
-}
-
-/**
* nm_utils_ip6_dns_to_variant:
* @dns: (type utf8): an array of IP address strings
*