summaryrefslogtreecommitdiff
path: root/gsupplicant
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2011-12-23 08:58:28 (GMT)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2011-12-23 11:36:31 (GMT)
commita1115c6d64c31c6293c4243f9bfbf97b7c35a88a (patch)
tree334da700fb5b8998d1ee474f9de3407c04b719da /gsupplicant
parent76a486a7cbdbb549c229cb2593c96f1c1402bb48 (diff)
downloadconnman-a1115c6d64c31c6293c4243f9bfbf97b7c35a88a.zip
connman-a1115c6d64c31c6293c4243f9bfbf97b7c35a88a.tar.gz
connman-a1115c6d64c31c6293c4243f9bfbf97b7c35a88a.tar.bz2
supplicant: Make create_name() UTF-8 aware
Create proper UTF-8 encoded names from SSIDs. Invalid sequneces will be replaced by replacement characters. This function is based on the _g_utf8_make_valid() from glib.
Diffstat (limited to 'gsupplicant')
-rw-r--r--gsupplicant/supplicant.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index b8e939d..3e61f74 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -995,25 +995,43 @@ static void interface_network_removed(DBusMessageIter *iter, void *user_data)
static char *create_name(unsigned char *ssid, int ssid_len)
{
- char *name;
- int i;
+ GString *string;
+ const gchar *remainder, *invalid;
+ int valid_bytes, remaining_bytes;
if (ssid_len < 1 || ssid[0] == '\0')
- name = NULL;
- else
- name = g_try_malloc0(ssid_len + 1);
-
- if (name == NULL)
return g_strdup("");
- for (i = 0; i < ssid_len; i++) {
- if (g_ascii_isprint(ssid[i]))
- name[i] = ssid[i];
- else
- name[i] = ' ';
+ string = NULL;
+ remainder = (const gchar *)ssid;
+ remaining_bytes = ssid_len;
+
+ while (remaining_bytes != 0) {
+ if (g_utf8_validate(remainder, remaining_bytes,
+ &invalid) == TRUE) {
+ break;
+ }
+
+ valid_bytes = invalid - remainder;
+
+ if (string == NULL)
+ string = g_string_sized_new(remaining_bytes);
+
+ g_string_append_len(string, remainder, valid_bytes);
+
+ /* append U+FFFD REPLACEMENT CHARACTER */
+ g_string_append(string, "\357\277\275");
+
+ remaining_bytes -= valid_bytes + 1;
+ remainder = invalid + 1;
}
- return name;
+ if (string == NULL)
+ return g_strndup((const gchar *)ssid, ssid_len + 1);
+
+ g_string_append(string, remainder);
+
+ return g_string_free(string, FALSE);
}
static char *create_group(struct g_supplicant_bss *bss)