From: Jaroslav Kysela Date: Sun, 3 Dec 2017 08:47:44 +0000 (+0100) Subject: channel icons: add '%U' to pass UTF-8 filenames, fixes #4755 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6927b21a568a2434704ba2b8c04f52a01a4f8929;p=thirdparty%2Ftvheadend.git channel icons: add '%U' to pass UTF-8 filenames, fixes #4755 --- diff --git a/docs/property/config_channelicon_path.md b/docs/property/config_channelicon_path.md index 33ee5b6b2..2c6f2aadc 100644 --- a/docs/property/config_channelicon_path.md +++ b/docs/property/config_channelicon_path.md @@ -4,8 +4,9 @@ The following placeholders are available: Placeholder | Function :----------:| -------- -**%C** | The transliterated channel name in in URL encoded ASCII with safe characters only - `WDR Köln :<>|*?'"` will be `WDR%20Koln%20________` -**%c** | The channel name (URL encoded UTF-8) +**%C** | The transliterated channel name in URL encoded ASCII with safe characters only - `WDR Köln :<>*?'"` will be `WDR%20Koln%20________` +**%c** | The transliterated channel name in URL encoded ASCII +**%U** | UTF-8 encoded URL Example: `file:///tmp/icons/%C.png` or `http://example.com/%c.png` diff --git a/src/channels.c b/src/channels.c index d7fb45388..b9d8b08da 100644 --- a/src/channels.c +++ b/src/channels.c @@ -941,8 +941,7 @@ channel_get_icon ( channel_t *ch ) chi = strdup(chicon); /* Check for and replace placeholders */ - if ((send = strstr(chi, "%C"))) { - + if ((send = strstr(chi, "%C")) || (send = strstr(chi, "%c"))) { sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1), chname, strlen(chname) * 2); if (sname == NULL) @@ -957,34 +956,24 @@ channel_get_icon ( channel_t *ch ) s = sname; while (s && *s) { c = *s; - if (c > 122 || strchr(":<>|*?'\"", c) != NULL) + if (send[1] == 'C' && (c > 122 || strchr(":<>|*?'\"", c) != NULL)) *(char *)s = '_'; else if (config.chicon_scheme == CHICON_LOWERCASE && c >= 'A' && c <= 'Z') *(char *)s = c - 'A' + 'a'; s++; } } - - } else if ((send = strstr(chi, "%c"))) { - - sname = intlconv_utf8safestr(intlconv_charset_id("ASCII", 1, 1), - chname, strlen(chname) * 2); - + } else if ((send = strstr(chi, "%U"))) { if (sname == NULL) sname = strdup(chname); if (config.chicon_scheme == CHICON_LOWERCASE) { - for (s = sname; *s; s++) { - c = *s; - if (c >= 'A' && c <= 'Z') - *(char *)s = c - 'A' + 'a'; - } + utf8_lowercase_inplace((char *)sname); } else if (config.chicon_scheme == CHICON_SVCNAME) { s = svcnamepicons(sname); free((char *)sname); sname = (char *)s; } - } else { buf[0] = '\0'; sname = NULL; diff --git a/src/tvheadend.h b/src/tvheadend.h index 306a37b9f..ece6ee433 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -765,6 +765,8 @@ char *base64_encode(char *out, int out_size, const uint8_t *in, int in_size); int put_utf8(char *out, int c); +char *utf8_lowercase_inplace(char *s); + static inline int64_t ts_rescale(int64_t ts, int tb) { // return (ts * tb + (tb / 2)) / 90000LL; diff --git a/src/utils.c b/src/utils.c index 45d03e478..2fd26761b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -291,6 +291,38 @@ put_utf8(char *out, int c) return 6; } +char *utf8_lowercase_inplace(char *s) +{ + char *r = s; + uint8_t c; + + for ( ; *s; s++) { + /* FIXME: this is really wrong version of lowercase for utf-8 */ + /* but it's a deep issue with the different locale handling */ + c = (uint8_t)*s; + if (c & 0x80) { + if ((c & 0xe0) == 0xc0) { + s++; + continue; + } else if ((c & 0xf0) == 0xe0) { + s++; + if (*s) s++; + } else if ((c & 0xf8) == 0xf0) { + s++; + if (*s) s++; + if (*s) s++; + } + } + if (c >= 'A' && c <= 'Z') + *(char *)s = c - 'A' + 'a'; + } + return r; +} + +/** + * + */ + static void sbuf_alloc_fail(int len) {