NetworkManager r3985 - in trunk: . libnm-util src/dhcp-manager
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r3985 - in trunk: . libnm-util src/dhcp-manager
- Date: Mon, 18 Aug 2008 21:24:31 +0000 (UTC)
Author: dcbw
Date: Mon Aug 18 21:24:31 2008
New Revision: 3985
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3985&view=rev
Log:
2008-08-18 Dan Williams <dcbw redhat com>
* libnm-util/nm-utils.c
libnm-util/nm-utils.h
- (nm_utils_garray_to_string): remove; NM was the only user and doesn't
export anything that needs to be converted with this function
* src/dhcp-manager/nm-dhcp-manager.c
- (garray_to_string): convert a byte array to a UTF-8 string with
minimal validation; the DHCP client sends it in ASCII anyway
- (get_option, copy_option): use garray_to_string()
Modified:
trunk/ChangeLog
trunk/libnm-util/nm-utils.c
trunk/libnm-util/nm-utils.h
trunk/src/dhcp-manager/nm-dhcp-manager.c
Modified: trunk/libnm-util/nm-utils.c
==============================================================================
--- trunk/libnm-util/nm-utils.c (original)
+++ trunk/libnm-util/nm-utils.c Mon Aug 18 21:24:31 2008
@@ -363,33 +363,6 @@
return table;
}
-/* Converts a GArray into a UTF-8 string */
-char *
-nm_utils_garray_to_string (GArray *array)
-{
- GString *str;
- int i;
- char c;
- char *converted = NULL;
-
- g_return_val_if_fail (array != NULL, NULL);
-
- str = g_string_sized_new (array->len);
- for (i = 0; i < array->len; i++) {
- c = array->data[i];
-
- /* Convert NULLs to spaces to increase the readability. */
- if (c == '\0')
- c = ' ';
- str = g_string_append_c (str, c);
- }
- str = g_string_append_c (str, '\0');
-
- converted = string_to_utf8 (str->str, (gsize) str->len);
- g_string_free (str, FALSE);
- return converted;
-}
-
void
nm_utils_slist_free (GSList *list, GDestroyNotify elem_destroy_fn)
{
Modified: trunk/libnm-util/nm-utils.h
==============================================================================
--- trunk/libnm-util/nm-utils.h (original)
+++ trunk/libnm-util/nm-utils.h Mon Aug 18 21:24:31 2008
@@ -147,9 +147,6 @@
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
-/* Converts a GArray into a UTF-8 string */
-char *nm_utils_garray_to_string (GArray *array);
-
void nm_utils_slist_free (GSList *list,
GDestroyNotify elem_destroy_fn);
Modified: trunk/src/dhcp-manager/nm-dhcp-manager.c
==============================================================================
--- trunk/src/dhcp-manager/nm-dhcp-manager.c (original)
+++ trunk/src/dhcp-manager/nm-dhcp-manager.c Mon Aug 18 21:24:31 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* nm-dhcp-manager.c - Handle the DHCP daemon for NetworkManager
*
@@ -265,10 +265,42 @@
}
static char *
-get_option (GHashTable * hash,
- gpointer key)
+garray_to_string (GArray *array, const char *key)
{
- GValue * value;
+ GString *str;
+ int i;
+ char c;
+ char *converted = NULL;
+
+ g_return_val_if_fail (array != NULL, NULL);
+
+ /* Since the DHCP options come through environment variables, they should
+ * already be UTF-8 safe, but just make sure.
+ */
+ str = g_string_sized_new (array->len);
+ for (i = 0; i < array->len; i++) {
+ c = array->data[i];
+
+ /* Convert NULLs to spaces and non-ASCII characters to ? */
+ if (c == '\0')
+ c = ' ';
+ else if (c > 127)
+ c = '?';
+ str = g_string_append_c (str, c);
+ }
+ str = g_string_append_c (str, '\0');
+
+ converted = str->str;
+ if (!g_utf8_validate (converted, -1, NULL))
+ nm_warning ("%s: DHCP option '%s' couldn't be converted to UTF-8", __func__, key);
+ g_string_free (str, FALSE);
+ return converted;
+}
+
+static char *
+get_option (GHashTable *hash, const char *key)
+{
+ GValue *value;
value = g_hash_table_lookup (hash, key);
if (value == NULL)
@@ -281,7 +313,7 @@
return NULL;
}
- return nm_utils_garray_to_string ((GArray *) g_value_get_boxed (value));
+ return garray_to_string ((GArray *) g_value_get_boxed (value), key);
}
static void
@@ -290,30 +322,19 @@
gpointer user_data)
{
NMDHCPDevice * device = (NMDHCPDevice *) user_data;
- char * dup_key = NULL;
- char * dup_value = NULL;
-
- dup_key = g_strdup (key);
- if (!dup_key)
- goto error;
+ const char *str_key = (const char *) key;
+ char *str_value = NULL;
if (G_VALUE_TYPE (value) != DBUS_TYPE_G_UCHAR_ARRAY) {
nm_warning ("Unexpected key %s value type was not "
"DBUS_TYPE_G_UCHAR_ARRAY",
- (char *) key);
- goto error;
+ str_key);
+ return;
}
- dup_value = nm_utils_garray_to_string ((GArray *) g_value_get_boxed (value));
- if (!dup_value)
- goto error;
-
- g_hash_table_insert (device->options, dup_key, dup_value);
- return;
-
-error:
- g_free (dup_key);
- g_free (dup_value);
+ str_value = garray_to_string ((GArray *) g_value_get_boxed (value), str_key);
+ if (str_value)
+ g_hash_table_insert (device->options, g_strdup (str_key), str_value);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]