2
* Copyright (C) 2003-2011 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
#include "icy_server.h"
28
#define G_LOG_DOMAIN "icy_server"
31
icy_server_metadata_header(const char *name,
32
const char *genre, const char *url,
33
const char *content_type, int metaint)
35
return g_strdup_printf("ICY 200 OK\r\n"
36
"icy-notice1:<BR>This stream requires an audio player!<BR>\r\n" /* TODO */
37
"icy-notice2:MPD - The music player daemon<BR>\r\n"
38
"icy-name: %s\r\n" /* TODO */
39
"icy-genre: %s\r\n" /* TODO */
40
"icy-url: %s\r\n" /* TODO */
43
/* TODO "icy-br:%d\r\n" */
44
"Content-Type: %s\r\n"
45
"Connection: close\r\n"
46
"Pragma: no-cache\r\n"
47
"Cache-Control: no-cache, no-store\r\n"
58
icy_server_metadata_string(const char *stream_title, const char* stream_url)
63
// The leading n is a placeholder for the length information
64
icy_metadata = g_strdup_printf("nStreamTitle='%s';"
69
g_return_val_if_fail(icy_metadata, NULL);
71
meta_length = strlen(icy_metadata);
73
meta_length--; // subtract placeholder
75
meta_length = ((int)meta_length / 16) + 1;
77
icy_metadata[0] = meta_length;
79
if (meta_length > 255) {
88
icy_server_metadata_page(const struct tag *tag, ...)
91
const gchar *tag_items[TAG_NUM_OF_ITEM_TYPES];
95
struct page *icy_metadata;
96
gchar stream_title[(1 + 255 - 28) * 16]; // Length + Metadata -
97
// "StreamTitle='';StreamUrl='';"
99
stream_title[0] = '\0';
106
const gchar *tag_item;
108
type = va_arg(args, enum tag_type);
110
if (type == TAG_NUM_OF_ITEM_TYPES)
113
tag_item = tag_get_value(tag, type);
116
tag_items[++last_item] = tag_item;
121
while (position < sizeof(stream_title) && item <= last_item) {
124
length = g_strlcpy(stream_title + position,
126
sizeof(stream_title) - position);
130
if (item <= last_item) {
131
length = g_strlcpy(stream_title + position,
133
sizeof(stream_title) - position);
139
icy_string = icy_server_metadata_string(stream_title, "");
141
if (icy_string == NULL)
144
icy_metadata = page_new_copy(icy_string, (icy_string[0] * 16) + 1);