2009-04-13 19:35:02 +02:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-04-13 19:35:02 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-30 09:08:50 +01:00
|
|
|
#include "IcyMetaDataServer.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2013-10-19 16:58:45 +02:00
|
|
|
#include "util/FormatString.hxx"
|
2016-04-12 22:27:15 +02:00
|
|
|
#include "util/AllocatedString.hxx"
|
2017-07-05 17:11:34 +02:00
|
|
|
#include "util/TruncateString.hxx"
|
2014-12-01 22:25:18 +01:00
|
|
|
#include "util/Macros.hxx"
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
#include <string.h>
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
AllocatedString<>
|
2009-04-13 19:35:02 +02:00
|
|
|
icy_server_metadata_header(const char *name,
|
|
|
|
const char *genre, const char *url,
|
|
|
|
const char *content_type, int metaint)
|
|
|
|
{
|
2016-04-12 22:27:15 +02:00
|
|
|
return FormatString("ICY 200 OK\r\n"
|
|
|
|
"icy-notice1:<BR>This stream requires an audio player!<BR>\r\n" /* TODO */
|
|
|
|
"icy-notice2:MPD - The music player daemon<BR>\r\n"
|
|
|
|
"icy-name: %s\r\n" /* TODO */
|
|
|
|
"icy-genre: %s\r\n" /* TODO */
|
|
|
|
"icy-url: %s\r\n" /* TODO */
|
|
|
|
"icy-pub:1\r\n"
|
|
|
|
"icy-metaint:%d\r\n"
|
|
|
|
/* TODO "icy-br:%d\r\n" */
|
|
|
|
"Content-Type: %s\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"Pragma: no-cache\r\n"
|
|
|
|
"Cache-Control: no-cache, no-store\r\n"
|
|
|
|
"\r\n",
|
|
|
|
name,
|
|
|
|
genre,
|
|
|
|
url,
|
|
|
|
metaint,
|
|
|
|
/* bitrate, */
|
|
|
|
content_type);
|
2009-04-13 19:35:02 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
static AllocatedString<>
|
2009-04-13 19:35:02 +02:00
|
|
|
icy_server_metadata_string(const char *stream_title, const char* stream_url)
|
|
|
|
{
|
|
|
|
// The leading n is a placeholder for the length information
|
2016-04-12 22:27:15 +02:00
|
|
|
auto icy_metadata = FormatString("nStreamTitle='%s';"
|
2017-02-19 19:06:48 +01:00
|
|
|
"StreamUrl='%s';"
|
|
|
|
/* pad 15 spaces just in case
|
|
|
|
the length needs to be
|
|
|
|
rounded up */
|
|
|
|
" ",
|
2016-04-12 22:27:15 +02:00
|
|
|
stream_title,
|
|
|
|
stream_url);
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
size_t meta_length = strlen(icy_metadata.c_str());
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2011-03-31 21:43:53 +02:00
|
|
|
meta_length--; // subtract placeholder
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2017-02-19 19:06:48 +01:00
|
|
|
meta_length = meta_length / 16;
|
2009-04-13 19:35:02 +02:00
|
|
|
|
|
|
|
icy_metadata[0] = meta_length;
|
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
if (meta_length > 255)
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2009-04-13 19:35:02 +02:00
|
|
|
|
|
|
|
return icy_metadata;
|
|
|
|
}
|
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
PagePtr
|
2013-10-20 13:32:59 +02:00
|
|
|
icy_server_metadata_page(const Tag &tag, const TagType *types)
|
2009-04-13 19:35:02 +02:00
|
|
|
{
|
2014-12-01 22:30:42 +01:00
|
|
|
const char *tag_items[TAG_NUM_OF_ITEM_TYPES];
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2014-12-01 22:30:42 +01:00
|
|
|
int last_item = -1;
|
2013-01-30 09:13:46 +01:00
|
|
|
while (*types != TAG_NUM_OF_ITEM_TYPES) {
|
2014-12-01 22:30:42 +01:00
|
|
|
const char *tag_item = tag.GetValue(*types++);
|
2009-04-13 19:35:02 +02:00
|
|
|
if (tag_item)
|
|
|
|
tag_items[++last_item] = tag_item;
|
|
|
|
}
|
|
|
|
|
2014-12-01 22:30:42 +01:00
|
|
|
int item = 0;
|
2014-12-01 22:25:30 +01:00
|
|
|
|
|
|
|
// Length + Metadata - "StreamTitle='';StreamUrl='';" = 4081 - 28
|
2014-12-01 22:30:42 +01:00
|
|
|
char stream_title[(1 + 255 - 28) * 16];
|
2014-12-01 22:25:18 +01:00
|
|
|
char *p = stream_title, *const end = stream_title + ARRAY_SIZE(stream_title);
|
2014-12-01 22:25:30 +01:00
|
|
|
stream_title[0] = '\0';
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2014-12-01 22:25:18 +01:00
|
|
|
while (p < end && item <= last_item) {
|
2017-07-05 17:15:58 +02:00
|
|
|
p = CopyTruncateString(p, tag_items[item++], end - p);
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2014-12-01 22:25:18 +01:00
|
|
|
if (item <= last_item)
|
2017-07-05 17:15:58 +02:00
|
|
|
p = CopyTruncateString(p, " - ", end - p);
|
2009-04-13 19:35:02 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
const auto icy_string = icy_server_metadata_string(stream_title, "");
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2016-04-12 22:27:15 +02:00
|
|
|
if (icy_string.IsNull())
|
2013-10-19 18:19:03 +02:00
|
|
|
return nullptr;
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
return std::make_shared<Page>(icy_string.c_str(),
|
|
|
|
uint8_t(icy_string[0]) * 16 + 1);
|
2009-04-13 19:35:02 +02:00
|
|
|
}
|