mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-02-02 15:07:36 -05:00
Fix: Corrected converting back and forth charsets for ICY
This commit is contained in:
parent
86f1c8970b
commit
b14ff56f64
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
@ -137,11 +138,13 @@ static void mp3_set_tag (format_plugin_t *plugin, const char *tag, const char *i
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_value)
|
||||
{
|
||||
value = util_conv_string (in_value, charset, plugin->charset);
|
||||
if (in_value) {
|
||||
value = util_conv_string (in_value, charset, "UTF-8");
|
||||
if (value == NULL)
|
||||
value = strdup (in_value);
|
||||
value = strdup(in_value);
|
||||
} else {
|
||||
thread_mutex_unlock(&source_mp3->url_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(tag, "title") == 0 || strcmp(tag, "song") == 0) {
|
||||
@ -159,7 +162,7 @@ static void mp3_set_tag (format_plugin_t *plugin, const char *tag, const char *i
|
||||
}
|
||||
|
||||
|
||||
static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigned int meta_len)
|
||||
static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigned int meta_len, bool update_vc)
|
||||
{
|
||||
if (metadata)
|
||||
{
|
||||
@ -181,6 +184,7 @@ static void filter_shoutcast_metadata (source_t *source, char *metadata, unsigne
|
||||
logging_playlist (source->mount, p, source->listeners);
|
||||
stats_event_conv (source->mount, "title", p, source->format->charset);
|
||||
stats_event_conv (source->mount, "display-title", p, source->format->charset);
|
||||
if (update_vc)
|
||||
format_set_vorbiscomment(source->format, MP3_METADATA_TITLE, p);
|
||||
yp_touch (source->mount);
|
||||
free (p);
|
||||
@ -233,38 +237,56 @@ static void mp3_set_title(source_t *source)
|
||||
{
|
||||
const char streamtitle[] = "StreamTitle='";
|
||||
const char streamurl[] = "StreamUrl='";
|
||||
const char *url_artist = vorbis_comment_query(&source->format->vc, MP3_METADATA_ARTIST, 0);
|
||||
const char *url_title = vorbis_comment_query(&source->format->vc, MP3_METADATA_TITLE, 0);
|
||||
const char *url = vorbis_comment_query(&source->format->vc, MP3_METADATA_URL, 0);
|
||||
const char *in_url_artist = vorbis_comment_query(&source->format->vc, MP3_METADATA_ARTIST, 0);
|
||||
const char *in_url_title = vorbis_comment_query(&source->format->vc, MP3_METADATA_TITLE, 0);
|
||||
const char *in_url = vorbis_comment_query(&source->format->vc, MP3_METADATA_URL, 0);
|
||||
char *url_artist = NULL;
|
||||
char *url_title = NULL;
|
||||
char *url = NULL;
|
||||
size_t size;
|
||||
unsigned char len_byte;
|
||||
refbuf_t *p;
|
||||
unsigned int len = sizeof(streamtitle) + 2; /* the StreamTitle, quotes, ; and null */
|
||||
mp3_state *source_mp3 = source->format->_state;
|
||||
const char *charset = source->format->charset;
|
||||
|
||||
/* make sure the url data does not disappear from under us */
|
||||
thread_mutex_lock (&source_mp3->url_lock);
|
||||
|
||||
/* work out message length */
|
||||
if (in_url_artist) {
|
||||
url_artist = util_conv_string(in_url_artist, "UTF-8", charset);
|
||||
if (url_artist)
|
||||
len += strlen (url_artist);
|
||||
len += strlen(url_artist);
|
||||
}
|
||||
|
||||
if (in_url_title) {
|
||||
url_title = util_conv_string(in_url_title, "UTF-8", charset);
|
||||
if (url_title)
|
||||
len += strlen (url_title);
|
||||
len += strlen(url_title);
|
||||
}
|
||||
|
||||
if (url_artist && url_title)
|
||||
len += 3;
|
||||
if (source_mp3->inline_url)
|
||||
{
|
||||
|
||||
if (source_mp3->inline_url) {
|
||||
char *end = strstr (source_mp3->inline_url, "';");
|
||||
if (end)
|
||||
len += end - source_mp3->inline_url+2;
|
||||
} else if (in_url) {
|
||||
url = util_conv_string(in_url, "UTF-8", charset);
|
||||
if (url)
|
||||
len += strlen(url) + strlen(streamurl) + 2;
|
||||
}
|
||||
else if (url)
|
||||
len += strlen (url) + strlen (streamurl) + 2;
|
||||
|
||||
#define MAX_META_LEN 255*16
|
||||
if (len > MAX_META_LEN)
|
||||
{
|
||||
thread_mutex_unlock (&source_mp3->url_lock);
|
||||
ICECAST_LOG_WARN("Metadata too long at %d chars", len);
|
||||
free(url_artist);
|
||||
free(url_title);
|
||||
free(url);
|
||||
return;
|
||||
}
|
||||
/* work out the metadata len byte */
|
||||
@ -304,12 +326,16 @@ static void mp3_set_title(source_t *source)
|
||||
snprintf (p->data+r, size-r, "StreamUrl='%s';", url);
|
||||
}
|
||||
ICECAST_LOG_DEBUG("shoutcast metadata block setup with %s", p->data+1);
|
||||
filter_shoutcast_metadata (source, p->data, size);
|
||||
filter_shoutcast_metadata (source, p->data, size, false);
|
||||
|
||||
refbuf_release (source_mp3->metadata);
|
||||
source_mp3->metadata = p;
|
||||
}
|
||||
thread_mutex_unlock (&source_mp3->url_lock);
|
||||
|
||||
free(url_artist);
|
||||
free(url_title);
|
||||
free(url);
|
||||
}
|
||||
|
||||
|
||||
@ -626,7 +652,7 @@ static refbuf_t *mp3_get_filter_meta(source_t *source)
|
||||
if (strncmp (meta->data+1, "StreamTitle=", 12) == 0)
|
||||
{
|
||||
filter_shoutcast_metadata (source, source_mp3->build_metadata,
|
||||
source_mp3->build_metadata_len);
|
||||
source_mp3->build_metadata_len, true);
|
||||
refbuf_release (source_mp3->metadata);
|
||||
source_mp3->metadata = meta;
|
||||
source_mp3->inline_url = strstr (meta->data+1, "StreamUrl='");
|
||||
|
Loading…
x
Reference in New Issue
Block a user