diff options
author | Tanu Kaskinen <tanuk@iki.fi> | 2016-10-11 17:27:06 +0300 |
---|---|---|
committer | Tanu Kaskinen <tanuk@iki.fi> | 2017-04-02 20:48:52 +0300 |
commit | d7e85813bd1ba10915a7069103ab8621b6e0ee36 (patch) | |
tree | 9e4e336764163b8487a4e7b5c4725aca3a8ad1ee /src/modules | |
parent | b53dd1f0df269d7e1b55e059b0a0d3d530b124b5 (diff) |
bluetooth: allow UTF-8 in device descriptions
Users may configure the device alias to have characters outside the
ASCII range, so our name cleanup routine was too aggressive. Let's just
make sure that the device description is a valid UTF-8 string.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=98160
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/bluetooth/bluez4-util.c | 31 | ||||
-rw-r--r-- | src/modules/bluetooth/bluez4-util.h | 2 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluez4-device.c | 3 | ||||
-rw-r--r-- | src/modules/bluetooth/module-bluez5-device.c | 35 |
4 files changed, 4 insertions, 67 deletions
diff --git a/src/modules/bluetooth/bluez4-util.c b/src/modules/bluetooth/bluez4-util.c index 06108f4b..82654508 100644 --- a/src/modules/bluetooth/bluez4-util.c +++ b/src/modules/bluetooth/bluez4-util.c @@ -1841,34 +1841,3 @@ const char *pa_bluez4_form_factor_to_string(pa_bluez4_form_factor_t ff) { pa_assert_not_reached(); } - -char *pa_bluez4_cleanup_name(const char *name) { - char *t, *s, *d; - bool space = false; - - pa_assert(name); - - while ((*name >= 1 && *name <= 32) || *name >= 127) - name++; - - t = pa_xstrdup(name); - - for (s = d = t; *s; s++) { - - if (*s <= 32 || *s >= 127 || *s == '_') { - space = true; - continue; - } - - if (space) { - *(d++) = ' '; - space = false; - } - - *(d++) = *s; - } - - *d = 0; - - return t; -} diff --git a/src/modules/bluetooth/bluez4-util.h b/src/modules/bluetooth/bluez4-util.h index ed588f17..f4b5ca34 100644 --- a/src/modules/bluetooth/bluez4-util.h +++ b/src/modules/bluetooth/bluez4-util.h @@ -155,8 +155,6 @@ typedef enum pa_bluez4_form_factor { pa_bluez4_form_factor_t pa_bluez4_get_form_factor(uint32_t class); const char *pa_bluez4_form_factor_to_string(pa_bluez4_form_factor_t ff); -char *pa_bluez4_cleanup_name(const char *name); - const char *pa_bluez4_profile_to_string(pa_bluez4_profile_t profile); #endif diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c index ac4ed63f..4c8ec8c7 100644 --- a/src/modules/bluetooth/module-bluez4-device.c +++ b/src/modules/bluetooth/module-bluez4-device.c @@ -31,6 +31,7 @@ #include <pulse/rtclock.h> #include <pulse/sample.h> #include <pulse/timeval.h> +#include <pulse/utf8.h> #include <pulse/xmalloc.h> #include <pulsecore/i18n.h> @@ -2280,7 +2281,7 @@ static int add_card(struct userdata *u) { data.driver = __FILE__; data.module = u->module; - n = pa_bluez4_cleanup_name(device->alias); + n = pa_utf8_filter(device->alias); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, n); pa_xfree(n); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, device->address); diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c index 97fe8beb..afcc4576 100644 --- a/src/modules/bluetooth/module-bluez5-device.c +++ b/src/modules/bluetooth/module-bluez5-device.c @@ -29,6 +29,7 @@ #include <pulse/rtclock.h> #include <pulse/timeval.h> +#include <pulse/utf8.h> #include <pulsecore/core-error.h> #include <pulsecore/core-rtclock.h> @@ -1619,38 +1620,6 @@ static void stop_thread(struct userdata *u) { } /* Run from main thread */ -static char *cleanup_name(const char *name) { - char *t, *s, *d; - bool space = false; - - pa_assert(name); - - while ((*name >= 1 && *name <= 32) || *name >= 127) - name++; - - t = pa_xstrdup(name); - - for (s = d = t; *s; s++) { - - if (*s <= 32 || *s >= 127 || *s == '_') { - space = true; - continue; - } - - if (space) { - *(d++) = ' '; - space = false; - } - - *(d++) = *s; - } - - *d = 0; - - return t; -} - -/* Run from main thread */ static pa_available_t get_port_availability(struct userdata *u, pa_direction_t direction) { pa_available_t result = PA_AVAILABLE_NO; unsigned i; @@ -1944,7 +1913,7 @@ static int add_card(struct userdata *u) { data.driver = __FILE__; data.module = u->module; - alias = cleanup_name(d->alias); + alias = pa_utf8_filter(d->alias); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, alias); pa_xfree(alias); |