Lennart Poettering wrote:
> At two places:
> get_service()
> and in:
> pa__init()
Attached patches to try and fix it ... the utf8 stuff is "borrowed" from
glib. I haven't actually tried it with UTF-8 data, but it should be ok.
I saw that the utf8 functions in pulse came from glib so I thought it'd
be ok to copy some more from there.
> (And while we're at it. Avahi's current implementation of
> avahi_alternative_service_name() which generates an alternative
> service name when a name conflict happens and basically just attaches
> " #2", " #3" to it, generates a 66 character string when you pass a 63
> character string to it. Which is obviously a bug in Avahi. I've posted
> this as bug #151 in avahi BT now.)
I tried looking through avahi, but it seems that the function used in
avahi counts chars using strlen() which isn't utf8 aware either. Either
way, avahi could also use something like the first patch to count UTF8
chars properly.
But this is just with a quick look :) I could be way off.
Cheers,
Rémi
add pa_utf8_strndup()
---
commit b31a36a0ef61fadefdfab9260e4546c292d3c129
tree 50ca97d46d8ab233ea5512771b30a609d0b5b9f1
parent 627801f1cbe02b17349f183e406c265bf4b582c2
author Remi Cardona <[EMAIL PROTECTED]> Sat, 11 Aug 2007 10:58:13 +0200
committer Remi Cardona <[EMAIL PROTECTED]> Sat, 11 Aug 2007 10:58:13 +0200
src/pulse/utf8.c | 17 +++++++++++++++++
src/pulse/utf8.h | 3 +++
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c
index 2ac2d10..250ed9a 100644
--- a/src/pulse/utf8.c
+++ b/src/pulse/utf8.c
@@ -88,6 +88,14 @@ static inline void merge_continuation_char(uint32_t *u_ch, uint8_t ch) {
*u_ch |= ch & 0x3f;
}
+static inline char * utf8_find_next_char (const char *p) {
+ if (*p) {
+ for (++p; (*p & 0xc0) == 0x80; ++p)
+ ;
+ }
+ return (char*)p;
+}
+
static char* utf8_validate(const char *str, char *output) {
uint32_t val = 0;
uint32_t min = 0;
@@ -182,6 +190,15 @@ const char* pa_utf8_valid (const char *str) {
return utf8_validate(str, NULL);
}
+char* pa_utf8_strndup(const char *str, unsigned int n) {
+ const char *s = str;
+ while (n && *s) {
+ s = utf8_find_next_char(s);
+ n--;
+ }
+ return pa_xstrndup(str, s - str);
+}
+
char* pa_utf8_filter (const char *str) {
char *new_str;
diff --git a/src/pulse/utf8.h b/src/pulse/utf8.h
index ff8dc21..2167463 100644
--- a/src/pulse/utf8.h
+++ b/src/pulse/utf8.h
@@ -36,6 +36,9 @@ PA_C_DECL_BEGIN
/** Test if the specified strings qualifies as valid UTF8. Return the string if so, otherwise NULL */
const char *pa_utf8_valid(const char *str);
+/** Copy N UTF-8 characters (not bytes) from a string to another. Free the string using pa_xfree(). */
+char* pa_utf8_strncpy(const char *str, unsigned int n);
+
/** Filter all invalid UTF8 characters from the specified string, returning a new fully UTF8 valid string. Don't forget to free the returned string with pa_xfree() */
char *pa_utf8_filter(const char *str);
restrict service::name and service::service_name to 63 UTF-8 chars
---
commit a4429e9e2b090f009fbc9c8dd6316417c52a86a1
tree 5d7eb5f06daf36c8701e9115136aa3a9c37990b1
parent b31a36a0ef61fadefdfab9260e4546c292d3c129
author Remi Cardona <[EMAIL PROTECTED]> Sat, 11 Aug 2007 11:06:03 +0200
committer Remi Cardona <[EMAIL PROTECTED]> Sat, 11 Aug 2007 11:06:03 +0200
src/modules/module-zeroconf-publish.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c
index 69508ad..6d9454b 100644
--- a/src/modules/module-zeroconf-publish.c
+++ b/src/modules/module-zeroconf-publish.c
@@ -245,6 +245,7 @@ finish:
static struct service *get_service(struct userdata *u, const char *name, const char *description) {
struct service *s;
char hn[64];
+ char * service_name;
if ((s = pa_hashmap_get(u->services, name)))
return s;
@@ -253,9 +254,11 @@ static struct service *get_service(struct userdata *u, const char *name, const c
s->userdata = u;
s->entry_group = NULL;
s->published = UNPUBLISHED;
- s->name = pa_xstrdup(name);
+ s->name = pa_utf8_strndup(name, 63);
s->loaded.valid = s->autoload.valid = 0;
- s->service_name = pa_sprintf_malloc("%s on %s", description ? description : s->name, pa_get_host_name(hn, sizeof(hn)));
+ service_name = pa_sprintf_malloc("%s on %s", description ? description : s->name, pa_get_host_name(hn, sizeof(hn)));
+ s->service_name = pa_utf8_strndup(service_name, 63);
+ pa_xfree(service_name);
pa_hashmap_put(u->services, s->name, s);
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss