1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2008 Red Hat, Inc.
21 #include "nm-default.h"
23 #include <dbus/dbus-glib.h>
27 #include "nm-types-private.h"
28 #include "nm-object-private.h"
29 #include "nm-object-cache.h"
30 #include "nm-dbus-glib-types.h"
31 #include "nm-setting-ip6-config.h"
34 _nm_ssid_copy (GByteArray *src)
38 dest = g_byte_array_sized_new (src->len);
39 g_byte_array_append (dest, src->data, src->len);
44 _nm_ssid_free (GByteArray *ssid)
46 g_byte_array_free (ssid, TRUE);
50 nm_ssid_get_type (void)
52 static GType our_type = 0;
55 our_type = g_boxed_type_register_static (g_intern_static_string ("NMSsid"),
56 (GBoxedCopyFunc) _nm_ssid_copy,
57 (GBoxedFreeFunc) _nm_ssid_free);
62 _nm_ssid_demarshal (GValue *value, GByteArray **dest)
66 if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY))
70 g_boxed_free (NM_TYPE_SSID, *dest);
74 array = (GByteArray *) g_value_get_boxed (value);
75 if (array && (array->len > 0)) {
76 *dest = g_byte_array_sized_new (array->len);
77 (*dest)->len = array->len;
78 memcpy ((*dest)->data, array->data, array->len);
84 /*****************************/
87 _nm_uint_array_copy (GArray *src)
91 dest = g_array_sized_new (FALSE, TRUE, sizeof (guint32), src->len);
92 g_array_append_vals (dest, src->data, src->len);
97 _nm_uint_array_free (GArray *array)
99 g_array_free (array, TRUE);
103 nm_uint_array_get_type (void)
105 static GType our_type = 0;
108 our_type = g_boxed_type_register_static (g_intern_static_string ("NMUintArray"),
109 (GBoxedCopyFunc) _nm_uint_array_copy,
110 (GBoxedFreeFunc) _nm_uint_array_free);
115 _nm_uint_array_demarshal (GValue *value, GArray **dest)
119 if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY))
123 g_boxed_free (NM_TYPE_UINT_ARRAY, *dest);
127 array = (GArray *) g_value_get_boxed (value);
128 if (array && (array->len > 0)) {
129 *dest = g_array_sized_new (FALSE, TRUE, sizeof (guint32), array->len);
130 g_array_append_vals (*dest, array->data, array->len);
136 /*****************************/
139 _nm_string_array_copy (GPtrArray *src)
144 dest = g_ptr_array_sized_new (src->len);
145 for (i = 0; i < src->len; i++)
146 g_ptr_array_add (dest, g_strdup (g_ptr_array_index (src, i)));
151 _nm_string_array_free (GPtrArray *array)
155 for (i = 0; i < array->len; i++)
156 g_free (g_ptr_array_index (array, i));
157 g_ptr_array_free (array, TRUE);
161 nm_string_array_get_type (void)
163 static GType our_type = 0;
166 our_type = g_boxed_type_register_static (g_intern_static_string ("NMStringArray"),
167 (GBoxedCopyFunc) _nm_string_array_copy,
168 (GBoxedFreeFunc) _nm_string_array_free);
173 _nm_string_array_demarshal (GValue *value, GPtrArray **dest)
177 if (!G_VALUE_HOLDS (value, G_TYPE_STRV))
181 g_boxed_free (NM_TYPE_STRING_ARRAY, *dest);
185 array = (char **) g_value_get_boxed (value);
186 if (array && array[0]) {
189 *dest = g_ptr_array_new ();
190 for (i = 0; array[i]; i++)
191 g_ptr_array_add (*dest, g_strdup (array[i]));
197 /*****************************/
200 _nm_object_array_copy (GPtrArray *src)
205 dest = g_ptr_array_sized_new (src->len);
206 for (i = 0; i < src->len; i++)
207 g_ptr_array_add (dest, g_object_ref (g_ptr_array_index (src, i)));
212 _nm_object_array_free (GPtrArray *array)
216 for (i = 0; i < array->len; i++)
217 g_object_unref (g_ptr_array_index (array, i));
218 g_ptr_array_free (array, TRUE);
222 nm_object_array_get_type (void)
224 static GType our_type = 0;
227 our_type = g_boxed_type_register_static (g_intern_static_string ("NMObjectArray"),
228 (GBoxedCopyFunc) _nm_object_array_copy,
229 (GBoxedFreeFunc) _nm_object_array_free);
234 _nm_object_array_demarshal (GValue *value,
236 DBusGConnection *connection,
237 NMObjectCreatorFunc func)
239 GPtrArray *temp = NULL;
242 if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH))
245 array = (GPtrArray *) g_value_get_boxed (value);
246 if (array && array->len) {
249 temp = g_ptr_array_sized_new (array->len);
250 for (i = 0; i < array->len; i++) {
254 path = g_ptr_array_index (array, i);
255 object = G_OBJECT (_nm_object_cache_get (path));
257 g_ptr_array_add (temp, object);
259 object = (*func) (connection, path);
261 g_ptr_array_add (temp, object);
263 g_warning ("%s: couldn't create object for %s", __func__, path);
267 temp = g_ptr_array_new ();
269 /* Deallocate after to ensure that an object that might already
270 * be in the array doesn't get destroyed due to refcounting.
273 g_boxed_free (NM_TYPE_OBJECT_ARRAY, *dest);
279 /*****************************/
282 _nm_ip6_address_object_array_copy (GPtrArray *src)
287 dest = g_ptr_array_sized_new (src->len);
288 for (i = 0; i < src->len; i++)
289 g_ptr_array_add (dest, nm_ip6_address_dup (g_ptr_array_index (src, i)));
294 _nm_ip6_address_object_array_free (GPtrArray *array)
298 for (i = 0; i < array->len; i++)
299 nm_ip6_address_unref (g_ptr_array_index (array, i));
300 g_ptr_array_free (array, TRUE);
304 nm_ip6_address_object_array_get_type (void)
306 static GType our_type = 0;
309 our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressObjectArray"),
310 (GBoxedCopyFunc) _nm_ip6_address_object_array_copy,
311 (GBoxedFreeFunc) _nm_ip6_address_object_array_free);
315 /*****************************/
318 _nm_ip6_address_array_copy (GPtrArray *src)
323 dest = g_ptr_array_sized_new (src->len);
324 for (i = 0; i < src->len; i++) {
325 struct in6_addr *addr = g_ptr_array_index (src, i);
326 struct in6_addr *copy;
328 copy = g_malloc0 (sizeof (struct in6_addr));
329 memcpy (copy, addr, sizeof (struct in6_addr));
330 g_ptr_array_add (dest, copy);
336 _nm_ip6_address_array_free (GPtrArray *array)
340 for (i = 0; i < array->len; i++)
341 g_free (g_ptr_array_index (array, i));
342 g_ptr_array_free (array, TRUE);
346 nm_ip6_address_array_get_type (void)
348 static GType our_type = 0;
351 our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6AddressArray"),
352 (GBoxedCopyFunc) _nm_ip6_address_array_copy,
353 (GBoxedFreeFunc) _nm_ip6_address_array_free);
358 _nm_ip6_address_array_demarshal (GValue *value, GSList **dest)
362 if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR))
366 g_slist_free_full (*dest, g_free);
370 array = (GPtrArray *) g_value_get_boxed (value);
371 if (array && array->len) {
374 for (i = 0; i < array->len; i++) {
375 GByteArray *bytearray = (GByteArray *) g_ptr_array_index (array, i);
376 struct in6_addr *addr;
378 addr = g_malloc0 (sizeof (struct in6_addr));
379 memcpy (addr->s6_addr, bytearray->data, bytearray->len);
380 *dest = g_slist_append (*dest, addr);
387 /*****************************/
390 _nm_ip6_route_object_array_copy (GPtrArray *src)
395 dest = g_ptr_array_sized_new (src->len);
396 for (i = 0; i < src->len; i++)
397 g_ptr_array_add (dest, nm_ip6_route_dup (g_ptr_array_index (src, i)));
402 _nm_ip6_route_object_array_free (GPtrArray *array)
406 for (i = 0; i < array->len; i++)
407 nm_ip6_route_unref (g_ptr_array_index (array, i));
408 g_ptr_array_free (array, TRUE);
412 nm_ip6_route_object_array_get_type (void)
414 static GType our_type = 0;
417 our_type = g_boxed_type_register_static (g_intern_static_string ("NMIP6RouteObjectArray"),
418 (GBoxedCopyFunc) _nm_ip6_route_object_array_copy,
419 (GBoxedFreeFunc) _nm_ip6_route_object_array_free);