mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
util: Add SSID to UTF8 pretty-print function
Use a static buffer for converting an SSID to an approximate string in UTF8. Replace each char that is not UTF8 compatible with the UTF8 replacement symbol.
This commit is contained in:
parent
007d9f3bd1
commit
bf25abf38d
@ -60,7 +60,8 @@ monitor_iwmon_SOURCES = monitor/main.c linux/nl80211.h \
|
||||
monitor/nlmon.h monitor/nlmon.c \
|
||||
monitor/pcap.h monitor/pcap.c \
|
||||
monitor/display.h monitor/display.c \
|
||||
src/ie.h src/ie.c
|
||||
src/ie.h src/ie.c \
|
||||
src/util.h src/util.c
|
||||
monitor_iwmon_LDADD = ell/libell-internal.la
|
||||
|
||||
noinst_PROGRAMS = tools/hwsim
|
||||
|
76
src/util.c
Normal file
76
src/util.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2014 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <ell/string.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid)
|
||||
{
|
||||
static char buf[3* 32 + 1];
|
||||
size_t i = 0, pos = 0;
|
||||
const uint8_t *start = ssid, *end;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (len > 32)
|
||||
goto no_ssid;
|
||||
|
||||
while (i < len && !ssid[i])
|
||||
i++;
|
||||
|
||||
if (i == len)
|
||||
goto no_ssid;
|
||||
|
||||
i = len;
|
||||
|
||||
while (i && (!l_utf8_validate((const char *)start, i,
|
||||
(const char **)&end))) {
|
||||
const char replacement[] = { 0xEF, 0xBF, 0xBD };
|
||||
int bytes = end - start;
|
||||
|
||||
memcpy(&buf[pos], start, bytes);
|
||||
pos += bytes;
|
||||
|
||||
memcpy(&buf[pos], replacement, sizeof(replacement));
|
||||
pos += sizeof(replacement);
|
||||
|
||||
start = end + 1;
|
||||
i -= (bytes + 1);
|
||||
}
|
||||
|
||||
if (i) {
|
||||
memcpy(&buf[pos], start, i);
|
||||
pos += i;
|
||||
}
|
||||
|
||||
no_ssid:
|
||||
buf[pos] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
31
src/util.h
Normal file
31
src/util.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
*
|
||||
* Wireless daemon for Linux
|
||||
*
|
||||
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_H
|
||||
#define __UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid);
|
||||
|
||||
#endif /* __UTIL_H */
|
Loading…
Reference in New Issue
Block a user